Add block api to retrive blocks in bulk.
This commit is contained in:
parent
48a02d72fb
commit
6165434265
2 changed files with 47 additions and 0 deletions
|
|
@ -79,6 +79,10 @@ namespace graphene { namespace app {
|
||||||
{
|
{
|
||||||
_database_api = std::make_shared< database_api >( std::ref( *_app.chain_database() ) );
|
_database_api = std::make_shared< database_api >( std::ref( *_app.chain_database() ) );
|
||||||
}
|
}
|
||||||
|
else if( api_name == "block_api" )
|
||||||
|
{
|
||||||
|
_block_api = std::make_shared< block_api >( std::ref( *_app.chain_database() ) );
|
||||||
|
}
|
||||||
else if( api_name == "network_broadcast_api" )
|
else if( api_name == "network_broadcast_api" )
|
||||||
{
|
{
|
||||||
_network_broadcast_api = std::make_shared< network_broadcast_api >( std::ref( _app ) );
|
_network_broadcast_api = std::make_shared< network_broadcast_api >( std::ref( _app ) );
|
||||||
|
|
@ -104,6 +108,20 @@ namespace graphene { namespace app {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// block_api
|
||||||
|
block_api::block_api(graphene::chain::database& db) : _db(db) { }
|
||||||
|
block_api::~block_api() { }
|
||||||
|
|
||||||
|
vector<optional<signed_block>> block_api::get_blocks(uint32_t block_num_from, uint32_t block_num_to)const
|
||||||
|
{
|
||||||
|
FC_ASSERT( block_num_to >= block_num_from );
|
||||||
|
vector<optional<signed_block>> res;
|
||||||
|
for(uint32_t block_num=block_num_from; block_num<=block_num_to; block_num++) {
|
||||||
|
res.push_back(_db.fetch_block_by_number(block_num));
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
network_broadcast_api::network_broadcast_api(application& a):_app(a)
|
network_broadcast_api::network_broadcast_api(application& a):_app(a)
|
||||||
{
|
{
|
||||||
_applied_block_connection = _app.chain_database()->applied_block.connect([this](const signed_block& b){ on_applied_block(b); });
|
_applied_block_connection = _app.chain_database()->applied_block.connect([this](const signed_block& b){ on_applied_block(b); });
|
||||||
|
|
@ -193,6 +211,12 @@ namespace graphene { namespace app {
|
||||||
return *_network_broadcast_api;
|
return *_network_broadcast_api;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fc::api<block_api> login_api::block()const
|
||||||
|
{
|
||||||
|
FC_ASSERT(_block_api);
|
||||||
|
return *_block_api;
|
||||||
|
}
|
||||||
|
|
||||||
fc::api<network_node_api> login_api::network_node()const
|
fc::api<network_node_api> login_api::network_node()const
|
||||||
{
|
{
|
||||||
FC_ASSERT(_network_node_api);
|
FC_ASSERT(_network_node_api);
|
||||||
|
|
|
||||||
|
|
@ -118,6 +118,22 @@ namespace graphene { namespace app {
|
||||||
application& _app;
|
application& _app;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Block api
|
||||||
|
*/
|
||||||
|
class block_api
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
block_api(graphene::chain::database& db);
|
||||||
|
~block_api();
|
||||||
|
|
||||||
|
vector<optional<signed_block>> get_blocks(uint32_t block_num_from, uint32_t block_num_to)const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
graphene::chain::database& _db;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The network_broadcast_api class allows broadcasting of transactions.
|
* @brief The network_broadcast_api class allows broadcasting of transactions.
|
||||||
*/
|
*/
|
||||||
|
|
@ -273,6 +289,8 @@ namespace graphene { namespace app {
|
||||||
* has sucessfully authenticated.
|
* has sucessfully authenticated.
|
||||||
*/
|
*/
|
||||||
bool login(const string& user, const string& password);
|
bool login(const string& user, const string& password);
|
||||||
|
/// @brief Retrieve the network block API
|
||||||
|
fc::api<block_api> block()const;
|
||||||
/// @brief Retrieve the network broadcast API
|
/// @brief Retrieve the network broadcast API
|
||||||
fc::api<network_broadcast_api> network_broadcast()const;
|
fc::api<network_broadcast_api> network_broadcast()const;
|
||||||
/// @brief Retrieve the database API
|
/// @brief Retrieve the database API
|
||||||
|
|
@ -291,6 +309,7 @@ namespace graphene { namespace app {
|
||||||
void enable_api( const string& api_name );
|
void enable_api( const string& api_name );
|
||||||
|
|
||||||
application& _app;
|
application& _app;
|
||||||
|
optional< fc::api<block_api> > _block_api;
|
||||||
optional< fc::api<database_api> > _database_api;
|
optional< fc::api<database_api> > _database_api;
|
||||||
optional< fc::api<network_broadcast_api> > _network_broadcast_api;
|
optional< fc::api<network_broadcast_api> > _network_broadcast_api;
|
||||||
optional< fc::api<network_node_api> > _network_node_api;
|
optional< fc::api<network_node_api> > _network_node_api;
|
||||||
|
|
@ -317,6 +336,9 @@ FC_API(graphene::app::history_api,
|
||||||
(get_market_history)
|
(get_market_history)
|
||||||
(get_market_history_buckets)
|
(get_market_history_buckets)
|
||||||
)
|
)
|
||||||
|
FC_API(graphene::app::block_api,
|
||||||
|
(get_blocks)
|
||||||
|
)
|
||||||
FC_API(graphene::app::network_broadcast_api,
|
FC_API(graphene::app::network_broadcast_api,
|
||||||
(broadcast_transaction)
|
(broadcast_transaction)
|
||||||
(broadcast_transaction_with_callback)
|
(broadcast_transaction_with_callback)
|
||||||
|
|
@ -343,6 +365,7 @@ FC_API(graphene::app::crypto_api,
|
||||||
)
|
)
|
||||||
FC_API(graphene::app::login_api,
|
FC_API(graphene::app::login_api,
|
||||||
(login)
|
(login)
|
||||||
|
(block)
|
||||||
(network_broadcast)
|
(network_broadcast)
|
||||||
(database)
|
(database)
|
||||||
(history)
|
(history)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue