hermez-node/common/token.go
common/token.goRaw
1package common
2
3import (
4 "encoding/binary"
5 "math/big"
6 "time"
7
8 ethCommon "github.com/ethereum/go-ethereum/common"
9)
10
11// Token is a struct that represents an Ethereum token that is supported in Hermez network
12type Token struct {
13 TokenID TokenID
14 EthAddr ethCommon.Address
15 Name string
16 Symbol string
17 Decimals uint64
18 EthTxHash ethCommon.Hash // Ethereum TxHash in which this token was registered
19 EthBlockNum uint64 // Ethereum block number in which this token was registered
20}
21
22// TokenInfo provides the price of the token in USD
23type TokenInfo struct {
24 TokenID uint32
25 Value float64
26 LastUpdated time.Time
27}
28
29// TokenID is the unique identifier of the token, as set in the smart contract
30type TokenID uint32 // current implementation supports up to 2^32 tokens
31
32// Bytes returns a byte array of length 4 representing the TokenID
33func (t TokenID) Bytes() []byte {
34 var tokenIDBytes [4]byte
35 binary.LittleEndian.PutUint32(tokenIDBytes[:], uint32(t))
36 return tokenIDBytes[:]
37}
38
39// BigInt returns the *big.Int representation of the TokenID
40func (t TokenID) BigInt() *big.Int {
41 return big.NewInt(int64(t))
42}