Skip to content

Commit 9db10a5

Browse files
committed
[refactor] clean up logic in testmempoolaccept
Cleans up reundant code and reduces the diff of the next commit.
1 parent f72d80b commit 9db10a5

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

src/rpc/rawtransaction.cpp

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -955,35 +955,30 @@ static RPCHelpMan testmempoolaccept()
955955
nullptr /* plTxnReplaced */, false /* bypass_limits */, /* test_accept */ true, &fee);
956956
}
957957

958-
// Check that fee does not exceed maximum fee
959-
if (test_accept_res && max_raw_tx_fee && fee > max_raw_tx_fee) {
960-
result_0.pushKV("allowed", false);
961-
result_0.pushKV("reject-reason", "max-fee-exceeded");
962-
result.push_back(std::move(result_0));
963-
return result;
964-
}
965-
result_0.pushKV("allowed", test_accept_res);
966-
967958
// Only return the fee and vsize if the transaction would pass ATMP.
968959
// These can be used to calculate the feerate.
969960
if (test_accept_res) {
970-
result_0.pushKV("vsize", virtual_size);
971-
UniValue fees(UniValue::VOBJ);
972-
fees.pushKV("base", ValueFromAmount(fee));
973-
result_0.pushKV("fees", fees);
961+
// Check that fee does not exceed maximum fee
962+
if (max_raw_tx_fee && fee > max_raw_tx_fee) {
963+
result_0.pushKV("allowed", false);
964+
result_0.pushKV("reject-reason", "max-fee-exceeded");
965+
} else {
966+
result_0.pushKV("allowed", true);
967+
result_0.pushKV("vsize", virtual_size);
968+
UniValue fees(UniValue::VOBJ);
969+
fees.pushKV("base", ValueFromAmount(fee));
970+
result_0.pushKV("fees", fees);
971+
}
972+
result.push_back(std::move(result_0));
974973
} else {
975-
if (state.IsInvalid()) {
976-
if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS) {
977-
result_0.pushKV("reject-reason", "missing-inputs");
978-
} else {
979-
result_0.pushKV("reject-reason", strprintf("%s", state.GetRejectReason()));
980-
}
974+
result_0.pushKV("allowed", false);
975+
if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS) {
976+
result_0.pushKV("reject-reason", "missing-inputs");
981977
} else {
982978
result_0.pushKV("reject-reason", state.GetRejectReason());
983979
}
980+
result.push_back(std::move(result_0));
984981
}
985-
986-
result.push_back(std::move(result_0));
987982
return result;
988983
},
989984
};

0 commit comments

Comments
 (0)