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.

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