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.

36 lines
988 B

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