diff --git a/libraries/app/impacted.cpp b/libraries/app/impacted.cpp index 80d7fc1d..41add58a 100644 --- a/libraries/app/impacted.cpp +++ b/libraries/app/impacted.cpp @@ -325,6 +325,9 @@ struct get_impacted_account_visitor void operator()( const son_wallet_close_operation& op ){ _impacted.insert( op.payer ); } + void operator()( const son_wallet_transfer_create_operation& op ){ + _impacted.insert( op.payer ); + } void operator()( const sidechain_address_add_operation& op ){ _impacted.insert( op.sidechain_address_account ); } diff --git a/libraries/chain/CMakeLists.txt b/libraries/chain/CMakeLists.txt index b716e974..c7dd5375 100644 --- a/libraries/chain/CMakeLists.txt +++ b/libraries/chain/CMakeLists.txt @@ -117,9 +117,10 @@ add_library( graphene_chain son_evaluator.cpp son_object.cpp - sidechain_address_evaluator.cpp - son_wallet_evaluator.cpp + son_wallet_transfer_evaluator.cpp + + sidechain_address_evaluator.cpp ${HEADERS} ${PROTOCOL_HEADERS} diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 9ef8be0d..77df1ab8 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -57,6 +57,7 @@ #include #include #include +#include #include #include @@ -81,6 +82,7 @@ #include #include #include +#include #include #include @@ -257,6 +259,7 @@ void database::initialize_evaluators() register_evaluator(); register_evaluator(); register_evaluator(); + register_evaluator(); register_evaluator(); register_evaluator(); register_evaluator(); @@ -305,6 +308,7 @@ void database::initialize_indexes() add_index< primary_index >(); add_index< primary_index >(); + add_index< primary_index >(); add_index< primary_index >(); diff --git a/libraries/chain/db_notify.cpp b/libraries/chain/db_notify.cpp index acc26bc6..28bf119f 100644 --- a/libraries/chain/db_notify.cpp +++ b/libraries/chain/db_notify.cpp @@ -312,6 +312,9 @@ struct get_impacted_account_visitor void operator()( const son_wallet_close_operation& op ) { _impacted.insert( op.payer ); } + void operator()( const son_wallet_transfer_create_operation& op ) { + _impacted.insert( op.payer ); + } void operator()( const sidechain_address_add_operation& op ) { _impacted.insert( op.sidechain_address_account ); } diff --git a/libraries/chain/include/graphene/chain/protocol/operations.hpp b/libraries/chain/include/graphene/chain/protocol/operations.hpp index e1c1ac0c..ec36480b 100644 --- a/libraries/chain/include/graphene/chain/protocol/operations.hpp +++ b/libraries/chain/include/graphene/chain/protocol/operations.hpp @@ -48,6 +48,7 @@ #include #include #include +#include namespace graphene { namespace chain { @@ -148,6 +149,7 @@ namespace graphene { namespace chain { son_wallet_create_operation, son_wallet_update_operation, son_wallet_close_operation, + son_wallet_transfer_create_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_transfer.hpp new file mode 100644 index 00000000..e9913d7d --- /dev/null +++ b/libraries/chain/include/graphene/chain/protocol/son_wallet_transfer.hpp @@ -0,0 +1,20 @@ +#pragma once +#include + +namespace graphene { namespace chain { + + struct son_wallet_transfer_create_operation : public base_operation + { + struct fee_parameters_type { uint64_t fee = 0; }; + + asset fee; + account_id_type payer; + + 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_transfer_create_operation::fee_parameters_type, (fee) ) +FC_REFLECT(graphene::chain::son_wallet_transfer_create_operation, (fee)(payer) ) diff --git a/libraries/chain/include/graphene/chain/protocol/types.hpp b/libraries/chain/include/graphene/chain/protocol/types.hpp index abfce9c8..c25c465c 100644 --- a/libraries/chain/include/graphene/chain/protocol/types.hpp +++ b/libraries/chain/include/graphene/chain/protocol/types.hpp @@ -148,6 +148,7 @@ namespace graphene { namespace chain { son_object_type, son_proposal_object_type, son_wallet_object_type, + son_wallet_transfer_object_type, sidechain_address_object_type, OBJECT_TYPE_COUNT ///< Sentry value which contains the number of different object types }; @@ -213,6 +214,7 @@ namespace graphene { namespace chain { class son_object; class son_proposal_object; class son_wallet_object; + class son_wallet_transfer_object; class sidechain_address_object; typedef object_id< protocol_ids, account_object_type, account_object> account_id_type; @@ -243,6 +245,7 @@ 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, sidechain_address_object_type, sidechain_address_object> sidechain_address_id_type; // implementation types @@ -431,6 +434,7 @@ FC_REFLECT_ENUM( graphene::chain::object_type, (son_object_type) (son_proposal_object_type) (son_wallet_object_type) + (son_wallet_transfer_object_type) (sidechain_address_object_type) (OBJECT_TYPE_COUNT) ) @@ -506,6 +510,7 @@ 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::sidechain_address_id_type ) diff --git a/libraries/chain/include/graphene/chain/son_wallet_transfer_evaluator.hpp b/libraries/chain/include/graphene/chain/son_wallet_transfer_evaluator.hpp new file mode 100644 index 00000000..7e72a347 --- /dev/null +++ b/libraries/chain/include/graphene/chain/son_wallet_transfer_evaluator.hpp @@ -0,0 +1,15 @@ +#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); +}; + +} } // namespace graphene::chain diff --git a/libraries/chain/include/graphene/chain/son_wallet_transfer_object.hpp b/libraries/chain/include/graphene/chain/son_wallet_transfer_object.hpp new file mode 100644 index 00000000..0eb88c3d --- /dev/null +++ b/libraries/chain/include/graphene/chain/son_wallet_transfer_object.hpp @@ -0,0 +1,61 @@ +#pragma once +#include +#include + +namespace graphene { namespace chain { + using namespace graphene::db; + + /** + * @class son_wallet_transfer_object + * @brief tracks information about a SON wallet transfer. + * @ingroup object + */ + class son_wallet_transfer_object : public abstract_object + { + public: + static const uint8_t space_id = protocol_ids; + static const uint8_t type_id = son_wallet_transfer_object_type; + + std::string uid; + time_point_sec timestamp; + peerplays_sidechain::sidechain_type sidechain; + std::string transaction_id; + std::string from; + std::string to; + int64_t amount; + + bool processed; + + flat_map addresses; + vector sons; + }; + + struct by_uid; + struct by_sidechain; + struct by_sidechain_and_processed; + using son_wallet_transfer_multi_index_type = multi_index_container< + son_wallet_transfer_object, + indexed_by< + ordered_unique< tag, + member + >, + ordered_unique< tag, + member + >, + ordered_non_unique< tag, + member + >, + ordered_non_unique< tag, + composite_key, + member + > + > + > + >; + using son_wallet_transfer_index = generic_index; +} } // graphene::chain + +FC_REFLECT_DERIVED( graphene::chain::son_wallet_transfer_object, (graphene::db::object), + (uid) (timestamp) (sidechain) (transaction_id) (from) (to) (amount) + (processed) ) diff --git a/libraries/chain/son_wallet_transfer_evaluator.cpp b/libraries/chain/son_wallet_transfer_evaluator.cpp new file mode 100644 index 00000000..d217c5bf --- /dev/null +++ b/libraries/chain/son_wallet_transfer_evaluator.cpp @@ -0,0 +1,25 @@ +#include + +#include +#include + +namespace graphene { namespace chain { + +void_result create_son_wallet_transfer_evaluator::do_evaluate(const son_wallet_transfer_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.");*/ + 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) +{ try { + const auto& new_son_wallet_transfer_object = db().create( [&]( son_wallet_transfer_object& obj ){ + /*obj.valid_from = db().head_block_time(); + obj.expires = time_point_sec::maximum(); + obj.sons = db().get_global_properties().active_sons;*/ + }); + return new_son_wallet_transfer_object.id; +} FC_CAPTURE_AND_RETHROW( (op) ) } + +} } // namespace graphene::chain