mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 11:26:44 +01:00
Wrap all errors with tracerr
This commit is contained in:
@@ -15,6 +15,7 @@ import (
|
||||
"github.com/hermeznetwork/hermez-node/common"
|
||||
HEZ "github.com/hermeznetwork/hermez-node/eth/contracts/tokenHEZ"
|
||||
"github.com/hermeznetwork/hermez-node/log"
|
||||
"github.com/hermeznetwork/tracerr"
|
||||
)
|
||||
|
||||
// ERC20Consts are the constants defined in a particular ERC20 Token instance
|
||||
@@ -105,7 +106,7 @@ func (c *EthereumClient) Account() *accounts.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 nil, tracerr.Wrap(ErrAccountNil)
|
||||
}
|
||||
return &c.account.Address, nil
|
||||
}
|
||||
@@ -116,12 +117,12 @@ func (c *EthereumClient) EthAddress() (*ethCommon.Address, error) {
|
||||
func (c *EthereumClient) CallAuth(gasLimit uint64,
|
||||
fn func(*ethclient.Client, *bind.TransactOpts) (*types.Transaction, error)) (*types.Transaction, error) {
|
||||
if c.account == nil {
|
||||
return nil, ErrAccountNil
|
||||
return nil, tracerr.Wrap(ErrAccountNil)
|
||||
}
|
||||
|
||||
gasPrice, err := c.client.SuggestGasPrice(context.Background())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
inc := new(big.Int).Set(gasPrice)
|
||||
inc.Div(inc, new(big.Int).SetUint64(c.config.GasPriceDiv))
|
||||
@@ -130,7 +131,7 @@ func (c *EthereumClient) CallAuth(gasLimit uint64,
|
||||
|
||||
auth, err := bind.NewKeyStoreTransactor(c.ks, *c.account)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
auth.Value = big.NewInt(0) // in wei
|
||||
if gasLimit == 0 {
|
||||
@@ -144,7 +145,7 @@ func (c *EthereumClient) CallAuth(gasLimit uint64,
|
||||
if tx != nil {
|
||||
log.Debugw("Transaction", "tx", tx.Hash().Hex(), "nonce", tx.Nonce())
|
||||
}
|
||||
return tx, err
|
||||
return tx, tracerr.Wrap(err)
|
||||
}
|
||||
|
||||
// ContractData contains the contract data
|
||||
@@ -167,20 +168,20 @@ func (c *EthereumClient) Deploy(name string,
|
||||
func(client *ethclient.Client, auth *bind.TransactOpts) (*types.Transaction, error) {
|
||||
addr, tx, _, err := fn(client, auth)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
contractData.Address = addr
|
||||
return tx, nil
|
||||
},
|
||||
)
|
||||
if err != nil {
|
||||
return contractData, fmt.Errorf(errStrDeploy, name, err)
|
||||
return contractData, tracerr.Wrap(fmt.Errorf(errStrDeploy, name, err))
|
||||
}
|
||||
log.Infow("Waiting receipt", "tx", tx.Hash().Hex(), "contract", name)
|
||||
contractData.Tx = tx
|
||||
receipt, err := c.WaitReceipt(tx)
|
||||
if err != nil {
|
||||
return contractData, fmt.Errorf(errStrWaitReceipt, name, err)
|
||||
return contractData, tracerr.Wrap(fmt.Errorf(errStrWaitReceipt, name, err))
|
||||
}
|
||||
contractData.Receipt = receipt
|
||||
return contractData, nil
|
||||
@@ -229,16 +230,16 @@ func (c *EthereumClient) waitReceipt(ctx context.Context, tx *types.Transaction,
|
||||
|
||||
if receipt != nil && receipt.Status == types.ReceiptStatusFailed {
|
||||
log.Errorw("Failed transaction", "tx", txHash.Hex())
|
||||
return receipt, ErrReceiptStatusFailed
|
||||
return receipt, tracerr.Wrap(ErrReceiptStatusFailed)
|
||||
}
|
||||
|
||||
if receipt == nil {
|
||||
log.Debugw("Pendingtransaction / Wait receipt timeout", "tx", txHash.Hex(), "lasterr", err)
|
||||
return receipt, ErrReceiptNotReceived
|
||||
return receipt, tracerr.Wrap(ErrReceiptNotReceived)
|
||||
}
|
||||
log.Debugw("Successful transaction", "tx", txHash.Hex())
|
||||
|
||||
return receipt, err
|
||||
return receipt, tracerr.Wrap(err)
|
||||
}
|
||||
|
||||
// EthLastBlock returns the last block number in the blockchain
|
||||
@@ -247,7 +248,7 @@ func (c *EthereumClient) EthLastBlock() (int64, error) {
|
||||
defer cancel()
|
||||
header, err := c.client.HeaderByNumber(ctx, nil)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
return 0, tracerr.Wrap(err)
|
||||
}
|
||||
return header.Number.Int64(), nil
|
||||
}
|
||||
@@ -266,7 +267,7 @@ func (c *EthereumClient) EthBlockByNumber(ctx context.Context, number int64) (*c
|
||||
}
|
||||
block, err := c.client.BlockByNumber(ctx, blockNum)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
b := &common.Block{
|
||||
Num: block.Number().Int64(),
|
||||
@@ -283,21 +284,21 @@ func (c *EthereumClient) EthERC20Consts(tokenAddress ethCommon.Address) (*ERC20C
|
||||
// ERC20, which allows us to access the standard ERC20 constants.
|
||||
instance, err := HEZ.NewHEZ(tokenAddress, c.client)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
name, err := instance.Name(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
|
||||
symbol, err := instance.Symbol(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
|
||||
decimals, err := instance.Decimals(nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
return &ERC20Consts{
|
||||
Name: name,
|
||||
|
||||
Reference in New Issue
Block a user