Skip to content

Commit 72fc959

Browse files
committed
wip
1 parent 9ba6283 commit 72fc959

File tree

3 files changed

+30
-10
lines changed
  • bindings/go/examples/prepare_split_coins
  • crates
    • iota-sdk-types/src/effects
    • iota-transaction-builder/src/builder

3 files changed

+30
-10
lines changed

bindings/go/examples/prepare_split_coins/main.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ func main() {
2222
sender,
2323
[]*sdk.PtbArgument{sdk.PtbArgumentRes("coin1"), sdk.PtbArgumentRes("coin2"), sdk.PtbArgumentRes("coin3")},
2424
)
25-
builder.Gas(coinObjId).GasBudget(1000000000)
2625

2726
txn, err := builder.Finish()
2827
if err.(*sdk.SdkFfiError) != nil {
@@ -36,14 +35,13 @@ func main() {
3635
log.Printf("Signing Digest: %v", sdk.HexEncode(txn.SigningDigest()))
3736
log.Printf("Txn Bytes: %v", sdk.Base64Encode(txnBytes))
3837

39-
res, err := builder.DryRun(false)
38+
skipChecks := bool(false)
39+
res, err := client.DryRunTx(txn, &skipChecks)
4040
if err.(*sdk.SdkFfiError) != nil {
41-
log.Fatalf("Failed to split coins: %v", err)
41+
log.Fatalf("Failed to dry run split coins: %v", err)
4242
}
43-
4443
if res.Error != nil {
4544
log.Fatalf("Failed to split coins: %v", *res.Error)
4645
}
47-
4846
log.Print("Split coins dry run was successful!")
4947
}

crates/iota-sdk-types/src/effects/v1.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ pub struct ChangedObject {
118118
/// Optional object type information. This is not part of the BCS protocol
119119
/// data but can be populated from other sources when available.
120120
#[cfg_attr(feature = "serde", serde(skip))]
121+
#[cfg_attr(feature = "proptest", strategy(proptest::strategy::Just(None)))]
122+
#[cfg_attr(feature = "schemars", schemars(skip))]
121123
pub object_type: Option<String>,
122124
}
123125

crates/iota-transaction-builder/src/builder/mod.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! Builder for Programmable Transactions.
55
66
use std::{
7-
collections::{BTreeMap, HashMap},
7+
collections::{BTreeMap, HashMap, HashSet},
88
marker::PhantomData,
99
time::Duration,
1010
};
@@ -730,7 +730,25 @@ impl<L> TransactionBuilder<Client, L> {
730730
let mut inputs = Vec::new();
731731
let mut gas = Vec::new();
732732
let mut input_map = HashMap::new();
733+
733734
if default_gas && !self.data.inputs.values().any(|i| i.is_gas) {
735+
let mut unusable_object_ids = HashSet::new();
736+
for cmd in &self.data.commands {
737+
for arg in match cmd {
738+
Command::MoveCall(MoveCall { arguments, .. }) => arguments.as_slice(),
739+
Command::TransferObjects(TransferObjects { objects, .. }) => objects.as_slice(),
740+
Command::MergeCoins(MergeCoins { coins_to_merge, .. }) => {
741+
coins_to_merge.as_slice()
742+
}
743+
_ => &[],
744+
} {
745+
if let Argument::Input(idx) = arg {
746+
if let Some(obj_id) = self.data.inputs[idx].object_id() {
747+
unusable_object_ids.insert(*obj_id);
748+
}
749+
}
750+
}
751+
}
734752
for coin in self
735753
.client
736754
.objects(
@@ -745,10 +763,12 @@ impl<L> TransactionBuilder<Client, L> {
745763
.map_err(Error::Client)?
746764
.data
747765
{
748-
self.set_input(
749-
InputKind::Input(iota_types::Input::ImmutableOrOwned(coin.object_ref())),
750-
true,
751-
);
766+
if !unusable_object_ids.contains(&coin.object_id()) {
767+
self.set_input(
768+
InputKind::Input(iota_types::Input::ImmutableOrOwned(coin.object_ref())),
769+
true,
770+
);
771+
}
752772
}
753773
}
754774
for (id, input) in std::mem::take(&mut self.data.inputs) {

0 commit comments

Comments
 (0)