mirror of
https://github.com/arnaucube/hermez-node.git
synced 2026-02-07 19:36:44 +01:00
Update common.L1Tx parsers, add test checks
This commit is contained in:
@@ -2,12 +2,16 @@ package common
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"math/big"
|
||||
"time"
|
||||
|
||||
ethCommon "github.com/ethereum/go-ethereum/common"
|
||||
)
|
||||
|
||||
// tokenIDBytesLen defines the length of the TokenID byte array representation
|
||||
const tokenIDBytesLen = 4
|
||||
|
||||
// Token is a struct that represents an Ethereum token that is supported in Hermez network
|
||||
type Token struct {
|
||||
TokenID TokenID `meddler:"token_id"`
|
||||
@@ -41,3 +45,12 @@ func (t TokenID) Bytes() []byte {
|
||||
func (t TokenID) BigInt() *big.Int {
|
||||
return big.NewInt(int64(t))
|
||||
}
|
||||
|
||||
// TokenIDFromBytes returns TokenID from a byte array
|
||||
func TokenIDFromBytes(b []byte) (TokenID, error) {
|
||||
if len(b) != tokenIDBytesLen {
|
||||
return 0, fmt.Errorf("can not parse TokenID, bytes len %d, expected 4", len(b))
|
||||
}
|
||||
tid := binary.LittleEndian.Uint32(b[:4])
|
||||
return TokenID(tid), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user