1
0
Fork 0
forked from lthn/blockchain

added get_assets_list command to daemon API

This commit is contained in:
cryptozoidberg 2024-04-20 00:05:31 +04:00
parent eae8fde294
commit ad66a6db30
No known key found for this signature in database
GPG key ID: 2E10CC61CAC8F36D
7 changed files with 68 additions and 4 deletions

View file

@ -3810,6 +3810,28 @@ bool blockchain_storage::get_asset_info(const crypto::public_key& asset_id, asse
return false;
}
//------------------------------------------------------------------
uint64_t blockchain_storage::get_assets(uint64_t offset, uint64_t count, std::list<asset_descriptor_with_id>& assets) const
{
CRITICAL_REGION_LOCAL(m_read_lock);
m_db_assets.enumerate_items([&](uint64_t i, const crypto::public_key& asset_id, const std::list<asset_descriptor_base>& asset_descriptor_history)
{
if (i < offset)
{
return true;
}
CHECK_AND_ASSERT_THROW_MES(asset_descriptor_history.size(), "asset_descriptor_history unexpectedly have 0 size");
assets.push_back(asset_descriptor_with_id());
static_cast<asset_descriptor_base&>(assets.back()) = asset_descriptor_history.back();
assets.back().asset_id = asset_id;
if (i + count > offset)
{
return false;
}
return true;
});
}
//------------------------------------------------------------------
uint64_t blockchain_storage::get_assets_count() const
{
CRITICAL_REGION_LOCAL(m_read_lock);

View file

@ -302,6 +302,7 @@ namespace currency
bool get_asset_history(const crypto::public_key& asset_id, std::list<asset_descriptor_operation>& result) const;
bool get_asset_info(const crypto::public_key& asset_id, asset_descriptor_base& info)const;
uint64_t get_assets_count() const;
uint64_t get_assets(uint64_t offset, uint64_t count, std::list<asset_descriptor_with_id>& assets) const;
bool check_tx_input(const transaction& tx, size_t in_index, const txin_to_key& txin, const crypto::hash& tx_prefix_hash, uint64_t& max_related_block_height, uint64_t& source_max_unlock_time_for_pos_coinbase)const;
bool check_tx_input(const transaction& tx, size_t in_index, const txin_multisig& txin, const crypto::hash& tx_prefix_hash, uint64_t& max_related_block_height)const;
bool check_tx_input(const transaction& tx, size_t in_index, const txin_htlc& txin, const crypto::hash& tx_prefix_hash, uint64_t& max_related_block_height)const;

@ -1 +1 @@
Subproject commit 3b816edf2da54c8df55e871a8005ac575ccb5dcd
Subproject commit 3b882866ddece56b624f7c326e317e69740fbe86

View file

@ -738,6 +738,18 @@ namespace currency
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_assets_list(const COMMAND_RPC_GET_ASSETS_LIST::request& req, COMMAND_RPC_GET_ASSETS_LIST::response& res, connection_context& cntx)
{
CHECK_CORE_READY();
if (!m_core.get_blockchain_storage().get_assets(req.offset, req.count, res.assets))
{
res.status = API_RETURN_CODE_NOT_FOUND;
return true;
}
res.status = API_RETURN_CODE_OK;
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_main_block_details(const COMMAND_RPC_GET_BLOCK_DETAILS::request& req, COMMAND_RPC_GET_BLOCK_DETAILS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx)
{
if (!m_core.get_blockchain_storage().get_main_block_rpc_details(req.id, res.block_details))

View file

@ -88,6 +88,7 @@ namespace currency
bool on_get_pool_info(const COMMAND_RPC_GET_POOL_INFO::request& req, COMMAND_RPC_GET_POOL_INFO::response& res, connection_context& cntx);
bool on_get_votes(const COMMAND_RPC_GET_VOTES::request& req, COMMAND_RPC_GET_VOTES::response& res, connection_context& cntx);
bool on_get_asset_info(const COMMAND_RPC_GET_ASSET_INFO::request& req, COMMAND_RPC_GET_ASSET_INFO::response& res, connection_context& cntx);
bool on_get_assets_list(const COMMAND_RPC_GET_ASSETS_LIST::request& req, COMMAND_RPC_GET_ASSETS_LIST::response& res, connection_context& cntx);
bool on_get_main_block_details(const COMMAND_RPC_GET_BLOCK_DETAILS::request& req, COMMAND_RPC_GET_BLOCK_DETAILS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
bool on_get_alt_block_details(const COMMAND_RPC_GET_BLOCK_DETAILS::request& req, COMMAND_RPC_GET_BLOCK_DETAILS::response& res, epee::json_rpc::error& error_resp, connection_context& cntx);
@ -150,7 +151,8 @@ namespace currency
MAP_JON_RPC ("getrandom_outs3", on_get_random_outs3, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS3)
MAP_JON_RPC ("get_votes", on_get_votes, COMMAND_RPC_GET_VOTES)
//assets api
MAP_JON_RPC ("get_asset_info", on_get_asset_info, COMMAND_RPC_GET_ASSET_INFO)
MAP_JON_RPC ("get_asset_info", on_get_asset_info, COMMAND_RPC_GET_ASSET_INFO)
MAP_JON_RPC ("get_assets_list", on_get_assets_list, COMMAND_RPC_GET_ASSETS_LIST)
MAP_JON_RPC_WE("get_main_block_details", on_get_main_block_details, COMMAND_RPC_GET_BLOCK_DETAILS)
MAP_JON_RPC_WE("get_alt_block_details", on_get_alt_block_details, COMMAND_RPC_GET_BLOCK_DETAILS)

View file

@ -135,6 +135,33 @@ namespace currency
};
};
struct COMMAND_RPC_GET_ASSETS_LIST
{
DOC_COMMAND("Return list of assets registered in Zano blockchain");
struct request
{
uint64_t offset = 0;
uint64_t count = 100;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(offset) DOC_DSCR("Offset for the item to start copying") DOC_EXMP(0) DOC_END
KV_SERIALIZE(count) DOC_DSCR("Number of items to recieve") DOC_EXMP(100) DOC_END
END_KV_SERIALIZE_MAP()
};
struct response
{
std::string status;
std::list<currency::asset_descriptor_with_id> assets;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(status) DOC_DSCR("Status code of operation, OK if success") DOC_EXMP(API_RETURN_CODE_OK) DOC_END
KV_SERIALIZE(assets) DOC_DSCR("List of assets registered in Zano blockchain") DOC_EXMP_AUTO(1) DOC_END
END_KV_SERIALIZE_MAP()
};
};
struct COMMAND_RPC_GET_HEIGHT
{
DOC_COMMAND("Return current blockchain height");

View file

@ -582,8 +582,8 @@ std::string wallets_manager::setup_wallet_rpc(const std::string& jwt_secret)
}
//we don't override command line JWT secret
if(!m_wallet_rpc_server.get_jwt_secret().size() )
m_wallet_rpc_server.set_jwt_secret(jwt_secret);
//if(!m_wallet_rpc_server.get_jwt_secret().size() )
m_wallet_rpc_server.set_jwt_secret(jwt_secret);
m_rpc_server.set_rpc_chain_handler(this);
#endif