common

package
v0.1.46 Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2024 License: BSD-3-Clause Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNoTxGiven = errors.New("no transaction was given")

Functions

func BuildCredentialList

func BuildCredentialList(ins []*avax.TransferableInput, signatures []*types.Signature) ([]verify.Verifiable, error)

BuildCredentialList builds a list of *secp256k1fx.Credentials using the given signatures

Based on tx inputs, we can determine the number of signatures required by each input and put correct number of signatures to construct the signed tx.

See https://github.com/ava-labs/avalanchego/blob/v1.9.0/vms/platformvm/txs/tx.go#L104 for more details.

func BuildPayloads

BuildPayloads performs transaction construction in /construction/payloads call and returns the unsigned transaction as well as the signing payloads. Chain specific logic is abstracted using the TxBuilder interface's BuildTx method.

func BuildSingletonCredentialList

func BuildSingletonCredentialList(signatures []*types.Signature) ([]verify.Verifiable, error)

BuildSingletonCredentialList builds a list of a single *secp256k1fx.Credential using the given signatures

func Combine

func Combine(
	combiner TxCombiner,
	rosettaTx *RosettaTx,
	signatures []*types.Signature,
) (*types.ConstructionCombineResponse, *types.Error)

Combine combines unsigned transactions with the provided signatures as part of /construction/combine call. Chain spacific logic is abstracted in TxCombiner interface's CombineTx method.

func DeriveBech32Address

DeriveBech32Address derives Bech32 addresses for the given chain using public key and hrp provided in the request

func HashTx

HashTx generates a transaction id for the given RosettaTx

func MatchOperations

func MatchOperations(operations []*types.Operation) ([]*parser.Match, error)

MatchOperations defines the operation Rosetta parser matching rules and parses the input operations

We require 2 types of operations; inputs with negative amounts and outputs with positive amounts parser guarantees there will be 2 matches.

func Parse

func Parse(parser TxParser, payloadsTx *RosettaTx, isSigned bool) (*types.ConstructionParseResponse, *types.Error)

Parse contains transaction parsing logic for /construction/parse endpoint Chain specific logic is abstracted using TxParser interface's ParseTx method

func SortUnique

func SortUnique(coins []*types.Coin) []*types.Coin

SortUnique deduplicates given slice of coins and sorts them by UTXO id in ascending order for consistency

Per https://docs.avax.network/apis/avalanchego/apis/p-chain#platformgetutxos and https://docs.avax.network/apis/avalanchego/apis/c-chain#avaxgetutxos paginated getUTXOs calls may have duplicate UTXOs in different pages, this helper eliminates them.

func SubmitTx

func SubmitTx(
	ctx context.Context,
	issuer TransactionIssuer,
	rosettaTx *RosettaTx,
) (*types.TransactionIdentifierResponse, *types.Error)

SubmitTx broadcasts given Rosetta tx on chain and returns the transaction id. Chain specific logic is abstracted using the TransactionIssuer interface's IssueTx method.

Types

type AvaxTx

type AvaxTx interface {
	Initialize() error
	Marshal() ([]byte, error)
	Unmarshal([]byte) error
	SigningPayload() []byte
	Hash() ids.ID
}

AvaxTx encapsulates P-chain and C-chain atomic transactions in order to reuse common logic between them

type RosettaTx

type RosettaTx struct {
	Tx                       AvaxTx
	AccountIdentifierSigners []Signer
	DestinationChain         string
	DestinationChainID       *ids.ID
}

RosettaTx wraps a transaction along with the input addresses and destination chain information. It is used during construction between /construction/payloads and /construction/parse since parse needs this information but C-chain atomic and P-chain tx formats strip this information and only retain UTXO ids.

func (*RosettaTx) GetAccountIdentifiers

func (t *RosettaTx) GetAccountIdentifiers(operations []*types.Operation) ([]*types.AccountIdentifier, error)

GetAccountIdentifiers extracts input account identifiers from given Rosetta operations

func (*RosettaTx) MarshalJSON

func (t *RosettaTx) MarshalJSON() ([]byte, error)

func (*RosettaTx) UnmarshalJSON

func (t *RosettaTx) UnmarshalJSON(data []byte) error

type Signer

type Signer struct {
	CoinIdentifier    string                   `json:"coin_identifier,omitempty"`
	AccountIdentifier *types.AccountIdentifier `json:"account_identifier"`
}

Signer contains details of coin identifiers and the accounts signing those coins

type TransactionIssuer

type TransactionIssuer interface {
	IssueTx(ctx context.Context, txByte []byte, options ...rpc.Option) (ids.ID, error)
}

TransactionIssuer implements chain specific transaction submission logic

type TxBuilder

type TxBuilder interface {
	BuildTx(matches []*types.Operation, rawMetadata map[string]interface{}) (AvaxTx, []*types.AccountIdentifier, *types.Error)
}

TxBuilder implements backend specific transaction construction logic

type TxCombiner

type TxCombiner interface {
	CombineTx(tx AvaxTx, signatures []*types.Signature) (AvaxTx, *types.Error)
}

TxCombiner implements backend specific transaction submission logic

type TxParser

type TxParser interface {
	ParseTx(tx *RosettaTx, inputAddresses map[string]*types.AccountIdentifier) ([]*types.Operation, error)
}

TxParser implements backend specific transaction parsing logic

Jump to

Keyboard shortcuts

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