Skip to content

Commit

Permalink
Added fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Brord van Wierst committed Jan 10, 2024
1 parent 4374ef0 commit 47148fb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
11 changes: 1 addition & 10 deletions cli/src/wallet_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,16 +356,7 @@ pub async fn address_command(wallet: &Wallet) -> Result<(), Error> {
// `allot-mana` command
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)))
.ok_or(WalletError::AccountNotFound)?;
let account_id = account_id.unwrap_or(wallet_data.first_account_id()?);
drop(wallet_data);

let transaction = wallet.allot_mana([ManaAllotment::new(account_id, mana)?], None).await?;
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())
}

pub fn first_account_id(&self) -> Result<AccountId> {
self.accounts()
.next()
.map(|o| o.output.as_account().account_id_non_null(&o.output_id))
.or(self.implicit_accounts().next().map(|o| AccountId::from(&o.output_id)))
.ok_or(Error::AccountNotFound)
}

/// 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
18 changes: 3 additions & 15 deletions sdk/src/wallet/operations/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,11 @@ 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)))
.ok_or(Error::AccountNotFound)?;
let issuer_id = issuer_id.into().unwrap_or(wallet_data.first_account_id()?);
drop(wallet_data);

let block = self
.client()
Expand Down

0 comments on commit 47148fb

Please sign in to comment.