Changeset View
Changeset View
Standalone View
Standalone View
src/script/sign.cpp
Show First 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | if (provider.GetPubKey(address, pubkey)) { | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
static bool CreateSig(const BaseSignatureCreator &creator, | static bool CreateSig(const BaseSignatureCreator &creator, | ||||
SignatureData &sigdata, const SigningProvider &provider, | SignatureData &sigdata, const SigningProvider &provider, | ||||
std::vector<uint8_t> &sig_out, const CKeyID &keyid, | std::vector<uint8_t> &sig_out, const CPubKey &pubkey, | ||||
const CScript &scriptcode) { | const CScript &scriptcode) { | ||||
CKeyID keyid = pubkey.GetID(); | |||||
const auto it = sigdata.signatures.find(keyid); | const auto it = sigdata.signatures.find(keyid); | ||||
if (it != sigdata.signatures.end()) { | if (it != sigdata.signatures.end()) { | ||||
sig_out = it->second.second; | sig_out = it->second.second; | ||||
return true; | return true; | ||||
} | } | ||||
CPubKey pubkey; | KeyOriginInfo info; | ||||
GetPubKey(provider, sigdata, keyid, pubkey); | if (provider.GetKeyOrigin(keyid, info)) { | ||||
sigdata.misc_pubkeys.emplace(keyid, | |||||
std::make_pair(pubkey, std::move(info))); | |||||
} | |||||
if (creator.CreateSig(provider, sig_out, keyid, scriptcode)) { | if (creator.CreateSig(provider, sig_out, keyid, scriptcode)) { | ||||
auto i = sigdata.signatures.emplace(keyid, SigPair(pubkey, sig_out)); | auto i = sigdata.signatures.emplace(keyid, SigPair(pubkey, sig_out)); | ||||
assert(i.second); | assert(i.second); | ||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
Show All 17 Lines | static bool SignStep(const SigningProvider &provider, | ||||
whichTypeRet = Solver(scriptPubKey, vSolutions); | whichTypeRet = Solver(scriptPubKey, vSolutions); | ||||
switch (whichTypeRet) { | switch (whichTypeRet) { | ||||
case TX_NONSTANDARD: | case TX_NONSTANDARD: | ||||
case TX_NULL_DATA: | case TX_NULL_DATA: | ||||
return false; | return false; | ||||
case TX_PUBKEY: | case TX_PUBKEY: | ||||
if (!CreateSig(creator, sigdata, provider, sig, | if (!CreateSig(creator, sigdata, provider, sig, | ||||
CPubKey(vSolutions[0]).GetID(), scriptPubKey)) { | CPubKey(vSolutions[0]), scriptPubKey)) { | ||||
return false; | return false; | ||||
} | } | ||||
ret.push_back(std::move(sig)); | ret.push_back(std::move(sig)); | ||||
return true; | return true; | ||||
case TX_PUBKEYHASH: { | case TX_PUBKEYHASH: { | ||||
CKeyID keyID = CKeyID(uint160(vSolutions[0])); | CKeyID keyID = CKeyID(uint160(vSolutions[0])); | ||||
if (!CreateSig(creator, sigdata, provider, sig, keyID, | CPubKey pubkey; | ||||
provider.GetPubKey(keyID, pubkey); | |||||
if (!CreateSig(creator, sigdata, provider, sig, pubkey, | |||||
scriptPubKey)) { | scriptPubKey)) { | ||||
return false; | return false; | ||||
} | } | ||||
ret.push_back(std::move(sig)); | ret.push_back(std::move(sig)); | ||||
CPubKey pubkey; | |||||
provider.GetPubKey(keyID, pubkey); | |||||
ret.push_back(ToByteVector(pubkey)); | ret.push_back(ToByteVector(pubkey)); | ||||
return true; | return true; | ||||
} | } | ||||
case TX_SCRIPTHASH: | case TX_SCRIPTHASH: | ||||
if (GetCScript(provider, sigdata, uint160(vSolutions[0]), | if (GetCScript(provider, sigdata, uint160(vSolutions[0]), | ||||
scriptRet)) { | scriptRet)) { | ||||
ret.push_back( | ret.push_back( | ||||
std::vector<uint8_t>(scriptRet.begin(), scriptRet.end())); | std::vector<uint8_t>(scriptRet.begin(), scriptRet.end())); | ||||
return true; | return true; | ||||
} | } | ||||
return false; | return false; | ||||
case TX_MULTISIG: { | case TX_MULTISIG: { | ||||
size_t required = vSolutions.front()[0]; | size_t required = vSolutions.front()[0]; | ||||
// workaround CHECKMULTISIG bug | // workaround CHECKMULTISIG bug | ||||
ret.push_back(valtype()); | ret.push_back(valtype()); | ||||
for (size_t i = 1; i < vSolutions.size() - 1; ++i) { | for (size_t i = 1; i < vSolutions.size() - 1; ++i) { | ||||
CPubKey pubkey = CPubKey(vSolutions[i]); | CPubKey pubkey = CPubKey(vSolutions[i]); | ||||
if (ret.size() < required + 1 && | if (ret.size() < required + 1 && | ||||
CreateSig(creator, sigdata, provider, sig, pubkey.GetID(), | CreateSig(creator, sigdata, provider, sig, pubkey, | ||||
scriptPubKey)) { | scriptPubKey)) { | ||||
ret.push_back(std::move(sig)); | ret.push_back(std::move(sig)); | ||||
} | } | ||||
} | } | ||||
bool ok = ret.size() == required + 1; | bool ok = ret.size() == required + 1; | ||||
for (size_t i = 0; i + ret.size() < required + 1; ++i) { | for (size_t i = 0; i + ret.size() < required + 1; ++i) { | ||||
ret.push_back(valtype()); | ret.push_back(valtype()); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 327 Lines • Show Last 20 Lines |