client

package
v0.0.0-...-7f300a8 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2021 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	ItemID    uint64              `json:"itemId"`
	Idx       StrHezIdx           `json:"accountIndex"`
	BatchNum  hezCommon.BatchNum  `json:"batch_num"`
	PublicKey apitypes.HezBJJ     `json:"bjj"`
	EthAddr   apitypes.HezEthAddr `json:"hezEthereumAddress"`
	Nonce     hezCommon.Nonce     `json:"nonce"`
	Balance   *BigInt             `json:"balance"`
	Token     hezCommon.Token     `json:"token"`
}

Account is a representation of a account with additional information required by the API

type AccountAPI

type AccountAPI struct {
	Accounts     Accounts `json:"accounts"`
	PendingItems uint64   `json:"pendingItems"`
}

AccountAPI is a representation of a account API response.

type AccountAuth

type AccountAuth struct {
	EthAddr   string `json:"hezEthereumAddress"`
	Bjj       string `json:"bjj"`
	Signature string `json:"signature"`
}

AccountAuth is a representation of a account authentication API request.

type AccountAuthAPI

type AccountAuthAPI struct {
	EthAddr   string                `json:"hezEthereumAddress"`
	Bjj       string                `json:"bjj"`
	Signature apitypes.EthSignature `json:"signature"`
	Timestamp time.Time             `json:"timestamp"`
	Message   string                `json:"Message"`
}

AccountAuthAPI is a representation of a account authentication API response.

type Accounts

type Accounts []Account

Accounts is a representation of a account list.

func (*Accounts) GetFirstAccount

func (acs *Accounts) GetFirstAccount(tokenID hezCommon.TokenID) (Account, error)

GetFirstAccount get the first account by token ID

type Batch

type Batch struct {
	ItemID        uint64             `json:"itemId"`
	BatchNum      hezCommon.BatchNum `json:"batchNum"`
	EthBlockNum   int64              `json:"ethereumBlockNum"`
	EthBlockHash  ethCommon.Hash     `json:"ethereumBlockHash"`
	Timestamp     time.Time          `json:"timestamp"`
	ForgerAddr    ethCommon.Address  `json:"forgerAddr"`
	CollectedFees CollectedFees      `json:"collectedFees"`
	TotalFeesUSD  *float64           `json:"historicTotalCollectedFeesUSD"`
	StateRoot     apitypes.BigIntStr `json:"stateRoot"`
	NumAccounts   int                `json:"numAccounts"`
	ExitRoot      apitypes.BigIntStr `json:"exitRoot"`
	ForgeL1TxsNum *int64             `json:"forgeL1TransactionsNum"`
	SlotNum       int64              `json:"slotNum"`
	ForgedTxs     int                `json:"forgedTransactions"`
}

Batch is a representation of a batch with additional information required by the API, and extracted by joining block table

type BatchAPI

type BatchAPI struct {
	Batches      []Batch `json:"batches"`
	PendingItems uint64  `json:"pendingItems"`
}

BatchAPI is a representation of a batches API response.

type BigInt

type BigInt struct {
	big.Int
}

BigInt is big.Int wrapper

func (*BigInt) UnmarshalJSON

func (i *BigInt) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshal BitInt object

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents the node API client object https://docs.hermez.io/#/developers/api

func New

func New(nodeURL string) *Client

New creates a new node API client

func (*Client) AccountAuth

func (c *Client) AccountAuth(ethAddr string) (*AccountAuthAPI, error)

AccountAuth get the account authentication from the node.

func (*Client) AccountCreationAuth

func (c *Client) AccountCreationAuth(ethAddr, bjj, signature string) error

AccountCreationAuth create an account authentication into the node.

func (*Client) GetAccount

func (c *Client) GetAccount(bjjAddress, hezEthAddress *string, tokenID hezCommon.TokenID) (*AccountAPI, error)

GetAccount get an account info based in the hermez-integration address and the token id

func (*Client) GetBatchTxs

func (c *Client) GetBatchTxs(batchNum hezCommon.BatchNum) (*TxAPI, error)

GetBatchTxs get all transactions history from a batch number

func (*Client) GetLastBatch

func (c *Client) GetLastBatch() (*Batch, error)

GetLastBatch get last Hermez rollup batch

func (*Client) GetPoolTx

func (c *Client) GetPoolTx(txID string) (*TxHistory, error)

GetPoolTx get a pool transaction by tx ID

func (*Client) GetTokens

func (c *Client) GetTokens() (*TokenAPI, error)

GetTokens get all supported tokens

func (*Client) GetTx

func (c *Client) GetTx(txID string) (*TxHistory, error)

GetTx get a transaction by tx ID

func (*Client) SendTransaction

func (c *Client) SendTransaction(tx hezCommon.PoolL2Tx, token hezCommon.Token) (string, error)

SendTransaction send L2 transaction to the coordinator pool

type CollectedFees

type CollectedFees map[hezCommon.TokenID]BigInt

CollectedFees is used to retrieve common.batch.CollectedFee from the DB

type CreateAccountAuthAPI

type CreateAccountAuthAPI struct {
	Message string `json:"Message"`
}

CreateAccountAuthAPI is a representation of a account authentication API response.

type StrHezIdx

type StrHezIdx hezCommon.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 unmarshal a StrHezIdx

type Token

type Token struct {
	ItemID      uint64            `json:"itemId"`
	TokenID     hezCommon.TokenID `json:"id"`
	EthBlockNum int64             `json:"ethereumBlockNum"`
	EthAddr     ethCommon.Address `json:"ethereumAddress"`
	Name        string            `json:"name"`
	Symbol      string            `json:"symbol"`
	Decimals    uint64            `json:"decimals"`
	USD         float64           `json:"USD"`
	USDUpdate   time.Time         `json:"fiatUpdate"`
}

Token is a representation of a tokens API object.

type TokenAPI

type TokenAPI struct {
	Tokens       Tokens `json:"tokens"`
	PendingItems uint64 `json:"pendingItems"`
}

TokenAPI is a representation of a tokens API response.

type Tokens

type Tokens []hezCommon.Token

Tokens is a representation of a list of tokens.

func (*Tokens) GetToken

func (ts *Tokens) GetToken(symbol string) (hezCommon.Token, error)

GetToken get a token by symbol

type Tx

type Tx struct {
	TxID      hezCommon.TxID `json:"id" binding:"required"`
	Type      string         `json:"type"`
	TokenID   uint32         `json:"tokenId"`
	FromIdx   string         `json:"fromAccountIndex" binding:"required"`
	ToIdx     string         `json:"toAccountIndex"`
	ToEthAddr string         `json:"toHezEthereumAddress"`
	ToBJJ     string         `json:"toBjj"`
	Amount    string         `json:"amount" binding:"required"`
	Fee       uint64         `json:"fee"`
	Nonce     uint64         `json:"nonce"`
	Signature string         `json:"signature"`
}

Tx is a representation of a transaction API request.

func NewTxRequest

func NewTxRequest(poolTx hezCommon.PoolL2Tx, token hezCommon.Token) *Tx

NewTxRequest convert L2 tx to API request model

type TxAPI

type TxAPI struct {
	Txs          []TxHistory `json:"transactions"`
	PendingItems uint64      `json:"pendingItems"`
}

TxAPI is a representation of a tx history API response.

type TxHistory

type TxHistory struct {
	Amount           apitypes.BigIntStr      `json:"amount"`
	Fee              hezCommon.FeeSelector   `json:"fee"`
	FromIdx          StrHezIdx               `json:"fromAccountIndex"`
	FromEthAddr      apitypes.HezEthAddr     `json:"fromHezEthereumAddress"`
	FromBJJ          apitypes.HezBJJ         `json:"fromBJJ"`
	TxID             hezCommon.TxID          `json:"id"`
	BatchNum         hezCommon.BatchNum      `json:"batchNum"`
	L1orL2           string                  `json:"L1orL2"`
	L1Info           interface{}             `json:"L1Info"`
	L2Info           interface{}             `json:"L2Info"`
	Nonce            hezCommon.Nonce         `json:"nonce"`
	RequestAmount    apitypes.BigIntStr      `json:"requestAmount"`
	RequestFee       hezCommon.FeeSelector   `json:"requestFee"`
	RequestFromIdx   StrHezIdx               `json:"requestFromAccountIndex"`
	RequestNonce     hezCommon.Nonce         `json:"requestNonce"`
	RequestToIdx     hezCommon.Idx           `json:"requestToAccountIndex"`
	RequestToBJJ     babyjub.PublicKeyComp   `json:"requestToBJJ"`
	RequestToEthAddr ethCommon.Address       `json:"requestToHezEthereumAddress"`
	RequestTokenID   hezCommon.TokenID       `json:"requestTokenId"`
	Signature        string                  `json:"signature"`
	State            hezCommon.PoolL2TxState `json:"state"`
	Timestamp        time.Time               `json:"timestamp"`
	ToIdx            StrHezIdx               `json:"toAccountIndex"`
	ToEthAddr        apitypes.HezEthAddr     `json:"toHezEthereumAddress"`
	ToBJJ            apitypes.HezBJJ         `json:"toBjj"`
	Token            hezCommon.Token         `json:"token"`
	Type             hezCommon.TxType        `json:"type"`
}

TxHistory is a representation of a transaction history API request.

Jump to

Keyboard shortcuts

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