SON wallet transfer object and operations, for tracking assets deposit/withdrawal
This commit is contained in:
parent
0142348a9c
commit
df7ee459f9
10 changed files with 141 additions and 2 deletions
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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}
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@
|
|||
#include <graphene/chain/son_object.hpp>
|
||||
#include <graphene/chain/son_proposal_object.hpp>
|
||||
#include <graphene/chain/son_wallet_object.hpp>
|
||||
#include <graphene/chain/son_wallet_transfer_object.hpp>
|
||||
#include <graphene/chain/sidechain_address_object.hpp>
|
||||
|
||||
#include <graphene/chain/account_evaluator.hpp>
|
||||
|
|
@ -81,6 +82,7 @@
|
|||
#include <graphene/chain/tournament_evaluator.hpp>
|
||||
#include <graphene/chain/son_evaluator.hpp>
|
||||
#include <graphene/chain/son_wallet_evaluator.hpp>
|
||||
#include <graphene/chain/son_wallet_transfer_evaluator.hpp>
|
||||
#include <graphene/chain/sidechain_address_evaluator.hpp>
|
||||
|
||||
#include <graphene/chain/protocol/fee_schedule.hpp>
|
||||
|
|
@ -257,6 +259,7 @@ void database::initialize_evaluators()
|
|||
register_evaluator<create_son_wallet_evaluator>();
|
||||
register_evaluator<update_son_wallet_evaluator>();
|
||||
register_evaluator<close_son_wallet_evaluator>();
|
||||
register_evaluator<create_son_wallet_transfer_evaluator>();
|
||||
register_evaluator<add_sidechain_address_evaluator>();
|
||||
register_evaluator<update_sidechain_address_evaluator>();
|
||||
register_evaluator<delete_sidechain_address_evaluator>();
|
||||
|
|
@ -305,6 +308,7 @@ void database::initialize_indexes()
|
|||
add_index< primary_index<son_proposal_index> >();
|
||||
|
||||
add_index< primary_index<son_wallet_index> >();
|
||||
add_index< primary_index<son_wallet_transfer_index> >();
|
||||
|
||||
add_index< primary_index<sidechain_address_index> >();
|
||||
|
||||
|
|
|
|||
|
|
@ -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 );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,7 @@
|
|||
#include <graphene/chain/protocol/son.hpp>
|
||||
#include <graphene/chain/protocol/sidechain_address.hpp>
|
||||
#include <graphene/chain/protocol/son_wallet.hpp>
|
||||
#include <graphene/chain/protocol/son_wallet_transfer.hpp>
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
#pragma once
|
||||
#include <graphene/chain/protocol/base.hpp>
|
||||
|
||||
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) )
|
||||
|
|
@ -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 )
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
#include <graphene/chain/evaluator.hpp>
|
||||
|
||||
namespace graphene { namespace chain {
|
||||
|
||||
class create_son_wallet_transfer_evaluator : public evaluator<create_son_wallet_transfer_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
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
#pragma once
|
||||
#include <graphene/chain/protocol/types.hpp>
|
||||
#include <graphene/peerplays_sidechain/defs.hpp>
|
||||
|
||||
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<son_wallet_transfer_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<peerplays_sidechain::sidechain_type, string> addresses;
|
||||
vector<son_info> 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<by_id>,
|
||||
member<object, object_id_type, &object::id>
|
||||
>,
|
||||
ordered_unique< tag<by_uid>,
|
||||
member<son_wallet_transfer_object, std::string, &son_wallet_transfer_object::uid>
|
||||
>,
|
||||
ordered_non_unique< tag<by_sidechain>,
|
||||
member<son_wallet_transfer_object, peerplays_sidechain::sidechain_type, &son_wallet_transfer_object::sidechain>
|
||||
>,
|
||||
ordered_non_unique< tag<by_sidechain_and_processed>,
|
||||
composite_key<son_wallet_transfer_object,
|
||||
member<son_wallet_transfer_object, peerplays_sidechain::sidechain_type, &son_wallet_transfer_object::sidechain>,
|
||||
member<son_wallet_transfer_object, bool, &son_wallet_transfer_object::processed>
|
||||
>
|
||||
>
|
||||
>
|
||||
>;
|
||||
using son_wallet_transfer_index = generic_index<son_wallet_transfer_object, son_wallet_transfer_multi_index_type>;
|
||||
} } // graphene::chain
|
||||
|
||||
FC_REFLECT_DERIVED( graphene::chain::son_wallet_transfer_object, (graphene::db::object),
|
||||
(uid) (timestamp) (sidechain) (transaction_id) (from) (to) (amount)
|
||||
(processed) )
|
||||
25
libraries/chain/son_wallet_transfer_evaluator.cpp
Normal file
25
libraries/chain/son_wallet_transfer_evaluator.cpp
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#include <graphene/chain/son_wallet_transfer_evaluator.hpp>
|
||||
|
||||
#include <graphene/chain/database.hpp>
|
||||
#include <graphene/chain/son_wallet_transfer_object.hpp>
|
||||
|
||||
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>( [&]( 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
|
||||
Loading…
Reference in a new issue