From 5a37d3ecd1daf4cb896bb6020d4e1a870cace99c Mon Sep 17 00:00:00 2001 From: Srdjan Obucina Date: Wed, 19 Feb 2020 16:29:49 +0100 Subject: [PATCH] Renaming son_wallet_transfer* to son_wallet_deposit*, introducing son_wallet_withdrawal* --- libraries/app/impacted.cpp | 10 +- libraries/chain/CMakeLists.txt | 3 +- libraries/chain/db_init.cpp | 15 ++- libraries/chain/db_maint.cpp | 4 +- libraries/chain/db_notify.cpp | 14 +- .../graphene/chain/protocol/operations.hpp | 9 +- ...et_transfer.hpp => son_wallet_deposit.hpp} | 16 +-- .../chain/protocol/son_wallet_withdrawal.hpp | 51 ++++++++ .../include/graphene/chain/protocol/types.hpp | 15 ++- .../chain/son_wallet_deposit_evaluator.hpp | 24 ++++ ...ject.hpp => son_wallet_deposit_object.hpp} | 28 ++-- .../chain/son_wallet_transfer_evaluator.hpp | 24 ---- .../chain/son_wallet_withdrawal_evaluator.hpp | 24 ++++ .../chain/son_wallet_withdrawal_object.hpp | 69 ++++++++++ ...r.cpp => son_wallet_deposit_evaluator.cpp} | 34 ++--- .../chain/son_wallet_withdrawal_evaluator.cpp | 120 ++++++++++++++++++ .../peerplays_sidechain_plugin.cpp | 61 +++++++-- .../sidechain_net_handler.cpp | 2 +- programs/js_operation_serializer/main.cpp | 3 +- 19 files changed, 428 insertions(+), 98 deletions(-) mode change 100644 => 100755 libraries/chain/CMakeLists.txt rename libraries/chain/include/graphene/chain/protocol/{son_wallet_transfer.hpp => son_wallet_deposit.hpp} (71%) create mode 100644 libraries/chain/include/graphene/chain/protocol/son_wallet_withdrawal.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} (58%) delete mode 100644 libraries/chain/include/graphene/chain/son_wallet_transfer_evaluator.hpp create mode 100644 libraries/chain/include/graphene/chain/son_wallet_withdrawal_evaluator.hpp create mode 100644 libraries/chain/include/graphene/chain/son_wallet_withdrawal_object.hpp rename libraries/chain/{son_wallet_transfer_evaluator.cpp => son_wallet_deposit_evaluator.cpp} (74%) create mode 100644 libraries/chain/son_wallet_withdrawal_evaluator.cpp diff --git a/libraries/app/impacted.cpp b/libraries/app/impacted.cpp index d3e8eb8c..17364ac2 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_withdrawal_create_operation& op ){ + _impacted.insert( op.payer ); + } + void operator()( const son_wallet_withdrawal_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..8ef21df6 --- 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_withdrawal_evaluator.cpp sidechain_address_evaluator.cpp diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 5c72d1bc..e2b5f099 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 a9fa77df..3c1685b3 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -440,13 +440,13 @@ void database::update_active_sons() map weights; a.active.weight_threshold = 0; a.active.account_auths.clear(); - + for( const son_object& son : sons ) { weights.emplace(son.son_account, _vote_tally_buffer[son.vote_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); diff --git a/libraries/chain/db_notify.cpp b/libraries/chain/db_notify.cpp index 98e02a1b..798494ea 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_withdrawal_create_operation& op ) { + _impacted.insert( op.payer ); + } + void operator()( const son_wallet_withdrawal_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_withdrawal_object_type:{ break; } case sidechain_address_object_type:{ const auto& aobj = dynamic_cast(obj); diff --git a/libraries/chain/include/graphene/chain/protocol/operations.hpp b/libraries/chain/include/graphene/chain/protocol/operations.hpp index 27980ae2..be2bb68c 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_withdrawal_create_operation, + son_wallet_withdrawal_process_operation, sidechain_address_add_operation, sidechain_address_update_operation, sidechain_address_delete_operation 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 71% 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 b45fdc4a..abcc4384 100644 --- a/libraries/chain/include/graphene/chain/protocol/son_wallet_transfer.hpp +++ b/libraries/chain/include/graphene/chain/protocol/son_wallet_deposit.hpp @@ -5,7 +5,7 @@ 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; }; @@ -28,14 +28,14 @@ namespace graphene { namespace chain { 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; } @@ -43,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) +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_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_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_withdrawal.hpp b/libraries/chain/include/graphene/chain/protocol/son_wallet_withdrawal.hpp new file mode 100644 index 00000000..d68997b4 --- /dev/null +++ b/libraries/chain/include/graphene/chain/protocol/son_wallet_withdrawal.hpp @@ -0,0 +1,51 @@ +#pragma once +#include + +#include + +namespace graphene { namespace chain { + + struct son_wallet_withdrawal_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 sidechain_uid; + std::string sidechain_transaction_id; + std::string sidechain_from; + std::string sidechain_to; + std::string sidechain_currency; + fc::safe sidechain_amount; + chain::account_id_type peerplays_from; + chain::account_id_type peerplays_to; + chain::asset peerplays_asset; + + account_id_type fee_payer()const { return payer; } + share_type calculate_fee(const fee_parameters_type& k)const { return 0; } + }; + + struct son_wallet_withdrawal_process_operation : public base_operation + { + struct fee_parameters_type { uint64_t fee = 0; }; + + asset fee; + account_id_type payer; + + son_wallet_withdrawal_id_type son_wallet_withdrawal_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_withdrawal_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT(graphene::chain::son_wallet_withdrawal_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_withdrawal_process_operation::fee_parameters_type, (fee) ) +FC_REFLECT(graphene::chain::son_wallet_withdrawal_process_operation, (fee)(payer) + (son_wallet_withdrawal_id)) diff --git a/libraries/chain/include/graphene/chain/protocol/types.hpp b/libraries/chain/include/graphene/chain/protocol/types.hpp index c25c465c..c2911cdf 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_withdrawal_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_withdrawal_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_withdrawal_object_type, son_wallet_withdrawal_object> son_wallet_withdrawal_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_withdrawal_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_withdrawal_id_type ) FC_REFLECT_TYPENAME( graphene::chain::sidechain_address_id_type ) 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 58% 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 6b2db8b8..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; @@ -36,33 +36,33 @@ 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_currency) (sidechain_amount) (peerplays_from) (peerplays_to) (peerplays_asset) 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_withdrawal_evaluator.hpp b/libraries/chain/include/graphene/chain/son_wallet_withdrawal_evaluator.hpp new file mode 100644 index 00000000..2a496996 --- /dev/null +++ b/libraries/chain/include/graphene/chain/son_wallet_withdrawal_evaluator.hpp @@ -0,0 +1,24 @@ +#pragma once +#include + +namespace graphene { namespace chain { + +class create_son_wallet_withdrawal_evaluator : public evaluator +{ +public: + typedef son_wallet_withdrawal_create_operation operation_type; + + void_result do_evaluate(const son_wallet_withdrawal_create_operation& o); + object_id_type do_apply(const son_wallet_withdrawal_create_operation& o); +}; + +class process_son_wallet_withdrawal_evaluator : public evaluator +{ +public: + typedef son_wallet_withdrawal_process_operation operation_type; + + void_result do_evaluate(const son_wallet_withdrawal_process_operation& o); + object_id_type do_apply(const son_wallet_withdrawal_process_operation& o); +}; + +} } // namespace graphene::chain diff --git a/libraries/chain/include/graphene/chain/son_wallet_withdrawal_object.hpp b/libraries/chain/include/graphene/chain/son_wallet_withdrawal_object.hpp new file mode 100644 index 00000000..7d35eb61 --- /dev/null +++ b/libraries/chain/include/graphene/chain/son_wallet_withdrawal_object.hpp @@ -0,0 +1,69 @@ +#pragma once +#include +#include + +namespace graphene { namespace chain { + using namespace graphene::db; + + /** + * @class son_wallet_withdrawal_object + * @brief tracks information about a SON wallet withdrawal. + * @ingroup object + */ + class son_wallet_withdrawal_object : public abstract_object + { + public: + static const uint8_t space_id = protocol_ids; + static const uint8_t type_id = son_wallet_withdrawal_object_type; + + time_point_sec timestamp; + peerplays_sidechain::sidechain_type sidechain; + int64_t confirmations; + std::string sidechain_uid; + std::string sidechain_transaction_id; + std::string sidechain_from; + std::string sidechain_to; + std::string sidechain_currency; + safe sidechain_amount; + chain::account_id_type peerplays_from; + chain::account_id_type peerplays_to; + chain::asset peerplays_asset; + + bool processed; + }; + + struct by_sidechain; + struct by_sidechain_uid; + struct by_processed; + struct by_sidechain_and_processed; + using son_wallet_withdrawal_multi_index_type = multi_index_container< + son_wallet_withdrawal_object, + indexed_by< + ordered_unique< tag, + member + >, + ordered_non_unique< tag, + member + >, + ordered_unique< tag, + member + >, + ordered_non_unique< tag, + member + >, + ordered_non_unique< tag, + composite_key, + member + > + > + > + >; + using son_wallet_withdrawal_index = generic_index; +} } // graphene::chain + +FC_REFLECT_DERIVED( graphene::chain::son_wallet_withdrawal_object, (graphene::db::object), + (timestamp) (sidechain) (confirmations) + (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/son_wallet_transfer_evaluator.cpp b/libraries/chain/son_wallet_deposit_evaluator.cpp similarity index 74% rename from libraries/chain/son_wallet_transfer_evaluator.cpp rename to libraries/chain/son_wallet_deposit_evaluator.cpp index eb557162..2f5a4f6b 100644 --- a/libraries/chain/son_wallet_transfer_evaluator.cpp +++ b/libraries/chain/son_wallet_deposit_evaluator.cpp @@ -1,27 +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( 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; @@ -35,22 +35,22 @@ object_id_type create_son_wallet_transfer_evaluator::do_apply(const son_wallet_t 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( 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"); @@ -96,14 +96,14 @@ void_result process_son_wallet_transfer_evaluator::do_evaluate(const son_wallet_ } 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; }); @@ -114,7 +114,7 @@ object_id_type process_son_wallet_transfer_evaluator::do_apply(const son_wallet_ 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_withdrawal_evaluator.cpp b/libraries/chain/son_wallet_withdrawal_evaluator.cpp new file mode 100644 index 00000000..31c221f3 --- /dev/null +++ b/libraries/chain/son_wallet_withdrawal_evaluator.cpp @@ -0,0 +1,120 @@ +#include + +#include +#include +#include + +namespace graphene { namespace chain { + +void_result create_son_wallet_withdrawal_evaluator::do_evaluate(const son_wallet_withdrawal_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." ); + + //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_withdrawal_evaluator::do_apply(const son_wallet_withdrawal_create_operation& op) +{ try { + 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_withdrawal_object = db().create( [&]( son_wallet_withdrawal_object& swto ){ + swto.timestamp = op.timestamp; + swto.sidechain = op.sidechain; + swto.confirmations = 1; + swto.sidechain_uid = op.sidechain_uid; + swto.sidechain_transaction_id = op.sidechain_transaction_id; + swto.sidechain_from = op.sidechain_from; + swto.sidechain_to = op.sidechain_to; + swto.sidechain_amount = op.sidechain_amount; + swto.peerplays_from = op.peerplays_from; + swto.peerplays_to = op.peerplays_to; + swto.peerplays_asset = op.peerplays_asset; + swto.processed = false; + }); + return new_son_wallet_withdrawal_object.id; + } else { + db().modify(*itr, [&op](son_wallet_withdrawal_object &swto) { + swto.confirmations = swto.confirmations + 1; + }); + return (*itr).id; + } +} FC_CAPTURE_AND_RETHROW( (op) ) } + +void_result process_son_wallet_withdrawal_evaluator::do_evaluate(const son_wallet_withdrawal_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_withdrawal_id); + FC_ASSERT(itr != idx.end(), "Son wallet transfer not found"); + //FC_ASSERT(itr->processed == false, "Son wallet transfer is already processed"); + + const database& d = db(); + + const account_object& from_account = itr->peerplays_to(d); // reversed, for withdrawal + const account_object& to_account = itr->peerplays_from(d); // reversed, for withdrawal + const asset_object& asset_type = itr->peerplays_asset.asset_id(d); + + try { + + GRAPHENE_ASSERT( + is_authorized_asset( d, from_account, asset_type ), + transfer_from_account_not_whitelisted, + "'from' account ${from} is not whitelisted for asset ${asset}", + ("from",from_account.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_asset.asset_id) + ); + + if( asset_type.is_transfer_restricted() ) + { + GRAPHENE_ASSERT( + 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_asset.asset_id) + ); + } + + 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_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_asset))("f",from_account.name)("t",to_account.name) ); +} FC_CAPTURE_AND_RETHROW( (op) ) } + +object_id_type process_son_wallet_withdrawal_evaluator::do_apply(const son_wallet_withdrawal_process_operation& op) +{ try { + const auto& idx = db().get_index_type().indices().get(); + auto itr = idx.find(op.son_wallet_withdrawal_id); + if(itr != idx.end()) + { + if (itr->processed == false) { + db().modify(*itr, [&op](son_wallet_withdrawal_object &swto) { + swto.processed = true; + }); + + const account_id_type from_account = itr->peerplays_to; // reversed, for withdrawal + const account_id_type to_account = itr->peerplays_from; // reversed, for withdrawal + + db().adjust_balance( from_account, -itr->peerplays_asset ); + db().adjust_balance( to_account, itr->peerplays_asset ); + } + } + return op.son_wallet_withdrawal_id; +} FC_CAPTURE_AND_RETHROW( (op) ) } + +} } // namespace graphene::chain diff --git a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp index 5ce0b1ca..e342bd9e 100644 --- a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp +++ b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp @@ -10,7 +10,8 @@ #include #include #include -#include +#include +#include #include #include #include @@ -46,7 +47,7 @@ class peerplays_sidechain_plugin_impl void create_son_down_proposals(); void recreate_primary_wallet(); void process_deposits(); - //void process_withdrawals(); + void process_withdrawals(); private: peerplays_sidechain_plugin& plugin; @@ -377,20 +378,20 @@ void peerplays_sidechain_plugin_impl::recreate_primary_wallet() void peerplays_sidechain_plugin_impl::process_deposits() { - const auto& idx = plugin.database().get_index_type().indices().get(); + 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 son_wallet_deposit_object& 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_transfer_process_operation p_op; + son_wallet_deposit_process_operation p_op; p_op.payer = GRAPHENE_SON_ACCOUNT; - p_op.son_wallet_transfer_id = swto.id; + 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; @@ -398,10 +399,10 @@ void peerplays_sidechain_plugin_impl::process_deposits() { 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)); + 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 ${swto} by ${son}", ("swto", swto.id) ("son", son_id)); + 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()) @@ -414,8 +415,44 @@ void peerplays_sidechain_plugin_impl::process_deposits() { }); } -//void peerplays_sidechain_plugin_impl::process_withdrawals() { -//} +void peerplays_sidechain_plugin_impl::process_withdrawals() { + + 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_withdrawal_object& 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)) { + + //son_wallet_withdrawal_process_operation p_op; + //p_op.payer = GRAPHENE_SON_ACCOUNT; + //p_op.son_wallet_withdrawal_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())); + //} + } + } + }); +} void peerplays_sidechain_plugin_impl::on_block_applied( const signed_block& b ) { @@ -496,13 +533,13 @@ 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; } diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp index 0e621027..a8aa5f81 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp @@ -57,7 +57,7 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_ const chain::global_property_object& gpo = database.get_global_properties(); - son_wallet_transfer_create_operation op; + son_wallet_deposit_create_operation op; op.payer = GRAPHENE_SON_ACCOUNT; op.timestamp = sed.timestamp; op.sidechain = sed.sidechain; diff --git a/programs/js_operation_serializer/main.cpp b/programs/js_operation_serializer/main.cpp index 04a94827..684d4d7d 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