c

package
v1.10.11-rc.1 Latest Latest
Warning

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

Go to latest
Published: Sep 22, 2023 License: BSD-3-Clause Imports: 23 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Account

type Account struct {
	Balance *big.Int
	Nonce   uint64
}

type Backend

type Backend interface {
	common.ChainUTXOs
	BuilderBackend
	SignerBackend

	AcceptAtomicTx(ctx stdcontext.Context, tx *evm.Tx) error
}

Backend defines the full interface required to support a C-chain wallet.

func NewBackend

func NewBackend(
	ctx Context,
	utxos common.ChainUTXOs,
	accounts map[ethcommon.Address]*Account,
) Backend

type Builder

type Builder interface {
	// GetBalance calculates the amount of AVAX that this builder has control
	// over.
	GetBalance(
		options ...common.Option,
	) (*big.Int, error)

	// GetImportableBalance calculates the amount of AVAX that this builder
	// could import from the provided chain.
	//
	// - [chainID] specifies the chain the funds are from.
	GetImportableBalance(
		chainID ids.ID,
		options ...common.Option,
	) (uint64, error)

	// NewImportTx creates an import transaction that attempts to consume all
	// the available UTXOs and import the funds to [to].
	//
	// - [chainID] specifies the chain to be importing funds from.
	// - [to] specifies where to send the imported funds to.
	// - [baseFee] specifies the fee price willing to be paid by this tx.
	NewImportTx(
		chainID ids.ID,
		to ethcommon.Address,
		baseFee *big.Int,
		options ...common.Option,
	) (*evm.UnsignedImportTx, error)

	// NewExportTx creates an export transaction that attempts to send all the
	// provided [outputs] to the requested [chainID].
	//
	// - [chainID] specifies the chain to be exporting the funds to.
	// - [outputs] specifies the outputs to send to the [chainID].
	// - [baseFee] specifies the fee price willing to be paid by this tx.
	NewExportTx(
		chainID ids.ID,
		outputs []*secp256k1fx.TransferOutput,
		baseFee *big.Int,
		options ...common.Option,
	) (*evm.UnsignedExportTx, error)
}

Builder provides a convenient interface for building unsigned C-chain transactions.

func NewBuilder

func NewBuilder(
	avaxAddrs set.Set[ids.ShortID],
	ethAddrs set.Set[ethcommon.Address],
	backend BuilderBackend,
) Builder

NewBuilder returns a new transaction builder.

  • [avaxAddrs] is the set of addresses in the AVAX format that the builder assumes can be used when signing the transactions in the future.
  • [ethAddrs] is the set of addresses in the Eth format that the builder assumes can be used when signing the transactions in the future.
  • [backend] provides the required access to the chain's context and state to build out the transactions.

func NewBuilderWithOptions

func NewBuilderWithOptions(builder Builder, options ...common.Option) Builder

NewBuilderWithOptions returns a new transaction builder that will use the given options by default.

  • [builder] is the builder that will be called to perform the underlying operations.
  • [options] will be provided to the builder in addition to the options provided in the method calls.

type BuilderBackend

type BuilderBackend interface {
	Context

	UTXOs(ctx stdcontext.Context, sourceChainID ids.ID) ([]*avax.UTXO, error)
	Balance(ctx stdcontext.Context, addr ethcommon.Address) (*big.Int, error)
	Nonce(ctx stdcontext.Context, addr ethcommon.Address) (uint64, error)
}

BuilderBackend specifies the required information needed to build unsigned C-chain transactions.

type Context

type Context interface {
	NetworkID() uint32
	BlockchainID() ids.ID
	AVAXAssetID() ids.ID
}

func NewContext

func NewContext(
	networkID uint32,
	blockchainID ids.ID,
	avaxAssetID ids.ID,
) Context

func NewContextFromClients

func NewContextFromClients(
	ctx stdcontext.Context,
	infoClient info.Client,
	xChainClient avm.Client,
) (Context, error)

func NewContextFromURI

func NewContextFromURI(ctx stdcontext.Context, uri string) (Context, error)

type EthKeychain

type EthKeychain interface {
	// The returned Signer can provide a signature for [addr]
	GetEth(addr ethcommon.Address) (keychain.Signer, bool)
	// Returns the set of addresses for which the accessor keeps an associated
	// signer
	EthAddresses() set.Set[ethcommon.Address]
}

type Signer

type Signer interface {
	SignUnsignedAtomic(ctx stdcontext.Context, tx evm.UnsignedAtomicTx) (*evm.Tx, error)
	SignAtomic(ctx stdcontext.Context, tx *evm.Tx) error
}

func NewSigner

func NewSigner(avaxKC keychain.Keychain, ethKC EthKeychain, backend SignerBackend) Signer

type SignerBackend

type SignerBackend interface {
	GetUTXO(ctx stdcontext.Context, chainID, utxoID ids.ID) (*avax.UTXO, error)
}

type Wallet

type Wallet interface {
	Context

	// Builder returns the builder that will be used to create the transactions.
	Builder() Builder

	// Signer returns the signer that will be used to sign the transactions.
	Signer() Signer

	// IssueImportTx creates, signs, and issues an import transaction that
	// attempts to consume all the available UTXOs and import the funds to [to].
	//
	// - [chainID] specifies the chain to be importing funds from.
	// - [to] specifies where to send the imported funds to.
	IssueImportTx(
		chainID ids.ID,
		to ethcommon.Address,
		options ...common.Option,
	) (*evm.Tx, error)

	// IssueExportTx creates, signs, and issues an export transaction that
	// attempts to send all the provided [outputs] to the requested [chainID].
	//
	// - [chainID] specifies the chain to be exporting the funds to.
	// - [outputs] specifies the outputs to send to the [chainID].
	IssueExportTx(
		chainID ids.ID,
		outputs []*secp256k1fx.TransferOutput,
		options ...common.Option,
	) (*evm.Tx, error)

	// IssueUnsignedTx signs and issues the unsigned tx.
	IssueUnsignedAtomicTx(
		utx evm.UnsignedAtomicTx,
		options ...common.Option,
	) (*evm.Tx, error)

	// IssueAtomicTx issues the signed tx.
	IssueAtomicTx(
		tx *evm.Tx,
		options ...common.Option,
	) error
}

func NewWallet

func NewWallet(
	builder Builder,
	signer Signer,
	avaxClient evm.Client,
	ethClient ethclient.Client,
	backend Backend,
) Wallet

func NewWalletWithOptions

func NewWalletWithOptions(
	wallet Wallet,
	options ...common.Option,
) Wallet

Jump to

Keyboard shortcuts

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