Struct iota_sdk::wallet::core::Wallet

source ·
pub struct Wallet<S: SecretManage = SecretManager> { /* private fields */ }
Available on crate feature wallet only.
Expand description

The wallet, used to create and get accounts. One wallet can hold many accounts, but they should all share the same secret_manager type with the same seed/mnemonic.

Implementations§

source§

impl<S: 'static + SecretManage> Wallet<S>
where Error: From<S::Error>,

source

pub async fn recover_accounts( &self, account_start_index: u32, account_gap_limit: u32, address_gap_limit: u32, sync_options: Option<SyncOptions> ) -> Result<Vec<Account<S>>>

Find accounts with unspent outputs.

Arguments:

  • account_start_index: The index of the first account to search for.
  • account_gap_limit: The number of accounts to search for, after the last account with unspent outputs.
  • address_gap_limit: The number of addresses to search for, after the last address with unspent outputs, in each account.
  • sync_options: Optional parameter to specify the sync options. The address_start_index and force_syncing fields will be overwritten to skip existing addresses.

Returns:

A vector of Account

source§

impl Wallet

source

pub async fn generate_ed25519_address( &self, account_index: u32, address_index: u32, options: impl Into<Option<GenerateAddressOptions>> + Send ) -> Result<Ed25519Address>

Generate an address without storing it

let public_addresses = wallet
    .generate_ed25519_addresses(
        0,
        false,
        0,
        None,
    )
    .await?;
source§

impl<S: 'static + SecretManage> Wallet<S>
where Error: From<S::Error>,

source

pub async fn get_bech32_hrp(&self) -> Result<Hrp>

Get the bech32 hrp from the first account address or if not existent, from the client

source§

impl<S: 'static + SecretManage> Wallet<S>
where Error: From<S::Error>,

source

pub async fn start_background_syncing( &self, options: Option<SyncOptions>, interval: Option<Duration> ) -> Result<()>

Start the background syncing process for all accounts, default interval is 7 seconds

source

pub async fn stop_background_syncing(&self) -> Result<()>

Stop the background syncing of the accounts

source§

impl<S: 'static + SecretManage> Wallet<S>

source

pub fn client(&self) -> &Client

source

pub async fn client_options(&self) -> ClientBuilder

source§

impl<S: 'static + SecretManage> Wallet<S>
where Error: From<S::Error>, WalletBuilder<S>: SaveLoadWallet,

source

pub async fn set_client_options( &self, client_options: ClientBuilder ) -> Result<()>

source

pub async fn update_node_auth( &self, url: Url, auth: Option<NodeAuth> ) -> Result<()>

Update the authentication for a node.

source§

impl<S: SecretManage> Wallet<S>

source

pub async fn get_account<I: Into<AccountIdentifier> + Send>( &self, identifier: I ) -> Result<Account<S>>

Get an account with an AccountIdentifier

source§

impl<S: 'static + SecretManage> Wallet<S>
where Error: From<S::Error>,

source

pub async fn get_or_create_account( &self, alias: impl Into<String> + Send ) -> Result<Account<S>>

source§

impl Wallet<LedgerSecretManager>

source

pub async fn get_ledger_nano_status(&self) -> Result<LedgerNanoStatus>

Get the ledger nano status

source§

impl Wallet

source

pub async fn get_ledger_nano_status(&self) -> Result<LedgerNanoStatus>

Get the ledger nano status

source§

impl Wallet

source§

impl Wallet

source

pub async fn set_stronghold_password( &self, password: impl Into<Password> + Send ) -> Result<()>

Sets the Stronghold password

source

pub async fn change_stronghold_password( &self, current_password: impl Into<Password> + Send, new_password: impl Into<Password> + Send ) -> Result<()>

Change the Stronghold password to another one and also re-encrypt the values in the loaded snapshot with it.

source

pub async fn set_stronghold_password_clear_interval( &self, timeout: Option<Duration> ) -> Result<()>

Sets the Stronghold password clear interval

source

pub async fn store_mnemonic(&self, mnemonic: Mnemonic) -> Result<()>

Stores a mnemonic into the Stronghold vault

source

pub async fn clear_stronghold_password(&self) -> Result<()>

Clears the Stronghold password from memory.

source

pub async fn is_stronghold_password_available(&self) -> Result<bool>

Checks if the Stronghold password is available.

source§

impl Wallet<StrongholdAdapter>

source

pub async fn set_stronghold_password( &self, password: impl Into<Password> + Send ) -> Result<()>

Sets the Stronghold password

source

pub async fn change_stronghold_password( &self, current_password: impl Into<Password> + Send, new_password: impl Into<Password> + Send ) -> Result<()>

Change the Stronghold password to another one and also re-encrypt the values in the loaded snapshot with it.

source

pub async fn set_stronghold_password_clear_interval( &self, timeout: Option<Duration> ) -> Result<()>

Sets the Stronghold password clear interval

source

pub async fn store_mnemonic(&self, mnemonic: Mnemonic) -> Result<()>

Stores a mnemonic into the Stronghold vault

source

pub async fn clear_stronghold_password(&self) -> Result<()>

Clears the Stronghold password from memory.

source

pub async fn is_stronghold_password_available(&self) -> Result<bool>

Checks if the Stronghold password is available.

source§

impl Wallet

source

pub async fn backup( &self, backup_path: PathBuf, stronghold_password: impl Into<Password> + Send ) -> Result<()>

Backup the wallet data in a Stronghold file. stronghold_password must be the current one when Stronghold is used as SecretManager.

source

pub async fn restore_backup( &self, backup_path: PathBuf, stronghold_password: impl Into<Password> + Send, ignore_if_coin_type_mismatch: Option<bool>, ignore_if_bech32_hrp_mismatch: Option<Hrp> ) -> Result<()>

Restore the wallet from a Stronghold backup file. Replaces client_options, coin_type, secret_manager and accounts. Returns an error if accounts were already created If Stronghold is used as secret_manager, the existing Stronghold file will be overwritten. If a mnemonic was stored, it will be gone. if ignore_if_coin_type_mismatch.is_some(), client options will not be restored if ignore_if_coin_type_mismatch == Some(true), client options coin type and accounts will not be restored if the coin type doesn’t match if ignore_if_bech32_hrp_mismatch == Some(“rms”), but addresses have something different like “smr”, no accounts will be restored.

source§

impl Wallet<StrongholdSecretManager>

source

pub async fn backup( &self, backup_path: PathBuf, stronghold_password: impl Into<Password> + Send ) -> Result<()>

Backup the wallet data in a Stronghold file stronghold_password must be the current one when Stronghold is used as SecretManager.

source

pub async fn restore_backup( &self, backup_path: PathBuf, stronghold_password: impl Into<Password> + Send, ignore_if_coin_type_mismatch: Option<bool>, ignore_if_bech32_hrp_mismatch: Option<&str> ) -> Result<()>

Restore a backup from a Stronghold file Replaces client_options, coin_type, secret_manager and accounts. Returns an error if accounts were already created If Stronghold is used as secret_manager, the existing Stronghold file will be overwritten. If a mnemonic was stored, it will be gone. if ignore_if_coin_type_mismatch.is_some(), client options will not be restored if ignore_if_coin_type_mismatch == Some(true), client options coin type and accounts will not be restored if the coin type doesn’t match if ignore_if_bech32_hrp_mismatch == Some(“rms”), but addresses have something different like “smr”, no accounts will be restored.

source§

impl<S: SecretManage> Wallet<S>

source

pub async fn verify_integrity(&self) -> Result<()>

Checks if there is no missing account for example indexes [0, 1, 3] should panic (for now, later return error, automatically fix?) Also checks for each account if there is a gap in an address list and no address is duplicated

source§

impl<S: 'static + SecretManage> Wallet<S>
where Error: From<S::Error>,

source

pub fn builder() -> WalletBuilder<S>

Initialises the wallet builder.

source

pub fn create_account(&self) -> AccountBuilder<S>

Create a new account

source§

impl<S: 'static + SecretManage> Wallet<S>
where Error: From<S::Error>,

source

pub async fn get_accounts(&self) -> Result<Vec<Account<S>>>

Get all accounts

source

pub async fn get_account_aliases(&self) -> Result<Vec<String>>

Get all account aliases

source

pub async fn remove_latest_account(&self) -> Result<()>

Removes the latest account (account with the largest account index).

source

pub async fn balance(&self) -> Result<Balance>

Get the balance of all accounts added together

source

pub async fn sync(&self, options: Option<SyncOptions>) -> Result<Balance>

Sync all accounts

Methods from Deref<Target = WalletInner<S>>§

source

pub fn get_secret_manager(&self) -> &Arc<RwLock<S>>

Get the SecretManager

source

pub async fn listen<F, I: IntoIterator<Item = WalletEventType> + Send>( &self, events: I, handler: F )
where I::IntoIter: Send, F: Fn(&Event) + 'static + Send + Sync,

Available on crate feature events only.

Listen to wallet events, empty vec will listen to all events

source

pub async fn clear_listeners<I: IntoIterator<Item = WalletEventType> + Send>( &self, events: I )
where I::IntoIter: Send,

Available on crate feature events only.

Remove wallet event listeners, empty vec will remove all listeners

source

pub fn generate_mnemonic(&self) -> Result<Mnemonic>

Generates a new random mnemonic.

source

pub fn verify_mnemonic(&self, mnemonic: &MnemonicRef) -> Result<()>

Verify that a &str is a valid mnemonic.

source

pub async fn emit_test_event(&self, event: WalletEvent)

Available on crate feature events only.

Helper function to test events. Emits a provided event with account index 0.

Trait Implementations§

source§

impl<S: SecretManage> Clone for Wallet<S>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<S: Debug + SecretManage> Debug for Wallet<S>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<S: SecretManage> Deref for Wallet<S>

§

type Target = WalletInner<S>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<S: SecretManage> Drop for Wallet<S>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<S> Freeze for Wallet<S>

§

impl<S = SecretManager> !RefUnwindSafe for Wallet<S>

§

impl<S> Send for Wallet<S>

§

impl<S> Sync for Wallet<S>

§

impl<S> Unpin for Wallet<S>

§

impl<S = SecretManager> !UnwindSafe for Wallet<S>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> ConvertTo<T> for T
where T: Send,

source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

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
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> Any for T
where T: Any,

source§

impl<T> CloneAny for T
where T: Any + Clone,