Skip to content

Commit

Permalink
Merge pull request #649 from arhag/get-ops-in-block
Browse files Browse the repository at this point in the history
Add get_ops_in_block method to database_api
  • Loading branch information
Michael Vandeberg committed Dec 14, 2016
2 parents da2e0f7 + 92b496b commit 45e1152
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
26 changes: 26 additions & 0 deletions libraries/app/database_api.cpp
Expand Up @@ -39,6 +39,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;
optional<signed_block> get_block(uint32_t block_num)const;
vector<applied_operation> get_ops_in_block(uint32_t block_num, bool only_virtual)const;

// Globals
fc::variant_object get_config()const;
Expand Down Expand Up @@ -249,6 +250,31 @@ optional<signed_block> database_api_impl::get_block(uint32_t block_num)const
return _db.fetch_block_by_number(block_num);
}

vector<applied_operation> database_api::get_ops_in_block(uint32_t block_num, bool only_virtual)const
{
return my->_db.with_read_lock( [&]()
{
return my->get_ops_in_block( block_num, only_virtual );
});
}

vector<applied_operation> database_api_impl::get_ops_in_block(uint32_t block_num, bool only_virtual)const
{
const auto& idx = _db.get_index< operation_index >().indices().get< by_location >();
auto itr = idx.lower_bound( block_num );
vector<applied_operation> result;
applied_operation temp;
while( itr != idx.end() && itr->block == block_num )
{
temp = *itr;
if( !only_virtual || is_virtual_operation(temp.op) )
result.push_back(temp);
++itr;
}
return result;
}


//////////////////////////////////////////////////////////////////////
// //
// Globals //
Expand Down
1 change: 1 addition & 0 deletions libraries/app/impacted.cpp
Expand Up @@ -43,6 +43,7 @@ struct get_impacted_account_visitor
template<typename T>
void operator()( const T& op )
{
op.get_required_posting_authorities( _impacted );
op.get_required_active_authorities( _impacted );
op.get_required_owner_authorities( _impacted );
}
Expand Down
9 changes: 9 additions & 0 deletions libraries/app/include/steemit/app/database_api.hpp
Expand Up @@ -154,6 +154,14 @@ class database_api
*/
optional<signed_block> get_block(uint32_t block_num)const;

/**
* @brief Get sequence of operations included/generated within a particular block
* @param block_num Height of the block whose generated virtual operations should be returned
* @param only_virtual Whether to only include virtual operations in returned results (default: true)
* @return sequence of operations included/generated within the block
*/
vector<applied_operation> get_ops_in_block(uint32_t block_num, bool only_virtual = true)const;

/////////////
// Globals //
/////////////
Expand Down Expand Up @@ -462,6 +470,7 @@ FC_API(steemit::app::database_api,
// Blocks and transactions
(get_block_header)
(get_block)
(get_ops_in_block)
(get_state)
(get_trending_categories)
(get_best_categories)
Expand Down
8 changes: 8 additions & 0 deletions libraries/wallet/include/steemit/wallet/wallet.hpp
Expand Up @@ -128,6 +128,13 @@ class wallet_api
*/
optional<signed_block_with_info> get_block( uint32_t num );

/** Returns sequence of operations included/generated in a specified block
*
* @param block_num Block height of specified block
* @param only_virtual Whether to only return virtual operations
*/
vector<applied_operation> get_ops_in_block( uint32_t block_num, bool only_virtual = true );

/** Return the current price feed history
*
* @returns Price feed history data on the blockchain
Expand Down Expand Up @@ -958,6 +965,7 @@ FC_API( steemit::wallet::wallet_api,
(get_witness)
(get_account)
(get_block)
(get_ops_in_block)
(get_feed_history)
(get_conversion_requests)
(get_account_history)
Expand Down
5 changes: 5 additions & 0 deletions libraries/wallet/wallet.cpp
Expand Up @@ -989,6 +989,11 @@ optional<signed_block_with_info> wallet_api::get_block(uint32_t num)
return my->_remote_db->get_block(num);
}

vector<applied_operation> wallet_api::get_ops_in_block(uint32_t block_num, bool only_virtual)
{
return my->_remote_db->get_ops_in_block(block_num, only_virtual);
}

vector<account_api_obj> wallet_api::list_my_accounts()
{
FC_ASSERT( !is_locked(), "Wallet must be unlocked to list accounts" );
Expand Down

0 comments on commit 45e1152

Please sign in to comment.