@@ -32,7 +32,7 @@ pub mod signtx;
32
32
use super :: pb;
33
33
use super :: Error ;
34
34
35
- use crate :: workflow:: confirm;
35
+ use crate :: workflow:: { confirm, Workflows } ;
36
36
37
37
use util:: bip32:: HARDENED ;
38
38
@@ -189,7 +189,8 @@ async fn address_simple(
189
189
}
190
190
191
191
/// Processes a multisig address api call.
192
- pub async fn address_multisig (
192
+ pub async fn address_multisig < W : Workflows > (
193
+ workflows : & mut W ,
193
194
coin : BtcCoin ,
194
195
multisig : & Multisig ,
195
196
keypath : & [ u32 ] ,
@@ -206,7 +207,7 @@ pub async fn address_multisig(
206
207
} ;
207
208
let title = "Receive to" ;
208
209
if display {
209
- multisig:: confirm ( title, coin_params, & name, multisig) . await ?;
210
+ multisig:: confirm ( workflows , title, coin_params, & name, multisig) . await ?;
210
211
}
211
212
let address = common:: Payload :: from_multisig (
212
213
coin_params,
@@ -216,19 +217,21 @@ pub async fn address_multisig(
216
217
) ?
217
218
. address ( coin_params) ?;
218
219
if display {
219
- confirm:: confirm ( & confirm:: Params {
220
- title,
221
- body : & address,
222
- scrollable : true ,
223
- ..Default :: default ( )
224
- } )
225
- . await ?;
220
+ workflows
221
+ . confirm ( & confirm:: Params {
222
+ title,
223
+ body : & address,
224
+ scrollable : true ,
225
+ ..Default :: default ( )
226
+ } )
227
+ . await ?;
226
228
}
227
229
Ok ( Response :: Pub ( pb:: PubResponse { r#pub : address } ) )
228
230
}
229
231
230
232
/// Processes a policy address api call.
231
- async fn address_policy (
233
+ async fn address_policy < W : Workflows > (
234
+ workflows : & mut W ,
232
235
coin : BtcCoin ,
233
236
policy : & Policy ,
234
237
keypath : & [ u32 ] ,
@@ -247,26 +250,30 @@ async fn address_policy(
247
250
248
251
if display {
249
252
parsed
250
- . confirm ( title, coin_params, & name, policies:: Mode :: Basic )
253
+ . confirm ( workflows , title, coin_params, & name, policies:: Mode :: Basic )
251
254
. await ?;
252
255
}
253
256
254
257
let address =
255
258
common:: Payload :: from_policy ( coin_params, & parsed, keypath) ?. address ( coin_params) ?;
256
259
if display {
257
- confirm:: confirm ( & confirm:: Params {
258
- title,
259
- body : & address,
260
- scrollable : true ,
261
- ..Default :: default ( )
262
- } )
263
- . await ?;
260
+ workflows
261
+ . confirm ( & confirm:: Params {
262
+ title,
263
+ body : & address,
264
+ scrollable : true ,
265
+ ..Default :: default ( )
266
+ } )
267
+ . await ?;
264
268
}
265
269
Ok ( Response :: Pub ( pb:: PubResponse { r#pub : address } ) )
266
270
}
267
271
268
272
/// Handle a Bitcoin xpub/address protobuf api call.
269
- pub async fn process_pub ( request : & pb:: BtcPubRequest ) -> Result < Response , Error > {
273
+ pub async fn process_pub < W : Workflows > (
274
+ workflows : & mut W ,
275
+ request : & pb:: BtcPubRequest ,
276
+ ) -> Result < Response , Error > {
270
277
let coin = BtcCoin :: try_from ( request. coin ) ?;
271
278
coin_enabled ( coin) ?;
272
279
match request. output {
@@ -283,24 +290,27 @@ pub async fn process_pub(request: &pb::BtcPubRequest) -> Result<Response, Error>
283
290
}
284
291
Some ( Output :: ScriptConfig ( BtcScriptConfig {
285
292
config : Some ( Config :: Multisig ( ref multisig) ) ,
286
- } ) ) => address_multisig ( coin, multisig, & request. keypath , request. display ) . await ,
293
+ } ) ) => address_multisig ( workflows , coin, multisig, & request. keypath , request. display ) . await ,
287
294
Some ( Output :: ScriptConfig ( BtcScriptConfig {
288
295
config : Some ( Config :: Policy ( ref policy) ) ,
289
- } ) ) => address_policy ( coin, policy, & request. keypath , request. display ) . await ,
296
+ } ) ) => address_policy ( workflows , coin, policy, & request. keypath , request. display ) . await ,
290
297
_ => Err ( Error :: InvalidInput ) ,
291
298
}
292
299
}
293
300
294
301
/// Handle a nexted Bitcoin protobuf api call.
295
- pub async fn process_api ( request : & Request ) -> Result < pb:: btc_response:: Response , Error > {
302
+ pub async fn process_api < W : Workflows > (
303
+ workflows : & mut W ,
304
+ request : & Request ,
305
+ ) -> Result < pb:: btc_response:: Response , Error > {
296
306
match request {
297
307
Request :: IsScriptConfigRegistered ( ref request) => {
298
308
registration:: process_is_script_config_registered ( request)
299
309
}
300
310
Request :: RegisterScriptConfig ( ref request) => {
301
- registration:: process_register_script_config ( request) . await
311
+ registration:: process_register_script_config ( workflows , request) . await
302
312
}
303
- Request :: SignMessage ( ref request) => signmsg:: process ( request) . await ,
313
+ Request :: SignMessage ( ref request) => signmsg:: process ( workflows , request) . await ,
304
314
// These are streamed asynchronously using the `next_request()` primitive in
305
315
// bitcoin/signtx.rs and are not handled directly.
306
316
Request :: PrevtxInit ( _)
@@ -317,6 +327,7 @@ mod tests {
317
327
318
328
use crate :: bb02_async:: block_on;
319
329
use crate :: bip32:: parse_xpub;
330
+ use crate :: workflow:: RealWorkflows ; // instead of TestingWorkflows until the tests are migrated
320
331
use alloc:: boxed:: Box ;
321
332
use alloc:: vec:: Vec ;
322
333
use bitbox02:: testing:: {
@@ -471,7 +482,7 @@ mod tests {
471
482
} ;
472
483
473
484
assert_eq ! (
474
- block_on( process_pub( & req) ) ,
485
+ block_on( process_pub( & mut RealWorkflows , & req) ) ,
475
486
Ok ( Response :: Pub ( pb:: PubResponse {
476
487
r#pub: test. expected_xpub. into( ) ,
477
488
} ) ) ,
@@ -492,7 +503,7 @@ mod tests {
492
503
} ) ;
493
504
mock_unlocked_using_mnemonic ( test. mnemonic , "" ) ;
494
505
assert_eq ! (
495
- block_on( process_pub( & req) ) ,
506
+ block_on( process_pub( & mut RealWorkflows , & req) ) ,
496
507
Ok ( Response :: Pub ( pb:: PubResponse {
497
508
r#pub: test. expected_xpub. into( ) ,
498
509
} ) ) ,
@@ -513,7 +524,7 @@ mod tests {
513
524
} ) ;
514
525
mock_unlocked ( ) ;
515
526
assert_eq ! (
516
- block_on( process_pub( & pb:: BtcPubRequest {
527
+ block_on( process_pub( & mut RealWorkflows , & pb:: BtcPubRequest {
517
528
coin: BtcCoin :: Btc as _,
518
529
keypath: [ 1 + HARDENED , 2 + HARDENED , 3 + HARDENED , 4 ] . to_vec( ) ,
519
530
display: false ,
@@ -553,7 +564,7 @@ mod tests {
553
564
} ) ;
554
565
mock_unlocked ( ) ;
555
566
assert_eq ! (
556
- block_on( process_pub( & pb:: BtcPubRequest {
567
+ block_on( process_pub( & mut RealWorkflows , & pb:: BtcPubRequest {
557
568
coin: BtcCoin :: Btc as _,
558
569
keypath: [ 1 + HARDENED , 2 + HARDENED , 3 + HARDENED , 4 ] . to_vec( ) ,
559
570
display: true ,
@@ -575,11 +586,11 @@ mod tests {
575
586
// -- Wrong coin: MIN-1
576
587
let mut req_invalid = req. clone ( ) ;
577
588
req_invalid. coin = BtcCoin :: Btc as i32 - 1 ;
578
- assert ! ( block_on( process_pub( & req_invalid) ) . is_err( ) ) ;
589
+ assert ! ( block_on( process_pub( & mut RealWorkflows , & req_invalid) ) . is_err( ) ) ;
579
590
// -- Wrong coin: MAX + 1
580
591
let mut req_invalid = req. clone ( ) ;
581
592
req_invalid. coin = BtcCoin :: Rbtc as i32 + 1 ;
582
- assert ! ( block_on( process_pub( & req_invalid) ) . is_err( ) ) ;
593
+ assert ! ( block_on( process_pub( & mut RealWorkflows , & req_invalid) ) . is_err( ) ) ;
583
594
}
584
595
585
596
#[ test]
@@ -778,7 +789,7 @@ mod tests {
778
789
// Without display.
779
790
mock_unlocked_using_mnemonic ( test. mnemonic , "" ) ;
780
791
assert_eq ! (
781
- block_on( process_pub( & req) ) ,
792
+ block_on( process_pub( & mut RealWorkflows , & req) ) ,
782
793
Ok ( Response :: Pub ( pb:: PubResponse {
783
794
r#pub: test. expected_address. into( ) ,
784
795
} ) ) ,
@@ -799,7 +810,7 @@ mod tests {
799
810
} ) ;
800
811
mock_unlocked_using_mnemonic ( test. mnemonic , "" ) ;
801
812
assert_eq ! (
802
- block_on( process_pub( & req) ) ,
813
+ block_on( process_pub( & mut RealWorkflows , & req) ) ,
803
814
Ok ( Response :: Pub ( pb:: PubResponse {
804
815
r#pub: test. expected_address. into( )
805
816
} ) ) ,
@@ -817,28 +828,31 @@ mod tests {
817
828
config : Some ( Config :: SimpleType ( SimpleType :: P2wpkhP2sh as _ ) ) ,
818
829
} ) ) ,
819
830
} ;
820
- assert ! ( block_on( process_pub( & req) ) . is_ok( ) ) ;
831
+ assert ! ( block_on( process_pub( & mut RealWorkflows , & req) ) . is_ok( ) ) ;
821
832
// -- Wrong coin: MIN-1
822
833
let mut req_invalid = req. clone ( ) ;
823
834
req_invalid. coin = BtcCoin :: Btc as i32 - 1 ;
824
- assert ! ( block_on( process_pub( & req_invalid) ) . is_err( ) ) ;
835
+ assert ! ( block_on( process_pub( & mut RealWorkflows , & req_invalid) ) . is_err( ) ) ;
825
836
// -- Wrong coin: MAX + 1
826
837
let mut req_invalid = req. clone ( ) ;
827
838
req_invalid. coin = BtcCoin :: Tltc as i32 + 1 ;
828
- assert ! ( block_on( process_pub( & req_invalid) ) . is_err( ) ) ;
839
+ assert ! ( block_on( process_pub( & mut RealWorkflows , & req_invalid) ) . is_err( ) ) ;
829
840
// -- Wrong keypath
830
841
let mut req_invalid = req. clone ( ) ;
831
842
req_invalid. keypath = [ 49 + HARDENED , 0 + HARDENED , 1 + HARDENED , 1 , 10000 ] . to_vec ( ) ;
832
- assert ! ( block_on( process_pub( & req_invalid) ) . is_err( ) ) ;
843
+ assert ! ( block_on( process_pub( & mut RealWorkflows , & req_invalid) ) . is_err( ) ) ;
833
844
// -- No taproot in Litecoin
834
- assert ! ( block_on( process_pub( & pb:: BtcPubRequest {
835
- coin: BtcCoin :: Ltc as _,
836
- keypath: [ 86 + HARDENED , 0 + HARDENED , 0 + HARDENED , 0 , 0 ] . to_vec( ) ,
837
- display: false ,
838
- output: Some ( Output :: ScriptConfig ( BtcScriptConfig {
839
- config: Some ( Config :: SimpleType ( SimpleType :: P2tr as _) ) ,
840
- } ) ) ,
841
- } ) )
845
+ assert ! ( block_on( process_pub(
846
+ & mut RealWorkflows ,
847
+ & pb:: BtcPubRequest {
848
+ coin: BtcCoin :: Ltc as _,
849
+ keypath: [ 86 + HARDENED , 0 + HARDENED , 0 + HARDENED , 0 , 0 ] . to_vec( ) ,
850
+ display: false ,
851
+ output: Some ( Output :: ScriptConfig ( BtcScriptConfig {
852
+ config: Some ( Config :: SimpleType ( SimpleType :: P2tr as _) ) ,
853
+ } ) ) ,
854
+ }
855
+ ) )
842
856
. is_err( ) ) ;
843
857
}
844
858
@@ -1053,7 +1067,7 @@ mod tests {
1053
1067
} ) ) ,
1054
1068
} ;
1055
1069
assert_eq ! (
1056
- block_on( process_pub( & req) ) ,
1070
+ block_on( process_pub( & mut RealWorkflows , & req) ) ,
1057
1071
Ok ( Response :: Pub ( pb:: PubResponse {
1058
1072
r#pub: test. expected_address. into( ) ,
1059
1073
} ) ) ,
@@ -1202,7 +1216,7 @@ mod tests {
1202
1216
} ) ) ,
1203
1217
} ;
1204
1218
assert_eq ! (
1205
- block_on( process_pub( & req) ) ,
1219
+ block_on( process_pub( & mut RealWorkflows , & req) ) ,
1206
1220
Ok ( Response :: Pub ( pb:: PubResponse {
1207
1221
r#pub: test. expected_address. into( ) ,
1208
1222
} ) ) ,
0 commit comments