Refactor analyzepsbt for use outside RPC code

Refactor the analyzepsbt RPC into (1) an AnalyzePSBT function, which returns
its output as a new strongly-typed PSBTAnalysis struct, and (2) a thin wrapper
which converts the struct into a UniValue for RPC use.
This commit is contained in:
Glenn Willen
2019-03-01 00:25:10 -08:00
parent afd20a25f2
commit ef22fe8c1f
3 changed files with 213 additions and 130 deletions

View File

@@ -7,6 +7,8 @@
#include <attributes.h>
#include <node/transaction.h>
#include <optional.h>
#include <policy/feerate.h>
#include <primitives/transaction.h>
#include <pubkey.h>
#include <script/sign.h>
@@ -548,8 +550,36 @@ struct PartiallySignedTransaction
}
};
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;
uint256 missing_witness_script;
};
struct PSBTAnalysis {
Optional<size_t> estimated_vsize;
Optional<CFeeRate> estimated_feerate;
Optional<CAmount> fee;
std::vector<PSBTInputAnalysis> inputs;
PSBTRole next;
};
std::string PSBTRoleName(PSBTRole role);
/** 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 signed. */
bool SignPSBTInput(const SigningProvider& provider, PartiallySignedTransaction& psbt, int index, int sighash = SIGHASH_ALL, SignatureData* out_sigdata = nullptr, bool use_dummy = false);
@@ -580,6 +610,14 @@ bool FinalizeAndExtractPSBT(PartiallySignedTransaction& psbtx, CMutableTransacti
*/
NODISCARD TransactionError CombinePSBTs(PartiallySignedTransaction& out, 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
NODISCARD bool DecodeBase64PSBT(PartiallySignedTransaction& decoded_psbt, const std::string& base64_psbt, std::string& error);
//! Decode a raw (binary blob) PSBT into a PartiallySignedTransaction