Help us shape the future of Go! Take the 2026 Go Developer Survey

builder

package
v1.36.39 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: BSD-3-Clause Imports: 22 Imported by: 1

Documentation

Index

Constants

View Source
const Alias = "P"

Variables

View Source
var (
	ErrNoChangeAddress           = errors.New("no possible change address")
	ErrUnknownOutputType         = errors.New("unknown output type")
	ErrUnknownOwnerType          = errors.New("unknown owner type")
	ErrInsufficientAuthorization = errors.New("insufficient authorization")
	ErrInsufficientFunds         = errors.New("insufficient funds")
)

Functions

func NewConsensusRuntime added in v1.22.87

func NewConsensusRuntime(networkID uint32, utxoAssetID ids.ID) (*runtime.Runtime, error)

func NewConsensusRuntimeWithChainID added in v1.22.87

func NewConsensusRuntimeWithChainID(networkID uint32, chainID ids.ID, utxoAssetID ids.ID) (*runtime.Runtime, error)

Types

type Backend

type Backend interface {
	UTXOs(ctx context.Context, sourceChainID ids.ID) ([]*lux.UTXO, error)
	GetOwner(ctx context.Context, ownerID ids.ID) (fx.Owner, error)
}

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 each asset that this builder has
	// control over.
	GetBalance(
		options ...common.Option,
	) (map[ids.ID]uint64, error)

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

	// NewBaseTx creates a new simple value transfer.
	//
	// - [outputs] specifies all the recipients and amounts that should be sent
	//   from this transaction.
	NewBaseTx(
		outputs []*lux.TransferableOutput,
		options ...common.Option,
	) (*txs.BaseTx, error)

	// NewAddValidatorTx creates a new validator of the primary network.
	//
	// - [vdr] specifies all the details of the validation period such as the
	//   startTime, endTime, stake weight, and nodeID.
	// - [rewardsOwner] specifies the owner of all the rewards this validator
	//   may accrue during its validation period.
	// - [shares] specifies the fraction (out of 1,000,000) that this validator
	//   will take from delegation rewards. If 1,000,000 is provided, 100% of
	//   the delegation reward will be sent to the validator's [rewardsOwner].
	NewAddValidatorTx(
		vdr *txs.Validator,
		rewardsOwner *secp256k1fx.OutputOwners,
		shares uint32,
		options ...common.Option,
	) (*txs.AddValidatorTx, error)

	// NewAddChainValidatorTx builds an unsigned legacy per-chain
	// validator registration tx.
	//
	// - [vdr] specifies all the details of the validation period such as the
	//   startTime, endTime, sampling weight, nodeID, and netID.
	//
	// Deprecated: Use NewAddValidatorTx. Under LP-018 sovereign-L1,
	// validators join a network — never a chain. A sovereign L1 IS a
	// primary network at its own networkID. Retained for one release
	// cycle for wire/codec compat with pre-LP-018 binaries.
	NewAddChainValidatorTx(
		vdr *txs.ChainValidator,
		options ...common.Option,
	) (*txs.AddChainValidatorTx, error)

	// NewRemoveChainValidatorTx removes [nodeID] from the validator
	// set [netID].
	NewRemoveChainValidatorTx(
		nodeID ids.NodeID,
		netID ids.ID,
		options ...common.Option,
	) (*txs.RemoveChainValidatorTx, error)

	// NewAddDelegatorTx creates a new delegator to a validator on the primary
	// network.
	//
	// - [vdr] specifies all the details of the delegation period such as the
	//   startTime, endTime, stake weight, and validator's nodeID.
	// - [rewardsOwner] specifies the owner of all the rewards this delegator
	//   may accrue at the end of its delegation period.
	NewAddDelegatorTx(
		vdr *txs.Validator,
		rewardsOwner *secp256k1fx.OutputOwners,
		options ...common.Option,
	) (*txs.AddDelegatorTx, error)

	// NewCreateChainTx creates a new chain in the named network.
	//
	// - [netID] specifies the net to launch the chain in.
	// - [genesis] specifies the initial state of the new chain.
	// - [vmID] specifies the vm that the new chain will run.
	// - [fxIDs] specifies all the feature extensions that the vm should be
	//   running with.
	// - [chainName] specifies a human readable name for the chain.
	NewCreateChainTx(
		netID ids.ID,
		genesis []byte,
		vmID ids.ID,
		fxIDs []ids.ID,
		chainName string,
		options ...common.Option,
	) (*txs.CreateChainTx, error)

	// NewCreateNetworkTx creates a new network with the specified owner.
	//
	// - [owner] specifies who has the ability to create new chains and add new
	//   validators to the network.
	NewCreateNetworkTx(
		owner *secp256k1fx.OutputOwners,
		options ...common.Option,
	) (*txs.CreateNetworkTx, error)

	// NewTransferChainOwnershipTx changes the owner of the named chain.
	//
	// - [chainID] specifies the chain to be modified
	// - [owner] specifies who has the ability to create new chains and add new
	//   validators to the chain.
	NewTransferChainOwnershipTx(
		chainID ids.ID,
		owner *secp256k1fx.OutputOwners,
		options ...common.Option,
	) (*txs.TransferChainOwnershipTx, error)

	// NewRegisterL1ValidatorTx adds a validator to an L1.
	//
	// - [balance] that the validator should allocate to continuous fees
	// - [proofOfPossession] is the BLS PoP for the key included in the Warp
	//   message
	// - [message] is the Warp message that authorizes this validator to be
	//   added
	NewRegisterL1ValidatorTx(
		balance uint64,
		proofOfPossession [bls.SignatureLen]byte,
		message []byte,
		options ...common.Option,
	) (*txs.RegisterL1ValidatorTx, error)

	// NewSetL1ValidatorWeightTx sets the weight of a validator on an L1.
	//
	// - [message] is the Warp message that authorizes this validator's weight
	//   to be changed
	NewSetL1ValidatorWeightTx(
		message []byte,
		options ...common.Option,
	) (*txs.SetL1ValidatorWeightTx, error)

	// NewIncreaseL1ValidatorBalanceTx increases the balance of a validator on
	// an L1 for the continuous fee.
	// the continuous fee.
	//
	// - [validationID] of the validator
	// - [balance] amount to increase the validator's balance by
	NewIncreaseL1ValidatorBalanceTx(
		validationID ids.ID,
		balance uint64,
		options ...common.Option,
	) (*txs.IncreaseL1ValidatorBalanceTx, error)

	// NewDisableL1ValidatorTx disables an L1 validator and returns the
	// remaining funds allocated to the continuous fee to the remaining balance
	// owner.
	//
	// - [validationID] of the validator to disable
	NewDisableL1ValidatorTx(
		validationID ids.ID,
		options ...common.Option,
	) (*txs.DisableL1ValidatorTx, 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.
	NewImportTx(
		chainID ids.ID,
		to *secp256k1fx.OutputOwners,
		options ...common.Option,
	) (*txs.ImportTx, 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].
	NewExportTx(
		chainID ids.ID,
		outputs []*lux.TransferableOutput,
		options ...common.Option,
	) (*txs.ExportTx, error)

	// Removed in regenesis
	// // NewTransformChainTx creates a transform net transaction that attempts
	// // to convert the provided [netID] from a permissioned net to a
	// // permissionless chain. This transaction will convert
	// // [maxSupply] - [initialSupply] of [assetID] to staking rewards.
	// //
	// // - [netID] specifies the net to transform.
	// // - [assetID] specifies the asset to use to reward stakers on the chain.
	// // - [initialSupply] is the amount of [assetID] that will be in circulation
	// //   after this transaction is accepted.
	// // - [maxSupply] is the maximum total amount of [assetID] that should ever
	// //   exist.
	// // - [minConsumptionRate] is the rate that a staker will receive rewards
	// //   if they stake with a duration of 0.
	// // - [maxConsumptionRate] is the maximum rate that staking rewards should be
	// //   consumed from the reward pool per year.
	// // - [minValidatorStake] is the minimum amount of funds required to become a
	// //   validator.
	// // - [maxValidatorStake] is the maximum amount of funds a single validator
	// //   can be allocated, including delegated funds.
	// // - [minStakeDuration] is the minimum number of seconds a staker can stake
	// //   for.
	// // - [maxStakeDuration] is the maximum number of seconds a staker can stake
	// //   for.
	// // - [minValidatorStake] is the minimum amount of funds required to become a
	// //   delegator.
	// // - [maxValidatorWeightFactor] is the factor which calculates the maximum
	// //   amount of delegation a validator can receive. A value of 1 effectively
	// //   disables delegation.
	// // - [uptimeRequirement] is the minimum percentage a validator must be
	// //   online and responsive to receive a reward.
	NewTransformChainTx(
		netID ids.ID,
		assetID ids.ID,
		initialSupply uint64,
		maxSupply uint64,
		minConsumptionRate uint64,
		maxConsumptionRate uint64,
		minValidatorStake uint64,
		maxValidatorStake uint64,
		minStakeDuration time.Duration,
		maxStakeDuration time.Duration,
		minDelegationFee uint32,
		minDelegatorStake uint64,
		maxValidatorWeightFactor byte,
		uptimeRequirement uint32,
		options ...common.Option,
	) (*txs.TransformChainTx, error)

	// NewAddPermissionlessValidatorTx creates a new validator of the specified
	// chain.
	//
	// - [vdr] specifies all the details of the validation period such as the
	//   netID, startTime, endTime, stake weight, and nodeID.
	// - [signer] if the netID is the primary network, this is the BLS key
	//   for this validator. Otherwise, this value should be the empty signer.
	// - [assetID] specifies the asset to stake.
	// - [validationRewardsOwner] specifies the owner of all the rewards this
	//   validator earns for its validation period.
	// - [delegationRewardsOwner] specifies the owner of all the rewards this
	//   validator earns for delegations during its validation period.
	// - [shares] specifies the fraction (out of 1,000,000) that this validator
	//   will take from delegation rewards. If 1,000,000 is provided, 100% of
	//   the delegation reward will be sent to the validator's [rewardsOwner].
	NewAddPermissionlessValidatorTx(
		vdr *txs.ChainValidator,
		signer signer.Signer,
		assetID ids.ID,
		validationRewardsOwner *secp256k1fx.OutputOwners,
		delegationRewardsOwner *secp256k1fx.OutputOwners,
		shares uint32,
		options ...common.Option,
	) (*txs.AddPermissionlessValidatorTx, error)

	// NewAddPermissionlessDelegatorTx creates a new delegator of the specified
	// net on the specified nodeID.
	//
	// - [vdr] specifies all the details of the delegation period such as the
	//   netID, startTime, endTime, stake weight, and nodeID.
	// - [assetID] specifies the asset to stake.
	// - [rewardsOwner] specifies the owner of all the rewards this delegator
	//   earns during its delegation period.
	NewAddPermissionlessDelegatorTx(
		vdr *txs.ChainValidator,
		assetID ids.ID,
		rewardsOwner *secp256k1fx.OutputOwners,
		options ...common.Option,
	) (*txs.AddPermissionlessDelegatorTx, error)
}

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

func New

func New(
	addrs set.Set[ids.ShortID],
	context *Context,
	backend Backend,
) Builder

New returns a new transaction builder.

  • [addrs] is the set of addresses that the builder assumes can be used when signing the transactions in the future.
  • context provides the chain's configuration.
  • [backend] provides the chain's state.

func NewWithOptions added in v1.1.11

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

NewWithOptions returns a new 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.

func WithOptions

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

WithOptions returns a new 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 Context

type Context struct {
	NetworkID         uint32
	ChainID           ids.ID // Optional: if set, overrides default PlatformChainID
	UTXOAssetID       ids.ID
	ComplexityWeights gas.Dimensions
	GasPrice          gas.Price
	StaticFeeConfig   fee.StaticConfig
}

Jump to

Keyboard shortcuts

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