Skip to content

Commit b6edb4f

Browse files
committed
Inline Sign1 and SignN
Sign1 and SignN are kind of redundant so remove them and inline their behavior into SignStep
1 parent 2643fa5 commit b6edb4f

File tree

1 file changed

+26
-39
lines changed

1 file changed

+26
-39
lines changed

src/script/sign.cpp

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -33,29 +33,6 @@ bool MutableTransactionSignatureCreator::CreateSig(const SigningProvider& provid
3333
return true;
3434
}
3535

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-
5936
/**
6037
* Sign scriptPubKey using signature made with creator.
6138
* 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
6845
CScript scriptRet;
6946
uint160 h160;
7047
ret.clear();
48+
std::vector<unsigned char> sig;
7149

7250
std::vector<valtype> vSolutions;
7351
if (!Solver(scriptPubKey, whichTypeRet, vSolutions))
7452
return false;
7553

76-
CKeyID keyID;
7754
switch (whichTypeRet)
7855
{
7956
case TX_NONSTANDARD:
8057
case TX_NULL_DATA:
8158
case TX_WITNESS_UNKNOWN:
8259
return false;
8360
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));
9663
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+
}
9773
case TX_SCRIPTHASH:
9874
if (provider.GetCScript(uint160(vSolutions[0]), scriptRet)) {
9975
ret.push_back(std::vector<unsigned char>(scriptRet.begin(), scriptRet.end()));
10076
return true;
10177
}
10278
return false;
10379

104-
case TX_MULTISIG:
80+
case TX_MULTISIG: {
81+
size_t required = vSolutions.front()[0];
10582
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+
}
10895
case TX_WITNESS_V0_KEYHASH:
10996
ret.push_back(vSolutions[0]);
11097
return true;

0 commit comments

Comments
 (0)