@@ -32,8 +32,9 @@ use common::{
3232 Signable , Transactable ,
3333 } ,
3434 tokens:: TokenId ,
35- ChainConfig , Destination , OrderId , PoolId , SighashInputCommitmentVersion ,
36- SignedTransaction , Transaction , TransactionCreationError , TxInput , TxOutput ,
35+ AccountCommand , ChainConfig , Destination , OrderAccountCommand , OrderId , PoolId ,
36+ SighashInputCommitmentVersion , SignedTransaction , Transaction , TransactionCreationError ,
37+ TxInput , TxOutput ,
3738 } ,
3839 primitives:: { Amount , BlockHeight } ,
3940} ;
@@ -160,6 +161,14 @@ impl TxAdditionalInfo {
160161 self . order_info . get ( order_id)
161162 }
162163
164+ pub fn token_info_iter ( & self ) -> impl Iterator < Item = ( & ' _ TokenId , & ' _ TokenAdditionalInfo ) > {
165+ self . token_info . iter ( )
166+ }
167+
168+ pub fn pool_info_iter ( & self ) -> impl Iterator < Item = ( & ' _ PoolId , & ' _ PoolAdditionalInfo ) > {
169+ self . pool_info . iter ( )
170+ }
171+
163172 pub fn order_info_iter ( & self ) -> impl Iterator < Item = ( & ' _ OrderId , & ' _ OrderAdditionalInfo ) > {
164173 self . order_info . iter ( )
165174 }
@@ -211,31 +220,51 @@ pub struct PartiallySignedTransaction {
211220}
212221
213222impl PartiallySignedTransaction {
214- pub fn new (
223+ pub fn new_unchecked (
215224 tx : Transaction ,
216225 witnesses : Vec < Option < InputWitness > > ,
217226 input_utxos : Vec < Option < TxOutput > > ,
218227 destinations : Vec < Option < Destination > > ,
219228 htlc_secrets : Option < Vec < Option < HtlcSecret > > > ,
220229 additional_info : TxAdditionalInfo ,
221- ) -> Result < Self , PartiallySignedTransactionError > {
230+ ) -> Self {
222231 let htlc_secrets = htlc_secrets. unwrap_or_else ( || vec ! [ None ; tx. inputs( ) . len( ) ] ) ;
223232
224- let this = Self {
233+ Self {
225234 tx,
226235 witnesses,
227236 input_utxos,
228237 destinations,
229238 htlc_secrets,
230239 additional_info,
231- } ;
240+ }
241+ }
232242
233- this. ensure_consistency ( ) ?;
243+ pub fn new (
244+ tx : Transaction ,
245+ witnesses : Vec < Option < InputWitness > > ,
246+ input_utxos : Vec < Option < TxOutput > > ,
247+ destinations : Vec < Option < Destination > > ,
248+ htlc_secrets : Option < Vec < Option < HtlcSecret > > > ,
249+ additional_info : TxAdditionalInfo ,
250+ ) -> Result < Self , PartiallySignedTransactionError > {
251+ let this = Self :: new_unchecked (
252+ tx,
253+ witnesses,
254+ input_utxos,
255+ destinations,
256+ htlc_secrets,
257+ additional_info,
258+ ) ;
234259
260+ this. ensure_consistency ( Self :: need_heavy_consistency_checks ( ) ) ?;
235261 Ok ( this)
236262 }
237263
238- pub fn ensure_consistency ( & self ) -> Result < ( ) , PartiallySignedTransactionError > {
264+ pub fn ensure_consistency (
265+ & self ,
266+ with_heavy_checks : bool ,
267+ ) -> Result < ( ) , PartiallySignedTransactionError > {
239268 ensure ! (
240269 self . tx. inputs( ) . len( ) == self . witnesses. len( ) ,
241270 PartiallySignedTransactionError :: InvalidWitnessCount
@@ -256,18 +285,18 @@ impl PartiallySignedTransaction {
256285 PartiallySignedTransactionError :: InvalidHtlcSecretsCount
257286 ) ;
258287
259- #[ cfg( debug_assertions) ]
260- {
288+ if with_heavy_checks {
261289 self . ensure_additional_info_completeness ( ) ?;
262290 }
263291
264292 Ok ( ( ) )
265293 }
266294
267- # [ cfg ( debug_assertions ) ]
268- fn ensure_additional_info_completeness ( & self ) -> Result < ( ) , PartiallySignedTransactionError > {
269- use common :: chain :: { AccountCommand , OrderAccountCommand } ;
295+ fn need_heavy_consistency_checks ( ) -> bool {
296+ cfg ! ( debug_assertions )
297+ }
270298
299+ fn ensure_additional_info_completeness ( & self ) -> Result < ( ) , PartiallySignedTransactionError > {
271300 let ensure_order_info_present =
272301 |order_id : & OrderId | -> Result < _ , PartiallySignedTransactionError > {
273302 ensure ! (
@@ -387,7 +416,7 @@ impl PartiallySignedTransaction {
387416 witnesses : Vec < Option < InputWitness > > ,
388417 ) -> Result < Self , PartiallySignedTransactionError > {
389418 self . witnesses = witnesses;
390- self . ensure_consistency ( ) ?;
419+ self . ensure_consistency ( Self :: need_heavy_consistency_checks ( ) ) ?;
391420 Ok ( self )
392421 }
393422
0 commit comments