son_wallet_object API and cli wallet commands

This commit is contained in:
Srdjan Obucina 2020-01-18 00:35:25 +01:00
parent b06e1d680a
commit 1dc0eee6b6
4 changed files with 139 additions and 0 deletions

View file

@ -152,6 +152,11 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
map<string, son_id_type> lookup_son_accounts(const string& lower_bound_name, uint32_t limit)const;
uint64_t get_son_count()const;
// SON wallets
optional<son_wallet_object> get_active_son_wallet();
optional<son_wallet_object> get_son_wallet_by_time_point(time_point_sec time_point);
vector<optional<son_wallet_object>> get_son_wallets(uint32_t limit);
// Sidechain addresses
vector<optional<sidechain_address_object>> get_sidechain_addresses(const vector<sidechain_address_id_type>& sidechain_address_ids)const;
vector<optional<sidechain_address_object>> get_sidechain_addresses_by_account(account_id_type account)const;
@ -1770,6 +1775,57 @@ uint64_t database_api_impl::get_son_count()const
return _db.get_index_type<son_index>().indices().size();
}
//////////////////////////////////////////////////////////////////////
// //
// SON Wallets //
// //
//////////////////////////////////////////////////////////////////////
optional<son_wallet_object> database_api::get_active_son_wallet()
{
return my->get_active_son_wallet();
}
optional<son_wallet_object> database_api_impl::get_active_son_wallet()
{
const auto& idx = _db.get_index_type<son_wallet_index>().indices().get<by_id>();
auto obj = idx.rbegin();
if (obj != idx.rend()) {
return *obj;
}
return {};
}
optional<son_wallet_object> database_api::get_son_wallet_by_time_point(time_point_sec time_point)
{
return my->get_son_wallet_by_time_point(time_point);
}
optional<son_wallet_object> database_api_impl::get_son_wallet_by_time_point(time_point_sec time_point)
{
const auto& son_wallets_by_id = _db.get_index_type<son_wallet_index>().indices().get<by_id>();
for (const son_wallet_object& swo : son_wallets_by_id) {
if ((time_point >= swo.valid_from) && (time_point < swo.expires))
return swo;
}
return {};
}
vector<optional<son_wallet_object>> database_api::get_son_wallets(uint32_t limit)
{
return my->get_son_wallets(limit);
}
vector<optional<son_wallet_object>> database_api_impl::get_son_wallets(uint32_t limit)
{
FC_ASSERT( limit <= 1000 );
vector<optional<son_wallet_object>> result;
const auto& son_wallets_by_id = _db.get_index_type<son_wallet_index>().indices().get<by_id>();
for (const son_wallet_object& swo : son_wallets_by_id)
result.push_back(swo);
return result;
}
//////////////////////////////////////////////////////////////////////
// //
// Sidechain Accounts //

View file

@ -44,6 +44,7 @@
#include <graphene/chain/betting_market_object.hpp>
#include <graphene/chain/global_betting_statistics_object.hpp>
#include <graphene/chain/son_object.hpp>
#include <graphene/chain/son_wallet_object.hpp>
#include <graphene/chain/sidechain_address_object.hpp>
#include <graphene/chain/worker_object.hpp>
@ -603,6 +604,30 @@ class database_api
*/
uint64_t get_son_count()const;
/////////////////////////
// SON Wallets //
/////////////////////////
/**
* @brief Get active SON wallet
* @return Active SON wallet object
*/
optional<son_wallet_object> get_active_son_wallet();
/**
* @brief Get SON wallet that was active for a given time point
* @param time_point Time point
* @return SON wallet object, for the wallet that was active for a given time point
*/
optional<son_wallet_object> get_son_wallet_by_time_point(time_point_sec time_point);
/**
* @brief Get full list of SON wallets
* @param limit Maximum number of results to return
* @return A list of SON wallet objects
*/
vector<optional<son_wallet_object>> get_son_wallets(uint32_t limit);
/////////////////////////
// Sidechain Addresses //
/////////////////////////
@ -855,6 +880,11 @@ FC_API(graphene::app::database_api,
(lookup_son_accounts)
(get_son_count)
// SON wallets
(get_active_son_wallet)
(get_son_wallet_by_time_point)
(get_son_wallets)
// Sidechain addresses
(get_sidechain_addresses)
(get_sidechain_addresses_by_account)

View file

@ -1372,6 +1372,26 @@ class wallet_api
*/
map<string, son_id_type> list_active_sons();
/**
* @brief Get active SON wallet
* @return Active SON wallet object
*/
optional<son_wallet_object> get_active_son_wallet();
/**
* @brief Get SON wallet that was active for a given time point
* @param time_point Time point
* @return SON wallet object, for the wallet that was active for a given time point
*/
optional<son_wallet_object> get_son_wallet_by_time_point(time_point_sec time_point);
/**
* @brief Get full list of SON wallets
* @param limit Maximum number of results to return
* @return A list of SON wallet objects
*/
vector<optional<son_wallet_object>> get_son_wallets(uint32_t limit);
/** Adds sidechain address owned by the given account for a given sidechain.
*
* An account can have at most one sidechain address for one sidechain.
@ -2202,6 +2222,9 @@ FC_API( graphene::wallet::wallet_api,
(update_son)
(delete_son)
(list_sons)
(get_active_son_wallet)
(get_son_wallet_by_time_point)
(get_son_wallets)
(add_sidechain_address)
(update_sidechain_address)
(delete_sidechain_address)

View file

@ -1968,6 +1968,21 @@ public:
return result;
} FC_CAPTURE_AND_RETHROW() }
optional<son_wallet_object> get_active_son_wallet()
{ try {
return _remote_db->get_active_son_wallet();
} FC_CAPTURE_AND_RETHROW() }
optional<son_wallet_object> get_son_wallet_by_time_point(time_point_sec time_point)
{ try {
return _remote_db->get_son_wallet_by_time_point(time_point);
} FC_CAPTURE_AND_RETHROW() }
vector<optional<son_wallet_object>> get_son_wallets(uint32_t limit)
{ try {
return _remote_db->get_son_wallets(limit);
} FC_CAPTURE_AND_RETHROW() }
signed_transaction add_sidechain_address(string account,
peerplays_sidechain::sidechain_type sidechain,
string address,
@ -4413,6 +4428,21 @@ map<string, son_id_type> wallet_api::list_active_sons()
return my->list_active_sons();
}
optional<son_wallet_object> wallet_api::get_active_son_wallet()
{
return my->get_active_son_wallet();
}
optional<son_wallet_object> wallet_api::get_son_wallet_by_time_point(time_point_sec time_point)
{
return my->get_son_wallet_by_time_point(time_point);
}
vector<optional<son_wallet_object>> wallet_api::get_son_wallets(uint32_t limit)
{
return my->get_son_wallets(limit);
}
signed_transaction wallet_api::add_sidechain_address(string account,
peerplays_sidechain::sidechain_type sidechain,
string address,