Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpc): Asset Unlock status by index #5776

Merged
14 changes: 8 additions & 6 deletions src/rpc/rawtransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,10 @@ static void getassetunlockstatuses_help(const JSONRPCRequest& request)
RPCResult{
RPCResult::Type::ARR, "", "Response is an array with the same size as the input txids",
{
{RPCResult::Type::OBJ, "xxxx", "Asset Unlock index.",
{RPCResult::Type::OBJ, "", "",
{
{RPCResult::Type::STR, "", "Status of the Asset Unlock index: {chainlocked|mined|mempooled|null}"},
{RPCResult::Type::NUM, "index", "The Asset Unlock index"},
{RPCResult::Type::STR, "status", "Status of the Asset Unlock index: {chainlocked|mined|mempooled|null}"},
}},
}
},
Expand Down Expand Up @@ -413,15 +414,16 @@ static UniValue getassetunlockstatuses(const JSONRPCRequest& request)
if (!ParseUInt64(str_indexes[i].get_str(), &index)) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid index");
}
obj.pushKV("index", index);
if (poolCL.has_value() && poolCL->indexes.Contains(index)) {
obj.pushKV(str_indexes[i].get_str(), "chainlocked");
obj.pushKV("status", "chainlocked");
result_arr.push_back(obj);
continue;
}
if (pTipBlockIndex != pBlockIndexBestCL) {
if (!poolOnTip.has_value()) poolOnTip = node.creditPoolManager->GetCreditPool(pTipBlockIndex, Params().GetConsensus());
if (poolOnTip->indexes.Contains(index)) {
obj.pushKV(str_indexes[i].get_str(), "mined");
obj.pushKV("status", "mined");
result_arr.push_back(obj);
continue;
}
Expand All @@ -441,10 +443,10 @@ static UniValue getassetunlockstatuses(const JSONRPCRequest& request)
}
}
if (is_mempooled)
obj.pushKV(str_indexes[i].get_str(), "mempooled");
obj.pushKV("status", "mempooled");
else {
UniValue jnull(UniValue::VNULL);
obj.pushKV(str_indexes[i].get_str(), jnull);
obj.pushKV("status", jnull);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: obj.pushKV("status", UniValue{}); does same, doesn't it?

}
result_arr.push_back(obj);
}
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 @@ -332,7 +332,7 @@ def run_test(self):
assert "assetUnlockTx" in node.getrawtransaction(txid, 1)

indexes_statuses = self.nodes[0].getassetunlockstatuses(["101", "102", "300"])
assert_equal([{'101': 'mempooled'}, {'102': None}, {'300': None}], indexes_statuses)
assert_equal([{'index': 101, 'status': 'mempooled'}, {'index': 102, 'status': None}, {'index': 300, 'status': None}], indexes_statuses)

self.mempool_size += 1
self.check_mempool_size()
Expand Down Expand Up @@ -507,7 +507,7 @@ def run_test(self):
self.sync_all()

indexes_statuses = self.nodes[0].getassetunlockstatuses(["101", "102", "103"])
assert_equal([{'101': 'mined'}, {'102': 'mined'}, {'103': None}], indexes_statuses)
assert_equal([{'index': 101, 'status': 'mined'}, {'index': 102, 'status': 'mined'}, {'index': 103, 'status': None}], indexes_statuses)

self.log.info("generate many blocks to be sure that mempool is empty after expiring txes...")
self.slowly_generate_batch(60)
Expand Down
Loading