diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index c9aba7ff..7dd38c79 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -170,8 +170,8 @@ class database_api_impl : public std::enable_shared_from_this // Sidechain addresses vector> get_sidechain_addresses(const vector& sidechain_address_ids)const; vector> get_sidechain_addresses_by_account(account_id_type account)const; - vector> get_sidechain_addresses_by_sidechain(peerplays_sidechain::sidechain_type sidechain)const; - fc::optional get_sidechain_address_by_account_and_sidechain(account_id_type account, peerplays_sidechain::sidechain_type sidechain)const; + vector> get_sidechain_addresses_by_sidechain(sidechain_type sidechain)const; + fc::optional get_sidechain_address_by_account_and_sidechain(account_id_type account, sidechain_type sidechain)const; uint64_t get_sidechain_addresses_count()const; // Votes @@ -1943,12 +1943,12 @@ vector> database_api_impl::get_sidechain_addr return result; } -vector> database_api::get_sidechain_addresses_by_sidechain(peerplays_sidechain::sidechain_type sidechain)const +vector> database_api::get_sidechain_addresses_by_sidechain(sidechain_type sidechain)const { return my->get_sidechain_addresses_by_sidechain( sidechain ); } -vector> database_api_impl::get_sidechain_addresses_by_sidechain(peerplays_sidechain::sidechain_type sidechain)const +vector> database_api_impl::get_sidechain_addresses_by_sidechain(sidechain_type sidechain)const { vector> result; const auto& sidechain_addresses_range = _db.get_index_type().indices().get().equal_range(sidechain); @@ -1959,12 +1959,12 @@ vector> database_api_impl::get_sidechain_addr return result; } -fc::optional database_api::get_sidechain_address_by_account_and_sidechain(account_id_type account, peerplays_sidechain::sidechain_type sidechain)const +fc::optional database_api::get_sidechain_address_by_account_and_sidechain(account_id_type account, sidechain_type sidechain)const { return my->get_sidechain_address_by_account_and_sidechain( account, sidechain ); } -fc::optional database_api_impl::get_sidechain_address_by_account_and_sidechain(account_id_type account, peerplays_sidechain::sidechain_type sidechain)const +fc::optional database_api_impl::get_sidechain_address_by_account_and_sidechain(account_id_type account, sidechain_type sidechain)const { const auto& idx = _db.get_index_type().indices().get(); auto itr = idx.find( boost::make_tuple( account, sidechain ) ); diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index a89224b4..6e8e64cb 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -679,7 +679,7 @@ class database_api * @param sidechain Sidechain for which addresses should be retrieved * @return The sidechain addresses objects, or null if the sidechain does not have any addresses */ - vector> get_sidechain_addresses_by_sidechain(peerplays_sidechain::sidechain_type sidechain)const; + vector> get_sidechain_addresses_by_sidechain(sidechain_type sidechain)const; /** * @brief Get the sidechain addresses for a given account and sidechain @@ -687,7 +687,7 @@ class database_api * @param sidechain Sidechain for which address should be retrieved * @return The sidechain addresses objects, or null if the account does not have a sidechain addresses for a given sidechain */ - fc::optional get_sidechain_address_by_account_and_sidechain(account_id_type account, peerplays_sidechain::sidechain_type sidechain)const; + fc::optional get_sidechain_address_by_account_and_sidechain(account_id_type account, sidechain_type sidechain)const; /** * @brief Get the total number of sidechain addresses registered with the blockchain diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 755c313d..9c146ea9 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -684,10 +684,11 @@ void database::update_active_sons() // Compare current and to-be lists of active sons auto cur_active_sons = gpo.active_sons; vector new_active_sons; + const auto &acc = get(gpo.parameters.son_account()); for( const son_object& son : sons ) { son_info swi; swi.son_id = son.id; - swi.total_votes = son.total_votes; + swi.weight = acc.active.account_auths.at(son.son_account); swi.signing_key = son.signing_key; swi.sidechain_public_keys = son.sidechain_public_keys; new_active_sons.push_back(swi); diff --git a/libraries/chain/include/graphene/chain/protocol/sidechain_address.hpp b/libraries/chain/include/graphene/chain/protocol/sidechain_address.hpp index e79f65de..2702ce49 100644 --- a/libraries/chain/include/graphene/chain/protocol/sidechain_address.hpp +++ b/libraries/chain/include/graphene/chain/protocol/sidechain_address.hpp @@ -11,7 +11,7 @@ namespace graphene { namespace chain { asset fee; account_id_type sidechain_address_account; - graphene::peerplays_sidechain::sidechain_type sidechain; + sidechain_type sidechain; string deposit_address; string withdraw_address; @@ -26,7 +26,7 @@ namespace graphene { namespace chain { asset fee; sidechain_address_id_type sidechain_address_id; account_id_type sidechain_address_account; - graphene::peerplays_sidechain::sidechain_type sidechain; + sidechain_type sidechain; optional deposit_address; optional withdraw_address; @@ -41,7 +41,7 @@ namespace graphene { namespace chain { asset fee; sidechain_address_id_type sidechain_address_id; account_id_type sidechain_address_account; - graphene::peerplays_sidechain::sidechain_type sidechain; + sidechain_type sidechain; account_id_type fee_payer()const { return sidechain_address_account; } share_type calculate_fee(const fee_parameters_type& k)const { return 0; } diff --git a/libraries/chain/include/graphene/chain/protocol/son.hpp b/libraries/chain/include/graphene/chain/protocol/son.hpp index 3dfbc52d..fc6a3e0f 100644 --- a/libraries/chain/include/graphene/chain/protocol/son.hpp +++ b/libraries/chain/include/graphene/chain/protocol/son.hpp @@ -13,7 +13,7 @@ namespace graphene { namespace chain { std::string url; vesting_balance_id_type deposit; public_key_type signing_key; - flat_map sidechain_public_keys; + flat_map sidechain_public_keys; vesting_balance_id_type pay_vb; account_id_type fee_payer()const { return owner_account; } @@ -30,7 +30,7 @@ namespace graphene { namespace chain { optional new_url; optional new_deposit; optional new_signing_key; - optional> new_sidechain_public_keys; + optional> new_sidechain_public_keys; optional new_pay_vb; account_id_type fee_payer()const { return owner_account; } diff --git a/libraries/chain/include/graphene/chain/protocol/son_wallet.hpp b/libraries/chain/include/graphene/chain/protocol/son_wallet.hpp index f41cfa1f..5194bed2 100644 --- a/libraries/chain/include/graphene/chain/protocol/son_wallet.hpp +++ b/libraries/chain/include/graphene/chain/protocol/son_wallet.hpp @@ -25,7 +25,7 @@ namespace graphene { namespace chain { account_id_type payer; son_wallet_id_type son_wallet_id; - graphene::peerplays_sidechain::sidechain_type sidechain; + sidechain_type sidechain; string address; account_id_type fee_payer()const { return payer; } diff --git a/libraries/chain/include/graphene/chain/sidechain_address_object.hpp b/libraries/chain/include/graphene/chain/sidechain_address_object.hpp index 86e1b16d..ca28231b 100644 --- a/libraries/chain/include/graphene/chain/sidechain_address_object.hpp +++ b/libraries/chain/include/graphene/chain/sidechain_address_object.hpp @@ -21,12 +21,12 @@ namespace graphene { namespace chain { static const uint8_t type_id = sidechain_address_object_type; account_id_type sidechain_address_account; - graphene::peerplays_sidechain::sidechain_type sidechain; + sidechain_type sidechain; string deposit_address; string withdraw_address; sidechain_address_object() : - sidechain(graphene::peerplays_sidechain::sidechain_type::bitcoin), + sidechain(sidechain_type::bitcoin), deposit_address(""), withdraw_address("") {} }; @@ -45,17 +45,17 @@ namespace graphene { namespace chain { member >, ordered_non_unique< tag, - member + member >, ordered_unique< tag, composite_key, - member + member > >, ordered_unique< tag, composite_key, + member, member > > diff --git a/libraries/chain/include/graphene/chain/sidechain_defs.hpp b/libraries/chain/include/graphene/chain/sidechain_defs.hpp index f51b9eaf..6bbc8b5c 100644 --- a/libraries/chain/include/graphene/chain/sidechain_defs.hpp +++ b/libraries/chain/include/graphene/chain/sidechain_defs.hpp @@ -5,6 +5,7 @@ namespace graphene { namespace chain { enum class sidechain_type { + unknown, bitcoin, ethereum, eos, @@ -13,13 +14,8 @@ enum class sidechain_type { } } -namespace graphene { namespace peerplays_sidechain { - -using sidechain_type = graphene::chain::sidechain_type; - -} } - FC_REFLECT_ENUM(graphene::chain::sidechain_type, + (unknown) (bitcoin) (ethereum) (eos) diff --git a/libraries/chain/include/graphene/chain/son_info.hpp b/libraries/chain/include/graphene/chain/son_info.hpp index bc0c823b..b85fb03a 100644 --- a/libraries/chain/include/graphene/chain/son_info.hpp +++ b/libraries/chain/include/graphene/chain/son_info.hpp @@ -12,14 +12,14 @@ namespace graphene { namespace chain { */ struct son_info { son_id_type son_id; - uint64_t total_votes = 0; + weight_type weight = 0; public_key_type signing_key; - flat_map sidechain_public_keys; + flat_map sidechain_public_keys; bool operator==(const son_info& rhs) { bool son_sets_equal = (son_id == rhs.son_id) && - (total_votes == rhs.total_votes) && + (weight == rhs.weight) && (signing_key == rhs.signing_key) && (sidechain_public_keys.size() == rhs.sidechain_public_keys.size()); @@ -33,4 +33,7 @@ namespace graphene { namespace chain { } } FC_REFLECT( graphene::chain::son_info, - (son_id)(total_votes)(signing_key)(sidechain_public_keys) ) + (son_id) + (weight) + (signing_key) + (sidechain_public_keys) ) diff --git a/libraries/chain/include/graphene/chain/son_object.hpp b/libraries/chain/include/graphene/chain/son_object.hpp index 5aee1265..0bc87ecc 100644 --- a/libraries/chain/include/graphene/chain/son_object.hpp +++ b/libraries/chain/include/graphene/chain/son_object.hpp @@ -70,7 +70,7 @@ namespace graphene { namespace chain { vesting_balance_id_type pay_vb; son_statistics_id_type statistics; son_status status = son_status::inactive; - flat_map sidechain_public_keys; + flat_map sidechain_public_keys; void pay_son_fee(share_type pay, database& db); }; diff --git a/libraries/chain/include/graphene/chain/son_wallet_deposit_object.hpp b/libraries/chain/include/graphene/chain/son_wallet_deposit_object.hpp index 6ddc44c2..80c749d2 100644 --- a/libraries/chain/include/graphene/chain/son_wallet_deposit_object.hpp +++ b/libraries/chain/include/graphene/chain/son_wallet_deposit_object.hpp @@ -18,7 +18,7 @@ namespace graphene { namespace chain { static const uint8_t type_id = son_wallet_deposit_object_type; time_point_sec timestamp; - sidechain_type sidechain; + sidechain_type sidechain = sidechain_type::unknown; std::string sidechain_uid; std::string sidechain_transaction_id; std::string sidechain_from; @@ -29,34 +29,29 @@ namespace graphene { namespace chain { chain::account_id_type peerplays_to; chain::asset peerplays_asset; - std::set expected_reports; + std::map expected_reports; std::set received_reports; - bool processed; + bool confirmed = false; + + bool processed = false; }; - struct by_sidechain; struct by_sidechain_uid; - struct by_processed; - struct by_sidechain_and_processed; + struct by_sidechain_and_confirmed_and_processed; using son_wallet_deposit_multi_index_type = multi_index_container< son_wallet_deposit_object, indexed_by< ordered_unique< tag, member >, - ordered_non_unique< tag, - member - >, ordered_unique< tag, member >, - ordered_non_unique< tag, - member - >, - ordered_non_unique< tag, + ordered_non_unique< tag, composite_key, + member, member > > @@ -70,4 +65,4 @@ FC_REFLECT_DERIVED( graphene::chain::son_wallet_deposit_object, (graphene::db::o (sidechain_uid) (sidechain_transaction_id) (sidechain_from) (sidechain_to) (sidechain_currency) (sidechain_amount) (peerplays_from) (peerplays_to) (peerplays_asset) (expected_reports) (received_reports) - (processed) ) + (confirmed) (processed) ) diff --git a/libraries/chain/include/graphene/chain/son_wallet_withdraw_object.hpp b/libraries/chain/include/graphene/chain/son_wallet_withdraw_object.hpp index ef39aadf..1afbe8b6 100644 --- a/libraries/chain/include/graphene/chain/son_wallet_withdraw_object.hpp +++ b/libraries/chain/include/graphene/chain/son_wallet_withdraw_object.hpp @@ -18,7 +18,7 @@ namespace graphene { namespace chain { static const uint8_t type_id = son_wallet_withdraw_object_type; time_point_sec timestamp; - sidechain_type sidechain; + sidechain_type sidechain = sidechain_type::unknown; std::string peerplays_uid; std::string peerplays_transaction_id; chain::account_id_type peerplays_from; @@ -28,16 +28,16 @@ namespace graphene { namespace chain { std::string withdraw_currency; safe withdraw_amount; - std::set expected_reports; + std::map expected_reports; std::set received_reports; - bool processed; + bool confirmed = false; + + bool processed = false; }; struct by_peerplays_uid; - struct by_withdraw_sidechain; - struct by_processed; - struct by_withdraw_sidechain_and_processed; + struct by_withdraw_sidechain_and_confirmed_and_processed; using son_wallet_withdraw_multi_index_type = multi_index_container< son_wallet_withdraw_object, indexed_by< @@ -47,15 +47,10 @@ namespace graphene { namespace chain { ordered_unique< tag, member >, - ordered_non_unique< tag, - member - >, - ordered_non_unique< tag, - member - >, - ordered_non_unique< tag, + ordered_non_unique< tag, composite_key, + member, member > > @@ -69,4 +64,4 @@ FC_REFLECT_DERIVED( graphene::chain::son_wallet_withdraw_object, (graphene::db:: (peerplays_uid) (peerplays_transaction_id) (peerplays_from) (peerplays_asset) (withdraw_sidechain) (withdraw_address) (withdraw_currency) (withdraw_amount) (expected_reports) (received_reports) - (processed) ) + (confirmed) (processed) ) diff --git a/libraries/chain/sidechain_transaction_evaluator.cpp b/libraries/chain/sidechain_transaction_evaluator.cpp index ab6e69a8..df3f2fd0 100644 --- a/libraries/chain/sidechain_transaction_evaluator.cpp +++ b/libraries/chain/sidechain_transaction_evaluator.cpp @@ -36,7 +36,7 @@ object_id_type sidechain_transaction_create_evaluator::do_apply(const sidechain_ return std::make_pair(si.son_id, std::string()); }); for (const auto &si : op.signers) { - sto.total_weight = sto.total_weight + si.total_votes; + sto.total_weight = sto.total_weight + si.weight; } sto.sidechain_transaction = ""; sto.current_weight = 0; @@ -91,7 +91,7 @@ object_id_type sidechain_transaction_sign_evaluator::do_apply(const sidechain_tr } for (size_t i = 0; i < sto.signers.size(); i++) { if (sto.signers.at(i).son_id == son_obj->id) { - sto.current_weight = sto.current_weight + sto.signers.at(i).total_votes; + sto.current_weight = sto.current_weight + sto.signers.at(i).weight; } } sto.complete = op.complete; diff --git a/libraries/chain/son_wallet_deposit_evaluator.cpp b/libraries/chain/son_wallet_deposit_evaluator.cpp index e2734ea4..643c967c 100644 --- a/libraries/chain/son_wallet_deposit_evaluator.cpp +++ b/libraries/chain/son_wallet_deposit_evaluator.cpp @@ -8,12 +8,52 @@ namespace graphene { namespace chain { void_result create_son_wallet_deposit_evaluator::do_evaluate(const son_wallet_deposit_create_operation& op) -{ try{ +{ try { FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); - FC_ASSERT( op.payer == db().get_global_properties().parameters.son_account(), "SON paying account must be set as payer." ); - const auto &idx = db().get_index_type().indices().get(); - FC_ASSERT(idx.find(op.son_id) != idx.end(), "Statistic object for a given SON ID does not exists"); + const auto &son_idx = db().get_index_type().indices().get(); + const auto so = son_idx.find(op.son_id); + FC_ASSERT(so != son_idx.end(), "SON not found"); + FC_ASSERT(so->son_account == op.payer, "Payer is not SON account owner"); + + const auto &ss_idx = db().get_index_type().indices().get(); + FC_ASSERT(ss_idx.find(op.son_id) != ss_idx.end(), "Statistic object for a given SON ID does not exists"); + + const auto &swdo_idx = db().get_index_type().indices().get(); + const auto swdo = swdo_idx.find(op.sidechain_uid); + if (swdo == swdo_idx.end()) { + auto &gpo = db().get_global_properties(); + bool expected = false; + for (auto &si : gpo.active_sons) { + if (op.son_id == si.son_id) { + expected = true; + break; + } + } + FC_ASSERT(expected, "Only active SON can create deposit"); + } else { + bool exactly_the_same = true; + exactly_the_same = exactly_the_same && (swdo->sidechain == op.sidechain); + exactly_the_same = exactly_the_same && (swdo->sidechain_uid == op.sidechain_uid); + exactly_the_same = exactly_the_same && (swdo->sidechain_transaction_id == op.sidechain_transaction_id); + exactly_the_same = exactly_the_same && (swdo->sidechain_from == op.sidechain_from); + exactly_the_same = exactly_the_same && (swdo->sidechain_to == op.sidechain_to); + exactly_the_same = exactly_the_same && (swdo->sidechain_currency == op.sidechain_currency); + exactly_the_same = exactly_the_same && (swdo->sidechain_amount == op.sidechain_amount); + exactly_the_same = exactly_the_same && (swdo->peerplays_from == op.peerplays_from); + exactly_the_same = exactly_the_same && (swdo->peerplays_to == op.peerplays_to); + exactly_the_same = exactly_the_same && (swdo->peerplays_asset == op.peerplays_asset); + FC_ASSERT(exactly_the_same, "Invalid withdraw confirmation"); + + bool expected = false; + for (auto &exp : swdo->expected_reports) { + if (op.son_id == exp.first) { + expected = true; + break; + } + } + FC_ASSERT(expected, "Confirmation from this SON not expected"); + } return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } @@ -38,7 +78,7 @@ object_id_type create_son_wallet_deposit_evaluator::do_apply(const son_wallet_de auto &gpo = db().get_global_properties(); for (auto &si : gpo.active_sons) { - swdo.expected_reports.insert(si.son_id); + swdo.expected_reports.insert(std::make_pair(si.son_id, si.weight)); auto stats_itr = db().get_index_type().indices().get().find(si.son_id); db().modify(*stats_itr, [&op, &si](son_statistics_object &sso) { @@ -51,12 +91,32 @@ object_id_type create_son_wallet_deposit_evaluator::do_apply(const son_wallet_de swdo.received_reports.insert(op.son_id); + uint64_t total_weight = 0; + for (const auto exp : swdo.expected_reports) { + total_weight = total_weight + exp.second; + } + uint64_t current_weight = 0; + for (const auto rec : swdo.received_reports) { + current_weight = current_weight + swdo.expected_reports.find(rec)->second; + } + swdo.confirmed = (current_weight > (total_weight * 2 / 3)); + swdo.processed = false; }); return new_son_wallet_deposit_object.id; } else { db().modify(*itr, [&op](son_wallet_deposit_object &swdo) { swdo.received_reports.insert(op.son_id); + + uint64_t total_weight = 0; + for (const auto exp : swdo.expected_reports) { + total_weight = total_weight + exp.second; + } + uint64_t current_weight = 0; + for (const auto rec : swdo.received_reports) { + current_weight = current_weight + swdo.expected_reports.find(rec)->second; + } + swdo.confirmed = (current_weight > (total_weight * 2 / 3)); }); auto stats_itr = db().get_index_type().indices().get().find(op.son_id); db().modify(*stats_itr, [&op](son_statistics_object &sso) { diff --git a/libraries/chain/son_wallet_withdraw_evaluator.cpp b/libraries/chain/son_wallet_withdraw_evaluator.cpp index 7a3930b1..8f843bd1 100644 --- a/libraries/chain/son_wallet_withdraw_evaluator.cpp +++ b/libraries/chain/son_wallet_withdraw_evaluator.cpp @@ -8,12 +8,51 @@ namespace graphene { namespace chain { void_result create_son_wallet_withdraw_evaluator::do_evaluate(const son_wallet_withdraw_create_operation& op) -{ try{ +{ try { FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); - FC_ASSERT( op.payer == db().get_global_properties().parameters.son_account(), "SON paying account must be set as payer." ); - const auto &idx = db().get_index_type().indices().get(); - FC_ASSERT(idx.find(op.son_id) != idx.end(), "Statistic object for a given SON ID does not exists"); + const auto &son_idx = db().get_index_type().indices().get(); + const auto so = son_idx.find(op.son_id); + FC_ASSERT(so != son_idx.end(), "SON not found"); + FC_ASSERT(so->son_account == op.payer, "Payer is not SON account owner"); + + const auto &ss_idx = db().get_index_type().indices().get(); + FC_ASSERT(ss_idx.find(op.son_id) != ss_idx.end(), "Statistic object for a given SON ID does not exists"); + + const auto &swwo_idx = db().get_index_type().indices().get(); + const auto swwo = swwo_idx.find(op.peerplays_uid); + if (swwo == swwo_idx.end()) { + auto &gpo = db().get_global_properties(); + bool expected = false; + for (auto &si : gpo.active_sons) { + if (op.son_id == si.son_id) { + expected = true; + break; + } + } + FC_ASSERT(expected, "Only active SON can create deposit"); + } else { + bool exactly_the_same = true; + exactly_the_same = exactly_the_same && (swwo->sidechain == op.sidechain); + exactly_the_same = exactly_the_same && (swwo->peerplays_uid == op.peerplays_uid); + exactly_the_same = exactly_the_same && (swwo->peerplays_transaction_id == op.peerplays_transaction_id); + exactly_the_same = exactly_the_same && (swwo->peerplays_from == op.peerplays_from); + exactly_the_same = exactly_the_same && (swwo->peerplays_asset == op.peerplays_asset); + exactly_the_same = exactly_the_same && (swwo->withdraw_sidechain == op.withdraw_sidechain); + exactly_the_same = exactly_the_same && (swwo->withdraw_address == op.withdraw_address); + exactly_the_same = exactly_the_same && (swwo->withdraw_currency == op.withdraw_currency); + exactly_the_same = exactly_the_same && (swwo->withdraw_amount == op.withdraw_amount); + FC_ASSERT(exactly_the_same, "Invalid withdraw confirmation"); + + bool expected = false; + for (auto &exp : swwo->expected_reports) { + if (op.son_id == exp.first) { + expected = true; + break; + } + } + FC_ASSERT(expected, "Confirmation from this SON not expected"); + } return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } @@ -37,7 +76,7 @@ object_id_type create_son_wallet_withdraw_evaluator::do_apply(const son_wallet_w auto &gpo = db().get_global_properties(); for (auto &si : gpo.active_sons) { - swwo.expected_reports.insert(si.son_id); + swwo.expected_reports.insert(std::make_pair(si.son_id, si.weight)); auto stats_itr = db().get_index_type().indices().get().find(si.son_id); db().modify(*stats_itr, [&op, &si](son_statistics_object &sso) { @@ -50,12 +89,32 @@ object_id_type create_son_wallet_withdraw_evaluator::do_apply(const son_wallet_w swwo.received_reports.insert(op.son_id); + uint64_t total_weight = 0; + for (const auto exp : swwo.expected_reports) { + total_weight = total_weight + exp.second; + } + uint64_t current_weight = 0; + for (const auto rec : swwo.received_reports) { + current_weight = current_weight + swwo.expected_reports.find(rec)->second; + } + swwo.confirmed = (current_weight > (total_weight * 2 / 3)); + swwo.processed = false; }); return new_son_wallet_withdraw_object.id; } else { db().modify(*itr, [&op](son_wallet_withdraw_object &swwo) { swwo.received_reports.insert(op.son_id); + + uint64_t total_weight = 0; + for (const auto exp : swwo.expected_reports) { + total_weight = total_weight + exp.second; + } + uint64_t current_weight = 0; + for (const auto rec : swwo.received_reports) { + current_weight = current_weight + swwo.expected_reports.find(rec)->second; + } + swwo.confirmed = (current_weight > (total_weight * 2 / 3)); }); auto stats_itr = db().get_index_type().indices().get().find(op.son_id); db().modify(*stats_itr, [&op](son_statistics_object &sso) { diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/defs.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/defs.hpp index 6dd49252..95026c1b 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/defs.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/defs.hpp @@ -14,6 +14,8 @@ namespace graphene { namespace peerplays_sidechain { +using namespace graphene::chain; + using bytes = std::vector; struct prev_out { @@ -64,9 +66,9 @@ struct sidechain_event_data { std::string sidechain_to; std::string sidechain_currency; fc::safe sidechain_amount; - chain::account_id_type peerplays_from; - chain::account_id_type peerplays_to; - chain::asset peerplays_asset; + account_id_type peerplays_from; + account_id_type peerplays_to; + asset peerplays_asset; }; }} // namespace graphene::peerplays_sidechain diff --git a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp index 75a89870..f22bebc9 100644 --- a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp +++ b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp @@ -442,16 +442,6 @@ void peerplays_sidechain_plugin_impl::approve_proposals() { continue; } - if (op_idx_0 == chain::operation::tag::value) { - approve_proposal(get_current_son_id(), proposal.id); - continue; - } - - if (op_idx_0 == chain::operation::tag::value) { - approve_proposal(get_current_son_id(), proposal.id); - continue; - } - if (op_idx_0 == chain::operation::tag::value) { approve_proposal(get_current_son_id(), proposal.id); continue; diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp index 31b5da39..34a1cd85 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp @@ -69,39 +69,32 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_ // Deposit request if ((sed.peerplays_to == gpo.parameters.son_account()) && (sed.sidechain_currency.compare("1.3.0") != 0)) { - son_wallet_deposit_create_operation op; - op.payer = gpo.parameters.son_account(); - //op.son_id = ; // to be filled for each son - op.timestamp = sed.timestamp; - op.sidechain = sed.sidechain; - op.sidechain_uid = sed.sidechain_uid; - op.sidechain_transaction_id = sed.sidechain_transaction_id; - op.sidechain_from = sed.sidechain_from; - op.sidechain_to = sed.sidechain_to; - op.sidechain_currency = sed.sidechain_currency; - op.sidechain_amount = sed.sidechain_amount; - op.peerplays_from = sed.peerplays_from; - op.peerplays_to = sed.peerplays_to; - op.peerplays_asset = sed.peerplays_asset; for (son_id_type son_id : plugin.get_sons()) { if (plugin.is_active_son(son_id)) { + son_wallet_deposit_create_operation op; + op.payer = plugin.get_son_object(son_id).son_account; op.son_id = son_id; + op.timestamp = sed.timestamp; + op.sidechain = sed.sidechain; + op.sidechain_uid = sed.sidechain_uid; + op.sidechain_transaction_id = sed.sidechain_transaction_id; + op.sidechain_from = sed.sidechain_from; + op.sidechain_to = sed.sidechain_to; + op.sidechain_currency = sed.sidechain_currency; + op.sidechain_amount = sed.sidechain_amount; + op.peerplays_from = sed.peerplays_from; + op.peerplays_to = sed.peerplays_to; + op.peerplays_asset = sed.peerplays_asset; - proposal_create_operation proposal_op; - proposal_op.fee_paying_account = plugin.get_son_object(son_id).son_account; - proposal_op.proposed_ops.emplace_back(op); - uint32_t lifetime = (gpo.parameters.block_interval * gpo.active_witnesses.size()) * 3; - proposal_op.expiration_time = time_point_sec(database.head_block_time().sec_since_epoch() + lifetime); - - signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(son_id), proposal_op); + signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(son_id), op); try { database.push_transaction(trx, database::validation_steps::skip_block_size_check); if (plugin.app().p2p_node()) plugin.app().p2p_node()->broadcast(net::trx_message(trx)); } catch (fc::exception e) { - elog("Sending proposal for son wallet deposit create operation by ${son} failed with exception ${e}", ("son", son_id)("e", e.what())); + elog("Sending son wallet deposit create operation by ${son} failed with exception ${e}", ("son", son_id)("e", e.what())); } } } @@ -116,38 +109,30 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_ if (addr_itr == sidechain_addresses_idx.end()) return; - son_wallet_withdraw_create_operation op; - op.payer = gpo.parameters.son_account(); - //op.son_id = ; // to be filled for each son - op.timestamp = sed.timestamp; - op.sidechain = sed.sidechain; - op.peerplays_uid = sed.sidechain_uid; - op.peerplays_transaction_id = sed.sidechain_transaction_id; - op.peerplays_from = sed.peerplays_from; - op.peerplays_asset = sed.peerplays_asset; - op.withdraw_sidechain = sidechain_type::bitcoin; // BTC payout only (for now) - op.withdraw_address = addr_itr->withdraw_address; // BTC payout only (for now) - op.withdraw_currency = "BTC"; // BTC payout only (for now) - op.withdraw_amount = sed.peerplays_asset.amount * 1000; // BTC payout only (for now) - for (son_id_type son_id : plugin.get_sons()) { if (plugin.is_active_son(son_id)) { + son_wallet_withdraw_create_operation op; + op.payer = plugin.get_son_object(son_id).son_account; op.son_id = son_id; + op.timestamp = sed.timestamp; + op.sidechain = sed.sidechain; + op.peerplays_uid = sed.sidechain_uid; + op.peerplays_transaction_id = sed.sidechain_transaction_id; + op.peerplays_from = sed.peerplays_from; + op.peerplays_asset = sed.peerplays_asset; + op.withdraw_sidechain = sidechain_type::bitcoin; // BTC payout only (for now) + op.withdraw_address = addr_itr->withdraw_address; // BTC payout only (for now) + op.withdraw_currency = "BTC"; // BTC payout only (for now) + op.withdraw_amount = sed.peerplays_asset.amount * 1000; // BTC payout only (for now) - proposal_create_operation proposal_op; - proposal_op.fee_paying_account = plugin.get_son_object(son_id).son_account; - proposal_op.proposed_ops.emplace_back(op); - uint32_t lifetime = (gpo.parameters.block_interval * gpo.active_witnesses.size()) * 3; - proposal_op.expiration_time = time_point_sec(database.head_block_time().sec_since_epoch() + lifetime); - - signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(son_id), proposal_op); + signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(son_id), op); try { database.push_transaction(trx, database::validation_steps::skip_block_size_check); if (plugin.app().p2p_node()) plugin.app().p2p_node()->broadcast(net::trx_message(trx)); } catch (fc::exception e) { - elog("Sending proposal for son wallet withdraw create operation by ${son} failed with exception ${e}", ("son", son_id)("e", e.what())); + elog("Sending son wallet withdraw create operation by ${son} failed with exception ${e}", ("son", son_id)("e", e.what())); } } } @@ -158,8 +143,8 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_ } void sidechain_net_handler::process_deposits() { - const auto &idx = database.get_index_type().indices().get(); - const auto &idx_range = idx.equal_range(std::make_tuple(sidechain, false)); + const auto &idx = database.get_index_type().indices().get(); + const auto &idx_range = idx.equal_range(std::make_tuple(sidechain, true, false)); std::for_each(idx_range.first, idx_range.second, [&](const son_wallet_deposit_object &swdo) { ilog("Deposit to process: ${swdo}", ("swdo", swdo)); @@ -203,8 +188,8 @@ void sidechain_net_handler::process_deposits() { } void sidechain_net_handler::process_withdrawals() { - const auto &idx = database.get_index_type().indices().get(); - const auto &idx_range = idx.equal_range(std::make_tuple(sidechain, false)); + const auto &idx = database.get_index_type().indices().get(); + const auto &idx_range = idx.equal_range(std::make_tuple(sidechain, true, false)); std::for_each(idx_range.first, idx_range.second, [&](const son_wallet_withdraw_object &swwo) { ilog("Withdraw to process: ${swwo}", ("swwo", swwo)); diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index dbc9e639..ac7796e1 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -1336,7 +1336,7 @@ class wallet_api string url, vesting_balance_id_type deposit_id, vesting_balance_id_type pay_vb_id, - flat_map sidechain_public_keys, + flat_map sidechain_public_keys, bool broadcast = false); /** @@ -1351,7 +1351,7 @@ class wallet_api signed_transaction update_son(string owner_account, string url, string block_signing_key, - flat_map sidechain_public_keys, + flat_map sidechain_public_keys, bool broadcast = false); @@ -1438,7 +1438,7 @@ class wallet_api * @returns the signed transaction adding sidechain address */ signed_transaction add_sidechain_address(string account, - peerplays_sidechain::sidechain_type sidechain, + sidechain_type sidechain, string deposit_address, string withdraw_address, bool broadcast = false); @@ -1455,7 +1455,7 @@ class wallet_api * @returns the signed transaction updating sidechain address */ signed_transaction update_sidechain_address(string account, - peerplays_sidechain::sidechain_type sidechain, + sidechain_type sidechain, string deposit_address, string withdraw_address, bool broadcast = false); @@ -1468,7 +1468,7 @@ class wallet_api * @returns the signed transaction updating sidechain address */ signed_transaction delete_sidechain_address(string account, - peerplays_sidechain::sidechain_type sidechain, + sidechain_type sidechain, bool broadcast = false); /** Retrieves all sidechain addresses owned by given account. @@ -1483,7 +1483,7 @@ class wallet_api * @param sidechain the name of the sidechain * @returns the list of all sidechain addresses registered for a given sidechain. */ - vector> get_sidechain_addresses_by_sidechain(peerplays_sidechain::sidechain_type sidechain); + vector> get_sidechain_addresses_by_sidechain(sidechain_type sidechain); /** Retrieves sidechain address owned by given account for a given sidechain. * @@ -1491,7 +1491,7 @@ class wallet_api * @param sidechain the name of the sidechain * @returns the sidechain address owned by given account for a given sidechain. */ - fc::optional get_sidechain_address_by_account_and_sidechain(string account, peerplays_sidechain::sidechain_type sidechain); + fc::optional get_sidechain_address_by_account_and_sidechain(string account, sidechain_type sidechain); /** Retrieves the total number of sidechain addresses registered in the system. * diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 89bc6415..112afc1a 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1937,7 +1937,7 @@ public: string url, vesting_balance_id_type deposit_id, vesting_balance_id_type pay_vb_id, - flat_map sidechain_public_keys, + flat_map sidechain_public_keys, bool broadcast /* = false */) { try { fc::scoped_lock lock(_resync_mutex); @@ -1966,7 +1966,7 @@ public: signed_transaction update_son(string owner_account, string url, string block_signing_key, - flat_map sidechain_public_keys, + flat_map sidechain_public_keys, bool broadcast /* = false */) { try { son_object son = get_son(owner_account); @@ -2096,7 +2096,7 @@ public: } FC_CAPTURE_AND_RETHROW() } signed_transaction add_sidechain_address(string account, - peerplays_sidechain::sidechain_type sidechain, + sidechain_type sidechain, string deposit_address, string withdraw_address, bool broadcast /* = false */) @@ -2118,7 +2118,7 @@ public: } FC_CAPTURE_AND_RETHROW() } signed_transaction update_sidechain_address(string account, - peerplays_sidechain::sidechain_type sidechain, + sidechain_type sidechain, string deposit_address, string withdraw_address, bool broadcast /* = false */) @@ -2144,7 +2144,7 @@ public: } FC_CAPTURE_AND_RETHROW() } signed_transaction delete_sidechain_address(string account, - peerplays_sidechain::sidechain_type sidechain, + sidechain_type sidechain, bool broadcast /* = false */) { try { account_id_type sidechain_address_account_id = get_account_id(account); @@ -4721,7 +4721,7 @@ signed_transaction wallet_api::create_son(string owner_account, string url, vesting_balance_id_type deposit_id, vesting_balance_id_type pay_vb_id, - flat_map sidechain_public_keys, + flat_map sidechain_public_keys, bool broadcast /* = false */) { return my->create_son(owner_account, url, deposit_id, pay_vb_id, sidechain_public_keys, broadcast); @@ -4730,7 +4730,7 @@ signed_transaction wallet_api::create_son(string owner_account, signed_transaction wallet_api::update_son(string owner_account, string url, string block_signing_key, - flat_map sidechain_public_keys, + flat_map sidechain_public_keys, bool broadcast /* = false */) { return my->update_son(owner_account, url, block_signing_key, sidechain_public_keys, broadcast); @@ -4778,7 +4778,7 @@ vector> wallet_api::get_son_wallets(uint32_t limit) } signed_transaction wallet_api::add_sidechain_address(string account, - peerplays_sidechain::sidechain_type sidechain, + sidechain_type sidechain, string deposit_address, string withdraw_address, bool broadcast /* = false */) @@ -4787,7 +4787,7 @@ signed_transaction wallet_api::add_sidechain_address(string account, } signed_transaction wallet_api::update_sidechain_address(string account, - peerplays_sidechain::sidechain_type sidechain, + sidechain_type sidechain, string deposit_address, string withdraw_address, bool broadcast /* = false */) @@ -4796,7 +4796,7 @@ signed_transaction wallet_api::update_sidechain_address(string account, } signed_transaction wallet_api::delete_sidechain_address(string account, - peerplays_sidechain::sidechain_type sidechain, + sidechain_type sidechain, bool broadcast /* = false */) { return my->delete_sidechain_address(account, sidechain, broadcast); @@ -4808,12 +4808,12 @@ vector> wallet_api::get_sidechain_addresses_b return my->_remote_db->get_sidechain_addresses_by_account(account_id); } -vector> wallet_api::get_sidechain_addresses_by_sidechain(peerplays_sidechain::sidechain_type sidechain) +vector> wallet_api::get_sidechain_addresses_by_sidechain(sidechain_type sidechain) { return my->_remote_db->get_sidechain_addresses_by_sidechain(sidechain); } -fc::optional wallet_api::get_sidechain_address_by_account_and_sidechain(string account, peerplays_sidechain::sidechain_type sidechain) +fc::optional wallet_api::get_sidechain_address_by_account_and_sidechain(string account, sidechain_type sidechain) { account_id_type account_id = get_account_id(account); return my->_remote_db->get_sidechain_address_by_account_and_sidechain(account_id, sidechain); diff --git a/tests/cli/son.cpp b/tests/cli/son.cpp index 7b1f395e..f640a1d7 100644 --- a/tests/cli/son.cpp +++ b/tests/cli/son.cpp @@ -40,7 +40,7 @@ public: } void create_son(const std::string& account_name, const std::string& son_url, - flat_map& sidechain_public_keys, + flat_map& sidechain_public_keys, bool generate_maintenance = true) { graphene::wallet::brain_key_info bki; @@ -112,16 +112,16 @@ BOOST_AUTO_TEST_CASE( create_sons ) BOOST_TEST_MESSAGE("SON cli wallet tests begin"); try { - flat_map sidechain_public_keys; + flat_map sidechain_public_keys; son_test_helper sth(*this); sidechain_public_keys.clear(); - sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 1"; + sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1"; sth.create_son("son1account", "http://son1", sidechain_public_keys); sidechain_public_keys.clear(); - sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 2"; + sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2"; sth.create_son("son2account", "http://son2", sidechain_public_keys); auto son1_obj = con.wallet_api_ptr->get_son("son1account"); @@ -146,10 +146,10 @@ BOOST_AUTO_TEST_CASE( cli_update_son ) { BOOST_TEST_MESSAGE("Cli get_son and update_son Test"); - flat_map sidechain_public_keys; + flat_map sidechain_public_keys; sidechain_public_keys.clear(); - sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 1"; + sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1"; son_test_helper sth(*this); sth.create_son("sonmember", "http://sonmember", sidechain_public_keys); @@ -163,7 +163,7 @@ BOOST_AUTO_TEST_CASE( cli_update_son ) // update SON sidechain_public_keys.clear(); - sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 2"; + sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2"; con.wallet_api_ptr->update_son("sonmember", "http://sonmember_updated", "", sidechain_public_keys, true); son_data = con.wallet_api_ptr->get_son("sonmember"); @@ -187,16 +187,16 @@ BOOST_AUTO_TEST_CASE( son_voting ) BOOST_TEST_MESSAGE("SON Vote cli wallet tests begin"); try { - flat_map sidechain_public_keys; + flat_map sidechain_public_keys; son_test_helper sth(*this); sidechain_public_keys.clear(); - sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 1"; + sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1"; sth.create_son("son1account", "http://son1", sidechain_public_keys); sidechain_public_keys.clear(); - sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 2"; + sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2"; sth.create_son("son2account", "http://son2", sidechain_public_keys); BOOST_TEST_MESSAGE("Voting for SONs"); @@ -267,16 +267,16 @@ BOOST_AUTO_TEST_CASE( delete_son ) BOOST_TEST_MESSAGE("SON delete cli wallet tests begin"); try { - flat_map sidechain_public_keys; + flat_map sidechain_public_keys; son_test_helper sth(*this); sidechain_public_keys.clear(); - sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 1"; + sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1"; sth.create_son("son1account", "http://son1", sidechain_public_keys); sidechain_public_keys.clear(); - sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 2"; + sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2"; sth.create_son("son2account", "http://son2", sidechain_public_keys); BOOST_TEST_MESSAGE("Deleting SONs"); @@ -315,13 +315,13 @@ BOOST_FIXTURE_TEST_CASE( select_top_fifteen_sons, cli_fixture ) gpo = con.wallet_api_ptr->get_global_properties(); unsigned int son_number = gpo.parameters.maximum_son_count; - flat_map sidechain_public_keys; + flat_map sidechain_public_keys; // create son accounts for(unsigned int i = 0; i < son_number + 1; i++) { sidechain_public_keys.clear(); - sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address " + fc::to_pretty_string(i); + sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address " + fc::to_pretty_string(i); sth.create_son("sonaccount" + fc::to_pretty_string(i), "http://son" + fc::to_pretty_string(i), sidechain_public_keys, @@ -390,16 +390,16 @@ BOOST_AUTO_TEST_CASE( list_son ) BOOST_TEST_MESSAGE("List SONs cli wallet tests begin"); try { - flat_map sidechain_public_keys; + flat_map sidechain_public_keys; son_test_helper sth(*this); sidechain_public_keys.clear(); - sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 1"; + sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1"; sth.create_son("son1account", "http://son1", sidechain_public_keys); sidechain_public_keys.clear(); - sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 2"; + sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2"; sth.create_son("son2account", "http://son2", sidechain_public_keys); auto res = con.wallet_api_ptr->list_sons("", 100); @@ -420,16 +420,16 @@ BOOST_AUTO_TEST_CASE( update_son_votes_test ) BOOST_TEST_MESSAGE("SON update_son_votes cli wallet tests begin"); try { - flat_map sidechain_public_keys; + flat_map sidechain_public_keys; son_test_helper sth(*this); sidechain_public_keys.clear(); - sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 1"; + sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1"; sth.create_son("son1account", "http://son1", sidechain_public_keys); sidechain_public_keys.clear(); - sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 2"; + sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2"; sth.create_son("son2account", "http://son2", sidechain_public_keys); BOOST_TEST_MESSAGE("Vote for 2 accounts with update_son_votes"); @@ -579,16 +579,16 @@ BOOST_AUTO_TEST_CASE( related_functions ) global_property_object gpo = con.wallet_api_ptr->get_global_properties(); BOOST_CHECK(gpo.active_sons.size() == 0); - flat_map sidechain_public_keys; + flat_map sidechain_public_keys; son_test_helper sth(*this); sidechain_public_keys.clear(); - sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 1"; + sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 1"; sth.create_son("son1account", "http://son1", sidechain_public_keys); sidechain_public_keys.clear(); - sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address 2"; + sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address 2"; sth.create_son("son2account", "http://son2", sidechain_public_keys); gpo = con.wallet_api_ptr->get_global_properties(); @@ -615,13 +615,13 @@ BOOST_FIXTURE_TEST_CASE( cli_list_active_sons, cli_fixture ) gpo = con.wallet_api_ptr->get_global_properties(); unsigned int son_number = gpo.parameters.maximum_son_count; - flat_map sidechain_public_keys; + flat_map sidechain_public_keys; // create son accounts for(unsigned int i = 0; i < son_number + 1; i++) { sidechain_public_keys.clear(); - sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address " + fc::to_pretty_string(i); + sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address " + fc::to_pretty_string(i); sth.create_son("sonaccount" + fc::to_pretty_string(i), "http://son" + fc::to_pretty_string(i), sidechain_public_keys, @@ -684,13 +684,13 @@ BOOST_AUTO_TEST_CASE( maintenance_test ) gpo = con.wallet_api_ptr->get_global_properties(); unsigned int son_number = gpo.parameters.maximum_son_count; - flat_map sidechain_public_keys; + flat_map sidechain_public_keys; // create son accounts for(unsigned int i = 0; i < son_number + 1; i++) { sidechain_public_keys.clear(); - sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin_address " + fc::to_pretty_string(i); + sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin_address " + fc::to_pretty_string(i); sth.create_son("sonaccount" + fc::to_pretty_string(i), "http://son" + fc::to_pretty_string(i), sidechain_public_keys, diff --git a/tests/tests/sidechain_addresses_test.cpp b/tests/tests/sidechain_addresses_test.cpp index e65cf11e..e3fb115f 100644 --- a/tests/tests/sidechain_addresses_test.cpp +++ b/tests/tests/sidechain_addresses_test.cpp @@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE( sidechain_address_add_test ) { sidechain_address_add_operation op; op.sidechain_address_account = alice_id; - op.sidechain = graphene::peerplays_sidechain::sidechain_type::bitcoin; + op.sidechain = sidechain_type::bitcoin; op.deposit_address = "deposit_address"; op.withdraw_address = "withdraw_address"; @@ -43,10 +43,10 @@ BOOST_AUTO_TEST_CASE( sidechain_address_add_test ) { const auto& idx = db.get_index_type().indices().get(); BOOST_REQUIRE( idx.size() == 1 ); - auto obj = idx.find( boost::make_tuple( alice_id, graphene::peerplays_sidechain::sidechain_type::bitcoin ) ); + auto obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin ) ); BOOST_REQUIRE( obj != idx.end() ); BOOST_CHECK( obj->sidechain_address_account == alice_id ); - BOOST_CHECK( obj->sidechain == graphene::peerplays_sidechain::sidechain_type::bitcoin ); + BOOST_CHECK( obj->sidechain == sidechain_type::bitcoin ); BOOST_CHECK( obj->deposit_address == "deposit_address" ); BOOST_CHECK( obj->withdraw_address == "withdraw_address" ); } @@ -61,7 +61,7 @@ BOOST_AUTO_TEST_CASE( sidechain_address_update_test ) { const auto& idx = db.get_index_type().indices().get(); BOOST_REQUIRE( idx.size() == 1 ); - auto obj = idx.find( boost::make_tuple( alice_id, graphene::peerplays_sidechain::sidechain_type::bitcoin ) ); + auto obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin ) ); BOOST_REQUIRE( obj != idx.end() ); std::string new_deposit_address = "new_deposit_address"; @@ -88,7 +88,7 @@ BOOST_AUTO_TEST_CASE( sidechain_address_update_test ) { const auto& idx = db.get_index_type().indices().get(); BOOST_REQUIRE( idx.size() == 1 ); - auto obj = idx.find( boost::make_tuple( alice_id, graphene::peerplays_sidechain::sidechain_type::bitcoin ) ); + auto obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin ) ); BOOST_REQUIRE( obj != idx.end() ); BOOST_CHECK( obj->sidechain_address_account == obj->sidechain_address_account ); BOOST_CHECK( obj->sidechain == obj->sidechain ); @@ -107,7 +107,7 @@ BOOST_AUTO_TEST_CASE( sidechain_address_delete_test ) { const auto& idx = db.get_index_type().indices().get(); BOOST_REQUIRE( idx.size() == 1 ); - auto obj = idx.find( boost::make_tuple( alice_id, graphene::peerplays_sidechain::sidechain_type::bitcoin ) ); + auto obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin ) ); BOOST_REQUIRE( obj != idx.end() ); { @@ -129,7 +129,7 @@ BOOST_AUTO_TEST_CASE( sidechain_address_delete_test ) { const auto& idx = db.get_index_type().indices().get(); BOOST_REQUIRE( idx.size() == 0 ); - auto obj = idx.find( boost::make_tuple( alice_id, graphene::peerplays_sidechain::sidechain_type::bitcoin ) ); + auto obj = idx.find( boost::make_tuple( alice_id, sidechain_type::bitcoin ) ); BOOST_REQUIRE( obj == idx.end() ); } } diff --git a/tests/tests/son_operations_tests.cpp b/tests/tests/son_operations_tests.cpp index a917e550..050b9c65 100644 --- a/tests/tests/son_operations_tests.cpp +++ b/tests/tests/son_operations_tests.cpp @@ -83,8 +83,8 @@ BOOST_AUTO_TEST_CASE( create_son_test ) { // alice became son { - flat_map sidechain_public_keys; - sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin address"; + flat_map sidechain_public_keys; + sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin address"; son_create_operation op; op.owner_account = alice_id; @@ -105,7 +105,7 @@ BOOST_AUTO_TEST_CASE( create_son_test ) { BOOST_REQUIRE( obj != idx.end() ); BOOST_CHECK( obj->url == test_url ); BOOST_CHECK( obj->signing_key == alice_public_key ); - BOOST_CHECK( obj->sidechain_public_keys.at(graphene::peerplays_sidechain::sidechain_type::bitcoin) == "bitcoin address" ); + BOOST_CHECK( obj->sidechain_public_keys.at(sidechain_type::bitcoin) == "bitcoin address" ); BOOST_CHECK( obj->deposit.instance == deposit.instance.value ); BOOST_CHECK( obj->pay_vb.instance == payment.instance.value ); } @@ -118,8 +118,8 @@ BOOST_AUTO_TEST_CASE( update_son_test ) { std::string new_url = "https://anewurl.com"; { - flat_map sidechain_public_keys; - sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "new bitcoin address"; + flat_map sidechain_public_keys; + sidechain_public_keys[sidechain_type::bitcoin] = "new bitcoin address"; son_update_operation op; op.son_id = son_id_type(0); @@ -138,7 +138,7 @@ BOOST_AUTO_TEST_CASE( update_son_test ) { auto obj = idx.find( alice_id ); BOOST_REQUIRE( obj != idx.end() ); BOOST_CHECK( obj->url == new_url ); - BOOST_CHECK( obj->sidechain_public_keys.at(graphene::peerplays_sidechain::sidechain_type::bitcoin) == "new bitcoin address" ); + BOOST_CHECK( obj->sidechain_public_keys.at(sidechain_type::bitcoin) == "new bitcoin address" ); } BOOST_AUTO_TEST_CASE( delete_son_test ) { diff --git a/tests/tests/son_wallet_tests.cpp b/tests/tests/son_wallet_tests.cpp index 7ef3abc0..cef29b54 100644 --- a/tests/tests/son_wallet_tests.cpp +++ b/tests/tests/son_wallet_tests.cpp @@ -71,8 +71,8 @@ BOOST_AUTO_TEST_CASE( son_wallet_recreate_test ) { // alice becomes son { - flat_map sidechain_public_keys; - sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin address"; + flat_map sidechain_public_keys; + sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin address"; son_create_operation op; op.owner_account = alice_id; @@ -126,8 +126,8 @@ BOOST_AUTO_TEST_CASE( son_wallet_recreate_test ) { // bob becomes son { - flat_map sidechain_public_keys; - sidechain_public_keys[graphene::peerplays_sidechain::sidechain_type::bitcoin] = "bitcoin address"; + flat_map sidechain_public_keys; + sidechain_public_keys[sidechain_type::bitcoin] = "bitcoin address"; son_create_operation op; op.owner_account = bob_id; @@ -157,18 +157,18 @@ BOOST_AUTO_TEST_CASE( son_wallet_recreate_test ) { { son_info si; si.son_id = son_id_type(0); - si.total_votes = 1000; + si.weight = 1000; si.signing_key = alice_public_key; - si.sidechain_public_keys[peerplays_sidechain::sidechain_type::bitcoin] = ""; + si.sidechain_public_keys[sidechain_type::bitcoin] = ""; op.sons.push_back(si); } { son_info si; si.son_id = son_id_type(1); - si.total_votes = 1000; + si.weight = 1000; si.signing_key = bob_public_key; - si.sidechain_public_keys[peerplays_sidechain::sidechain_type::bitcoin] = ""; + si.sidechain_public_keys[sidechain_type::bitcoin] = ""; op.sons.push_back(si); } @@ -201,7 +201,7 @@ BOOST_AUTO_TEST_CASE( son_wallet_update_test ) { op.payer = db.get_global_properties().parameters.son_account(); op.son_wallet_id = son_wallet_id_type(0); - op.sidechain = graphene::peerplays_sidechain::sidechain_type::bitcoin; + op.sidechain = sidechain_type::bitcoin; op.address = "bitcoin address"; trx.operations.push_back(op); @@ -217,7 +217,7 @@ BOOST_AUTO_TEST_CASE( son_wallet_update_test ) { BOOST_REQUIRE( idx.size() == 1 ); auto obj = idx.find(son_wallet_id_type(0)); BOOST_REQUIRE( obj != idx.end() ); - BOOST_REQUIRE( obj->addresses.at(graphene::peerplays_sidechain::sidechain_type::bitcoin) == "bitcoin address" ); + BOOST_REQUIRE( obj->addresses.at(sidechain_type::bitcoin) == "bitcoin address" ); } }