Skip to content

Commit

Permalink
added get_block_header issue cryptonomex#262
Browse files Browse the repository at this point in the history
  • Loading branch information
oxarbitrage committed Apr 19, 2017
1 parent 342c8a2 commit 0aae0ea
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
19 changes: 19 additions & 0 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>

// Blocks and transactions
optional<block_header> get_block_header(uint32_t block_num)const;
map<uint32_t,block_header> get_block_header_batch(const vector<uint32_t> block_num)const;
optional<signed_block> get_block(uint32_t block_num)const;
processed_transaction get_transaction( uint32_t block_num, uint32_t trx_in_block )const;

Expand Down Expand Up @@ -362,6 +363,24 @@ optional<block_header> database_api_impl::get_block_header(uint32_t block_num) c
return *result;
return {};
}
map<uint32_t,block_header> database_api::get_block_header_batch(const vector<uint32_t> block_num)const
{
return my->get_block_header_batch( block_num );
}

map<uint32_t,block_header> database_api_impl::get_block_header_batch(const vector<uint32_t> block_num) const
{
map<uint32_t,block_header> results;
for (const uint32_t& i : block_num) {
auto result = _db.fetch_block_by_number(i);
if (result)
results[i] = *result;
else
results[i] = {};

}
return results;
}

optional<signed_block> database_api::get_block(uint32_t block_num)const
{
Expand Down
9 changes: 9 additions & 0 deletions libraries/app/include/graphene/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,14 @@ class database_api
*/
optional<block_header> get_block_header(uint32_t block_num)const;

/**
* @brief Retrieve multiple block header by block numbers
* @param block_num vector containing heights of the block whose header should be returned
* @return array of headers of the referenced blocks, or null if no matching block was found
*/
map<uint32_t,block_header> get_block_header_batch(const vector<uint32_t> block_num)const;


/**
* @brief Retrieve a full, signed block
* @param block_num Height of the block to be returned
Expand Down Expand Up @@ -588,6 +596,7 @@ FC_API(graphene::app::database_api,

// Blocks and transactions
(get_block_header)
(get_block_header_batch)
(get_block)
(get_transaction)
(get_recent_transaction_by_id)
Expand Down

0 comments on commit 0aae0ea

Please sign in to comment.