Renaming son_wallet_transfer* to son_wallet_deposit*, introducing son_wallet_withdrawal*

This commit is contained in:
Srdjan Obucina 2020-02-19 16:29:49 +01:00
parent caba98cfe3
commit 5a37d3ecd1
19 changed files with 428 additions and 98 deletions

View file

@ -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 ){

3
libraries/chain/CMakeLists.txt Normal file → Executable file
View file

@ -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

View file

@ -57,7 +57,8 @@
#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/son_wallet_deposit_object.hpp>
#include <graphene/chain/son_wallet_withdrawal_object.hpp>
#include <graphene/chain/sidechain_address_object.hpp>
#include <graphene/chain/account_evaluator.hpp>
@ -82,7 +83,8 @@
#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/son_wallet_deposit_evaluator.hpp>
#include <graphene/chain/son_wallet_withdrawal_evaluator.hpp>
#include <graphene/chain/sidechain_address_evaluator.hpp>
#include <graphene/chain/protocol/fee_schedule.hpp>
@ -258,8 +260,10 @@ void database::initialize_evaluators()
register_evaluator<son_maintenance_evaluator>();
register_evaluator<recreate_son_wallet_evaluator>();
register_evaluator<update_son_wallet_evaluator>();
register_evaluator<create_son_wallet_transfer_evaluator>();
register_evaluator<process_son_wallet_transfer_evaluator>();
register_evaluator<create_son_wallet_deposit_evaluator>();
register_evaluator<process_son_wallet_deposit_evaluator>();
register_evaluator<create_son_wallet_withdrawal_evaluator>();
register_evaluator<process_son_wallet_withdrawal_evaluator>();
register_evaluator<add_sidechain_address_evaluator>();
register_evaluator<update_sidechain_address_evaluator>();
register_evaluator<delete_sidechain_address_evaluator>();
@ -308,7 +312,8 @@ 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<son_wallet_deposit_index> >();
add_index< primary_index<son_wallet_withdrawal_index> >();
add_index< primary_index<sidechain_address_index> >();

View file

@ -440,13 +440,13 @@ void database::update_active_sons()
map<account_id_type, uint64_t> 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);

View file

@ -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<account_id_type>& 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<const sidechain_address_object*>(obj);

View file

@ -48,7 +48,8 @@
#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>
#include <graphene/chain/protocol/son_wallet_deposit.hpp>
#include <graphene/chain/protocol/son_wallet_withdrawal.hpp>
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

View file

@ -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))

View file

@ -0,0 +1,51 @@
#pragma once
#include <graphene/chain/protocol/base.hpp>
#include <fc/safe.hpp>
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<int64_t> 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))

View file

@ -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 )

View file

@ -0,0 +1,24 @@
#pragma once
#include <graphene/chain/evaluator.hpp>
namespace graphene { namespace chain {
class create_son_wallet_deposit_evaluator : public evaluator<create_son_wallet_deposit_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<process_son_wallet_deposit_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

View file

@ -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<son_wallet_transfer_object>
class son_wallet_deposit_object : public abstract_object<son_wallet_deposit_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<by_id>,
member<object, object_id_type, &object::id>
>,
ordered_non_unique< tag<by_sidechain>,
member<son_wallet_transfer_object, peerplays_sidechain::sidechain_type, &son_wallet_transfer_object::sidechain>
member<son_wallet_deposit_object, peerplays_sidechain::sidechain_type, &son_wallet_deposit_object::sidechain>
>,
ordered_unique< tag<by_sidechain_uid>,
member<son_wallet_transfer_object, std::string, &son_wallet_transfer_object::sidechain_uid>
member<son_wallet_deposit_object, std::string, &son_wallet_deposit_object::sidechain_uid>
>,
ordered_non_unique< tag<by_processed>,
member<son_wallet_transfer_object, bool, &son_wallet_transfer_object::processed>
member<son_wallet_deposit_object, bool, &son_wallet_deposit_object::processed>
>,
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>
composite_key<son_wallet_deposit_object,
member<son_wallet_deposit_object, peerplays_sidechain::sidechain_type, &son_wallet_deposit_object::sidechain>,
member<son_wallet_deposit_object, bool, &son_wallet_deposit_object::processed>
>
>
>
>;
using son_wallet_transfer_index = generic_index<son_wallet_transfer_object, son_wallet_transfer_multi_index_type>;
using son_wallet_deposit_index = generic_index<son_wallet_deposit_object, son_wallet_deposit_multi_index_type>;
} } // 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)

View file

@ -1,24 +0,0 @@
#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);
};
class process_son_wallet_transfer_evaluator : public evaluator<process_son_wallet_transfer_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

View file

@ -0,0 +1,24 @@
#pragma once
#include <graphene/chain/evaluator.hpp>
namespace graphene { namespace chain {
class create_son_wallet_withdrawal_evaluator : public evaluator<create_son_wallet_withdrawal_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<process_son_wallet_withdrawal_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

View file

@ -0,0 +1,69 @@
#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_withdrawal_object
* @brief tracks information about a SON wallet withdrawal.
* @ingroup object
*/
class son_wallet_withdrawal_object : public abstract_object<son_wallet_withdrawal_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<int64_t> 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<by_id>,
member<object, object_id_type, &object::id>
>,
ordered_non_unique< tag<by_sidechain>,
member<son_wallet_withdrawal_object, peerplays_sidechain::sidechain_type, &son_wallet_withdrawal_object::sidechain>
>,
ordered_unique< tag<by_sidechain_uid>,
member<son_wallet_withdrawal_object, std::string, &son_wallet_withdrawal_object::sidechain_uid>
>,
ordered_non_unique< tag<by_processed>,
member<son_wallet_withdrawal_object, bool, &son_wallet_withdrawal_object::processed>
>,
ordered_non_unique< tag<by_sidechain_and_processed>,
composite_key<son_wallet_withdrawal_object,
member<son_wallet_withdrawal_object, peerplays_sidechain::sidechain_type, &son_wallet_withdrawal_object::sidechain>,
member<son_wallet_withdrawal_object, bool, &son_wallet_withdrawal_object::processed>
>
>
>
>;
using son_wallet_withdrawal_index = generic_index<son_wallet_withdrawal_object, son_wallet_withdrawal_multi_index_type>;
} } // 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) )

View file

@ -1,27 +1,27 @@
#include <graphene/chain/son_wallet_transfer_evaluator.hpp>
#include <graphene/chain/son_wallet_deposit_evaluator.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/is_authorized_asset.hpp>
#include <graphene/chain/son_wallet_transfer_object.hpp>
#include <graphene/chain/son_wallet_deposit_object.hpp>
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<son_wallet_transfer_index>().indices().get<by_sidechain_uid>();
//const auto& idx = db().get_index_type<son_wallet_deposit_index>().indices().get<by_sidechain_uid>();
//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<son_wallet_transfer_index>().indices().get<by_sidechain_uid>();
const auto& idx = db().get_index_type<son_wallet_deposit_index>().indices().get<by_sidechain_uid>();
auto itr = idx.find(op.sidechain_uid);
if (itr == idx.end()) {
const auto& new_son_wallet_transfer_object = db().create<son_wallet_transfer_object>( [&]( son_wallet_transfer_object& swto ){
const auto& new_son_wallet_deposit_object = db().create<son_wallet_deposit_object>( [&]( 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<son_wallet_transfer_index>().indices().get<by_id>();
const auto& itr = idx.find(op.son_wallet_transfer_id);
const auto& idx = db().get_index_type<son_wallet_deposit_index>().indices().get<by_id>();
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<son_wallet_transfer_index>().indices().get<by_id>();
auto itr = idx.find(op.son_wallet_transfer_id);
const auto& idx = db().get_index_type<son_wallet_deposit_index>().indices().get<by_id>();
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

View file

@ -0,0 +1,120 @@
#include <graphene/chain/son_wallet_withdrawal_evaluator.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/is_authorized_asset.hpp>
#include <graphene/chain/son_wallet_withdrawal_object.hpp>
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<son_wallet_withdrawal_index>().indices().get<by_sidechain_uid>();
//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<son_wallet_withdrawal_index>().indices().get<by_sidechain_uid>();
auto itr = idx.find(op.sidechain_uid);
if (itr == idx.end()) {
const auto& new_son_wallet_withdrawal_object = db().create<son_wallet_withdrawal_object>( [&]( 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<son_wallet_withdrawal_index>().indices().get<by_id>();
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<son_wallet_withdrawal_index>().indices().get<by_id>();
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

View file

@ -10,7 +10,8 @@
#include <graphene/chain/proposal_object.hpp>
#include <graphene/chain/sidechain_address_object.hpp>
#include <graphene/chain/son_wallet_object.hpp>
#include <graphene/chain/son_wallet_transfer_object.hpp>
#include <graphene/chain/son_wallet_deposit_object.hpp>
#include <graphene/chain/son_wallet_withdrawal_object.hpp>
#include <graphene/chain/protocol/transfer.hpp>
#include <graphene/peerplays_sidechain/sidechain_net_manager.hpp>
#include <graphene/utilities/key_conversion.hpp>
@ -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<son_wallet_transfer_index>().indices().get<by_processed>();
const auto& idx = plugin.database().get_index_type<son_wallet_deposit_index>().indices().get<by_processed>();
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<son_wallet_withdrawal_index>().indices().get<by_processed>();
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 vector<object_id_type
}
if(proposal->proposed_transaction.operations.size() == 1
&& proposal->proposed_transaction.operations[0].which() == chain::operation::tag<chain::son_wallet_transfer_create_operation>::value) {
&& proposal->proposed_transaction.operations[0].which() == chain::operation::tag<chain::son_wallet_deposit_create_operation>::value) {
approve_proposal( son_id, proposal->id );
continue;
}
if(proposal->proposed_transaction.operations.size() == 1
&& proposal->proposed_transaction.operations[0].which() == chain::operation::tag<chain::son_wallet_transfer_process_operation>::value) {
&& proposal->proposed_transaction.operations[0].which() == chain::operation::tag<chain::son_wallet_deposit_process_operation>::value) {
approve_proposal( son_id, proposal->id );
continue;
}

View file

@ -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;

View file

@ -45,7 +45,8 @@
#include <graphene/chain/game_object.hpp>
#include <graphene/chain/son_object.hpp>
#include <graphene/chain/son_wallet_object.hpp>
#include <graphene/chain/son_wallet_transfer_object.hpp>
#include <graphene/chain/son_wallet_deposit_object.hpp>
#include <graphene/chain/son_wallet_withdrawal_object.hpp>
#include <graphene/chain/sidechain_address_object.hpp>
#include <fc/smart_ref_impl.hpp>