Skip to content

Commit

Permalink
Claim specific output (#121)
Browse files Browse the repository at this point in the history
* Claim specific output

* Rename id to output_id

* Add doc
  • Loading branch information
thibault-martinez authored Jul 7, 2022
1 parent 7a6e377 commit ab7f478
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
14 changes: 13 additions & 1 deletion documentation/docs/03_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,24 @@ Burn a provided NFT.

Tries to claim outputs with storage deposit return, expiration or timelock unlock conditions.

#### Example
#### Parameters

| Name | Optional | Default | Example |
| ----------- | --------- | ------- | ------------------------------------------------------------------------ |
| `output_id` || N/A | "0xd5dff9ee869dfa7796d5132b220cb5c00146c36abba27d3562e2d726decb50850000" |

#### Examples

Try to claim all outputs with storage deposit return, expiration or timelock unlock conditions.
```sh
> Account "main": claim
```

Try to claim a specific output.
```sh
> Account "main": claim 0xd5dff9ee869dfa7796d5132b220cb5c00146c36abba27d3562e2d726decb50850000
```

### `clear`

Clears the terminal.
Expand Down
2 changes: 1 addition & 1 deletion src/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ pub async fn account_prompt_internal(account_handle: AccountHandle) -> Result<bo
burn_native_token_command(&account_handle, token_id, amount).await
}
AccountCommand::BurnNft { nft_id } => burn_nft_command(&account_handle, nft_id).await,
AccountCommand::Claim => claim_command(&account_handle).await,
AccountCommand::Claim { output_id } => claim_command(&account_handle, output_id).await,
AccountCommand::Consolidate => consolidate_command(&account_handle).await,
AccountCommand::DestroyAlias { alias_id } => destroy_alias_command(&account_handle, alias_id).await,
AccountCommand::DestroyFoundry { foundry_id } => {
Expand Down
20 changes: 14 additions & 6 deletions src/command/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub enum AccountCommand {
/// Burn an NFT: `burn-nft "0x..."`
BurnNft { nft_id: String },
/// Claim outputs with storage deposit return, expiration or timelock unlock conditions.
Claim,
Claim { output_id: Option<String> },
/// Consolidate all basic outputs into one address.
Consolidate,
/// Destroy an alias: `destroy-alias "0x..."`
Expand Down Expand Up @@ -150,13 +150,21 @@ pub async fn balance_command(account_handle: &AccountHandle) -> Result<(), Error
}

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

let claiming_txs = account_handle.try_claim_outputs(OutputsToClaim::All).await?;
account_handle
.claim_outputs(vec![OutputId::from_str(&output_id)?])
.await?
} else {
log::info!("Claiming outputs.");

account_handle.try_claim_outputs(OutputsToClaim::All).await?
};

for claim_tx in claiming_txs {
log::info!("Claim transaction sent: {claim_tx:?}");
for claiming_tx in claiming_txs {
log::info!("Claim transaction sent: {claiming_tx:?}");
}

Ok(())
Expand Down

0 comments on commit ab7f478

Please sign in to comment.