| 178 | } |
| 179 | |
| 180 | bool ProduceSignature(const SigningProvider& provider, const BaseSignatureCreator& creator, const CScript& fromPubKey, SignatureData& sigdata, bool no_forkid) |
| 181 | { |
| 182 | if (sigdata.complete) return true; |
| 183 | |
| 184 | std::vector<valtype> result; |
| 185 | txnouttype whichType; |
| 186 | bool solved = SignStep(provider, creator, fromPubKey, result, whichType, SigVersion::BASE, sigdata); |
| 187 | bool P2SH = false; |
| 188 | CScript subscript; |
| 189 | sigdata.scriptWitness.stack.clear(); |
| 190 | |
| 191 | if (solved && whichType == TX_SCRIPTHASH) |
| 192 | { |
| 193 | // Solver returns the subscript that needs to be evaluated; |
| 194 | // the final scriptSig is the signatures from that |
| 195 | // and then the serialized subscript: |
| 196 | subscript = CScript(result[0].begin(), result[0].end()); |
| 197 | sigdata.redeem_script = subscript; |
| 198 | solved = solved && SignStep(provider, creator, subscript, result, whichType, SigVersion::BASE, sigdata) && whichType != TX_SCRIPTHASH; |
| 199 | P2SH = true; |
| 200 | } |
| 201 | |
| 202 | if (solved && whichType == TX_WITNESS_V0_KEYHASH) |
| 203 | { |
| 204 | CScript witnessscript; |
| 205 | witnessscript << OP_DUP << OP_HASH160 << ToByteVector(result[0]) << OP_EQUALVERIFY << OP_CHECKSIG; |
| 206 | txnouttype subType; |
| 207 | solved = solved && SignStep(provider, creator, witnessscript, result, subType, SigVersion::WITNESS_V0, sigdata); |
| 208 | sigdata.scriptWitness.stack = result; |
| 209 | sigdata.witness = true; |
| 210 | result.clear(); |
| 211 | } |
| 212 | else if (solved && whichType == TX_WITNESS_V0_SCRIPTHASH) |
| 213 | { |
| 214 | CScript witnessscript(result[0].begin(), result[0].end()); |
| 215 | sigdata.witness_script = witnessscript; |
| 216 | txnouttype subType; |
| 217 | 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; |
| 218 | result.push_back(std::vector<unsigned char>(witnessscript.begin(), witnessscript.end())); |
| 219 | sigdata.scriptWitness.stack = result; |
| 220 | sigdata.witness = true; |
| 221 | result.clear(); |
| 222 | } else if (solved && whichType == TX_WITNESS_UNKNOWN) { |
| 223 | sigdata.witness = true; |
| 224 | } |
| 225 | |
| 226 | if (P2SH) { |
| 227 | result.push_back(std::vector<unsigned char>(subscript.begin(), subscript.end())); |
| 228 | } |
| 229 | sigdata.scriptSig = PushAll(result); |
| 230 | |
| 231 | // Test solution |
| 232 | unsigned int flag = no_forkid ? (STANDARD_SCRIPT_VERIFY_FLAGS | SCRIPT_FORKID_DISABLED) : STANDARD_SCRIPT_VERIFY_FLAGS; |
| 233 | sigdata.complete = solved && VerifyScript(sigdata.scriptSig, fromPubKey, &sigdata.scriptWitness, flag, creator.Checker()); |
| 234 | return sigdata.complete; |
| 235 | } |
| 236 | |
| 237 | bool PSBTInputSigned(PSBTInput& input) |