Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/iota-sdk/examples/transaction_builder/batch_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down Expand Up @@ -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?;
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-sdk/examples/transaction_builder/pay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-sdk/examples/transaction_builder/stake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-sdk/examples/transaction_builder/transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion crates/iota-sdk/examples/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ pub fn retrieve_wallet() -> Result<WalletContext, anyhow::Error> {
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)
}
Expand Down
12 changes: 6 additions & 6 deletions crates/iota-sdk/src/wallet_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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,
)
Expand All @@ -235,7 +235,7 @@ impl WalletContext {
address: IotaAddress,
) -> anyhow::Result<Option<ObjectRef>> {
Ok(self
.get_gas_objects_owned_by_address(address, Some(1))
.get_gas_objects_owned_by_address(address, 1)
.await?
.pop())
}
Expand Down Expand Up @@ -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?)
}
Expand Down
68 changes: 40 additions & 28 deletions crates/iota-transaction-builder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl TransactionBuilder {
async fn select_gas(
&self,
signer: IotaAddress,
input_gas: Option<ObjectID>,
input_gas: impl Into<Option<ObjectID>>,
gas_budget: u64,
input_objects: Vec<ObjectID>,
gas_price: u64,
Expand All @@ -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?;
Expand Down Expand Up @@ -118,14 +118,14 @@ impl TransactionBuilder {
kind: TransactionKind,
gas_budget: u64,
gas_price: u64,
gas_payment: Option<Vec<ObjectID>>,
gas_sponsor: Option<IotaAddress>,
gas_payment: impl Into<Option<Vec<ObjectID>>>,
gas_sponsor: impl Into<Option<IotaAddress>>,
) -> 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,
Expand All @@ -147,7 +147,7 @@ impl TransactionBuilder {
gas_budget: u64,
gas_price: u64,
gas_payment: Vec<ObjectID>,
gas_sponsor: Option<IotaAddress>,
gas_sponsor: impl Into<Option<IotaAddress>>,
) -> Result<TransactionData, anyhow::Error> {
let gas_payment = if gas_payment.is_empty() {
let input_objs = kind
Expand All @@ -171,7 +171,7 @@ impl TransactionBuilder {
gas_payment,
gas_budget,
gas_price,
gas_sponsor.unwrap_or(sender),
gas_sponsor.into().unwrap_or(sender),
))
}

Expand All @@ -190,7 +190,7 @@ impl TransactionBuilder {
&self,
signer: IotaAddress,
object_id: ObjectID,
gas: Option<ObjectID>,
gas: impl Into<Option<ObjectID>>,
gas_budget: u64,
recipient: IotaAddress,
) -> anyhow::Result<TransactionData> {
Expand Down Expand Up @@ -224,10 +224,10 @@ impl TransactionBuilder {
pub fn transfer_iota_tx_kind(
&self,
recipient: IotaAddress,
amount: Option<u64>,
amount: impl Into<Option<u64>>,
) -> TransactionKind {
let mut builder = ProgrammableTransactionBuilder::new();
builder.transfer_iota(recipient, amount);
builder.transfer_iota(recipient, amount.into());
let pt = builder.finish();
TransactionKind::programmable(pt)
}
Expand All @@ -238,12 +238,17 @@ impl TransactionBuilder {
iota_object_id: ObjectID,
gas_budget: u64,
recipient: IotaAddress,
amount: Option<u64>,
amount: impl Into<Option<u64>>,
) -> anyhow::Result<TransactionData> {
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,
))
}

Expand All @@ -265,9 +270,11 @@ impl TransactionBuilder {
input_coins: Vec<ObjectID>,
recipients: Vec<IotaAddress>,
amounts: Vec<u64>,
gas: Option<ObjectID>,
gas: impl Into<Option<ObjectID>>,
gas_budget: u64,
) -> anyhow::Result<TransactionData> {
let gas = gas.into();

if let Some(gas) = gas {
if input_coins.contains(&gas) {
return Err(anyhow!(
Expand Down Expand Up @@ -406,10 +413,12 @@ impl TransactionBuilder {
function: &str,
type_args: Vec<IotaTypeTag>,
call_args: Vec<IotaJsonValue>,
gas: Option<ObjectID>,
gas: impl Into<Option<ObjectID>>,
gas_budget: u64,
gas_price: Option<u64>,
gas_price: impl Into<Option<u64>>,
) -> anyhow::Result<TransactionData> {
let gas_price = gas_price.into();

let mut builder = ProgrammableTransactionBuilder::new();
self.single_move_call(
&mut builder,
Expand Down Expand Up @@ -610,7 +619,7 @@ impl TransactionBuilder {
sender: IotaAddress,
compiled_modules: Vec<Vec<u8>>,
dep_ids: Vec<ObjectID>,
gas: Option<ObjectID>,
gas: impl Into<Option<ObjectID>>,
gas_budget: u64,
) -> anyhow::Result<TransactionData> {
let gas_price = self.0.get_reference_gas_price().await?;
Expand Down Expand Up @@ -704,7 +713,7 @@ impl TransactionBuilder {
upgrade_capability: ObjectID,
upgrade_policy: u8,
digest: Vec<u8>,
gas: Option<ObjectID>,
gas: impl Into<Option<ObjectID>>,
gas_budget: u64,
) -> anyhow::Result<TransactionData> {
let gas_price = self.0.get_reference_gas_price().await?;
Expand Down Expand Up @@ -742,9 +751,12 @@ impl TransactionBuilder {
pub async fn split_coin_tx_kind(
&self,
coin_object_id: ObjectID,
split_amounts: Option<Vec<u64>>,
split_count: Option<u64>,
split_amounts: impl Into<Option<Vec<u64>>>,
split_count: impl Into<Option<u64>>,
) -> Result<TransactionKind, anyhow::Error> {
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."
Expand Down Expand Up @@ -791,7 +803,7 @@ impl TransactionBuilder {
signer: IotaAddress,
coin_object_id: ObjectID,
split_amounts: Vec<u64>,
gas: Option<ObjectID>,
gas: impl Into<Option<ObjectID>>,
gas_budget: u64,
) -> anyhow::Result<TransactionData> {
let coin = self
Expand Down Expand Up @@ -829,7 +841,7 @@ impl TransactionBuilder {
signer: IotaAddress,
coin_object_id: ObjectID,
split_count: u64,
gas: Option<ObjectID>,
gas: impl Into<Option<ObjectID>>,
gas_budget: u64,
) -> anyhow::Result<TransactionData> {
let coin = self
Expand Down Expand Up @@ -897,7 +909,7 @@ impl TransactionBuilder {
signer: IotaAddress,
primary_coin: ObjectID,
coin_to_merge: ObjectID,
gas: Option<ObjectID>,
gas: impl Into<Option<ObjectID>>,
gas_budget: u64,
) -> anyhow::Result<TransactionData> {
let coin = self
Expand Down Expand Up @@ -940,7 +952,7 @@ impl TransactionBuilder {
&self,
signer: IotaAddress,
single_transaction_params: Vec<RPCTransactionRequestParams>,
gas: Option<ObjectID>,
gas: impl Into<Option<ObjectID>>,
gas_budget: u64,
) -> anyhow::Result<TransactionData> {
fp_ensure!(
Expand Down Expand Up @@ -997,9 +1009,9 @@ impl TransactionBuilder {
&self,
signer: IotaAddress,
mut coins: Vec<ObjectID>,
amount: Option<u64>,
amount: impl Into<Option<u64>>,
validator: IotaAddress,
gas: Option<ObjectID>,
gas: impl Into<Option<ObjectID>>,
gas_budget: u64,
) -> anyhow::Result<TransactionData> {
let gas_price = self.0.get_reference_gas_price().await?;
Expand Down Expand Up @@ -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)?))
Expand Down Expand Up @@ -1065,7 +1077,7 @@ impl TransactionBuilder {
&self,
signer: IotaAddress,
staked_iota: ObjectID,
gas: Option<ObjectID>,
gas: impl Into<Option<ObjectID>>,
gas_budget: u64,
) -> anyhow::Result<TransactionData> {
let staked_iota = self.get_object_ref(staked_iota).await?;
Expand Down
Loading