apitypes

package
v1.8.0-rc2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 8, 2021 License: AGPL-3.0 Imports: 15 Imported by: 1

Documentation

Overview

Package apitypes is used to map the common types used across the node with the format expected by the API.

This is done using different strategies: - Marshallers: they get triggered when the API marshals the response structs into JSONs - Scanners/Valuers: they get triggered when a struct is sent/received to/from the SQL database - Adhoc functions: when the already mentioned strategies are not suitable, functions are added to the structs to facilitate the conversions

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BigIntStr

type BigIntStr string

BigIntStr is used to scan/value *big.Int directly into strings from/to sql DBs. It assumes that *big.Int are inserted/fetched to/from the DB using the BigIntMeddler meddler defined at github.com/hermeznetwork/hermez-node/db. Since *big.Int is stored as DECIMAL in SQL, there's no need to implement Scan()/Value() because DECIMALS are encoded/decoded as strings by the sql driver, and BigIntStr is already a string.

func NewBigIntStr

func NewBigIntStr(bigInt *big.Int) *BigIntStr

NewBigIntStr creates a *BigIntStr from a *big.Int. If the provided bigInt is nil the returned *BigIntStr will also be nil

type CollectedFeesAPI

type CollectedFeesAPI map[common.TokenID]BigIntStr

CollectedFeesAPI is send common.batch.CollectedFee through the API

func NewCollectedFeesAPI

func NewCollectedFeesAPI(m map[common.TokenID]*big.Int) CollectedFeesAPI

NewCollectedFeesAPI creates a new CollectedFeesAPI from a *big.Int map

type EthSignature

type EthSignature string

EthSignature is used to scan/value []byte representing an Ethereum signature directly into strings from/to sql DBs.

func NewEthSignature

func NewEthSignature(signature []byte) *EthSignature

NewEthSignature creates a *EthSignature from []byte If the provided signature is nil the returned *EthSignature will also be nil

func (*EthSignature) Scan

func (e *EthSignature) Scan(src interface{}) error

Scan implements Scanner for database/sql

func (*EthSignature) UnmarshalText

func (e *EthSignature) UnmarshalText(text []byte) error

UnmarshalText unmarshals a StrEthSignature

func (EthSignature) Value

func (e EthSignature) Value() (driver.Value, error)

Value implements valuer for database/sql

type HezBJJ

type HezBJJ string

HezBJJ is used to scan/value *babyjub.PublicKeyComp directly into strings that follow the BJJ public key hez format (^hez:[A-Za-z0-9_-]{44}$) from/to sql DBs. It assumes that *babyjub.PublicKeyComp are inserted/fetched to/from the DB using the default Scan/Value interface

func NewHezBJJ

func NewHezBJJ(pkComp babyjub.PublicKeyComp) HezBJJ

NewHezBJJ creates a HezBJJ from a *babyjub.PublicKeyComp. Calling this method with a nil bjj causes panic

func (*HezBJJ) Scan

func (b *HezBJJ) Scan(src interface{}) error

Scan implements Scanner for database/sql

func (HezBJJ) ToBJJ

func (b HezBJJ) ToBJJ() (babyjub.PublicKeyComp, error)

ToBJJ returns a babyjub.PublicKeyComp created from HezBJJ

func (HezBJJ) Value

func (b HezBJJ) Value() (driver.Value, error)

Value implements valuer for database/sql

type HezEthAddr

type HezEthAddr string

HezEthAddr is used to scan/value Ethereum Address directly into strings that follow the Ethereum address hez format (^hez:0x[a-fA-F0-9]{40}$) from/to sql DBs. It assumes that Ethereum Address are inserted/fetched to/from the DB using the default Scan/Value interface

func NewHezEthAddr

func NewHezEthAddr(addr ethCommon.Address) HezEthAddr

NewHezEthAddr creates a HezEthAddr from an Ethereum addr

func (*HezEthAddr) Scan

func (a *HezEthAddr) Scan(src interface{}) error

Scan implements Scanner for database/sql

func (HezEthAddr) ToEthAddr

func (a HezEthAddr) ToEthAddr() (ethCommon.Address, error)

ToEthAddr returns an Ethereum Address created from HezEthAddr

func (HezEthAddr) Value

func (a HezEthAddr) Value() (driver.Value, error)

Value implements valuer for database/sql

type HezIdx

type HezIdx string

HezIdx is used to value common.Idx directly into strings that follow the Idx key hez format (hez:tokenSymbol:idx) to sql DBs. Note that this can only be used to insert to DB since there is no way to automatically read from the DB since it needs the tokenSymbol

type StrBigInt

type StrBigInt big.Int

StrBigInt is used to unmarshal BigIntStr directly into an alias of big.Int

func (*StrBigInt) UnmarshalText

func (s *StrBigInt) UnmarshalText(text []byte) error

UnmarshalText unmarshals a StrBigInt

type StrHezBJJ

type StrHezBJJ babyjub.PublicKeyComp

StrHezBJJ is used to unmarshal HezBJJ directly into an alias of babyjub.PublicKeyComp

func (*StrHezBJJ) UnmarshalText

func (s *StrHezBJJ) UnmarshalText(text []byte) error

UnmarshalText unmarshalls a StrHezBJJ

type StrHezEthAddr

type StrHezEthAddr ethCommon.Address

StrHezEthAddr is used to unmarshal HezEthAddr directly into an alias of ethCommon.Address

func (*StrHezEthAddr) UnmarshalText

func (s *StrHezEthAddr) UnmarshalText(text []byte) error

UnmarshalText unmarshals a StrHezEthAddr

type StrHezIdx

type StrHezIdx common.Idx

StrHezIdx is used to unmarshal HezIdx directly into an alias of common.Idx

func (*StrHezIdx) UnmarshalText

func (s *StrHezIdx) UnmarshalText(text []byte) error

UnmarshalText unmarshals a StrHezIdx

type TxL2

type TxL2 struct {
	ItemID               uint64                `json:"itemId"`
	TxID                 common.TxID           `json:"id"`
	Type                 common.TxType         `json:"type"`
	FromIdx              HezIdx                `json:"fromAccountIndex"`
	EffectiveFromEthAddr *HezEthAddr           `json:"fromHezEthereumAddress"`
	EffectiveFromBJJ     *HezBJJ               `json:"fromBJJ"`
	ToIdx                *HezIdx               `json:"toAccountIndex"`
	EffectiveToEthAddr   *HezEthAddr           `json:"toHezEthereumAddress"`
	EffectiveToBJJ       *HezBJJ               `json:"toBJJ"`
	Amount               BigIntStr             `json:"amount"`
	Fee                  common.FeeSelector    `json:"fee"`
	Nonce                nonce.Nonce           `json:"nonce"`
	State                common.PoolL2TxState  `json:"state"`
	BatchNum             *common.BatchNum      `json:"batchNum"`
	MaxNumBatch          uint32                `json:"maxNumBatch"`
	Info                 *string               `json:"info"`
	ErrorCode            *int                  `json:"errorCode"`
	ErrorType            *string               `json:"errorType"`
	Signature            babyjub.SignatureComp `json:"signature"`
	Timestamp            time.Time             `json:"timestamp"`
	RqFromIdx            *HezIdx               `json:"requestFromAccountIndex"`
	RqToIdx              *HezIdx               `json:"requestToAccountIndex"`
	RqToEthAddr          *HezEthAddr           `json:"requestToHezEthereumAddress"`
	RqToBJJ              *HezBJJ               `json:"requestToBJJ"`
	RqTokenID            *common.TokenID       `json:"requestTokenId"`
	RqAmount             *BigIntStr            `json:"requestAmount"`
	RqFee                *common.FeeSelector   `json:"requestFee"`
	RqNonce              *nonce.Nonce          `json:"requestNonce"`
	Token                token                 `json:"token"`
}

TxL2 represents a L2 Tx pool with extra metadata used by the API

func (TxL2) MarshalJSON

func (tx TxL2) MarshalJSON() ([]byte, error)

MarshalJSON is used to convert TxL2 in JSON

func (*TxL2) UnmarshalJSON

func (tx *TxL2) UnmarshalJSON(data []byte) error

UnmarshalJSON is used to create a TxL2 from JSON data

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL