mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-21 13:10:08 +01:00
[refactor] return MempoolAcceptResult
This creates a cleaner interface with ATMP, allows us to make results const, and makes accessing values that don't make sense (e.g. fee when tx is invalid) an error.
This commit is contained in:
@@ -946,18 +946,13 @@ static RPCHelpMan testmempoolaccept()
|
||||
result_0.pushKV("txid", tx->GetHash().GetHex());
|
||||
result_0.pushKV("wtxid", tx->GetWitnessHash().GetHex());
|
||||
|
||||
TxValidationState state;
|
||||
bool test_accept_res;
|
||||
CAmount fee{0};
|
||||
{
|
||||
LOCK(cs_main);
|
||||
test_accept_res = AcceptToMemoryPool(mempool, state, std::move(tx),
|
||||
nullptr /* plTxnReplaced */, false /* bypass_limits */, /* test_accept */ true, &fee);
|
||||
}
|
||||
const MempoolAcceptResult accept_result = WITH_LOCK(cs_main, return AcceptToMemoryPool(mempool, std::move(tx),
|
||||
false /* bypass_limits */, /* test_accept */ true));
|
||||
|
||||
// Only return the fee and vsize if the transaction would pass ATMP.
|
||||
// These can be used to calculate the feerate.
|
||||
if (test_accept_res) {
|
||||
if (accept_result.m_result_type == MempoolAcceptResult::ResultType::VALID) {
|
||||
const CAmount fee = accept_result.m_base_fees.value();
|
||||
// Check that fee does not exceed maximum fee
|
||||
if (max_raw_tx_fee && fee > max_raw_tx_fee) {
|
||||
result_0.pushKV("allowed", false);
|
||||
@@ -972,6 +967,7 @@ static RPCHelpMan testmempoolaccept()
|
||||
result.push_back(std::move(result_0));
|
||||
} else {
|
||||
result_0.pushKV("allowed", false);
|
||||
const TxValidationState state = accept_result.m_state;
|
||||
if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS) {
|
||||
result_0.pushKV("reject-reason", "missing-inputs");
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user