Struct iota_wallet::account::handle::AccountHandle
source · [−]pub struct AccountHandle {
account: Arc<RwLock<Account>>,
pub(crate) client: Client,
pub(crate) secret_manager: Arc<RwLock<SecretManager>>,
pub(crate) last_synced: Arc<Mutex<u128>>,
pub(crate) event_emitter: Arc<Mutex<EventEmitter>>,
pub(crate) storage_manager: Arc<Mutex<StorageManager>>,
}
Expand description
A thread guard over an account, so we can lock the account during operations.
Fields
account: Arc<RwLock<Account>>
client: Client
secret_manager: Arc<RwLock<SecretManager>>
last_synced: Arc<Mutex<u128>>
event_emitter: Arc<Mutex<EventEmitter>>
storage_manager: Arc<Mutex<StorageManager>>
Implementations
sourceimpl AccountHandle
impl AccountHandle
sourcepub(crate) fn new(
account: Account,
client: Client,
secret_manager: Arc<RwLock<SecretManager>>,
event_emitter: Arc<Mutex<EventEmitter>>,
storage_manager: Arc<Mutex<StorageManager>>
) -> Self
pub(crate) fn new(
account: Account,
client: Client,
secret_manager: Arc<RwLock<SecretManager>>,
event_emitter: Arc<Mutex<EventEmitter>>,
storage_manager: Arc<Mutex<StorageManager>>
) -> Self
Create a new AccountHandle with an Account
pub async fn alias(&self) -> String
pub fn client(&self) -> &Client
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_foundry_output(
&self,
native_token_id: TokenId
) -> Result<Output>
pub async fn get_foundry_output(
&self,
native_token_id: TokenId
) -> Result<Output>
Get the [Output
] that minted a native token by the token ID. First try to get it
from the account, if it isn’t in the account try to get it from the node
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_data(
&self,
transaction_id: &TransactionId
) -> Option<(TransactionPayload, Vec<OutputResponse>)>
pub async fn get_incoming_transaction_data(
&self,
transaction_id: &TransactionId
) -> Option<(TransactionPayload, Vec<OutputResponse>)>
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 list_addresses(&self) -> Result<Vec<AccountAddress>>
pub async fn list_addresses(&self) -> Result<Vec<AccountAddress>>
Returns all addresses of the account
sourcepub async fn list_addresses_with_unspent_outputs(
&self
) -> Result<Vec<AddressWithUnspentOutputs>>
pub async fn list_addresses_with_unspent_outputs(
&self
) -> Result<Vec<AddressWithUnspentOutputs>>
Returns only addresses of the account with balance
sourcepub async fn list_outputs(
&self,
filter: Option<FilterOptions>
) -> Result<Vec<OutputData>>
pub async fn list_outputs(
&self,
filter: Option<FilterOptions>
) -> Result<Vec<OutputData>>
Returns outputs of the account
sourcepub async fn list_unspent_outputs(
&self,
filter: Option<FilterOptions>
) -> Result<Vec<OutputData>>
pub async fn list_unspent_outputs(
&self,
filter: Option<FilterOptions>
) -> Result<Vec<OutputData>>
Returns unspent outputs of the account
sourcepub async fn list_incoming_transactions(
&self
) -> Result<HashMap<TransactionId, (TransactionPayload, Vec<OutputResponse>)>>
pub async fn list_incoming_transactions(
&self
) -> Result<HashMap<TransactionId, (TransactionPayload, Vec<OutputResponse>)>>
Returns all incoming transactions of the account
sourcepub async fn list_transactions(&self) -> Result<Vec<Transaction>>
pub async fn list_transactions(&self) -> Result<Vec<Transaction>>
Returns all transactions of the account
sourcepub async fn list_pending_transactions(&self) -> Result<Vec<Transaction>>
pub async fn list_pending_transactions(&self) -> Result<Vec<Transaction>>
Returns all pending transactions of the account
sourceimpl AccountHandle
impl AccountHandle
sourcepub async fn generate_addresses(
&self,
amount: u32,
options: Option<AddressGenerationOptions>
) -> Result<Vec<AccountAddress>>
pub async fn generate_addresses(
&self,
amount: u32,
options: Option<AddressGenerationOptions>
) -> Result<Vec<AccountAddress>>
Generate addresses and stores them in the account
let public_addresses = account_handle.generate_addresses(2, None).await?;
// internal addresses are used for remainder outputs, if the RemainderValueStrategy for transactions is set to ChangeAddress
let internal_addresses = account_handle
.generate_addresses(
1,
Some(AddressGenerationOptions {
internal: true,
..Default::default()
}),
)
.await?;
sourcepub(crate) async fn generate_remainder_address(&self) -> Result<AccountAddress>
pub(crate) async fn generate_remainder_address(&self) -> Result<AccountAddress>
Generate an internal address and store in the account, internal addresses are used for remainder outputs
sourceimpl AccountHandle
impl AccountHandle
sourcepub async fn balance(&self) -> Result<AccountBalance>
pub async fn balance(&self) -> Result<AccountBalance>
Get the AccountBalance
sourceimpl AccountHandle
impl AccountHandle
sourcepub async fn get_unlockable_outputs_with_additional_unlock_conditions(
&self,
outputs_to_claim: OutputsToClaim
) -> Result<Vec<OutputId>>
pub async fn get_unlockable_outputs_with_additional_unlock_conditions(
&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 get_basic_outputs_for_additional_inputs(
&self
) -> Result<Vec<OutputData>>
pub async fn get_basic_outputs_for_additional_inputs(
&self
) -> Result<Vec<OutputData>>
Get basic outputs that have only one unlock condition which is [AddressUnlockCondition], so they can be used as additional inputs
sourcepub async fn claim_outputs(
&self,
output_ids_to_claim: Vec<OutputId>
) -> Result<Transaction>
pub async fn claim_outputs(
&self,
output_ids_to_claim: Vec<OutputId>
) -> Result<Transaction>
Try to claim basic or nft outputs that have additional unlock conditions to their [AddressUnlockCondition]
from AccountHandle::get_unlockable_outputs_with_additional_unlock_conditions()
.
sourcepub(crate) async fn claim_outputs_internal(
&self,
output_ids_to_claim: Vec<OutputId>,
possible_additional_inputs: Vec<OutputData>
) -> Result<Transaction>
pub(crate) async fn claim_outputs_internal(
&self,
output_ids_to_claim: Vec<OutputId>,
possible_additional_inputs: Vec<OutputData>
) -> Result<Transaction>
Try to claim basic outputs that have additional unlock conditions to their [AddressUnlockCondition].
sourceimpl AccountHandle
impl AccountHandle
sourcepub async fn consolidate_outputs(
self: &AccountHandle,
force: bool,
output_consolidation_threshold: Option<usize>
) -> Result<Transaction>
pub async fn consolidate_outputs(
self: &AccountHandle,
force: bool,
output_consolidation_threshold: Option<usize>
) -> Result<Transaction>
Consolidate basic outputs with only an [AddressUnlockCondition] from an account by sending them to an own
address again if the output amount is >= the output_consolidation_threshold. When force
is set to true
, the
threshold is ignored. Only consolidates the amount of outputs that fit into a single transaction.
sourceimpl AccountHandle
impl AccountHandle
sourcepub(crate) async fn search_addresses_with_outputs(
self: &AccountHandle,
address_gap_limit: u32,
sync_options: Option<SyncOptions>
) -> Result<usize>
pub(crate) async fn search_addresses_with_outputs(
self: &AccountHandle,
address_gap_limit: u32,
sync_options: Option<SyncOptions>
) -> Result<usize>
Search addresses with unspent outputs
address_gap_limit
: The number of addresses to search for, after the last address with unspent outputs
Addresses that got crated during this operation and have a higher key_index than the latest one with outputs,
will be removed again, to keep the account size smaller
sourceasync fn clean_account_after_recovery(
&self,
old_highest_public_address_index: u32,
old_highest_internal_address_index: Option<u32>
) -> AccountHandle
async fn clean_account_after_recovery(
&self,
old_highest_public_address_index: u32,
old_highest_internal_address_index: Option<u32>
) -> AccountHandle
During search_addresses_with_outputs we created new addresses that don’t have funds, so we remove them again.
sourceimpl AccountHandle
impl AccountHandle
sourcepub(crate) async fn get_addresses_to_sync(
&self,
options: &SyncOptions
) -> Result<Vec<AddressWithUnspentOutputs>>
pub(crate) async fn get_addresses_to_sync(
&self,
options: &SyncOptions
) -> Result<Vec<AddressWithUnspentOutputs>>
Get the addresses that should be synced with the current known unspent output ids
Also adds alias and nft addresses from unspent alias or nft outputs that have no Timelock, Expiration or
StorageDepositReturn [UnlockCondition
]
sourcepub(crate) async fn get_address_output_ids(
&self,
options: &SyncOptions,
addresses_with_unspent_outputs: Vec<AddressWithUnspentOutputs>
) -> Result<(Vec<AddressWithUnspentOutputs>, Vec<OutputId>)>
pub(crate) async fn get_address_output_ids(
&self,
options: &SyncOptions,
addresses_with_unspent_outputs: Vec<AddressWithUnspentOutputs>
) -> Result<(Vec<AddressWithUnspentOutputs>, Vec<OutputId>)>
Get the current output ids for provided addresses and only returns addresses that have unspent outputs and return spent outputs separated
sourcepub(crate) async fn get_addresses_outputs(
&self,
addresses_with_unspent_outputs: Vec<AddressWithUnspentOutputs>
) -> Result<(Vec<AddressWithUnspentOutputs>, Vec<OutputData>)>
pub(crate) async fn get_addresses_outputs(
&self,
addresses_with_unspent_outputs: Vec<AddressWithUnspentOutputs>
) -> Result<(Vec<AddressWithUnspentOutputs>, Vec<OutputData>)>
Get outputs from addresses
sourcepub(crate) async fn request_address_output_ids(
&self,
client: &Client,
address: AddressWithUnspentOutputs,
sync_options: &SyncOptions
) -> Result<(AddressWithUnspentOutputs, Vec<OutputId>)>
pub(crate) async fn request_address_output_ids(
&self,
client: &Client,
address: AddressWithUnspentOutputs,
sync_options: &SyncOptions
) -> Result<(AddressWithUnspentOutputs, Vec<OutputId>)>
Returns output ids for outputs that are directly (Ed25519 address in AddressUnlockCondition) or indirectly (alias/nft address in AddressUnlockCondition and the alias/nft output is controlled with the Ed25519 address) connected to
sourceimpl AccountHandle
impl AccountHandle
sourcepub(crate) async fn output_response_to_output_data(
&self,
output_responses: Vec<OutputResponse>,
associated_address: &AddressWithUnspentOutputs
) -> Result<Vec<OutputData>>
pub(crate) async fn output_response_to_output_data(
&self,
output_responses: Vec<OutputResponse>,
associated_address: &AddressWithUnspentOutputs
) -> Result<Vec<OutputData>>
Convert OutputResponse to OutputData with the network_id added
sourcepub(crate) async fn get_outputs(
&self,
output_ids: Vec<OutputId>,
spent_outputs: bool
) -> Result<(Vec<OutputResponse>, Vec<OutputResponse>)>
pub(crate) async fn get_outputs(
&self,
output_ids: Vec<OutputId>,
spent_outputs: bool
) -> Result<(Vec<OutputResponse>, Vec<OutputResponse>)>
Gets outputs by their id, already known outputs are not requested again, but loaded from the account set as unspent, because we wouldn’t get them from the node if they were spent New requested output responses are returned and old ones separated with their accumulated balance
pub(crate) async fn request_incoming_transaction_data(
&self,
transaction_ids: Vec<TransactionId>
) -> Result<()>
sourceimpl AccountHandle
impl AccountHandle
sourcepub(crate) async fn sync_pending_transactions(&self) -> Result<()>
pub(crate) async fn sync_pending_transactions(&self) -> Result<()>
Sync transactions and reattach them if unconfirmed. Returns the transaction with updated metadata and spent output ids that don’t need to be locked anymore
sourceimpl AccountHandle
impl AccountHandle
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 in iota.rs. Returns the included block at first position and additional reattached blocks
sourcepub async fn sync(&self, options: Option<SyncOptions>) -> Result<AccountBalance>
pub async fn sync(&self, options: Option<SyncOptions>) -> Result<AccountBalance>
Sync the account by fetching new information from the nodes. Will also retry pending transactions if necessary.
sourceimpl AccountHandle
impl AccountHandle
sourcepub(crate) async fn build_transaction_essence(
&self,
selected_transaction_data: SelectedTransactionData,
options: Option<TransactionOptions>
) -> Result<PreparedTransactionData>
pub(crate) async fn build_transaction_essence(
&self,
selected_transaction_data: SelectedTransactionData,
options: Option<TransactionOptions>
) -> Result<PreparedTransactionData>
Function to build the transaction essence from the selected in and outputs
sourceimpl AccountHandle
impl AccountHandle
sourcepub async fn burn_native_token(
&self,
token_id: TokenId,
burn_amount: U256,
options: Option<TransactionOptions>
) -> Result<Transaction>
pub async fn burn_native_token(
&self,
token_id: TokenId,
burn_amount: U256,
options: Option<TransactionOptions>
) -> Result<Transaction>
Function to burn native tokens. This 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.
async fn get_burn_inputs_and_outputs(
&self,
token_id: TokenId,
burn_token_amount: U256
) -> Result<StrippedOutputAggregate>
sourceasync fn aggregate_stripped_alias_and_foundry_outputs(
&self,
token_id: TokenId,
burn_token_amount: U256,
stripped_foundry_output: Vec<StrippedOutput>,
stripped_alias_outputs: HashMap<AliasId, StrippedOutput>
) -> Result<StrippedOutputAggregate>
async fn aggregate_stripped_alias_and_foundry_outputs(
&self,
token_id: TokenId,
burn_token_amount: U256,
stripped_foundry_output: Vec<StrippedOutput>,
stripped_alias_outputs: HashMap<AliasId, StrippedOutput>
) -> Result<StrippedOutputAggregate>
Aggregate foundry and alias outputs that sum up to
required burn_token_amount
, if controlling alias doesn’t have
the specified native token it’s added anyways for unlock purpose
async fn add_controlling_alias_to_aggregate(
&self,
alias_id: AliasId,
aggregate: &mut StrippedOutputAggregate,
stripped_alias_outputs: &mut HashMap<AliasId, StrippedOutput>
) -> Result<bool>
sourceimpl AccountHandle
impl AccountHandle
sourcepub async fn burn_nft(
&self,
nft_id: NftId,
options: Option<TransactionOptions>
) -> Result<Transaction>
pub async fn burn_nft(
&self,
nft_id: NftId,
options: Option<TransactionOptions>
) -> Result<Transaction>
Function to burn an nft output. Outputs controlled by it will be sweeped before if they don’t have a storage deposit return, timelock or expiration unlock condition.
async fn output_id_and_basic_output_for_nft(
&self,
nft_id: NftId
) -> Result<(OutputId, Output)>
sourceimpl AccountHandle
impl AccountHandle
sourcepub async fn decrease_native_token_supply(
&self,
token_id: TokenId,
melt_amount: U256,
options: Option<TransactionOptions>
) -> Result<Transaction>
pub async fn decrease_native_token_supply(
&self,
token_id: TokenId,
melt_amount: U256,
options: Option<TransactionOptions>
) -> Result<Transaction>
Function to melt 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.
sourceimpl AccountHandle
impl AccountHandle
sourcepub async fn destroy_alias(
&self,
alias_id: AliasId,
options: Option<TransactionOptions>
) -> Result<Transaction>
pub async fn destroy_alias(
&self,
alias_id: AliasId,
options: Option<TransactionOptions>
) -> Result<Transaction>
Function to destroy an alias output. Outputs controlled by it will be sweeped before if they don’t have a storage deposit return, timelock or expiration unlock condition. The amount and possible native tokens will be sent to the governor address.
async fn output_id_and_basic_output_for_alias(
&self,
alias_id: AliasId
) -> Result<(OutputId, Output)>
sourceimpl AccountHandle
impl AccountHandle
sourcepub async fn destroy_foundry(
&self,
foundry_id: FoundryId,
options: Option<TransactionOptions>
) -> Result<Transaction>
pub async fn destroy_foundry(
&self,
foundry_id: FoundryId,
options: Option<TransactionOptions>
) -> Result<Transaction>
Function to destroy a foundry output with a circulating supply of 0. Native tokens in the foundry (minted by other foundries) will be transactioned to the controlling alias
sourcepub async fn destroy_foundries(
&self,
foundry_ids: HashSet<FoundryId>,
options: Option<TransactionOptions>
) -> Result<Vec<TransactionId>>
pub async fn destroy_foundries(
&self,
foundry_ids: HashSet<FoundryId>,
options: Option<TransactionOptions>
) -> Result<Vec<TransactionId>>
Destroy all foundries in the given set foundry_ids
sourcepub(super) async fn find_alias_and_foundry_output_data(
&self,
alias_id: AliasId,
foundry_id: FoundryId
) -> Result<(OutputData, OutputData)>
pub(super) async fn find_alias_and_foundry_output_data(
&self,
alias_id: AliasId,
foundry_id: FoundryId
) -> Result<(OutputData, OutputData)>
Find and return unspent OutputData
for given alias_id
and foundry_id
sourceimpl AccountHandle
impl AccountHandle
pub(crate) async fn get_sweep_remainder_address(
&self,
options: &Option<TransactionOptions>
) -> Result<AddressWrapper>
async fn output_id_and_nft_output(
&self,
nft_id: NftId
) -> Result<(OutputId, NftOutput)>
async fn output_id_and_next_alias_output_state(
&self,
alias_id: AliasId
) -> Result<(OutputId, AliasOutput)>
pub(crate) fn sweep_address_outputs<'a>(
&'a self,
address: Address,
remainder_address: &'a AddressWrapper
) -> Pin<Box<dyn Future<Output = Result<Vec<TransactionId>>> + Send + 'a>>
pub(crate) async fn send_sweep_transaction(
&self,
address: AddressWrapper,
output_ids: impl IntoIterator<Item = OutputId>,
outputs: impl IntoIterator<Item = Output>
) -> Result<TransactionId>
sourceasync fn fetch_governor_address_alias_outputs(
&self,
address: &AddressWrapper
) -> Result<Vec<OutputResponse>>
async fn fetch_governor_address_alias_outputs(
&self,
address: &AddressWrapper
) -> Result<Vec<OutputResponse>>
Fetches alias outputs with address
set as Governor unlock condition
sourceasync fn fetch_address_basic_outputs(
&self,
address: &AddressWrapper
) -> Result<Vec<OutputResponse>>
async fn fetch_address_basic_outputs(
&self,
address: &AddressWrapper
) -> Result<Vec<OutputResponse>>
Fetches basic outputs with address unlock conditions only
sourceasync fn fetch_address_nft_outputs(
&self,
address: &AddressWrapper
) -> Result<Vec<OutputResponse>>
async fn fetch_address_nft_outputs(
&self,
address: &AddressWrapper
) -> Result<Vec<OutputResponse>>
Fetches nft outputs with address unlock conditions only
sourceasync fn update_unspent_output(
&self,
output_response: OutputResponse,
output_id: OutputId,
network_id: u64
) -> Result<()>
async fn update_unspent_output(
&self,
output_response: OutputResponse,
output_id: OutputId,
network_id: u64
) -> Result<()>
Update unspent output, this function is originally intended for updating recursively synced alias and nft address output
async fn sweep_foundries(
&self,
hrp: &str,
alias_address: &AliasAddress
) -> Result<Vec<TransactionId>>
sourceimpl AccountHandle
impl AccountHandle
sourcepub async fn increase_native_token_supply(
&self,
token_id: TokenId,
mint_amount: U256,
_increase_native_token_supply_options: Option<IncreaseNativeTokenSupplyOptions>,
options: Option<TransactionOptions>
) -> Result<MintTokenTransaction>
pub async fn increase_native_token_supply(
&self,
token_id: TokenId,
mint_amount: U256,
_increase_native_token_supply_options: Option<IncreaseNativeTokenSupplyOptions>,
options: Option<TransactionOptions>
) -> Result<MintTokenTransaction>
Function to mint more native tokens when the max supply isn’t 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_handle.increase_native_token_supply(
TokenId::from_str("08e68f7616cd4948efebc6a77c4f93aed770ac53860100000000000000000000000000000000")?,
U256::from(100),
native_token_options,
None
).await?;
println!("Transaction created: {}", tx.transaction_id);
if let Some(block_id) = tx.block_id {
println!("Block sent: {}", block_id);
}
sourceimpl AccountHandle
impl AccountHandle
sourcepub async fn mint_native_token(
&self,
native_token_options: NativeTokenOptions,
options: Option<TransactionOptions>
) -> Result<MintTokenTransaction>
pub async fn mint_native_token(
&self,
native_token_options: NativeTokenOptions,
options: Option<TransactionOptions>
) -> Result<MintTokenTransaction>
Function to mint native tokens This happens in a two step process:
- Create or get an existing alias output
- Create a new foundry output with native tokens minted to the account address Calls AccountHandle.send() internally, the options can define the RemainderValueStrategy or custom inputs. Address needs to be Bech32 encoded
let native_token_options = NativeTokenOptions {
account_address: None,
circulating_supply: U256::from(100),
maximum_supply: U256::from(100),
foundry_metadata: None
};
let tx = account_handle.mint_native_token(native_token_options, None,).await?;
println!("Transaction created: {}", tx.transaction_id);
if let Some(block_id) = tx.block_id {
println!("Block sent: {}", block_id);
}
sourcepub(crate) async fn get_or_create_alias_output(
&self,
controller_address: Address,
options: Option<TransactionOptions>
) -> Result<AliasId>
pub(crate) async fn get_or_create_alias_output(
&self,
controller_address: Address,
options: Option<TransactionOptions>
) -> Result<AliasId>
Get an existing alias output or create a new one
sourceimpl AccountHandle
impl AccountHandle
sourcepub async fn mint_nfts(
&self,
nfts_options: Vec<NftOptions>,
options: Option<TransactionOptions>
) -> Result<Transaction>
pub async fn mint_nfts(
&self,
nfts_options: Vec<NftOptions>,
options: Option<TransactionOptions>
) -> Result<Transaction>
Function to mint nfts. Calls AccountHandle.send() internally, the options can define the RemainderValueStrategy or custom inputs. Address needs to be Bech32 encoded
let nft_id: [u8; 38] =
prefix_hex::decode("08e68f7616cd4948efebc6a77c4f93aed770ac53860100000000000000000000000000000000")?
.try_into()
.unwrap();
let nft_options = vec![NftOptions {
address: Some("rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu".to_string()),
immutable_metadata: Some(b"some immutable nft metadata".to_vec()),
metadata: Some(b"some nft metadata".to_vec()),
}];
let transaction = account.mint_nfts(nft_options, None).await?;
println!(
"Transaction: {} Block sent: http://localhost:14265/api/core/v2/blocks/{}",
transaction.transaction_id,
transaction.block_id.expect("no block created yet")
);
sourceasync fn prepare_mint_nfts(
&self,
nfts_options: Vec<NftOptions>,
options: Option<TransactionOptions>
) -> Result<PreparedTransactionData>
async fn prepare_mint_nfts(
&self,
nfts_options: Vec<NftOptions>,
options: Option<TransactionOptions>
) -> Result<PreparedTransactionData>
Function to prepare the transaction for AccountHandle.mint_nfts()
sourceimpl AccountHandle
impl AccountHandle
sourcepub async fn send_amount(
&self,
addresses_with_amount: Vec<AddressWithAmount>,
options: Option<TransactionOptions>
) -> Result<Transaction>
pub async fn send_amount(
&self,
addresses_with_amount: Vec<AddressWithAmount>,
options: Option<TransactionOptions>
) -> Result<Transaction>
Function to create basic outputs with which we then will call AccountHandle.send(), the options can define the RemainderValueStrategy or custom inputs. Address needs to be Bech32 encoded
let outputs = vec![AddressWithAmount{
address: "rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu".to_string(),
amount: 1_000_000,
}];
let tx = account_handle.send_amount(outputs, 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_amount(
&self,
addresses_with_amount: Vec<AddressWithAmount>,
options: Option<TransactionOptions>
) -> Result<PreparedTransactionData>
pub async fn prepare_send_amount(
&self,
addresses_with_amount: Vec<AddressWithAmount>,
options: Option<TransactionOptions>
) -> Result<PreparedTransactionData>
Function to prepare the transaction for AccountHandle.send_amount()
sourceimpl AccountHandle
impl AccountHandle
sourcepub async fn send_micro_transaction(
&self,
addresses_with_micro_amount: Vec<AddressWithMicroAmount>,
options: Option<TransactionOptions>
) -> Result<Transaction>
pub async fn send_micro_transaction(
&self,
addresses_with_micro_amount: Vec<AddressWithMicroAmount>,
options: Option<TransactionOptions>
) -> Result<Transaction>
Function to send micro transactions by using the [StorageDepositReturnUnlockCondition] with an [ExpirationUnlockCondition]. Will call AccountHandle.send(), the options can define the RemainderValueStrategy or custom inputs. Address needs to be Bech32 encoded
let outputs = vec![AddressWithMicroAmount{
address: "rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu".to_string(),
amount: 1,
return_address: None,
expiration: None,
}];
let transaction = account_handle.send_micro_transaction(outputs, None ).await?;
println!(
"Transaction: {} Block sent: http://localhost:14265/api/core/v2/blocks/{}",
transaction.transaction_id,
transaction.block_id.expect("no block created yet")
);
sourceasync fn prepare_send_micro_transaction(
&self,
addresses_with_micro_amount: Vec<AddressWithMicroAmount>,
options: Option<TransactionOptions>
) -> Result<PreparedTransactionData>
async fn prepare_send_micro_transaction(
&self,
addresses_with_micro_amount: Vec<AddressWithMicroAmount>,
options: Option<TransactionOptions>
) -> Result<PreparedTransactionData>
Function to prepare the transaction for AccountHandle.send_micro_transaction()
sourceimpl AccountHandle
impl AccountHandle
sourcepub async fn send_native_tokens(
&self,
addresses_native_tokens: Vec<AddressNativeTokens>,
options: Option<TransactionOptions>
) -> Result<Transaction>
pub async fn send_native_tokens(
&self,
addresses_native_tokens: Vec<AddressNativeTokens>,
options: Option<TransactionOptions>
) -> Result<Transaction>
Function to send native tokens in basic outputs with a [StorageDepositReturnUnlockCondition] and [ExpirationUnlockCondition], so the storage deposit gets back to the sender and also that the sender gets access to the output again after a defined time (default 1 day), Calls AccountHandle.send() internally, the options can define the RemainderValueStrategy or custom inputs. Address needs to be Bech32 encoded
let outputs = vec![AddressNativeTokens {
address: "rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu".to_string(),
native_tokens: vec![(
TokenId::from_str("08e68f7616cd4948efebc6a77c4f93aed770ac53860100000000000000000000000000000000")?,
U256::from(50),
)],
..Default::default()
}];
let tx = account_handle.send_native_tokens(outputs, None).await?;
println!("Transaction created: {}", tx.transaction_id);
if let Some(block_id) = tx.block_id {
println!("Block sent: {}", block_id);
}
sourceasync fn prepare_send_native_tokens(
&self,
addresses_native_tokens: Vec<AddressNativeTokens>,
options: Option<TransactionOptions>
) -> Result<PreparedTransactionData>
async fn prepare_send_native_tokens(
&self,
addresses_native_tokens: Vec<AddressNativeTokens>,
options: Option<TransactionOptions>
) -> Result<PreparedTransactionData>
Function to prepare the transaction for AccountHandle.send_native_tokens()
sourceimpl AccountHandle
impl AccountHandle
sourcepub async fn send_nft(
&self,
addresses_nft_ids: Vec<AddressAndNftId>,
options: Option<TransactionOptions>
) -> Result<Transaction>
pub async fn send_nft(
&self,
addresses_nft_ids: Vec<AddressAndNftId>,
options: Option<TransactionOptions>
) -> Result<Transaction>
Function to send native tokens in basic outputs with a
[StorageDepositReturnUnlockCondition
](iota_client::block::output::unlock_condition::
StorageDepositReturnUnlockCondition) and [ExpirationUnlockCondition
](iota_client::block::output::
unlock_condition::ExpirationUnlockCondition), so the storage deposit gets back to the sender and also that
the sender gets access to the output again after a defined time (default 1 day), Calls
AccountHandle.send() internally, the options can define the
RemainderValueStrategy. Custom inputs will be replaced with the required nft inputs.
Address needs to be Bech32 encoded
let outputs = vec![AddressAndNftId {
address: "rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu".to_string(),
nft_id: NftId::from_str("04f9b54d488d2e83a6c90db08ae4b39651bbba8a")?,
}];
let transaction = account.send_nft(outputs, None).await?;
println!(
"Transaction: {} Block sent: http://localhost:14265/api/core/v2/blocks/{}",
transaction.transaction_id,
transaction.block_id.expect("no block created yet")
);
sourceasync fn prepare_send_nft(
&self,
addresses_nft_ids: Vec<AddressAndNftId>,
options: Option<TransactionOptions>
) -> Result<PreparedTransactionData>
async fn prepare_send_nft(
&self,
addresses_nft_ids: Vec<AddressAndNftId>,
options: Option<TransactionOptions>
) -> Result<PreparedTransactionData>
Function to prepare the transaction for AccountHandle.send_nft()
sourceimpl AccountHandle
impl AccountHandle
sourcepub(crate) async fn select_inputs(
&self,
outputs: Vec<Output>,
custom_inputs: Option<Vec<InputSigningData>>,
remainder_address: Option<Address>,
rent_structure: &RentStructure,
allow_burning: bool
) -> Result<SelectedTransactionData>
pub(crate) async fn select_inputs(
&self,
outputs: Vec<Output>,
custom_inputs: Option<Vec<InputSigningData>>,
remainder_address: Option<Address>,
rent_structure: &RentStructure,
allow_burning: bool
) -> Result<SelectedTransactionData>
Selects inputs for a transaction and locks them in the account, so they don’t get used again
sourceimpl AccountHandle
impl AccountHandle
sourcepub async fn prepare_output(
&self,
options: OutputOptions,
transaction_options: Option<TransactionOptions>
) -> Result<Output>
pub async fn prepare_output(
&self,
options: OutputOptions,
transaction_options: Option<TransactionOptions>
) -> Result<Output>
Prepare an 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
sourceasync fn prepare_nft_output(
&self,
options: OutputOptions,
transaction_options: Option<TransactionOptions>,
nft_id: NftId
) -> Result<Output>
async fn prepare_nft_output(
&self,
options: OutputOptions,
transaction_options: Option<TransactionOptions>,
nft_id: NftId
) -> Result<Output>
Prepare an nft output
async fn get_remainder_address(
&self,
transaction_options: Option<TransactionOptions>
) -> Result<Address>
sourceimpl AccountHandle
impl AccountHandle
sourcepub async fn prepare_transaction(
&self,
outputs: Vec<Output>,
options: Option<TransactionOptions>
) -> Result<PreparedTransactionData>
pub async fn prepare_transaction(
&self,
outputs: Vec<Output>,
options: Option<TransactionOptions>
) -> Result<PreparedTransactionData>
Get inputs and build the transaction essence
sourceimpl AccountHandle
impl AccountHandle
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>
Function to sign a transaction essence
sourceimpl AccountHandle
impl AccountHandle
sourcepub(crate) async fn submit_transaction_payload(
&self,
transaction_payload: TransactionPayload
) -> Result<BlockId>
pub(crate) async fn submit_transaction_payload(
&self,
transaction_payload: TransactionPayload
) -> Result<BlockId>
Submits a payload in a block
sourceimpl AccountHandle
impl AccountHandle
sourcepub async fn send(
&self,
outputs: Vec<Output>,
options: Option<TransactionOptions>
) -> Result<Transaction>
pub async fn send(
&self,
outputs: Vec<Output>,
options: Option<TransactionOptions>
) -> Result<Transaction>
Send a transaction, if sending a block fails, the function will return None for the block_id, but the wallet will retry sending the transaction during syncing.
let outputs = vec![TransactionOutput {
address: "rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu".to_string(),
amount: 1_000_000,
output_kind: None,
}];
let tx = account_handle
.send(
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: Vec<Output>,
options: Option<TransactionOptions>
) -> Result<Transaction>
pub async fn finish_transaction(
&self,
outputs: Vec<Output>,
options: Option<TransactionOptions>
) -> 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
) -> Result<Transaction>
pub async fn sign_and_submit_transaction(
&self,
prepared_transaction_data: PreparedTransactionData
) -> Result<Transaction>
Sign 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
) -> Result<Transaction>
pub async fn submit_and_store_transaction(
&self,
signed_transaction_data: SignedTransactionData
) -> Result<Transaction>
Validate the transaction, submit it to a node and store it in the account
async fn unlock_inputs(&self, inputs: Vec<InputSigningData>) -> Result<()>
fn monitor_tx_confirmation(&self, block_id: BlockId)
sourceimpl AccountHandle
impl AccountHandle
pub async fn set_alias(&self, alias: &str) -> Result<()>
sourcepub(crate) async fn update_account(
&self,
addresses_with_unspent_outputs: Vec<AddressWithUnspentOutputs>,
unspent_outputs: Vec<OutputData>,
spent_outputs: Vec<OutputId>,
spent_or_not_synced_output_responses: Vec<OutputResponse>,
options: &SyncOptions
) -> Result<()>
pub(crate) async fn update_account(
&self,
addresses_with_unspent_outputs: Vec<AddressWithUnspentOutputs>,
unspent_outputs: Vec<OutputData>,
spent_outputs: Vec<OutputId>,
spent_or_not_synced_output_responses: Vec<OutputResponse>,
options: &SyncOptions
) -> Result<()>
Update account with newly synced data and emit events for outputs
sourcepub(crate) async fn update_account_with_transactions(
&self,
updated_transactions: Vec<Transaction>,
spent_output_ids: Vec<OutputId>,
output_ids_to_unlock: Vec<OutputId>
) -> Result<()>
pub(crate) async fn update_account_with_transactions(
&self,
updated_transactions: Vec<Transaction>,
spent_output_ids: Vec<OutputId>,
output_ids_to_unlock: Vec<OutputId>
) -> Result<()>
Update account with newly synced transactions
sourcepub(crate) async fn update_account_addresses(
&self,
internal: bool,
new_addresses: Vec<AccountAddress>
) -> Result<()>
pub(crate) async fn update_account_addresses(
&self,
internal: bool,
new_addresses: Vec<AccountAddress>
) -> Result<()>
Update account with newly generated addresses
pub(crate) async fn update_account_with_new_client(
&mut self,
client: Client
) -> Result<()>
sourcepub(crate) async fn update_unspent_outputs(
&self,
output_responses: Vec<OutputResponse>
) -> Result<()>
pub(crate) async fn update_unspent_outputs(
&self,
output_responses: Vec<OutputResponse>
) -> Result<()>
Update unspent outputs, this function is originally intended for updating recursively synced alias and nft address outputs
Methods from Deref<Target = RwLock<Account>>
pub async fn read(&self) -> RwLockReadGuard<'_, T>
pub async fn read(&self) -> RwLockReadGuard<'_, T>
Locks this RwLock
with shared read access, causing the current task
to yield until the lock has been acquired.
The calling task will yield until there are no writers which hold the lock. There may be other readers inside the lock when the task resumes.
Note that under the priority policy of [RwLock
], read locks are not
granted until prior write locks, to prevent starvation. Therefore
deadlock may occur if a read lock is held by the current task, a write
lock attempt is made, and then a subsequent read lock attempt is made
by the current task.
Returns an RAII guard which will drop this read access of the RwLock
when dropped.
Cancel safety
This method uses a queue to fairly distribute locks in the order they
were requested. Cancelling a call to read
makes you lose your place in
the queue.
Examples
use std::sync::Arc;
use tokio::sync::RwLock;
#[tokio::main]
async fn main() {
let lock = Arc::new(RwLock::new(1));
let c_lock = lock.clone();
let n = lock.read().await;
assert_eq!(*n, 1);
tokio::spawn(async move {
// While main has an active read lock, we acquire one too.
let r = c_lock.read().await;
assert_eq!(*r, 1);
}).await.expect("The spawned task has panicked");
// Drop the guard after the spawned task finishes.
drop(n);
}
pub fn blocking_read(&self) -> RwLockReadGuard<'_, T>
pub fn blocking_read(&self) -> RwLockReadGuard<'_, T>
Blockingly locks this RwLock
with shared read access.
This method is intended for use cases where you need to use this rwlock in asynchronous code as well as in synchronous code.
Returns an RAII guard which will drop the read access of this RwLock
when dropped.
Panics
This function panics if called within an asynchronous execution context.
- If you find yourself in an asynchronous execution context and needing
to call some (synchronous) function which performs one of these
blocking_
operations, then consider wrapping that call inside [spawn_blocking()
][crate::runtime::Handle::spawn_blocking] (or [block_in_place()
][crate::task::block_in_place]).
Examples
use std::sync::Arc;
use tokio::sync::RwLock;
#[tokio::main]
async fn main() {
let rwlock = Arc::new(RwLock::new(1));
let mut write_lock = rwlock.write().await;
let blocking_task = tokio::task::spawn_blocking({
let rwlock = Arc::clone(&rwlock);
move || {
// This shall block until the `write_lock` is released.
let read_lock = rwlock.blocking_read();
assert_eq!(*read_lock, 0);
}
});
*write_lock -= 1;
drop(write_lock); // release the lock.
// Await the completion of the blocking task.
blocking_task.await.unwrap();
// Assert uncontended.
assert!(rwlock.try_write().is_ok());
}
pub async fn read_owned(self: Arc<RwLock<T>>) -> OwnedRwLockReadGuard<T, T>
pub async fn read_owned(self: Arc<RwLock<T>>) -> OwnedRwLockReadGuard<T, T>
Locks this RwLock
with shared read access, causing the current task
to yield until the lock has been acquired.
The calling task will yield until there are no writers which hold the lock. There may be other readers inside the lock when the task resumes.
This method is identical to [RwLock::read
], except that the returned
guard references the RwLock
with an Arc
rather than by borrowing
it. Therefore, the RwLock
must be wrapped in an Arc
to call this
method, and the guard will live for the 'static
lifetime, as it keeps
the RwLock
alive by holding an Arc
.
Note that under the priority policy of [RwLock
], read locks are not
granted until prior write locks, to prevent starvation. Therefore
deadlock may occur if a read lock is held by the current task, a write
lock attempt is made, and then a subsequent read lock attempt is made
by the current task.
Returns an RAII guard which will drop this read access of the RwLock
when dropped.
Cancel safety
This method uses a queue to fairly distribute locks in the order they
were requested. Cancelling a call to read_owned
makes you lose your
place in the queue.
Examples
use std::sync::Arc;
use tokio::sync::RwLock;
#[tokio::main]
async fn main() {
let lock = Arc::new(RwLock::new(1));
let c_lock = lock.clone();
let n = lock.read_owned().await;
assert_eq!(*n, 1);
tokio::spawn(async move {
// While main has an active read lock, we acquire one too.
let r = c_lock.read_owned().await;
assert_eq!(*r, 1);
}).await.expect("The spawned task has panicked");
// Drop the guard after the spawned task finishes.
drop(n);
}
pub fn try_read(&self) -> Result<RwLockReadGuard<'_, T>, TryLockError>
pub fn try_read(&self) -> Result<RwLockReadGuard<'_, T>, TryLockError>
Attempts to acquire this RwLock
with shared read access.
If the access couldn’t be acquired immediately, returns TryLockError
.
Otherwise, an RAII guard is returned which will release read access
when dropped.
Examples
use std::sync::Arc;
use tokio::sync::RwLock;
#[tokio::main]
async fn main() {
let lock = Arc::new(RwLock::new(1));
let c_lock = lock.clone();
let v = lock.try_read().unwrap();
assert_eq!(*v, 1);
tokio::spawn(async move {
// While main has an active read lock, we acquire one too.
let n = c_lock.read().await;
assert_eq!(*n, 1);
}).await.expect("The spawned task has panicked");
// Drop the guard when spawned task finishes.
drop(v);
}
pub fn try_read_owned(
self: Arc<RwLock<T>>
) -> Result<OwnedRwLockReadGuard<T, T>, TryLockError>
pub fn try_read_owned(
self: Arc<RwLock<T>>
) -> Result<OwnedRwLockReadGuard<T, T>, TryLockError>
Attempts to acquire this RwLock
with shared read access.
If the access couldn’t be acquired immediately, returns TryLockError
.
Otherwise, an RAII guard is returned which will release read access
when dropped.
This method is identical to [RwLock::try_read
], except that the
returned guard references the RwLock
with an Arc
rather than by
borrowing it. Therefore, the RwLock
must be wrapped in an Arc
to
call this method, and the guard will live for the 'static
lifetime,
as it keeps the RwLock
alive by holding an Arc
.
Examples
use std::sync::Arc;
use tokio::sync::RwLock;
#[tokio::main]
async fn main() {
let lock = Arc::new(RwLock::new(1));
let c_lock = lock.clone();
let v = lock.try_read_owned().unwrap();
assert_eq!(*v, 1);
tokio::spawn(async move {
// While main has an active read lock, we acquire one too.
let n = c_lock.read_owned().await;
assert_eq!(*n, 1);
}).await.expect("The spawned task has panicked");
// Drop the guard when spawned task finishes.
drop(v);
}
pub async fn write(&self) -> RwLockWriteGuard<'_, T>
pub async fn write(&self) -> RwLockWriteGuard<'_, T>
Locks this RwLock
with exclusive write access, causing the current
task to yield until the lock has been acquired.
The calling task will yield while other writers or readers currently have access to the lock.
Returns an RAII guard which will drop the write access of this RwLock
when dropped.
Cancel safety
This method uses a queue to fairly distribute locks in the order they
were requested. Cancelling a call to write
makes you lose your place
in the queue.
Examples
use tokio::sync::RwLock;
#[tokio::main]
async fn main() {
let lock = RwLock::new(1);
let mut n = lock.write().await;
*n = 2;
}
pub fn blocking_write(&self) -> RwLockWriteGuard<'_, T>
pub fn blocking_write(&self) -> RwLockWriteGuard<'_, T>
Blockingly locks this RwLock
with exclusive write access.
This method is intended for use cases where you need to use this rwlock in asynchronous code as well as in synchronous code.
Returns an RAII guard which will drop the write access of this RwLock
when dropped.
Panics
This function panics if called within an asynchronous execution context.
- If you find yourself in an asynchronous execution context and needing
to call some (synchronous) function which performs one of these
blocking_
operations, then consider wrapping that call inside [spawn_blocking()
][crate::runtime::Handle::spawn_blocking] (or [block_in_place()
][crate::task::block_in_place]).
Examples
use std::sync::Arc;
use tokio::{sync::RwLock};
#[tokio::main]
async fn main() {
let rwlock = Arc::new(RwLock::new(1));
let read_lock = rwlock.read().await;
let blocking_task = tokio::task::spawn_blocking({
let rwlock = Arc::clone(&rwlock);
move || {
// This shall block until the `read_lock` is released.
let mut write_lock = rwlock.blocking_write();
*write_lock = 2;
}
});
assert_eq!(*read_lock, 1);
// Release the last outstanding read lock.
drop(read_lock);
// Await the completion of the blocking task.
blocking_task.await.unwrap();
// Assert uncontended.
let read_lock = rwlock.try_read().unwrap();
assert_eq!(*read_lock, 2);
}
pub async fn write_owned(self: Arc<RwLock<T>>) -> OwnedRwLockWriteGuard<T>
pub async fn write_owned(self: Arc<RwLock<T>>) -> OwnedRwLockWriteGuard<T>
Locks this RwLock
with exclusive write access, causing the current
task to yield until the lock has been acquired.
The calling task will yield while other writers or readers currently have access to the lock.
This method is identical to [RwLock::write
], except that the returned
guard references the RwLock
with an Arc
rather than by borrowing
it. Therefore, the RwLock
must be wrapped in an Arc
to call this
method, and the guard will live for the 'static
lifetime, as it keeps
the RwLock
alive by holding an Arc
.
Returns an RAII guard which will drop the write access of this RwLock
when dropped.
Cancel safety
This method uses a queue to fairly distribute locks in the order they
were requested. Cancelling a call to write_owned
makes you lose your
place in the queue.
Examples
use std::sync::Arc;
use tokio::sync::RwLock;
#[tokio::main]
async fn main() {
let lock = Arc::new(RwLock::new(1));
let mut n = lock.write_owned().await;
*n = 2;
}
pub fn try_write(&self) -> Result<RwLockWriteGuard<'_, T>, TryLockError>
pub fn try_write(&self) -> Result<RwLockWriteGuard<'_, T>, TryLockError>
Attempts to acquire this RwLock
with exclusive write access.
If the access couldn’t be acquired immediately, returns TryLockError
.
Otherwise, an RAII guard is returned which will release write access
when dropped.
Examples
use tokio::sync::RwLock;
#[tokio::main]
async fn main() {
let rw = RwLock::new(1);
let v = rw.read().await;
assert_eq!(*v, 1);
assert!(rw.try_write().is_err());
}
pub fn try_write_owned(
self: Arc<RwLock<T>>
) -> Result<OwnedRwLockWriteGuard<T>, TryLockError>
pub fn try_write_owned(
self: Arc<RwLock<T>>
) -> Result<OwnedRwLockWriteGuard<T>, TryLockError>
Attempts to acquire this RwLock
with exclusive write access.
If the access couldn’t be acquired immediately, returns TryLockError
.
Otherwise, an RAII guard is returned which will release write access
when dropped.
This method is identical to [RwLock::try_write
], except that the
returned guard references the RwLock
with an Arc
rather than by
borrowing it. Therefore, the RwLock
must be wrapped in an Arc
to
call this method, and the guard will live for the 'static
lifetime,
as it keeps the RwLock
alive by holding an Arc
.
Examples
use std::sync::Arc;
use tokio::sync::RwLock;
#[tokio::main]
async fn main() {
let rw = Arc::new(RwLock::new(1));
let v = Arc::clone(&rw).read_owned().await;
assert_eq!(*v, 1);
assert!(rw.try_write_owned().is_err());
}
Trait Implementations
sourceimpl Clone for AccountHandle
impl Clone for AccountHandle
sourcefn clone(&self) -> AccountHandle
fn clone(&self) -> AccountHandle
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl Debug for AccountHandle
impl Debug for AccountHandle
Auto Trait Implementations
impl !RefUnwindSafe for AccountHandle
impl Send for AccountHandle
impl Sync for AccountHandle
impl Unpin for AccountHandle
impl !UnwindSafe for AccountHandle
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more