Skip to content

Commit 6696bfd

Browse files
authored
Add tx options param to prepare_claim_outputs() (#2237)
* Add tx options param to prepare_claim_outputs() * Add new param * Bump version and set release data
1 parent 3e44c80 commit 6696bfd

File tree

12 files changed

+72
-33
lines changed

12 files changed

+72
-33
lines changed

bindings/core/src/method/wallet.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,11 @@ pub enum WalletMethod {
226226
/// Claim outputs.
227227
/// Expected response: [`PreparedTransaction`](crate::Response::PreparedTransaction)
228228
#[serde(rename_all = "camelCase")]
229-
PrepareClaimOutputs { output_ids_to_claim: Vec<OutputId> },
229+
PrepareClaimOutputs {
230+
output_ids_to_claim: Vec<OutputId>,
231+
#[serde(default)]
232+
options: Option<TransactionOptions>,
233+
},
230234
/// Consolidate outputs.
231235
/// Expected response: [`PreparedTransaction`](crate::Response::PreparedTransaction)
232236
PrepareConsolidateOutputs { params: ConsolidationParams },

bindings/core/src/method_handler/wallet.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,11 @@ pub(crate) async fn call_wallet_method_internal(
234234
let data = wallet.prepare_burn(burn, options).await?;
235235
Response::PreparedTransaction(data)
236236
}
237-
WalletMethod::PrepareClaimOutputs { output_ids_to_claim } => {
238-
let data = wallet.prepare_claim_outputs(output_ids_to_claim).await?;
237+
WalletMethod::PrepareClaimOutputs {
238+
output_ids_to_claim,
239+
options,
240+
} => {
241+
let data = wallet.prepare_claim_outputs(output_ids_to_claim, options).await?;
239242
Response::PreparedTransaction(data)
240243
}
241244
WalletMethod::PrepareConsolidateOutputs { params } => {

bindings/nodejs/CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1919
2020
### Security -->
2121

22+
## 2.0.0-alpha.9 - 2024-05-02
23+
24+
### Added
25+
26+
- `Wallet::prepareClaimOutputs()` optional transactionOptions parameter;
27+
2228
## 2.0.0-alpha.8 - 2024-04-22
2329

2430
### Fixed

bindings/nodejs/lib/types/wallet/bridge/wallet.ts

+1
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ export type __PrepareClaimOutputsMethod__ = {
153153
name: 'prepareClaimOutputs';
154154
data: {
155155
outputIdsToClaim: OutputId[];
156+
options?: TransactionOptions;
156157
};
157158
};
158159

bindings/nodejs/lib/wallet/wallet.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -419,8 +419,11 @@ export class Wallet {
419419
*/
420420
async claimOutputs(
421421
outputIds: OutputId[],
422+
transactionOptions?: TransactionOptions,
422423
): Promise<TransactionWithMetadata> {
423-
return (await this.prepareClaimOutputs(outputIds)).send();
424+
return (
425+
await this.prepareClaimOutputs(outputIds, transactionOptions)
426+
).send();
424427
}
425428

426429
/**
@@ -431,11 +434,13 @@ export class Wallet {
431434
*/
432435
async prepareClaimOutputs(
433436
outputIds: OutputId[],
437+
transactionOptions?: TransactionOptions,
434438
): Promise<PreparedTransaction> {
435439
const response = await this.methodHandler.callMethod({
436440
name: 'prepareClaimOutputs',
437441
data: {
438442
outputIdsToClaim: outputIds,
443+
options: transactionOptions,
439444
},
440445
});
441446
const parsed = JSON.parse(

bindings/nodejs/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@iota/sdk",
3-
"version": "2.0.0-alpha.8",
3+
"version": "2.0.0-alpha.9",
44
"description": "Node.js binding to the IOTA SDK library",
55
"main": "out/index.js",
66
"types": "out/index.d.ts",

bindings/python/iota_sdk/wallet/wallet.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -286,18 +286,19 @@ def prepare_burn_nft(self,
286286
return PreparedTransaction(self, prepared)
287287

288288
def claim_outputs(
289-
self, output_ids_to_claim: List[OutputId]) -> TransactionWithMetadata:
289+
self, output_ids_to_claim: List[OutputId], options: Optional[TransactionOptions] = None) -> TransactionWithMetadata:
290290
"""Claim outputs.
291291
"""
292-
return self.prepare_claim_outputs(output_ids_to_claim).send()
292+
return self.prepare_claim_outputs(output_ids_to_claim, options).send()
293293

294294
def prepare_claim_outputs(
295-
self, output_ids_to_claim: List[OutputId]) -> PreparedTransaction:
295+
self, output_ids_to_claim: List[OutputId], options: Optional[TransactionOptions] = None) -> PreparedTransaction:
296296
"""Claim outputs.
297297
"""
298298
return PreparedTransaction(self, PreparedTransactionData.from_dict(self._call_method(
299299
'prepareClaimOutputs', {
300-
'outputIdsToClaim': output_ids_to_claim
300+
'outputIdsToClaim': output_ids_to_claim,
301+
'options': options
301302
}
302303
)))
303304

cli/src/wallet_cli/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ pub async fn claim_command(wallet: &Wallet, output_id: Option<OutputId>) -> Resu
568568
if let Some(output_id) = output_id {
569569
println_log_info!("Claiming output {output_id}");
570570

571-
let transaction = wallet.claim_outputs([output_id]).await?;
571+
let transaction = wallet.claim_outputs([output_id], None).await?;
572572

573573
println_log_info!(
574574
"Claiming transaction sent:\n{:?}\n{:?}",
@@ -587,7 +587,7 @@ pub async fn claim_command(wallet: &Wallet, output_id: Option<OutputId>) -> Resu
587587
// Doing chunks of only 60, because we might need to create the double amount of outputs, because of potential
588588
// storage deposit return unlock conditions and also consider the remainder output.
589589
for output_ids_chunk in output_ids.chunks(60) {
590-
let transaction = wallet.claim_outputs(output_ids_chunk.to_vec()).await?;
590+
let transaction = wallet.claim_outputs(output_ids_chunk.to_vec(), None).await?;
591591
println_log_info!(
592592
"Claiming transaction sent:\n{:?}\n{:?}",
593593
transaction.transaction_id,

sdk/examples/how_tos/advanced_transactions/claim_transaction.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
3737
println!("{}", output_id);
3838
}
3939

40-
let transaction = wallet.claim_outputs(output_ids).await?;
40+
let transaction = wallet.claim_outputs(output_ids, None).await?;
4141
println!("Transaction sent: {}", transaction.transaction_id);
4242

4343
wallet

sdk/src/wallet/operations/output_claiming.rs

+25-12
Original file line numberDiff line numberDiff line change
@@ -230,12 +230,15 @@ where
230230
pub async fn claim_outputs<I: IntoIterator<Item = OutputId> + Send>(
231231
&self,
232232
output_ids_to_claim: I,
233+
transaction_options: impl Into<Option<TransactionOptions>> + Send,
233234
) -> Result<TransactionWithMetadata, WalletError>
234235
where
235236
I::IntoIter: Send,
236237
{
237238
log::debug!("[OUTPUT_CLAIMING] claim_outputs");
238-
let prepared_transaction = self.prepare_claim_outputs(output_ids_to_claim).await?;
239+
let prepared_transaction = self
240+
.prepare_claim_outputs(output_ids_to_claim, transaction_options)
241+
.await?;
239242

240243
let claim_tx = self.sign_and_submit_transaction(prepared_transaction, None).await?;
241244

@@ -251,6 +254,7 @@ where
251254
pub async fn prepare_claim_outputs<I: IntoIterator<Item = OutputId> + Send>(
252255
&self,
253256
output_ids_to_claim: I,
257+
transaction_options: impl Into<Option<TransactionOptions>> + Send,
254258
) -> Result<PreparedTransactionData, WalletError>
255259
where
256260
I::IntoIter: Send,
@@ -278,7 +282,8 @@ where
278282
));
279283
}
280284

281-
let wallet_address = self.address().await;
285+
let transaction_options = transaction_options.into();
286+
let remainder_address = self.get_remainder_address(transaction_options.clone()).await?;
282287
drop(wallet_ledger);
283288

284289
let mut nft_outputs_to_send = Vec::new();
@@ -301,31 +306,39 @@ where
301306
// deposit for the remaining amount and possible native tokens
302307
NftOutputBuilder::from(nft_output)
303308
.with_nft_id(nft_output.nft_id_non_null(&output_data.output_id))
304-
.with_unlock_conditions([AddressUnlockCondition::new(&wallet_address)])
309+
.with_unlock_conditions([AddressUnlockCondition::new(remainder_address.clone())])
305310
.finish_output()?
306311
} else {
307312
NftOutputBuilder::from(nft_output)
308313
.with_minimum_amount(storage_score_params)
309314
.with_nft_id(nft_output.nft_id_non_null(&output_data.output_id))
310-
.with_unlock_conditions([AddressUnlockCondition::new(&wallet_address)])
315+
.with_unlock_conditions([AddressUnlockCondition::new(remainder_address.clone())])
311316
.finish_output()?
312317
};
313318

314319
nft_outputs_to_send.push(nft_output);
315320
}
316321
}
317322

323+
let required_inputs = outputs_to_claim
324+
.iter()
325+
.map(|o| o.output_id)
326+
// add additional inputs
327+
.chain(possible_additional_inputs.iter().map(|o| o.output_id))
328+
.collect();
329+
318330
self.prepare_send_outputs(
319331
// We only need to provide the NFT outputs, ISA automatically creates basic outputs as remainder outputs
320332
nft_outputs_to_send,
321-
TransactionOptions {
322-
required_inputs: outputs_to_claim
323-
.iter()
324-
.map(|o| o.output_id)
325-
// add additional inputs
326-
.chain(possible_additional_inputs.iter().map(|o| o.output_id))
327-
.collect(),
328-
..Default::default()
333+
match transaction_options {
334+
Some(mut tx_options) => {
335+
tx_options.required_inputs = required_inputs;
336+
tx_options
337+
}
338+
None => TransactionOptions {
339+
required_inputs,
340+
..Default::default()
341+
},
329342
},
330343
)
331344
.await

sdk/src/wallet/operations/transaction/prepare_output.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ impl<S: 'static + SecretManage> Wallet<S> {
259259
}
260260

261261
// Get a remainder address based on transaction_options or use the first account address
262-
async fn get_remainder_address(
262+
pub(crate) async fn get_remainder_address(
263263
&self,
264264
transaction_options: impl Into<Option<TransactionOptions>> + Send,
265265
) -> Result<Address, WalletError> {

sdk/tests/wallet/claim_outputs.rs

+14-8
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ async fn claim_2_basic_micro_outputs() -> Result<(), Box<dyn std::error::Error>>
5656
let base_coin_amount_before_claiming = balance.base_coin().available();
5757

5858
let tx = wallet_0
59-
.claim_outputs(wallet_0.claimable_outputs(OutputsToClaim::MicroTransactions).await?)
59+
.claim_outputs(
60+
wallet_0.claimable_outputs(OutputsToClaim::MicroTransactions).await?,
61+
None,
62+
)
6063
.await?;
6164
wallet_0
6265
.wait_for_transaction_acceptance(&tx.transaction_id, None, None)
@@ -113,7 +116,7 @@ async fn claim_1_of_2_basic_outputs() -> Result<(), Box<dyn std::error::Error>>
113116
let base_coin_amount_before_claiming = balance.base_coin().available();
114117

115118
let tx = wallet_0
116-
.claim_outputs(wallet_0.claimable_outputs(OutputsToClaim::Amount).await?)
119+
.claim_outputs(wallet_0.claimable_outputs(OutputsToClaim::Amount).await?, None)
117120
.await?;
118121
wallet_0
119122
.wait_for_transaction_acceptance(&tx.transaction_id, None, None)
@@ -193,7 +196,7 @@ async fn claim_2_basic_outputs_no_available_in_claim_account() -> Result<(), Box
193196
let base_coin_amount_before_claiming = balance.base_coin().available();
194197

195198
let tx = wallet_1
196-
.claim_outputs(wallet_1.claimable_outputs(OutputsToClaim::All).await?)
199+
.claim_outputs(wallet_1.claimable_outputs(OutputsToClaim::All).await?, None)
197200
.await?;
198201
wallet_1
199202
.wait_for_transaction_acceptance(&tx.transaction_id, None, None)
@@ -281,7 +284,7 @@ async fn claim_2_native_tokens() -> Result<(), Box<dyn std::error::Error>> {
281284
assert_eq!(balance.potentially_locked_outputs().len(), 2);
282285

283286
let tx = wallet_0
284-
.claim_outputs(wallet_0.claimable_outputs(OutputsToClaim::NativeTokens).await?)
287+
.claim_outputs(wallet_0.claimable_outputs(OutputsToClaim::NativeTokens).await?, None)
285288
.await?;
286289
wallet_0
287290
.wait_for_transaction_acceptance(&tx.transaction_id, None, None)
@@ -404,7 +407,7 @@ async fn claim_2_native_tokens_no_available_balance_in_claim_account() -> Result
404407
assert_eq!(balance.potentially_locked_outputs().len(), 2);
405408

406409
let tx = wallet_1
407-
.claim_outputs(wallet_1.claimable_outputs(OutputsToClaim::NativeTokens).await?)
410+
.claim_outputs(wallet_1.claimable_outputs(OutputsToClaim::NativeTokens).await?, None)
408411
.await?;
409412
wallet_1
410413
.wait_for_transaction_acceptance(&tx.transaction_id, None, None)
@@ -470,7 +473,7 @@ async fn claim_2_nft_outputs() -> Result<(), Box<dyn std::error::Error>> {
470473
assert_eq!(balance.potentially_locked_outputs().len(), 2);
471474

472475
let tx = wallet_0
473-
.claim_outputs(wallet_0.claimable_outputs(OutputsToClaim::Nfts).await?)
476+
.claim_outputs(wallet_0.claimable_outputs(OutputsToClaim::Nfts).await?, None)
474477
.await?;
475478
wallet_0
476479
.wait_for_transaction_acceptance(&tx.transaction_id, None, None)
@@ -547,7 +550,7 @@ async fn claim_2_nft_outputs_no_available_in_claim_account() -> Result<(), Box<d
547550
assert_eq!(balance.potentially_locked_outputs().len(), 2);
548551

549552
let tx = wallet_1
550-
.claim_outputs(wallet_1.claimable_outputs(OutputsToClaim::Nfts).await?)
553+
.claim_outputs(wallet_1.claimable_outputs(OutputsToClaim::Nfts).await?, None)
551554
.await?;
552555
wallet_1
553556
.wait_for_transaction_acceptance(&tx.transaction_id, None, None)
@@ -612,7 +615,10 @@ async fn claim_basic_micro_output_error() -> Result<(), Box<dyn std::error::Erro
612615
assert_eq!(balance.potentially_locked_outputs().len(), 1);
613616

614617
let result = wallet_1
615-
.claim_outputs(wallet_1.claimable_outputs(OutputsToClaim::MicroTransactions).await?)
618+
.claim_outputs(
619+
wallet_1.claimable_outputs(OutputsToClaim::MicroTransactions).await?,
620+
None,
621+
)
616622
.await;
617623
assert!(matches!(
618624
result,

0 commit comments

Comments
 (0)