@@ -3,7 +3,7 @@ use std::collections::HashMap;
33use super :: { handler:: HandlerContexts , input:: TransactionInput } ;
44use crate :: {
55 core:: TransactionBuilder ,
6- traits:: CellCollectorError ,
6+ traits:: { CellCollectorError , LiveCell } ,
77 transaction:: TransactionBuilderConfiguration ,
88 tx_builder:: { BalanceTxCapacityError , TxBuilderError } ,
99 ScriptGroup , TransactionWithScriptGroups ,
@@ -143,6 +143,7 @@ fn inner_build<
143143 input_iter : I ,
144144 configuration : & TransactionBuilderConfiguration ,
145145 contexts : & HandlerContexts ,
146+ rc_cells : Vec < LiveCell > ,
146147) -> Result < TransactionWithScriptGroups , TxBuilderError > {
147148 let mut lock_groups: HashMap < Byte32 , ScriptGroup > = HashMap :: default ( ) ;
148149 let mut type_groups: HashMap < Byte32 , ScriptGroup > = HashMap :: default ( ) ;
@@ -159,10 +160,43 @@ fn inner_build<
159160 }
160161 }
161162
163+ let rc_len = rc_cells. len ( ) ;
164+
165+ for ( input_index, input) in rc_cells. into_iter ( ) . enumerate ( ) {
166+ let input = TransactionInput :: new ( input, 0 ) ;
167+ tx. input ( input. cell_input ( ) ) ;
168+ tx. witness ( packed:: Bytes :: default ( ) ) ;
169+
170+ inputs. insert (
171+ input. live_cell . out_point . clone ( ) ,
172+ (
173+ input. live_cell . output . clone ( ) ,
174+ input. live_cell . output_data . clone ( ) ,
175+ ) ,
176+ ) ;
177+
178+ let previous_output = input. previous_output ( ) ;
179+ let lock_script = previous_output. lock ( ) ;
180+ lock_groups
181+ . entry ( lock_script. calc_script_hash ( ) )
182+ . or_insert_with ( || ScriptGroup :: from_lock_script ( & lock_script) )
183+ . input_indices
184+ . push ( input_index) ;
185+
186+ if let Some ( type_script) = previous_output. type_ ( ) . to_opt ( ) {
187+ type_groups
188+ . entry ( type_script. calc_script_hash ( ) )
189+ . or_insert_with ( || ScriptGroup :: from_type_script ( & type_script) )
190+ . input_indices
191+ . push ( input_index) ;
192+ }
193+ }
194+
162195 // setup change output and data
163196 change_builder. init ( & mut tx) ;
164197 // collect inputs
165- for ( input_index, input) in input_iter. enumerate ( ) {
198+ for ( mut input_index, input) in input_iter. enumerate ( ) {
199+ input_index += rc_len;
166200 let input = input?;
167201 tx. input ( input. cell_input ( ) ) ;
168202 tx. witness ( packed:: Bytes :: default ( ) ) ;
0 commit comments