Skip to content

Commit

Permalink
PR suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Coats committed Nov 30, 2023
1 parent 8ad09a5 commit 4e7324c
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 25 deletions.
2 changes: 2 additions & 0 deletions bindings/core/src/method_handler/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
.data()
.await
.incoming_transactions()
.values()
.map(TransactionWithMetadataDto::from)
.collect(),
),
Expand Down Expand Up @@ -409,6 +410,7 @@ pub(crate) async fn call_wallet_method_internal(wallet: &Wallet, method: WalletM
.data()
.await
.transactions()
.values()
.map(TransactionWithMetadataDto::from)
.collect(),
),
Expand Down
6 changes: 3 additions & 3 deletions cli/src/wallet_cli/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -823,9 +823,9 @@ pub async fn sync_command(wallet: &Wallet) -> Result<(), Error> {
pub async fn transaction_command(wallet: &Wallet, selector: TransactionSelector) -> Result<(), Error> {
let wallet_data = wallet.data().await;
let transaction = match selector {
TransactionSelector::Id(id) => wallet_data.transactions().find(|tx| tx.transaction_id == id),
TransactionSelector::Id(id) => wallet_data.get_transaction(&id),
TransactionSelector::Index(index) => {
let mut transactions = wallet_data.transactions().collect::<Vec<_>>();
let mut transactions = wallet_data.transactions().values().collect::<Vec<_>>();
transactions.sort_unstable_by(|a, b| b.timestamp.cmp(&a.timestamp));
transactions.into_iter().nth(index)
}
Expand All @@ -843,7 +843,7 @@ pub async fn transaction_command(wallet: &Wallet, selector: TransactionSelector)
/// `transactions` command
pub async fn transactions_command(wallet: &Wallet, show_details: bool) -> Result<(), Error> {
let wallet_data = wallet.data().await;
let mut transactions = wallet_data.transactions().collect::<Vec<_>>();
let mut transactions = wallet_data.transactions().values().collect::<Vec<_>>();
transactions.sort_unstable_by(|a, b| b.timestamp.cmp(&a.timestamp));

if transactions.is_empty() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ async fn main() -> Result<()> {

// Print transaction ids
println!("Sent transactions:");
for transaction in wallet.data().await.transactions() {
println!("{}", transaction.transaction_id);
for transaction_id in wallet.data().await.transactions().keys() {
println!("{}", transaction_id);
}

// Print received transaction ids
println!("Received transactions:");
for transaction in wallet.data().await.incoming_transactions() {
println!("{}", transaction.transaction_id);
for transaction_id in wallet.data().await.incoming_transactions().keys() {
println!("{}", transaction_id);
}

Ok(())
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/wallet/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,13 +331,13 @@ impl WalletData {
}

/// Returns all incoming transactions of the wallet
pub fn incoming_transactions(&self) -> impl Iterator<Item = &TransactionWithMetadata> {
self.incoming_transactions.values()
pub fn incoming_transactions(&self) -> &HashMap<TransactionId, TransactionWithMetadata> {
&self.incoming_transactions
}

/// Returns all transactions of the wallet
pub fn transactions(&self) -> impl Iterator<Item = &TransactionWithMetadata> {
self.transactions.values()
pub fn transactions(&self) -> &HashMap<TransactionId, TransactionWithMetadata> {
&self.transactions
}

/// Returns all pending transactions of the wallet
Expand Down
8 changes: 1 addition & 7 deletions sdk/src/wallet/operations/syncing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,7 @@ where

let wallet_address_with_unspent_outputs = AddressWithUnspentOutputs {
address: self.address().await,
output_ids: self
.data()
.await
.unspent_outputs()
.values()
.map(|data| data.output_id)
.collect(),
output_ids: self.data().await.unspent_outputs().keys().copied().collect(),
internal: false,
key_index: 0,
};
Expand Down
8 changes: 1 addition & 7 deletions sdk/src/wallet/operations/transaction/high_level/send_nft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,7 @@ where
self.client().bech32_hrp_matches(address.hrp()).await?;

// Find nft output from the inputs
if let Some(nft_output_data) = self.data().await.unspent_outputs().values().find(|o| {
if let Output::Nft(nft_output) = &o.output {
nft_id == nft_output.nft_id_non_null(&o.output_id)
} else {
false
}
}) {
if let Some(nft_output_data) = self.data().await.unspent_nft_output(&nft_id) {
if let Output::Nft(nft_output) = &nft_output_data.output {
// Set the nft id and new address unlock condition
let nft_builder = NftOutputBuilder::from(nft_output)
Expand Down

0 comments on commit 4e7324c

Please sign in to comment.