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