mirror of
https://github.com/Retropex/bitcoin.git
synced 2025-05-17 05:30:43 +02:00
[style] Clean up BroadcastTransaction()
This commit is contained in:
parent
7282d4c036
commit
5a77abd4e6
@ -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)
|
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.
|
// BroadcastTransaction can be called by either sendrawtransaction RPC or the wallet.
|
||||||
// node.peerman is assigned both before chain clients and before RPC server is accepting calls,
|
// chainman, mempool and peerman are initialized before the RPC server and wallet are started
|
||||||
// and reset after chain clients and RPC sever are stopped. node.peerman should never be null here.
|
// and reset after the RPC sever and wallet are stopped.
|
||||||
assert(node.peerman);
|
assert(node.chainman);
|
||||||
assert(node.mempool);
|
assert(node.mempool);
|
||||||
|
assert(node.peerman);
|
||||||
|
|
||||||
std::promise<void> promise;
|
std::promise<void> promise;
|
||||||
uint256 txid = tx->GetHash();
|
uint256 txid = tx->GetHash();
|
||||||
uint256 wtxid = tx->GetWitnessHash();
|
uint256 wtxid = tx->GetWitnessHash();
|
||||||
bool callback_set = false;
|
bool callback_set = false;
|
||||||
|
|
||||||
{ // cs_main scope
|
{
|
||||||
assert(node.chainman);
|
|
||||||
LOCK(cs_main);
|
LOCK(cs_main);
|
||||||
|
|
||||||
// If the transaction is already confirmed in the chain, don't do anything
|
// If the transaction is already confirmed in the chain, don't do anything
|
||||||
// and return early.
|
// and return early.
|
||||||
CCoinsViewCache &view = node.chainman->ActiveChainstate().CoinsTip();
|
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.
|
// So if the output does exist, then this transaction exists in the chain.
|
||||||
if (!existingCoin.IsSpent()) return TransactionError::ALREADY_IN_CHAIN;
|
if (!existingCoin.IsSpent()) return TransactionError::ALREADY_IN_CHAIN;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto mempool_tx = node.mempool->get(txid); mempool_tx) {
|
if (auto mempool_tx = node.mempool->get(txid); mempool_tx) {
|
||||||
// There's already a transaction in the mempool with this txid. Don't
|
// 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
|
// 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;
|
callback_set = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // cs_main
|
} // cs_main
|
||||||
|
|
||||||
if (callback_set) {
|
if (callback_set) {
|
||||||
|
Loading…
Reference in New Issue
Block a user