Remove proposals for creating deposit and withdrawal objects, strenghten evaluator checks

This commit is contained in:
Srdjan Obucina 2020-03-26 15:05:52 +01:00
parent 0f97241f1b
commit 94cf6b6ef4
4 changed files with 89 additions and 59 deletions

View file

@ -8,12 +8,39 @@
namespace graphene { namespace chain {
void_result create_son_wallet_deposit_evaluator::do_evaluate(const son_wallet_deposit_create_operation& op)
{ try{
{ try {
FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK");
FC_ASSERT( op.payer == db().get_global_properties().parameters.son_account(), "SON paying account must be set as payer." );
const auto &idx = db().get_index_type<son_stats_index>().indices().get<by_owner>();
FC_ASSERT(idx.find(op.son_id) != idx.end(), "Statistic object for a given SON ID does not exists");
const auto &swdo_idx = db().get_index_type<son_wallet_deposit_index>().indices().get<by_sidechain_uid>();
const auto swdo = swdo_idx.find(op.sidechain_uid);
if (swdo == swdo_idx.end()) {
auto &gpo = db().get_global_properties();
bool expected = false;
for (auto &si : gpo.active_sons) {
if (op.son_id == si.son_id) {
expected = true;
break;
}
}
FC_ASSERT(expected, "Only active SON can create deposit");
} else {
bool expected = false;
for (auto &son_id : swdo->expected_reports) {
if (op.son_id == son_id) {
expected = true;
break;
}
}
FC_ASSERT(expected, "Confirmation from this SON not expected");
}
const auto &son_idx = db().get_index_type<son_index>().indices().get<by_id>();
const auto so = son_idx.find(op.son_id);
FC_ASSERT(so != son_idx.end(), "SON not found");
FC_ASSERT(so->son_account == op.payer, "Payer is not SON account owner");
const auto &ss_idx = db().get_index_type<son_stats_index>().indices().get<by_owner>();
FC_ASSERT(ss_idx.find(op.son_id) != ss_idx.end(), "Statistic object for a given SON ID does not exists");
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }

View file

@ -8,12 +8,40 @@
namespace graphene { namespace chain {
void_result create_son_wallet_withdraw_evaluator::do_evaluate(const son_wallet_withdraw_create_operation& op)
{ try{
{ try {
FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK");
FC_ASSERT( op.payer == db().get_global_properties().parameters.son_account(), "SON paying account must be set as payer." );
const auto &idx = db().get_index_type<son_stats_index>().indices().get<by_owner>();
FC_ASSERT(idx.find(op.son_id) != idx.end(), "Statistic object for a given SON ID does not exists");
const auto &swwo_idx = db().get_index_type<son_wallet_withdraw_index>().indices().get<by_peerplays_uid>();
const auto swwo = swwo_idx.find(op.peerplays_uid);
if (swwo == swwo_idx.end()) {
auto &gpo = db().get_global_properties();
bool expected = false;
for (auto &si : gpo.active_sons) {
if (op.son_id == si.son_id) {
expected = true;
break;
}
}
FC_ASSERT(expected, "Only active SON can create deposit");
} else {
bool expected = false;
for (auto &son_id : swwo->expected_reports) {
if (op.son_id == son_id) {
expected = true;
break;
}
}
FC_ASSERT(expected, "Confirmation from this SON not expected");
}
const auto &son_idx = db().get_index_type<son_index>().indices().get<by_id>();
const auto so = son_idx.find(op.son_id);
FC_ASSERT(so != son_idx.end(), "SON not found");
FC_ASSERT(so->son_account == op.payer, "Payer is not SON account owner");
const auto &ss_idx = db().get_index_type<son_stats_index>().indices().get<by_owner>();
FC_ASSERT(ss_idx.find(op.son_id) != ss_idx.end(), "Statistic object for a given SON ID does not exists");
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }

View file

@ -439,16 +439,6 @@ void peerplays_sidechain_plugin_impl::approve_proposals() {
continue;
}
if (op_idx_0 == chain::operation::tag<chain::son_wallet_deposit_create_operation>::value) {
approve_proposal(get_current_son_id(), proposal.id);
continue;
}
if (op_idx_0 == chain::operation::tag<chain::son_wallet_withdraw_create_operation>::value) {
approve_proposal(get_current_son_id(), proposal.id);
continue;
}
if (op_idx_0 == chain::operation::tag<chain::son_wallet_withdraw_process_operation>::value) {
approve_proposal(get_current_son_id(), proposal.id);
continue;

View file

@ -69,33 +69,26 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_
// Deposit request
if ((sed.peerplays_to == gpo.parameters.son_account()) && (sed.sidechain_currency.compare("1.3.0") != 0)) {
son_wallet_deposit_create_operation op;
op.payer = gpo.parameters.son_account();
//op.son_id = ; // to be filled for each son
op.timestamp = sed.timestamp;
op.sidechain = sed.sidechain;
op.sidechain_uid = sed.sidechain_uid;
op.sidechain_transaction_id = sed.sidechain_transaction_id;
op.sidechain_from = sed.sidechain_from;
op.sidechain_to = sed.sidechain_to;
op.sidechain_currency = sed.sidechain_currency;
op.sidechain_amount = sed.sidechain_amount;
op.peerplays_from = sed.peerplays_from;
op.peerplays_to = sed.peerplays_to;
op.peerplays_asset = sed.peerplays_asset;
for (son_id_type son_id : plugin.get_sons()) {
if (plugin.is_active_son(son_id)) {
son_wallet_deposit_create_operation op;
op.payer = plugin.get_current_son_object().son_account;
op.son_id = son_id;
op.timestamp = sed.timestamp;
op.sidechain = sed.sidechain;
op.sidechain_uid = sed.sidechain_uid;
op.sidechain_transaction_id = sed.sidechain_transaction_id;
op.sidechain_from = sed.sidechain_from;
op.sidechain_to = sed.sidechain_to;
op.sidechain_currency = sed.sidechain_currency;
op.sidechain_amount = sed.sidechain_amount;
op.peerplays_from = sed.peerplays_from;
op.peerplays_to = sed.peerplays_to;
op.peerplays_asset = sed.peerplays_asset;
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);
uint32_t lifetime = (gpo.parameters.block_interval * gpo.active_witnesses.size()) * 3;
proposal_op.expiration_time = time_point_sec(database.head_block_time().sec_since_epoch() + lifetime);
signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(son_id), proposal_op);
signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(son_id), op);
try {
database.push_transaction(trx, database::validation_steps::skip_block_size_check);
if (plugin.app().p2p_node())
@ -116,32 +109,24 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_
if (addr_itr == sidechain_addresses_idx.end())
return;
son_wallet_withdraw_create_operation op;
op.payer = gpo.parameters.son_account();
//op.son_id = ; // to be filled for each son
op.timestamp = sed.timestamp;
op.sidechain = sed.sidechain;
op.peerplays_uid = sed.sidechain_uid;
op.peerplays_transaction_id = sed.sidechain_transaction_id;
op.peerplays_from = sed.peerplays_from;
op.peerplays_asset = sed.peerplays_asset;
op.withdraw_sidechain = sidechain_type::bitcoin; // BTC payout only (for now)
op.withdraw_address = addr_itr->withdraw_address; // BTC payout only (for now)
op.withdraw_currency = "BTC"; // BTC payout only (for now)
op.withdraw_amount = sed.peerplays_asset.amount * 1000; // BTC payout only (for now)
for (son_id_type son_id : plugin.get_sons()) {
if (plugin.is_active_son(son_id)) {
son_wallet_withdraw_create_operation op;
op.payer = plugin.get_current_son_object().son_account;
op.son_id = son_id;
op.timestamp = sed.timestamp;
op.sidechain = sed.sidechain;
op.peerplays_uid = sed.sidechain_uid;
op.peerplays_transaction_id = sed.sidechain_transaction_id;
op.peerplays_from = sed.peerplays_from;
op.peerplays_asset = sed.peerplays_asset;
op.withdraw_sidechain = sidechain_type::bitcoin; // BTC payout only (for now)
op.withdraw_address = addr_itr->withdraw_address; // BTC payout only (for now)
op.withdraw_currency = "BTC"; // BTC payout only (for now)
op.withdraw_amount = sed.peerplays_asset.amount * 1000; // BTC payout only (for now)
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);
uint32_t lifetime = (gpo.parameters.block_interval * gpo.active_witnesses.size()) * 3;
proposal_op.expiration_time = time_point_sec(database.head_block_time().sec_since_epoch() + lifetime);
signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(son_id), proposal_op);
signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(son_id), op);
try {
database.push_transaction(trx, database::validation_steps::skip_block_size_check);
if (plugin.app().p2p_node())