You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.3 KiB

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