Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added first_account_id getter #1828

Merged
merged 10 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions cli/src/wallet_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -367,14 +367,7 @@ pub async fn address_command(wallet: &Wallet) -> Result<(), Error> {
pub async fn allot_mana_command(wallet: &Wallet, mana: u64, account_id: Option<AccountId>) -> Result<(), Error> {
let wallet_data = wallet.data().await;
let account_id = account_id
.or(wallet_data
.accounts()
.next()
.map(|o| o.output.as_account().account_id_non_null(&o.output_id)))
.or(wallet_data
.implicit_accounts()
.next()
.map(|o| AccountId::from(&o.output_id)))
.or_else(|| wallet_data.first_account_id())
thibault-martinez marked this conversation as resolved.
Show resolved Hide resolved
.ok_or(WalletError::AccountNotFound)?;
drop(wallet_data);

Expand Down
8 changes: 8 additions & 0 deletions sdk/src/wallet/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,14 @@ impl WalletData {
.filter(|output_data| output_data.output.is_account())
}

// Returns the first possible Account id, which can be an implicit account.
pub fn first_account_id(&self) -> Option<AccountId> {
self.accounts()
.next()
.map(|o| o.output.as_account().account_id_non_null(&o.output_id))
.or_else(|| self.implicit_accounts().next().map(|o| AccountId::from(&o.output_id)))
}

/// Get the [`OutputData`] of an output stored in the wallet.
pub fn get_output(&self, output_id: &OutputId) -> Option<&OutputData> {
self.outputs.get(output_id)
Expand Down
15 changes: 3 additions & 12 deletions sdk/src/wallet/operations/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,14 @@ where
issuer_id: impl Into<Option<AccountId>> + Send,
) -> Result<BlockId> {
log::debug!("submit_basic_block");
let wallet_data = self.data().await;

// If an issuer ID is provided, use it; otherwise, use the first available account or implicit account.
let issuer_id = issuer_id
.into()
.or(self
.data()
.await
.accounts()
.next()
.map(|o| o.output.as_account().account_id_non_null(&o.output_id)))
.or(self
.data()
.await
.implicit_accounts()
.next()
.map(|o| AccountId::from(&o.output_id)))
.or_else(|| wallet_data.first_account_id())
.ok_or(Error::AccountNotFound)?;
drop(wallet_data);

let block = self
.client()
Expand Down