@@ -9,6 +9,8 @@ use simplicityhl::elements::{
99} ;
1010
1111use crate :: provider:: SimplicityNetwork ;
12+ use crate :: transaction:: partial_input:: { IssuanceSig , ProgramSig } ;
13+ use crate :: transaction:: { ProgramIssuanceSig , RegularSig } ;
1214use crate :: utils;
1315
1416use super :: partial_input:: { IssuanceInput , PartialInput , ProgramInput , RequiredSignature } ;
@@ -157,79 +159,51 @@ impl FinalTransaction {
157159 }
158160
159161 /// Adds a new input to the transaction.
160- ///
161- /// # Panics
162- /// Panics if the requested signature is not `NativeEcdsa` or `None`.
163- /// (i.e. if `required_sig` is `RequiredSignature::Witness` or `RequiredSignature::WitnessWithPath`)
164- pub fn add_input ( & mut self , partial_input : PartialInput , required_sig : RequiredSignature ) {
165- match required_sig {
166- RequiredSignature :: Witness ( _) | RequiredSignature :: WitnessWithPath ( _, _) => {
167- panic ! ( "Requested signature is not NativeEcdsa or None" )
168- }
169- _ => { }
170- }
171-
172- self . push_new_input ( FinalInput :: new ( partial_input, required_sig) ) ;
162+ pub fn add_input < S : RegularSig > ( & mut self , partial_input : PartialInput , required_sig : S ) {
163+ self . push_new_input ( FinalInput :: new ( partial_input, required_sig. into_required_sig ( ) ) ) ;
173164 }
174165
175166 /// Adds a new program input to the transaction.
176- ///
177- /// # Panics
178- /// The function will panic if the `required_sig` parameter is of type `RequiredSignature::NativeEcdsa`,
179- /// as this type of signature is not applicable for program inputs.
180- pub fn add_program_input (
167+ pub fn add_program_input < S : ProgramSig > (
181168 & mut self ,
182169 partial_input : PartialInput ,
183170 program_input : ProgramInput ,
184- required_sig : RequiredSignature ,
171+ required_sig : S ,
185172 ) {
186- if let RequiredSignature :: NativeEcdsa = required_sig {
187- panic ! ( "Requested signature is not Witness or None" ) ;
188- }
189-
190- self . push_new_input ( FinalInput :: new ( partial_input, required_sig) . with_program ( program_input) ) ;
173+ self . push_new_input (
174+ FinalInput :: new ( partial_input, required_sig. into_required_sig ( ) ) . with_program ( program_input) ,
175+ ) ;
191176 }
192177
193178 /// Adds an issuance (or reissuance) input to the transaction.
194179 ///
195180 /// # Panics
196- /// This function panics if the `required_sig` is of type `Witness` or
197- /// `WitnessWithPath`, as these signature types are not allowed in the current context.
198- pub fn add_issuance_input (
181+ /// Panics if the populated input fails to return valid issuance details.
182+ pub fn add_issuance_input < S : IssuanceSig > (
199183 & mut self ,
200184 partial_input : PartialInput ,
201185 issuance_input : IssuanceInput ,
202- required_sig : RequiredSignature ,
186+ required_sig : S ,
203187 ) -> IssuanceDetails {
204- match required_sig {
205- RequiredSignature :: Witness ( _) | RequiredSignature :: WitnessWithPath ( _, _) => {
206- panic ! ( "Requested signature is not NativeEcdsa or None" )
207- }
208- _ => { }
209- }
210-
211- self . push_new_input ( FinalInput :: new ( partial_input, required_sig) . with_issuance ( issuance_input) )
212- . unwrap ( )
188+ self . push_new_input (
189+ FinalInput :: new ( partial_input, required_sig. into_required_sig ( ) ) . with_issuance ( issuance_input) ,
190+ )
191+ . unwrap ( )
213192 }
214193
215194 /// Adds an issuance program input to the transaction with the specified parameters.
216195 ///
217196 /// # Panics
218- /// Panics if the `required_sig` parameter is of type `RequiredSignature::NativeEcdsa`.
219- /// Also panics if the populated input fails to return valid issuance details.
220- pub fn add_program_issuance_input (
197+ /// Panics if the populated input fails to return valid issuance details.
198+ pub fn add_program_issuance_input < S : ProgramIssuanceSig > (
221199 & mut self ,
222200 partial_input : PartialInput ,
223201 program_input : ProgramInput ,
224202 issuance_input : IssuanceInput ,
225- required_sig : RequiredSignature ,
203+ required_sig : S ,
226204 ) -> IssuanceDetails {
227- if let RequiredSignature :: NativeEcdsa = required_sig {
228- panic ! ( "Requested signature is not Witness or None" ) ;
229- }
230-
231205 self . push_new_input (
232- FinalInput :: new ( partial_input, required_sig)
206+ FinalInput :: new ( partial_input, required_sig. into_required_sig ( ) )
233207 . with_program ( program_input)
234208 . with_issuance ( issuance_input) ,
235209 )
@@ -417,7 +391,7 @@ mod tests {
417391
418392 use simplicityhl:: elements:: { OutPoint , Script , TxOut , Txid } ;
419393
420- use crate :: transaction:: UTXO ;
394+ use crate :: transaction:: { NoneSig , UTXO } ;
421395
422396 use super :: * ;
423397
@@ -460,7 +434,7 @@ mod tests {
460434 let partial_output = PartialOutput :: new ( Script :: new ( ) , 4000 , policy) ;
461435
462436 let mut ft = FinalTransaction :: new ( ) ;
463- ft. add_input ( partial_input. clone ( ) , RequiredSignature :: None ) ;
437+ ft. add_input ( partial_input. clone ( ) , NoneSig ) ;
464438 ft. add_output ( partial_output. clone ( ) ) ;
465439
466440 let mut expected_pst = PartiallySignedTransaction :: new_v2 ( ) ;
@@ -487,7 +461,7 @@ mod tests {
487461 let partial_output = PartialOutput :: new ( Script :: new ( ) , 2000 , policy) ;
488462
489463 let mut ft = FinalTransaction :: new ( ) ;
490- ft. add_input ( partial_input. clone ( ) , RequiredSignature :: None ) ;
464+ ft. add_input ( partial_input. clone ( ) , NoneSig ) ;
491465 ft. add_output ( partial_output. clone ( ) ) ;
492466
493467 let mut expected_pst = PartiallySignedTransaction :: new_v2 ( ) ;
@@ -520,8 +494,8 @@ mod tests {
520494 let output_b = PartialOutput :: new ( Script :: new ( ) , 800 , other) ;
521495
522496 let mut ft = FinalTransaction :: new ( ) ;
523- ft. add_input ( explicit_partial. clone ( ) , RequiredSignature :: None ) ;
524- ft. add_input ( conf_partial. clone ( ) , RequiredSignature :: None ) ;
497+ ft. add_input ( explicit_partial. clone ( ) , NoneSig ) ;
498+ ft. add_input ( conf_partial. clone ( ) , NoneSig ) ;
525499 ft. add_output ( output_a. clone ( ) ) ;
526500 ft. add_output ( output_b. clone ( ) ) ;
527501
@@ -560,7 +534,7 @@ mod tests {
560534 let partial_output = PartialOutput :: new ( Script :: new ( ) , 4000 , policy) ;
561535
562536 let mut ft = FinalTransaction :: new ( ) ;
563- ft. add_issuance_input ( partial_input. clone ( ) , issuance. clone ( ) , RequiredSignature :: None ) ;
537+ ft. add_issuance_input ( partial_input. clone ( ) , issuance. clone ( ) , NoneSig ) ;
564538 ft. add_output ( partial_output. clone ( ) ) ;
565539
566540 // build expected pst, merge partial_input and issuance manually
@@ -598,7 +572,7 @@ mod tests {
598572 let partial_output = PartialOutput :: new ( Script :: new ( ) , 1000 , policy) ;
599573
600574 let mut ft = FinalTransaction :: new ( ) ;
601- ft. add_issuance_input ( partial_input. clone ( ) , reissuance_input. clone ( ) , RequiredSignature :: None ) ;
575+ ft. add_issuance_input ( partial_input. clone ( ) , reissuance_input. clone ( ) , NoneSig ) ;
602576 ft. add_output ( partial_output. clone ( ) ) ;
603577
604578 // build expected pst, merge partial_input and issuance manually
0 commit comments