mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 03:16:45 +01:00
Update test ethclient and coordinator
This commit is contained in:
@@ -240,11 +240,11 @@ type AuctionInterface interface {
|
||||
AuctionUpdateCoordinatorInfo(forgerAddress ethCommon.Address, newWithdrawAddress ethCommon.Address, newURL string) (*types.Transaction, error)
|
||||
|
||||
// Slot Info
|
||||
AuctionGetSlotNumber(blockNum int64) (int64, error)
|
||||
AuctionGetCurrentSlotNumber() (int64, error)
|
||||
AuctionGetMinBidBySlot(slot int64) (*big.Int, error)
|
||||
AuctionGetDefaultSlotSetBid(slotSet uint8) (*big.Int, error)
|
||||
AuctionGetSlotSet(slot int64) (*big.Int, error)
|
||||
AuctionGetSlotNumber(blockNum int64) (*big.Int, error)
|
||||
|
||||
// Bidding
|
||||
// AuctionTokensReceived(operator, from, to ethCommon.Address, amount *big.Int,
|
||||
@@ -698,7 +698,7 @@ func (c *AuctionClient) AuctionGetDefaultSlotSetBid(slotSet uint8) (*big.Int, er
|
||||
}
|
||||
|
||||
// AuctionGetSlotNumber is the interface to call the smart contract function
|
||||
func (c *AuctionClient) AuctionGetSlotNumber(blockNum int64) (*big.Int, error) {
|
||||
func (c *AuctionClient) AuctionGetSlotNumber(blockNum int64) (int64, error) {
|
||||
var slot *big.Int
|
||||
if err := c.client.Call(func(ec *ethclient.Client) error {
|
||||
auction, err := HermezAuctionProtocol.NewHermezAuctionProtocol(c.address, ec)
|
||||
@@ -709,9 +709,9 @@ func (c *AuctionClient) AuctionGetSlotNumber(blockNum int64) (*big.Int, error) {
|
||||
slot, err = auction.GetSlotNumber(nil, blockNumBig)
|
||||
return err
|
||||
}); err != nil {
|
||||
return big.NewInt(0), err
|
||||
return 0, err
|
||||
}
|
||||
return slot, nil
|
||||
return slot.Int64(), nil
|
||||
}
|
||||
|
||||
// AuctionBid is the interface to call the smart contract function
|
||||
|
||||
@@ -21,6 +21,8 @@ type EthereumInterface interface {
|
||||
EthCurrentBlock() (int64, error)
|
||||
// EthHeaderByNumber(context.Context, *big.Int) (*types.Header, error)
|
||||
EthBlockByNumber(context.Context, int64) (*common.Block, error)
|
||||
EthAddress() (*ethCommon.Address, error)
|
||||
EthTransactionReceipt(context.Context, ethCommon.Hash) (*types.Receipt, error)
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -90,6 +92,14 @@ func (c *EthereumClient) Account() *accounts.Account {
|
||||
return c.account
|
||||
}
|
||||
|
||||
// EthAddress returns the ethereum address of the account loaded into the EthereumClient
|
||||
func (c *EthereumClient) EthAddress() (*ethCommon.Address, error) {
|
||||
if c.account == nil {
|
||||
return nil, ErrAccountNil
|
||||
}
|
||||
return &c.account.Address, nil
|
||||
}
|
||||
|
||||
// CallAuth performs a Smart Contract method call that requires authorization.
|
||||
// This call requires a valid account with Ether that can be spend during the
|
||||
// call.
|
||||
@@ -186,16 +196,21 @@ func (c *EthereumClient) GetReceipt(tx *types.Transaction) (*types.Receipt, erro
|
||||
return c.waitReceipt(ctx, tx, 0)
|
||||
}
|
||||
|
||||
// EthTransactionReceipt returns the transaction receipt of the given txHash
|
||||
func (c *EthereumClient) EthTransactionReceipt(ctx context.Context, txHash ethCommon.Hash) (*types.Receipt, error) {
|
||||
return c.client.TransactionReceipt(ctx, txHash)
|
||||
}
|
||||
|
||||
func (c *EthereumClient) waitReceipt(ctx context.Context, tx *types.Transaction, timeout time.Duration) (*types.Receipt, error) {
|
||||
var err error
|
||||
var receipt *types.Receipt
|
||||
|
||||
txid := tx.Hash()
|
||||
log.Debugw("Waiting for receipt", "tx", txid.Hex())
|
||||
txHash := tx.Hash()
|
||||
log.Debugw("Waiting for receipt", "tx", txHash.Hex())
|
||||
|
||||
start := time.Now()
|
||||
for {
|
||||
receipt, err = c.client.TransactionReceipt(ctx, txid)
|
||||
receipt, err = c.client.TransactionReceipt(ctx, txHash)
|
||||
if receipt != nil || time.Since(start) >= timeout {
|
||||
break
|
||||
}
|
||||
@@ -203,15 +218,15 @@ func (c *EthereumClient) waitReceipt(ctx context.Context, tx *types.Transaction,
|
||||
}
|
||||
|
||||
if receipt != nil && receipt.Status == types.ReceiptStatusFailed {
|
||||
log.Errorw("Failed transaction", "tx", txid.Hex())
|
||||
log.Errorw("Failed transaction", "tx", txHash.Hex())
|
||||
return receipt, ErrReceiptStatusFailed
|
||||
}
|
||||
|
||||
if receipt == nil {
|
||||
log.Debugw("Pendingtransaction / Wait receipt timeout", "tx", txid.Hex(), "lasterr", err)
|
||||
log.Debugw("Pendingtransaction / Wait receipt timeout", "tx", txHash.Hex(), "lasterr", err)
|
||||
return receipt, ErrReceiptNotReceived
|
||||
}
|
||||
log.Debugw("Successful transaction", "tx", txid.Hex())
|
||||
log.Debugw("Successful transaction", "tx", txHash.Hex())
|
||||
|
||||
return receipt, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user