MCPcopy Create free account
hub / github.com/Bitcoin-ABC/bitcoin-abc / SignStep

Function SignStep

src/script/sign.cpp:106–181  ·  view source on GitHub ↗

* Sign scriptPubKey using signature made with creator. * Signatures are returned in scriptSigRet (or returns false if scriptPubKey * can't be signed), unless whichTypeRet is TxoutType::SCRIPTHASH, in which * case scriptSigRet is the redemption script. * Returns false if scriptPubKey could not be completely satisfied. */

Source from the content-addressed store, hash-verified

104 * Returns false if scriptPubKey could not be completely satisfied.
105 */
106static bool SignStep(const SigningProvider &provider,
107 const BaseSignatureCreator &creator,
108 const CScript &scriptPubKey, std::vector<valtype> &ret,
109 TxoutType &whichTypeRet, SignatureData &sigdata) {
110 CScript scriptRet;
111 uint160 h160;
112 ret.clear();
113 std::vector<uint8_t> sig;
114
115 std::vector<valtype> vSolutions;
116 whichTypeRet = Solver(scriptPubKey, vSolutions);
117
118 switch (whichTypeRet) {
119 case TxoutType::NONSTANDARD:
120 case TxoutType::NULL_DATA:
121 return false;
122 case TxoutType::PUBKEY:
123 if (!CreateSig(creator, sigdata, provider, sig,
124 CPubKey(vSolutions[0]), scriptPubKey)) {
125 return false;
126 }
127 ret.push_back(std::move(sig));
128 return true;
129 case TxoutType::PUBKEYHASH: {
130 CKeyID keyID = CKeyID(uint160(vSolutions[0]));
131 CPubKey pubkey;
132 if (!GetPubKey(provider, sigdata, keyID, pubkey)) {
133 // Pubkey could not be found, add to missing
134 sigdata.missing_pubkeys.push_back(keyID);
135 return false;
136 }
137 if (!CreateSig(creator, sigdata, provider, sig, pubkey,
138 scriptPubKey)) {
139 return false;
140 }
141 ret.push_back(std::move(sig));
142 ret.push_back(ToByteVector(pubkey));
143 return true;
144 }
145 case TxoutType::SCRIPTHASH:
146 h160 = uint160(vSolutions[0]);
147 if (GetCScript(provider, sigdata, CScriptID{h160}, scriptRet)) {
148 ret.push_back(
149 std::vector<uint8_t>(scriptRet.begin(), scriptRet.end()));
150 return true;
151 }
152 // Could not find redeemScript, add to missing
153 sigdata.missing_redeem_script = h160;
154 return false;
155 case TxoutType::MULTISIG: {
156 size_t required = vSolutions.front()[0];
157 // workaround CHECKMULTISIG bug
158 ret.push_back(valtype());
159 for (size_t i = 1; i < vSolutions.size() - 1; ++i) {
160 CPubKey pubkey = CPubKey(vSolutions[i]);
161 // We need to always call CreateSig in order to fill sigdata
162 // with all possible signatures that we can create. This will
163 // allow further PSBT processing to work as it needs all

Callers 1

ProduceSignatureFunction · 0.85

Calls 14

SolverFunction · 0.85
CreateSigFunction · 0.85
GetPubKeyFunction · 0.85
ToByteVectorFunction · 0.85
GetCScriptFunction · 0.85
frontMethod · 0.80
CPubKeyClass · 0.70
CKeyIDClass · 0.70
clearMethod · 0.65
uint160Class · 0.50
push_backMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected