json serialization for rpc-relevant monero types

Structured {de-,}serialization methods for (many new) types
which are used for requests or responses in the RPC.

New types include RPC requests and responses, and structs which compose
types within those.

# Conflicts:
#	src/cryptonote_core/blockchain.cpp
This commit is contained in:
Thomas Winget 2017-09-05 12:20:27 -04:00
parent 5c1e08fe80
commit 77986023c3
No known key found for this signature in database
GPG key ID: 58131A160789E630
29 changed files with 4968 additions and 3 deletions

View file

@ -1574,7 +1574,7 @@ void Blockchain::add_out_to_get_random_outs(COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_A
uint64_t Blockchain::get_num_mature_outputs(uint64_t amount) const
{
auto num_outs = m_db->get_num_outputs(amount);
uint64_t num_outs = m_db->get_num_outputs(amount);
// ensure we don't include outputs that aren't yet eligible to be used
// outpouts are sorted by height
while (num_outs > 0)

View file

@ -790,6 +790,13 @@ namespace cryptonote
return BLOCKS_SYNCHRONIZING_DEFAULT_COUNT_PRE_V4;
}
//-----------------------------------------------------------------------------------------------
bool core::are_key_images_spent_in_pool(const std::vector<crypto::key_image>& key_im, std::vector<bool> &spent) const
{
spent.clear();
return m_mempool.check_for_key_images(key_im, spent);
}
//-----------------------------------------------------------------------------------------------
std::pair<uint64_t, uint64_t> core::get_coinbase_tx_sum(const uint64_t start_offset, const size_t count)
{
uint64_t emission_amount = 0;
@ -1175,6 +1182,11 @@ namespace cryptonote
return m_mempool.get_transactions_and_spent_keys_info(tx_infos, key_image_infos);
}
//-----------------------------------------------------------------------------------------------
bool core::get_pool_for_rpc(std::vector<cryptonote::rpc::tx_in_pool>& tx_infos, cryptonote::rpc::key_images_with_tx_hashes& key_image_infos) const
{
return m_mempool.get_pool_for_rpc(tx_infos, key_image_infos);
}
//-----------------------------------------------------------------------------------------------
bool core::get_short_chain_history(std::list<crypto::hash>& ids) const
{
return m_blockchain_storage.get_short_chain_history(ids);

View file

@ -462,6 +462,13 @@ namespace cryptonote
*/
bool get_pool_transactions_and_spent_keys_info(std::vector<tx_info>& tx_infos, std::vector<spent_key_image_info>& key_image_infos) const;
/**
* @copydoc tx_memory_pool::get_pool_for_rpc
*
* @note see tx_memory_pool::get_pool_for_rpc
*/
bool get_pool_for_rpc(std::vector<cryptonote::rpc::tx_in_pool>& tx_infos, cryptonote::rpc::key_images_with_tx_hashes& key_image_infos) const;
/**
* @copydoc tx_memory_pool::get_transactions_count
*
@ -707,6 +714,16 @@ namespace cryptonote
*/
bool are_key_images_spent(const std::vector<crypto::key_image>& key_im, std::vector<bool> &spent) const;
/**
* @brief check if multiple key images are spent in the transaction pool
*
* @param key_im list of key images to check
* @param spent return-by-reference result for each image checked
*
* @return true
*/
bool are_key_images_spent_in_pool(const std::vector<crypto::key_image>& key_im, std::vector<bool> &spent) const;
/**
* @brief get the number of blocks to sync in one go
*

View file

@ -684,6 +684,65 @@ namespace cryptonote
return true;
}
//---------------------------------------------------------------------------------
bool tx_memory_pool::get_pool_for_rpc(std::vector<cryptonote::rpc::tx_in_pool>& tx_infos, cryptonote::rpc::key_images_with_tx_hashes& key_image_infos) const
{
CRITICAL_REGION_LOCAL(m_transactions_lock);
CRITICAL_REGION_LOCAL1(m_blockchain);
m_blockchain.for_all_txpool_txes([&tx_infos, key_image_infos](const crypto::hash &txid, const txpool_tx_meta_t &meta, const cryptonote::blobdata *bd){
cryptonote::rpc::tx_in_pool txi;
txi.tx_hash = txid;
transaction tx;
if (!parse_and_validate_tx_from_blob(*bd, tx))
{
MERROR("Failed to parse tx from txpool");
// continue
return true;
}
txi.tx = tx;
txi.blob_size = meta.blob_size;
txi.fee = meta.fee;
txi.kept_by_block = meta.kept_by_block;
txi.max_used_block_height = meta.max_used_block_height;
txi.max_used_block_hash = meta.max_used_block_id;
txi.last_failed_block_height = meta.last_failed_height;
txi.last_failed_block_hash = meta.last_failed_id;
txi.receive_time = meta.receive_time;
txi.relayed = meta.relayed;
txi.last_relayed_time = meta.last_relayed_time;
txi.do_not_relay = meta.do_not_relay;
tx_infos.push_back(txi);
return true;
}, true);
for (const key_images_container::value_type& kee : m_spent_key_images) {
std::vector<crypto::hash> tx_hashes;
const std::unordered_set<crypto::hash>& kei_image_set = kee.second;
for (const crypto::hash& tx_id_hash : kei_image_set)
{
tx_hashes.push_back(tx_id_hash);
}
const crypto::key_image& k_image = kee.first;
key_image_infos[k_image] = tx_hashes;
}
return true;
}
//---------------------------------------------------------------------------------
bool tx_memory_pool::check_for_key_images(const std::vector<crypto::key_image>& key_images, std::vector<bool> spent) const
{
CRITICAL_REGION_LOCAL(m_transactions_lock);
CRITICAL_REGION_LOCAL1(m_blockchain);
spent.clear();
for (const auto& image : key_images)
{
spent.push_back(m_spent_key_images.find(image) == m_spent_key_images.end() ? false : true);
}
return true;
}
//---------------------------------------------------------------------------------
bool tx_memory_pool::get_transaction(const crypto::hash& id, cryptonote::blobdata& txblob) const
{
CRITICAL_REGION_LOCAL(m_transactions_lock);

View file

@ -46,6 +46,7 @@
#include "blockchain_db/blockchain_db.h"
#include "crypto/hash.h"
#include "rpc/core_rpc_server_commands_defs.h"
#include "rpc/message_data_structs.h"
namespace cryptonote
{
@ -268,6 +269,28 @@ namespace cryptonote
*/
bool get_transactions_and_spent_keys_info(std::vector<tx_info>& tx_infos, std::vector<spent_key_image_info>& key_image_infos) const;
/**
* @brief get information about all transactions and key images in the pool
*
* see documentation on tx_in_pool and key_images_with_tx_hashes for more details
*
* @param tx_infos [out] the transactions' information
* @param key_image_infos [out] the spent key images' information
*
* @return true
*/
bool get_pool_for_rpc(std::vector<cryptonote::rpc::tx_in_pool>& tx_infos, cryptonote::rpc::key_images_with_tx_hashes& key_image_infos) const;
/**
* @brief check for presence of key images in the pool
*
* @param key_images [in] vector of key images to check
* @param spent [out] vector of bool to return
*
* @return true
*/
bool check_for_key_images(const std::vector<crypto::key_image>& key_images, std::vector<bool> spent) const;
/**
* @brief get a specific transaction from the pool
*