mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-10 15:47:17 +02:00
rpc: Add abortprivatebroadcast
Co-authored-by: l0rinc <pap.lorinc@gmail.com>
This commit is contained in:
@@ -202,6 +202,61 @@ static RPCHelpMan getprivatebroadcastinfo()
|
||||
};
|
||||
}
|
||||
|
||||
static RPCHelpMan abortprivatebroadcast()
|
||||
{
|
||||
return RPCHelpMan{
|
||||
"abortprivatebroadcast",
|
||||
"Abort private broadcast attempts for a transaction currently being privately broadcast.\n"
|
||||
"The transaction will be removed from the private broadcast queue.\n",
|
||||
{
|
||||
{"id", RPCArg::Type::STR_HEX, RPCArg::Optional::NO, "A transaction identifier to abort. It will be matched against both txid and wtxid for all transactions in the private broadcast queue.\n"
|
||||
"If the provided id matches a txid that corresponds to multiple transactions with different wtxids, multiple transactions will be removed and returned."},
|
||||
},
|
||||
RPCResult{
|
||||
RPCResult::Type::OBJ, "", "",
|
||||
{
|
||||
{RPCResult::Type::ARR, "removed_transactions", "Transactions removed from the private broadcast queue",
|
||||
{
|
||||
{RPCResult::Type::OBJ, "", "",
|
||||
{
|
||||
{RPCResult::Type::STR_HEX, "txid", "The transaction hash in hex"},
|
||||
{RPCResult::Type::STR_HEX, "wtxid", "The transaction witness hash in hex"},
|
||||
{RPCResult::Type::STR_HEX, "hex", "The serialized, hex-encoded transaction data"},
|
||||
}},
|
||||
}},
|
||||
}
|
||||
},
|
||||
RPCExamples{
|
||||
HelpExampleCli("abortprivatebroadcast", "\"id\"")
|
||||
+ HelpExampleRpc("abortprivatebroadcast", "\"id\"")
|
||||
},
|
||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||
{
|
||||
const uint256 id{ParseHashV(self.Arg<UniValue>("id"), "id")};
|
||||
|
||||
const NodeContext& node{EnsureAnyNodeContext(request.context)};
|
||||
PeerManager& peerman{EnsurePeerman(node)};
|
||||
|
||||
const auto removed_txs{peerman.AbortPrivateBroadcast(id)};
|
||||
if (removed_txs.empty()) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in private broadcast queue. Check getprivatebroadcastinfo.");
|
||||
}
|
||||
|
||||
UniValue removed_transactions(UniValue::VARR);
|
||||
for (const auto& tx : removed_txs) {
|
||||
UniValue o(UniValue::VOBJ);
|
||||
o.pushKV("txid", tx->GetHash().ToString());
|
||||
o.pushKV("wtxid", tx->GetWitnessHash().ToString());
|
||||
o.pushKV("hex", EncodeHexTx(*tx));
|
||||
removed_transactions.push_back(std::move(o));
|
||||
}
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
ret.pushKV("removed_transactions", std::move(removed_transactions));
|
||||
return ret;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
static RPCHelpMan testmempoolaccept()
|
||||
{
|
||||
return RPCHelpMan{
|
||||
@@ -1395,6 +1450,7 @@ void RegisterMempoolRPCCommands(CRPCTable& t)
|
||||
static const CRPCCommand commands[]{
|
||||
{"rawtransactions", &sendrawtransaction},
|
||||
{"rawtransactions", &getprivatebroadcastinfo},
|
||||
{"rawtransactions", &abortprivatebroadcast},
|
||||
{"rawtransactions", &testmempoolaccept},
|
||||
{"blockchain", &getmempoolancestors},
|
||||
{"blockchain", &getmempooldescendants},
|
||||
|
||||
Reference in New Issue
Block a user