primary

package
v0.1.1 Latest Latest
Warning

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

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

Documentation

Index

Examples

Constants

View Source
const (
	MainnetAPIURI = "https://api.lux.network"
	TestnetAPIURI = "https://api.lux-test.network"
	LocalAPIURI   = "http://localhost:9650"
)

Variables

View Source
var (
	NewOptions              = wallet.NewOptions
	UnionOptions            = wallet.UnionOptions
	WithContext             = wallet.WithContext
	WithCustomAddresses     = wallet.WithCustomAddresses
	WithCustomEthAddresses  = wallet.WithCustomEthAddresses
	WithBaseFee             = wallet.WithBaseFee
	WithMinIssuanceTime     = wallet.WithMinIssuanceTime
	WithStakeableLocked     = wallet.WithStakeableLocked
	WithChangeOwner         = wallet.WithChangeOwner
	WithMemo                = wallet.WithMemo
	WithAssumeDecided       = wallet.WithAssumeDecided
	WithPollFrequency       = wallet.WithPollFrequency
	WithIssuanceHandler     = wallet.WithIssuanceHandler
	WithConfirmationHandler = wallet.WithConfirmationHandler
)
View Source
var (
	NewUTXOs      = wallet.NewUTXOs
	NewChainUTXOs = wallet.NewChainUTXOs
)
View Source
var MatchOwners = wallet.MatchOwners

Re-export MatchOwners from the wallet package for backward compatibility

Functions

func AddAllUTXOs

func AddAllUTXOs(
	ctx context.Context,
	utxos wallet.UTXOs,
	client UTXOClient,
	codec codec.Manager,
	sourceChainID ids.ID,
	destinationChainID ids.ID,
	addrs []ids.ShortID,
) error

AddAllUTXOs fetches all the UTXOs referenced by [addresses] that were sent from [sourceChainID] to [destinationChainID] from the client. It then uses codec to parse the returned UTXOs and it adds them into [utxos]. If [ctx] expires, then the returned error will be immediately reported.

func FetchPState

func FetchPState(
	ctx context.Context,
	uri string,
	addrs set.Set[ids.ShortID],
) (
	*platformvm.Client,
	*pbuilder.Context,
	wallet.UTXOs,
	error,
)

func MakePWallet

func MakePWallet(
	ctx context.Context,
	uri string,
	keychain keychain.Keychain,
	config WalletConfig,
) (pwallet.Wallet, error)

MakePWallet returns a P-chain wallet that supports issuing transactions.

On creation, the wallet attaches to the provided uri and fetches all UTXOs that reference any of the provided keys. If the UTXOs are modified through an external issuance process, such as another instance of the wallet, the UTXOs may become out of sync. The wallet will also fetch all requested P-chain owners.

The wallet manages all state locally, and performs all tx signing locally.

Types

type ChainUTXOs

type ChainUTXOs = wallet.ChainUTXOs

type ConfirmationReceipt

type ConfirmationReceipt = wallet.ConfirmationReceipt

type EthState

type EthState struct {
	Client   ethclient.Client
	Accounts map[ethcommon.Address]*c.Account
}

func FetchEthState

func FetchEthState(
	ctx context.Context,
	uri string,
	addrs set.Set[ethcommon.Address],
) (*EthState, error)

type IssuanceReceipt

type IssuanceReceipt = wallet.IssuanceReceipt

type LUXState

type LUXState struct {
	PClient *platformvm.Client
	PCTX    *pbuilder.Context
	XClient *xvm.Client
	XCTX    *xbuilder.Context
	CClient client.Client
	CCTX    *c.Context
	UTXOs   wallet.UTXOs
}

func FetchState

func FetchState(
	ctx context.Context,
	uri string,
	addrs set.Set[ids.ShortID],
) (
	*LUXState,
	error,
)

type Option

type Option = wallet.Option

Re-export types and functions from the wallet package for backward compatibility

type Options

type Options = wallet.Options

type UTXOClient

type UTXOClient interface {
	GetAtomicUTXOs(
		ctx context.Context,
		addrs []ids.ShortID,
		sourceChain string,
		limit uint32,
		startAddress ids.ShortID,
		startUTXOID ids.ID,
		options ...rpc.Option,
	) ([][]byte, ids.ShortID, ids.ID, error)
}

type UTXOs

type UTXOs = wallet.UTXOs

Re-export types and functions from the wallet package for backward compatibility

type Wallet

type Wallet struct {
	// contains filtered or unexported fields
}

Wallet provides chain wallets for the primary network.

Example
ctx := context.Background()
kc := secp256k1fx.NewKeychain(genesis.EWOQKey)

// MakeWallet fetches the available UTXOs owned by [kc] on the network that
// [LocalAPIURI] is hosting.
walletSyncStartTime := time.Now()
wallet, err := MakeWallet(
	ctx,
	LocalAPIURI,
	kc,
	kc,
	WalletConfig{},
)
if err != nil {
	log.Fatalf("failed to initialize wallet with: %s\n", err)
	return
}
log.Printf("synced wallet in %s\n", time.Since(walletSyncStartTime))

// Get the P-chain and the X-chain wallets
pWallet := wallet.P()
xWallet := wallet.X()
xBuilder := xWallet.Builder()
xContext := xBuilder.Context()

// Pull out useful constants to use when issuing transactions.
xChainID := xContext.BlockchainID
owner := &secp256k1fx.OutputOwners{
	Threshold: 1,
	Addrs: []ids.ShortID{
		genesis.EWOQKey.PublicKey().Address(),
	},
}

// Create a custom asset to send to the P-chain.
createAssetStartTime := time.Now()
createAssetTx, err := xWallet.IssueCreateAssetTx(
	"RnM",
	"RNM",
	9,
	map[uint32][]verify.State{
		0: {
			&secp256k1fx.TransferOutput{
				Amt:          100 * units.MegaLux,
				OutputOwners: *owner,
			},
		},
	},
)
if err != nil {
	log.Fatalf("failed to create new X-chain asset with: %s\n", err)
	return
}
createAssetTxID := createAssetTx.ID()
log.Printf("created X-chain asset %s in %s\n", createAssetTxID, time.Since(createAssetStartTime))

// Send 100 MegaLux to the P-chain.
exportStartTime := time.Now()
exportTx, err := xWallet.IssueExportTx(
	constants.PlatformChainID,
	[]*lux.TransferableOutput{
		{
			Asset: lux.Asset{
				ID: createAssetTxID,
			},
			Out: &secp256k1fx.TransferOutput{
				Amt:          100 * units.MegaLux,
				OutputOwners: *owner,
			},
		},
	},
)
if err != nil {
	log.Fatalf("failed to issue X->P export transaction with: %s\n", err)
	return
}
exportTxID := exportTx.ID()
log.Printf("issued X->P export %s in %s\n", exportTxID, time.Since(exportStartTime))

// Import the 100 MegaLux from the X-chain into the P-chain.
importStartTime := time.Now()
importTx, err := pWallet.IssueImportTx(xChainID, owner)
if err != nil {
	log.Fatalf("failed to issue X->P import transaction with: %s\n", err)
	return
}
importTxID := importTx.ID()
log.Printf("issued X->P import %s in %s\n", importTxID, time.Since(importStartTime))

createSubnetStartTime := time.Now()
createSubnetTx, err := pWallet.IssueCreateSubnetTx(owner)
if err != nil {
	log.Fatalf("failed to issue create subnet transaction with: %s\n", err)
	return
}
createSubnetTxID := createSubnetTx.ID()
log.Printf("issued create subnet transaction %s in %s\n", createSubnetTxID, time.Since(createSubnetStartTime))

transformSubnetStartTime := time.Now()
transformSubnetTx, err := pWallet.IssueTransformSubnetTx(
	createSubnetTxID,
	createAssetTxID,
	50*units.MegaLux,
	100*units.MegaLux,
	reward.PercentDenominator,
	reward.PercentDenominator,
	1,
	100*units.MegaLux,
	time.Second,
	365*24*time.Hour,
	0,
	1,
	5,
	.80*reward.PercentDenominator,
)
if err != nil {
	log.Fatalf("failed to issue transform subnet transaction with: %s\n", err)
	return
}
transformSubnetTxID := transformSubnetTx.ID()
log.Printf("issued transform subnet transaction %s in %s\n", transformSubnetTxID, time.Since(transformSubnetStartTime))

addPermissionlessValidatorStartTime := time.Now()
startTime := time.Now().Add(time.Minute)
addSubnetValidatorTx, err := pWallet.IssueAddPermissionlessValidatorTx(
	&txs.SubnetValidator{
		Validator: txs.Validator{
			NodeID: genesis.LocalConfig.InitialStakers[0].NodeID,
			Start:  uint64(startTime.Unix()),
			End:    uint64(startTime.Add(5 * time.Second).Unix()),
			Wght:   25 * units.MegaLux,
		},
		Subnet: createSubnetTxID,
	},
	&signer.Empty{},
	createAssetTx.ID(),
	&secp256k1fx.OutputOwners{},
	&secp256k1fx.OutputOwners{},
	reward.PercentDenominator,
)
if err != nil {
	log.Fatalf("failed to issue add subnet validator with: %s\n", err)
	return
}
addSubnetValidatorTxID := addSubnetValidatorTx.ID()
log.Printf("issued add subnet validator transaction %s in %s\n", addSubnetValidatorTxID, time.Since(addPermissionlessValidatorStartTime))

addPermissionlessDelegatorStartTime := time.Now()
addSubnetDelegatorTx, err := pWallet.IssueAddPermissionlessDelegatorTx(
	&txs.SubnetValidator{
		Validator: txs.Validator{
			NodeID: genesis.LocalConfig.InitialStakers[0].NodeID,
			Start:  uint64(startTime.Unix()),
			End:    uint64(startTime.Add(5 * time.Second).Unix()),
			Wght:   25 * units.MegaLux,
		},
		Subnet: createSubnetTxID,
	},
	createAssetTxID,
	&secp256k1fx.OutputOwners{},
)
if err != nil {
	log.Fatalf("failed to issue add subnet delegator with: %s\n", err)
	return
}
addSubnetDelegatorTxID := addSubnetDelegatorTx.ID()
log.Printf("issued add subnet validator delegator %s in %s\n", addSubnetDelegatorTxID, time.Since(addPermissionlessDelegatorStartTime))

func MakeWallet

func MakeWallet(
	ctx context.Context,
	uri string,
	luxKeychain keychain.Keychain,
	ethKeychain c.EthKeychain,
	config WalletConfig,
) (*Wallet, error)

MakeWallet returns a wallet that supports issuing transactions to the chains living in the primary network.

On creation, the wallet attaches to the provided uri and fetches all UTXOs that reference any of the provided keys. If the UTXOs are modified through an external issuance process, such as another instance of the wallet, the UTXOs may become out of sync. The wallet will also fetch all requested P-chain owners.

The wallet manages all state locally, and performs all tx signing locally.

func NewWallet

func NewWallet(p pwallet.Wallet, x x.Wallet, c c.Wallet) *Wallet

Creates a new default wallet

func NewWalletWithOptions

func NewWalletWithOptions(w *Wallet, options ...Option) *Wallet

Creates a Wallet with the given set of options

func (*Wallet) C

func (w *Wallet) C() c.Wallet

func (*Wallet) P

func (w *Wallet) P() pwallet.Wallet

func (*Wallet) X

func (w *Wallet) X() x.Wallet

type WalletConfig

type WalletConfig struct {
	// Subnet IDs that the wallet should know about to be able to generate
	// transactions.
	SubnetIDs []ids.ID // optional
	// Validation IDs that the wallet should know about to be able to generate
	// transactions.
	ValidationIDs []ids.ID // optional
}

Jump to

Keyboard shortcuts

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