[refactor] clean up logic in testmempoolaccept

Cleans up reundant code and reduces the diff of the next commit.
This commit is contained in:
gzhao408 2021-01-26 11:50:00 -08:00
parent f72d80b07a
commit 9db10a5506

View file

@ -955,35 +955,30 @@ static RPCHelpMan testmempoolaccept()
nullptr /* plTxnReplaced */, false /* bypass_limits */, /* test_accept */ true, &fee);
}
// Check that fee does not exceed maximum fee
if (test_accept_res && max_raw_tx_fee && fee > max_raw_tx_fee) {
result_0.pushKV("allowed", false);
result_0.pushKV("reject-reason", "max-fee-exceeded");
result.push_back(std::move(result_0));
return result;
}
result_0.pushKV("allowed", test_accept_res);
// Only return the fee and vsize if the transaction would pass ATMP.
// These can be used to calculate the feerate.
if (test_accept_res) {
result_0.pushKV("vsize", virtual_size);
UniValue fees(UniValue::VOBJ);
fees.pushKV("base", ValueFromAmount(fee));
result_0.pushKV("fees", fees);
// Check that fee does not exceed maximum fee
if (max_raw_tx_fee && fee > max_raw_tx_fee) {
result_0.pushKV("allowed", false);
result_0.pushKV("reject-reason", "max-fee-exceeded");
} else {
result_0.pushKV("allowed", true);
result_0.pushKV("vsize", virtual_size);
UniValue fees(UniValue::VOBJ);
fees.pushKV("base", ValueFromAmount(fee));
result_0.pushKV("fees", fees);
}
result.push_back(std::move(result_0));
} else {
if (state.IsInvalid()) {
if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS) {
result_0.pushKV("reject-reason", "missing-inputs");
} else {
result_0.pushKV("reject-reason", strprintf("%s", state.GetRejectReason()));
}
result_0.pushKV("allowed", false);
if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS) {
result_0.pushKV("reject-reason", "missing-inputs");
} else {
result_0.pushKV("reject-reason", state.GetRejectReason());
}
result.push_back(std::move(result_0));
}
result.push_back(std::move(result_0));
return result;
},
};