MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / SignPSBTInput

Function SignPSBTInput

src/script/sign.cpp:242–295  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

240}
241
242bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction& psbt, SignatureData& sigdata, int index, bool no_forkid, int sighash)
243{
244 PSBTInput& input = psbt.inputs.at(index);
245 const CMutableTransaction& tx = *psbt.tx;
246
247 if (PSBTInputSigned(input)) {
248 return true;
249 }
250
251 // Fill SignatureData with input info
252 input.FillSignatureData(sigdata);
253
254 // Get UTXO
255 bool require_witness_sig = false;
256 CTxOut utxo;
257
258 // Verify input sanity, which checks that at most one of witness or non-witness utxos is provided.
259 if (!input.IsSane()) {
260 return false;
261 }
262
263 if (input.non_witness_utxo) {
264 // If we're taking our information from a non-witness UTXO, verify that it matches the prevout.
265 COutPoint prevout = tx.vin[index].prevout;
266 if (input.non_witness_utxo->GetHash() != prevout.hash) {
267 return false;
268 }
269 utxo = input.non_witness_utxo->vout[prevout.n];
270 } else if (!input.witness_utxo.IsNull()) {
271 utxo = input.witness_utxo;
272 // When we're taking our information from a witness UTXO, we can't verify it is actually data from
273 // the output being spent. This is safe in case a witness signature is produced (which includes this
274 // information directly in the hash), but not for non-witness signatures. Remember that we require
275 // a witness signature in this situation.
276 require_witness_sig = true;
277 } else {
278 return false;
279 }
280
281 MutableTransactionSignatureCreator creator(&tx, index, utxo.nValue, no_forkid, sighash);
282 sigdata.witness = false;
283 bool sig_complete = ProduceSignature(provider, creator, utxo.scriptPubKey, sigdata, no_forkid);
284 // Verify that a witness signature was produced in case one was required.
285 if (require_witness_sig && !sigdata.witness) return false;
286 input.FromSignatureData(sigdata);
287
288 // If we have a witness signature, use the smaller witness UTXO.
289 if (sigdata.witness) {
290 input.witness_utxo = utxo;
291 input.non_witness_utxo = nullptr;
292 }
293
294 return sig_complete;
295}
296
297class SignatureExtractorChecker final : public BaseSignatureChecker
298{

Callers 2

FillPSBTFunction · 0.85
finalizepsbtFunction · 0.85

Calls 7

PSBTInputSignedFunction · 0.85
ProduceSignatureFunction · 0.85
FillSignatureDataMethod · 0.80
IsSaneMethod · 0.80
FromSignatureDataMethod · 0.80
GetHashMethod · 0.45
IsNullMethod · 0.45

Tested by

no test coverage detected