aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2017-01-15 20:32:57 -0500
committerRiccardo Spagni <ric@spagni.net>2017-01-15 20:32:57 -0500
commitab69d5b3670cc21a10aab9ad16919afdcc80fdba (patch)
treef0c009b9b943a570ee505f2881be2243c68e16cd /src/rpc
parentMerge pull request #1522 (diff)
parentspecify restore height by YYYY-MM-DD format (diff)
downloadmonero-ab69d5b3670cc21a10aab9ad16919afdcc80fdba.tar.xz
Merge pull request #1569
16b8b66a specify restore height by YYYY-MM-DD format (kenshi84)
Diffstat (limited to 'src/rpc')
-rw-r--r--src/rpc/core_rpc_server.cpp30
-rw-r--r--src/rpc/core_rpc_server.h2
-rw-r--r--src/rpc/core_rpc_server_commands_defs.h24
3 files changed, 55 insertions, 1 deletions
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp
index 29c61eca2..1c5c321da 100644
--- a/src/rpc/core_rpc_server.cpp
+++ b/src/rpc/core_rpc_server.cpp
@@ -190,6 +190,36 @@ namespace cryptonote
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
+ bool core_rpc_server::on_get_blocks_by_height(const COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::request& req, COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::response& res)
+ {
+ CHECK_CORE_BUSY();
+ res.status = "Failed";
+ res.blocks.clear();
+ res.blocks.reserve(req.heights.size());
+ for (uint64_t height : req.heights)
+ {
+ block blk;
+ try
+ {
+ blk = m_core.get_blockchain_storage().get_db().get_block_from_height(height);
+ }
+ catch (...)
+ {
+ res.status = "Error retrieving block at height " + height;
+ return true;
+ }
+ std::list<transaction> txs;
+ std::list<crypto::hash> missed_txs;
+ m_core.get_transactions(blk.tx_hashes, txs, missed_txs);
+ res.blocks.resize(res.blocks.size() + 1);
+ res.blocks.back().block = block_to_blob(blk);
+ for (auto& tx : txs)
+ res.blocks.back().txs.push_back(tx_to_blob(tx));
+ }
+ res.status = CORE_RPC_STATUS_OK;
+ return true;
+ }
+ //------------------------------------------------------------------------------------------------------------------------------
bool core_rpc_server::on_get_hashes(const COMMAND_RPC_GET_HASHES_FAST::request& req, COMMAND_RPC_GET_HASHES_FAST::response& res)
{
CHECK_CORE_BUSY();
diff --git a/src/rpc/core_rpc_server.h b/src/rpc/core_rpc_server.h
index 9d6ff9740..84871e8bb 100644
--- a/src/rpc/core_rpc_server.h
+++ b/src/rpc/core_rpc_server.h
@@ -76,6 +76,7 @@ namespace cryptonote
BEGIN_URI_MAP2()
MAP_URI_AUTO_JON2("/getheight", on_get_height, COMMAND_RPC_GET_HEIGHT)
MAP_URI_AUTO_BIN2("/getblocks.bin", on_get_blocks, COMMAND_RPC_GET_BLOCKS_FAST)
+ MAP_URI_AUTO_BIN2("/getblocks_by_height.bin", on_get_blocks_by_height, COMMAND_RPC_GET_BLOCKS_BY_HEIGHT)
MAP_URI_AUTO_BIN2("/gethashes.bin", on_get_hashes, COMMAND_RPC_GET_HASHES_FAST)
MAP_URI_AUTO_BIN2("/get_o_indexes.bin", on_get_indexes, COMMAND_RPC_GET_TX_GLOBAL_OUTPUTS_INDEXES)
MAP_URI_AUTO_BIN2("/getrandom_outs.bin", on_get_random_outs, COMMAND_RPC_GET_RANDOM_OUTPUTS_FOR_AMOUNTS)
@@ -125,6 +126,7 @@ namespace cryptonote
bool on_get_height(const COMMAND_RPC_GET_HEIGHT::request& req, COMMAND_RPC_GET_HEIGHT::response& res);
bool on_get_blocks(const COMMAND_RPC_GET_BLOCKS_FAST::request& req, COMMAND_RPC_GET_BLOCKS_FAST::response& res);
+ bool on_get_blocks_by_height(const COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::request& req, COMMAND_RPC_GET_BLOCKS_BY_HEIGHT::response& res);
bool on_get_hashes(const COMMAND_RPC_GET_HASHES_FAST::request& req, COMMAND_RPC_GET_HASHES_FAST::response& res);
bool on_get_transactions(const COMMAND_RPC_GET_TRANSACTIONS::request& req, COMMAND_RPC_GET_TRANSACTIONS::response& res);
bool on_is_key_image_spent(const COMMAND_RPC_IS_KEY_IMAGE_SPENT::request& req, COMMAND_RPC_IS_KEY_IMAGE_SPENT::response& res);
diff --git a/src/rpc/core_rpc_server_commands_defs.h b/src/rpc/core_rpc_server_commands_defs.h
index b3aa8d901..0fc230d11 100644
--- a/src/rpc/core_rpc_server_commands_defs.h
+++ b/src/rpc/core_rpc_server_commands_defs.h
@@ -49,7 +49,7 @@ namespace cryptonote
// advance which version they will stop working with
// Don't go over 32767 for any of these
#define CORE_RPC_VERSION_MAJOR 1
-#define CORE_RPC_VERSION_MINOR 5
+#define CORE_RPC_VERSION_MINOR 6
#define MAKE_CORE_RPC_VERSION(major,minor) (((major)<<16)|(minor))
#define CORE_RPC_VERSION MAKE_CORE_RPC_VERSION(CORE_RPC_VERSION_MAJOR, CORE_RPC_VERSION_MINOR)
@@ -122,6 +122,28 @@ namespace cryptonote
};
};
+ struct COMMAND_RPC_GET_BLOCKS_BY_HEIGHT
+ {
+ struct request
+ {
+ std::vector<uint64_t> heights;
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(heights)
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct response
+ {
+ std::vector<block_complete_entry> blocks;
+ std::string status;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(blocks)
+ KV_SERIALIZE(status)
+ END_KV_SERIALIZE_MAP()
+ };
+ };
+
struct COMMAND_RPC_GET_HASHES_FAST
{