Skip to content

Commit

Permalink
adjust code to API changes of cadence package
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed May 2, 2024
1 parent acd7741 commit ceaa21e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 20 deletions.
11 changes: 1 addition & 10 deletions bootstrap/create-multi-key-account.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,16 +171,7 @@ func eventsFromTx(tx *flow.TransactionResult) events {
}

func newEvent(event flow.Event) flowEvent {
var names []string

for _, eventType := range event.Value.EventType.Fields {
names = append(names, eventType.Identifier)
}
values := make(map[string]cadence.Value)
for id, field := range event.Value.Fields {
values[names[id]] = field
}

values := cadence.FieldsMappedByName(event.Value)
return flowEvent{
Type: event.Type,
Values: values,
Expand Down
2 changes: 1 addition & 1 deletion models/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func decodeBlock(event cadence.Event) (*types.Block, error) {

hashes := make([]common.Hash, len(payload.TransactionHashes))
for i, h := range payload.TransactionHashes {
hashes[i] = common.HexToHash(h.ToGoValue().(string))
hashes[i] = common.HexToHash(string(h))
}

return &types.Block{
Expand Down
3 changes: 1 addition & 2 deletions models/events_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import (

func TestCadenceEvents_Block(t *testing.T) {

v, _ := cadence.NewString("invalid")
invalid, _ := cadence.NewValue(v)
invalid := cadence.String("invalid")

b0, e0, err := newBlock(0)
require.NoError(t, err)
Expand Down
14 changes: 7 additions & 7 deletions services/requester/requester.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import (
"strings"

"github.com/onflow/cadence"
"github.com/onflow/flow-evm-gateway/api/errors"
"github.com/onflow/flow-evm-gateway/config"
"github.com/onflow/flow-go-sdk"
"github.com/onflow/flow-go-sdk/access"
"github.com/onflow/flow-go-sdk/crypto"
Expand All @@ -24,6 +22,9 @@ import (
gethVM "github.com/onflow/go-ethereum/core/vm"
"github.com/rs/zerolog"
"golang.org/x/sync/errgroup"

"github.com/onflow/flow-evm-gateway/api/errors"
"github.com/onflow/flow-evm-gateway/config"
)

var (
Expand Down Expand Up @@ -283,7 +284,7 @@ func (e *EVM) GetBalance(
e.logger.Panic().Msg(fmt.Sprintf("failed to convert balance %v to UInt", val))
}

return val.(cadence.UInt).ToGoValue().(*big.Int), nil
return val.(cadence.UInt).Big(), nil
}

func (e *EVM) GetNonce(
Expand Down Expand Up @@ -313,7 +314,7 @@ func (e *EVM) GetNonce(
e.logger.Panic().Msg(fmt.Sprintf("failed to convert balance %v to UInt64", val))
}

return val.(cadence.UInt64).ToGoValue().(uint64), nil
return uint64(val.(cadence.UInt64)), nil
}

func (e *EVM) Call(
Expand Down Expand Up @@ -458,7 +459,7 @@ func (e *EVM) GetLatestEVMHeight(ctx context.Context) (uint64, error) {
e.logger.Panic().Msg(fmt.Sprintf("failed to convert height %v to UInt64", val))
}

return val.(cadence.UInt64).ToGoValue().(uint64), nil
return uint64(val.(cadence.UInt64)), nil
}

// getSignerNetworkInfo loads the signer account from network and returns key index and sequence number
Expand Down Expand Up @@ -537,8 +538,7 @@ func cadenceStringToBytes(value cadence.Value) ([]byte, error) {
return nil, fmt.Errorf("failed to convert cadence value to string: %v", value)
}

hexEncodedCode := cdcString.ToGoValue().(string)
code, err := hex.DecodeString(hexEncodedCode)
code, err := hex.DecodeString(string(cdcString))
if err != nil {
return nil, fmt.Errorf("failed to decode string to byte array: %w", err)
}
Expand Down

0 comments on commit ceaa21e

Please sign in to comment.