Browse Source

Add missing error handling

feature/sql-semaphore1
Eduard S 4 years ago
parent
commit
ca3ae28f46
4 changed files with 21 additions and 8 deletions
  1. +5
    -3
      eth/auction.go
  2. +3
    -0
      eth/ethereum.go
  3. +8
    -2
      eth/main_test.go
  4. +5
    -3
      eth/wdelayer.go

+ 5
- 3
eth/auction.go

@ -958,7 +958,9 @@ var (
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 @@ func (c *AuctionClient) AuctionEventsByBlock(blockNum int64) (*AuctionEvents, *e
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:

+ 3
- 0
eth/ethereum.go

@ -30,6 +30,9 @@ var (
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 (

+ 8
- 2
eth/main_test.go

@ -126,9 +126,15 @@ func TestMain(m *testing.M) {
// 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)

+ 5
- 3
eth/wdelayer.go

@ -430,7 +430,9 @@ var (
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 @@ func (c *WDelayerClient) WDelayerEventsByBlock(blockNum int64) (*WDelayerEvents,
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:

Loading…
Cancel
Save