Add pubkeys and whether input was witness to SignatureData
Stores pubkeys in SignatureData and retrieves them when using GetPubKey(). Stores whether the signatures in a SignatureData are for a witness input.
This commit is contained in:
parent
41c607f09b
commit
12bcc64f27
2 changed files with 16 additions and 3 deletions
|
@ -49,9 +49,10 @@ static bool GetCScript(const SigningProvider& provider, const SignatureData& sig
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool GetPubKey(const SigningProvider& provider, const SignatureData& sigdata, const CKeyID& address, CPubKey& pubkey)
|
static bool GetPubKey(const SigningProvider& provider, SignatureData& sigdata, const CKeyID& address, CPubKey& pubkey)
|
||||||
{
|
{
|
||||||
if (provider.GetPubKey(address, pubkey)) {
|
if (provider.GetPubKey(address, pubkey)) {
|
||||||
|
sigdata.misc_pubkeys.emplace(pubkey.GetID(), pubkey);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// Look for pubkey in all partial sigs
|
// Look for pubkey in all partial sigs
|
||||||
|
@ -60,6 +61,12 @@ static bool GetPubKey(const SigningProvider& provider, const SignatureData& sigd
|
||||||
pubkey = it->second.first;
|
pubkey = it->second.first;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
// Look for pubkey in pubkey list
|
||||||
|
const auto& pk_it = sigdata.misc_pubkeys.find(address);
|
||||||
|
if (pk_it != sigdata.misc_pubkeys.end()) {
|
||||||
|
pubkey = pk_it->second;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,9 +77,9 @@ static bool CreateSig(const BaseSignatureCreator& creator, SignatureData& sigdat
|
||||||
sig_out = it->second.second;
|
sig_out = it->second.second;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (creator.CreateSig(provider, sig_out, keyid, scriptcode, sigversion)) {
|
|
||||||
CPubKey pubkey;
|
CPubKey pubkey;
|
||||||
GetPubKey(provider, sigdata, keyid, pubkey);
|
GetPubKey(provider, sigdata, keyid, pubkey);
|
||||||
|
if (creator.CreateSig(provider, sig_out, keyid, scriptcode, sigversion)) {
|
||||||
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;
|
||||||
|
@ -200,6 +207,7 @@ bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreato
|
||||||
txnouttype subType;
|
txnouttype subType;
|
||||||
solved = solved && SignStep(provider, creator, witnessscript, result, subType, SigVersion::WITNESS_V0, sigdata);
|
solved = solved && SignStep(provider, creator, witnessscript, result, subType, SigVersion::WITNESS_V0, sigdata);
|
||||||
sigdata.scriptWitness.stack = result;
|
sigdata.scriptWitness.stack = result;
|
||||||
|
sigdata.witness = true;
|
||||||
result.clear();
|
result.clear();
|
||||||
}
|
}
|
||||||
else if (solved && whichType == TX_WITNESS_V0_SCRIPTHASH)
|
else if (solved && whichType == TX_WITNESS_V0_SCRIPTHASH)
|
||||||
|
@ -210,7 +218,10 @@ bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreato
|
||||||
solved = solved && SignStep(provider, creator, witnessscript, result, subType, SigVersion::WITNESS_V0, sigdata) && subType != TX_SCRIPTHASH && subType != TX_WITNESS_V0_SCRIPTHASH && subType != TX_WITNESS_V0_KEYHASH;
|
solved = solved && SignStep(provider, creator, witnessscript, result, subType, SigVersion::WITNESS_V0, sigdata) && subType != TX_SCRIPTHASH && subType != TX_WITNESS_V0_SCRIPTHASH && subType != TX_WITNESS_V0_KEYHASH;
|
||||||
result.push_back(std::vector<unsigned char>(witnessscript.begin(), witnessscript.end()));
|
result.push_back(std::vector<unsigned char>(witnessscript.begin(), witnessscript.end()));
|
||||||
sigdata.scriptWitness.stack = result;
|
sigdata.scriptWitness.stack = result;
|
||||||
|
sigdata.witness = true;
|
||||||
result.clear();
|
result.clear();
|
||||||
|
} else if (solved && whichType == TX_WITNESS_UNKNOWN) {
|
||||||
|
sigdata.witness = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (P2SH) {
|
if (P2SH) {
|
||||||
|
|
|
@ -66,11 +66,13 @@ typedef std::pair<CPubKey, std::vector<unsigned char>> SigPair;
|
||||||
// in order to construct final scriptSigs and scriptWitnesses.
|
// in order to construct final scriptSigs and scriptWitnesses.
|
||||||
struct SignatureData {
|
struct SignatureData {
|
||||||
bool complete = false; ///< Stores whether the scriptSig and scriptWitness are complete
|
bool complete = false; ///< Stores whether the scriptSig and scriptWitness are complete
|
||||||
|
bool witness = false; ///< Stores whether the input this SigData corresponds to is a witness input
|
||||||
CScript scriptSig; ///< The scriptSig of an input. Contains complete signatures or the traditional partial signatures format
|
CScript scriptSig; ///< The scriptSig of an input. Contains complete signatures or the traditional partial signatures format
|
||||||
CScript redeem_script; ///< The redeemScript (if any) for the input
|
CScript redeem_script; ///< The redeemScript (if any) for the input
|
||||||
CScript witness_script; ///< The witnessScript (if any) for the input. witnessScripts are used in P2WSH outputs.
|
CScript witness_script; ///< The witnessScript (if any) for the input. witnessScripts are used in P2WSH outputs.
|
||||||
CScriptWitness scriptWitness; ///< The scriptWitness of an input. Contains complete signatures or the traditional partial signatures format. scriptWitness is part of a transaction input per BIP 144.
|
CScriptWitness scriptWitness; ///< The scriptWitness of an input. Contains complete signatures or the traditional partial signatures format. scriptWitness is part of a transaction input per BIP 144.
|
||||||
std::map<CKeyID, SigPair> signatures; ///< BIP 174 style partial signatures for the input. May contain all signatures necessary for producing a final scriptSig or scriptWitness.
|
std::map<CKeyID, SigPair> signatures; ///< BIP 174 style partial signatures for the input. May contain all signatures necessary for producing a final scriptSig or scriptWitness.
|
||||||
|
std::map<CKeyID, CPubKey> misc_pubkeys;
|
||||||
|
|
||||||
SignatureData() {}
|
SignatureData() {}
|
||||||
explicit SignatureData(const CScript& script) : scriptSig(script) {}
|
explicit SignatureData(const CScript& script) : scriptSig(script) {}
|
||||||
|
|
Loading…
Add table
Reference in a new issue