From a9cfadc500dd2c4547bf54818f998b9b88b482f5 Mon Sep 17 00:00:00 2001 From: gladcow Date: Sun, 23 Feb 2020 19:31:51 +0300 Subject: [PATCH 1/2] [SON-242] fix list_active_sons call after deleting an active son (#292) * test to reproduce error in list_active_sons after delete_son * prevent exception in list_active_list --- libraries/wallet/wallet.cpp | 21 ++++++++++++--------- tests/cli/son.cpp | 3 +++ 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 194254be..943b6f1c 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -1988,19 +1988,22 @@ public: }); std::vector> son_objects = _remote_db->get_sons(son_ids); vector owners; - owners.resize(son_objects.size()); - std::transform(son_objects.begin(), son_objects.end(), owners.begin(), - [](const fc::optional& obj) { - FC_ASSERT(obj, "Invalid active SONs list in global properties."); - return obj->son_account; - }); + for(auto obj: son_objects) + { + if (obj) + owners.push_back(obj->son_account); + } vector> accs = _remote_db->get_accounts(owners); + std::remove_if(son_objects.begin(), son_objects.end(), + [](const fc::optional& obj) -> bool { return obj.valid(); }); map result; - std::transform(accs.begin(), accs.end(), son_ids.begin(), + std::transform(accs.begin(), accs.end(), son_objects.begin(), std::inserter(result, result.end()), - [](fc::optional& acct, son_id_type& sid) { + [](fc::optional& acct, fc::optional son) { FC_ASSERT(acct, "Invalid active SONs list in global properties."); - return std::make_pair(string(acct->name), std::move(sid)); + if (son.valid()) + return std::make_pair(string(acct->name), std::move(son->id)); + return std::make_pair(string(acct->name), std::move(son_id_type())); }); return result; } FC_CAPTURE_AND_RETHROW() } diff --git a/tests/cli/son.cpp b/tests/cli/son.cpp index d71ac4c8..7915c71e 100644 --- a/tests/cli/son.cpp +++ b/tests/cli/son.cpp @@ -650,6 +650,9 @@ BOOST_FIXTURE_TEST_CASE( cli_list_active_sons, cli_fixture ) BOOST_CHECK(active_sons.find(name) != active_sons.end()); } + // check list_active_son after SON deletion + con.wallet_api_ptr->delete_son("sonaccount1", true); + BOOST_CHECK_NO_THROW(con.wallet_api_ptr->list_active_sons()); } catch( fc::exception& e ) { BOOST_TEST_MESSAGE("SON cli wallet tests exception"); edump((e.to_detail_string())); From 13d2b27ed98c3a920b17f277431b6fe30aa620b4 Mon Sep 17 00:00:00 2001 From: obucinac Date: Sun, 23 Feb 2020 18:33:43 +0200 Subject: [PATCH 2/2] [SON-260] Sidechain Token withdrawal (#286) * Extend GPO.active_sons to contain votes and all public keys * Introduce son_wallet_object * son_wallet_object operations * son_wallet_object operations * son_wallet_object operations completed, basic tests added * Create son_wallet_object on new set of SONs, to initiate primary wallet recreation * son_wallet_object API and cli wallet commands * Send RPC command to bitcoin node to recreate multisig wallet * Send RPC command to bitcoin node to recreate multisig wallet * Send RPC command to bitcoin node to recreate multisig wallet * Wallet recreation by scheduled SON only, some cosmetic refactoring * Wallet recreation by scheduled SON only, some cosmetic refactoring * Updating wallet info through operation instead through database.modify() for persistance * SON wallet transfer object and operations, for tracking assets deposit/withdrawal * Update libraries/chain/include/graphene/chain/protocol/son_wallet.hpp Co-Authored-By: gladcow * Update libraries/chain/include/graphene/chain/protocol/son_wallet.hpp Co-Authored-By: gladcow * Fix #include * SON wallet transfer object and operations, for tracking assets deposit/withdrawal * SON wallet transfer object and operations, for tracking assets deposit/withdrawal * Refactor primary wallet recreation * Refactor primary wallet recreation * PW recreation refactoring, prevent duplicated recreations, update wallet address through proposal * PW recreation refactoring, prevent duplicated recreations, update wallet address through proposal * Quickfix for checking payer in evaluator * Quickfix for checking payer in evaluator * Fix failing son_wallet_tests - Check for son_btc_account is temporarely disabled * Remove redundant file * Squashed commit of the following: commit a688bb93ed4e16232a907aa8c76e240c83c771bf Author: obucinac Date: Tue Feb 4 19:31:45 2020 +0100 son_wallet_object operations and multisig wallet recreation by RPC (#263) * Extend GPO.active_sons to contain votes and all public keys * Introduce son_wallet_object * son_wallet_object operations * Create son_wallet_object on new set of SONs, to initiate primary wallet recreation * son_wallet_object API and cli wallet commands * Send RPC command to bitcoin node to recreate multisig wallet * Updating wallet info through operation instead through database.modify() for persistance * Update libraries/chain/include/graphene/chain/protocol/son_wallet.hpp * Update libraries/chain/include/graphene/chain/protocol/son_wallet.hpp * Fix #include * Refactor primary wallet recreation * PW recreation refactoring, prevent duplicated recreations, update wallet address through proposal * Quickfix for checking payer in evaluator * Fix failing son_wallet_tests - Check for son_btc_account is temporarely disabled * Remove redundant file Co-authored-by: gladcow commit 6e61d6b055eb276757e426245a3a7c23a61b3854 Author: satyakoneru Date: Tue Feb 4 00:14:39 2020 +1100 SON233 - Provide correct downtime metrics to user (#278) * Remove duplicated item in CMakeLists.txt * Issue tokens to the user who deposited Bitcoin, WIP... * Add son_wallet_transfer_process_operation * Issue tokens to the user who deposited Bitcoin, WIP... * Support multiple SON nodes per software instance * Add is_active_son guards for sidechain events processing * Add is_active_son guards, fix sending proposals and aprovals * Managing GRAPHENE_SON_ACCOUNT and issuing assets on Bitcoin deposit * Fix bad param * Fix aprovals on already approved or invalid proposals * Move transfer inside son_wallet_transfer_process_operation * Fix merging issue * Add cmake command line option SUPPORT_MULTIPLE_SONS * Skeleton of sidechain_net_handler_peerplays * Skeleton of Peerplays network listener * Temoprary disable account history tests for tracking accounts * Full Peerplays listener, use GRAPHENE_SON_ACCOUNT instead son_btc_account * Renaming son_wallet_transfer* to son_wallet_deposit*, introducing son_wallet_withdrawal* * Extend sidechain_address_object to contain withdrawal addresses - Withdrawal address is the address where system will send sidechain currencies * Rename son_wallet_withdrawal* to son_wallet_withdraw* * Some refactoring * Withdrawal refactoring * Withdrawal refactoring Co-authored-by: gladcow --- libraries/app/impacted.cpp | 10 +- libraries/chain/CMakeLists.txt | 3 +- libraries/chain/db_init.cpp | 15 +- libraries/chain/db_maint.cpp | 85 +------ libraries/chain/db_notify.cpp | 14 +- .../chain/protocol/chain_parameters.hpp | 5 - .../graphene/chain/protocol/operations.hpp | 9 +- .../chain/protocol/sidechain_address.hpp | 14 +- ...et_transfer.hpp => son_wallet_deposit.hpp} | 25 +- .../chain/protocol/son_wallet_withdraw.hpp | 50 ++++ .../include/graphene/chain/protocol/types.hpp | 15 +- .../chain/sidechain_address_object.hpp | 18 +- .../chain/son_wallet_deposit_evaluator.hpp | 24 ++ ...ject.hpp => son_wallet_deposit_object.hpp} | 37 +-- .../chain/son_wallet_transfer_evaluator.hpp | 24 -- .../chain/son_wallet_withdraw_evaluator.hpp | 24 ++ .../chain/son_wallet_withdraw_object.hpp | 67 +++++ .../include/graphene/chain/vote_count.hpp | 11 + .../chain/sidechain_address_evaluator.cpp | 10 +- libraries/chain/son_evaluator.cpp | 2 +- ...r.cpp => son_wallet_deposit_evaluator.cpp} | 60 +++-- libraries/chain/son_wallet_evaluator.cpp | 6 +- .../chain/son_wallet_withdraw_evaluator.cpp | 70 ++++++ .../peerplays_sidechain/CMakeLists.txt | 1 + .../graphene/peerplays_sidechain/defs.hpp | 6 +- .../sidechain_net_handler.hpp | 9 +- .../sidechain_net_handler_bitcoin.hpp | 7 +- .../sidechain_net_handler_peerplays.hpp | 34 +++ .../sidechain_net_manager.hpp | 2 + .../peerplays_sidechain_plugin.cpp | 89 ++++--- .../sidechain_net_handler.cpp | 229 ++++++++++++++---- .../sidechain_net_handler_bitcoin.cpp | 43 ++-- .../sidechain_net_handler_peerplays.cpp | 99 ++++++++ .../sidechain_net_manager.cpp | 19 ++ .../wallet/include/graphene/wallet/wallet.hpp | 20 +- libraries/wallet/wallet.cpp | 34 ++- programs/js_operation_serializer/main.cpp | 3 +- tests/tests/history_api_tests.cpp | 0 tests/tests/sidechain_addresses_test.cpp | 25 +- tests/tests/son_operations_tests.cpp | 33 +-- tests/tests/son_wallet_tests.cpp | 4 +- 41 files changed, 843 insertions(+), 412 deletions(-) mode change 100644 => 100755 libraries/chain/CMakeLists.txt rename libraries/chain/include/graphene/chain/protocol/{son_wallet_transfer.hpp => son_wallet_deposit.hpp} (57%) create mode 100644 libraries/chain/include/graphene/chain/protocol/son_wallet_withdraw.hpp create mode 100644 libraries/chain/include/graphene/chain/son_wallet_deposit_evaluator.hpp rename libraries/chain/include/graphene/chain/{son_wallet_transfer_object.hpp => son_wallet_deposit_object.hpp} (52%) delete mode 100644 libraries/chain/include/graphene/chain/son_wallet_transfer_evaluator.hpp create mode 100644 libraries/chain/include/graphene/chain/son_wallet_withdraw_evaluator.hpp create mode 100644 libraries/chain/include/graphene/chain/son_wallet_withdraw_object.hpp rename libraries/chain/{son_wallet_transfer_evaluator.cpp => son_wallet_deposit_evaluator.cpp} (54%) create mode 100644 libraries/chain/son_wallet_withdraw_evaluator.cpp mode change 100644 => 100755 libraries/plugins/peerplays_sidechain/CMakeLists.txt create mode 100644 libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_peerplays.hpp create mode 100644 libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp mode change 100755 => 100644 tests/tests/history_api_tests.cpp diff --git a/libraries/app/impacted.cpp b/libraries/app/impacted.cpp index d3e8eb8c..e0de1d05 100644 --- a/libraries/app/impacted.cpp +++ b/libraries/app/impacted.cpp @@ -322,10 +322,16 @@ struct get_impacted_account_visitor void operator()( const son_wallet_update_operation& op ){ _impacted.insert( op.payer ); } - void operator()( const son_wallet_transfer_create_operation& op ){ + void operator()( const son_wallet_deposit_create_operation& op ){ _impacted.insert( op.payer ); } - void operator()( const son_wallet_transfer_process_operation& op ){ + void operator()( const son_wallet_deposit_process_operation& op ){ + _impacted.insert( op.payer ); + } + void operator()( const son_wallet_withdraw_create_operation& op ){ + _impacted.insert( op.payer ); + } + void operator()( const son_wallet_withdraw_process_operation& op ){ _impacted.insert( op.payer ); } void operator()( const sidechain_address_add_operation& op ){ diff --git a/libraries/chain/CMakeLists.txt b/libraries/chain/CMakeLists.txt old mode 100644 new mode 100755 index c7dd5375..85d5a91b --- a/libraries/chain/CMakeLists.txt +++ b/libraries/chain/CMakeLists.txt @@ -118,7 +118,8 @@ add_library( graphene_chain son_object.cpp son_wallet_evaluator.cpp - son_wallet_transfer_evaluator.cpp + son_wallet_deposit_evaluator.cpp + son_wallet_withdraw_evaluator.cpp sidechain_address_evaluator.cpp diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 5c72d1bc..0be37c42 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -57,7 +57,8 @@ #include #include #include -#include +#include +#include #include #include @@ -82,7 +83,8 @@ #include #include #include -#include +#include +#include #include #include @@ -258,8 +260,10 @@ void database::initialize_evaluators() register_evaluator(); register_evaluator(); register_evaluator(); - register_evaluator(); - register_evaluator(); + register_evaluator(); + register_evaluator(); + register_evaluator(); + register_evaluator(); register_evaluator(); register_evaluator(); register_evaluator(); @@ -308,7 +312,8 @@ void database::initialize_indexes() add_index< primary_index >(); add_index< primary_index >(); - add_index< primary_index >(); + add_index< primary_index >(); + add_index< primary_index >(); add_index< primary_index >(); diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 9469bbce..3c1685b3 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -457,8 +457,9 @@ void database::update_active_sons() a.active.account_auths[weight.first] += votes; a.active.weight_threshold += votes; } - - a.active.weight_threshold /= 2; + + a.active.weight_threshold *= 2; + a.active.weight_threshold /= 3; a.active.weight_threshold += 1; } else @@ -466,12 +467,11 @@ void database::update_active_sons() vote_counter vc; for( const son_object& son : sons ) vc.add( son.son_account, std::max(_vote_tally_buffer[son.vote_id], UINT64_C(1)) ); - vc.finish( a.active ); + vc.finish_2_3( a.active ); } } ); // Compare current and to-be lists of active sons - //const global_property_object& gpo = get_global_properties(); auto cur_active_sons = gpo.active_sons; vector new_active_sons; for( const son_object& son : sons ) { @@ -602,83 +602,6 @@ void database::update_active_sons() update_son_metrics(); - if(gpo.active_sons.size() > 0 ) { - if(gpo.parameters.get_son_btc_account_id() == GRAPHENE_NULL_ACCOUNT) { - const auto& son_btc_account = create( [&]( account_object& obj ) { - uint64_t total_votes = 0; - obj.name = "son_btc_account"; - obj.statistics = create([&]( account_statistics_object& acc_stat ){ acc_stat.owner = obj.id; }).id; - obj.membership_expiration_date = time_point_sec::maximum(); - obj.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; - obj.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; - - for( const auto& son_info : gpo.active_sons ) - { - const son_object& son = get(son_info.son_id); - total_votes += _vote_tally_buffer[son.vote_id]; - } - // total_votes is 64 bits. Subtract the number of leading low bits from 64 to get the number of useful bits, - // then I want to keep the most significant 16 bits of what's left. - int8_t bits_to_drop = std::max(int(boost::multiprecision::detail::find_msb(total_votes)) - 15, 0); - - for( const auto& son_info : gpo.active_sons ) - { - // Ensure that everyone has at least one vote. Zero weights aren't allowed. - const son_object& son = get(son_info.son_id); - uint16_t votes = std::max((_vote_tally_buffer[son.vote_id] >> bits_to_drop), uint64_t(1) ); - obj.owner.account_auths[son.son_account] += votes; - obj.owner.weight_threshold += votes; - obj.active.account_auths[son.son_account] += votes; - obj.active.weight_threshold += votes; - } - obj.owner.weight_threshold *= 2; - obj.owner.weight_threshold /= 3; - obj.owner.weight_threshold += 1; - obj.active.weight_threshold *= 2; - obj.active.weight_threshold /= 3; - obj.active.weight_threshold += 1; - }); - - modify( gpo, [&]( global_property_object& gpo ) { - gpo.parameters.extensions.value.son_btc_account = son_btc_account.get_id(); - if( gpo.pending_parameters ) - gpo.pending_parameters->extensions.value.son_btc_account = son_btc_account.get_id(); - }); - } else { - modify( get(gpo.parameters.get_son_btc_account_id()), [&]( account_object& obj ) - { - uint64_t total_votes = 0; - obj.owner.weight_threshold = 0; - obj.owner.account_auths.clear(); - obj.active.weight_threshold = 0; - obj.active.account_auths.clear(); - for( const auto& son_info : gpo.active_sons ) - { - const son_object& son = get(son_info.son_id); - total_votes += _vote_tally_buffer[son.vote_id]; - } - // total_votes is 64 bits. Subtract the number of leading low bits from 64 to get the number of useful bits, - // then I want to keep the most significant 16 bits of what's left. - int8_t bits_to_drop = std::max(int(boost::multiprecision::detail::find_msb(total_votes)) - 15, 0); - for( const auto& son_info : gpo.active_sons ) - { - // Ensure that everyone has at least one vote. Zero weights aren't allowed. - const son_object& son = get(son_info.son_id); - uint16_t votes = std::max((_vote_tally_buffer[son.vote_id] >> bits_to_drop), uint64_t(1) ); - obj.owner.account_auths[son.son_account] += votes; - obj.owner.weight_threshold += votes; - obj.active.account_auths[son.son_account] += votes; - obj.active.weight_threshold += votes; - } - obj.owner.weight_threshold *= 2; - obj.owner.weight_threshold /= 3; - obj.owner.weight_threshold += 1; - obj.active.weight_threshold *= 2; - obj.active.weight_threshold /= 3; - obj.active.weight_threshold += 1; - }); - } - } } FC_CAPTURE_AND_RETHROW() } void database::initialize_budget_record( fc::time_point_sec now, budget_record& rec )const diff --git a/libraries/chain/db_notify.cpp b/libraries/chain/db_notify.cpp index 98e02a1b..1b0b5158 100644 --- a/libraries/chain/db_notify.cpp +++ b/libraries/chain/db_notify.cpp @@ -309,10 +309,16 @@ struct get_impacted_account_visitor void operator()( const son_wallet_update_operation& op ) { _impacted.insert( op.payer ); } - void operator()( const son_wallet_transfer_create_operation& op ) { + void operator()( const son_wallet_deposit_create_operation& op ) { _impacted.insert( op.payer ); } - void operator()( const son_wallet_transfer_process_operation& op ) { + void operator()( const son_wallet_deposit_process_operation& op ) { + _impacted.insert( op.payer ); + } + void operator()( const son_wallet_withdraw_create_operation& op ) { + _impacted.insert( op.payer ); + } + void operator()( const son_wallet_withdraw_process_operation& op ) { _impacted.insert( op.payer ); } void operator()( const sidechain_address_add_operation& op ) { @@ -419,7 +425,9 @@ void get_relevant_accounts( const object* obj, flat_set& accoun break; } case son_wallet_object_type:{ break; - } case son_wallet_transfer_object_type:{ + } case son_wallet_deposit_object_type:{ + break; + } case son_wallet_withdraw_object_type:{ break; } case sidechain_address_object_type:{ const auto& aobj = dynamic_cast(obj); diff --git a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp index 51024e16..c62274ba 100644 --- a/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp +++ b/libraries/chain/include/graphene/chain/protocol/chain_parameters.hpp @@ -46,7 +46,6 @@ namespace graphene { namespace chain { optional < uint32_t > son_vesting_amount; optional < uint32_t > son_vesting_period; optional < uint32_t > son_pay_daily_max; - optional < account_id_type > son_btc_account; }; struct chain_parameters @@ -139,9 +138,6 @@ namespace graphene { namespace chain { inline uint16_t son_pay_daily_max()const { return extensions.value.son_pay_daily_max.valid() ? *extensions.value.son_pay_daily_max : MIN_SON_PAY_DAILY_MAX; } - inline account_id_type get_son_btc_account_id() const { - return extensions.value.son_btc_account.valid() ? *extensions.value.son_btc_account : GRAPHENE_NULL_ACCOUNT; - } }; } } // graphene::chain @@ -159,7 +155,6 @@ FC_REFLECT( graphene::chain::parameter_extension, (son_vesting_amount) (son_vesting_period) (son_pay_daily_max) - (son_btc_account) ) FC_REFLECT( graphene::chain::chain_parameters, diff --git a/libraries/chain/include/graphene/chain/protocol/operations.hpp b/libraries/chain/include/graphene/chain/protocol/operations.hpp index 27980ae2..37eccf80 100644 --- a/libraries/chain/include/graphene/chain/protocol/operations.hpp +++ b/libraries/chain/include/graphene/chain/protocol/operations.hpp @@ -48,7 +48,8 @@ #include #include #include -#include +#include +#include namespace graphene { namespace chain { @@ -148,8 +149,10 @@ namespace graphene { namespace chain { son_maintenance_operation, son_wallet_recreate_operation, son_wallet_update_operation, - son_wallet_transfer_create_operation, - son_wallet_transfer_process_operation, + son_wallet_deposit_create_operation, + son_wallet_deposit_process_operation, + son_wallet_withdraw_create_operation, + son_wallet_withdraw_process_operation, sidechain_address_add_operation, sidechain_address_update_operation, sidechain_address_delete_operation diff --git a/libraries/chain/include/graphene/chain/protocol/sidechain_address.hpp b/libraries/chain/include/graphene/chain/protocol/sidechain_address.hpp index d0e658b4..7418f55e 100644 --- a/libraries/chain/include/graphene/chain/protocol/sidechain_address.hpp +++ b/libraries/chain/include/graphene/chain/protocol/sidechain_address.hpp @@ -12,9 +12,8 @@ namespace graphene { namespace chain { asset fee; account_id_type sidechain_address_account; graphene::peerplays_sidechain::sidechain_type sidechain; - string address; - string private_key; - string public_key; + string deposit_address; + string withdraw_address; account_id_type fee_payer()const { return sidechain_address_account; } share_type calculate_fee(const fee_parameters_type& k)const { return 0; } @@ -28,9 +27,8 @@ namespace graphene { namespace chain { sidechain_address_id_type sidechain_address_id; account_id_type sidechain_address_account; graphene::peerplays_sidechain::sidechain_type sidechain; - optional address; - optional private_key; - optional public_key; + optional deposit_address; + optional withdraw_address; account_id_type fee_payer()const { return sidechain_address_account; } share_type calculate_fee(const fee_parameters_type& k)const { return 0; } @@ -53,12 +51,12 @@ namespace graphene { namespace chain { FC_REFLECT(graphene::chain::sidechain_address_add_operation::fee_parameters_type, (fee) ) FC_REFLECT(graphene::chain::sidechain_address_add_operation, (fee) - (sidechain_address_account)(sidechain)(address)(private_key)(public_key) ) + (sidechain_address_account)(sidechain)(deposit_address)(withdraw_address) ) FC_REFLECT(graphene::chain::sidechain_address_update_operation::fee_parameters_type, (fee) ) FC_REFLECT(graphene::chain::sidechain_address_update_operation, (fee) (sidechain_address_id) - (sidechain_address_account)(sidechain)(address)(private_key)(public_key) ) + (sidechain_address_account)(sidechain)(deposit_address)(withdraw_address) ) FC_REFLECT(graphene::chain::sidechain_address_delete_operation::fee_parameters_type, (fee) ) FC_REFLECT(graphene::chain::sidechain_address_delete_operation, (fee) diff --git a/libraries/chain/include/graphene/chain/protocol/son_wallet_transfer.hpp b/libraries/chain/include/graphene/chain/protocol/son_wallet_deposit.hpp similarity index 57% rename from libraries/chain/include/graphene/chain/protocol/son_wallet_transfer.hpp rename to libraries/chain/include/graphene/chain/protocol/son_wallet_deposit.hpp index 38f8dac6..abcc4384 100644 --- a/libraries/chain/include/graphene/chain/protocol/son_wallet_transfer.hpp +++ b/libraries/chain/include/graphene/chain/protocol/son_wallet_deposit.hpp @@ -1,9 +1,11 @@ #pragma once #include +#include + namespace graphene { namespace chain { - struct son_wallet_transfer_create_operation : public base_operation + struct son_wallet_deposit_create_operation : public base_operation { struct fee_parameters_type { uint64_t fee = 0; }; @@ -16,23 +18,24 @@ namespace graphene { namespace chain { std::string sidechain_transaction_id; std::string sidechain_from; std::string sidechain_to; - int64_t sidechain_amount; + std::string sidechain_currency; + fc::safe sidechain_amount; chain::account_id_type peerplays_from; chain::account_id_type peerplays_to; - chain::asset peerplays_amount; + chain::asset peerplays_asset; account_id_type fee_payer()const { return payer; } share_type calculate_fee(const fee_parameters_type& k)const { return 0; } }; - struct son_wallet_transfer_process_operation : public base_operation + struct son_wallet_deposit_process_operation : public base_operation { struct fee_parameters_type { uint64_t fee = 0; }; asset fee; account_id_type payer; - son_wallet_transfer_id_type son_wallet_transfer_id; + son_wallet_deposit_id_type son_wallet_deposit_id; account_id_type fee_payer()const { return payer; } share_type calculate_fee(const fee_parameters_type& k)const { return 0; } @@ -40,9 +43,9 @@ namespace graphene { namespace chain { } } // namespace graphene::chain -FC_REFLECT(graphene::chain::son_wallet_transfer_create_operation::fee_parameters_type, (fee) ) -FC_REFLECT(graphene::chain::son_wallet_transfer_create_operation, (fee)(payer) - (timestamp) (sidechain) (sidechain_uid) (sidechain_transaction_id) (sidechain_from) (sidechain_to) (sidechain_amount) (peerplays_from) (peerplays_to) (peerplays_amount)) -FC_REFLECT(graphene::chain::son_wallet_transfer_process_operation::fee_parameters_type, (fee) ) -FC_REFLECT(graphene::chain::son_wallet_transfer_process_operation, (fee)(payer) - (son_wallet_transfer_id)) +FC_REFLECT(graphene::chain::son_wallet_deposit_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT(graphene::chain::son_wallet_deposit_create_operation, (fee)(payer) + (timestamp) (sidechain) (sidechain_uid) (sidechain_transaction_id) (sidechain_from) (sidechain_to) (sidechain_currency) (sidechain_amount) (peerplays_from) (peerplays_to) (peerplays_asset)) +FC_REFLECT(graphene::chain::son_wallet_deposit_process_operation::fee_parameters_type, (fee) ) +FC_REFLECT(graphene::chain::son_wallet_deposit_process_operation, (fee)(payer) + (son_wallet_deposit_id)) diff --git a/libraries/chain/include/graphene/chain/protocol/son_wallet_withdraw.hpp b/libraries/chain/include/graphene/chain/protocol/son_wallet_withdraw.hpp new file mode 100644 index 00000000..99c263be --- /dev/null +++ b/libraries/chain/include/graphene/chain/protocol/son_wallet_withdraw.hpp @@ -0,0 +1,50 @@ +#pragma once +#include + +#include + +namespace graphene { namespace chain { + + struct son_wallet_withdraw_create_operation : public base_operation + { + struct fee_parameters_type { uint64_t fee = 0; }; + + asset fee; + account_id_type payer; + + fc::time_point_sec timestamp; + peerplays_sidechain::sidechain_type sidechain; + std::string peerplays_uid; + std::string peerplays_transaction_id; + chain::account_id_type peerplays_from; + chain::asset peerplays_asset; + peerplays_sidechain::sidechain_type withdraw_sidechain; + std::string withdraw_address; + std::string withdraw_currency; + safe withdraw_amount; + + account_id_type fee_payer()const { return payer; } + share_type calculate_fee(const fee_parameters_type& k)const { return 0; } + }; + + struct son_wallet_withdraw_process_operation : public base_operation + { + struct fee_parameters_type { uint64_t fee = 0; }; + + asset fee; + account_id_type payer; + + son_wallet_withdraw_id_type son_wallet_withdraw_id; + + account_id_type fee_payer()const { return payer; } + share_type calculate_fee(const fee_parameters_type& k)const { return 0; } + }; + +} } // namespace graphene::chain + +FC_REFLECT(graphene::chain::son_wallet_withdraw_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT(graphene::chain::son_wallet_withdraw_create_operation, (fee)(payer) + (timestamp) (sidechain) (peerplays_uid) (peerplays_transaction_id) (peerplays_from) (peerplays_asset) (withdraw_sidechain) (withdraw_address) (withdraw_currency) (withdraw_amount) ) +FC_REFLECT(graphene::chain::son_wallet_withdraw_process_operation::fee_parameters_type, (fee) ) +FC_REFLECT(graphene::chain::son_wallet_withdraw_process_operation, (fee)(payer) + (son_wallet_withdraw_id)) diff --git a/libraries/chain/include/graphene/chain/protocol/types.hpp b/libraries/chain/include/graphene/chain/protocol/types.hpp index c25c465c..ac6ec067 100644 --- a/libraries/chain/include/graphene/chain/protocol/types.hpp +++ b/libraries/chain/include/graphene/chain/protocol/types.hpp @@ -148,7 +148,8 @@ namespace graphene { namespace chain { son_object_type, son_proposal_object_type, son_wallet_object_type, - son_wallet_transfer_object_type, + son_wallet_deposit_object_type, + son_wallet_withdraw_object_type, sidechain_address_object_type, OBJECT_TYPE_COUNT ///< Sentry value which contains the number of different object types }; @@ -214,7 +215,8 @@ namespace graphene { namespace chain { class son_object; class son_proposal_object; class son_wallet_object; - class son_wallet_transfer_object; + class son_wallet_deposit_object; + class son_wallet_withdraw_object; class sidechain_address_object; typedef object_id< protocol_ids, account_object_type, account_object> account_id_type; @@ -245,7 +247,8 @@ namespace graphene { namespace chain { typedef object_id< protocol_ids, son_object_type, son_object> son_id_type; typedef object_id< protocol_ids, son_proposal_object_type, son_proposal_object> son_proposal_id_type; typedef object_id< protocol_ids, son_wallet_object_type, son_wallet_object> son_wallet_id_type; - typedef object_id< protocol_ids, son_wallet_transfer_object_type, son_wallet_transfer_object> son_wallet_transfer_id_type; + typedef object_id< protocol_ids, son_wallet_deposit_object_type, son_wallet_deposit_object> son_wallet_deposit_id_type; + typedef object_id< protocol_ids, son_wallet_withdraw_object_type, son_wallet_withdraw_object> son_wallet_withdraw_id_type; typedef object_id< protocol_ids, sidechain_address_object_type, sidechain_address_object> sidechain_address_id_type; // implementation types @@ -434,7 +437,8 @@ FC_REFLECT_ENUM( graphene::chain::object_type, (son_object_type) (son_proposal_object_type) (son_wallet_object_type) - (son_wallet_transfer_object_type) + (son_wallet_deposit_object_type) + (son_wallet_withdraw_object_type) (sidechain_address_object_type) (OBJECT_TYPE_COUNT) ) @@ -510,7 +514,8 @@ FC_REFLECT_TYPENAME( graphene::chain::tournament_details_id_type ) FC_REFLECT_TYPENAME( graphene::chain::son_id_type ) FC_REFLECT_TYPENAME( graphene::chain::son_proposal_id_type ) FC_REFLECT_TYPENAME( graphene::chain::son_wallet_id_type ) -FC_REFLECT_TYPENAME( graphene::chain::son_wallet_transfer_id_type ) +FC_REFLECT_TYPENAME( graphene::chain::son_wallet_deposit_id_type ) +FC_REFLECT_TYPENAME( graphene::chain::son_wallet_withdraw_id_type ) FC_REFLECT_TYPENAME( graphene::chain::sidechain_address_id_type ) diff --git a/libraries/chain/include/graphene/chain/sidechain_address_object.hpp b/libraries/chain/include/graphene/chain/sidechain_address_object.hpp index 8c77fad2..1a8b6967 100644 --- a/libraries/chain/include/graphene/chain/sidechain_address_object.hpp +++ b/libraries/chain/include/graphene/chain/sidechain_address_object.hpp @@ -21,21 +21,19 @@ namespace graphene { namespace chain { account_id_type sidechain_address_account; graphene::peerplays_sidechain::sidechain_type sidechain; - string address; - string private_key; - string public_key; + string deposit_address; + string withdraw_address; sidechain_address_object() : sidechain(graphene::peerplays_sidechain::sidechain_type::bitcoin), - address(""), - private_key(""), - public_key("") {} + deposit_address(""), + withdraw_address("") {} }; struct by_account; struct by_sidechain; struct by_account_and_sidechain; - struct by_sidechain_and_address; + struct by_sidechain_and_deposit_address; using sidechain_address_multi_index_type = multi_index_container< sidechain_address_object, indexed_by< @@ -54,10 +52,10 @@ namespace graphene { namespace chain { member > >, - ordered_unique< tag, + ordered_unique< tag, composite_key, - member + member > > > @@ -67,4 +65,4 @@ namespace graphene { namespace chain { } } // graphene::chain FC_REFLECT_DERIVED( graphene::chain::sidechain_address_object, (graphene::db::object), - (sidechain_address_account)(sidechain)(address)(private_key)(public_key) ) + (sidechain_address_account) (sidechain) (deposit_address) (withdraw_address) ) diff --git a/libraries/chain/include/graphene/chain/son_wallet_deposit_evaluator.hpp b/libraries/chain/include/graphene/chain/son_wallet_deposit_evaluator.hpp new file mode 100644 index 00000000..f3780c1f --- /dev/null +++ b/libraries/chain/include/graphene/chain/son_wallet_deposit_evaluator.hpp @@ -0,0 +1,24 @@ +#pragma once +#include + +namespace graphene { namespace chain { + +class create_son_wallet_deposit_evaluator : public evaluator +{ +public: + typedef son_wallet_deposit_create_operation operation_type; + + void_result do_evaluate(const son_wallet_deposit_create_operation& o); + object_id_type do_apply(const son_wallet_deposit_create_operation& o); +}; + +class process_son_wallet_deposit_evaluator : public evaluator +{ +public: + typedef son_wallet_deposit_process_operation operation_type; + + void_result do_evaluate(const son_wallet_deposit_process_operation& o); + object_id_type do_apply(const son_wallet_deposit_process_operation& o); +}; + +} } // namespace graphene::chain diff --git a/libraries/chain/include/graphene/chain/son_wallet_transfer_object.hpp b/libraries/chain/include/graphene/chain/son_wallet_deposit_object.hpp similarity index 52% rename from libraries/chain/include/graphene/chain/son_wallet_transfer_object.hpp rename to libraries/chain/include/graphene/chain/son_wallet_deposit_object.hpp index 68293784..668af1d1 100644 --- a/libraries/chain/include/graphene/chain/son_wallet_transfer_object.hpp +++ b/libraries/chain/include/graphene/chain/son_wallet_deposit_object.hpp @@ -6,15 +6,15 @@ namespace graphene { namespace chain { using namespace graphene::db; /** - * @class son_wallet_transfer_object - * @brief tracks information about a SON wallet transfer. + * @class son_wallet_deposit_object + * @brief tracks information about a SON wallet deposit. * @ingroup object */ - class son_wallet_transfer_object : public abstract_object + class son_wallet_deposit_object : public abstract_object { public: static const uint8_t space_id = protocol_ids; - static const uint8_t type_id = son_wallet_transfer_object_type; + static const uint8_t type_id = son_wallet_deposit_object_type; time_point_sec timestamp; peerplays_sidechain::sidechain_type sidechain; @@ -23,10 +23,11 @@ namespace graphene { namespace chain { std::string sidechain_transaction_id; std::string sidechain_from; std::string sidechain_to; - int64_t sidechain_amount; + std::string sidechain_currency; + safe sidechain_amount; chain::account_id_type peerplays_from; chain::account_id_type peerplays_to; - chain::asset peerplays_amount; + chain::asset peerplays_asset; bool processed; }; @@ -35,34 +36,34 @@ namespace graphene { namespace chain { struct by_sidechain_uid; struct by_processed; struct by_sidechain_and_processed; - using son_wallet_transfer_multi_index_type = multi_index_container< - son_wallet_transfer_object, + 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 + member >, ordered_unique< tag, - member + member >, ordered_non_unique< tag, - member + member >, ordered_non_unique< tag, - composite_key, - member + composite_key, + member > > > >; - using son_wallet_transfer_index = generic_index; + using son_wallet_deposit_index = generic_index; } } // graphene::chain -FC_REFLECT_DERIVED( graphene::chain::son_wallet_transfer_object, (graphene::db::object), +FC_REFLECT_DERIVED( graphene::chain::son_wallet_deposit_object, (graphene::db::object), (timestamp) (sidechain) (confirmations) - (sidechain_uid) (sidechain_transaction_id) (sidechain_from) (sidechain_to) (sidechain_amount) - (peerplays_from) (peerplays_to) (peerplays_amount) + (sidechain_uid) (sidechain_transaction_id) (sidechain_from) (sidechain_to) (sidechain_currency) (sidechain_amount) + (peerplays_from) (peerplays_to) (peerplays_asset) (processed) ) diff --git a/libraries/chain/include/graphene/chain/son_wallet_transfer_evaluator.hpp b/libraries/chain/include/graphene/chain/son_wallet_transfer_evaluator.hpp deleted file mode 100644 index 68fd0ad5..00000000 --- a/libraries/chain/include/graphene/chain/son_wallet_transfer_evaluator.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include - -namespace graphene { namespace chain { - -class create_son_wallet_transfer_evaluator : public evaluator -{ -public: - typedef son_wallet_transfer_create_operation operation_type; - - void_result do_evaluate(const son_wallet_transfer_create_operation& o); - object_id_type do_apply(const son_wallet_transfer_create_operation& o); -}; - -class process_son_wallet_transfer_evaluator : public evaluator -{ -public: - typedef son_wallet_transfer_process_operation operation_type; - - void_result do_evaluate(const son_wallet_transfer_process_operation& o); - object_id_type do_apply(const son_wallet_transfer_process_operation& o); -}; - -} } // namespace graphene::chain diff --git a/libraries/chain/include/graphene/chain/son_wallet_withdraw_evaluator.hpp b/libraries/chain/include/graphene/chain/son_wallet_withdraw_evaluator.hpp new file mode 100644 index 00000000..f5c08cd3 --- /dev/null +++ b/libraries/chain/include/graphene/chain/son_wallet_withdraw_evaluator.hpp @@ -0,0 +1,24 @@ +#pragma once +#include + +namespace graphene { namespace chain { + +class create_son_wallet_withdraw_evaluator : public evaluator +{ +public: + typedef son_wallet_withdraw_create_operation operation_type; + + void_result do_evaluate(const son_wallet_withdraw_create_operation& o); + object_id_type do_apply(const son_wallet_withdraw_create_operation& o); +}; + +class process_son_wallet_withdraw_evaluator : public evaluator +{ +public: + typedef son_wallet_withdraw_process_operation operation_type; + + void_result do_evaluate(const son_wallet_withdraw_process_operation& o); + object_id_type do_apply(const son_wallet_withdraw_process_operation& o); +}; + +} } // namespace graphene::chain diff --git a/libraries/chain/include/graphene/chain/son_wallet_withdraw_object.hpp b/libraries/chain/include/graphene/chain/son_wallet_withdraw_object.hpp new file mode 100644 index 00000000..68e870e0 --- /dev/null +++ b/libraries/chain/include/graphene/chain/son_wallet_withdraw_object.hpp @@ -0,0 +1,67 @@ +#pragma once +#include +#include + +namespace graphene { namespace chain { + using namespace graphene::db; + + /** + * @class son_wallet_withdraw_object + * @brief tracks information about a SON wallet withdrawal. + * @ingroup object + */ + class son_wallet_withdraw_object : public abstract_object + { + public: + static const uint8_t space_id = protocol_ids; + static const uint8_t type_id = son_wallet_withdraw_object_type; + + time_point_sec timestamp; + peerplays_sidechain::sidechain_type sidechain; + int64_t confirmations; + std::string peerplays_uid; + std::string peerplays_transaction_id; + chain::account_id_type peerplays_from; + chain::asset peerplays_asset; + peerplays_sidechain::sidechain_type withdraw_sidechain; + std::string withdraw_address; + std::string withdraw_currency; + safe withdraw_amount; + bool processed; + }; + + struct by_peerplays_uid; + struct by_withdraw_sidechain; + struct by_processed; + struct by_withdraw_sidechain_and_processed; + using son_wallet_withdraw_multi_index_type = multi_index_container< + son_wallet_withdraw_object, + indexed_by< + ordered_unique< tag, + member + >, + ordered_unique< tag, + member + >, + ordered_non_unique< tag, + member + >, + ordered_non_unique< tag, + member + >, + ordered_non_unique< tag, + composite_key, + member + > + > + > + >; + using son_wallet_withdraw_index = generic_index; +} } // graphene::chain + +FC_REFLECT_DERIVED( graphene::chain::son_wallet_withdraw_object, (graphene::db::object), + (timestamp) (sidechain) (confirmations) + (peerplays_uid) (peerplays_transaction_id) (peerplays_from) (peerplays_asset) + (withdraw_sidechain) (withdraw_address) (withdraw_currency) (withdraw_amount) + (processed) ) diff --git a/libraries/chain/include/graphene/chain/vote_count.hpp b/libraries/chain/include/graphene/chain/vote_count.hpp index f76a784d..ab2f3612 100644 --- a/libraries/chain/include/graphene/chain/vote_count.hpp +++ b/libraries/chain/include/graphene/chain/vote_count.hpp @@ -63,6 +63,17 @@ struct vote_counter out_auth = auth; } + void finish_2_3( authority& out_auth ) + { + if( total_votes == 0 ) + return; + assert( total_votes <= std::numeric_limits::max() ); + uint32_t weight = uint32_t( total_votes ); + weight = (weight * 2 / 3) + 1; + auth.weight_threshold = weight; + out_auth = auth; + } + bool is_empty()const { return (total_votes == 0); diff --git a/libraries/chain/sidechain_address_evaluator.cpp b/libraries/chain/sidechain_address_evaluator.cpp index d79d4cb1..5382195d 100644 --- a/libraries/chain/sidechain_address_evaluator.cpp +++ b/libraries/chain/sidechain_address_evaluator.cpp @@ -19,9 +19,8 @@ object_id_type add_sidechain_address_evaluator::do_apply(const sidechain_address const auto& new_sidechain_address_object = db().create( [&]( sidechain_address_object& obj ){ obj.sidechain_address_account = op.sidechain_address_account; obj.sidechain = op.sidechain; - obj.address = op.address; - obj.private_key = op.private_key; - obj.public_key = op.public_key; + obj.deposit_address = op.deposit_address; + obj.withdraw_address = op.withdraw_address; }); return new_sidechain_address_object.id; } FC_CAPTURE_AND_RETHROW( (op) ) } @@ -41,9 +40,8 @@ object_id_type update_sidechain_address_evaluator::do_apply(const sidechain_addr if(itr != idx.end()) { db().modify(*itr, [&op](sidechain_address_object &sao) { - if(op.address.valid()) sao.address = *op.address; - if(op.private_key.valid()) sao.private_key = *op.private_key; - if(op.public_key.valid()) sao.public_key = *op.public_key; + if(op.deposit_address.valid()) sao.deposit_address = *op.deposit_address; + if(op.withdraw_address.valid()) sao.withdraw_address = *op.withdraw_address; }); } return op.sidechain_address_id; diff --git a/libraries/chain/son_evaluator.cpp b/libraries/chain/son_evaluator.cpp index bcdda1ba..0adfa778 100644 --- a/libraries/chain/son_evaluator.cpp +++ b/libraries/chain/son_evaluator.cpp @@ -166,7 +166,7 @@ object_id_type son_heartbeat_evaluator::do_apply(const son_heartbeat_operation& void_result son_report_down_evaluator::do_evaluate(const son_report_down_operation& op) { try { FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); // can be removed after HF date pass - FC_ASSERT(op.payer == db().get_global_properties().parameters.get_son_btc_account_id(), "Payer should be the son btc account"); + FC_ASSERT(op.payer == GRAPHENE_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() ); auto itr = idx.find(op.son_id); diff --git a/libraries/chain/son_wallet_transfer_evaluator.cpp b/libraries/chain/son_wallet_deposit_evaluator.cpp similarity index 54% rename from libraries/chain/son_wallet_transfer_evaluator.cpp rename to libraries/chain/son_wallet_deposit_evaluator.cpp index 6245efa8..2f5a4f6b 100644 --- a/libraries/chain/son_wallet_transfer_evaluator.cpp +++ b/libraries/chain/son_wallet_deposit_evaluator.cpp @@ -1,28 +1,27 @@ -#include +#include #include #include -#include +#include namespace graphene { namespace chain { -void_result create_son_wallet_transfer_evaluator::do_evaluate(const son_wallet_transfer_create_operation& op) +void_result create_son_wallet_deposit_evaluator::do_evaluate(const son_wallet_deposit_create_operation& op) { try{ FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); - //FC_ASSERT(db().get_global_properties().parameters.get_son_btc_account_id() != GRAPHENE_NULL_ACCOUNT, "SON paying account not set."); - FC_ASSERT( op.payer == db().get_global_properties().parameters.get_son_btc_account_id(), "SON paying account must be set as payer." ); + FC_ASSERT( op.payer == GRAPHENE_SON_ACCOUNT, "SON paying account must be set as payer." ); - //const auto& idx = db().get_index_type().indices().get(); + //const auto& idx = db().get_index_type().indices().get(); //FC_ASSERT(idx.find(op.sidechain_uid) == idx.end(), "Already registered " + op.sidechain_uid); return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } -object_id_type create_son_wallet_transfer_evaluator::do_apply(const son_wallet_transfer_create_operation& op) +object_id_type create_son_wallet_deposit_evaluator::do_apply(const son_wallet_deposit_create_operation& op) { try { - const auto& idx = db().get_index_type().indices().get(); + const auto& idx = db().get_index_type().indices().get(); auto itr = idx.find(op.sidechain_uid); if (itr == idx.end()) { - const auto& new_son_wallet_transfer_object = db().create( [&]( son_wallet_transfer_object& swto ){ + const auto& new_son_wallet_deposit_object = db().create( [&]( son_wallet_deposit_object& swto ){ swto.timestamp = op.timestamp; swto.sidechain = op.sidechain; swto.confirmations = 1; @@ -33,26 +32,25 @@ object_id_type create_son_wallet_transfer_evaluator::do_apply(const son_wallet_t swto.sidechain_amount = op.sidechain_amount; swto.peerplays_from = op.peerplays_from; swto.peerplays_to = op.peerplays_to; - swto.peerplays_amount = op.peerplays_amount; + swto.peerplays_asset = op.peerplays_asset; swto.processed = false; }); - return new_son_wallet_transfer_object.id; + return new_son_wallet_deposit_object.id; } else { - db().modify(*itr, [&op](son_wallet_transfer_object &swto) { + db().modify(*itr, [&op](son_wallet_deposit_object &swto) { swto.confirmations = swto.confirmations + 1; }); return (*itr).id; } } FC_CAPTURE_AND_RETHROW( (op) ) } -void_result process_son_wallet_transfer_evaluator::do_evaluate(const son_wallet_transfer_process_operation& op) +void_result process_son_wallet_deposit_evaluator::do_evaluate(const son_wallet_deposit_process_operation& op) { try{ FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); - //FC_ASSERT(db().get_global_properties().parameters.get_son_btc_account_id() != GRAPHENE_NULL_ACCOUNT, "SON paying account not set."); - FC_ASSERT( op.payer == db().get_global_properties().parameters.get_son_btc_account_id(), "SON paying account must be set as payer." ); + FC_ASSERT( op.payer == GRAPHENE_SON_ACCOUNT, "SON paying account must be set as payer." ); - const auto& idx = db().get_index_type().indices().get(); - const auto& itr = idx.find(op.son_wallet_transfer_id); + const auto& idx = db().get_index_type().indices().get(); + const auto& itr = idx.find(op.son_wallet_deposit_id); FC_ASSERT(itr != idx.end(), "Son wallet transfer not found"); //FC_ASSERT(itr->processed == false, "Son wallet transfer is already processed"); @@ -60,7 +58,7 @@ void_result process_son_wallet_transfer_evaluator::do_evaluate(const son_wallet_ const account_object& from_account = itr->peerplays_to(d); // reversed, for deposit const account_object& to_account = itr->peerplays_from(d); // reversed, for deposit - const asset_object& asset_type = itr->peerplays_amount.asset_id(d); + const asset_object& asset_type = itr->peerplays_asset.asset_id(d); try { @@ -69,14 +67,14 @@ void_result process_son_wallet_transfer_evaluator::do_evaluate(const son_wallet_ transfer_from_account_not_whitelisted, "'from' account ${from} is not whitelisted for asset ${asset}", ("from",from_account.id) - ("asset",itr->peerplays_amount.asset_id) + ("asset",itr->peerplays_asset.asset_id) ); GRAPHENE_ASSERT( is_authorized_asset( d, to_account, asset_type ), transfer_to_account_not_whitelisted, "'to' account ${to} is not whitelisted for asset ${asset}", ("to",to_account.id) - ("asset",itr->peerplays_amount.asset_id) + ("asset",itr->peerplays_asset.asset_id) ); if( asset_type.is_transfer_restricted() ) @@ -85,38 +83,38 @@ void_result process_son_wallet_transfer_evaluator::do_evaluate(const son_wallet_ from_account.id == asset_type.issuer || to_account.id == asset_type.issuer, transfer_restricted_transfer_asset, "Asset {asset} has transfer_restricted flag enabled", - ("asset", itr->peerplays_amount.asset_id) + ("asset", itr->peerplays_asset.asset_id) ); } - bool insufficient_balance = d.get_balance( from_account, asset_type ).amount >= itr->peerplays_amount.amount; + bool insufficient_balance = d.get_balance( from_account, asset_type ).amount >= itr->peerplays_asset.amount; FC_ASSERT( insufficient_balance, "Insufficient Balance: ${balance}, unable to transfer '${total_transfer}' from account '${a}' to '${t}'", - ("a",from_account.name)("t",to_account.name)("total_transfer",d.to_pretty_string(itr->peerplays_amount))("balance",d.to_pretty_string(d.get_balance(from_account, asset_type))) ); + ("a",from_account.name)("t",to_account.name)("total_transfer",d.to_pretty_string(itr->peerplays_asset))("balance",d.to_pretty_string(d.get_balance(from_account, asset_type))) ); return void_result(); - } FC_RETHROW_EXCEPTIONS( error, "Unable to transfer ${a} from ${f} to ${t}", ("a",d.to_pretty_string(itr->peerplays_amount))("f",from_account.name)("t",to_account.name) ); + } FC_RETHROW_EXCEPTIONS( error, "Unable to transfer ${a} from ${f} to ${t}", ("a",d.to_pretty_string(itr->peerplays_asset))("f",from_account.name)("t",to_account.name) ); } FC_CAPTURE_AND_RETHROW( (op) ) } -object_id_type process_son_wallet_transfer_evaluator::do_apply(const son_wallet_transfer_process_operation& op) +object_id_type process_son_wallet_deposit_evaluator::do_apply(const son_wallet_deposit_process_operation& op) { try { - const auto& idx = db().get_index_type().indices().get(); - auto itr = idx.find(op.son_wallet_transfer_id); + const auto& idx = db().get_index_type().indices().get(); + auto itr = idx.find(op.son_wallet_deposit_id); if(itr != idx.end()) { if (itr->processed == false) { - db().modify(*itr, [&op](son_wallet_transfer_object &swto) { + db().modify(*itr, [&op](son_wallet_deposit_object &swto) { swto.processed = true; }); const account_id_type from_account = itr->peerplays_to; // reversed, for deposit const account_id_type to_account = itr->peerplays_from; // reversed, for deposit - db().adjust_balance( from_account, -itr->peerplays_amount ); - db().adjust_balance( to_account, itr->peerplays_amount ); + db().adjust_balance( from_account, -itr->peerplays_asset ); + db().adjust_balance( to_account, itr->peerplays_asset ); } } - return op.son_wallet_transfer_id; + return op.son_wallet_deposit_id; } FC_CAPTURE_AND_RETHROW( (op) ) } } } // namespace graphene::chain diff --git a/libraries/chain/son_wallet_evaluator.cpp b/libraries/chain/son_wallet_evaluator.cpp index 736832d9..15a1d120 100644 --- a/libraries/chain/son_wallet_evaluator.cpp +++ b/libraries/chain/son_wallet_evaluator.cpp @@ -8,8 +8,7 @@ namespace graphene { namespace chain { void_result recreate_son_wallet_evaluator::do_evaluate(const son_wallet_recreate_operation& op) { try{ FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); - //FC_ASSERT(db().get_global_properties().parameters.get_son_btc_account_id() != GRAPHENE_NULL_ACCOUNT, "SON paying account not set."); - FC_ASSERT( op.payer == db().get_global_properties().parameters.get_son_btc_account_id(), "SON paying account must be set as payer." ); + FC_ASSERT( op.payer == GRAPHENE_SON_ACCOUNT, "SON paying account must be set as payer." ); const auto& idx = db().get_index_type().indices().get(); auto itr = idx.rbegin(); @@ -54,8 +53,7 @@ object_id_type recreate_son_wallet_evaluator::do_apply(const son_wallet_recreate void_result update_son_wallet_evaluator::do_evaluate(const son_wallet_update_operation& op) { try{ FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); - //FC_ASSERT(db().get_global_properties().parameters.get_son_btc_account_id() != GRAPHENE_NULL_ACCOUNT, "SON paying account not set."); - FC_ASSERT( op.payer == db().get_global_properties().parameters.get_son_btc_account_id(), "SON paying account must be set as payer." ); + FC_ASSERT( op.payer == GRAPHENE_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_wallet_id) != idx.end() ); diff --git a/libraries/chain/son_wallet_withdraw_evaluator.cpp b/libraries/chain/son_wallet_withdraw_evaluator.cpp new file mode 100644 index 00000000..d3a32a1b --- /dev/null +++ b/libraries/chain/son_wallet_withdraw_evaluator.cpp @@ -0,0 +1,70 @@ +#include + +#include +#include +#include + +namespace graphene { namespace chain { + +void_result create_son_wallet_withdraw_evaluator::do_evaluate(const son_wallet_withdraw_create_operation& op) +{ try{ + FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); + FC_ASSERT( op.payer == GRAPHENE_SON_ACCOUNT, "SON paying account must be set as payer." ); + + return void_result(); +} FC_CAPTURE_AND_RETHROW( (op) ) } + +object_id_type create_son_wallet_withdraw_evaluator::do_apply(const son_wallet_withdraw_create_operation& op) +{ try { + const auto& idx = db().get_index_type().indices().get(); + auto itr = idx.find(op.peerplays_uid); + if (itr == idx.end()) { + const auto& new_son_wallet_withdraw_object = db().create( [&]( son_wallet_withdraw_object& swwo ){ + swwo.timestamp = op.timestamp; + swwo.sidechain = op.sidechain; + swwo.confirmations = 1; + swwo.peerplays_uid = op.peerplays_uid; + swwo.peerplays_transaction_id = op.peerplays_transaction_id; + swwo.peerplays_from = op.peerplays_from; + swwo.peerplays_asset = op.peerplays_asset; + swwo.withdraw_sidechain = op.withdraw_sidechain; + swwo.withdraw_address = op.withdraw_address; + swwo.withdraw_currency = op.withdraw_currency; + swwo.withdraw_amount = op.withdraw_amount; + swwo.processed = false; + }); + return new_son_wallet_withdraw_object.id; + } else { + db().modify(*itr, [&op](son_wallet_withdraw_object &swto) { + swto.confirmations = swto.confirmations + 1; + }); + return (*itr).id; + } +} FC_CAPTURE_AND_RETHROW( (op) ) } + +void_result process_son_wallet_withdraw_evaluator::do_evaluate(const son_wallet_withdraw_process_operation& op) +{ try{ + FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK"); + FC_ASSERT( op.payer == GRAPHENE_SON_ACCOUNT, "SON paying account must be set as payer." ); + + const auto& idx = db().get_index_type().indices().get(); + const auto& itr = idx.find(op.son_wallet_withdraw_id); + FC_ASSERT(itr != idx.end(), "Son wallet withdraw not found"); +} FC_CAPTURE_AND_RETHROW( (op) ) } + +object_id_type process_son_wallet_withdraw_evaluator::do_apply(const son_wallet_withdraw_process_operation& op) +{ try { + const auto& idx = db().get_index_type().indices().get(); + auto itr = idx.find(op.son_wallet_withdraw_id); + if(itr != idx.end()) + { + if (itr->processed == false) { + db().modify(*itr, [&op](son_wallet_withdraw_object &swto) { + swto.processed = true; + }); + } + } + return op.son_wallet_withdraw_id; +} FC_CAPTURE_AND_RETHROW( (op) ) } + +} } // namespace graphene::chain diff --git a/libraries/plugins/peerplays_sidechain/CMakeLists.txt b/libraries/plugins/peerplays_sidechain/CMakeLists.txt old mode 100644 new mode 100755 index a3910c9e..e7d9acfe --- a/libraries/plugins/peerplays_sidechain/CMakeLists.txt +++ b/libraries/plugins/peerplays_sidechain/CMakeLists.txt @@ -5,6 +5,7 @@ add_library( peerplays_sidechain sidechain_net_manager.cpp sidechain_net_handler.cpp sidechain_net_handler_bitcoin.cpp + sidechain_net_handler_peerplays.cpp bitcoin_utils.cpp ) 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 ae1d222c..7c6e8742 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/defs.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/defs.hpp @@ -4,9 +4,11 @@ #include #include +#include #include #include +#include #include namespace graphene { namespace peerplays_sidechain { @@ -70,9 +72,11 @@ struct sidechain_event_data { std::string sidechain_transaction_id; std::string sidechain_from; std::string sidechain_to; - int64_t sidechain_amount; + std::string sidechain_currency; + fc::safe sidechain_amount; chain::account_id_type peerplays_from; chain::account_id_type peerplays_to; + chain::asset peerplays_asset; }; } } // graphene::peerplays_sidechain diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler.hpp index da6321a9..fe042306 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler.hpp @@ -16,11 +16,16 @@ public: virtual ~sidechain_net_handler(); graphene::peerplays_sidechain::sidechain_type get_sidechain(); - std::vector get_sidechain_addresses(); + std::vector get_sidechain_deposit_addresses(); + std::vector get_sidechain_withdraw_addresses(); void sidechain_event_data_received(const sidechain_event_data& sed); virtual void recreate_primary_wallet() = 0; + virtual void process_deposits() = 0; + virtual void process_deposit(const son_wallet_deposit_object& swdo) = 0; + virtual void process_withdrawals() = 0; + virtual void process_withdrawal(const son_wallet_withdraw_object& swwo) = 0; protected: peerplays_sidechain_plugin& plugin; @@ -32,8 +37,6 @@ protected: virtual std::string sign_transaction( const std::string& transaction ) = 0; virtual std::string send_transaction( const std::string& transaction ) = 0; - virtual void handle_event( const std::string& event_data ) = 0; - private: }; diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp index 9768066b..6128ced8 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp @@ -7,7 +7,6 @@ #include #include -#include namespace graphene { namespace peerplays_sidechain { @@ -72,8 +71,10 @@ public: virtual ~sidechain_net_handler_bitcoin(); void recreate_primary_wallet(); - - bool connection_is_not_defined() const; + void process_deposits(); + void process_deposit(const son_wallet_deposit_object& swdo); + void process_withdrawals(); + void process_withdrawal(const son_wallet_withdraw_object& swwo); std::string create_multisignature_wallet( const std::vector public_keys ); std::string transfer( const std::string& from, const std::string& to, const uint64_t amount ); diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_peerplays.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_peerplays.hpp new file mode 100644 index 00000000..13d5de52 --- /dev/null +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_peerplays.hpp @@ -0,0 +1,34 @@ +#pragma once + +#include + +#include + +#include + +namespace graphene { namespace peerplays_sidechain { + +class sidechain_net_handler_peerplays : public sidechain_net_handler { +public: + sidechain_net_handler_peerplays(peerplays_sidechain_plugin& _plugin, const boost::program_options::variables_map& options); + virtual ~sidechain_net_handler_peerplays(); + + void recreate_primary_wallet(); + void process_deposits(); + void process_deposit(const son_wallet_deposit_object& swdo); + void process_withdrawals(); + void process_withdrawal(const son_wallet_withdraw_object& swwo); + + std::string create_multisignature_wallet( const std::vector public_keys ); + std::string transfer( const std::string& from, const std::string& to, const uint64_t amount ); + std::string sign_transaction( const std::string& transaction ); + std::string send_transaction( const std::string& transaction ); + +private: + + void on_block_applied(const signed_block& b); + +}; + +} } // graphene::peerplays_sidechain + diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_manager.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_manager.hpp index bd6f1ab3..b9ae658f 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_manager.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_manager.hpp @@ -17,6 +17,8 @@ public: bool create_handler(peerplays_sidechain::sidechain_type sidechain, const boost::program_options::variables_map& options); void recreate_primary_wallet(); + void process_deposits(); + void process_withdrawals(); private: peerplays_sidechain_plugin& plugin; graphene::chain::database& database; diff --git a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp index a32d9dd8..e5680d45 100644 --- a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp +++ b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include @@ -46,27 +46,30 @@ class peerplays_sidechain_plugin_impl void create_son_down_proposals(); void recreate_primary_wallet(); void process_deposits(); - //void process_withdrawals(); - void on_block_applied( const signed_block& b ); - void on_objects_new(const vector& new_object_ids); + void process_withdrawals(); private: peerplays_sidechain_plugin& plugin; bool config_ready_son; bool config_ready_bitcoin; + bool config_ready_peerplays; std::unique_ptr net_manager; std::map _private_keys; std::set _sons; fc::future _heartbeat_task; + void on_block_applied( const signed_block& b ); + void on_objects_new(const vector& new_object_ids); + }; peerplays_sidechain_plugin_impl::peerplays_sidechain_plugin_impl(peerplays_sidechain_plugin& _plugin) : plugin(_plugin), config_ready_son(false), config_ready_bitcoin(false), + config_ready_peerplays(false), net_manager(nullptr) { } @@ -177,6 +180,14 @@ void peerplays_sidechain_plugin_impl::plugin_initialize(const boost::program_opt // wlog("Haven't set up Ethereum sidechain parameters"); //} + config_ready_peerplays = true; + if (config_ready_peerplays) { + net_manager->create_handler(sidechain_type::peerplays, options); + ilog("Peerplays sidechain handler created"); + } else { + wlog("Haven't set up Peerplays sidechain parameters"); + } + if (!(config_ready_bitcoin /*&& config_ready_ethereum*/)) { wlog("Haven't set up any sidechain parameters"); throw; @@ -200,6 +211,10 @@ void peerplays_sidechain_plugin_impl::plugin_startup() //if (config_ready_ethereum) { // ilog("Ethereum sidechain handler running"); //} + + if (config_ready_peerplays) { + ilog("Peerplays sidechain handler running"); + } } std::set& peerplays_sidechain_plugin_impl::get_sons() @@ -307,7 +322,7 @@ void peerplays_sidechain_plugin_impl::create_son_down_proposals() auto son_obj = idx.find( my_son_id ); chain::son_report_down_operation son_down_op; - son_down_op.payer = gpo.parameters.get_son_btc_account_id(); + son_down_op.payer = GRAPHENE_SON_ACCOUNT; son_down_op.son_id = son_id; son_down_op.down_ts = last_active_ts; @@ -360,47 +375,15 @@ void peerplays_sidechain_plugin_impl::recreate_primary_wallet() net_manager->recreate_primary_wallet(); } -void peerplays_sidechain_plugin_impl::process_deposits() { - - const auto& idx = plugin.database().get_index_type().indices().get(); - const auto& idx_range = idx.equal_range(false); - - std::for_each(idx_range.first, idx_range.second, - [&] (const son_wallet_transfer_object& swto) { - - const chain::global_property_object& gpo = plugin.database().get_global_properties(); - - for (son_id_type son_id : plugin.get_sons()) { - if (plugin.is_active_son(son_id)) { - - son_wallet_transfer_process_operation p_op; - p_op.payer = gpo.parameters.get_son_btc_account_id(); - p_op.son_wallet_transfer_id = swto.id; - - 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_wrapper( p_op ) ); - uint32_t lifetime = ( gpo.parameters.block_interval * gpo.active_witnesses.size() ) * 3; - proposal_op.expiration_time = time_point_sec( plugin.database().head_block_time().sec_since_epoch() + lifetime ); - - ilog("sidechain_net_handler: sending proposal for transfer operation ${swto} by ${son}", ("swto", swto.id) ("son", son_id)); - signed_transaction trx = plugin.database().create_signed_transaction(plugin.get_private_key(son_id), proposal_op); - trx.validate(); - ilog("sidechain_net_handler: transaction validated ${swto} by ${son}", ("swto", swto.id) ("son", son_id)); - try { - plugin.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){ - ilog("sidechain_net_handler: sending proposal for transfer operation failed with exception ${e}",("e", e.what())); - } - } - } - }); +void peerplays_sidechain_plugin_impl::process_deposits() +{ + net_manager->process_deposits(); } -//void peerplays_sidechain_plugin_impl::process_withdrawals() { -//} +void peerplays_sidechain_plugin_impl::process_withdrawals() +{ + net_manager->process_withdrawals(); +} void peerplays_sidechain_plugin_impl::on_block_applied( const signed_block& b ) { @@ -423,7 +406,7 @@ void peerplays_sidechain_plugin_impl::on_block_applied( const signed_block& b ) process_deposits(); - //process_withdrawals(); + process_withdrawals(); } } @@ -481,13 +464,25 @@ void peerplays_sidechain_plugin_impl::on_objects_new(const vectorproposed_transaction.operations.size() == 1 - && proposal->proposed_transaction.operations[0].which() == chain::operation::tag::value) { + && proposal->proposed_transaction.operations[0].which() == chain::operation::tag::value) { approve_proposal( son_id, proposal->id ); continue; } if(proposal->proposed_transaction.operations.size() == 1 - && proposal->proposed_transaction.operations[0].which() == chain::operation::tag::value) { + && proposal->proposed_transaction.operations[0].which() == chain::operation::tag::value) { + approve_proposal( son_id, proposal->id ); + continue; + } + + if(proposal->proposed_transaction.operations.size() == 1 + && proposal->proposed_transaction.operations[0].which() == chain::operation::tag::value) { + approve_proposal( son_id, proposal->id ); + continue; + } + + if(proposal->proposed_transaction.operations.size() == 1 + && proposal->proposed_transaction.operations[0].which() == chain::operation::tag::value) { approve_proposal( 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 ac50974c..e89bd9c8 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp @@ -1,6 +1,8 @@ #include #include +#include +#include #include @@ -19,25 +21,29 @@ graphene::peerplays_sidechain::sidechain_type sidechain_net_handler::get_sidecha return sidechain; } -std::vector sidechain_net_handler::get_sidechain_addresses() { +std::vector sidechain_net_handler::get_sidechain_deposit_addresses() { std::vector result; - switch (sidechain) { - case sidechain_type::bitcoin: - { - const auto& sidechain_addresses_idx = database.get_index_type(); - const auto& sidechain_addresses_by_sidechain_idx = sidechain_addresses_idx.indices().get(); - const auto& sidechain_addresses_by_sidechain_range = sidechain_addresses_by_sidechain_idx.equal_range(sidechain); - std::for_each(sidechain_addresses_by_sidechain_range.first, sidechain_addresses_by_sidechain_range.second, - [&result] (const sidechain_address_object& sao) { - result.push_back(sao.address); - }); - break; - } - default: - assert(false); - } + const auto& sidechain_addresses_idx = database.get_index_type(); + const auto& sidechain_addresses_by_sidechain_idx = sidechain_addresses_idx.indices().get(); + const auto& sidechain_addresses_by_sidechain_range = sidechain_addresses_by_sidechain_idx.equal_range(sidechain); + std::for_each(sidechain_addresses_by_sidechain_range.first, sidechain_addresses_by_sidechain_range.second, + [&result] (const sidechain_address_object& sao) { + result.push_back(sao.deposit_address); + }); + return result; +} +std::vector sidechain_net_handler::get_sidechain_withdraw_addresses() { + std::vector result; + + const auto& sidechain_addresses_idx = database.get_index_type(); + const auto& sidechain_addresses_by_sidechain_idx = sidechain_addresses_idx.indices().get(); + const auto& sidechain_addresses_by_sidechain_range = sidechain_addresses_by_sidechain_idx.equal_range(sidechain); + std::for_each(sidechain_addresses_by_sidechain_range.first, sidechain_addresses_by_sidechain_range.second, + [&result] (const sidechain_address_object& sao) { + result.push_back(sao.withdraw_address); + }); return result; } @@ -49,44 +55,181 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_ ilog( " sidechain_transaction_id: ${transaction_id}", ( "transaction_id", sed.sidechain_transaction_id ) ); ilog( " sidechain_from: ${from}", ( "from", sed.sidechain_from ) ); ilog( " sidechain_to: ${to}", ( "to", sed.sidechain_to ) ); + ilog( " sidechain_currency: ${currency}", ( "currency", sed.sidechain_currency ) ); ilog( " sidechain_amount: ${amount}", ( "amount", sed.sidechain_amount ) ); ilog( " peerplays_from: ${peerplays_from}", ( "peerplays_from", sed.peerplays_from ) ); ilog( " peerplays_to: ${peerplays_to}", ( "peerplays_to", sed.peerplays_to ) ); + ilog( " peerplays_asset: ${peerplays_asset}", ( "peerplays_asset", sed.peerplays_asset ) ); const chain::global_property_object& gpo = database.get_global_properties(); - son_wallet_transfer_create_operation op; - op.payer = gpo.parameters.get_son_btc_account_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_amount = sed.sidechain_amount; - op.peerplays_from = sed.peerplays_from; - op.peerplays_to = sed.peerplays_to; - op.peerplays_amount = asset(sed.sidechain_amount / 1000); // For Bitcoin, the exchange rate is 1:1, for others, get the exchange rate from market + // Deposit request + if ((sed.peerplays_to == GRAPHENE_SON_ACCOUNT) && (sed.sidechain_currency.compare("1.3.0") != 0)) { + son_wallet_deposit_create_operation op; + op.payer = GRAPHENE_SON_ACCOUNT; + 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)) { - 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_wrapper( 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 ); + for (son_id_type son_id : plugin.get_sons()) { + if (plugin.is_active_son(son_id)) { + 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_wrapper( 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 ); - ilog("sidechain_net_handler: sending proposal for son wallet transfer create operation by ${son}", ("son", son_id)); - signed_transaction trx = plugin.database().create_signed_transaction(plugin.get_private_key(son_id), proposal_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){ - ilog("sidechain_net_handler: sending proposal for son wallet transfer create operation by ${son} failed with exception ${e}", ("son", son_id) ("e", e.what())); + ilog("sidechain_net_handler: sending proposal for son wallet deposit create operation by ${son}", ("son", son_id)); + signed_transaction trx = plugin.database().create_signed_transaction(plugin.get_private_key(son_id), proposal_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){ + ilog("sidechain_net_handler: sending proposal for son wallet deposit create operation by ${son} failed with exception ${e}", ("son", son_id) ("e", e.what())); + } } } + return; } + + // Withdrawal request + if ((sed.peerplays_to == GRAPHENE_SON_ACCOUNT) && (sed.sidechain_currency.compare("1.3.0") == 0)) { + // BTC Payout only (for now) + const auto& sidechain_addresses_idx = database.get_index_type().indices().get(); + const auto& addr_itr = sidechain_addresses_idx.find(std::make_tuple(sed.peerplays_from, sidechain_type::bitcoin)); + if ( addr_itr == sidechain_addresses_idx.end() ) + return; + + son_wallet_withdraw_create_operation op; + op.payer = GRAPHENE_SON_ACCOUNT; + 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)) { + 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_wrapper( 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 ); + + ilog("sidechain_net_handler: sending proposal for son wallet withdraw create operation by ${son}", ("son", son_id)); + signed_transaction trx = plugin.database().create_signed_transaction(plugin.get_private_key(son_id), proposal_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){ + ilog("sidechain_net_handler: sending proposal for son wallet withdraw create operation by ${son} failed with exception ${e}", ("son", son_id) ("e", e.what())); + } + } + } + return; + } + + FC_ASSERT(false, "Invalid sidechain event"); +} + +void sidechain_net_handler::recreate_primary_wallet() { + FC_ASSERT(false, "recreate_primary_wallet not implemented"); +} + +void sidechain_net_handler::process_deposits() { + const auto& idx = plugin.database().get_index_type().indices().get(); + const auto& idx_range = idx.equal_range(std::make_tuple(sidechain, false)); + + std::for_each(idx_range.first, idx_range.second, + [&] (const son_wallet_deposit_object& swdo) { + + process_deposit(swdo); + + const chain::global_property_object& gpo = plugin.database().get_global_properties(); + + for (son_id_type son_id : plugin.get_sons()) { + if (plugin.is_active_son(son_id)) { + + son_wallet_deposit_process_operation p_op; + p_op.payer = GRAPHENE_SON_ACCOUNT; + p_op.son_wallet_deposit_id = swdo.id; + + 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_wrapper( p_op ) ); + uint32_t lifetime = ( gpo.parameters.block_interval * gpo.active_witnesses.size() ) * 3; + proposal_op.expiration_time = time_point_sec( plugin.database().head_block_time().sec_since_epoch() + lifetime ); + + ilog("sidechain_net_handler: sending proposal for transfer operation ${swdo} by ${son}", ("swdo", swdo.id) ("son", son_id)); + signed_transaction trx = plugin.database().create_signed_transaction(plugin.get_private_key(son_id), proposal_op); + trx.validate(); + ilog("sidechain_net_handler: transaction validated ${swdo} by ${son}", ("swdo", swdo.id) ("son", son_id)); + try { + plugin.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){ + ilog("sidechain_net_handler: sending proposal for transfer operation failed with exception ${e}",("e", e.what())); + } + } + } + }); +} + +void sidechain_net_handler::process_withdrawals() { + const auto& idx = plugin.database().get_index_type().indices().get(); + const auto& idx_range = idx.equal_range(std::make_tuple(sidechain, false)); + + std::for_each(idx_range.first, idx_range.second, + [&] (const son_wallet_withdraw_object& swwo) { + + process_withdrawal(swwo); + + const chain::global_property_object& gpo = plugin.database().get_global_properties(); + + for (son_id_type son_id : plugin.get_sons()) { + if (plugin.is_active_son(son_id)) { + + ilog("SON ${son_id}: Withdraw to process: ${swwo}", ("son_id", son_id) ("swwo", swwo)); + //son_wallet_withdraw_process_operation p_op; + //p_op.payer = GRAPHENE_SON_ACCOUNT; + //p_op.son_wallet_withdraw_id = swwo.id; + // + //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_wrapper( p_op ) ); + //uint32_t lifetime = ( gpo.parameters.block_interval * gpo.active_witnesses.size() ) * 3; + //proposal_op.expiration_time = time_point_sec( plugin.database().head_block_time().sec_since_epoch() + lifetime ); + // + //ilog("sidechain_net_handler: sending proposal for transfer operation ${swwo} by ${son}", ("swwo", swwo.id) ("son", son_id)); + //signed_transaction trx = plugin.database().create_signed_transaction(plugin.get_private_key(son_id), proposal_op); + //trx.validate(); + //ilog("sidechain_net_handler: transaction validated ${swwo} by ${son}", ("swwo", swwo.id) ("son", son_id)); + //try { + // plugin.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){ + // ilog("sidechain_net_handler: sending proposal for transfer operation failed with exception ${e}",("e", e.what())); + //} + } + } + }); } } } // graphene::peerplays_sidechain diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp index 40da9240..9dd5ab39 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp @@ -15,6 +15,8 @@ #include #include #include +#include +#include #include namespace graphene { namespace peerplays_sidechain { @@ -396,7 +398,7 @@ void sidechain_net_handler_bitcoin::recreate_primary_wallet() { boost::property_tree::json_parser::write_json(res, pt.get_child("result")); son_wallet_update_operation op; - op.payer = gpo.parameters.get_son_btc_account_id(); + op.payer = GRAPHENE_SON_ACCOUNT; op.son_wallet_id = (*obj).id; op.sidechain = sidechain_type::bitcoin; op.address = res.str(); @@ -422,43 +424,45 @@ void sidechain_net_handler_bitcoin::recreate_primary_wallet() { } } -bool sidechain_net_handler_bitcoin::connection_is_not_defined() const -{ - return listener->connection_is_not_defined() && bitcoin_client->connection_is_not_defined(); +void sidechain_net_handler_bitcoin::process_deposits() { + sidechain_net_handler::process_deposits(); } -std::string sidechain_net_handler_bitcoin::create_multisignature_wallet( const std::vector public_keys ) -{ +void sidechain_net_handler_bitcoin::process_deposit(const son_wallet_deposit_object& swdo) { +} + +void sidechain_net_handler_bitcoin::process_withdrawals() { + sidechain_net_handler::process_withdrawals(); +} + +void sidechain_net_handler_bitcoin::process_withdrawal(const son_wallet_withdraw_object& swwo) { +} + +std::string sidechain_net_handler_bitcoin::create_multisignature_wallet( const std::vector public_keys ) { return bitcoin_client->add_multisig_address(public_keys); } -std::string sidechain_net_handler_bitcoin::transfer( const std::string& from, const std::string& to, const uint64_t amount ) -{ +std::string sidechain_net_handler_bitcoin::transfer( const std::string& from, const std::string& to, const uint64_t amount ) { return ""; } -std::string sidechain_net_handler_bitcoin::sign_transaction( const std::string& transaction ) -{ +std::string sidechain_net_handler_bitcoin::sign_transaction( const std::string& transaction ) { return ""; } -std::string sidechain_net_handler_bitcoin::send_transaction( const std::string& transaction ) -{ +std::string sidechain_net_handler_bitcoin::send_transaction( const std::string& transaction ) { return ""; } void sidechain_net_handler_bitcoin::handle_event( const std::string& event_data ) { - ilog("peerplays sidechain plugin: sidechain_net_handler_bitcoin::handle_event"); - ilog(" event_data: ${event_data}", ("event_data", event_data)); - std::string block = bitcoin_client->receive_full_block( event_data ); if( block != "" ) { const auto& vins = extract_info_from_block( block ); - const auto& sidechain_addresses_idx = database.get_index_type().indices().get(); + const auto& sidechain_addresses_idx = database.get_index_type().indices().get(); for( const auto& v : vins ) { - const auto& addr_itr = sidechain_addresses_idx.find(std::make_tuple(sidechain_type::bitcoin, v.address)); + const auto& addr_itr = sidechain_addresses_idx.find(std::make_tuple(sidechain, v.address)); if ( addr_itr == sidechain_addresses_idx.end() ) continue; @@ -473,16 +477,17 @@ void sidechain_net_handler_bitcoin::handle_event( const std::string& event_data sed.sidechain_transaction_id = v.out.hash_tx; sed.sidechain_from = ""; sed.sidechain_to = v.address; + sed.sidechain_currency = "BTC"; sed.sidechain_amount = v.out.amount; sed.peerplays_from = addr_itr->sidechain_address_account; sed.peerplays_to = GRAPHENE_SON_ACCOUNT; + sed.peerplays_asset = asset(sed.sidechain_amount / 1000); // For Bitcoin, the exchange rate is 1:1, for others, get the exchange rate from market sidechain_event_data_received(sed); } } } -std::vector sidechain_net_handler_bitcoin::extract_info_from_block( const std::string& _block ) -{ +std::vector sidechain_net_handler_bitcoin::extract_info_from_block( const std::string& _block ) { std::stringstream ss( _block ); boost::property_tree::ptree block; boost::property_tree::read_json( ss, block ); diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp new file mode 100644 index 00000000..bfdd5370 --- /dev/null +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp @@ -0,0 +1,99 @@ +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace graphene { namespace peerplays_sidechain { + +sidechain_net_handler_peerplays::sidechain_net_handler_peerplays(peerplays_sidechain_plugin& _plugin, const boost::program_options::variables_map& options) : + sidechain_net_handler(_plugin, options) { + sidechain = sidechain_type::peerplays; + plugin.database().applied_block.connect( [&] (const signed_block& b) { on_block_applied(b); } ); +} + +sidechain_net_handler_peerplays::~sidechain_net_handler_peerplays() { +} + +void sidechain_net_handler_peerplays::recreate_primary_wallet() { +} + +void sidechain_net_handler_peerplays::process_deposits() { + sidechain_net_handler::process_deposits(); +} + +void sidechain_net_handler_peerplays::process_deposit(const son_wallet_deposit_object& swdo) { +} + +void sidechain_net_handler_peerplays::process_withdrawals() { + sidechain_net_handler::process_withdrawals(); +} + +void sidechain_net_handler_peerplays::process_withdrawal(const son_wallet_withdraw_object& swwo) { +} + +std::string sidechain_net_handler_peerplays::create_multisignature_wallet( const std::vector public_keys ) { + return ""; +} + +std::string sidechain_net_handler_peerplays::transfer( const std::string& from, const std::string& to, const uint64_t amount ) { + return ""; +} + +std::string sidechain_net_handler_peerplays::sign_transaction( const std::string& transaction ) { + return ""; +} + +std::string sidechain_net_handler_peerplays::send_transaction( const std::string& transaction ) { + return ""; +} + +void sidechain_net_handler_peerplays::on_block_applied(const signed_block& b) { + for (const auto& trx: b.transactions) { + size_t operation_index = -1; + for (auto op: trx.operations) { + operation_index = operation_index + 1; + if (op.which() == operation::tag::value){ + transfer_operation transfer_op = op.get(); + if (transfer_op.to != GRAPHENE_SON_ACCOUNT) { + continue; + } + + std::stringstream ss; + ss << "peerplays" << "-" << trx.id().str() << "-" << operation_index; + std::string sidechain_uid = ss.str(); + + sidechain_event_data sed; + sed.timestamp = plugin.database().head_block_time(); + sed.sidechain = sidechain_type::peerplays; + sed.sidechain_uid = sidechain_uid; + sed.sidechain_transaction_id = trx.id().str(); + sed.sidechain_from = fc::to_string(transfer_op.from.space_id) + "." + fc::to_string(transfer_op.from.type_id) + "." + fc::to_string((uint64_t)transfer_op.from.instance); + sed.sidechain_to = fc::to_string(transfer_op.to.space_id) + "." + fc::to_string(transfer_op.to.type_id) + "." + fc::to_string((uint64_t)transfer_op.to.instance); + sed.sidechain_currency = fc::to_string(transfer_op.amount.asset_id.space_id) + "." + fc::to_string(transfer_op.amount.asset_id.type_id) + "." + fc::to_string((uint64_t)transfer_op.amount.asset_id.instance); //transfer_op.amount.asset_id(plugin.database()).symbol; + sed.sidechain_amount = transfer_op.amount.amount; + sed.peerplays_from = transfer_op.from; + sed.peerplays_to = transfer_op.to; + // We should calculate exchange rate between CORE/TEST and other Peerplays asset + sed.peerplays_asset = asset(transfer_op.amount.amount / transfer_op.amount.asset_id(plugin.database()).options.core_exchange_rate.quote.amount); + sidechain_event_data_received(sed); + } + } + } +} + +} } // graphene::peerplays_sidechain + diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_manager.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_manager.cpp index 8b6f18c1..b9e5dd8d 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_manager.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_manager.cpp @@ -3,6 +3,7 @@ #include #include #include +#include namespace graphene { namespace peerplays_sidechain { @@ -26,6 +27,12 @@ bool sidechain_net_manager::create_handler(peerplays_sidechain::sidechain_type s ret_val = true; break; } + case sidechain_type::peerplays: { + std::unique_ptr h = std::unique_ptr(new sidechain_net_handler_peerplays(plugin, options)); + net_handlers.push_back(std::move(h)); + ret_val = true; + break; + } default: assert(false); } @@ -39,5 +46,17 @@ void sidechain_net_manager::recreate_primary_wallet() { } } +void sidechain_net_manager::process_deposits() { + for ( size_t i = 0; i < net_handlers.size(); i++ ) { + net_handlers.at(i)->process_deposits(); + } +} + +void sidechain_net_manager::process_withdrawals() { + for ( size_t i = 0; i < net_handlers.size(); i++ ) { + net_handlers.at(i)->process_withdrawals(); + } +} + } } // graphene::peerplays_sidechain diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index bfe9ab35..34fc1885 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -1416,17 +1416,15 @@ class wallet_api * * @param account the name or id of the account who owns the address * @param sidechain a sidechain to whom address belongs - * @param address sidechain address - * @param private_key private key for sidechain address - * @param public_key public key for sidechain address + * @param deposit_address sidechain address for deposits + * @param withdraw_address sidechain address for withdrawals * @param broadcast true to broadcast the transaction on the network * @returns the signed transaction adding sidechain address */ signed_transaction add_sidechain_address(string account, peerplays_sidechain::sidechain_type sidechain, - string address, - string private_key, - string public_key, + string deposit_address, + string withdraw_address, bool broadcast = false); /** Updates existing sidechain address owned by the given account for a given sidechain. @@ -1435,17 +1433,15 @@ class wallet_api * * @param account the name or id of the account who owns the address * @param sidechain a sidechain to whom address belongs - * @param address sidechain address - * @param private_key private key for sidechain address - * @param public_key public key for sidechain address + * @param deposit_address sidechain address for deposits + * @param withdraw_address sidechain address for withdrawals * @param broadcast true to broadcast the transaction on the network * @returns the signed transaction updating sidechain address */ signed_transaction update_sidechain_address(string account, peerplays_sidechain::sidechain_type sidechain, - string address, - string private_key, - string public_key, + string deposit_address, + string withdraw_address, bool broadcast = false); /** Deletes existing sidechain address owned by the given account for a given sidechain. diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 943b6f1c..8af353e2 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -2025,9 +2025,8 @@ public: signed_transaction add_sidechain_address(string account, peerplays_sidechain::sidechain_type sidechain, - string address, - string private_key, - string public_key, + string deposit_address, + string withdraw_address, bool broadcast /* = false */) { try { account_id_type sidechain_address_account_id = get_account_id(account); @@ -2035,9 +2034,8 @@ public: sidechain_address_add_operation op; op.sidechain_address_account = sidechain_address_account_id; op.sidechain = sidechain; - op.address = address; - op.private_key = private_key; - op.public_key = public_key; + op.deposit_address = deposit_address; + op.withdraw_address = withdraw_address; signed_transaction tx; tx.operations.push_back( op ); @@ -2049,9 +2047,8 @@ public: signed_transaction update_sidechain_address(string account, peerplays_sidechain::sidechain_type sidechain, - string address, - string private_key, - string public_key, + string deposit_address, + string withdraw_address, bool broadcast /* = false */) { try { account_id_type sidechain_address_account_id = get_account_id(account); @@ -2063,9 +2060,8 @@ public: op.sidechain_address_id = sao->id; op.sidechain_address_account = sidechain_address_account_id; op.sidechain = sidechain; - op.address = address; - op.private_key = private_key; - op.public_key = public_key; + op.deposit_address = deposit_address; + op.withdraw_address = withdraw_address; signed_transaction tx; tx.operations.push_back( op ); @@ -4504,22 +4500,20 @@ vector> wallet_api::get_son_wallets(uint32_t limit) signed_transaction wallet_api::add_sidechain_address(string account, peerplays_sidechain::sidechain_type sidechain, - string address, - string private_key, - string public_key, + string deposit_address, + string withdraw_address, bool broadcast /* = false */) { - return my->add_sidechain_address(account, sidechain, address, private_key, public_key, broadcast); + return my->add_sidechain_address(account, sidechain, deposit_address, withdraw_address, broadcast); } signed_transaction wallet_api::update_sidechain_address(string account, peerplays_sidechain::sidechain_type sidechain, - string address, - string private_key, - string public_key, + string deposit_address, + string withdraw_address, bool broadcast /* = false */) { - return my->update_sidechain_address(account, sidechain, address, private_key, public_key, broadcast); + return my->update_sidechain_address(account, sidechain, deposit_address, withdraw_address, broadcast); } signed_transaction wallet_api::delete_sidechain_address(string account, diff --git a/programs/js_operation_serializer/main.cpp b/programs/js_operation_serializer/main.cpp index 04a94827..3c2c2577 100644 --- a/programs/js_operation_serializer/main.cpp +++ b/programs/js_operation_serializer/main.cpp @@ -45,7 +45,8 @@ #include #include #include -#include +#include +#include #include #include diff --git a/tests/tests/history_api_tests.cpp b/tests/tests/history_api_tests.cpp old mode 100755 new mode 100644 diff --git a/tests/tests/sidechain_addresses_test.cpp b/tests/tests/sidechain_addresses_test.cpp index eef76784..bee7cec8 100644 --- a/tests/tests/sidechain_addresses_test.cpp +++ b/tests/tests/sidechain_addresses_test.cpp @@ -30,9 +30,8 @@ BOOST_AUTO_TEST_CASE( sidechain_address_add_test ) { op.sidechain_address_account = alice_id; op.sidechain = graphene::peerplays_sidechain::sidechain_type::bitcoin; - op.address = "address"; - op.private_key = "private_key"; - op.public_key = "public_key"; + op.deposit_address = "deposit_address"; + op.withdraw_address = "withdraw_address"; trx.operations.push_back(op); sign(trx, alice_private_key); @@ -48,9 +47,8 @@ BOOST_AUTO_TEST_CASE( sidechain_address_add_test ) { 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->address == "address" ); - BOOST_CHECK( obj->private_key == "private_key" ); - BOOST_CHECK( obj->public_key == "public_key" ); + BOOST_CHECK( obj->deposit_address == "deposit_address" ); + BOOST_CHECK( obj->withdraw_address == "withdraw_address" ); } BOOST_AUTO_TEST_CASE( sidechain_address_update_test ) { @@ -66,9 +64,8 @@ BOOST_AUTO_TEST_CASE( sidechain_address_update_test ) { auto obj = idx.find( boost::make_tuple( alice_id, graphene::peerplays_sidechain::sidechain_type::bitcoin ) ); BOOST_REQUIRE( obj != idx.end() ); - std::string new_address = "new_address"; - std::string new_private_key = "new_private_key"; - std::string new_public_key = "new_public_key"; + std::string new_deposit_address = "new_deposit_address"; + std::string new_withdraw_address = "new_withdraw_address"; { BOOST_TEST_MESSAGE("Send sidechain_address_update_operation"); @@ -77,9 +74,8 @@ BOOST_AUTO_TEST_CASE( sidechain_address_update_test ) { op.sidechain_address_id = sidechain_address_id_type(0); op.sidechain_address_account = obj->sidechain_address_account; op.sidechain = obj->sidechain; - op.address = new_address; - op.private_key = new_private_key; - op.public_key = new_public_key; + op.deposit_address = new_deposit_address; + op.withdraw_address = new_withdraw_address; trx.operations.push_back(op); sign(trx, alice_private_key); @@ -96,9 +92,8 @@ BOOST_AUTO_TEST_CASE( sidechain_address_update_test ) { BOOST_REQUIRE( obj != idx.end() ); BOOST_CHECK( obj->sidechain_address_account == obj->sidechain_address_account ); BOOST_CHECK( obj->sidechain == obj->sidechain ); - BOOST_CHECK( obj->address == new_address ); - BOOST_CHECK( obj->private_key == new_private_key ); - BOOST_CHECK( obj->public_key == new_public_key ); + BOOST_CHECK( obj->deposit_address == new_deposit_address ); + BOOST_CHECK( obj->withdraw_address == new_withdraw_address ); } } diff --git a/tests/tests/son_operations_tests.cpp b/tests/tests/son_operations_tests.cpp index c283f21e..3925f02b 100644 --- a/tests/tests/son_operations_tests.cpp +++ b/tests/tests/son_operations_tests.cpp @@ -843,35 +843,12 @@ BOOST_AUTO_TEST_CASE( son_report_down_test ) { BOOST_CHECK( obj->status == son_status::active); - const auto& son_btc_account = db.create( [&]( account_object& obj ) { - obj.name = "son_btc_account"; - obj.statistics = db.create([&]( account_statistics_object& acc_stat ){ acc_stat.owner = obj.id; }).id; - obj.membership_expiration_date = time_point_sec::maximum(); - obj.network_fee_percentage = GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; - obj.lifetime_referrer_fee_percentage = GRAPHENE_100_PERCENT - GRAPHENE_DEFAULT_NETWORK_PERCENT_OF_FEE; - - obj.owner.add_authority( bob_id, 1 ); - obj.active.add_authority( bob_id, 1 ); - obj.active.weight_threshold = 1; - obj.owner.weight_threshold = 1; - }); - - db.modify( db.get_global_properties(), [&]( global_property_object& _gpo ) - { - _gpo.parameters.extensions.value.son_pay_daily_max = 200; - _gpo.parameters.witness_pay_per_block = 0; - - _gpo.parameters.extensions.value.son_btc_account = son_btc_account.get_id(); - if( _gpo.pending_parameters ) - _gpo.pending_parameters->extensions.value.son_btc_account = son_btc_account.get_id(); - }); - { // Check that transaction fails if down_ts < last_active_timestamp generate_block(); // Send Report Down Operation for an active status SON son_report_down_operation op; - op.payer = db.get_global_properties().parameters.get_son_btc_account_id(); + op.payer = GRAPHENE_SON_ACCOUNT; op.son_id = son_id_type(0); op.down_ts = fc::time_point_sec(son_stats_obj->last_active_timestamp - fc::seconds(1)); @@ -884,7 +861,7 @@ BOOST_AUTO_TEST_CASE( son_report_down_test ) { } { - // Check that transaction fails if payer is not son_btc_account. + // Check that transaction fails if payer is not GRAPHENE_SON_ACCOUNT. generate_block(); // Send Report Down Operation for an active status SON son_report_down_operation op; @@ -901,11 +878,11 @@ BOOST_AUTO_TEST_CASE( son_report_down_test ) { } { - // Check that transaction succeeds after getting enough approvals on son_btc_account. + // Check that transaction succeeds after getting enough approvals on GRAPHENE_SON_ACCOUNT. generate_block(); // Send Report Down Operation for an active status SON son_report_down_operation op; - op.payer = db.get_global_properties().parameters.get_son_btc_account_id(); + op.payer = GRAPHENE_SON_ACCOUNT; op.son_id = son_id_type(0); op.down_ts = son_stats_obj->last_active_timestamp; @@ -925,7 +902,7 @@ BOOST_AUTO_TEST_CASE( son_report_down_test ) { generate_block(); // Send Report Down Operation for an active status SON son_report_down_operation op; - op.payer = db.get_global_properties().parameters.get_son_btc_account_id(); + op.payer = GRAPHENE_SON_ACCOUNT; op.son_id = son_id_type(0); op.down_ts = son_stats_obj->last_active_timestamp; diff --git a/tests/tests/son_wallet_tests.cpp b/tests/tests/son_wallet_tests.cpp index 1a912e05..486f46ed 100644 --- a/tests/tests/son_wallet_tests.cpp +++ b/tests/tests/son_wallet_tests.cpp @@ -152,7 +152,7 @@ BOOST_AUTO_TEST_CASE( son_wallet_recreate_test ) { son_wallet_recreate_operation op; - op.payer = db.get_global_properties().parameters.get_son_btc_account_id(); + op.payer = GRAPHENE_SON_ACCOUNT; { son_info si; @@ -199,7 +199,7 @@ BOOST_AUTO_TEST_CASE( son_wallet_update_test ) { son_wallet_update_operation op; - op.payer = db.get_global_properties().parameters.get_son_btc_account_id(); + op.payer = GRAPHENE_SON_ACCOUNT; op.son_wallet_id = son_wallet_id_type(0); op.sidechain = graphene::peerplays_sidechain::sidechain_type::bitcoin; op.address = "bitcoin address";