diff --git a/crates/iota-sdk/examples/transaction_builder/batch_tx.rs b/crates/iota-sdk/examples/transaction_builder/batch_tx.rs index a2c7933f126..2fe664a30db 100644 --- a/crates/iota-sdk/examples/transaction_builder/batch_tx.rs +++ b/crates/iota-sdk/examples/transaction_builder/batch_tx.rs @@ -41,7 +41,7 @@ async fn main() -> Result<(), anyhow::Error> { object_id: coin_object_id_2, }), ], - Some(gas_coin_object_id), + gas_coin_object_id, gas_budget, ) .await?; diff --git a/crates/iota-sdk/examples/transaction_builder/move_package.rs b/crates/iota-sdk/examples/transaction_builder/move_package.rs index 143c8874811..4d29e774b6b 100644 --- a/crates/iota-sdk/examples/transaction_builder/move_package.rs +++ b/crates/iota-sdk/examples/transaction_builder/move_package.rs @@ -36,7 +36,7 @@ async fn main() -> Result<(), anyhow::Error> { sender, module.get_package_bytes(false), module.published_dependency_ids(), - Some(gas_coin_object_id), + gas_coin_object_id, gas_budget, ) .await?; @@ -93,7 +93,7 @@ async fn main() -> Result<(), anyhow::Error> { upgrade_capability, 0, package_digest.to_vec(), - Some(gas_coin_object_id), + gas_coin_object_id, gas_budget, ) .await?; diff --git a/crates/iota-sdk/examples/transaction_builder/pay.rs b/crates/iota-sdk/examples/transaction_builder/pay.rs index 3e116a5a50c..1dbf1015ac0 100644 --- a/crates/iota-sdk/examples/transaction_builder/pay.rs +++ b/crates/iota-sdk/examples/transaction_builder/pay.rs @@ -34,7 +34,7 @@ async fn main() -> Result<(), anyhow::Error> { vec![coin_object_id], vec![recipient], vec![1_000], - Some(gas_coin_object_id), + gas_coin_object_id, gas_budget, ) .await?; diff --git a/crates/iota-sdk/examples/transaction_builder/stake.rs b/crates/iota-sdk/examples/transaction_builder/stake.rs index f73518bd49a..98df0109bff 100644 --- a/crates/iota-sdk/examples/transaction_builder/stake.rs +++ b/crates/iota-sdk/examples/transaction_builder/stake.rs @@ -43,7 +43,7 @@ async fn main() -> Result<(), anyhow::Error> { sender, vec![coin.coin_object_id], // Min delegation amount is 1 IOTA - Some(1_000_000_000), + 1_000_000_000, validator, None, gas_budget, diff --git a/crates/iota-sdk/examples/transaction_builder/transfer.rs b/crates/iota-sdk/examples/transaction_builder/transfer.rs index fc024501ead..9674672b31f 100644 --- a/crates/iota-sdk/examples/transaction_builder/transfer.rs +++ b/crates/iota-sdk/examples/transaction_builder/transfer.rs @@ -50,7 +50,7 @@ async fn main() -> Result<(), anyhow::Error> { .transfer_object( sender, object_to_transfer.coin_object_id, - Some(gas_coin.coin_object_id), + gas_coin.coin_object_id, gas_budget, recipient, ) diff --git a/crates/iota-sdk/examples/utils.rs b/crates/iota-sdk/examples/utils.rs index aa3959e96bf..dc2a57a0c76 100644 --- a/crates/iota-sdk/examples/utils.rs +++ b/crates/iota-sdk/examples/utils.rs @@ -291,7 +291,7 @@ pub fn retrieve_wallet() -> Result { client_config.active_address = Some(default_active_address); client_config.save(&wallet_conf)?; - let wallet = WalletContext::new(&wallet_conf, Some(std::time::Duration::from_secs(60)), None)?; + let wallet = WalletContext::new(&wallet_conf, std::time::Duration::from_secs(60), None)?; Ok(wallet) } diff --git a/crates/iota-sdk/src/wallet_context.rs b/crates/iota-sdk/src/wallet_context.rs index f7e2072e322..a8ee2a85a30 100644 --- a/crates/iota-sdk/src/wallet_context.rs +++ b/crates/iota-sdk/src/wallet_context.rs @@ -122,10 +122,10 @@ impl WalletContext { .read_api() .get_owned_objects( address, - Some(IotaObjectResponseQuery::new( + IotaObjectResponseQuery::new( Some(IotaObjectDataFilter::StructType(GasCoin::type_())), Some(IotaObjectDataOptions::full_content()), - )), + ), cursor, None, ) @@ -212,10 +212,10 @@ impl WalletContext { .read_api() .get_owned_objects( address, - Some(IotaObjectResponseQuery::new( + IotaObjectResponseQuery::new( Some(IotaObjectDataFilter::StructType(GasCoin::type_())), Some(IotaObjectDataOptions::full_content()), - )), + ), None, limit, ) @@ -235,7 +235,7 @@ impl WalletContext { address: IotaAddress, ) -> anyhow::Result> { Ok(self - .get_gas_objects_owned_by_address(address, Some(1)) + .get_gas_objects_owned_by_address(address, 1) .await? .pop()) } @@ -335,7 +335,7 @@ impl WalletContext { .with_events() .with_object_changes() .with_balance_changes(), - Some(iota_types::quorum_driver_types::ExecuteTransactionRequestType::WaitForLocalExecution), + iota_types::quorum_driver_types::ExecuteTransactionRequestType::WaitForLocalExecution, ) .await?) } diff --git a/crates/iota-transaction-builder/src/lib.rs b/crates/iota-transaction-builder/src/lib.rs index c297e3c3e12..2dd0c56316f 100644 --- a/crates/iota-transaction-builder/src/lib.rs +++ b/crates/iota-transaction-builder/src/lib.rs @@ -72,7 +72,7 @@ impl TransactionBuilder { async fn select_gas( &self, signer: IotaAddress, - input_gas: Option, + input_gas: impl Into>, gas_budget: u64, input_objects: Vec, gas_price: u64, @@ -82,7 +82,7 @@ impl TransactionBuilder { "Gas budget {gas_budget} is less than the reference gas price {gas_price}. The gas budget must be at least the current reference gas price of {gas_price}." ) } - if let Some(gas) = input_gas { + if let Some(gas) = input_gas.into() { self.get_object_ref(gas).await } else { let gas_objs = self.0.get_owned_objects(signer, GasCoin::type_()).await?; @@ -118,14 +118,14 @@ impl TransactionBuilder { kind: TransactionKind, gas_budget: u64, gas_price: u64, - gas_payment: Option>, - gas_sponsor: Option, + gas_payment: impl Into>>, + gas_sponsor: impl Into>, ) -> TransactionData { let gas_payment = self - .input_refs(gas_payment.unwrap_or_default().as_ref()) + .input_refs(gas_payment.into().unwrap_or_default().as_ref()) .await .unwrap_or_default(); - let gas_sponsor = gas_sponsor.unwrap_or(sender); + let gas_sponsor = gas_sponsor.into().unwrap_or(sender); TransactionData::new_with_gas_coins_allow_sponsor( kind, sender, @@ -147,7 +147,7 @@ impl TransactionBuilder { gas_budget: u64, gas_price: u64, gas_payment: Vec, - gas_sponsor: Option, + gas_sponsor: impl Into>, ) -> Result { let gas_payment = if gas_payment.is_empty() { let input_objs = kind @@ -171,7 +171,7 @@ impl TransactionBuilder { gas_payment, gas_budget, gas_price, - gas_sponsor.unwrap_or(sender), + gas_sponsor.into().unwrap_or(sender), )) } @@ -190,7 +190,7 @@ impl TransactionBuilder { &self, signer: IotaAddress, object_id: ObjectID, - gas: Option, + gas: impl Into>, gas_budget: u64, recipient: IotaAddress, ) -> anyhow::Result { @@ -224,10 +224,10 @@ impl TransactionBuilder { pub fn transfer_iota_tx_kind( &self, recipient: IotaAddress, - amount: Option, + amount: impl Into>, ) -> TransactionKind { let mut builder = ProgrammableTransactionBuilder::new(); - builder.transfer_iota(recipient, amount); + builder.transfer_iota(recipient, amount.into()); let pt = builder.finish(); TransactionKind::programmable(pt) } @@ -238,12 +238,17 @@ impl TransactionBuilder { iota_object_id: ObjectID, gas_budget: u64, recipient: IotaAddress, - amount: Option, + amount: impl Into>, ) -> anyhow::Result { let object = self.get_object_ref(iota_object_id).await?; let gas_price = self.0.get_reference_gas_price().await?; Ok(TransactionData::new_transfer_iota( - recipient, signer, amount, object, gas_budget, gas_price, + recipient, + signer, + amount.into(), + object, + gas_budget, + gas_price, )) } @@ -265,9 +270,11 @@ impl TransactionBuilder { input_coins: Vec, recipients: Vec, amounts: Vec, - gas: Option, + gas: impl Into>, gas_budget: u64, ) -> anyhow::Result { + let gas = gas.into(); + if let Some(gas) = gas { if input_coins.contains(&gas) { return Err(anyhow!( @@ -406,10 +413,12 @@ impl TransactionBuilder { function: &str, type_args: Vec, call_args: Vec, - gas: Option, + gas: impl Into>, gas_budget: u64, - gas_price: Option, + gas_price: impl Into>, ) -> anyhow::Result { + let gas_price = gas_price.into(); + let mut builder = ProgrammableTransactionBuilder::new(); self.single_move_call( &mut builder, @@ -610,7 +619,7 @@ impl TransactionBuilder { sender: IotaAddress, compiled_modules: Vec>, dep_ids: Vec, - gas: Option, + gas: impl Into>, gas_budget: u64, ) -> anyhow::Result { let gas_price = self.0.get_reference_gas_price().await?; @@ -704,7 +713,7 @@ impl TransactionBuilder { upgrade_capability: ObjectID, upgrade_policy: u8, digest: Vec, - gas: Option, + gas: impl Into>, gas_budget: u64, ) -> anyhow::Result { let gas_price = self.0.get_reference_gas_price().await?; @@ -742,9 +751,12 @@ impl TransactionBuilder { pub async fn split_coin_tx_kind( &self, coin_object_id: ObjectID, - split_amounts: Option>, - split_count: Option, + split_amounts: impl Into>>, + split_count: impl Into>, ) -> Result { + let split_amounts = split_amounts.into(); + let split_count = split_count.into(); + if split_amounts.is_none() && split_count.is_none() { bail!( "Either split_amounts or split_count must be provided for split_coin transaction." @@ -791,7 +803,7 @@ impl TransactionBuilder { signer: IotaAddress, coin_object_id: ObjectID, split_amounts: Vec, - gas: Option, + gas: impl Into>, gas_budget: u64, ) -> anyhow::Result { let coin = self @@ -829,7 +841,7 @@ impl TransactionBuilder { signer: IotaAddress, coin_object_id: ObjectID, split_count: u64, - gas: Option, + gas: impl Into>, gas_budget: u64, ) -> anyhow::Result { let coin = self @@ -897,7 +909,7 @@ impl TransactionBuilder { signer: IotaAddress, primary_coin: ObjectID, coin_to_merge: ObjectID, - gas: Option, + gas: impl Into>, gas_budget: u64, ) -> anyhow::Result { let coin = self @@ -940,7 +952,7 @@ impl TransactionBuilder { &self, signer: IotaAddress, single_transaction_params: Vec, - gas: Option, + gas: impl Into>, gas_budget: u64, ) -> anyhow::Result { fp_ensure!( @@ -997,9 +1009,9 @@ impl TransactionBuilder { &self, signer: IotaAddress, mut coins: Vec, - amount: Option, + amount: impl Into>, validator: IotaAddress, - gas: Option, + gas: impl Into>, gas_budget: u64, ) -> anyhow::Result { let gas_price = self.0.get_reference_gas_price().await?; @@ -1037,7 +1049,7 @@ impl TransactionBuilder { builder.input(CallArg::IOTA_SYSTEM_MUT).unwrap(), builder.make_obj_vec(obj_vec)?, builder - .input(CallArg::Pure(bcs::to_bytes(&amount)?)) + .input(CallArg::Pure(bcs::to_bytes(&amount.into())?)) .unwrap(), builder .input(CallArg::Pure(bcs::to_bytes(&validator)?)) @@ -1065,7 +1077,7 @@ impl TransactionBuilder { &self, signer: IotaAddress, staked_iota: ObjectID, - gas: Option, + gas: impl Into>, gas_budget: u64, ) -> anyhow::Result { let staked_iota = self.get_object_ref(staked_iota).await?;