Skip to content

Commit

Permalink
feat: getrawislock ability to return JSON with verbose=1
Browse files Browse the repository at this point in the history
  • Loading branch information
knst committed Jan 9, 2025
1 parent 97a3d83 commit 331da10
Showing 1 changed file with 45 additions and 4 deletions.
49 changes: 45 additions & 4 deletions src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,13 +376,30 @@ static RPCHelpMan getrawislocks()
{"txid", RPCArg::Type::STR_HEX, RPCArg::Optional::OMITTED, "A transaction hash"},
},
},
{"verbose", RPCArg::Type::NUM, RPCArg::Default{1}, "0 for hex-encoded data, 1 for a json object"},
},
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{"for verbose = 0 if InstantSend Lock is known for specified txid",
RPCResult::Type::STR, "data", "The serialized, hex-encoded data for 'txid'"
},
RPCResult{"for verbose = 1 if InstantSend Lock is known for specified txid",
RPCResult::Type::OBJ, "", "",
{
{RPCResult::Type::STR_HEX, "txid", "The transaction id"},
{RPCResult::Type::ARR, "inputs", "The inputs",
{
{"", RPCArg::Type::OBJ, RPCArg::Optional::OMITTED, "",
{
{RPCResult::Type::STR_HEX, "txid", "The transaction id"},
{RPCResult::Type::NUM, "vout", "The output number"},
},
},
},
{RPCResult::Type::STR_HEX, "cycleHash", "The Cycle Hash"},
{RPCResult::Type::STR_HEX, "signature", "The InstantSend's BLS signature"},
}},
RPCResult{"if no InstantSend Lock is known for specified txid",
RPCResult::Type::STR, "data", "Just 'None' string"
},
Expand All @@ -401,14 +418,38 @@ static RPCHelpMan getrawislocks()
throw JSONRPCError(RPC_INVALID_PARAMETER, "Up to 100 txids only");
}

int verbose = 1;
if (!request.params[0].isNull()) {
if (request.params[0].isBool()) {
verbose = request.params[0].get_bool() ? 1 : 0;
} else {
verbose = request.params[0].get_int();
}
}

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));
if (verbose == 1) {
UniValue objIS;
objIS.pushKV("txid", islock->txid.ToString());
UniValue outputs;
for (const auto out : islock->inputs) {
UniValue outpoint;
outpoint.pushKV("txid", out.hash.ToString());
outpoint.pushKV("vout", static_cast<int64_t>(out.n));
outputs.push_back(outpoint);
}
objIS.pushKV("cycleHash", islock->cycleHash.ToString());
objIS.pushKV("sig", islock->sig.ToString());
result_arr.push_back(objIS);
} else {
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
ssTx << *islock;
result_arr.push_back(HexStr(ssTx));
}
} else {
result_arr.push_back("None");
}
Expand Down

0 comments on commit 331da10

Please sign in to comment.