@@ -402,8 +402,7 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
402
402
// P2PK compressed
403
403
{
404
404
CBasicKeyStore keystore;
405
- scriptPubKey.clear ();
406
- scriptPubKey << ToByteVector (pubkeys[0 ]) << OP_CHECKSIG;
405
+ scriptPubKey = GetScriptForRawPubKey (pubkeys[0 ]);
407
406
408
407
// Keystore does not have key
409
408
result = IsMine (keystore, scriptPubKey);
@@ -418,8 +417,7 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
418
417
// P2PK uncompressed
419
418
{
420
419
CBasicKeyStore keystore;
421
- scriptPubKey.clear ();
422
- scriptPubKey << ToByteVector (uncompressedPubkey) << OP_CHECKSIG;
420
+ scriptPubKey = GetScriptForRawPubKey (uncompressedPubkey);
423
421
424
422
// Keystore does not have key
425
423
result = IsMine (keystore, scriptPubKey);
@@ -434,8 +432,7 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
434
432
// P2PKH compressed
435
433
{
436
434
CBasicKeyStore keystore;
437
- scriptPubKey.clear ();
438
- scriptPubKey << OP_DUP << OP_HASH160 << ToByteVector (pubkeys[0 ].GetID ()) << OP_EQUALVERIFY << OP_CHECKSIG;
435
+ scriptPubKey = GetScriptForDestination (pubkeys[0 ].GetID ());
439
436
440
437
// Keystore does not have key
441
438
result = IsMine (keystore, scriptPubKey);
@@ -450,8 +447,7 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
450
447
// P2PKH uncompressed
451
448
{
452
449
CBasicKeyStore keystore;
453
- scriptPubKey.clear ();
454
- scriptPubKey << OP_DUP << OP_HASH160 << ToByteVector (uncompressedPubkey.GetID ()) << OP_EQUALVERIFY << OP_CHECKSIG;
450
+ scriptPubKey = GetScriptForDestination (uncompressedPubkey.GetID ());
455
451
456
452
// Keystore does not have key
457
453
result = IsMine (keystore, scriptPubKey);
@@ -467,11 +463,8 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
467
463
{
468
464
CBasicKeyStore keystore;
469
465
470
- CScript redeemScript;
471
- redeemScript << OP_DUP << OP_HASH160 << ToByteVector (pubkeys[0 ].GetID ()) << OP_EQUALVERIFY << OP_CHECKSIG;
472
-
473
- scriptPubKey.clear ();
474
- scriptPubKey << OP_HASH160 << ToByteVector (CScriptID (redeemScript)) << OP_EQUAL;
466
+ CScript redeemScript = GetScriptForDestination (pubkeys[0 ].GetID ());
467
+ scriptPubKey = GetScriptForDestination (CScriptID (redeemScript));
475
468
476
469
// Keystore does not have redeemScript or key
477
470
result = IsMine (keystore, scriptPubKey);
@@ -492,12 +485,9 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
492
485
{
493
486
CBasicKeyStore keystore;
494
487
495
- CScript redeemscript, redeemscript_inner;
496
- redeemscript_inner << OP_DUP << OP_HASH160 << ToByteVector (pubkeys[0 ].GetID ()) << OP_EQUALVERIFY << OP_CHECKSIG;
497
- redeemscript << OP_HASH160 << ToByteVector (CScriptID (redeemscript_inner)) << OP_EQUAL;
498
-
499
- scriptPubKey.clear ();
500
- scriptPubKey << OP_HASH160 << ToByteVector (CScriptID (redeemscript)) << OP_EQUAL;
488
+ CScript redeemscript_inner = GetScriptForDestination (pubkeys[0 ].GetID ());
489
+ CScript redeemscript = GetScriptForDestination (CScriptID (redeemscript_inner));
490
+ scriptPubKey = GetScriptForDestination (CScriptID (redeemscript));
501
491
502
492
keystore.AddCScript (redeemscript);
503
493
keystore.AddCScript (redeemscript_inner);
@@ -511,14 +501,9 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
511
501
{
512
502
CBasicKeyStore keystore;
513
503
514
- CScript witnessscript, redeemscript;
515
- redeemscript << OP_DUP << OP_HASH160 << ToByteVector (pubkeys[0 ].GetID ()) << OP_EQUALVERIFY << OP_CHECKSIG;
516
- witnessscript << OP_HASH160 << ToByteVector (CScriptID (redeemscript)) << OP_EQUAL;
517
-
518
- uint256 scripthash;
519
- CSHA256 ().Write (witnessscript.data (), witnessscript.size ()).Finalize (scripthash.begin ());
520
- scriptPubKey.clear ();
521
- scriptPubKey << OP_0 << ToByteVector (scripthash);
504
+ CScript redeemscript = GetScriptForDestination (pubkeys[0 ].GetID ());
505
+ CScript witnessscript = GetScriptForDestination (CScriptID (redeemscript));
506
+ scriptPubKey = GetScriptForDestination (WitnessV0ScriptHash (witnessscript));
522
507
523
508
keystore.AddCScript (witnessscript);
524
509
keystore.AddCScript (redeemscript);
@@ -532,13 +517,8 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
532
517
{
533
518
CBasicKeyStore keystore;
534
519
535
- CScript witnessscript;
536
- witnessscript << OP_0 << ToByteVector (pubkeys[0 ].GetID ());
537
-
538
- scriptPubKey.clear ();
539
- uint256 scripthash;
540
- CSHA256 ().Write (witnessscript.data (), witnessscript.size ()).Finalize (scripthash.begin ());
541
- scriptPubKey << OP_0 << ToByteVector (scripthash);
520
+ CScript witnessscript = GetScriptForDestination (WitnessV0KeyHash (pubkeys[0 ].GetID ()));
521
+ scriptPubKey = GetScriptForDestination (WitnessV0ScriptHash (witnessscript));
542
522
543
523
keystore.AddCScript (witnessscript);
544
524
keystore.AddCScript (scriptPubKey);
@@ -551,16 +531,9 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
551
531
{
552
532
CBasicKeyStore keystore;
553
533
554
- CScript witnessscript_inner;
555
- witnessscript_inner << OP_DUP << OP_HASH160 << ToByteVector (pubkeys[0 ].GetID ()) << OP_EQUALVERIFY << OP_CHECKSIG;
556
- uint256 scripthash;
557
- CSHA256 ().Write (witnessscript_inner.data (), witnessscript_inner.size ()).Finalize (scripthash.begin ());
558
- CScript witnessscript;
559
- witnessscript << OP_0 << ToByteVector (scripthash);
560
-
561
- scriptPubKey.clear ();
562
- CSHA256 ().Write (witnessscript.data (), witnessscript.size ()).Finalize (scripthash.begin ());
563
- scriptPubKey << OP_0 << ToByteVector (scripthash);
534
+ CScript witnessscript_inner = GetScriptForDestination (pubkeys[0 ].GetID ());
535
+ CScript witnessscript = GetScriptForDestination (WitnessV0ScriptHash (witnessscript_inner));
536
+ scriptPubKey = GetScriptForDestination (WitnessV0ScriptHash (witnessscript));
564
537
565
538
keystore.AddCScript (witnessscript_inner);
566
539
keystore.AddCScript (witnessscript);
@@ -575,8 +548,7 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
575
548
CBasicKeyStore keystore;
576
549
keystore.AddKey (keys[0 ]);
577
550
578
- scriptPubKey.clear ();
579
- scriptPubKey << OP_0 << ToByteVector (pubkeys[0 ].GetID ());
551
+ scriptPubKey = GetScriptForDestination (WitnessV0KeyHash (pubkeys[0 ].GetID ()));
580
552
581
553
// Keystore implicitly has key and P2SH redeemScript
582
554
keystore.AddCScript (scriptPubKey);
@@ -589,8 +561,7 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
589
561
CBasicKeyStore keystore;
590
562
keystore.AddKey (uncompressedKey);
591
563
592
- scriptPubKey.clear ();
593
- scriptPubKey << OP_0 << ToByteVector (uncompressedPubkey.GetID ());
564
+ scriptPubKey = GetScriptForDestination (WitnessV0KeyHash (uncompressedPubkey.GetID ()));
594
565
595
566
// Keystore has key, but no P2SH redeemScript
596
567
result = IsMine (keystore, scriptPubKey);
@@ -606,11 +577,7 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
606
577
{
607
578
CBasicKeyStore keystore;
608
579
609
- scriptPubKey.clear ();
610
- scriptPubKey << OP_2 <<
611
- ToByteVector (uncompressedPubkey) <<
612
- ToByteVector (pubkeys[1 ]) <<
613
- OP_2 << OP_CHECKMULTISIG;
580
+ scriptPubKey = GetScriptForMultisig (2 , {uncompressedPubkey, pubkeys[1 ]});
614
581
615
582
// Keystore does not have any keys
616
583
result = IsMine (keystore, scriptPubKey);
@@ -641,14 +608,8 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
641
608
keystore.AddKey (uncompressedKey);
642
609
keystore.AddKey (keys[1 ]);
643
610
644
- CScript redeemScript;
645
- redeemScript << OP_2 <<
646
- ToByteVector (uncompressedPubkey) <<
647
- ToByteVector (pubkeys[1 ]) <<
648
- OP_2 << OP_CHECKMULTISIG;
649
-
650
- scriptPubKey.clear ();
651
- scriptPubKey << OP_HASH160 << ToByteVector (CScriptID (redeemScript)) << OP_EQUAL;
611
+ CScript redeemScript = GetScriptForMultisig (2 , {uncompressedPubkey, pubkeys[1 ]});
612
+ scriptPubKey = GetScriptForDestination (CScriptID (redeemScript));
652
613
653
614
// Keystore has no redeemScript
654
615
result = IsMine (keystore, scriptPubKey);
@@ -666,18 +627,8 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
666
627
keystore.AddKey (keys[0 ]);
667
628
keystore.AddKey (keys[1 ]);
668
629
669
- CScript witnessScript;
670
- witnessScript << OP_2 <<
671
- ToByteVector (pubkeys[0 ]) <<
672
- ToByteVector (pubkeys[1 ]) <<
673
- OP_2 << OP_CHECKMULTISIG;
674
-
675
- uint256 scriptHash;
676
- CSHA256 ().Write (&witnessScript[0 ], witnessScript.size ())
677
- .Finalize (scriptHash.begin ());
678
-
679
- scriptPubKey.clear ();
680
- scriptPubKey << OP_0 << ToByteVector (scriptHash);
630
+ CScript witnessScript = GetScriptForMultisig (2 , {pubkeys[0 ], pubkeys[1 ]});
631
+ scriptPubKey = GetScriptForDestination (WitnessV0ScriptHash (witnessScript));
681
632
682
633
// Keystore has keys, but no witnessScript or P2SH redeemScript
683
634
result = IsMine (keystore, scriptPubKey);
@@ -700,18 +651,8 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
700
651
keystore.AddKey (uncompressedKey);
701
652
keystore.AddKey (keys[1 ]);
702
653
703
- CScript witnessScript;
704
- witnessScript << OP_2 <<
705
- ToByteVector (uncompressedPubkey) <<
706
- ToByteVector (pubkeys[1 ]) <<
707
- OP_2 << OP_CHECKMULTISIG;
708
-
709
- uint256 scriptHash;
710
- CSHA256 ().Write (&witnessScript[0 ], witnessScript.size ())
711
- .Finalize (scriptHash.begin ());
712
-
713
- scriptPubKey.clear ();
714
- scriptPubKey << OP_0 << ToByteVector (scriptHash);
654
+ CScript witnessScript = GetScriptForMultisig (2 , {uncompressedPubkey, pubkeys[1 ]});
655
+ scriptPubKey = GetScriptForDestination (WitnessV0ScriptHash (witnessScript));
715
656
716
657
// Keystore has keys, but no witnessScript or P2SH redeemScript
717
658
result = IsMine (keystore, scriptPubKey);
@@ -732,21 +673,9 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
732
673
{
733
674
CBasicKeyStore keystore;
734
675
735
- CScript witnessScript;
736
- witnessScript << OP_2 <<
737
- ToByteVector (pubkeys[0 ]) <<
738
- ToByteVector (pubkeys[1 ]) <<
739
- OP_2 << OP_CHECKMULTISIG;
740
-
741
- uint256 scriptHash;
742
- CSHA256 ().Write (&witnessScript[0 ], witnessScript.size ())
743
- .Finalize (scriptHash.begin ());
744
-
745
- CScript redeemScript;
746
- redeemScript << OP_0 << ToByteVector (scriptHash);
747
-
748
- scriptPubKey.clear ();
749
- scriptPubKey << OP_HASH160 << ToByteVector (CScriptID (redeemScript)) << OP_EQUAL;
676
+ CScript witnessScript = GetScriptForMultisig (2 , {pubkeys[0 ], pubkeys[1 ]});
677
+ CScript redeemScript = GetScriptForDestination (WitnessV0ScriptHash (witnessScript));
678
+ scriptPubKey = GetScriptForDestination (CScriptID (redeemScript));
750
679
751
680
// Keystore has no witnessScript, P2SH redeemScript, or keys
752
681
result = IsMine (keystore, scriptPubKey);
0 commit comments