Documentation
¶
Index ¶
- Constants
- func AddAllUTXOs(ctx context.Context, utxos walletcommon.UTXOs, client UTXOClient, ...) error
- func NewChainUTXOs(chainID ids.ID, utxos UTXOs) common.ChainUTXOs
- type EthAccount
- type EthKeychain
- type EthState
- type KeychainAdapter
- type LUXState
- type UTXOClient
- type UTXOs
- type Wallet
- type WalletConfig
- type XClient
Examples ¶
Constants ¶
const ( MainnetAPIURI = "https://api.lux.network" TestnetAPIURI = "https://api.lux-test.network" LocalAPIURI = "http://localhost:9630" )
Variables ¶
This section is empty.
Functions ¶
func AddAllUTXOs ¶
func AddAllUTXOs( ctx context.Context, utxos walletcommon.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 NewChainUTXOs ¶
func NewChainUTXOs(chainID ids.ID, utxos UTXOs) common.ChainUTXOs
Types ¶
type EthAccount ¶
EthAccount represents an Ethereum account's state
type EthKeychain ¶
type EthKeychain interface {
GetEth(addr gethcommon.Address) (keychain.Signer, bool)
EthAddresses() set.Set[gethcommon.Address]
}
EthKeychain is an interface for keychains that support Ethereum addresses
type EthState ¶
type EthState struct {
Client *ethclient.Client
Accounts map[ethcommon.Address]*EthAccount
}
type KeychainAdapter ¶
type KeychainAdapter struct {
*secp256k1fx.Keychain
}
KeychainAdapter adapts secp256k1fx.Keychain to wallet/keychain.Keychain and EthKeychain interfaces. This allows secp256k1fx.Keychain to be used with MakeWallet.
func NewKeychainAdapter ¶
func NewKeychainAdapter(kc *secp256k1fx.Keychain) *KeychainAdapter
NewKeychainAdapter creates a KeychainAdapter from a secp256k1fx.Keychain
func (*KeychainAdapter) Addresses ¶
func (kc *KeychainAdapter) Addresses() set.Set[ids.ShortID]
Addresses implements wallet/keychain.Keychain
func (*KeychainAdapter) EthAddresses ¶
func (kc *KeychainAdapter) EthAddresses() set.Set[gethcommon.Address]
EthAddresses implements EthKeychain
func (*KeychainAdapter) Get ¶
Get implements wallet/keychain.Keychain (returns wallet/keychain.Signer, not utils/crypto/keychain.Signer)
func (*KeychainAdapter) GetEth ¶
func (kc *KeychainAdapter) GetEth(addr gethcommon.Address) (keychain.Signer, bool)
GetEth implements EthKeychain
type LUXState ¶
type LUXState struct {
PClient *platformvm.Client
PCTX *pbuilder.Context
XClient *XClient
XCTX *xbuilder.Context
// CClient evm.Client // Implementation note
// CCTX *c.Context
UTXOs walletcommon.UTXOs
}
type UTXOClient ¶
type UTXOs ¶
type UTXOs interface {
AddUTXO(ctx context.Context, sourceChainID, destinationChainID ids.ID, utxo *lux.UTXO) error
RemoveUTXO(ctx context.Context, sourceChainID, destinationChainID, utxoID ids.ID) error
UTXOs(ctx context.Context, sourceChainID, destinationChainID ids.ID) ([]*lux.UTXO, error)
GetUTXO(ctx context.Context, sourceChainID, destinationChainID, utxoID ids.ID) (*lux.UTXO, error)
}
type Wallet ¶
Wallet provides chain wallets for the primary network. NOTE: C-Chain wallet is disabled - use github.com/luxfi/evm/ethclient directly
Example ¶
ctx := context.Background()
// Load key from local key storage (~/.lux/keys/) or environment variables
// Priority: LUX_MNEMONIC > LUX_PRIVATE_KEY > LUX_KEY_NAME > CLI arg > default key
localKey, err := keyutil.LoadKey()
if err != nil {
log.Printf("no local key available, skipping example: %v", err)
return
}
kc := secp256k1fx.NewKeychain(localKey)
wkc := kc.AsWalletKeychain()
// MakeWallet fetches the available UTXOs owned by [kc] on the network that
// [LocalAPIURI] is hosting.
walletSyncStartTime := time.Now()
wallet, err := MakeWallet(ctx, &WalletConfig{
URI: LocalAPIURI,
LUXKeychain: wkc,
EthKeychain: wkc,
})
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{
localKey.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.IssueTransformChainTx(
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 net transaction with: %s\n", err)
return
}
transformSubnetTxID := transformSubnetTx.ID()
log.Printf("issued transform net transaction %s in %s\n", transformSubnetTxID, time.Since(transformSubnetStartTime))
addPermissionlessValidatorStartTime := time.Now()
startTime := time.Now().Add(time.Minute)
// Generate a test node ID for this example
testNodeID := ids.GenerateTestNodeID()
addNetValidatorTx, err := pWallet.IssueAddPermissionlessValidatorTx(
&txs.ChainValidator{
Validator: txs.Validator{
NodeID: testNodeID,
Start: uint64(startTime.Unix()),
End: uint64(startTime.Add(5 * time.Second).Unix()),
Wght: 25 * units.MegaLux,
},
Chain: createSubnetTxID,
},
&signer.Empty{},
createAssetTx.ID(),
&secp256k1fx.OutputOwners{},
&secp256k1fx.OutputOwners{},
reward.PercentDenominator,
)
if err != nil {
log.Fatalf("failed to issue add net validator with: %s\n", err)
return
}
addNetValidatorTxID := addNetValidatorTx.ID()
log.Printf("issued add net validator transaction %s in %s\n", addNetValidatorTxID, time.Since(addPermissionlessValidatorStartTime))
addPermissionlessDelegatorStartTime := time.Now()
addNetDelegatorTx, err := pWallet.IssueAddPermissionlessDelegatorTx(
&txs.ChainValidator{
Validator: txs.Validator{
NodeID: testNodeID,
Start: uint64(startTime.Unix()),
End: uint64(startTime.Add(5 * time.Second).Unix()),
Wght: 25 * units.MegaLux,
},
Chain: createSubnetTxID,
},
createAssetTxID,
&secp256k1fx.OutputOwners{},
)
if err != nil {
log.Fatalf("failed to issue add net delegator with: %s\n", err)
return
}
addNetDelegatorTxID := addNetDelegatorTx.ID()
log.Printf("issued add net validator delegator %s in %s\n", addNetDelegatorTxID, time.Since(addPermissionlessDelegatorStartTime))
func MakeWallet ¶
func MakeWallet(ctx context.Context, 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 transactions.
The wallet manages all state locally, and performs all tx signing locally.
type WalletConfig ¶
type WalletConfig struct {
// Base URI to use for all node requests.
URI string // required
// Keys to use for signing all transactions.
LUXKeychain keychain.Keychain // required
EthKeychain EthKeychain // optional - for future C-Chain support
// Set of P-chain transactions that the wallet should know about to be able
// to generate transactions.
PChainTxs map[ids.ID]*txs.Tx // optional
// Set of P-chain transactions that the wallet should fetch to be able to
// generate transactions.
PChainTxsToFetch set.Set[ids.ID] // optional
}
type XClient ¶
type XClient struct {
// contains filtered or unexported fields
}
XClient is a client for interacting with the X-Chain
func NewXClient ¶
NewXClient returns a new X-Chain client
func (*XClient) GetAtomicUTXOs ¶
func (c *XClient) 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)
GetAtomicUTXOs implements UTXOClient. For local/dev networks where X-chain atomic operations aren't needed, this returns empty to allow P-chain operations to proceed.
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
add-primary-validator
command
|
|
|
convert-subnet-to-l1
command
|
|
|
create-asset
command
|
|
|
create-chain
command
|
|
|
create-locked-stakeable
command
|
|
|
create-subnet
command
|
|
|
disable-l1-validator
command
|
|
|
get-p-chain-balance
command
|
|
|
get-x-chain-balance
command
|
|
|
increase-l1-validator-balance
command
|
|
|
keyutil
Package keyutil provides utilities for loading private keys that integrate with the Lux CLI key management system (~/.lux/keys/).
|
Package keyutil provides utilities for loading private keys that integrate with the Lux CLI key management system (~/.lux/keys/). |
|
register-l1-validator
command
|
|
|
remove-subnet-validator
command
|
|
|
set-l1-validator-weight
command
|
|
|
sign-l1-validator-registration
command
|
|
|
sign-l1-validator-weight-update
command
|
|
|
sign-subnet-to-l1-conversion
command
|