|
3 | 3 | //! This module provides PSBT deserialization that works across different |
4 | 4 | //! bitcoin-like networks, including those with non-standard transaction formats. |
5 | 5 |
|
| 6 | +mod p2tr_musig2_input; |
| 7 | +mod propkv; |
6 | 8 | mod sighash; |
7 | 9 | mod zcash_psbt; |
8 | 10 |
|
| 11 | +pub use p2tr_musig2_input::{ |
| 12 | + parse_musig2_nonces, parse_musig2_partial_sigs, parse_musig2_participants, Musig2Error, |
| 13 | + Musig2Input, Musig2PartialSig, Musig2Participants, Musig2PubNonce, |
| 14 | +}; |
9 | 15 | pub use sighash::validate_sighash_type; |
10 | 16 |
|
11 | 17 | use crate::{bitgo_psbt::zcash_psbt::ZcashPsbt, networks::Network}; |
@@ -184,9 +190,8 @@ mod tests { |
184 | 190 | } |
185 | 191 | } |
186 | 192 |
|
187 | | - crate::test_psbt_fixtures!(test_parse_network_mainnet_only, network, { |
188 | | - test_parse_with_format(fixtures::TxFormat::Psbt, network); |
189 | | - test_parse_with_format(fixtures::TxFormat::PsbtLite, network); |
| 193 | + crate::test_psbt_fixtures!(test_parse_network_mainnet_only, network, format, { |
| 194 | + test_parse_with_format(format, network); |
190 | 195 | }); |
191 | 196 |
|
192 | 197 | #[test] |
@@ -242,9 +247,8 @@ mod tests { |
242 | 247 | } |
243 | 248 | } |
244 | 249 |
|
245 | | - crate::test_psbt_fixtures!(test_round_trip_mainnet_only, network, { |
246 | | - test_round_trip_with_format(fixtures::TxFormat::Psbt, network); |
247 | | - test_round_trip_with_format(fixtures::TxFormat::PsbtLite, network); |
| 250 | + crate::test_psbt_fixtures!(test_round_trip_mainnet_only, network, format, { |
| 251 | + test_round_trip_with_format(format, network); |
248 | 252 | }); |
249 | 253 |
|
250 | 254 | fn parse_derivation_path(path: &str) -> Result<(u32, u32), String> { |
@@ -281,26 +285,6 @@ mod tests { |
281 | 285 | Ok((chain, index)) |
282 | 286 | } |
283 | 287 |
|
284 | | - fn find_input_with_script_type( |
285 | | - fixture: &fixtures::PsbtFixture, |
286 | | - script_type: fixtures::ScriptType, |
287 | | - ) -> Result<(usize, &fixtures::PsbtInputFixture), String> { |
288 | | - let result = fixture |
289 | | - .psbt_inputs |
290 | | - .iter() |
291 | | - .enumerate() |
292 | | - .filter(|(_, input)| script_type.matches_fixture(input)) |
293 | | - .collect::<Vec<_>>(); |
294 | | - if result.len() != 1 { |
295 | | - return Err(format!( |
296 | | - "Expected 1 input with script type {}, got {}", |
297 | | - script_type.as_str(), |
298 | | - result.len() |
299 | | - )); |
300 | | - } |
301 | | - Ok(result[0]) |
302 | | - } |
303 | | - |
304 | 288 | fn get_output_script_from_non_witness_utxo( |
305 | 289 | input: &fixtures::P2shInput, |
306 | 290 | index: usize, |
@@ -343,7 +327,7 @@ mod tests { |
343 | 327 |
|
344 | 328 | // Check if the script type is supported by the network |
345 | 329 | let output_script_support = network.output_script_support(); |
346 | | - let input_fixture = find_input_with_script_type(&fixture, script_type); |
| 330 | + let input_fixture = fixture.find_input_with_script_type(script_type); |
347 | 331 | if !script_type.is_supported_by(&output_script_support) { |
348 | 332 | // Script type not supported by network - skip test (no fixture expected) |
349 | 333 | assert!( |
@@ -441,101 +425,47 @@ mod tests { |
441 | 425 | Ok(()) |
442 | 426 | } |
443 | 427 |
|
444 | | - crate::test_psbt_fixtures!(test_p2sh_script_generation_from_fixture, network, { |
445 | | - test_wallet_script_type( |
446 | | - fixtures::ScriptType::P2sh, |
447 | | - network, |
448 | | - fixtures::TxFormat::Psbt, |
449 | | - ) |
450 | | - .unwrap(); |
451 | | - test_wallet_script_type( |
452 | | - fixtures::ScriptType::P2sh, |
453 | | - network, |
454 | | - fixtures::TxFormat::PsbtLite, |
455 | | - ) |
456 | | - .unwrap(); |
| 428 | + crate::test_psbt_fixtures!(test_p2sh_script_generation_from_fixture, network, format, { |
| 429 | + test_wallet_script_type(fixtures::ScriptType::P2sh, network, format).unwrap(); |
457 | 430 | }); |
458 | 431 |
|
459 | | - crate::test_psbt_fixtures!(test_p2sh_p2wsh_script_generation_from_fixture, network, { |
460 | | - test_wallet_script_type( |
461 | | - fixtures::ScriptType::P2shP2wsh, |
462 | | - network, |
463 | | - fixtures::TxFormat::Psbt, |
464 | | - ) |
465 | | - .unwrap(); |
466 | | - test_wallet_script_type( |
467 | | - fixtures::ScriptType::P2shP2wsh, |
468 | | - network, |
469 | | - fixtures::TxFormat::PsbtLite, |
470 | | - ) |
471 | | - .unwrap(); |
472 | | - }); |
| 432 | + crate::test_psbt_fixtures!( |
| 433 | + test_p2sh_p2wsh_script_generation_from_fixture, |
| 434 | + network, |
| 435 | + format, |
| 436 | + { |
| 437 | + test_wallet_script_type(fixtures::ScriptType::P2shP2wsh, network, format).unwrap(); |
| 438 | + } |
| 439 | + ); |
473 | 440 |
|
474 | | - crate::test_psbt_fixtures!(test_p2wsh_script_generation_from_fixture, network, { |
475 | | - test_wallet_script_type( |
476 | | - fixtures::ScriptType::P2wsh, |
477 | | - network, |
478 | | - fixtures::TxFormat::Psbt, |
479 | | - ) |
480 | | - .unwrap(); |
481 | | - test_wallet_script_type( |
482 | | - fixtures::ScriptType::P2wsh, |
483 | | - network, |
484 | | - fixtures::TxFormat::PsbtLite, |
485 | | - ) |
486 | | - .unwrap(); |
487 | | - }); |
| 441 | + crate::test_psbt_fixtures!( |
| 442 | + test_p2wsh_script_generation_from_fixture, |
| 443 | + network, |
| 444 | + format, |
| 445 | + { |
| 446 | + test_wallet_script_type(fixtures::ScriptType::P2wsh, network, format).unwrap(); |
| 447 | + } |
| 448 | + ); |
488 | 449 |
|
489 | | - crate::test_psbt_fixtures!(test_p2tr_script_generation_from_fixture, network, { |
490 | | - test_wallet_script_type( |
491 | | - fixtures::ScriptType::P2tr, |
492 | | - network, |
493 | | - fixtures::TxFormat::Psbt, |
494 | | - ) |
495 | | - .unwrap(); |
496 | | - test_wallet_script_type( |
497 | | - fixtures::ScriptType::P2tr, |
498 | | - network, |
499 | | - fixtures::TxFormat::PsbtLite, |
500 | | - ) |
501 | | - .unwrap(); |
| 450 | + crate::test_psbt_fixtures!(test_p2tr_script_generation_from_fixture, network, format, { |
| 451 | + test_wallet_script_type(fixtures::ScriptType::P2tr, network, format).unwrap(); |
502 | 452 | }); |
503 | 453 |
|
504 | 454 | crate::test_psbt_fixtures!( |
505 | 455 | test_p2tr_musig2_script_path_generation_from_fixture, |
506 | 456 | network, |
| 457 | + format, |
507 | 458 | { |
508 | | - test_wallet_script_type( |
509 | | - fixtures::ScriptType::P2trMusig2, |
510 | | - network, |
511 | | - fixtures::TxFormat::Psbt, |
512 | | - ) |
513 | | - .unwrap(); |
514 | | - test_wallet_script_type( |
515 | | - fixtures::ScriptType::P2trMusig2, |
516 | | - network, |
517 | | - fixtures::TxFormat::PsbtLite, |
518 | | - ) |
519 | | - .unwrap(); |
| 459 | + test_wallet_script_type(fixtures::ScriptType::P2trMusig2, network, format).unwrap(); |
520 | 460 | } |
521 | 461 | ); |
522 | 462 |
|
523 | 463 | crate::test_psbt_fixtures!( |
524 | 464 | test_p2tr_musig2_key_path_spend_script_generation_from_fixture, |
525 | 465 | network, |
| 466 | + format, |
526 | 467 | { |
527 | | - test_wallet_script_type( |
528 | | - fixtures::ScriptType::TaprootKeypath, |
529 | | - network, |
530 | | - fixtures::TxFormat::Psbt, |
531 | | - ) |
532 | | - .unwrap(); |
533 | | - test_wallet_script_type( |
534 | | - fixtures::ScriptType::TaprootKeypath, |
535 | | - network, |
536 | | - fixtures::TxFormat::PsbtLite, |
537 | | - ) |
538 | | - .unwrap(); |
| 468 | + test_wallet_script_type(fixtures::ScriptType::TaprootKeypath, network, format).unwrap(); |
539 | 469 | } |
540 | 470 | ); |
541 | 471 |
|
|
0 commit comments