@@ -32,8 +32,9 @@ use common::{
32
32
Signable , Transactable ,
33
33
} ,
34
34
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 ,
37
38
} ,
38
39
primitives:: { Amount , BlockHeight } ,
39
40
} ;
@@ -160,6 +161,14 @@ impl TxAdditionalInfo {
160
161
self . order_info . get ( order_id)
161
162
}
162
163
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
+
163
172
pub fn order_info_iter ( & self ) -> impl Iterator < Item = ( & ' _ OrderId , & ' _ OrderAdditionalInfo ) > {
164
173
self . order_info . iter ( )
165
174
}
@@ -211,31 +220,51 @@ pub struct PartiallySignedTransaction {
211
220
}
212
221
213
222
impl PartiallySignedTransaction {
214
- pub fn new (
223
+ pub fn new_unchecked (
215
224
tx : Transaction ,
216
225
witnesses : Vec < Option < InputWitness > > ,
217
226
input_utxos : Vec < Option < TxOutput > > ,
218
227
destinations : Vec < Option < Destination > > ,
219
228
htlc_secrets : Option < Vec < Option < HtlcSecret > > > ,
220
229
additional_info : TxAdditionalInfo ,
221
- ) -> Result < Self , PartiallySignedTransactionError > {
230
+ ) -> Self {
222
231
let htlc_secrets = htlc_secrets. unwrap_or_else ( || vec ! [ None ; tx. inputs( ) . len( ) ] ) ;
223
232
224
- let this = Self {
233
+ Self {
225
234
tx,
226
235
witnesses,
227
236
input_utxos,
228
237
destinations,
229
238
htlc_secrets,
230
239
additional_info,
231
- } ;
240
+ }
241
+ }
232
242
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
+ ) ;
234
259
260
+ this. ensure_consistency ( Self :: need_heavy_consistency_checks ( ) ) ?;
235
261
Ok ( this)
236
262
}
237
263
238
- pub fn ensure_consistency ( & self ) -> Result < ( ) , PartiallySignedTransactionError > {
264
+ pub fn ensure_consistency (
265
+ & self ,
266
+ with_heavy_checks : bool ,
267
+ ) -> Result < ( ) , PartiallySignedTransactionError > {
239
268
ensure ! (
240
269
self . tx. inputs( ) . len( ) == self . witnesses. len( ) ,
241
270
PartiallySignedTransactionError :: InvalidWitnessCount
@@ -256,18 +285,18 @@ impl PartiallySignedTransaction {
256
285
PartiallySignedTransactionError :: InvalidHtlcSecretsCount
257
286
) ;
258
287
259
- #[ cfg( debug_assertions) ]
260
- {
288
+ if with_heavy_checks {
261
289
self . ensure_additional_info_completeness ( ) ?;
262
290
}
263
291
264
292
Ok ( ( ) )
265
293
}
266
294
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
+ }
270
298
299
+ fn ensure_additional_info_completeness ( & self ) -> Result < ( ) , PartiallySignedTransactionError > {
271
300
let ensure_order_info_present =
272
301
|order_id : & OrderId | -> Result < _ , PartiallySignedTransactionError > {
273
302
ensure ! (
@@ -387,7 +416,7 @@ impl PartiallySignedTransaction {
387
416
witnesses : Vec < Option < InputWitness > > ,
388
417
) -> Result < Self , PartiallySignedTransactionError > {
389
418
self . witnesses = witnesses;
390
- self . ensure_consistency ( ) ?;
419
+ self . ensure_consistency ( Self :: need_heavy_consistency_checks ( ) ) ?;
391
420
Ok ( self )
392
421
}
393
422
0 commit comments