pub struct Account<S: SecretManage = SecretManager> { /* private fields */ }
wallet
only.Expand description
A thread guard over an account, so we can lock the account during operations.
Implementations§
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
sourcepub async fn generate_ed25519_addresses(
&self,
amount: u32,
options: impl Into<Option<GenerateAddressOptions>> + Send
) -> Result<Vec<AccountAddress>>
pub async fn generate_ed25519_addresses( &self, amount: u32, options: impl Into<Option<GenerateAddressOptions>> + Send ) -> Result<Vec<AccountAddress>>
Generate addresses and stores them in the account
let public_addresses = account.generate_ed25519_addresses(2, None).await?;
// internal addresses are used for remainder outputs, if the RemainderValueStrategy for transactions is set to ChangeAddress
let internal_addresses = account
.generate_ed25519_addresses(
1,
Some(GenerateAddressOptions {
internal: true,
..Default::default()
}),
)
.await?;
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
sourcepub async fn claimable_outputs(
&self,
outputs_to_claim: OutputsToClaim
) -> Result<Vec<OutputId>>
pub async fn claimable_outputs( &self, outputs_to_claim: OutputsToClaim ) -> Result<Vec<OutputId>>
Get basic and nft outputs that have
ExpirationUnlockCondition
,
StorageDepositReturnUnlockCondition
or
TimelockUnlockCondition
and can be
unlocked now and also get basic outputs with only an AddressUnlockCondition
unlock condition, for
additional inputs
sourcepub async fn claim_outputs<I: IntoIterator<Item = OutputId> + Send>(
&self,
output_ids_to_claim: I
) -> Result<Transaction>
pub async fn claim_outputs<I: IntoIterator<Item = OutputId> + Send>( &self, output_ids_to_claim: I ) -> Result<Transaction>
Try to claim basic or nft outputs that have additional unlock conditions to their AddressUnlockCondition
from Account::claimable_outputs()
.
sourcepub async fn prepare_claim_outputs<I: IntoIterator<Item = OutputId> + Send>(
&self,
output_ids_to_claim: I
) -> Result<PreparedTransactionData>
pub async fn prepare_claim_outputs<I: IntoIterator<Item = OutputId> + Send>( &self, output_ids_to_claim: I ) -> Result<PreparedTransactionData>
Try to claim basic outputs that have additional unlock conditions to their AddressUnlockCondition.
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
sourcepub async fn consolidate_outputs(
&self,
params: ConsolidationParams
) -> Result<Transaction>
pub async fn consolidate_outputs( &self, params: ConsolidationParams ) -> Result<Transaction>
Consolidates basic outputs with only an AddressUnlockCondition from an account by sending them to a provided
address or to an own address again if the output amount is >= the output_threshold. When force
is set to true
, the threshold is ignored. Only consolidates the amount of outputs that fit into a single
transaction.
sourcepub async fn prepare_consolidate_outputs(
&self,
params: ConsolidationParams
) -> Result<PreparedTransactionData>
pub async fn prepare_consolidate_outputs( &self, params: ConsolidationParams ) -> Result<PreparedTransactionData>
Prepares the transaction for Account::consolidate_outputs().
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
sourcepub async fn register_participation_events(
&self,
options: &ParticipationEventRegistrationOptions
) -> Result<HashMap<ParticipationEventId, ParticipationEventWithNodes>>
pub async fn register_participation_events( &self, options: &ParticipationEventRegistrationOptions ) -> Result<HashMap<ParticipationEventId, ParticipationEventWithNodes>>
Stores participation information for the given events locally and returns them all.
This will NOT store the node url and auth inside the client options.
sourcepub async fn deregister_participation_event(
&self,
id: &ParticipationEventId
) -> Result<()>
pub async fn deregister_participation_event( &self, id: &ParticipationEventId ) -> Result<()>
Removes a previously registered participation event from local storage.
sourcepub async fn get_participation_event(
&self,
id: ParticipationEventId
) -> Result<Option<ParticipationEventWithNodes>>
pub async fn get_participation_event( &self, id: ParticipationEventId ) -> Result<Option<ParticipationEventWithNodes>>
Retrieves corresponding information for a participation event from local storage.
sourcepub async fn get_participation_events(
&self
) -> Result<HashMap<ParticipationEventId, ParticipationEventWithNodes>>
pub async fn get_participation_events( &self ) -> Result<HashMap<ParticipationEventId, ParticipationEventWithNodes>>
Retrieves information for all registered participation events.
sourcepub async fn get_participation_event_ids(
&self,
node: &Node,
event_type: Option<ParticipationEventType>
) -> Result<Vec<ParticipationEventId>>
pub async fn get_participation_event_ids( &self, node: &Node, event_type: Option<ParticipationEventType> ) -> Result<Vec<ParticipationEventId>>
Retrieves IDs of all events tracked by the client options node.
sourcepub async fn get_participation_event_status(
&self,
id: &ParticipationEventId
) -> Result<ParticipationEventStatus>
pub async fn get_participation_event_status( &self, id: &ParticipationEventId ) -> Result<ParticipationEventStatus>
Retrieves the latest status of a given participation event.
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
sourcepub async fn vote(
&self,
event_id: impl Into<Option<ParticipationEventId>> + Send,
answers: impl Into<Option<Vec<u8>>> + Send
) -> Result<Transaction>
pub async fn vote( &self, event_id: impl Into<Option<ParticipationEventId>> + Send, answers: impl Into<Option<Vec<u8>>> + Send ) -> Result<Transaction>
Casts a given number of votes for a given (voting) event.
If voting for other events, continues voting for them. Removes metadata for any event that has expired (uses event IDs to get cached event information, checks event milestones in there against latest network milestone). If already voting for this event, overwrites existing output metadata. If existing voting output(s) do NOT have enough funds (or don’t exist), throws an error. If exceeds output metadata limit, throws an error (although better if automatically handled, but has UX implications). If event has expired, throws an error (do NOT remove previous votes).
This is an add OR update function, not just add. This should use regular client options, NOT specific node for the event.
sourcepub async fn prepare_vote(
&self,
event_id: impl Into<Option<ParticipationEventId>> + Send,
answers: impl Into<Option<Vec<u8>>> + Send
) -> Result<PreparedTransactionData>
pub async fn prepare_vote( &self, event_id: impl Into<Option<ParticipationEventId>> + Send, answers: impl Into<Option<Vec<u8>>> + Send ) -> Result<PreparedTransactionData>
Prepares the transaction for Account::vote().
sourcepub async fn stop_participating(
&self,
event_id: ParticipationEventId
) -> Result<Transaction>
pub async fn stop_participating( &self, event_id: ParticipationEventId ) -> Result<Transaction>
Removes metadata corresponding to a given (voting) event ID from the voting output if it contains it.
If voting for other events, continues voting for them. Removes metadata for any event that has expired (use event IDs to get cached event information, checks event milestones in there against latest network milestone). If NOT already voting for this event, throws an error.
sourcepub async fn prepare_stop_participating(
&self,
event_id: ParticipationEventId
) -> Result<PreparedTransactionData>
pub async fn prepare_stop_participating( &self, event_id: ParticipationEventId ) -> Result<PreparedTransactionData>
Prepares the transaction for Account::stop_participating().
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
sourcepub async fn get_voting_power(&self) -> Result<u64>
pub async fn get_voting_power(&self) -> Result<u64>
Returns an account’s total voting power (voting or NOT voting).
sourcepub async fn increase_voting_power(&self, amount: u64) -> Result<Transaction>
pub async fn increase_voting_power(&self, amount: u64) -> Result<Transaction>
Designates a given amount of tokens towards an account’s “voting power” by creating a special output, which is really a basic one with some metadata.
If not enough funds, throws an error.
If voting, use voting output (should only ever have one unless more space for more votes is needed).
This will stop voting in most cases (if there is a remainder), but the voting data isn’t lost and calling Vote
without parameters will revote. Removes metadata for any events that have expired (uses event IDs to get
cached event information, checks event milestones in there against latest network milestone).
Prioritizes consuming outputs that are designated for voting but don’t have any metadata (only possible if user
increases voting power then increases again immediately after).
sourcepub async fn prepare_increase_voting_power(
&self,
amount: u64
) -> Result<PreparedTransactionData>
pub async fn prepare_increase_voting_power( &self, amount: u64 ) -> Result<PreparedTransactionData>
Prepares the transaction for Account::increase_voting_power().
sourcepub async fn decrease_voting_power(&self, amount: u64) -> Result<Transaction>
pub async fn decrease_voting_power(&self, amount: u64) -> Result<Transaction>
Reduces an account’s “voting power” by a given amount.
This will stop voting, but the voting data isn’t lost and calling Vote
without parameters will revote.
If amount is higher than actual voting power, throws an error. If voting and amount is equal to voting power, removes tagged data payload and output metadata. Removes metadata for any events that have expired (uses event IDs to get cached event information, checks event milestones in there against latest network milestone). Prioritizes consuming outputs that are designated for voting but don’t have any metadata (only possible if user increases voting power then decreases immediately after).
sourcepub async fn prepare_decrease_voting_power(
&self,
amount: u64
) -> Result<PreparedTransactionData>
pub async fn prepare_decrease_voting_power( &self, amount: u64 ) -> Result<PreparedTransactionData>
Prepares the transaction for Account::decrease_voting_power().
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
sourcepub async fn get_participation_overview(
&self,
event_ids: Option<Vec<ParticipationEventId>>
) -> Result<AccountParticipationOverview>
pub async fn get_participation_overview( &self, event_ids: Option<Vec<ParticipationEventId>> ) -> Result<AccountParticipationOverview>
Calculates the voting overview of an account. If event_ids are provided, only return outputs and tracked participations for them.
sourcepub async fn get_voting_output(&self) -> Result<Option<OutputData>>
pub async fn get_voting_output(&self) -> Result<Option<OutputData>>
Returns the voting output (“PARTICIPATION” tag).
If multiple outputs with this tag exist, the one with the largest amount will be returned.
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
sourcepub async fn retry_until_included(
&self,
block_id: &BlockId,
interval: Option<u64>,
max_attempts: Option<u64>
) -> Result<Vec<(BlockId, Block)>>
pub async fn retry_until_included( &self, block_id: &BlockId, interval: Option<u64>, max_attempts: Option<u64> ) -> Result<Vec<(BlockId, Block)>>
Retries (promotes or reattaches) a block for provided block id until it’s included (referenced by a milestone). This function is re-exported from the client library and default interval is as defined there. Returns the included block at first position and additional reattached blocks
sourcepub async fn retry_transaction_until_included(
&self,
transaction_id: &TransactionId,
interval: Option<u64>,
max_attempts: Option<u64>
) -> Result<BlockId>
pub async fn retry_transaction_until_included( &self, transaction_id: &TransactionId, interval: Option<u64>, max_attempts: Option<u64> ) -> Result<BlockId>
Retries (promotes or reattaches) a transaction sent from the account for a provided transaction id until it’s included (referenced by a milestone). Returns the included block id.
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
sourcepub async fn set_default_sync_options(&self, options: SyncOptions) -> Result<()>
pub async fn set_default_sync_options(&self, options: SyncOptions) -> Result<()>
Set the fallback SyncOptions for account syncing. If storage is enabled, will persist during restarts.
pub async fn default_sync_options(&self) -> SyncOptions
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
sourcepub async fn melt_native_token(
&self,
token_id: TokenId,
melt_amount: impl Into<U256> + Send,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<Transaction>
pub async fn melt_native_token( &self, token_id: TokenId, melt_amount: impl Into<U256> + Send, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<Transaction>
Melts native tokens.
This happens with the foundry output which minted them, by increasing it’s
melted_tokens
field. This should be preferred over burning, because after burning, the foundry can never be
destroyed anymore.
sourcepub async fn prepare_melt_native_token(
&self,
token_id: TokenId,
melt_amount: impl Into<U256> + Send,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<PreparedTransactionData>
pub async fn prepare_melt_native_token( &self, token_id: TokenId, melt_amount: impl Into<U256> + Send, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<PreparedTransactionData>
Prepares the transaction for Account::melt_native_token().
source§impl Account
impl Account
sourcepub async fn burn(
&self,
burn: impl Into<Burn> + Send,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<Transaction>
pub async fn burn( &self, burn: impl Into<Burn> + Send, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<Transaction>
A generic function that can be used to burn native tokens, nfts, foundries and aliases.
Note that burning native tokens doesn’t require the foundry output which minted them, but will not increase
the foundries melted_tokens
field, which makes it impossible to destroy the foundry output. Therefore it’s
recommended to use melting, if the foundry output is available.
sourcepub async fn prepare_burn(
&self,
burn: impl Into<Burn> + Send,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<PreparedTransactionData>
pub async fn prepare_burn( &self, burn: impl Into<Burn> + Send, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<PreparedTransactionData>
A generic prepare_burn()
function that can be used to prepare the burn of native tokens, nfts, foundries and
aliases.
Note that burning native tokens doesn’t require the foundry output which minted them, but will not increase
the foundries melted_tokens
field, which makes it impossible to destroy the foundry output. Therefore it’s
recommended to use melting, if the foundry output is available.
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
sourcepub async fn create_alias_output(
&self,
params: Option<CreateAliasParams>,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<Transaction>
pub async fn create_alias_output( &self, params: Option<CreateAliasParams>, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<Transaction>
Creates an alias output.
let params = CreateAliasParams {
address: None,
immutable_metadata: Some(b"some immutable alias metadata".to_vec()),
metadata: Some(b"some alias metadata".to_vec()),
state_metadata: Some(b"some alias state metadata".to_vec()),
};
let transaction = account.create_alias_output(params, None).await?;
println!(
"Transaction sent: {}/transaction/{}",
std::env::var("EXPLORER_URL").unwrap(),
transaction.transaction_id
);
sourcepub async fn prepare_create_alias_output(
&self,
params: Option<CreateAliasParams>,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<PreparedTransactionData>
pub async fn prepare_create_alias_output( &self, params: Option<CreateAliasParams>, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<PreparedTransactionData>
Prepares the transaction for Account::create_alias_output().
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
sourcepub async fn create_native_token(
&self,
params: CreateNativeTokenParams,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<CreateNativeTokenTransaction>
pub async fn create_native_token( &self, params: CreateNativeTokenParams, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<CreateNativeTokenTransaction>
Creates a new foundry output with minted native tokens.
Calls Account::prepare_transaction() internally, the options may define the remainder value strategy or custom inputs.
let params = CreateNativeTokenParams {
alias_id: None,
circulating_supply: U256::from(100),
maximum_supply: U256::from(100),
foundry_metadata: None
};
let tx = account.create_native_token(params, None).await?;
println!("Transaction created: {}", tx.transaction_id);
if let Some(block_id) = tx.block_id {
println!("Block sent: {}", block_id);
}
sourcepub async fn prepare_create_native_token(
&self,
params: CreateNativeTokenParams,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<PreparedCreateNativeTokenTransaction>
pub async fn prepare_create_native_token( &self, params: CreateNativeTokenParams, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<PreparedCreateNativeTokenTransaction>
Prepares the transaction for Account::create_native_token().
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
sourcepub async fn mint_native_token(
&self,
token_id: TokenId,
mint_amount: impl Into<U256> + Send,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<Transaction>
pub async fn mint_native_token( &self, token_id: TokenId, mint_amount: impl Into<U256> + Send, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<Transaction>
Mints additional native tokens.
The max supply must not be reached yet. The foundry needs to be controlled by this account. Address needs to be Bech32 encoded. This will not change the max supply.
let tx = account.mint_native_token(
TokenId::from_str("08e68f7616cd4948efebc6a77c4f93aed770ac53860100000000000000000000000000000000")?,
100,
None
).await?;
println!("Transaction created: {}", tx.transaction_id);
if let Some(block_id) = tx.block_id {
println!("Block sent: {}", block_id);
}
sourcepub async fn prepare_mint_native_token(
&self,
token_id: TokenId,
mint_amount: impl Into<U256> + Send,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<PreparedTransactionData>
pub async fn prepare_mint_native_token( &self, token_id: TokenId, mint_amount: impl Into<U256> + Send, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<PreparedTransactionData>
Prepares the transaction for Account::mint_native_token().
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
sourcepub async fn mint_nfts<I: IntoIterator<Item = MintNftParams> + Send>(
&self,
params: I,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<Transaction>
pub async fn mint_nfts<I: IntoIterator<Item = MintNftParams> + Send>( &self, params: I, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<Transaction>
Mints NFTs.
Calls Account::prepare_transaction() internally. The options may define the remainder value strategy or custom inputs. Note that addresses need to be bech32-encoded.
let nft_id: [u8; 38] =
prefix_hex::decode("08e68f7616cd4948efebc6a77c4f93aed770ac53860100000000000000000000000000000000")?
.try_into()
.unwrap();
let params = [MintNftParams::new()
try_with_address("rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu")?
with_metadata(b"some nft metadata".to_vec())
with_immutable_metadata(b"some immutable nft metadata".to_vec())
];
let transaction = account.mint_nfts(params, None).await?;
println!(
"Transaction sent: {}/transaction/{}",
std::env::var("EXPLORER_URL").unwrap(),
transaction.transaction_id,
);
sourcepub async fn prepare_mint_nfts<I: IntoIterator<Item = MintNftParams> + Send>(
&self,
params: I,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<PreparedTransactionData>
pub async fn prepare_mint_nfts<I: IntoIterator<Item = MintNftParams> + Send>( &self, params: I, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<PreparedTransactionData>
Prepares the transaction for Account::mint_nfts().
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
sourcepub async fn send(
&self,
amount: u64,
address: impl ConvertTo<Bech32Address>,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<Transaction>
pub async fn send( &self, amount: u64, address: impl ConvertTo<Bech32Address>, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<Transaction>
Sends a certain amount of base coins to a single address.
Calls Account::send_with_params() internally.
The options may define the remainder value strategy or custom inputs.
The provided Addresses provided with SendParams
need to be bech32-encoded.
sourcepub async fn send_with_params<I: IntoIterator<Item = SendParams> + Send>(
&self,
params: I,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<Transaction>
pub async fn send_with_params<I: IntoIterator<Item = SendParams> + Send>( &self, params: I, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<Transaction>
Sends a certain amount of base coins with full customizability of the transaction.
Calls Account::send_outputs() internally.
The options may define the remainder value strategy or custom inputs.
Addresses provided with SendParams
need to be bech32-encoded.
let params = [SendParams::new(
"rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu",
1_000_000)?
];
let tx = account.send(params, None ).await?;
println!("Transaction created: {}", tx.transaction_id);
if let Some(block_id) = tx.block_id {
println!("Block sent: {}", block_id);
}
sourcepub async fn prepare_send<I: IntoIterator<Item = SendParams> + Send>(
&self,
params: I,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<PreparedTransactionData>
pub async fn prepare_send<I: IntoIterator<Item = SendParams> + Send>( &self, params: I, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<PreparedTransactionData>
Prepares the transaction for Account::send().
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
sourcepub async fn send_native_tokens<I: IntoIterator<Item = SendNativeTokensParams> + Send>(
&self,
params: I,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<Transaction>
pub async fn send_native_tokens<I: IntoIterator<Item = SendNativeTokensParams> + Send>( &self, params: I, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<Transaction>
Sends native tokens in basic outputs with a StorageDepositReturnUnlockCondition
and an
ExpirationUnlockCondition
, so that the storage deposit is returned to the sender and the sender gets access
to the output again after a predefined time (default 1 day).
Calls Account::send_outputs() internally. The options may define the
remainder value strategy or custom inputs. Note that the address needs to be bech32-encoded.
let params = [SendNativeTokensParams {
address: "rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu".to_string(),
native_tokens: vec![(
TokenId::from_str("08e68f7616cd4948efebc6a77c4f93aed770ac53860100000000000000000000000000000000")?,
U256::from(50),
)],
..Default::default()
}];
let tx = account.send_native_tokens(params, None).await?;
println!("Transaction created: {}", tx.transaction_id);
if let Some(block_id) = tx.block_id {
println!("Block sent: {}", block_id);
}
sourcepub async fn prepare_send_native_tokens<I: IntoIterator<Item = SendNativeTokensParams> + Send>(
&self,
params: I,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<PreparedTransactionData>
pub async fn prepare_send_native_tokens<I: IntoIterator<Item = SendNativeTokensParams> + Send>( &self, params: I, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<PreparedTransactionData>
Prepares the transaction for Account::send_native_tokens().
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
sourcepub async fn send_nft<I: IntoIterator<Item = SendNftParams> + Send>(
&self,
params: I,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<Transaction>
pub async fn send_nft<I: IntoIterator<Item = SendNftParams> + Send>( &self, params: I, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<Transaction>
Sends an NFT to the provided address. Calls Account::prepare_transaction() internally. The options may define the remainder value strategy. Note that custom inputs will be replaced with the required nft inputs and addresses need to be bech32-encoded.
let params = [SendNftParams::new(
"rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu",
"0xe645042a8a082957cb4bec4927936699ee8e56048834b090379da64213ce231b",
)?];
let transaction = account.send_nft(params, None).await?;
println!(
"Transaction sent: {}/transaction/{}",
std::env::var("EXPLORER_URL").unwrap(),
transaction.transaction_id
);
sourcepub async fn prepare_send_nft<I: IntoIterator<Item = SendNftParams> + Send>(
&self,
params: I,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<PreparedTransactionData>
pub async fn prepare_send_nft<I: IntoIterator<Item = SendNftParams> + Send>( &self, params: I, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<PreparedTransactionData>
Prepares the transaction for Account::send_nft().
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
sourcepub async fn prepare_output(
&self,
params: OutputParams,
transaction_options: impl Into<Option<TransactionOptions>> + Send
) -> Result<Output>
pub async fn prepare_output( &self, params: OutputParams, transaction_options: impl Into<Option<TransactionOptions>> + Send ) -> Result<Output>
Prepare a basic or NFT output for sending
If the amount is below the minimum required storage deposit, by default the remaining amount will automatically
be added with a StorageDepositReturn UnlockCondition, when setting the ReturnStrategy to gift
, the full
minimum required storage deposit will be sent to the recipient.
When the assets contain an nft_id, the data from the existing nft output will be used, just with the address
unlock conditions replaced
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
sourcepub async fn prepare_transaction(
&self,
outputs: impl Into<Vec<Output>> + Send,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<PreparedTransactionData>
pub async fn prepare_transaction( &self, outputs: impl Into<Vec<Output>> + Send, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<PreparedTransactionData>
Get inputs and build the transaction essence
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
sourcepub async fn sign_transaction_essence(
&self,
prepared_transaction_data: &PreparedTransactionData
) -> Result<SignedTransactionData>
pub async fn sign_transaction_essence( &self, prepared_transaction_data: &PreparedTransactionData ) -> Result<SignedTransactionData>
Signs a transaction essence.
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
sourcepub async fn send_outputs(
&self,
outputs: impl Into<Vec<Output>> + Send,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<Transaction>
pub async fn send_outputs( &self, outputs: impl Into<Vec<Output>> + Send, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<Transaction>
Sends a transaction by specifying its outputs.
Note that, if sending a block fails, the method will return None
for the block id, but the wallet
will retry sending the transaction during syncing.
let outputs = [
BasicOutputBuilder::new_with_amount(1_000_000)?
.add_unlock_condition(AddressUnlockCondition::new(
Address::try_from_bech32("rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu")?,
))
.finish_output(account.client.get_token_supply().await?;)?,
];
let tx = account
.send_outputs(
outputs,
Some(TransactionOptions {
remainder_value_strategy: RemainderValueStrategy::ReuseAddress,
..Default::default()
}),
)
.await?;
println!("Transaction created: {}", tx.transaction_id);
if let Some(block_id) = tx.block_id {
println!("Block sent: {}", block_id);
}
sourcepub async fn finish_transaction(
&self,
outputs: impl Into<Vec<Output>> + Send,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<Transaction>
pub async fn finish_transaction( &self, outputs: impl Into<Vec<Output>> + Send, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<Transaction>
Separated function from send, so syncing isn’t called recursively with the consolidation function, which sends transactions
sourcepub async fn sign_and_submit_transaction(
&self,
prepared_transaction_data: PreparedTransactionData,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<Transaction>
pub async fn sign_and_submit_transaction( &self, prepared_transaction_data: PreparedTransactionData, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<Transaction>
Signs a transaction, submit it to a node and store it in the account
sourcepub async fn submit_and_store_transaction(
&self,
signed_transaction_data: SignedTransactionData,
options: impl Into<Option<TransactionOptions>> + Send
) -> Result<Transaction>
pub async fn submit_and_store_transaction( &self, signed_transaction_data: SignedTransactionData, options: impl Into<Option<TransactionOptions>> + Send ) -> Result<Transaction>
Validates the transaction, submit it to a node and store it in the account
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
source§impl<S: SecretManage> Account<S>
impl<S: SecretManage> Account<S>
pub fn get_secret_manager(&self) -> &Arc<RwLock<S>>
source§impl<S: 'static + SecretManage> Account<S>
impl<S: 'static + SecretManage> Account<S>
Methods from Deref<Target = AccountInner>§
pub async fn details(&self) -> RwLockReadGuard<'_, AccountDetails>
pub async fn details_mut(&self) -> RwLockWriteGuard<'_, AccountDetails>
pub async fn alias(&self) -> String
sourcepub async fn get_output(&self, output_id: &OutputId) -> Option<OutputData>
pub async fn get_output(&self, output_id: &OutputId) -> Option<OutputData>
Get the OutputData
of an output stored in the account
sourcepub async fn get_transaction(
&self,
transaction_id: &TransactionId
) -> Option<Transaction>
pub async fn get_transaction( &self, transaction_id: &TransactionId ) -> Option<Transaction>
Get the Transaction
of a transaction stored in the account
sourcepub async fn get_incoming_transaction(
&self,
transaction_id: &TransactionId
) -> Option<Transaction>
pub async fn get_incoming_transaction( &self, transaction_id: &TransactionId ) -> Option<Transaction>
Get the transaction with inputs of an incoming transaction stored in the account List might not be complete, if the node pruned the data already
sourcepub async fn addresses(&self) -> Result<Vec<AccountAddress>>
pub async fn addresses(&self) -> Result<Vec<AccountAddress>>
Returns all addresses of the account
sourcepub async fn addresses_with_unspent_outputs(
&self
) -> Result<Vec<AddressWithUnspentOutputs>>
pub async fn addresses_with_unspent_outputs( &self ) -> Result<Vec<AddressWithUnspentOutputs>>
Returns only addresses of the account with balance
sourcepub async fn outputs(
&self,
filter: impl Into<Option<FilterOptions>> + Send
) -> Result<Vec<OutputData>>
pub async fn outputs( &self, filter: impl Into<Option<FilterOptions>> + Send ) -> Result<Vec<OutputData>>
Returns outputs of the account
sourcepub async fn unspent_outputs(
&self,
filter: impl Into<Option<FilterOptions>> + Send
) -> Result<Vec<OutputData>>
pub async fn unspent_outputs( &self, filter: impl Into<Option<FilterOptions>> + Send ) -> Result<Vec<OutputData>>
Returns unspent outputs of the account
sourcepub async fn unspent_alias_output(
&self,
alias_id: &AliasId
) -> Result<Option<OutputData>>
pub async fn unspent_alias_output( &self, alias_id: &AliasId ) -> Result<Option<OutputData>>
Gets the unspent alias output matching the given ID.
sourcepub async fn unspent_foundry_output(
&self,
foundry_id: &FoundryId
) -> Result<Option<OutputData>>
pub async fn unspent_foundry_output( &self, foundry_id: &FoundryId ) -> Result<Option<OutputData>>
Gets the unspent foundry output matching the given ID.
sourcepub async fn unspent_nft_output(
&self,
nft_id: &NftId
) -> Result<Option<OutputData>>
pub async fn unspent_nft_output( &self, nft_id: &NftId ) -> Result<Option<OutputData>>
Gets the unspent nft output matching the given ID.
sourcepub async fn incoming_transactions(&self) -> Vec<Transaction>
pub async fn incoming_transactions(&self) -> Vec<Transaction>
Returns all incoming transactions of the account
sourcepub async fn transactions(&self) -> Vec<Transaction>
pub async fn transactions(&self) -> Vec<Transaction>
Returns all transactions of the account
sourcepub async fn pending_transactions(&self) -> Vec<Transaction>
pub async fn pending_transactions(&self) -> Vec<Transaction>
Returns all pending transactions of the account
Trait Implementations§
source§impl<S: SecretManage> Clone for Account<S>
impl<S: SecretManage> Clone for Account<S>
Auto Trait Implementations§
impl<S> Freeze for Account<S>
impl<S = SecretManager> !RefUnwindSafe for Account<S>
impl<S> Send for Account<S>
impl<S> Sync for Account<S>
impl<S> Unpin for Account<S>
impl<S = SecretManager> !UnwindSafe for Account<S>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more