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.

42 lines
1.1 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
  11. EthAddr ethCommon.Address
  12. Name string
  13. Symbol string
  14. Decimals uint64
  15. EthTxHash ethCommon.Hash // Ethereum TxHash in which this token was registered
  16. EthBlockNum uint64 // Ethereum block number in which this token was registered
  17. }
  18. // TokenInfo provides the price of the token in USD
  19. type TokenInfo struct {
  20. TokenID uint32
  21. Value float64
  22. LastUpdated time.Time
  23. }
  24. // TokenID is the unique identifier of the token, as set in the smart contract
  25. type TokenID uint32 // current implementation supports up to 2^32 tokens
  26. // Bytes returns a byte array of length 4 representing the TokenID
  27. func (t TokenID) Bytes() []byte {
  28. var tokenIDBytes [4]byte
  29. binary.LittleEndian.PutUint32(tokenIDBytes[:], uint32(t))
  30. return tokenIDBytes[:]
  31. }
  32. // BigInt returns the *big.Int representation of the TokenID
  33. func (t TokenID) BigInt() *big.Int {
  34. return big.NewInt(int64(t))
  35. }