Merge branch 'hotfix/extend_get_block_api' into 'develop'
Streamline get_block API from database and cli wallet See merge request PBSA/peerplays!197
This commit is contained in:
commit
cb60cbe5d1
4 changed files with 55 additions and 31 deletions
|
|
@ -71,6 +71,17 @@ std::string object_id_to_string(object_id_type id) {
|
||||||
return object_id;
|
return object_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
signed_block_with_info::signed_block_with_info(){};
|
||||||
|
|
||||||
|
signed_block_with_info::signed_block_with_info(const signed_block &block) :
|
||||||
|
signed_block(block) {
|
||||||
|
block_id = id();
|
||||||
|
signing_key = signee();
|
||||||
|
transaction_ids.reserve(transactions.size());
|
||||||
|
for (const processed_transaction &tx : transactions)
|
||||||
|
transaction_ids.push_back(tx.id());
|
||||||
|
}
|
||||||
|
|
||||||
class database_api_impl : public std::enable_shared_from_this<database_api_impl> {
|
class database_api_impl : public std::enable_shared_from_this<database_api_impl> {
|
||||||
public:
|
public:
|
||||||
database_api_impl(graphene::chain::database &db);
|
database_api_impl(graphene::chain::database &db);
|
||||||
|
|
@ -89,6 +100,7 @@ public:
|
||||||
optional<block_header> get_block_header(uint32_t block_num) const;
|
optional<block_header> get_block_header(uint32_t block_num) const;
|
||||||
map<uint32_t, optional<block_header>> get_block_header_batch(const vector<uint32_t> block_nums) const;
|
map<uint32_t, optional<block_header>> get_block_header_batch(const vector<uint32_t> block_nums) const;
|
||||||
optional<signed_block> get_block(uint32_t block_num) const;
|
optional<signed_block> get_block(uint32_t block_num) const;
|
||||||
|
optional<signed_block_with_info> get_block2(uint32_t block_num) const;
|
||||||
vector<optional<signed_block>> get_blocks(uint32_t block_num_from, uint32_t block_num_to) const;
|
vector<optional<signed_block>> get_blocks(uint32_t block_num_from, uint32_t block_num_to) const;
|
||||||
processed_transaction get_transaction(uint32_t block_num, uint32_t trx_in_block) const;
|
processed_transaction get_transaction(uint32_t block_num, uint32_t trx_in_block) const;
|
||||||
|
|
||||||
|
|
@ -532,6 +544,17 @@ optional<signed_block> database_api_impl::get_block(uint32_t block_num) const {
|
||||||
return _db.fetch_block_by_number(block_num);
|
return _db.fetch_block_by_number(block_num);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
optional<signed_block_with_info> database_api::get_block2(uint32_t block_num) const {
|
||||||
|
return my->get_block2(block_num);
|
||||||
|
}
|
||||||
|
|
||||||
|
optional<signed_block_with_info> database_api_impl::get_block2(uint32_t block_num) const {
|
||||||
|
auto result = _db.fetch_block_by_number(block_num);
|
||||||
|
if (result)
|
||||||
|
return signed_block_with_info(*result);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
vector<optional<signed_block>> database_api::get_blocks(uint32_t block_num_from, uint32_t block_num_to) const {
|
vector<optional<signed_block>> database_api::get_blocks(uint32_t block_num_from, uint32_t block_num_to) const {
|
||||||
return my->get_blocks(block_num_from, block_num_to);
|
return my->get_blocks(block_num_from, block_num_to);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,15 @@ using namespace std;
|
||||||
|
|
||||||
class database_api_impl;
|
class database_api_impl;
|
||||||
|
|
||||||
|
struct signed_block_with_info : public signed_block {
|
||||||
|
signed_block_with_info();
|
||||||
|
signed_block_with_info(const signed_block &block);
|
||||||
|
signed_block_with_info(const signed_block_with_info &block) = default;
|
||||||
|
block_id_type block_id;
|
||||||
|
public_key_type signing_key;
|
||||||
|
vector<transaction_id_type> transaction_ids;
|
||||||
|
};
|
||||||
|
|
||||||
struct order {
|
struct order {
|
||||||
double price;
|
double price;
|
||||||
double quote;
|
double quote;
|
||||||
|
|
@ -202,6 +211,13 @@ public:
|
||||||
*/
|
*/
|
||||||
optional<signed_block> get_block(uint32_t block_num) const;
|
optional<signed_block> get_block(uint32_t block_num) const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Retrieve a full, signed block, with some extra info
|
||||||
|
* @param block_num Height of the block to be returned
|
||||||
|
* @return the referenced block, or null if no matching block was found
|
||||||
|
*/
|
||||||
|
optional<signed_block_with_info> get_block2(uint32_t block_num) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Retrieve a list of signed blocks
|
* @brief Retrieve a list of signed blocks
|
||||||
* @param block_num_from start
|
* @param block_num_from start
|
||||||
|
|
@ -1075,6 +1091,8 @@ extern template class fc::api<graphene::app::database_api>;
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|
||||||
|
FC_REFLECT_DERIVED(graphene::app::signed_block_with_info, (graphene::chain::signed_block), (block_id)(signing_key)(transaction_ids));
|
||||||
|
|
||||||
FC_REFLECT(graphene::app::order, (price)(quote)(base));
|
FC_REFLECT(graphene::app::order, (price)(quote)(base));
|
||||||
FC_REFLECT(graphene::app::order_book, (base)(quote)(bids)(asks));
|
FC_REFLECT(graphene::app::order_book, (base)(quote)(bids)(asks));
|
||||||
FC_REFLECT(graphene::app::market_ticker, (base)(quote)(latest)(lowest_ask)(highest_bid)(percent_change)(base_volume)(quote_volume));
|
FC_REFLECT(graphene::app::market_ticker, (base)(quote)(latest)(lowest_ask)(highest_bid)(percent_change)(base_volume)(quote_volume));
|
||||||
|
|
@ -1097,6 +1115,7 @@ FC_API(graphene::app::database_api,
|
||||||
(get_block_header)
|
(get_block_header)
|
||||||
(get_block_header_batch)
|
(get_block_header_batch)
|
||||||
(get_block)
|
(get_block)
|
||||||
|
(get_block2)
|
||||||
(get_blocks)
|
(get_blocks)
|
||||||
(get_transaction)
|
(get_transaction)
|
||||||
(get_recent_transaction_by_id)
|
(get_recent_transaction_by_id)
|
||||||
|
|
|
||||||
|
|
@ -191,17 +191,6 @@ struct worker_vote_delta
|
||||||
flat_set<worker_id_type> vote_abstain;
|
flat_set<worker_id_type> vote_abstain;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct signed_block_with_info : public signed_block
|
|
||||||
{
|
|
||||||
signed_block_with_info();
|
|
||||||
signed_block_with_info( const signed_block& block );
|
|
||||||
signed_block_with_info( const signed_block_with_info& block ) = default;
|
|
||||||
|
|
||||||
block_id_type block_id;
|
|
||||||
public_key_type signing_key;
|
|
||||||
vector< transaction_id_type > transaction_ids;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct vesting_balance_object_with_info : public vesting_balance_object
|
struct vesting_balance_object_with_info : public vesting_balance_object
|
||||||
{
|
{
|
||||||
vesting_balance_object_with_info();
|
vesting_balance_object_with_info();
|
||||||
|
|
@ -276,7 +265,12 @@ class wallet_api
|
||||||
* @param num height of the block to retrieve
|
* @param num height of the block to retrieve
|
||||||
* @returns info about the block, or null if not found
|
* @returns info about the block, or null if not found
|
||||||
*/
|
*/
|
||||||
optional<signed_block_with_info> get_block( uint32_t num );
|
optional<signed_block> get_block( uint32_t num );
|
||||||
|
/** Returns info about a specified block, with some extra info.
|
||||||
|
* @param num height of the block to retrieve
|
||||||
|
* @returns info about the block, or null if not found
|
||||||
|
*/
|
||||||
|
optional<signed_block_with_info> get_block2( uint32_t num );
|
||||||
/** Get signed blocks
|
/** Get signed blocks
|
||||||
* @param block_num_from The lowest block number
|
* @param block_num_from The lowest block number
|
||||||
* @param block_num_to The highest block number
|
* @param block_num_to The highest block number
|
||||||
|
|
@ -2762,9 +2756,6 @@ FC_REFLECT( graphene::wallet::worker_vote_delta,
|
||||||
(vote_abstain)
|
(vote_abstain)
|
||||||
)
|
)
|
||||||
|
|
||||||
FC_REFLECT_DERIVED( graphene::wallet::signed_block_with_info, (graphene::chain::signed_block),
|
|
||||||
(block_id)(signing_key)(transaction_ids) )
|
|
||||||
|
|
||||||
FC_REFLECT_DERIVED( graphene::wallet::vesting_balance_object_with_info, (graphene::chain::vesting_balance_object),
|
FC_REFLECT_DERIVED( graphene::wallet::vesting_balance_object_with_info, (graphene::chain::vesting_balance_object),
|
||||||
(allowed_withdraw)(allowed_withdraw_time) )
|
(allowed_withdraw)(allowed_withdraw_time) )
|
||||||
|
|
||||||
|
|
@ -2882,6 +2873,7 @@ FC_API( graphene::wallet::wallet_api,
|
||||||
(get_account)
|
(get_account)
|
||||||
(get_account_id)
|
(get_account_id)
|
||||||
(get_block)
|
(get_block)
|
||||||
|
(get_block2)
|
||||||
(get_blocks)
|
(get_blocks)
|
||||||
(get_account_count)
|
(get_account_count)
|
||||||
(get_account_history)
|
(get_account_history)
|
||||||
|
|
|
||||||
|
|
@ -4549,11 +4549,16 @@ bool wallet_api::copy_wallet_file(string destination_filename)
|
||||||
return my->copy_wallet_file(destination_filename);
|
return my->copy_wallet_file(destination_filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
optional<signed_block_with_info> wallet_api::get_block(uint32_t num)
|
optional<signed_block> wallet_api::get_block(uint32_t num)
|
||||||
{
|
{
|
||||||
return my->_remote_db->get_block(num);
|
return my->_remote_db->get_block(num);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
optional<signed_block_with_info> wallet_api::get_block2(uint32_t num)
|
||||||
|
{
|
||||||
|
return my->_remote_db->get_block2(num);
|
||||||
|
}
|
||||||
|
|
||||||
vector<optional<signed_block>> wallet_api::get_blocks(uint32_t block_num_from, uint32_t block_num_to) const
|
vector<optional<signed_block>> wallet_api::get_blocks(uint32_t block_num_from, uint32_t block_num_to) const
|
||||||
{
|
{
|
||||||
return my->_remote_db->get_blocks(block_num_from, block_num_to);
|
return my->_remote_db->get_blocks(block_num_from, block_num_to);
|
||||||
|
|
@ -7289,10 +7294,6 @@ vector<account_role_object> wallet_api::get_account_roles_by_owner(string owner_
|
||||||
account_object owner_account = my->get_account(owner_account_id_or_name);
|
account_object owner_account = my->get_account(owner_account_id_or_name);
|
||||||
return my->_remote_db->get_account_roles_by_owner(owner_account.id);
|
return my->_remote_db->get_account_roles_by_owner(owner_account.id);
|
||||||
}
|
}
|
||||||
// default ctor necessary for FC_REFLECT
|
|
||||||
signed_block_with_info::signed_block_with_info()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
order_book wallet_api::get_order_book( const string& base, const string& quote, unsigned limit )
|
order_book wallet_api::get_order_book( const string& base, const string& quote, unsigned limit )
|
||||||
{
|
{
|
||||||
|
|
@ -7359,17 +7360,6 @@ std::string wallet_api::eth_estimate_withdrawal_transaction_fee() const
|
||||||
return my->eth_estimate_withdrawal_transaction_fee();
|
return my->eth_estimate_withdrawal_transaction_fee();
|
||||||
}
|
}
|
||||||
|
|
||||||
// default ctor necessary for FC_REFLECT
|
|
||||||
signed_block_with_info::signed_block_with_info( const signed_block& block )
|
|
||||||
: signed_block( block )
|
|
||||||
{
|
|
||||||
block_id = id();
|
|
||||||
signing_key = signee();
|
|
||||||
transaction_ids.reserve( transactions.size() );
|
|
||||||
for( const processed_transaction& tx : transactions )
|
|
||||||
transaction_ids.push_back( tx.id() );
|
|
||||||
}
|
|
||||||
|
|
||||||
vesting_balance_object_with_info::vesting_balance_object_with_info()
|
vesting_balance_object_with_info::vesting_balance_object_with_info()
|
||||||
: vesting_balance_object()
|
: vesting_balance_object()
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue