son_wallet_object operations
This commit is contained in:
parent
61b8ff0cc7
commit
6f0c025462
9 changed files with 153 additions and 4 deletions
|
|
@ -316,6 +316,12 @@ struct get_impacted_account_visitor
|
||||||
void operator()( const son_wallet_create_operation& op ){
|
void operator()( const son_wallet_create_operation& op ){
|
||||||
_impacted.insert( op.payer );
|
_impacted.insert( op.payer );
|
||||||
}
|
}
|
||||||
|
void operator()( const son_wallet_update_operation& op ){
|
||||||
|
_impacted.insert( op.payer );
|
||||||
|
}
|
||||||
|
void operator()( const son_wallet_close_operation& op ){
|
||||||
|
_impacted.insert( op.payer );
|
||||||
|
}
|
||||||
void operator()( const sidechain_address_add_operation& op ){
|
void operator()( const sidechain_address_add_operation& op ){
|
||||||
_impacted.insert( op.sidechain_address_account );
|
_impacted.insert( op.sidechain_address_account );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -253,7 +253,9 @@ void database::initialize_evaluators()
|
||||||
register_evaluator<delete_son_evaluator>();
|
register_evaluator<delete_son_evaluator>();
|
||||||
register_evaluator<son_heartbeat_evaluator>();
|
register_evaluator<son_heartbeat_evaluator>();
|
||||||
register_evaluator<son_report_down_evaluator>();
|
register_evaluator<son_report_down_evaluator>();
|
||||||
register_evaluator<son_wallet_evaluator>();
|
register_evaluator<create_son_wallet_evaluator>();
|
||||||
|
register_evaluator<update_son_wallet_evaluator>();
|
||||||
|
register_evaluator<close_son_wallet_evaluator>();
|
||||||
register_evaluator<add_sidechain_address_evaluator>();
|
register_evaluator<add_sidechain_address_evaluator>();
|
||||||
register_evaluator<update_sidechain_address_evaluator>();
|
register_evaluator<update_sidechain_address_evaluator>();
|
||||||
register_evaluator<delete_sidechain_address_evaluator>();
|
register_evaluator<delete_sidechain_address_evaluator>();
|
||||||
|
|
|
||||||
|
|
@ -303,6 +303,12 @@ struct get_impacted_account_visitor
|
||||||
void operator()( const son_wallet_create_operation& op ) {
|
void operator()( const son_wallet_create_operation& op ) {
|
||||||
_impacted.insert( op.payer );
|
_impacted.insert( op.payer );
|
||||||
}
|
}
|
||||||
|
void operator()( const son_wallet_update_operation& op ) {
|
||||||
|
_impacted.insert( op.payer );
|
||||||
|
}
|
||||||
|
void operator()( const son_wallet_close_operation& op ) {
|
||||||
|
_impacted.insert( op.payer );
|
||||||
|
}
|
||||||
void operator()( const sidechain_address_add_operation& op ) {
|
void operator()( const sidechain_address_add_operation& op ) {
|
||||||
_impacted.insert( op.sidechain_address_account );
|
_impacted.insert( op.sidechain_address_account );
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -145,6 +145,8 @@ namespace graphene { namespace chain {
|
||||||
son_heartbeat_operation,
|
son_heartbeat_operation,
|
||||||
son_report_down_operation,
|
son_report_down_operation,
|
||||||
son_wallet_create_operation,
|
son_wallet_create_operation,
|
||||||
|
son_wallet_update_operation,
|
||||||
|
son_wallet_close_operation,
|
||||||
sidechain_address_add_operation,
|
sidechain_address_add_operation,
|
||||||
sidechain_address_update_operation,
|
sidechain_address_update_operation,
|
||||||
sidechain_address_delete_operation
|
sidechain_address_delete_operation
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,33 @@ namespace graphene { namespace chain {
|
||||||
share_type calculate_fee(const fee_parameters_type& k)const { return 0; }
|
share_type calculate_fee(const fee_parameters_type& k)const { return 0; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct son_wallet_update_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; }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct son_wallet_close_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
|
} } // namespace graphene::chain
|
||||||
|
|
||||||
FC_REFLECT(graphene::chain::son_wallet_create_operation::fee_parameters_type, (fee) )
|
FC_REFLECT(graphene::chain::son_wallet_create_operation::fee_parameters_type, (fee) )
|
||||||
FC_REFLECT(graphene::chain::son_wallet_create_operation, (fee)(payer) )
|
FC_REFLECT(graphene::chain::son_wallet_create_operation, (fee)(payer) )
|
||||||
|
FC_REFLECT(graphene::chain::son_wallet_update_operation::fee_parameters_type, (fee) )
|
||||||
|
FC_REFLECT(graphene::chain::son_wallet_update_operation, (fee)(payer) )
|
||||||
|
FC_REFLECT(graphene::chain::son_wallet_close_operation::fee_parameters_type, (fee) )
|
||||||
|
FC_REFLECT(graphene::chain::son_wallet_close_operation, (fee)(payer) )
|
||||||
|
|
|
||||||
|
|
@ -13,4 +13,22 @@ public:
|
||||||
object_id_type do_apply(const son_wallet_create_operation& o);
|
object_id_type do_apply(const son_wallet_create_operation& o);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class update_son_wallet_evaluator : public evaluator<update_son_wallet_evaluator>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef son_wallet_update_operation operation_type;
|
||||||
|
|
||||||
|
void_result do_evaluate(const son_wallet_update_operation& o);
|
||||||
|
object_id_type do_apply(const son_wallet_update_operation& o);
|
||||||
|
};
|
||||||
|
|
||||||
|
class close_son_wallet_evaluator : public evaluator<close_son_wallet_evaluator>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
typedef son_wallet_close_operation operation_type;
|
||||||
|
|
||||||
|
void_result do_evaluate(const son_wallet_close_operation& o);
|
||||||
|
object_id_type do_apply(const son_wallet_close_operation& o);
|
||||||
|
};
|
||||||
|
|
||||||
} } // namespace graphene::chain
|
} } // namespace graphene::chain
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <graphene/chain/protocol/types.hpp>
|
#include <graphene/chain/protocol/types.hpp>
|
||||||
|
#include <graphene/chain/son_info.hpp>
|
||||||
#include <graphene/peerplays_sidechain/defs.hpp>
|
#include <graphene/peerplays_sidechain/defs.hpp>
|
||||||
|
|
||||||
namespace graphene { namespace chain {
|
namespace graphene { namespace chain {
|
||||||
|
|
@ -20,15 +21,22 @@ namespace graphene { namespace chain {
|
||||||
time_point_sec expires;
|
time_point_sec expires;
|
||||||
|
|
||||||
flat_map<peerplays_sidechain::sidechain_type, string> addresses;
|
flat_map<peerplays_sidechain::sidechain_type, string> addresses;
|
||||||
|
vector<son_info> sons;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct by_sidechain_type;
|
struct by_valid_from;
|
||||||
struct by_address;
|
struct by_expires;
|
||||||
using son_wallet_multi_index_type = multi_index_container<
|
using son_wallet_multi_index_type = multi_index_container<
|
||||||
son_wallet_object,
|
son_wallet_object,
|
||||||
indexed_by<
|
indexed_by<
|
||||||
ordered_unique< tag<by_id>,
|
ordered_unique< tag<by_id>,
|
||||||
member<object, object_id_type, &object::id>
|
member<object, object_id_type, &object::id>
|
||||||
|
>,
|
||||||
|
ordered_unique< tag<by_valid_from>,
|
||||||
|
member<son_wallet_object, time_point_sec, &son_wallet_object::valid_from>
|
||||||
|
>,
|
||||||
|
ordered_unique< tag<by_expires>,
|
||||||
|
member<son_wallet_object, time_point_sec, &son_wallet_object::expires>
|
||||||
>
|
>
|
||||||
>
|
>
|
||||||
>;
|
>;
|
||||||
|
|
@ -36,4 +44,4 @@ namespace graphene { namespace chain {
|
||||||
} } // graphene::chain
|
} } // graphene::chain
|
||||||
|
|
||||||
FC_REFLECT_DERIVED( graphene::chain::son_wallet_object, (graphene::db::object),
|
FC_REFLECT_DERIVED( graphene::chain::son_wallet_object, (graphene::db::object),
|
||||||
(valid_from) (expires) (addresses) )
|
(valid_from) (expires) (addresses) (sons) )
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,41 @@ object_id_type create_son_wallet_evaluator::do_apply(const son_wallet_create_ope
|
||||||
const auto& new_son_wallet_object = db().create<son_wallet_object>( [&]( son_wallet_object& obj ){
|
const auto& new_son_wallet_object = db().create<son_wallet_object>( [&]( son_wallet_object& obj ){
|
||||||
obj.valid_from = db().head_block_time();
|
obj.valid_from = db().head_block_time();
|
||||||
obj.expires = time_point_sec::maximum();
|
obj.expires = time_point_sec::maximum();
|
||||||
|
obj.sons = db().get_global_properties().active_sons;
|
||||||
|
});
|
||||||
|
return new_son_wallet_object.id;
|
||||||
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||||
|
|
||||||
|
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.");
|
||||||
|
return void_result();
|
||||||
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||||
|
|
||||||
|
object_id_type update_son_wallet_evaluator::do_apply(const son_wallet_update_operation& op)
|
||||||
|
{ try {
|
||||||
|
const auto& new_son_wallet_object = db().create<son_wallet_object>( [&]( son_wallet_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_object.id;
|
||||||
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||||
|
|
||||||
|
void_result close_son_wallet_evaluator::do_evaluate(const son_wallet_close_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 close_son_wallet_evaluator::do_apply(const son_wallet_close_operation& op)
|
||||||
|
{ try {
|
||||||
|
const auto& new_son_wallet_object = db().create<son_wallet_object>( [&]( son_wallet_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_object.id;
|
return new_son_wallet_object.id;
|
||||||
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||||
|
|
|
||||||
46
tests/tests/son_wallet_tests.cpp
Normal file
46
tests/tests/son_wallet_tests.cpp
Normal file
|
|
@ -0,0 +1,46 @@
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
#include "../common/database_fixture.hpp"
|
||||||
|
|
||||||
|
#include <graphene/chain/hardfork.hpp>
|
||||||
|
#include <graphene/chain/son_wallet_object.hpp>
|
||||||
|
#include <graphene/chain/son_wallet_evaluator.hpp>
|
||||||
|
|
||||||
|
using namespace graphene::chain;
|
||||||
|
using namespace graphene::chain::test;
|
||||||
|
|
||||||
|
|
||||||
|
BOOST_FIXTURE_TEST_SUITE( son_wallet_tests, database_fixture )
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE( son_wallet_create_test ) {
|
||||||
|
|
||||||
|
BOOST_TEST_MESSAGE("son_wallet_create_test");
|
||||||
|
|
||||||
|
generate_block();
|
||||||
|
set_expiration(db, trx);
|
||||||
|
|
||||||
|
ACTORS((alice));
|
||||||
|
|
||||||
|
generate_block();
|
||||||
|
set_expiration(db, trx);
|
||||||
|
|
||||||
|
{
|
||||||
|
BOOST_TEST_MESSAGE("Send son_wallet_create_operation");
|
||||||
|
|
||||||
|
son_wallet_create_operation op;
|
||||||
|
|
||||||
|
op.payer = gpo.parameters.get_son_btc_account_id();
|
||||||
|
|
||||||
|
trx.operations.push_back(op);
|
||||||
|
sign(trx, alice_private_key);
|
||||||
|
PUSH_TX(db, trx, ~0);
|
||||||
|
}
|
||||||
|
generate_block();
|
||||||
|
|
||||||
|
BOOST_TEST_MESSAGE("Check son_wallet_create_operation results");
|
||||||
|
|
||||||
|
const auto& idx = db.get_index_type<son_wallet_index>().indices().get<by_valid_from>();
|
||||||
|
BOOST_REQUIRE( idx.size() == 1 );
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
Loading…
Reference in a new issue