Skip to content

Commit

Permalink
Allow querying witness_node version by API
Browse files Browse the repository at this point in the history
  • Loading branch information
serkixenos committed Jun 17, 2022
1 parent 9012e86 commit 0a38927
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
25 changes: 25 additions & 0 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,15 @@
#include <graphene/chain/pts_address.hpp>
#include <graphene/chain/tournament_object.hpp>

#include <graphene/utilities/git_revision.hpp>

#include <fc/bloom_filter.hpp>

#include <fc/crypto/hex.hpp>
#include <fc/rpc/api_connection.hpp>
#include <fc/uint128.hpp>

#include <boost/algorithm/string.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/iterator_range.hpp>
#include <boost/rational.hpp>
Expand Down Expand Up @@ -90,6 +93,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
processed_transaction get_transaction(uint32_t block_num, uint32_t trx_in_block) const;

// Globals
version_info get_version_info() const;
chain_property_object get_chain_properties() const;
global_property_object get_global_properties() const;
fc::variant_object get_config() const;
Expand Down Expand Up @@ -563,6 +567,27 @@ processed_transaction database_api_impl::get_transaction(uint32_t block_num, uin
// //
//////////////////////////////////////////////////////////////////////

version_info database_api::get_version_info() const {
return my->get_version_info();
}

version_info database_api_impl::get_version_info() const {

std::string witness_version(graphene::utilities::git_revision_description);
const size_t pos = witness_version.find('/');
if (pos != std::string::npos && witness_version.size() > pos)
witness_version = witness_version.substr(pos + 1);

version_info vi;
vi.version = witness_version;
vi.git_revision = graphene::utilities::git_revision_sha;
vi.built = std::string(__DATE__) + " at " + std::string(__TIME__);
vi.openssl = OPENSSL_VERSION_TEXT;
vi.boost = boost::replace_all_copy(std::string(BOOST_LIB_VERSION), "_", ".");

return vi;
}

chain_property_object database_api::get_chain_properties() const {
return my->get_chain_properties();
}
Expand Down
15 changes: 15 additions & 0 deletions libraries/app/include/graphene/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ struct gpos_info {
share_type account_vested_balance;
};

struct version_info {
string version;
string git_revision;
string built;
string openssl;
string boost;
};

/**
* @brief The database_api class implements the RPC API for the chain database.
*
Expand Down Expand Up @@ -218,6 +226,11 @@ class database_api {
// Globals //
/////////////

/**
* @brief Retrieve the @ref version_info associated with the witness node
*/
version_info get_version_info() const;

/**
* @brief Retrieve the @ref chain_property_object associated with the chain
*/
Expand Down Expand Up @@ -1040,6 +1053,7 @@ FC_REFLECT(graphene::app::market_ticker, (base)(quote)(latest)(lowest_ask)(highe
FC_REFLECT(graphene::app::market_volume, (base)(quote)(base_volume)(quote_volume));
FC_REFLECT(graphene::app::market_trade, (date)(price)(amount)(value));
FC_REFLECT(graphene::app::gpos_info, (vesting_factor)(award)(total_amount)(current_subperiod)(last_voted_time)(allowed_withdraw_amount)(account_vested_balance));
FC_REFLECT(graphene::app::version_info, (version)(git_revision)(built)(openssl)(boost));

FC_API(graphene::app::database_api,
// Objects
Expand All @@ -1060,6 +1074,7 @@ FC_API(graphene::app::database_api,
(get_recent_transaction_by_id)

// Globals
(get_version_info)
(get_chain_properties)
(get_global_properties)
(get_config)
Expand Down

0 comments on commit 0a38927

Please sign in to comment.