aboutsummaryrefslogtreecommitdiff
path: root/src/psbt.h
diff options
context:
space:
mode:
authorGlenn Willen <gwillen@nerdnet.org>2019-03-01 00:25:10 -0800
committerGlenn Willen <gwillen@nerdnet.org>2019-03-26 17:38:00 -0700
commitef22fe8c1f331b4f13f21a54d12030b92e83fbe7 (patch)
tree4aef4053e59dc759ffbb3b0a18ad21b7af6fece6 /src/psbt.h
parentafd20a25f2937fee8d992c279631fa26cde4a7c8 (diff)
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.
Diffstat (limited to 'src/psbt.h')
-rw-r--r--src/psbt.h40
1 files changed, 39 insertions, 1 deletions
diff --git a/src/psbt.h b/src/psbt.h
index d89fd68c21..0f17a71a44 100644
--- a/src/psbt.h
+++ b/src/psbt.h
@@ -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