arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
Add missing error handling
Eduard S eduard@iden3.io
Wed, 30 Sep 2020 11:58:31 +0200
commit

ca3ae28f4625f9b788079b4bd9d6456584174aa2

parent

8451b922955aacc237452be53e23f7bf5c2cfacf

4 files changed, 21 insertions(+), 8 deletions(-)

jump to
M eth/auction.go → eth/auction.go

@@ -958,7 +958,9 @@ logNewForge = crypto.Keccak256Hash([]byte("NewForge(address,uint128)"))

logHEZClaimed = crypto.Keccak256Hash([]byte("HEZClaimed(address,uint128)")) ) -// AuctionEventsByBlock returns the events in a block that happened in the Auction Smart Contract +// AuctionEventsByBlock returns the events in a block that happened in the +// Auction Smart Contract and the blockHash where the eents happened. If there +// are no events in that block, blockHash is nil. func (c *AuctionClient) AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *ethCommon.Hash, error) { var auctionEvents AuctionEvents var blockHash ethCommon.Hash

@@ -974,14 +976,14 @@ }

logs, err := c.client.client.FilterLogs(context.TODO(), query) if err != nil { - fmt.Println(err) + return nil, nil, err } if len(logs) > 0 { blockHash = logs[0].BlockHash } for _, vLog := range logs { if vLog.BlockHash != blockHash { - return nil, nil, err + return nil, nil, ErrBlockHashMismatchEvent } switch vLog.Topics[0] { case logNewBid:
M eth/ethereum.go → eth/ethereum.go

@@ -30,6 +30,9 @@ // ErrReceiptStatusFailed is used when receiving a failed transaction

ErrReceiptStatusFailed = fmt.Errorf("receipt status is failed") // ErrReceiptNotReceived is used when unable to retrieve a transaction ErrReceiptNotReceived = fmt.Errorf("receipt not available") + // ErrBlockHashMismatchEvent is used when there's a block hash mismatch + // beetween different events of the same block + ErrBlockHashMismatchEvent = fmt.Errorf("block hash mismatch in event log") ) const (
M eth/main_test.go → eth/main_test.go

@@ -126,9 +126,15 @@

// Controllable Governance Address ethereumClientGov := NewEthereumClient(ethClient, accountGov, ks, nil) - auctionClient, _ = NewAuctionClient(ethereumClientGov, auctionAddressConst, tokenHezAddressConst) + auctionClient, err = NewAuctionClient(ethereumClientGov, auctionAddressConst, tokenHezAddressConst) + if err != nil { + panic(err) + } rollupClient = NewRollupClient(ethereumClientGov, hermezRollupAddressConst) - wdelayerClient, _ = NewWDelayerClient(ethereumClientGov, wdelayerAddressConst) + wdelayerClient, err = NewWDelayerClient(ethereumClientGov, wdelayerAddressConst) + if err != nil { + panic(err) + } ethereumClientKep = NewEthereumClient(ethClient, accountKep, ks, nil) ethereumClientWhite = NewEthereumClient(ethClient, accountWhite, ks, nil)
M eth/wdelayer.go → eth/wdelayer.go

@@ -430,7 +430,9 @@ logNewWhiteHackGroupAddress = crypto.Keccak256Hash([]byte("NewWhiteHackGroupAddress(address)"))

logNewHermezGovernanceDAOAddress = crypto.Keccak256Hash([]byte("NewHermezGovernanceDAOAddress(address)")) ) -// WDelayerEventsByBlock returns the events in a block that happened in the WDelayer Smart Contract +// WDelayerEventsByBlock returns the events in a block that happened in the +// WDelayer Smart Contract and the blockHash where the eents happened. If +// there are no events in that block, blockHash is nil. func (c *WDelayerClient) WDelayerEventsByBlock(blockNum int64) (*WDelayerEvents, *ethCommon.Hash, error) { var wdelayerEvents WDelayerEvents var blockHash ethCommon.Hash

@@ -447,14 +449,14 @@ }

logs, err := c.client.client.FilterLogs(context.Background(), query) if err != nil { - fmt.Println(err) + return nil, nil, err } if len(logs) > 0 { blockHash = logs[0].BlockHash } for _, vLog := range logs { if vLog.BlockHash != blockHash { - return nil, nil, err + return nil, nil, ErrBlockHashMismatchEvent } switch vLog.Topics[0] { case logDeposit: