mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-12 11:19:08 -05:00
[style] Clean up BroadcastTransaction()
This commit is contained in:
parent
7282d4c036
commit
5a77abd4e6
1 changed files with 66 additions and 64 deletions
|
@ -28,19 +28,21 @@ static TransactionError HandleATMPError(const TxValidationState& state, std::str
|
|||
|
||||
TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef tx, std::string& err_string, const CAmount& max_tx_fee, bool relay, bool wait_callback)
|
||||
{
|
||||
// BroadcastTransaction can be called by either sendrawtransaction RPC or wallet RPCs.
|
||||
// node.peerman is assigned both before chain clients and before RPC server is accepting calls,
|
||||
// and reset after chain clients and RPC sever are stopped. node.peerman should never be null here.
|
||||
assert(node.peerman);
|
||||
// BroadcastTransaction can be called by either sendrawtransaction RPC or the wallet.
|
||||
// chainman, mempool and peerman are initialized before the RPC server and wallet are started
|
||||
// and reset after the RPC sever and wallet are stopped.
|
||||
assert(node.chainman);
|
||||
assert(node.mempool);
|
||||
assert(node.peerman);
|
||||
|
||||
std::promise<void> promise;
|
||||
uint256 txid = tx->GetHash();
|
||||
uint256 wtxid = tx->GetWitnessHash();
|
||||
bool callback_set = false;
|
||||
|
||||
{ // cs_main scope
|
||||
assert(node.chainman);
|
||||
{
|
||||
LOCK(cs_main);
|
||||
|
||||
// If the transaction is already confirmed in the chain, don't do anything
|
||||
// and return early.
|
||||
CCoinsViewCache &view = node.chainman->ActiveChainstate().CoinsTip();
|
||||
|
@ -50,6 +52,7 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
|
|||
// So if the output does exist, then this transaction exists in the chain.
|
||||
if (!existingCoin.IsSpent()) return TransactionError::ALREADY_IN_CHAIN;
|
||||
}
|
||||
|
||||
if (auto mempool_tx = node.mempool->get(txid); mempool_tx) {
|
||||
// There's already a transaction in the mempool with this txid. Don't
|
||||
// try to submit this transaction to the mempool (since it'll be
|
||||
|
@ -102,7 +105,6 @@ TransactionError BroadcastTransaction(NodeContext& node, const CTransactionRef t
|
|||
callback_set = true;
|
||||
}
|
||||
}
|
||||
|
||||
} // cs_main
|
||||
|
||||
if (callback_set) {
|
||||
|
|
Loading…
Add table
Reference in a new issue