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:
@@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
"github.com/hermeznetwork/tracerr"
|
||||
"github.com/iden3/go-iden3-crypto/babyjub"
|
||||
"github.com/iden3/go-iden3-crypto/poseidon"
|
||||
)
|
||||
@@ -63,12 +64,12 @@ func NewPoolL2Tx(poolL2Tx *PoolL2Tx) (*PoolL2Tx, error) {
|
||||
txType = TxTypeTransferToEthAddr
|
||||
}
|
||||
} else {
|
||||
return nil, errors.New("malformed transaction")
|
||||
return nil, tracerr.Wrap(errors.New("malformed transaction"))
|
||||
}
|
||||
|
||||
// if TxType!=poolL2Tx.TxType return error
|
||||
if poolL2Tx.Type != "" && poolL2Tx.Type != txType {
|
||||
return poolL2Tx, fmt.Errorf("type: %s, should be: %s", poolL2Tx.Type, txType)
|
||||
return poolL2Tx, tracerr.Wrap(fmt.Errorf("type: %s, should be: %s", poolL2Tx.Type, txType))
|
||||
}
|
||||
poolL2Tx.Type = txType
|
||||
|
||||
@@ -76,19 +77,19 @@ func NewPoolL2Tx(poolL2Tx *PoolL2Tx) (*PoolL2Tx, error) {
|
||||
txid[0] = TxIDPrefixL2Tx
|
||||
fromIdxBytes, err := poolL2Tx.FromIdx.Bytes()
|
||||
if err != nil {
|
||||
return poolL2Tx, err
|
||||
return poolL2Tx, tracerr.Wrap(err)
|
||||
}
|
||||
copy(txid[1:7], fromIdxBytes[:])
|
||||
nonceBytes, err := poolL2Tx.Nonce.Bytes()
|
||||
if err != nil {
|
||||
return poolL2Tx, err
|
||||
return poolL2Tx, tracerr.Wrap(err)
|
||||
}
|
||||
copy(txid[7:12], nonceBytes[:])
|
||||
txID := TxID(txid)
|
||||
|
||||
// if TxID!=poolL2Tx.TxID return error
|
||||
if poolL2Tx.TxID != (TxID{}) && poolL2Tx.TxID != txID {
|
||||
return poolL2Tx, fmt.Errorf("id: %s, should be: %s", poolL2Tx.TxID.String(), txID.String())
|
||||
return poolL2Tx, tracerr.Wrap(fmt.Errorf("id: %s, should be: %s", poolL2Tx.TxID.String(), txID.String()))
|
||||
}
|
||||
poolL2Tx.TxID = txID
|
||||
return poolL2Tx, nil
|
||||
@@ -109,12 +110,12 @@ func (tx *PoolL2Tx) TxCompressedData() (*big.Int, error) {
|
||||
// sigconstant
|
||||
sc, ok := new(big.Int).SetString("3322668559", 10)
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("error parsing SignatureConstant")
|
||||
return nil, tracerr.Wrap(fmt.Errorf("error parsing SignatureConstant"))
|
||||
}
|
||||
|
||||
amountFloat16, err := NewFloat16(tx.Amount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
var b [31]byte
|
||||
toBJJSign := byte(0)
|
||||
@@ -125,19 +126,19 @@ func (tx *PoolL2Tx) TxCompressedData() (*big.Int, error) {
|
||||
b[1] = byte(tx.Fee)
|
||||
nonceBytes, err := tx.Nonce.Bytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
copy(b[2:7], nonceBytes[:])
|
||||
copy(b[7:11], tx.TokenID.Bytes())
|
||||
copy(b[11:13], amountFloat16.Bytes())
|
||||
toIdxBytes, err := tx.ToIdx.Bytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
copy(b[13:19], toIdxBytes[:])
|
||||
fromIdxBytes, err := tx.FromIdx.Bytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
copy(b[19:25], fromIdxBytes[:])
|
||||
copy(b[25:27], []byte{0, 1}) // TODO this will be generated by the ChainID config parameter
|
||||
@@ -162,7 +163,7 @@ func (tx *PoolL2Tx) TxCompressedDataV2() (*big.Int, error) {
|
||||
}
|
||||
amountFloat16, err := NewFloat16(tx.Amount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
var b [25]byte
|
||||
toBJJSign := byte(0)
|
||||
@@ -173,19 +174,19 @@ func (tx *PoolL2Tx) TxCompressedDataV2() (*big.Int, error) {
|
||||
b[1] = byte(tx.Fee)
|
||||
nonceBytes, err := tx.Nonce.Bytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
copy(b[2:7], nonceBytes[:])
|
||||
copy(b[7:11], tx.TokenID.Bytes())
|
||||
copy(b[11:13], amountFloat16.Bytes())
|
||||
toIdxBytes, err := tx.ToIdx.Bytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
copy(b[13:19], toIdxBytes[:])
|
||||
fromIdxBytes, err := tx.FromIdx.Bytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
copy(b[19:25], fromIdxBytes[:])
|
||||
|
||||
@@ -213,7 +214,7 @@ func (tx *PoolL2Tx) RqTxCompressedDataV2() (*big.Int, error) {
|
||||
}
|
||||
amountFloat16, err := NewFloat16(tx.RqAmount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
var b [25]byte
|
||||
toBJJSign := byte(0)
|
||||
@@ -224,19 +225,19 @@ func (tx *PoolL2Tx) RqTxCompressedDataV2() (*big.Int, error) {
|
||||
b[1] = byte(tx.RqFee)
|
||||
nonceBytes, err := tx.RqNonce.Bytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
copy(b[2:7], nonceBytes[:])
|
||||
copy(b[7:11], tx.RqTokenID.Bytes())
|
||||
copy(b[11:13], amountFloat16.Bytes())
|
||||
toIdxBytes, err := tx.RqToIdx.Bytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
copy(b[13:19], toIdxBytes[:])
|
||||
fromIdxBytes, err := tx.RqFromIdx.Bytes()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
copy(b[19:25], fromIdxBytes[:])
|
||||
|
||||
@@ -248,7 +249,7 @@ func (tx *PoolL2Tx) RqTxCompressedDataV2() (*big.Int, error) {
|
||||
func (tx *PoolL2Tx) HashToSign() (*big.Int, error) {
|
||||
toCompressedData, err := tx.TxCompressedData()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
toEthAddr := EthAddrToBigInt(tx.ToEthAddr)
|
||||
rqToEthAddr := EthAddrToBigInt(tx.RqToEthAddr)
|
||||
@@ -258,7 +259,7 @@ func (tx *PoolL2Tx) HashToSign() (*big.Int, error) {
|
||||
}
|
||||
rqTxCompressedDataV2, err := tx.RqTxCompressedDataV2()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, tracerr.Wrap(err)
|
||||
}
|
||||
rqToBJJY := big.NewInt(0)
|
||||
if tx.RqToBJJ != nil {
|
||||
|
||||
Reference in New Issue
Block a user