Skip to content

Commit

Permalink
Update to 1 tx for claiming and consolidation (#148)
Browse files Browse the repository at this point in the history
* Update to 1 tx claiming from wallet.rs

* Update consolidation to a single transaction
  • Loading branch information
Thoralf-M authored Sep 16, 2022
1 parent 8ecf673 commit 7e13a16
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ path = "src/main.rs"
clap = { version = "3.2.8", default-features = false, features = [ "derive", "std" ] }
dialoguer = { version = "0.10.1", default-features = false, features = [ "password" ] }
fern-logger = { version = "0.5.0", default-features = false }
iota-wallet = { git = "https://github.com/iotaledger/wallet.rs", rev = "58df4927d4894b300d929d5099faa654459c82fc", default-features = false, features = [ "storage", "stronghold" ] }
iota-wallet = { git = "https://github.com/iotaledger/wallet.rs", rev = "a45278f2c06058a24bd056a9f91f08d3e42fa9fa", default-features = false, features = [ "storage", "stronghold" ] }
log = { version = "0.4.17", default-features = false }
prefix-hex = { version = "0.4.0", default-features = false, features = [ "std" ] }
thiserror = { version = "1.0.31", default-features = false }
Expand Down
33 changes: 21 additions & 12 deletions src/command/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,32 @@ pub async fn balance_command(account_handle: &AccountHandle) -> Result<(), Error

// `claim` command
pub async fn claim_command(account_handle: &AccountHandle, output_id: Option<String>) -> Result<(), Error> {
let claiming_txs = if let Some(output_id) = output_id {
if let Some(output_id) = output_id {
log::info!("Claiming output {output_id}");

account_handle
let claiming_tx = account_handle
.claim_outputs(vec![OutputId::from_str(&output_id)?])
.await?
.await?;

log::info!("Claim transaction sent: {claiming_tx:?}");
} else {
log::info!("Claiming outputs.");

account_handle.try_claim_outputs(OutputsToClaim::All).await?
};
let output_ids = account_handle
.get_unlockable_outputs_with_additional_unlock_conditions(OutputsToClaim::All)
.await?;

for claiming_tx in claiming_txs {
log::info!("Claim transaction sent: {claiming_tx:?}");
}
if output_ids.is_empty() {
log::info!("No outputs available to claim.");
}

// Doing chunks of only 60, because we might need to create the double amount of outputs, because of potential
// storage deposit return unlock conditions and also consider the remainder output.
for output_ids_chunk in output_ids.chunks(60) {
let claiming_tx = account_handle.claim_outputs(output_ids_chunk.to_vec()).await?;
log::info!("Claim transaction sent: {claiming_tx:?}");
}
};

Ok(())
}
Expand All @@ -193,11 +204,9 @@ pub async fn claim_command(account_handle: &AccountHandle, output_id: Option<Str
pub async fn consolidate_command(account_handle: &AccountHandle) -> Result<(), Error> {
log::info!("Consolidating outputs.");

let consolidation_txs = account_handle.consolidate_outputs(true, None).await?;
let consolidation_tx = account_handle.consolidate_outputs(true, None).await?;

for consolidation_tx in consolidation_txs {
log::info!("Consolidation transaction sent: {consolidation_tx:?}");
}
log::info!("Consolidation transaction sent: {consolidation_tx:?}");

Ok(())
}
Expand Down

0 comments on commit 7e13a16

Please sign in to comment.