Changeset View
Changeset View
Standalone View
Standalone View
src/psbt.cpp
// Copyright (c) 2009-2018 The Bitcoin Core developers | // Copyright (c) 2009-2018 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <psbt.h> | #include <psbt.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
PartiallySignedTransaction::PartiallySignedTransaction( | PartiallySignedTransaction::PartiallySignedTransaction( | ||||
const CMutableTransaction &txIn) | const CMutableTransaction &txIn) | ||||
: tx(txIn) { | : tx(txIn) { | ||||
inputs.resize(txIn.vin.size()); | inputs.resize(txIn.vin.size()); | ||||
outputs.resize(txIn.vout.size()); | outputs.resize(txIn.vout.size()); | ||||
} | } | ||||
bool PartiallySignedTransaction::IsNull() const { | bool PartiallySignedTransaction::IsNull() const { | ||||
▲ Show 20 Lines • Show All 151 Lines • ▼ Show 20 Lines | if (redeem_script.empty() && !output.redeem_script.empty()) { | ||||
redeem_script = output.redeem_script; | redeem_script = output.redeem_script; | ||||
} | } | ||||
} | } | ||||
bool PSBTInputSigned(const PSBTInput &input) { | bool PSBTInputSigned(const PSBTInput &input) { | ||||
return !input.final_script_sig.empty(); | return !input.final_script_sig.empty(); | ||||
} | } | ||||
void UpdatePSBTOutput(const SigningProvider &provider, | |||||
PartiallySignedTransaction &psbt, int index) { | |||||
const CTxOut &out = psbt.tx->vout.at(index); | |||||
PSBTOutput &psbt_out = psbt.outputs.at(index); | |||||
// Fill a SignatureData with output info | |||||
SignatureData sigdata; | |||||
psbt_out.FillSignatureData(sigdata); | |||||
// Construct a would-be spend of this output, to update sigdata with. | |||||
// Note that ProduceSignature is used to fill in metadata (not actual | |||||
// signatures), so provider does not need to provide any private keys (it | |||||
// can be a HidingSigningProvider). | |||||
MutableTransactionSignatureCreator creator(psbt.tx.get_ptr(), /* index */ 0, | |||||
out.nValue, | |||||
SigHashType().withForkId()); | |||||
ProduceSignature(provider, creator, out.scriptPubKey, sigdata); | |||||
// Put redeem_script and key paths, into PSBTOutput. | |||||
psbt_out.FromSignatureData(sigdata); | |||||
} | |||||
bool SignPSBTInput(const SigningProvider &provider, | bool SignPSBTInput(const SigningProvider &provider, | ||||
PartiallySignedTransaction &psbt, int index, | PartiallySignedTransaction &psbt, int index, | ||||
SigHashType sighash, SignatureData *out_sigdata, | SigHashType sighash, SignatureData *out_sigdata, | ||||
bool use_dummy) { | bool use_dummy) { | ||||
PSBTInput &input = psbt.inputs.at(index); | PSBTInput &input = psbt.inputs.at(index); | ||||
const CMutableTransaction &tx = *psbt.tx; | const CMutableTransaction &tx = *psbt.tx; | ||||
if (PSBTInputSigned(input)) { | if (PSBTInputSigned(input)) { | ||||
▲ Show 20 Lines • Show All 134 Lines • Show Last 20 Lines |