diff --git a/bindings/core/src/method/wallet.rs b/bindings/core/src/method/wallet.rs index 3a578919f0..f65467ae52 100644 --- a/bindings/core/src/method/wallet.rs +++ b/bindings/core/src/method/wallet.rs @@ -43,6 +43,9 @@ use crate::OmittedDebug; #[serde(tag = "name", content = "data", rename_all = "camelCase")] #[non_exhaustive] pub enum WalletMethod { + /// Returns the accounts of the wallet. + /// Expected response: [`OutputsData`](crate::Response::OutputsData) + Accounts, /// Backup storage. Password must be the current one, when Stronghold is used as SecretManager. /// Expected response: [`Ok`](crate::Response::Ok) #[cfg(feature = "stronghold")] diff --git a/bindings/core/src/method_handler/wallet.rs b/bindings/core/src/method_handler/wallet.rs index 50948dadb7..ee8102677d 100644 --- a/bindings/core/src/method_handler/wallet.rs +++ b/bindings/core/src/method_handler/wallet.rs @@ -22,6 +22,10 @@ use crate::{method::WalletMethod, response::Response, Result}; /// Call a wallet method. pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletMethod) -> Result { let response = match method { + WalletMethod::Accounts => { + let accounts = wallet.accounts().await; + Response::OutputsData(accounts.iter().map(OutputDataDto::from).collect()) + } #[cfg(feature = "stronghold")] WalletMethod::Backup { destination, password } => { wallet.backup(destination, password).await?; diff --git a/bindings/nodejs/lib/types/wallet/bridge/account.ts b/bindings/nodejs/lib/types/wallet/bridge/account.ts index 408216fcc9..b661582704 100644 --- a/bindings/nodejs/lib/types/wallet/bridge/account.ts +++ b/bindings/nodejs/lib/types/wallet/bridge/account.ts @@ -149,6 +149,10 @@ export type __ImplicitAccountCreationAddressMethod__ = { name: 'implicitAccountCreationAddress'; }; +export type __AccountsMethod__ = { + name: 'accounts'; +}; + export type __ImplicitAccountsMethod__ = { name: 'implicitAccounts'; }; diff --git a/bindings/nodejs/lib/types/wallet/bridge/index.ts b/bindings/nodejs/lib/types/wallet/bridge/index.ts index ae459e428c..348fa3c54a 100644 --- a/bindings/nodejs/lib/types/wallet/bridge/index.ts +++ b/bindings/nodejs/lib/types/wallet/bridge/index.ts @@ -16,6 +16,7 @@ import type { __OutputsMethod__, __PendingTransactionsMethod__, __ImplicitAccountCreationAddressMethod__, + __AccountsMethod__, __ImplicitAccountsMethod__, __IncomingTransactionsMethod__, __TransactionsMethod__, @@ -99,6 +100,7 @@ export type __AccountMethod__ = | __OutputsMethod__ | __PendingTransactionsMethod__ | __ImplicitAccountCreationAddressMethod__ + | __AccountsMethod__ | __ImplicitAccountsMethod__ | __IncomingTransactionsMethod__ | __TransactionsMethod__ diff --git a/bindings/nodejs/lib/wallet/account.ts b/bindings/nodejs/lib/wallet/account.ts index 117975e1d7..d9e67a4510 100644 --- a/bindings/nodejs/lib/wallet/account.ts +++ b/bindings/nodejs/lib/wallet/account.ts @@ -774,6 +774,23 @@ export class Account { return JSON.parse(response).payload; } + /** + * Returns the accounts of the wallet. + * + * @returns The accounts of the wallet. + */ + async accounts(): Promise { + const response = await this.methodHandler.callAccountMethod( + this.meta.index, + { + name: 'accounts', + }, + ); + + const parsed = JSON.parse(response) as Response; + return plainToInstance(OutputData, parsed.payload); + } + /** * Returns the implicit accounts of the wallet. * diff --git a/bindings/python/iota_sdk/wallet/account.py b/bindings/python/iota_sdk/wallet/account.py index c8fc251e54..7219e560e9 100644 --- a/bindings/python/iota_sdk/wallet/account.py +++ b/bindings/python/iota_sdk/wallet/account.py @@ -278,6 +278,14 @@ def implicit_account_creation_address(self) -> str: 'implicitAccountCreationAddress' ) + def accounts(self) -> List[OutputData]: + """Returns the accounts of the wallet. + """ + outputs = self._call_account_method( + 'accounts' + ) + return [from_dict(OutputData, o) for o in outputs] + def implicit_accounts(self) -> List[OutputData]: """Returns the implicit accounts of the wallet. """ diff --git a/cli/src/wallet_cli/completer.rs b/cli/src/wallet_cli/completer.rs index b11cb140bb..140183b0b6 100644 --- a/cli/src/wallet_cli/completer.rs +++ b/cli/src/wallet_cli/completer.rs @@ -9,6 +9,7 @@ use rustyline::{ }; const WALLET_COMMANDS: &[&str] = &[ + "accounts", "address", "balance", "burn-native-token", diff --git a/cli/src/wallet_cli/mod.rs b/cli/src/wallet_cli/mod.rs index f78c3dc5ce..87720cf67d 100644 --- a/cli/src/wallet_cli/mod.rs +++ b/cli/src/wallet_cli/mod.rs @@ -56,6 +56,8 @@ impl WalletCli { #[derive(Debug, Subcommand)] #[allow(clippy::large_enum_variant)] pub enum WalletCommand { + /// Lists the accounts of the wallet. + Accounts, /// Print the wallet address. Address, /// Print the wallet balance. @@ -304,6 +306,11 @@ impl FromStr for OutputSelector { } } +// `accounts` command +pub async fn accounts_command(wallet: &Wallet) -> Result<(), Error> { + print_outputs(wallet.accounts().await, "Accounts:").await +} + // `address` command pub async fn address_command(wallet: &Wallet) -> Result<(), Error> { print_wallet_address(wallet).await?; @@ -1057,6 +1064,7 @@ pub async fn prompt_internal( } }; match protocol_cli.command { + WalletCommand::Accounts => accounts_command(wallet).await, WalletCommand::Address => address_command(wallet).await, WalletCommand::Balance => balance_command(wallet).await, WalletCommand::BurnNativeToken { token_id, amount } => { diff --git a/sdk/src/wallet/core/mod.rs b/sdk/src/wallet/core/mod.rs index 00ae19d59c..3569f1981c 100644 --- a/sdk/src/wallet/core/mod.rs +++ b/sdk/src/wallet/core/mod.rs @@ -37,7 +37,7 @@ use crate::{ dto::FoundryOutputDto, AccountId, AnchorId, DelegationId, FoundryId, FoundryOutput, NftId, Output, OutputId, TokenId, }, - payload::signed_transaction::{dto::TransactionDto, Transaction, TransactionId}, + payload::signed_transaction::TransactionId, }, TryFromDto, }, @@ -466,6 +466,17 @@ where .collect() } + /// Returns accounts of the wallet. + pub async fn accounts(&self) -> Vec { + self.data() + .await + .unspent_outputs + .values() + .filter(|output_data| output_data.output.is_account()) + .cloned() + .collect() + } + /// Returns all incoming transactions of the wallet pub async fn incoming_transactions(&self) -> Vec { self.data().await.incoming_transactions.values().cloned().collect()