pub struct Wallet<S: SecretManage = SecretManager> { /* private fields */ }
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>
impl<S: 'static + SecretManage> Wallet<S>
sourcepub 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>>>
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. Theaddress_start_index
andforce_syncing
fields will be overwritten to skip existing addresses.
Returns:
A vector of Account
source§impl Wallet
impl Wallet
sourcepub async fn generate_ed25519_address(
&self,
account_index: u32,
address_index: u32,
options: impl Into<Option<GenerateAddressOptions>> + Send
) -> Result<Ed25519Address>
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>
impl<S: 'static + SecretManage> Wallet<S>
sourcepub async fn get_bech32_hrp(&self) -> Result<Hrp>
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>
impl<S: 'static + SecretManage> Wallet<S>
sourcepub async fn start_background_syncing(
&self,
options: Option<SyncOptions>,
interval: Option<Duration>
) -> Result<()>
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
sourcepub async fn stop_background_syncing(&self) -> Result<()>
pub async fn stop_background_syncing(&self) -> Result<()>
Stop the background syncing of the accounts
source§impl<S: 'static + SecretManage> Wallet<S>
impl<S: 'static + SecretManage> Wallet<S>
pub fn client(&self) -> &Client
pub async fn client_options(&self) -> ClientBuilder
source§impl<S: 'static + SecretManage> Wallet<S>
impl<S: 'static + SecretManage> Wallet<S>
pub async fn set_client_options( &self, client_options: ClientBuilder ) -> Result<()>
source§impl<S: SecretManage> Wallet<S>
impl<S: SecretManage> Wallet<S>
sourcepub async fn get_account<I: Into<AccountIdentifier> + Send>(
&self,
identifier: I
) -> Result<Account<S>>
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>
impl<S: 'static + SecretManage> Wallet<S>
source§impl Wallet<LedgerSecretManager>
impl Wallet<LedgerSecretManager>
sourcepub async fn get_ledger_nano_status(&self) -> Result<LedgerNanoStatus>
pub async fn get_ledger_nano_status(&self) -> Result<LedgerNanoStatus>
Get the ledger nano status
source§impl Wallet
impl Wallet
sourcepub async fn get_ledger_nano_status(&self) -> Result<LedgerNanoStatus>
pub async fn get_ledger_nano_status(&self) -> Result<LedgerNanoStatus>
Get the ledger nano status
source§impl Wallet
impl Wallet
sourcepub async fn set_stronghold_password(
&self,
password: impl Into<Password> + Send
) -> Result<()>
pub async fn set_stronghold_password( &self, password: impl Into<Password> + Send ) -> Result<()>
Sets the Stronghold password
sourcepub async fn change_stronghold_password(
&self,
current_password: impl Into<Password> + Send,
new_password: impl Into<Password> + Send
) -> Result<()>
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.
sourcepub async fn set_stronghold_password_clear_interval(
&self,
timeout: Option<Duration>
) -> Result<()>
pub async fn set_stronghold_password_clear_interval( &self, timeout: Option<Duration> ) -> Result<()>
Sets the Stronghold password clear interval
sourcepub async fn store_mnemonic(&self, mnemonic: Mnemonic) -> Result<()>
pub async fn store_mnemonic(&self, mnemonic: Mnemonic) -> Result<()>
Stores a mnemonic into the Stronghold vault
sourcepub async fn clear_stronghold_password(&self) -> Result<()>
pub async fn clear_stronghold_password(&self) -> Result<()>
Clears the Stronghold password from memory.
sourcepub async fn is_stronghold_password_available(&self) -> Result<bool>
pub async fn is_stronghold_password_available(&self) -> Result<bool>
Checks if the Stronghold password is available.
source§impl Wallet<StrongholdAdapter>
impl Wallet<StrongholdAdapter>
sourcepub async fn set_stronghold_password(
&self,
password: impl Into<Password> + Send
) -> Result<()>
pub async fn set_stronghold_password( &self, password: impl Into<Password> + Send ) -> Result<()>
Sets the Stronghold password
sourcepub async fn change_stronghold_password(
&self,
current_password: impl Into<Password> + Send,
new_password: impl Into<Password> + Send
) -> Result<()>
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.
sourcepub async fn set_stronghold_password_clear_interval(
&self,
timeout: Option<Duration>
) -> Result<()>
pub async fn set_stronghold_password_clear_interval( &self, timeout: Option<Duration> ) -> Result<()>
Sets the Stronghold password clear interval
sourcepub async fn store_mnemonic(&self, mnemonic: Mnemonic) -> Result<()>
pub async fn store_mnemonic(&self, mnemonic: Mnemonic) -> Result<()>
Stores a mnemonic into the Stronghold vault
sourcepub async fn clear_stronghold_password(&self) -> Result<()>
pub async fn clear_stronghold_password(&self) -> Result<()>
Clears the Stronghold password from memory.
sourcepub async fn is_stronghold_password_available(&self) -> Result<bool>
pub async fn is_stronghold_password_available(&self) -> Result<bool>
Checks if the Stronghold password is available.
source§impl Wallet
impl Wallet
sourcepub async fn backup(
&self,
backup_path: PathBuf,
stronghold_password: impl Into<Password> + Send
) -> Result<()>
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.
sourcepub 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<()>
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>
impl Wallet<StrongholdSecretManager>
sourcepub async fn backup(
&self,
backup_path: PathBuf,
stronghold_password: impl Into<Password> + Send
) -> Result<()>
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.
sourcepub 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<()>
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>
impl<S: SecretManage> Wallet<S>
sourcepub async fn verify_integrity(&self) -> Result<()>
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>
impl<S: 'static + SecretManage> Wallet<S>
sourcepub fn builder() -> WalletBuilder<S>
pub fn builder() -> WalletBuilder<S>
Initialises the wallet builder.
sourcepub fn create_account(&self) -> AccountBuilder<S>
pub fn create_account(&self) -> AccountBuilder<S>
Create a new account
source§impl<S: 'static + SecretManage> Wallet<S>
impl<S: 'static + SecretManage> Wallet<S>
sourcepub async fn get_accounts(&self) -> Result<Vec<Account<S>>>
pub async fn get_accounts(&self) -> Result<Vec<Account<S>>>
Get all accounts
sourcepub async fn get_account_aliases(&self) -> Result<Vec<String>>
pub async fn get_account_aliases(&self) -> Result<Vec<String>>
Get all account aliases
sourcepub async fn remove_latest_account(&self) -> Result<()>
pub async fn remove_latest_account(&self) -> Result<()>
Removes the latest account (account with the largest account index).
Methods from Deref<Target = WalletInner<S>>§
sourcepub fn get_secret_manager(&self) -> &Arc<RwLock<S>>
pub fn get_secret_manager(&self) -> &Arc<RwLock<S>>
Get the SecretManager
sourcepub async fn listen<F, I: IntoIterator<Item = WalletEventType> + Send>(
&self,
events: I,
handler: F
)
Available on crate feature events
only.
pub async fn listen<F, I: IntoIterator<Item = WalletEventType> + Send>( &self, events: I, handler: F )
events
only.Listen to wallet events, empty vec will listen to all events
sourcepub async fn clear_listeners<I: IntoIterator<Item = WalletEventType> + Send>(
&self,
events: I
)
Available on crate feature events
only.
pub async fn clear_listeners<I: IntoIterator<Item = WalletEventType> + Send>( &self, events: I )
events
only.Remove wallet event listeners, empty vec will remove all listeners
sourcepub fn generate_mnemonic(&self) -> Result<Mnemonic>
pub fn generate_mnemonic(&self) -> Result<Mnemonic>
Generates a new random mnemonic.
sourcepub fn verify_mnemonic(&self, mnemonic: &MnemonicRef) -> Result<()>
pub fn verify_mnemonic(&self, mnemonic: &MnemonicRef) -> Result<()>
Verify that a &str is a valid mnemonic.
sourcepub async fn emit_test_event(&self, event: WalletEvent)
Available on crate feature events
only.
pub async fn emit_test_event(&self, event: WalletEvent)
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>
impl<S: SecretManage> Clone for Wallet<S>
source§impl<S: SecretManage> Deref for Wallet<S>
impl<S: SecretManage> Deref for Wallet<S>
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> 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