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.

64 lines
2.1 KiB

  1. package api
  2. import (
  3. "encoding/base64"
  4. "math/big"
  5. "strconv"
  6. ethCommon "github.com/ethereum/go-ethereum/common"
  7. "github.com/hermeznetwork/hermez-node/common"
  8. "github.com/iden3/go-iden3-crypto/babyjub"
  9. )
  10. const exitIdx = "hez:EXIT:1"
  11. type errorMsg struct {
  12. Message string
  13. }
  14. func bjjToString(bjj *babyjub.PublicKey) string {
  15. pkComp := [32]byte(bjj.Compress())
  16. sum := pkComp[0]
  17. for i := 1; i < len(pkComp); i++ {
  18. sum += pkComp[i]
  19. }
  20. bjjSum := append(pkComp[:], sum)
  21. return "hez:" + base64.RawURLEncoding.EncodeToString(bjjSum)
  22. }
  23. func ethAddrToHez(addr ethCommon.Address) string {
  24. return "hez:" + addr.String()
  25. }
  26. func idxToHez(idx common.Idx, tokenSymbol string) string {
  27. if idx == 1 {
  28. return exitIdx
  29. }
  30. return "hez:" + tokenSymbol + ":" + strconv.Itoa(int(idx))
  31. }
  32. // Config
  33. type rollupConstants struct {
  34. PublicConstants common.RollupConstants `json:"publicConstants"`
  35. MaxFeeIdxCoordinator int `json:"maxFeeIdxCoordinator"`
  36. ReservedIdx int `json:"reservedIdx"`
  37. ExitIdx int `json:"exitIdx"`
  38. LimitLoadAmount *big.Int `json:"limitLoadAmount"`
  39. LimitL2TransferAmount *big.Int `json:"limitL2TransferAmount"`
  40. LimitTokens int `json:"limitTokens"`
  41. L1CoordinatorTotalBytes int `json:"l1CoordinatorTotalBytes"`
  42. L1UserTotalBytes int `json:"l1UserTotalBytes"`
  43. MaxL1UserTx int `json:"maxL1UserTx"`
  44. MaxL1Tx int `json:"maxL1Tx"`
  45. InputSHAConstantBytes int `json:"inputSHAConstantBytes"`
  46. NumBuckets int `json:"numBuckets"`
  47. MaxWithdrawalDelay int `json:"maxWithdrawalDelay"`
  48. ExchangeMultiplier int `json:"exchangeMultiplier"`
  49. }
  50. type configAPI struct {
  51. RollupConstants rollupConstants `json:"hermez"`
  52. AuctionConstants common.AuctionConstants `json:"auction"`
  53. WDelayerConstants common.WDelayerConstants `json:"withdrawalDelayer"`
  54. }