get_son_network_status cli wallet command
This commit is contained in:
parent
d95de9fea0
commit
a1c8ca60d7
5 changed files with 69 additions and 27 deletions
|
|
@ -1,15 +1,8 @@
|
||||||
#include <graphene/peerplays_sidechain/common/utils.hpp>
|
#include <graphene/peerplays_sidechain/common/utils.hpp>
|
||||||
|
|
||||||
std::string account_id_to_string(graphene::chain::account_id_type account_id) {
|
std::string object_id_to_string(graphene::chain::object_id_type id) {
|
||||||
std::string account_id_str = fc::to_string(account_id.space_id) + "." +
|
std::string object_id = fc::to_string(id.space()) + "." +
|
||||||
fc::to_string(account_id.type_id) + "." +
|
fc::to_string(id.type()) + "." +
|
||||||
fc::to_string((uint64_t)account_id.instance);
|
fc::to_string(id.instance());
|
||||||
return account_id_str;
|
return object_id;
|
||||||
}
|
|
||||||
|
|
||||||
std::string asset_id_to_string(graphene::chain::asset_id_type asset_id) {
|
|
||||||
std::string asset_id_str = fc::to_string(asset_id.space_id) + "." +
|
|
||||||
fc::to_string(asset_id.type_id) + "." +
|
|
||||||
fc::to_string((uint64_t)asset_id.instance);
|
|
||||||
return asset_id_str;
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,5 +2,4 @@
|
||||||
|
|
||||||
#include <graphene/chain/protocol/asset.hpp>
|
#include <graphene/chain/protocol/asset.hpp>
|
||||||
|
|
||||||
std::string account_id_to_string(graphene::chain::account_id_type account_id);
|
std::string object_id_to_string(graphene::chain::object_id_type id);
|
||||||
std::string asset_id_to_string(graphene::chain::asset_id_type asset_id);
|
|
||||||
|
|
|
||||||
|
|
@ -183,9 +183,9 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_
|
||||||
enable_peerplays_asset_deposits);
|
enable_peerplays_asset_deposits);
|
||||||
|
|
||||||
bool withdraw_condition = (sed.peerplays_to == gpo.parameters.son_account()) && (sed.sidechain == sidechain_type::peerplays) &&
|
bool withdraw_condition = (sed.peerplays_to == gpo.parameters.son_account()) && (sed.sidechain == sidechain_type::peerplays) &&
|
||||||
((sed.sidechain_currency == asset_id_to_string(gpo.parameters.btc_asset())) ||
|
((sed.sidechain_currency == object_id_to_string(gpo.parameters.btc_asset())) ||
|
||||||
(sed.sidechain_currency == asset_id_to_string(gpo.parameters.hbd_asset())) ||
|
(sed.sidechain_currency == object_id_to_string(gpo.parameters.hbd_asset())) ||
|
||||||
(sed.sidechain_currency == asset_id_to_string(gpo.parameters.hive_asset())));
|
(sed.sidechain_currency == object_id_to_string(gpo.parameters.hive_asset())));
|
||||||
|
|
||||||
// Deposit request
|
// Deposit request
|
||||||
if (deposit_condition) {
|
if (deposit_condition) {
|
||||||
|
|
@ -236,15 +236,15 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_
|
||||||
|
|
||||||
std::string withdraw_currency = "";
|
std::string withdraw_currency = "";
|
||||||
price withdraw_currency_price = {};
|
price withdraw_currency_price = {};
|
||||||
if (sed.sidechain_currency == asset_id_to_string(gpo.parameters.btc_asset())) {
|
if (sed.sidechain_currency == object_id_to_string(gpo.parameters.btc_asset())) {
|
||||||
withdraw_currency = "BTC";
|
withdraw_currency = "BTC";
|
||||||
withdraw_currency_price = database.get<asset_object>(database.get_global_properties().parameters.btc_asset()).options.core_exchange_rate;
|
withdraw_currency_price = database.get<asset_object>(database.get_global_properties().parameters.btc_asset()).options.core_exchange_rate;
|
||||||
}
|
}
|
||||||
if (sed.sidechain_currency == asset_id_to_string(gpo.parameters.hbd_asset())) {
|
if (sed.sidechain_currency == object_id_to_string(gpo.parameters.hbd_asset())) {
|
||||||
withdraw_currency = "HBD";
|
withdraw_currency = "HBD";
|
||||||
withdraw_currency_price = database.get<asset_object>(database.get_global_properties().parameters.hbd_asset()).options.core_exchange_rate;
|
withdraw_currency_price = database.get<asset_object>(database.get_global_properties().parameters.hbd_asset()).options.core_exchange_rate;
|
||||||
}
|
}
|
||||||
if (sed.sidechain_currency == asset_id_to_string(gpo.parameters.hive_asset())) {
|
if (sed.sidechain_currency == object_id_to_string(gpo.parameters.hive_asset())) {
|
||||||
withdraw_currency = "HIVE";
|
withdraw_currency = "HIVE";
|
||||||
withdraw_currency_price = database.get<asset_object>(database.get_global_properties().parameters.hive_asset()).options.core_exchange_rate;
|
withdraw_currency_price = database.get<asset_object>(database.get_global_properties().parameters.hive_asset()).options.core_exchange_rate;
|
||||||
}
|
}
|
||||||
|
|
@ -642,7 +642,7 @@ void sidechain_net_handler::on_applied_block(const signed_block &b) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string sidechain_from = account_id_to_string(transfer_op.from);
|
std::string sidechain_from = object_id_to_string(transfer_op.from);
|
||||||
std::string memo = "";
|
std::string memo = "";
|
||||||
if (transfer_op.memo) {
|
if (transfer_op.memo) {
|
||||||
memo = transfer_op.memo->get_message(fc::ecc::private_key(), public_key_type());
|
memo = transfer_op.memo->get_message(fc::ecc::private_key(), public_key_type());
|
||||||
|
|
@ -664,8 +664,8 @@ void sidechain_net_handler::on_applied_block(const signed_block &b) {
|
||||||
sed.sidechain_uid = sidechain_uid;
|
sed.sidechain_uid = sidechain_uid;
|
||||||
sed.sidechain_transaction_id = trx.id().str();
|
sed.sidechain_transaction_id = trx.id().str();
|
||||||
sed.sidechain_from = sidechain_from;
|
sed.sidechain_from = sidechain_from;
|
||||||
sed.sidechain_to = account_id_to_string(transfer_op.to);
|
sed.sidechain_to = object_id_to_string(transfer_op.to);
|
||||||
sed.sidechain_currency = asset_id_to_string(transfer_op.amount.asset_id);
|
sed.sidechain_currency = object_id_to_string(transfer_op.amount.asset_id);
|
||||||
sed.sidechain_amount = transfer_op.amount.amount;
|
sed.sidechain_amount = transfer_op.amount.amount;
|
||||||
sed.peerplays_from = transfer_op.from;
|
sed.peerplays_from = transfer_op.from;
|
||||||
sed.peerplays_to = transfer_op.to;
|
sed.peerplays_to = transfer_op.to;
|
||||||
|
|
|
||||||
|
|
@ -1478,6 +1478,12 @@ class wallet_api
|
||||||
*/
|
*/
|
||||||
map<string, son_id_type> list_active_sons();
|
map<string, son_id_type> list_active_sons();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get SON network status
|
||||||
|
* @return SON network status description
|
||||||
|
*/
|
||||||
|
map<son_id_type, string> get_son_network_status();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get active SON wallet
|
* @brief Get active SON wallet
|
||||||
* @return Active SON wallet object
|
* @return Active SON wallet object
|
||||||
|
|
@ -2618,6 +2624,7 @@ FC_API( graphene::wallet::wallet_api,
|
||||||
(update_son_vesting_balances)
|
(update_son_vesting_balances)
|
||||||
(list_sons)
|
(list_sons)
|
||||||
(list_active_sons)
|
(list_active_sons)
|
||||||
|
(get_son_network_status)
|
||||||
(request_son_maintenance)
|
(request_son_maintenance)
|
||||||
(cancel_request_son_maintenance)
|
(cancel_request_son_maintenance)
|
||||||
(get_active_son_wallet)
|
(get_active_son_wallet)
|
||||||
|
|
|
||||||
|
|
@ -734,12 +734,16 @@ public:
|
||||||
{
|
{
|
||||||
return _remote_db->get_dynamic_global_properties();
|
return _remote_db->get_dynamic_global_properties();
|
||||||
}
|
}
|
||||||
|
std::string object_id_to_string(object_id_type id) const
|
||||||
|
{
|
||||||
|
std::string object_id = fc::to_string(id.space())
|
||||||
|
+ "." + fc::to_string(id.type())
|
||||||
|
+ "." + fc::to_string(id.instance());
|
||||||
|
return object_id;
|
||||||
|
}
|
||||||
std::string account_id_to_string(account_id_type id) const
|
std::string account_id_to_string(account_id_type id) const
|
||||||
{
|
{
|
||||||
std::string account_id = fc::to_string(id.space_id)
|
return object_id_to_string(id);
|
||||||
+ "." + fc::to_string(id.type_id)
|
|
||||||
+ "." + fc::to_string(id.instance.value);
|
|
||||||
return account_id;
|
|
||||||
}
|
}
|
||||||
account_object get_account(account_id_type id) const
|
account_object get_account(account_id_type id) const
|
||||||
{
|
{
|
||||||
|
|
@ -2203,6 +2207,40 @@ public:
|
||||||
return result;
|
return result;
|
||||||
} FC_CAPTURE_AND_RETHROW() }
|
} FC_CAPTURE_AND_RETHROW() }
|
||||||
|
|
||||||
|
map<son_id_type, string> get_son_network_status()
|
||||||
|
{ try {
|
||||||
|
global_property_object gpo = get_global_properties();
|
||||||
|
vector<son_id_type> son_ids;
|
||||||
|
son_ids.reserve(gpo.active_sons.size());
|
||||||
|
std::transform(gpo.active_sons.begin(), gpo.active_sons.end(),
|
||||||
|
std::inserter(son_ids, son_ids.end()),
|
||||||
|
[](const son_info& swi) {
|
||||||
|
return swi.son_id;
|
||||||
|
});
|
||||||
|
|
||||||
|
map<son_id_type, string> result;
|
||||||
|
std::vector<fc::optional<son_object>> son_objects = _remote_db->get_sons(son_ids);
|
||||||
|
for(auto son_obj: son_objects) {
|
||||||
|
string status;
|
||||||
|
if (son_obj) {
|
||||||
|
son_statistics_object sso = get_object(son_obj->statistics);
|
||||||
|
if (sso.last_active_timestamp + fc::seconds(gpo.parameters.son_heartbeat_frequency()) > time_point::now()) {
|
||||||
|
status = "OK, regular SON heartbeat";
|
||||||
|
} else {
|
||||||
|
if (sso.last_active_timestamp + fc::seconds(gpo.parameters.son_down_time()) > time_point::now()) {
|
||||||
|
status = "OK, irregular SON heartbeat, but not triggering SON down proposal";
|
||||||
|
} else {
|
||||||
|
status = "NOT OK, irregular SON heartbeat, triggering SON down proposal";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
status = "NOT OK, invalid SON id";
|
||||||
|
}
|
||||||
|
result[son_obj->id] = status;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
} FC_CAPTURE_AND_RETHROW() }
|
||||||
|
|
||||||
optional<son_wallet_object> get_active_son_wallet()
|
optional<son_wallet_object> get_active_son_wallet()
|
||||||
{ try {
|
{ try {
|
||||||
return _remote_db->get_active_son_wallet();
|
return _remote_db->get_active_son_wallet();
|
||||||
|
|
@ -5043,6 +5081,11 @@ map<string, son_id_type> wallet_api::list_active_sons()
|
||||||
return my->list_active_sons();
|
return my->list_active_sons();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
map<son_id_type, string> wallet_api::get_son_network_status()
|
||||||
|
{
|
||||||
|
return my->get_son_network_status();
|
||||||
|
}
|
||||||
|
|
||||||
optional<son_wallet_object> wallet_api::get_active_son_wallet()
|
optional<son_wallet_object> wallet_api::get_active_son_wallet()
|
||||||
{
|
{
|
||||||
return my->get_active_son_wallet();
|
return my->get_active_son_wallet();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue