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 `meddler:"token_id"`
14 EthBlockNum int64 `meddler:"eth_block_num"` // Ethereum block number in which this token was registered
15 EthAddr ethCommon.Address `meddler:"eth_addr"`
16 Name string `meddler:"name"`
17 Symbol string `meddler:"symbol"`
18 Decimals uint64 `meddler:"decimals"`
19 USD float32 `meddler:"usd,zeroisnull"`
20 USDUpdate time.Time `meddler:"usd_update,utctimez"`
21}
22
23// TokenInfo provides the price of the token in USD
24type TokenInfo struct {
25 TokenID uint32
26 Value float64
27 LastUpdated time.Time
28}
29
30// TokenID is the unique identifier of the token, as set in the smart contract
31type TokenID uint32 // current implementation supports up to 2^32 tokens
32
33// Bytes returns a byte array of length 4 representing the TokenID
34func (t TokenID) Bytes() []byte {
35 var tokenIDBytes [4]byte
36 binary.LittleEndian.PutUint32(tokenIDBytes[:], uint32(t))
37 return tokenIDBytes[:]
38}
39
40// BigInt returns the *big.Int representation of the TokenID
41func (t TokenID) BigInt() *big.Int {
42 return big.NewInt(int64(t))
43}