c

package
v1.18.1-qos Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2025 License: BSD-3-Clause Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const (
	EVMOutputGas = 100 // Implementation note
	EVMInputGas  = 100 // Implementation note

	// Transaction status
	Accepted = "Accepted"
)

Constants

View Source
const Alias = "C"

Variables

View Source
var (
	// Codec is the codec used for serialization
	Codec codec.Manager
)

Variables

Functions

func CalculateDynamicFee added in v1.1.11

func CalculateDynamicFee(gasUsed uint64, baseFee *big.Int) (uint64, error)

CalculateDynamicFee calculates the dynamic fee based on EIP-1559 Fee = gasUsed * (baseFee + priorityFee)

Types

type Account

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

type Backend

type Backend interface {
	common.ChainUTXOs
	BuilderBackend
	SignerBackend

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

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

func NewBackend

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

type BaseTx added in v1.1.11

type BaseTx struct {
	NetworkID    uint32
	BlockchainID ids.ID
	Outs         []*lux.TransferableOutput
	Ins          []*lux.TransferableInput
	Memo         []byte
}

BaseTx contains common transaction fields

type Builder

type Builder interface {
	// Context returns the configuration of the chain that this builder uses to
	// create transactions.
	Context() *Context

	// GetBalance calculates the amount of LUX that this builder has control
	// over.
	GetBalance(
		options ...common.Option,
	) (*big.Int, error)

	// GetImportableBalance calculates the amount of LUX 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,
	) (*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,
	) (*UnsignedExportTx, error)
}

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

func NewBuilder

func NewBuilder(
	luxAddrs set.Set[ids.ShortID],
	ethAddrs set.Set[ethcommon.Address],
	context *Context,
	backend BuilderBackend,
) Builder

NewBuilder returns a new transaction builder.

  • [luxAddrs] is the set of addresses in the LUX 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 {
	UTXOs(ctx context.Context, sourceChainID ids.ID) ([]*lux.UTXO, error)
	Balance(ctx context.Context, addr ethcommon.Address) (*big.Int, error)
	Nonce(ctx context.Context, addr ethcommon.Address) (uint64, error)
}

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

type Client added in v1.1.11

type Client interface {
	IssueTx(tx *Tx) (ids.ID, error)
	GetAtomicTxStatus(txID ids.ID) (Status, error)
}

Client represents the C-chain client interface

type Context

type Context struct {
	NetworkID    uint32
	BlockchainID ids.ID
	LUXAssetID   ids.ID
}

func NewContextFromClients

func NewContextFromClients(
	ctx context.Context,
	infoClient info.Client,
	xChainClient xvm.Client,
) (*Context, error)

func NewContextFromURI

func NewContextFromURI(ctx context.Context, uri string) (*Context, error)

type EVMInput added in v1.1.11

type EVMInput struct {
	Address common.Address
	Amount  uint64
	AssetID ids.ID
	Nonce   uint64
}

EVMInput represents an input on the C-chain

func (*EVMInput) Compare added in v1.1.11

func (e *EVMInput) Compare(other *EVMInput) int

Compare implements utils.Sortable

type EVMOutput added in v1.1.11

type EVMOutput struct {
	Address common.Address
	Amount  uint64
}

EVMOutput represents an output on the C-chain

type EthKeychain

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

type Signer

type Signer interface {
	// SignAtomic adds as many missing signatures as possible to the provided
	// transaction.
	//
	// If there are already some signatures on the transaction, those signatures
	// will not be removed.
	//
	// If the signer doesn't have the ability to provide a required signature,
	// the signature slot will be skipped without reporting an error.
	SignAtomic(ctx context.Context, tx *Tx) error
}

func NewSigner

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

type SignerBackend

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

type Status added in v1.1.11

type Status string

Status represents the status of a transaction

type Tx added in v1.1.11

type Tx struct {
	ID               ids.ID
	UnsignedAtomicTx UnsignedAtomicTx
	Creds            []verify.Verifiable
	// contains filtered or unexported fields
}

Tx represents a transaction on the C-Chain

func SignUnsignedAtomic

func SignUnsignedAtomic(ctx context.Context, signer Signer, utx UnsignedAtomicTx) (*Tx, error)

func (*Tx) Initialize added in v1.1.11

func (tx *Tx) Initialize(unsignedBytes, signedBytes []byte)

Initialize initializes the transaction with computed ID and caches bytes

func (*Tx) Sign added in v1.1.11

func (tx *Tx) Sign(codec codec.Manager, signers [][]*secp256k1.PrivateKey) error

Sign signs the transaction with the provided private keys

func (*Tx) SignedBytes added in v1.1.11

func (tx *Tx) SignedBytes() []byte

SignedBytes returns the signed bytes of the transaction

type UnsignedAtomicTx added in v1.1.11

type UnsignedAtomicTx interface {
	InputUTXOs() []ids.ID
}

UnsignedAtomicTx is the interface for unsigned atomic transactions

type UnsignedAtomicTxWrapper added in v1.1.11

type UnsignedAtomicTxWrapper struct {
	UnsignedAtomicTx UnsignedAtomicTx
}

UnsignedAtomicTx field for Tx

type UnsignedExportTx added in v1.1.11

type UnsignedExportTx struct {
	BaseTx
	DestinationChain ids.ID
	ExportedOutputs  []*lux.TransferableOutput
	Ins              []*EVMInput
}

UnsignedExportTx is an unsigned export transaction

func (*UnsignedExportTx) GasUsed added in v1.1.11

func (tx *UnsignedExportTx) GasUsed(fixedFee bool) (uint64, error)

GasUsed returns the gas used by this transaction

func (*UnsignedExportTx) ID added in v1.1.11

func (tx *UnsignedExportTx) ID() ids.ID

ID returns the transaction ID

func (*UnsignedExportTx) InputUTXOs added in v1.1.11

func (tx *UnsignedExportTx) InputUTXOs() []ids.ID

InputUTXOs implements UnsignedAtomicTx

type UnsignedImportTx added in v1.1.11

type UnsignedImportTx struct {
	BaseTx
	SourceChain    ids.ID
	ImportedInputs []*lux.TransferableInput
	Outs           []*EVMOutput
}

UnsignedImportTx is an unsigned import transaction

func (*UnsignedImportTx) GasUsed added in v1.1.11

func (tx *UnsignedImportTx) GasUsed(fixedFee bool) (uint64, error)

GasUsed returns the gas used by this transaction

func (*UnsignedImportTx) InputUTXOs added in v1.1.11

func (tx *UnsignedImportTx) InputUTXOs() []ids.ID

InputUTXOs implements UnsignedAtomicTx

type Wallet

type Wallet interface {
	// 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,
	) (*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,
	) (*Tx, error)

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

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

func NewWallet

func NewWallet(
	builder Builder,
	signer Signer,
	luxClient 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