diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index e66797cd88bb1e..b80c47d10c48eb 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -115,6 +115,7 @@ static const CRPCConvertParam vRPCConvertParams[] = { "gettransaction", 1, "include_watchonly" }, { "gettransaction", 2, "verbose" }, { "getrawtransaction", 1, "verbose" }, + { "getrawislocks", 0, "txids" }, { "getrawtransactionmulti", 0, "transactions" }, { "getrawtransactionmulti", 1, "verbose" }, { "gettxchainlocks", 0, "txids" }, diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index 4fbbe10a2a037c..7b243a8a26f2e0 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -299,6 +299,7 @@ static RPCHelpMan getrawtransactionmulti() { {"verbose", RPCArg::Type::BOOL, RPCArg::Default{false}, "If false, return a string, otherwise return a json object"}, }, + // TODO: replace RPCResults to proper annotation RPCResults{}, RPCExamples{ HelpExampleCli("getrawtransactionmulti", @@ -365,6 +366,59 @@ static RPCHelpMan getrawtransactionmulti() { }; } +static RPCHelpMan getrawislocks() +{ + return RPCHelpMan{"getrawislocks", + "\nReturns the raw InstantSend lock data for each txids. Returns Null if there is no known IS yet.", + { + {"txids", RPCArg::Type::ARR, RPCArg::Optional::NO, "The transaction ids (no more than 100)", + { + {"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "A transaction hash"}, + }, + }, + }, + RPCResult{ + RPCResult::Type::ARR, "", "Response is an array with the same size as the input txids", + { + RPCResult{"if InstantSend Lock is known for specified txid", + RPCResult::Type::STR, "data", "The serialized, hex-encoded data for 'txid'" + }, + RPCResult{"if no InstantSend Lock is known for specified txid", + RPCResult::Type::STR, "data", "Just 'None' string" + }, + }}, + RPCExamples{ + HelpExampleCli("getrawislocks", "'[\"txid\",...]'") + + HelpExampleRpc("getrawislocks", "'[\"txid\",...]'") + }, + [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue +{ + const NodeContext& node = EnsureAnyNodeContext(request.context); + + UniValue result_arr(UniValue::VARR); + UniValue txids = request.params[0].get_array(); + if (txids.size() > 100) { + throw JSONRPCError(RPC_INVALID_PARAMETER, "Up to 100 txids only"); + } + + const LLMQContext& llmq_ctx = EnsureLLMQContext(node); + for (const auto idx : irange::range(txids.size())) { + const uint256 txid(ParseHashV(txids[idx], "txid")); + + if (const llmq::CInstantSendLockPtr islock = llmq_ctx.isman->GetInstantSendLockByTxid(txid); islock != nullptr) { + CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION); + ssTx << *islock; + result_arr.push_back(HexStr(ssTx)); + } else { + result_arr.push_back("None"); + } + } + return result_arr; + +}, + }; +} + static RPCHelpMan gettxchainlocks() { return RPCHelpMan{ @@ -1927,6 +1981,7 @@ static const CRPCCommand commands[] = { "rawtransactions", &getassetunlockstatuses, }, { "rawtransactions", &getrawtransaction, }, { "rawtransactions", &getrawtransactionmulti, }, + { "rawtransactions", &getrawislocks, }, { "rawtransactions", &gettxchainlocks, }, { "rawtransactions", &createrawtransaction, }, { "rawtransactions", &decoderawtransaction, }, diff --git a/test/functional/interface_zmq_dash.py b/test/functional/interface_zmq_dash.py index b1f64e445da49a..c5da66d510c890 100755 --- a/test/functional/interface_zmq_dash.py +++ b/test/functional/interface_zmq_dash.py @@ -285,6 +285,7 @@ def test_instantsend_publishers(self): # Create two raw TXs, they will conflict with each other rpc_raw_tx_1 = self.create_raw_tx(self.nodes[0], self.nodes[0], 1, 1, 100) rpc_raw_tx_2 = self.create_raw_tx(self.nodes[0], self.nodes[0], 1, 1, 100) + assert_equal(['None'], self.nodes[0].getrawislocks([rpc_raw_tx_1['txid']])) # Send the first transaction and wait for the InstantLock rpc_raw_tx_1_hash = self.nodes[0].sendrawtransaction(rpc_raw_tx_1['hex']) self.wait_for_instantlock(rpc_raw_tx_1_hash, self.nodes[0]) @@ -304,6 +305,7 @@ def test_instantsend_publishers(self): assert_equal(zmq_tx_lock_tx.hash, rpc_raw_tx_1['txid']) zmq_tx_lock = msg_isdlock() zmq_tx_lock.deserialize(zmq_tx_lock_sig_stream) + assert_equal([zmq_tx_lock.serialize().hex()], self.nodes[0].getrawislocks([rpc_raw_tx_1['txid']])) assert_equal(uint256_to_string(zmq_tx_lock.txid), rpc_raw_tx_1['txid']) # Try to send the second transaction. This must throw an RPC error because it conflicts with rpc_raw_tx_1 # which already got the InstantSend lock.