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