diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index c4566d24..71ef02c5 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -152,6 +152,11 @@ class database_api_impl : public std::enable_shared_from_this map lookup_son_accounts(const string& lower_bound_name, uint32_t limit)const; uint64_t get_son_count()const; + // SON wallets + optional get_active_son_wallet(); + optional get_son_wallet_by_time_point(time_point_sec time_point); + vector> get_son_wallets(uint32_t limit); + // Sidechain addresses vector> get_sidechain_addresses(const vector& sidechain_address_ids)const; vector> 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().indices().size(); } +////////////////////////////////////////////////////////////////////// +// // +// SON Wallets // +// // +////////////////////////////////////////////////////////////////////// + +optional database_api::get_active_son_wallet() +{ + return my->get_active_son_wallet(); +} + +optional database_api_impl::get_active_son_wallet() +{ + const auto& idx = _db.get_index_type().indices().get(); + auto obj = idx.rbegin(); + if (obj != idx.rend()) { + return *obj; + } + return {}; +} + +optional database_api::get_son_wallet_by_time_point(time_point_sec time_point) +{ + return my->get_son_wallet_by_time_point(time_point); +} + +optional database_api_impl::get_son_wallet_by_time_point(time_point_sec time_point) +{ + const auto& son_wallets_by_id = _db.get_index_type().indices().get(); + for (const son_wallet_object& swo : son_wallets_by_id) { + if ((time_point >= swo.valid_from) && (time_point < swo.expires)) + return swo; + } + return {}; +} + +vector> database_api::get_son_wallets(uint32_t limit) +{ + return my->get_son_wallets(limit); +} + +vector> database_api_impl::get_son_wallets(uint32_t limit) +{ + FC_ASSERT( limit <= 1000 ); + vector> result; + const auto& son_wallets_by_id = _db.get_index_type().indices().get(); + for (const son_wallet_object& swo : son_wallets_by_id) + result.push_back(swo); + return result; +} + ////////////////////////////////////////////////////////////////////// // // // Sidechain Accounts // diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index e3252ec6..76ef822c 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -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 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 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> 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) diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index a158587a..ddc909d9 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -1372,6 +1372,26 @@ class wallet_api */ map list_active_sons(); + /** + * @brief Get active SON wallet + * @return Active SON wallet object + */ + optional 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 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> 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) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index be837940..a7f5c527 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1968,6 +1968,21 @@ public: return result; } FC_CAPTURE_AND_RETHROW() } + optional get_active_son_wallet() + { try { + return _remote_db->get_active_son_wallet(); + } FC_CAPTURE_AND_RETHROW() } + + optional 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> 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 wallet_api::list_active_sons() return my->list_active_sons(); } +optional wallet_api::get_active_son_wallet() +{ + return my->get_active_son_wallet(); +} + +optional wallet_api::get_son_wallet_by_time_point(time_point_sec time_point) +{ + return my->get_son_wallet_by_time_point(time_point); +} + +vector> 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,