Skip to content

Commit 638e40c

Browse files
committed
Have a PSBTAnalysis state that indicates invalid PSBT
Invalid PSBTs need to be re-created, so the next role is the Creator (new PSBTRole). Additionally, we need to know what went wrong so an error field was added to PSBTAnalysis. A PSBTAnalysis indicating invalid will have empty everything, next will be set to PSBTRole::CREATOR, and an error message.
1 parent b4a1da9 commit 638e40c

File tree

4 files changed

+18
-1
lines changed

4 files changed

+18
-1
lines changed

src/node/psbt.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ struct PSBTAnalysis {
3030
Optional<CAmount> fee; //!< Amount of fee being paid by the transaction
3131
std::vector<PSBTInputAnalysis> inputs; //!< More information about the individual inputs of the transaction
3232
PSBTRole next; //!< Which of the BIP 174 roles needs to handle the transaction next
33+
std::string error; //!< Error message
34+
35+
void SetInvalid(std::string err_msg)
36+
{
37+
estimated_vsize = nullopt;
38+
estimated_feerate = nullopt;
39+
fee = nullopt;
40+
inputs.clear();
41+
next = PSBTRole::CREATOR;
42+
error = err_msg;
43+
}
3344
};
3445

3546
/**

src/psbt.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ TransactionError CombinePSBTs(PartiallySignedTransaction& out, const std::vector
348348

349349
std::string PSBTRoleName(PSBTRole role) {
350350
switch (role) {
351+
case PSBTRole::CREATOR: return "creator";
351352
case PSBTRole::UPDATER: return "updater";
352353
case PSBTRole::SIGNER: return "signer";
353354
case PSBTRole::FINALIZER: return "finalizer";

src/psbt.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ struct PartiallySignedTransaction
560560
};
561561

562562
enum class PSBTRole {
563+
CREATOR,
563564
UPDATER,
564565
SIGNER,
565566
FINALIZER,

src/rpc/rawtransaction.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1672,6 +1672,7 @@ UniValue analyzepsbt(const JSONRPCRequest& request)
16721672
" \"estimated_feerate\" : feerate (numeric, optional) Estimated feerate of the final signed transaction in " + CURRENCY_UNIT + "/kB. Shown only if all UTXO slots in the PSBT have been filled.\n"
16731673
" \"fee\" : fee (numeric, optional) The transaction fee paid. Shown only if all UTXO slots in the PSBT have been filled.\n"
16741674
" \"next\" : \"role\" (string) Role of the next person that this psbt needs to go to\n"
1675+
" \"error\" : \"error\" (string) Error message if there is one"
16751676
"}\n"
16761677
},
16771678
RPCExamples {
@@ -1724,7 +1725,7 @@ UniValue analyzepsbt(const JSONRPCRequest& request)
17241725
}
17251726
inputs_result.push_back(input_univ);
17261727
}
1727-
result.pushKV("inputs", inputs_result);
1728+
if (!inputs_result.empty()) result.pushKV("inputs", inputs_result);
17281729

17291730
if (psbta.estimated_vsize != nullopt) {
17301731
result.pushKV("estimated_vsize", (int)*psbta.estimated_vsize);
@@ -1736,6 +1737,9 @@ UniValue analyzepsbt(const JSONRPCRequest& request)
17361737
result.pushKV("fee", ValueFromAmount(*psbta.fee));
17371738
}
17381739
result.pushKV("next", PSBTRoleName(psbta.next));
1740+
if (!psbta.error.empty()) {
1741+
result.pushKV("error", psbta.error);
1742+
}
17391743

17401744
return result;
17411745
}

0 commit comments

Comments
 (0)