Skip to content

Commit 12bcc64

Browse files
committed
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.
1 parent 41c607f commit 12bcc64

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

src/script/sign.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ static bool GetCScript(const SigningProvider& provider, const SignatureData& sig
4949
return false;
5050
}
5151

52-
static bool GetPubKey(const SigningProvider& provider, const SignatureData& sigdata, const CKeyID& address, CPubKey& pubkey)
52+
static bool GetPubKey(const SigningProvider& provider, SignatureData& sigdata, const CKeyID& address, CPubKey& pubkey)
5353
{
5454
if (provider.GetPubKey(address, pubkey)) {
55+
sigdata.misc_pubkeys.emplace(pubkey.GetID(), pubkey);
5556
return true;
5657
}
5758
// Look for pubkey in all partial sigs
@@ -60,6 +61,12 @@ static bool GetPubKey(const SigningProvider& provider, const SignatureData& sigd
6061
pubkey = it->second.first;
6162
return true;
6263
}
64+
// Look for pubkey in pubkey list
65+
const auto& pk_it = sigdata.misc_pubkeys.find(address);
66+
if (pk_it != sigdata.misc_pubkeys.end()) {
67+
pubkey = pk_it->second;
68+
return true;
69+
}
6370
return false;
6471
}
6572

@@ -70,9 +77,9 @@ static bool CreateSig(const BaseSignatureCreator& creator, SignatureData& sigdat
7077
sig_out = it->second.second;
7178
return true;
7279
}
80+
CPubKey pubkey;
81+
GetPubKey(provider, sigdata, keyid, pubkey);
7382
if (creator.CreateSig(provider, sig_out, keyid, scriptcode, sigversion)) {
74-
CPubKey pubkey;
75-
GetPubKey(provider, sigdata, keyid, pubkey);
7683
auto i = sigdata.signatures.emplace(keyid, SigPair(pubkey, sig_out));
7784
assert(i.second);
7885
return true;
@@ -200,6 +207,7 @@ bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreato
200207
txnouttype subType;
201208
solved = solved && SignStep(provider, creator, witnessscript, result, subType, SigVersion::WITNESS_V0, sigdata);
202209
sigdata.scriptWitness.stack = result;
210+
sigdata.witness = true;
203211
result.clear();
204212
}
205213
else if (solved && whichType == TX_WITNESS_V0_SCRIPTHASH)
@@ -210,7 +218,10 @@ bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreato
210218
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;
211219
result.push_back(std::vector<unsigned char>(witnessscript.begin(), witnessscript.end()));
212220
sigdata.scriptWitness.stack = result;
221+
sigdata.witness = true;
213222
result.clear();
223+
} else if (solved && whichType == TX_WITNESS_UNKNOWN) {
224+
sigdata.witness = true;
214225
}
215226

216227
if (P2SH) {

src/script/sign.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,13 @@ typedef std::pair<CPubKey, std::vector<unsigned char>> SigPair;
6666
// in order to construct final scriptSigs and scriptWitnesses.
6767
struct SignatureData {
6868
bool complete = false; ///< Stores whether the scriptSig and scriptWitness are complete
69+
bool witness = false; ///< Stores whether the input this SigData corresponds to is a witness input
6970
CScript scriptSig; ///< The scriptSig of an input. Contains complete signatures or the traditional partial signatures format
7071
CScript redeem_script; ///< The redeemScript (if any) for the input
7172
CScript witness_script; ///< The witnessScript (if any) for the input. witnessScripts are used in P2WSH outputs.
7273
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.
7374
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.
75+
std::map<CKeyID, CPubKey> misc_pubkeys;
7476

7577
SignatureData() {}
7678
explicit SignatureData(const CScript& script) : scriptSig(script) {}

0 commit comments

Comments
 (0)