@@ -33,29 +33,6 @@ bool MutableTransactionSignatureCreator::CreateSig(const SigningProvider& provid
33
33
return true ;
34
34
}
35
35
36
- static bool Sign1 (const SigningProvider& provider, const CKeyID& address, const BaseSignatureCreator& creator, const CScript& scriptCode, std::vector<valtype>& ret, SigVersion sigversion)
37
- {
38
- std::vector<unsigned char > vchSig;
39
- if (!creator.CreateSig (provider, vchSig, address, scriptCode, sigversion))
40
- return false ;
41
- ret.push_back (vchSig);
42
- return true ;
43
- }
44
-
45
- static bool SignN (const SigningProvider& provider, const std::vector<valtype>& multisigdata, const BaseSignatureCreator& creator, const CScript& scriptCode, std::vector<valtype>& ret, SigVersion sigversion)
46
- {
47
- int nSigned = 0 ;
48
- int nRequired = multisigdata.front ()[0 ];
49
- for (unsigned int i = 1 ; i < multisigdata.size ()-1 && nSigned < nRequired; i++)
50
- {
51
- const valtype& pubkey = multisigdata[i];
52
- CKeyID keyID = CPubKey (pubkey).GetID ();
53
- if (Sign1 (provider, keyID, creator, scriptCode, ret, sigversion))
54
- ++nSigned;
55
- }
56
- return nSigned==nRequired;
57
- }
58
-
59
36
/* *
60
37
* Sign scriptPubKey using signature made with creator.
61
38
* Signatures are returned in scriptSigRet (or returns false if scriptPubKey can't be signed),
@@ -68,43 +45,53 @@ static bool SignStep(const SigningProvider& provider, const BaseSignatureCreator
68
45
CScript scriptRet;
69
46
uint160 h160;
70
47
ret.clear ();
48
+ std::vector<unsigned char > sig;
71
49
72
50
std::vector<valtype> vSolutions;
73
51
if (!Solver (scriptPubKey, whichTypeRet, vSolutions))
74
52
return false ;
75
53
76
- CKeyID keyID;
77
54
switch (whichTypeRet)
78
55
{
79
56
case TX_NONSTANDARD:
80
57
case TX_NULL_DATA:
81
58
case TX_WITNESS_UNKNOWN:
82
59
return false ;
83
60
case TX_PUBKEY:
84
- keyID = CPubKey (vSolutions[0 ]).GetID ();
85
- return Sign1 (provider, keyID, creator, scriptPubKey, ret, sigversion);
86
- case TX_PUBKEYHASH:
87
- keyID = CKeyID (uint160 (vSolutions[0 ]));
88
- if (!Sign1 (provider, keyID, creator, scriptPubKey, ret, sigversion))
89
- return false ;
90
- else
91
- {
92
- CPubKey vch;
93
- provider.GetPubKey (keyID, vch);
94
- ret.push_back (ToByteVector (vch));
95
- }
61
+ if (!creator.CreateSig (provider, sig, CPubKey (vSolutions[0 ]).GetID (), scriptPubKey, sigversion)) return false ;
62
+ ret.push_back (std::move (sig));
96
63
return true ;
64
+ case TX_PUBKEYHASH: {
65
+ CKeyID keyID = CKeyID (uint160 (vSolutions[0 ]));
66
+ if (!creator.CreateSig (provider, sig, keyID, scriptPubKey, sigversion)) return false ;
67
+ ret.push_back (std::move (sig));
68
+ CPubKey pubkey;
69
+ provider.GetPubKey (keyID, pubkey);
70
+ ret.push_back (ToByteVector (pubkey));
71
+ return true ;
72
+ }
97
73
case TX_SCRIPTHASH:
98
74
if (provider.GetCScript (uint160 (vSolutions[0 ]), scriptRet)) {
99
75
ret.push_back (std::vector<unsigned char >(scriptRet.begin (), scriptRet.end ()));
100
76
return true ;
101
77
}
102
78
return false ;
103
79
104
- case TX_MULTISIG:
80
+ case TX_MULTISIG: {
81
+ size_t required = vSolutions.front ()[0 ];
105
82
ret.push_back (valtype ()); // workaround CHECKMULTISIG bug
106
- return (SignN (provider, vSolutions, creator, scriptPubKey, ret, sigversion));
107
-
83
+ for (size_t i = 1 ; i < vSolutions.size () - 1 ; ++i) {
84
+ CPubKey pubkey = CPubKey (vSolutions[i]);
85
+ if (ret.size () < required + 1 && creator.CreateSig (provider, sig, pubkey.GetID (), scriptPubKey, sigversion)) {
86
+ ret.push_back (std::move (sig));
87
+ }
88
+ }
89
+ bool ok = ret.size () == required + 1 ;
90
+ for (size_t i = 0 ; i + ret.size () < required + 1 ; ++i) {
91
+ ret.push_back (valtype ());
92
+ }
93
+ return ok;
94
+ }
108
95
case TX_WITNESS_V0_KEYHASH:
109
96
ret.push_back (vSolutions[0 ]);
110
97
return true ;
0 commit comments