22 if (
tx->GetId() != psbt.
tx->GetId()) {
26 for (
size_t i = 0; i <
inputs.size(); ++i) {
29 for (
size_t i = 0; i <
outputs.size(); ++i) {
39 if (!input.IsSane()) {
48 if (std::find(
tx->vin.begin(),
tx->vin.end(), txin) !=
tx->vin.end()) {
51 tx->vin.push_back(txin);
60 tx->vout.push_back(txout);
66 int input_index)
const {
77 return utxo.IsNull() && partial_sigs.empty() &&
unknown.empty() &&
78 hd_keypaths.empty() && redeem_script.empty();
82 if (!final_script_sig.empty()) {
90 sigdata.
signatures.insert(partial_sigs.begin(), partial_sigs.end());
91 if (!redeem_script.empty()) {
94 for (
const auto &key_pair : hd_keypaths) {
95 sigdata.
misc_pubkeys.emplace(key_pair.first.GetID(), key_pair);
101 partial_sigs.clear();
103 redeem_script.clear();
116 hd_keypaths.emplace(entry.second);
142 if (!redeem_script.empty()) {
145 for (
const auto &key_pair : hd_keypaths) {
146 sigdata.
misc_pubkeys.emplace(key_pair.first.GetID(), key_pair);
155 hd_keypaths.emplace(entry.second);
160 return redeem_script.empty() && hd_keypaths.empty() &&
unknown.empty();
178 const CTxOut &out = psbt.
tx->vout.at(index);
190 psbt.
tx ? &psbt.
tx.value() :
nullptr, 0, out.
nValue,
227 bool sig_complete{
false};
240 if (out_sigdata !=
nullptr) {
255 bool complete =
true;
256 for (
size_t i = 0; i < psbtx.
tx->vin.size(); ++i) {
274 for (
size_t i = 0; i < result.
vin.size(); ++i) {
275 result.
vin[i].scriptSig = psbtx.
inputs[i].final_script_sig;
282 const std::vector<PartiallySignedTransaction> &psbtxs) {
287 for (
auto it = std::next(psbtxs.begin()); it != psbtxs.end(); ++it) {
288 if (!out.
Merge(*it)) {
317 const std::string &base64_tx, std::string &
error) {
319 std::string tx_data =
DecodeBase64(base64_tx, &invalid);
321 error =
"invalid base64";
328 std::string &
error) {
329 CDataStream ss_data(tx_data.data(), tx_data.data() + tx_data.size(),
333 if (!ss_data.empty()) {
334 error =
"extra data after PSBT";
337 }
catch (
const std::exception &e) {
bool AddInput(const CTxIn &txin, PSBTInput &psbtin)
std::map< std::vector< uint8_t >, std::vector< uint8_t > > unknown
iterator insert(iterator pos, const T &value)
CScript scriptSig
The scriptSig of an input.
std::vector< CKeyID > missing_sigs
KeyIDs of pubkeys for signatures which could not be found.
bool FinalizePSBT(PartiallySignedTransaction &psbtx)
Finalizes a PSBT if possible, combining partial signatures.
std::vector< CKeyID > missing_pubkeys
KeyIDs of pubkeys which could not be found.
const BaseSignatureCreator & DUMMY_SIGNATURE_CREATOR
A signature creator that just produces 71-byte empty signatures.
std::vector< uint8_t > DecodeBase64(const char *p, bool *pf_invalid)
void Merge(const PSBTOutput &output)
std::vector< CTxOut > vout
A version of CTransaction with the PSBT format.
Double ended buffer combining vector and stream-like interfaces.
std::map< CKeyID, std::pair< CPubKey, KeyOriginInfo > > misc_pubkeys
A signature creator for transactions.
bool AddOutput(const CTxOut &txout, const PSBTOutput &psbtout)
bool FinalizeAndExtractPSBT(PartiallySignedTransaction &psbtx, CMutableTransaction &result)
Finalizes a PSBT if possible, and extracts it to a CMutableTransaction if it could be finalized...
void FromSignatureData(const SignatureData &sigdata)
A structure for PSBTs which contains per output information.
std::vector< PSBTOutput > outputs
std::map< CPubKey, KeyOriginInfo > hd_keypaths
uint160 missing_redeem_script
ScriptID of the missing redeemScript (if any)
SigHashType withForkId(bool forkId=true) const
An input of a transaction.
bool DecodeBase64PSBT(PartiallySignedTransaction &psbt, const std::string &base64_tx, std::string &error)
Decode a base64ed PSBT into a PartiallySignedTransaction.
const SigningProvider & DUMMY_SIGNING_PROVIDER
An output of a transaction.
void UpdatePSBTOutput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index)
Updates a PSBTOutput with information from provider.
bool SignPSBTInput(const SigningProvider &provider, PartiallySignedTransaction &psbt, int index, SigHashType sighash, SignatureData *out_sigdata, bool use_dummy)
Signs a PSBTInput, verifying that all provided data matches what is being signed. ...
std::vector< PSBTInput > inputs
bool DecodeRawPSBT(PartiallySignedTransaction &psbt, const std::string &tx_data, std::string &error)
Decode a raw (binary blob) PSBT into a PartiallySignedTransaction.
void FillSignatureData(SignatureData &sigdata) const
NODISCARD bool Merge(const PartiallySignedTransaction &psbt)
Merge psbt into this.
An interface to be implemented by keystores that support signing.
static const int PROTOCOL_VERSION
network protocol versioning
A mutable version of CTransaction.
bool ProduceSignature(const SigningProvider &provider, const BaseSignatureCreator &creator, const CScript &fromPubKey, SignatureData &sigdata)
Produce a script signature using a generic signature creator.
bool PSBTInputSigned(const PSBTInput &input)
Checks whether a PSBTInput is already signed.
std::optional< CMutableTransaction > tx
std::string PSBTRoleName(const PSBTRole role)
bool complete
Stores whether the scriptSig are complete.
bool GetInputUTXO(CTxOut &utxo, int input_index) const
Finds the UTXO for a given input index.
bool error(const char *fmt, const Args &... args)
CScript redeem_script
The redeemScript (if any) for the input.
PartiallySignedTransaction()
std::map< std::vector< uint8_t >, std::vector< uint8_t > > unknown
std::map< CKeyID, SigPair > signatures
BIP 174 style partial signatures for the input.
Signature hash type wrapper class.
TransactionError CombinePSBTs(PartiallySignedTransaction &out, const std::vector< PartiallySignedTransaction > &psbtxs)
Combines PSBTs with the same underlying transaction, resulting in a single PSBT with all partial sign...