transaction

package
v0.1.8 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2021 License: Apache-2.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AmountToFloat40 added in v0.1.5

func AmountToFloat40(amount *big.Int) (*big.Int, error)

func AtomicTransfer added in v0.1.3

func AtomicTransfer(hezClient client.HermezClient, txs []AtomicTxItem) (serverResponse string, atomicGroupID hezCommon.AtomicGroupID, err error)

AtomicTransfer creates PoolL2Txs using basic information provided in the AtomicTxItems, set metadata and fields based on the current state. Also links the txs setting the Rq* fields and sign txs. After performs token or ETH transfers in a pool of transactions.

func AtomicTransferJSON added in v0.1.4

func AtomicTransferJSON(hezClient client.HermezClient, txsJSON []string) (serverResponse string, atomicGroupID hezCommon.AtomicGroupID, err error)

AtomicTransferJSON receives an array of AtomicTxItems in JSON format, create PoolL2Txs, atomic group, sign and post

func BjjToString

func BjjToString(bjj babyjub.PublicKeyComp) string

BjjToString convert the BJJ public key to string

func CreateFullTxs added in v0.1.4

func CreateFullTxs(hezClient client.HermezClient, txs []AtomicTxItem) (fullTxs []hezCommon.PoolL2Tx, err error)

CreateFullTxs turn the basic information in a PoolL2Tx, set metadata and fields based on the current state. Also links the txs setting the Rq* fields.

func IdxToHez

func IdxToHez(idx hezCommon.Idx, tokenSymbol string) string

IdxToHez convert idx to hez idx

func SendAtomicTxsGroup added in v0.1.4

func SendAtomicTxsGroup(hezClient client.HermezClient, atomicTxs hezCommon.AtomicGroup) (serverResponse string, err error)

SendAtomicTxsGroup submits Atomic transaction to the current coordinator endpoint

func SetAtomicGroupID added in v0.1.4

func SetAtomicGroupID(atomicGroup hezCommon.AtomicGroup) hezCommon.AtomicGroup

SetAtomicGroupID defines the AtomicGroup ID and propagate to txs

Types

type APITx

type APITx 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"`
}

APITx is a representation of a transaction API request.

func ExecuteL2Transaction

func ExecuteL2Transaction(hezClient client.HermezClient, apiTx APITx) (apiTxReturn APITx, serverResponse string, err error)

ExecuteL2Transaction submits L2 transaction to the current coordinator endpoint

func L2Transfer

func L2Transfer(hezClient client.HermezClient,
	senderBjjWallet account.BJJWallet,
	receiverAddress string,
	tokenSymbolToTransfer string,
	amount *big.Int,
	feeRangeSelectedID int) (apiTxReturn APITx, serverResponse string, err error)

L2Transfer perform token or ETH transfer within Hermez network (we say L2 or Layer2)

func MarshalTransaction

func MarshalTransaction(itemToTransfer string,
	senderAcctDetails account.AccountAPIResponse,
	receiverAcctDetails account.AccountAPIResponse,
	senderBjjWallet account.BJJWallet,
	amount *big.Int,
	feeSelector int,
	ethereumChainID int) (apiTxRequest APITx, err error)

MarshalTransaction marshal transaction information into a Hermez transaction API request

func NewHermezAPITxRequest

func NewHermezAPITxRequest(poolTx *hezCommon.PoolL2Tx, token hezCommon.Token) APITx

NewHermezAPITxRequest convert L2 tx to Hermez API request model

func NewSignedAPITxToEthAddr added in v0.1.5

func NewSignedAPITxToEthAddr(chainID int, fromBjjWallet account.BJJWallet, fromIdx uint64, toEthAddress string, amount *big.Int, feeSelector hezCommon.FeeSelector, token hezCommon.Token, nonce int) (APITx, error)

NewSignedAPITxToEthAddr creates and signs a new APITx to transfer to eth addr

func SignAPITx added in v0.1.5

func SignAPITx(chainID int, fromBjjWallet account.BJJWallet, token hezCommon.Token, tx *hezCommon.PoolL2Tx) (APITx, error)

type AtomicTxItem added in v0.1.3

type AtomicTxItem struct {
	SenderBjjWallet       account.BJJWallet
	ReceiverAddress       string
	TokenSymbolToTransfer string
	Amount                *big.Int
	FeeRangeSelectedID    int
	RqOffSet              int
}

type PoolTxAPI added in v0.1.4

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

func GetTransactionPool added in v0.1.8

func GetTransactionPool(hezClient client.HermezClient, txID hezCommon.TxID) (transaction PoolTxAPI, err error)

GetTransactionInPool connects to the hezClient.CurrentCoordinatorURL and pull a single transaction from the pool based on it's ID

type TransactionsAPIResponse added in v0.1.4

type TransactionsAPIResponse struct {
	Transactions []PoolTxAPI `json:"transactions"`
}

func GetTransactionsInPool added in v0.1.4

func GetTransactionsInPool(hezClient client.HermezClient) (transactions TransactionsAPIResponse, err error)

GetTransactionsInPool connects to a hermez node and pull all transactions in the pool

type TxReceiverMetadata added in v0.1.5

type TxReceiverMetadata struct {
	ToEthAddr   string `json:"to_eth_addr"`
	FeeSelector uint   `json:"fee_selector"`
	Amount      string `json:"amount"`
}

Jump to

Keyboard shortcuts

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