diff options
author | gzhao408 <gzhao408@berkeley.edu> | 2021-01-19 05:29:40 -0800 |
---|---|---|
committer | gzhao408 <gzhao408@berkeley.edu> | 2021-02-09 07:01:52 -0800 |
commit | f82baf0762f60c2ca5ffc339b095f9271d7c2f33 (patch) | |
tree | 4439a2ad3f6021a62be8bba8a8bf8da6d4b03174 /src/rpc/rawtransaction.cpp | |
parent | 9db10a55061e09021ff8ea1d6637d99f7959035f (diff) | |
download | bitcoin-f82baf0762f60c2ca5ffc339b095f9271d7c2f33.tar.xz |
[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.
Diffstat (limited to 'src/rpc/rawtransaction.cpp')
-rw-r--r-- | src/rpc/rawtransaction.cpp | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 31190ef9fc..784a53e060 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -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 { |