Skip to content

Commit

Permalink
suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
ogabrielides committed Dec 19, 2023
1 parent 6e16d19 commit 08ad2cb
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 37 deletions.
65 changes: 32 additions & 33 deletions src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,10 @@ static UniValue gettxchainlocks(const JSONRPCRequest& request)
return result_arr;
}

static UniValue getassetunlockchainlocks(const JSONRPCRequest& request)
static void getassetunlockstatuses_help(const JSONRPCRequest& request)
{
RPCHelpMan{
"getassetunlockchainlocks",
"getassetunlockstatuses",
"\nReturns the status of given Asset Unlock indexes.\n",
{
{"indexes", RPCArg::Type::ARR, RPCArg::Optional::NO, "The Asset Unlock indexes (no more than 100)",
Expand All @@ -356,15 +356,20 @@ static UniValue getassetunlockchainlocks(const JSONRPCRequest& request)
{
{RPCResult::Type::OBJ, "xxxx", "Asset Unlock index.",
{
{RPCResult::Type::STR, "", "Status of the Asset Unlock index: {chainlocked|mempooled|null}"},
{RPCResult::Type::STR, "", "Status of the Asset Unlock index: {chainlocked|mined|mempooled|null}"},
}},
}
},
RPCExamples{
HelpExampleCli("getassetunlockchainlocks", "'[\"myindex\",...]'")
+ HelpExampleRpc("getassetunlockchainlocks", "[\"myindex\",...]")
HelpExampleCli("getassetunlockstatuses", "'[\"myindex\",...]'")
+ HelpExampleRpc("getassetunlockstatuses", "[\"myindex\",...]")
},
}.Check(request);
}

static UniValue getassetunlockstatuses(const JSONRPCRequest& request)
{
getassetunlockstatuses_help(request);

const NodeContext& node = EnsureAnyNodeContext(request.context);
const CTxMemPool& mempool = EnsureMemPool(node);
Expand All @@ -381,19 +386,14 @@ static UniValue getassetunlockchainlocks(const JSONRPCRequest& request)
g_txindex->BlockUntilSyncedToCurrentChain();
}

CBlockIndex* pTipBlockIndex{nullptr};
{
LOCK(cs_main);
pTipBlockIndex = chainman.ActiveChain().Tip();
}
CBlockIndex* pTipBlockIndex= WITH_LOCK(cs_main, return chainman.ActiveChain().Tip());

CBlockIndex* pBlockIndex{nullptr};
bool chainlock_info = false;
llmq::CChainLockSig bestclsig = llmq_ctx.clhandler->GetBestChainLock();
if (bestclsig.IsNull()) {
// If no CL info is available, try to use CbTx CL information
auto cbtx_best_cl = GetNonNullCoinbaseChainlock(pTipBlockIndex);
if (cbtx_best_cl.has_value()) {
if (auto cbtx_best_cl = GetNonNullCoinbaseChainlock(pTipBlockIndex); cbtx_best_cl.has_value()) {
pBlockIndex = pTipBlockIndex->GetAncestor(pTipBlockIndex->nHeight - cbtx_best_cl->second - 1);
chainlock_info = true;
}
Expand Down Expand Up @@ -425,29 +425,28 @@ static UniValue getassetunlockchainlocks(const JSONRPCRequest& request)
result_arr.push_back(obj);
continue;
}
{
LOCK(mempool.cs);
bool is_mempooled = false;
for (const CTxMemPoolEntry& e : mempool.mapTx) {
if (e.GetTx().nType == CAssetUnlockPayload::SPECIALTX_TYPE) {
CAssetUnlockPayload assetUnlockTx;
if (!GetTxPayload(e.GetTx(), assetUnlockTx)) {
throw JSONRPCError(RPC_TRANSACTION_ERROR, "bad-assetunlocktx-payload");
}
if (index == assetUnlockTx.getIndex()) {
is_mempooled = true;
break;
}

LOCK(mempool.cs);
bool is_mempooled = false;
for (const CTxMemPoolEntry& e : mempool.mapTx) {
if (e.GetTx().nType == CAssetUnlockPayload::SPECIALTX_TYPE) {
CAssetUnlockPayload assetUnlockTx;
if (!GetTxPayload(e.GetTx(), assetUnlockTx)) {
throw JSONRPCError(RPC_TRANSACTION_ERROR, "bad-assetunlocktx-payload");
}
if (index == assetUnlockTx.getIndex()) {
is_mempooled = true;
break;
}
}
if (is_mempooled)
obj.pushKV(str_indexes[i].get_str(), "mempooled");
else {
UniValue jnull(UniValue::VNULL);
obj.pushKV(str_indexes[i].get_str(), jnull);
}
result_arr.push_back(obj);
}
if (is_mempooled)
obj.pushKV(str_indexes[i].get_str(), "mempooled");
else {
UniValue jnull(UniValue::VNULL);
obj.pushKV(str_indexes[i].get_str(), jnull);
}
result_arr.push_back(obj);
}

return result_arr;
Expand Down Expand Up @@ -1874,7 +1873,7 @@ void RegisterRawTransactionRPCCommands(CRPCTable &t)
static const CRPCCommand commands[] =
{ // category name actor (function) argNames
// --------------------- ------------------------ ----------------------- ----------
{ "rawtransactions", "getassetunlockchainlocks", &getassetunlockchainlocks, {"indexes"} },
{ "rawtransactions", "getassetunlockstatuses", &getassetunlockstatuses, {"indexes"} },
{ "rawtransactions", "getrawtransaction", &getrawtransaction, {"txid","verbose","blockhash"} },
{ "rawtransactions", "gettxchainlocks", &gettxchainlocks, {"txids"} },
{ "rawtransactions", "createrawtransaction", &createrawtransaction, {"inputs","outputs","locktime"} },
Expand Down
2 changes: 1 addition & 1 deletion src/rpc/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ std::string CRPCTable::help(const std::string& strCommand, const std::string& st
void CRPCTable::InitPlatformRestrictions()
{
mapPlatformRestrictions = {
{"getassetunlockchainlocks", {}},
{"getassetunlockstatuses", {}},
{"getbestblockhash", {}},
{"getblockhash", {}},
{"getblockcount", {}},
Expand Down
4 changes: 2 additions & 2 deletions test/functional/feature_asset_locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ def run_test(self):
txid = self.send_tx(asset_unlock_tx)
assert "assetUnlockTx" in node.getrawtransaction(txid, 1)

indexes_statuses = self.nodes[0].getassetunlockchainlocks(["101", "102", "300"])
indexes_statuses = self.nodes[0].getassetunlockstatuses(["101", "102", "300"])
self.log.info(f'{indexes_statuses}')
assert any('101' in d for d in indexes_statuses)
assert_equal(next((d['101'] for d in indexes_statuses if '101' in d), None), "mempooled")
Expand Down Expand Up @@ -512,7 +512,7 @@ def run_test(self):
node.generate(1)
self.sync_all()

indexes_statuses = self.nodes[0].getassetunlockchainlocks(["101", "102", "103"])
indexes_statuses = self.nodes[0].getassetunlockstatuses(["101", "102", "103"])
self.log.info(f'{indexes_statuses}')
assert any('101' in d for d in indexes_statuses)
assert_equal(next((d['101'] for d in indexes_statuses if '101' in d), None), "mined")
Expand Down
2 changes: 1 addition & 1 deletion test/functional/rpc_platform_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_command(method, params, auth, expexted_status, should_not_match=False):
assert_equal(resp.status, expexted_status)
conn.close()

whitelisted = ["getassetunlockchainlocks",
whitelisted = ["getassetunlockstatuses",
"getbestblockhash",
"getblockhash",
"getblockcount",
Expand Down

0 comments on commit 08ad2cb

Please sign in to comment.