apitypes

package
v2.0.0-rc3 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2021 License: AGPL-3.0 Imports: 12 Imported by: 0

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/arnaubennassar/hermez-node/v2/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

Jump to

Keyboard shortcuts

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