44//! Builder for Programmable Transactions.
55
66use 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