feat: implement new RPC getrawbestchainlock

This commit is contained in:
Konstantin Akimov 2024-12-06 16:50:24 +07:00
parent 085b5fd00d
commit a4256c9261
No known key found for this signature in database
GPG Key ID: 2176C4A5D01EA524
2 changed files with 33 additions and 0 deletions

View File

@ -275,6 +275,37 @@ static RPCHelpMan getbestchainlock()
}; };
} }
static RPCHelpMan getrawbestchainlock()
{
return RPCHelpMan{"getrawbestchainlock",
"\nReturns the raw best ChainLock. Throws an error if there is no known ChainLock yet.",
{},
RPCResult{
RPCResult::Type::STR, "data", "The serialized, hex-encoded data for best ChainLock"
},
RPCExamples{
HelpExampleCli("getrawbestchainlock", "")
+ HelpExampleRpc("getrawbestchainlock", "")
},
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
{
UniValue result(UniValue::VOBJ);
const NodeContext& node = EnsureAnyNodeContext(request.context);
LLMQContext& llmq_ctx = EnsureLLMQContext(node);
llmq::CChainLockSig clsig = llmq_ctx.clhandler->GetBestChainLock();
if (clsig.IsNull()) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Unable to find any ChainLock");
}
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
ssTx << clsig;
return HexStr(ssTx);
},
};
}
void RPCNotifyBlockChange(const CBlockIndex* pindex) void RPCNotifyBlockChange(const CBlockIndex* pindex)
{ {
if(pindex) { if(pindex) {
@ -3106,6 +3137,7 @@ static const CRPCCommand commands[] =
{ "blockchain", &getblockstats, }, { "blockchain", &getblockstats, },
{ "blockchain", &getbestblockhash, }, { "blockchain", &getbestblockhash, },
{ "blockchain", &getbestchainlock, }, { "blockchain", &getbestchainlock, },
{ "blockchain", &getrawbestchainlock, },
{ "blockchain", &getblockcount, }, { "blockchain", &getblockcount, },
{ "blockchain", &getblock, }, { "blockchain", &getblock, },
{ "blockchain", &getblockfrompeer, }, { "blockchain", &getblockfrompeer, },

View File

@ -263,6 +263,7 @@ class DashZMQTest (DashTestFramework):
assert_equal(uint256_to_string(zmq_chain_lock.blockHash), rpc_chain_lock_hash) assert_equal(uint256_to_string(zmq_chain_lock.blockHash), rpc_chain_lock_hash)
assert_equal(zmq_chain_locked_block.hash, rpc_chain_lock_hash) assert_equal(zmq_chain_locked_block.hash, rpc_chain_lock_hash)
assert_equal(zmq_chain_lock.sig.hex(), rpc_best_chain_lock_sig) assert_equal(zmq_chain_lock.sig.hex(), rpc_best_chain_lock_sig)
assert_equal(zmq_chain_lock.serialize().hex(), self.nodes[0].getrawbestchainlock())
# Unsubscribe from ChainLock messages # Unsubscribe from ChainLock messages
self.unsubscribe(chain_lock_publishers) self.unsubscribe(chain_lock_publishers)