arnaucube
arnaucube/hermez-nodePublic Self-hosted repository
hermez-node/api/dbtoapistructs.go
api/dbtoapistructs.goRaw
 1package api
 2
 3import (
 4	"encoding/base64"
 5	"strconv"
 6
 7	ethCommon "github.com/ethereum/go-ethereum/common"
 8	"github.com/hermeznetwork/hermez-node/common"
 9	"github.com/iden3/go-iden3-crypto/babyjub"
10)
11
12const exitIdx = "hez:EXIT:1"
13
14type errorMsg struct {
15	Message string
16}
17
18func bjjToString(bjj *babyjub.PublicKey) string {
19	pkComp := [32]byte(bjj.Compress())
20	sum := pkComp[0]
21	for i := 1; i < len(pkComp); i++ {
22		sum += pkComp[i]
23	}
24	bjjSum := append(pkComp[:], sum)
25	return "hez:" + base64.RawURLEncoding.EncodeToString(bjjSum)
26}
27
28func ethAddrToHez(addr ethCommon.Address) string {
29	return "hez:" + addr.String()
30}
31
32func idxToHez(idx common.Idx, tokenSymbol string) string {
33	if idx == 1 {
34		return exitIdx
35	}
36	return "hez:" + tokenSymbol + ":" + strconv.Itoa(int(idx))
37}