Changeset View
Changeset View
Standalone View
Standalone View
src/psbt.h
// Copyright (c) 2009-2019 The Bitcoin Core developers | // Copyright (c) 2009-2019 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. | ||||
#ifndef BITCOIN_PSBT_H | #ifndef BITCOIN_PSBT_H | ||||
#define BITCOIN_PSBT_H | #define BITCOIN_PSBT_H | ||||
#include <attributes.h> | #include <attributes.h> | ||||
#include <node/transaction.h> | #include <node/transaction.h> | ||||
#include <optional.h> | |||||
#include <primitives/transaction.h> | #include <primitives/transaction.h> | ||||
#include <pubkey.h> | #include <pubkey.h> | ||||
#include <script/sign.h> | #include <script/sign.h> | ||||
// Magic bytes | // Magic bytes | ||||
static constexpr uint8_t PSBT_MAGIC_BYTES[5] = {'p', 's', 'b', 't', 0xff}; | static constexpr uint8_t PSBT_MAGIC_BYTES[5] = {'p', 's', 'b', 't', 0xff}; | ||||
// Global types | // Global types | ||||
▲ Show 20 Lines • Show All 458 Lines • ▼ Show 20 Lines | struct PartiallySignedTransaction { | ||||
} | } | ||||
template <typename Stream> | template <typename Stream> | ||||
PartiallySignedTransaction(deserialize_type, Stream &s) { | PartiallySignedTransaction(deserialize_type, Stream &s) { | ||||
Unserialize(s); | Unserialize(s); | ||||
} | } | ||||
}; | }; | ||||
enum class PSBTRole { | |||||
UPDATER, | |||||
SIGNER, | |||||
FINALIZER, | |||||
EXTRACTOR, | |||||
}; | |||||
struct PSBTInputAnalysis { | |||||
bool has_utxo; | |||||
bool is_final; | |||||
PSBTRole next; | |||||
std::vector<CKeyID> missing_pubkeys; | |||||
std::vector<CKeyID> missing_sigs; | |||||
uint160 missing_redeem_script; | |||||
}; | |||||
struct PSBTAnalysis { | |||||
Optional<size_t> estimated_vsize; | |||||
Optional<CFeeRate> estimated_feerate; | |||||
Optional<Amount> fee; | |||||
std::vector<PSBTInputAnalysis> inputs; | |||||
PSBTRole next; | |||||
}; | |||||
std::string PSBTRoleName(PSBTRole role); | |||||
/** Checks whether a PSBTInput is already signed. */ | /** Checks whether a PSBTInput is already signed. */ | ||||
bool PSBTInputSigned(PSBTInput &input); | bool PSBTInputSigned(const PSBTInput &input); | ||||
/** | /** | ||||
* Signs a PSBTInput, verifying that all provided data matches what is being | * Signs a PSBTInput, verifying that all provided data matches what is being | ||||
* signed. | * signed. | ||||
*/ | */ | ||||
bool SignPSBTInput(const SigningProvider &provider, | bool SignPSBTInput(const SigningProvider &provider, | ||||
PartiallySignedTransaction &psbt, int index, | PartiallySignedTransaction &psbt, int index, | ||||
SigHashType sighash = SigHashType(), | SigHashType sighash = SigHashType(), | ||||
Show All 28 Lines | |||||
* @param[in] psbtxs the PSBTs to combine | * @param[in] psbtxs the PSBTs to combine | ||||
* @return error (OK if we successfully combined the transactions, other error | * @return error (OK if we successfully combined the transactions, other error | ||||
* if they were not compatible) | * if they were not compatible) | ||||
*/ | */ | ||||
NODISCARD TransactionError | NODISCARD TransactionError | ||||
CombinePSBTs(PartiallySignedTransaction &out, | CombinePSBTs(PartiallySignedTransaction &out, | ||||
const std::vector<PartiallySignedTransaction> &psbtxs); | const std::vector<PartiallySignedTransaction> &psbtxs); | ||||
/** | |||||
* Provides helpful miscellaneous information about where a PSBT is in the | |||||
* signing workflow. | |||||
* | |||||
* @param[in] psbtx the PSBT to analyze | |||||
* @return A PSBTAnalysis with information about the provided PSBT. | |||||
*/ | |||||
PSBTAnalysis AnalyzePSBT(PartiallySignedTransaction psbtx); | |||||
//! Decode a base64ed PSBT into a PartiallySignedTransaction | //! Decode a base64ed PSBT into a PartiallySignedTransaction | ||||
NODISCARD bool DecodeBase64PSBT(PartiallySignedTransaction &decoded_psbt, | NODISCARD bool DecodeBase64PSBT(PartiallySignedTransaction &decoded_psbt, | ||||
const std::string &base64_psbt, | const std::string &base64_psbt, | ||||
std::string &error); | std::string &error); | ||||
//! Decode a raw (binary blob) PSBT into a PartiallySignedTransaction | //! Decode a raw (binary blob) PSBT into a PartiallySignedTransaction | ||||
NODISCARD bool DecodeRawPSBT(PartiallySignedTransaction &decoded_psbt, | NODISCARD bool DecodeRawPSBT(PartiallySignedTransaction &decoded_psbt, | ||||
const std::string &raw_psbt, std::string &error); | const std::string &raw_psbt, std::string &error); | ||||
#endif // BITCOIN_PSBT_H | #endif // BITCOIN_PSBT_H |