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