Skip to content

Commit

Permalink
Merge pull request #324 from onflow/auto-update-onflow-cadence-v1.0.0…
Browse files Browse the repository at this point in the history
…-preview.35

Update to Cadence v1.0.0-preview.35
  • Loading branch information
turbolent authored Jun 28, 2024
2 parents d69a16c + 85cbd6f commit 07940bf
Show file tree
Hide file tree
Showing 15 changed files with 80 additions and 108 deletions.
6 changes: 1 addition & 5 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,11 +236,7 @@ func (b *BlockChainAPI) GetTransactionByHash(
return handleError[*Transaction](b.logger, err)
}

txHash, err := tx.Hash()
if err != nil {
b.logger.Error().Err(err).Any("tx", tx).Msg("failed to calculate tx hash")
return nil, errs.ErrInternal
}
txHash := tx.Hash()

rcp, err := b.receipts.GetByTransactionID(txHash)
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions api/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,7 @@ func NewTransaction(
receipt models.StorageReceipt,
config config.Config,
) (*Transaction, error) {
txHash, err := tx.Hash()
if err != nil {
return nil, err
}
txHash := tx.Hash()

f, err := tx.From()
if err != nil {
Expand Down
6 changes: 1 addition & 5 deletions api/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,8 @@ func (api *PullAPI) getTransactions(latestHeight uint64, filter *transactionsFil
return nil, err
}

h, err := tx.Hash()
if err != nil {
continue
}
txs = append(txs, tx)
hashes = append(hashes, h)
hashes = append(hashes, tx.Hash())
}
}

Expand Down
5 changes: 1 addition & 4 deletions api/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,7 @@ func (s *StreamAPI) NewPendingTransactions(ctx context.Context, fullTx *bool) (*
return nil, fmt.Errorf("failed to get receipt with hash: %s at height: %d: %w", hash, height, err)
}

h, err := tx.Hash()
if err != nil {
return nil, fmt.Errorf("failed to compute tx hash: %w", err)
}
h := tx.Hash()

t, err := NewTransaction(tx, *rcp, *s.config)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ require (
github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593
github.com/goccy/go-json v0.10.2
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/onflow/cadence v1.0.0-preview.34
github.com/onflow/flow-go v0.35.14-crescendo-preview.27
github.com/onflow/flow-go-sdk v1.0.0-preview.36
github.com/onflow/cadence v1.0.0-preview.35
github.com/onflow/flow-go v0.35.14-crescendo-preview.27.0.20240626210601-604590f19db9
github.com/onflow/flow-go-sdk v1.0.0-preview.37
github.com/onflow/go-ethereum v1.13.4
github.com/rs/cors v1.8.0
github.com/rs/zerolog v1.31.0
Expand Down Expand Up @@ -129,14 +129,14 @@ require (
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/onflow/atree v0.7.0-rc.2 // indirect
github.com/onflow/crypto v0.25.1 // indirect
github.com/onflow/flow-core-contracts/lib/go/contracts v1.1.0 // indirect
github.com/onflow/flow-core-contracts/lib/go/templates v1.0.0 // indirect
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.0 // indirect
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.0 // indirect
github.com/onflow/flow-ft/lib/go/contracts v1.0.0 // indirect
github.com/onflow/flow-ft/lib/go/templates v1.0.0 // indirect
github.com/onflow/flow-nft/lib/go/contracts v1.2.1 // indirect
github.com/onflow/flow-nft/lib/go/templates v1.2.0 // indirect
github.com/onflow/flow/protobuf/go/flow v0.4.4 // indirect
github.com/onflow/sdks v0.5.1-0.20230912225508-b35402f12bba // indirect
github.com/onflow/sdks v0.6.0-preview.1 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/onsi/gomega v1.18.1 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
Expand Down
23 changes: 12 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1941,24 +1941,24 @@ github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f/go.mod h1:xvP61FoOs
github.com/onflow/atree v0.7.0-rc.2 h1:mZmVrl/zPlfI44EjV3FdR2QwIqT8nz1sCONUBFcML/U=
github.com/onflow/atree v0.7.0-rc.2/go.mod h1:xvP61FoOs95K7IYdIYRnNcYQGf4nbF/uuJ0tHf4DRuM=
github.com/onflow/cadence v1.0.0-M3/go.mod h1:odXGZZ/wGNA5mwT8bC9v8u8EXACHllB2ABSZK65TGL8=
github.com/onflow/cadence v1.0.0-preview.34 h1:MJSli75W6LJVUqSx/tq4MQe64H1+EcQBD/sNgpOO4jE=
github.com/onflow/cadence v1.0.0-preview.34/go.mod h1:jOwvPSSLTr9TvaKMs7KKiBYMmpdpNNAFxBsjMlrqVD0=
github.com/onflow/cadence v1.0.0-preview.35 h1:HZgt/9Foa6sCSH9SNaIFUSXK6q2ZxETg0ivsZbf+hhU=
github.com/onflow/cadence v1.0.0-preview.35/go.mod h1:jOwvPSSLTr9TvaKMs7KKiBYMmpdpNNAFxBsjMlrqVD0=
github.com/onflow/crypto v0.25.0/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI=
github.com/onflow/crypto v0.25.1 h1:0txy2PKPMM873JbpxQNbJmuOJtD56bfs48RQfm0ts5A=
github.com/onflow/crypto v0.25.1/go.mod h1:C8FbaX0x8y+FxWjbkHy0Q4EASCDR9bSPWZqlpCLYyVI=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.1.0 h1:AegPBm079X0qjneUYs+mRCpEUxSZ1lw5h4MbuXHlqn0=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.1.0/go.mod h1:u/mkP/B+PbV33tEG3qfkhhBlydSvAKxfLZSfB4lsJHg=
github.com/onflow/flow-core-contracts/lib/go/templates v1.0.0 h1:za6bxPPW4JIsthhasUDTa1ruKjIO8DIhun9INQfj61Y=
github.com/onflow/flow-core-contracts/lib/go/templates v1.0.0/go.mod h1:NgbMOYnMh0GN48VsNKZuiwK7uyk38Wyo8jN9+C9QE30=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.0 h1:cq3RfBr9TnTSnsGlUHMjMGZib24Horfb1XJqMpkN5ew=
github.com/onflow/flow-core-contracts/lib/go/contracts v1.3.0/go.mod h1:u/mkP/B+PbV33tEG3qfkhhBlydSvAKxfLZSfB4lsJHg=
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.0 h1:aMFJdB2CW+Dzm+AJ5QN6J1yWh+a0l2RxHN2/TtLaXUo=
github.com/onflow/flow-core-contracts/lib/go/templates v1.3.0/go.mod h1:NgbMOYnMh0GN48VsNKZuiwK7uyk38Wyo8jN9+C9QE30=
github.com/onflow/flow-ft/lib/go/contracts v1.0.0 h1:mToacZ5NWqtlWwk/7RgIl/jeKB/Sy/tIXdw90yKHcV0=
github.com/onflow/flow-ft/lib/go/contracts v1.0.0/go.mod h1:PwsL8fC81cjnUnTfmyL/HOIyHnyaw/JA474Wfj2tl6A=
github.com/onflow/flow-ft/lib/go/templates v1.0.0 h1:6cMS/lUJJ17HjKBfMO/eh0GGvnpElPgBXx7h5aoWJhs=
github.com/onflow/flow-ft/lib/go/templates v1.0.0/go.mod h1:uQ8XFqmMK2jxyBSVrmyuwdWjTEb+6zGjRYotfDJ5pAE=
github.com/onflow/flow-go v0.35.14-crescendo-preview.27 h1:sWjWsutcFOP9o/etZF3Zii0eq4MMqKQchquwmyElWCQ=
github.com/onflow/flow-go v0.35.14-crescendo-preview.27/go.mod h1:P7AnyTH5W+hNm5pmhnYasIh7T6Z2kU4tiy53NJKvhZA=
github.com/onflow/flow-go v0.35.14-crescendo-preview.27.0.20240626210601-604590f19db9 h1:9GfHBXy9T8QEAkwX+KkmZjJadSOAVgiyn2n8s7sSueY=
github.com/onflow/flow-go v0.35.14-crescendo-preview.27.0.20240626210601-604590f19db9/go.mod h1:SE4kph7kpF6ydOXObtueEecGk3Hrjy/if/0UHY/eRO8=
github.com/onflow/flow-go-sdk v1.0.0-M1/go.mod h1:TDW0MNuCs4SvqYRUzkbRnRmHQL1h4X8wURsCw9P9beo=
github.com/onflow/flow-go-sdk v1.0.0-preview.36 h1:3g72MjmZPEEVAbtDATbjwqKoNSB7yHLWswUHSAB5zwQ=
github.com/onflow/flow-go-sdk v1.0.0-preview.36/go.mod h1:mjkXIluC+kseYyd8Z1aTq73IiffAUeoY5fuX/C2Z+1w=
github.com/onflow/flow-go-sdk v1.0.0-preview.37 h1:ujeIQheD+skzFt9+eOT9nXcc1rFxVLSCzwisEI3+2DA=
github.com/onflow/flow-go-sdk v1.0.0-preview.37/go.mod h1:2aSN7RdKzxWoCtCyOJz9W/ZNqkLgQDQS3hKLYwPlvGw=
github.com/onflow/flow-nft/lib/go/contracts v1.2.1 h1:woAAS5z651sDpi7ihAHll8NvRS9uFXIXkL6xR+bKFZY=
github.com/onflow/flow-nft/lib/go/contracts v1.2.1/go.mod h1:2gpbza+uzs1k7x31hkpBPlggIRkI53Suo0n2AyA2HcE=
github.com/onflow/flow-nft/lib/go/templates v1.2.0 h1:JSQyh9rg0RC+D1930BiRXN8lrtMs+ubVMK6aQPon6Yc=
Expand All @@ -1968,8 +1968,9 @@ github.com/onflow/flow/protobuf/go/flow v0.4.4 h1:lD1owoZGFgLcvdLZDmP0Kc4GOuQeSU
github.com/onflow/flow/protobuf/go/flow v0.4.4/go.mod h1:NA2pX2nw8zuaxfKphhKsk00kWLwfd+tv8mS23YXO4Sk=
github.com/onflow/go-ethereum v1.13.4 h1:iNO86fm8RbBbhZ87ZulblInqCdHnAQVY8okBrNsTevc=
github.com/onflow/go-ethereum v1.13.4/go.mod h1:cE/gEUkAffhwbVmMJYz+t1dAfVNHNwZCgc3BWtZxBGY=
github.com/onflow/sdks v0.5.1-0.20230912225508-b35402f12bba h1:rIehuhO6bj4FkwE4VzwEjX7MoAlOhUJENBJLqDqVxAo=
github.com/onflow/sdks v0.5.1-0.20230912225508-b35402f12bba/go.mod h1:F0dj0EyHC55kknLkeD10js4mo14yTdMotnWMslPirrU=
github.com/onflow/sdks v0.6.0-preview.1 h1:mb/cUezuqWEP1gFZNAgUI4boBltudv4nlfxke1KBp9k=
github.com/onflow/sdks v0.6.0-preview.1/go.mod h1:F0dj0EyHC55kknLkeD10js4mo14yTdMotnWMslPirrU=
github.com/onflow/wal v1.0.2 h1:5bgsJVf2O3cfMNK12fiiTyYZ8cOrUiELt3heBJfHOhc=
github.com/onflow/wal v1.0.2/go.mod h1:iMC8gkLqu4nkbkAla5HkSBb+FGyQOZiWz3DYm2wSXCk=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
Expand Down
5 changes: 1 addition & 4 deletions models/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,7 @@ func MarshalReceipt(
return map[string]interface{}{}, err
}

txHash, err := tx.Hash()
if err != nil {
return map[string]interface{}{}, err
}
txHash := tx.Hash()

fields := map[string]interface{}{
"blockHash": receipt.BlockHash,
Expand Down
9 changes: 4 additions & 5 deletions models/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ import (
)

type Transaction interface {
// TODO(m-Peter): Remove the error return value once flow-go is updated
Hash() (common.Hash, error)
Hash() common.Hash
RawSignatureValues() (v *big.Int, r *big.Int, s *big.Int)
From() (common.Address, error)
To() *common.Address
Expand All @@ -41,7 +40,7 @@ type DirectCall struct {
*types.DirectCall
}

func (dc DirectCall) Hash() (common.Hash, error) {
func (dc DirectCall) Hash() common.Hash {
return dc.DirectCall.Hash()
}

Expand Down Expand Up @@ -132,8 +131,8 @@ type TransactionCall struct {
*gethTypes.Transaction
}

func (tc TransactionCall) Hash() (common.Hash, error) {
return tc.Transaction.Hash(), nil
func (tc TransactionCall) Hash() common.Hash {
return tc.Transaction.Hash()
}

func (tc TransactionCall) From() (common.Address, error) {
Expand Down
26 changes: 15 additions & 11 deletions models/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ func createTestEvent(t *testing.T, txBinary string) (cadence.Event, *types.Resul
directCall, err := types.DirectCallFromEncoded(txEncoded)
require.NoError(t, err)

txHash, err = directCall.Hash()
require.NoError(t, err)
txHash = directCall.Hash()

txType = types.DirectCallTxType
} else {
Expand Down Expand Up @@ -81,9 +80,10 @@ func Test_DecodeEVMTransaction(t *testing.T) {
require.NoError(t, err)
require.IsType(t, TransactionCall{}, decTx)

txHash, err := decTx.Hash()
require.NoError(t, err)
txHash := decTx.Hash()

v, r, s := decTx.RawSignatureValues()

from, err := decTx.From()
require.NoError(t, err)

Expand Down Expand Up @@ -126,15 +126,17 @@ func Test_DecodeDirectCall(t *testing.T) {
require.NoError(t, err)
require.IsType(t, DirectCall{}, decTx)

txHash, err := decTx.Hash()
txHash := decTx.Hash()
require.NoError(t, err)

v, r, s := decTx.RawSignatureValues()

from, err := decTx.From()
require.NoError(t, err)

assert.Equal(
t,
gethCommon.HexToHash("0xe090f3a66f269d436e4185551d790d923f53a2caabf475c18d60bf1f091813d9"),
gethCommon.HexToHash("0xb055748f36d6bbe99a7ab5e45202b5c095ceda985dec0cc2a8747fd88c80c8c9"),
txHash,
)
assert.Equal(t, big.NewInt(0), v)
Expand Down Expand Up @@ -178,9 +180,10 @@ func Test_UnmarshalTransaction(t *testing.T) {
require.NoError(t, err)
require.IsType(t, TransactionCall{}, decTx)

txHash, err := decTx.Hash()
require.NoError(t, err)
txHash := decTx.Hash()

v, r, s := decTx.RawSignatureValues()

from, err := decTx.From()
require.NoError(t, err)

Expand Down Expand Up @@ -231,15 +234,16 @@ func Test_UnmarshalTransaction(t *testing.T) {
require.NoError(t, err)
require.IsType(t, DirectCall{}, decTx)

txHash, err := decTx.Hash()
require.NoError(t, err)
txHash := decTx.Hash()

v, r, s := decTx.RawSignatureValues()

from, err := decTx.From()
require.NoError(t, err)

assert.Equal(
t,
gethCommon.HexToHash("0xe090f3a66f269d436e4185551d790d923f53a2caabf475c18d60bf1f091813d9"),
gethCommon.HexToHash("0xb055748f36d6bbe99a7ab5e45202b5c095ceda985dec0cc2a8747fd88c80c8c9"),
txHash,
)
assert.Equal(t, big.NewInt(0), v)
Expand Down
7 changes: 2 additions & 5 deletions services/ingestion/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,8 @@ func (e *Engine) indexTransaction(tx models.Transaction, receipt *models.Storage
if tx == nil || receipt == nil { // safety check shouldn't happen
return fmt.Errorf("can't process empty tx or receipt")
}
// TODO(m-Peter): Remove the error return value once flow-go is updated
txHash, err := tx.Hash()
if err != nil {
return fmt.Errorf("failed to compute TX hash: %w", err)
}

txHash := tx.Hash()

e.log.Info().
Str("contract-address", receipt.ContractAddress.String()).
Expand Down
12 changes: 2 additions & 10 deletions services/ingestion/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,11 +268,7 @@ func TestBlockAndTransactionIngestion(t *testing.T) {
transactions.
On("Store", mock.AnythingOfType("models.TransactionCall")).
Return(func(tx models.Transaction) error {
transactionHash, err := transaction.Hash()
require.NoError(t, err)
txHash, err := tx.Hash()
require.NoError(t, err)
assert.Equal(t, transactionHash, txHash) // if hashes are equal tx is equal
assert.Equal(t, transaction.Hash(), tx.Hash()) // if hashes are equal tx is equal
return nil
}).
Once()
Expand Down Expand Up @@ -480,11 +476,7 @@ func TestBlockAndTransactionIngestion(t *testing.T) {
transactions.
On("Store", mock.AnythingOfType("models.TransactionCall")).
Return(func(tx models.Transaction) error {
transactionHash, err := transaction.Hash()
require.NoError(t, err)
txHash, err := tx.Hash()
require.NoError(t, err)
assert.Equal(t, transactionHash, txHash) // if hashes are equal tx is equal
assert.Equal(t, transaction.Hash(), tx.Hash()) // if hashes are equal tx is equal
require.True(t, blockIndexedFirst)
txsStored++
return nil
Expand Down
23 changes: 10 additions & 13 deletions storage/index_testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,12 +352,12 @@ func (s *TransactionTestSuite) TestGetTransaction() {
err := s.TransactionIndexer.Store(tx)
s.Require().NoError(err)

txHash, err := tx.Hash()
s.Require().NoError(err)
txHash := tx.Hash()

retTx, err := s.TransactionIndexer.Get(txHash)
s.Require().NoError(err)
retTxHash, err := retTx.Hash()
s.Require().NoError(err)

retTxHash := retTx.Hash()
s.Require().Equal(txHash, retTxHash) // if hashes are equal the data must be equal

// allow same transaction overwrites
Expand All @@ -372,14 +372,13 @@ func (s *TransactionTestSuite) TestGetTransaction() {
s.Require().NoError(err)
}

txHash, err := tx.Hash()
s.Require().NoError(err)
txHash := tx.Hash()

t, err := s.TransactionIndexer.Get(txHash)
s.Require().NoError(err)
tHash, err := t.Hash()
s.Require().NoError(err)

tHash := t.Hash()
s.Require().Equal(txHash, tHash)
s.Require().NoError(err)
})

s.Run("non-existing transaction", func() {
Expand Down Expand Up @@ -414,8 +413,7 @@ func (a *AccountTestSuite) TestNonce() {
txCall, ok := tx.(models.TransactionCall)
a.Require().True(ok)

txHash, err := tx.Hash()
a.Require().NoError(err)
txHash := tx.Hash()

rcp := mocks.NewReceipt(uint64(i+5), txHash)
gethTx, err := types.SignTx(txCall.Transaction, evmEmulator.GetDefaultSigner(), key)
Expand All @@ -439,8 +437,7 @@ func (a *AccountTestSuite) TestNonce() {
txCall, ok := tx.(models.TransactionCall)
a.Require().True(ok)

txHash, err := tx.Hash()
a.Require().NoError(err)
txHash := tx.Hash()

rcp := mocks.NewReceipt(uint64(i+5), txHash)
gethTx, err := types.SignTx(txCall.Transaction, evmEmulator.GetDefaultSigner(), key)
Expand Down
8 changes: 3 additions & 5 deletions storage/pebble/transactions.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package pebble
import (
"sync"

"github.com/onflow/go-ethereum/common"

"github.com/onflow/flow-evm-gateway/models"
"github.com/onflow/flow-evm-gateway/storage"
"github.com/onflow/go-ethereum/common"
)

var _ storage.TransactionIndexer = &Transactions{}
Expand All @@ -31,10 +32,7 @@ func (t *Transactions) Store(tx models.Transaction) error {
return err
}

txHash, err := tx.Hash()
if err != nil {
return err
}
txHash := tx.Hash()

return t.store.set(txIDKey, txHash.Bytes(), val, nil)
}
Expand Down
Loading

0 comments on commit 07940bf

Please sign in to comment.