Depositing Peerplays asset refactored

This commit is contained in:
Srdjan Obucina 2020-03-20 01:27:16 +01:00
parent 8e71b66575
commit 1bc038e6f6
11 changed files with 49 additions and 65 deletions

View file

@ -4,6 +4,7 @@
#include <graphene/db/generic_index.hpp>
#include <graphene/chain/sidechain_defs.hpp>
#include <boost/multi_index/composite_key.hpp>
namespace graphene { namespace chain {
using namespace graphene::db;

View file

@ -1,4 +1,5 @@
#pragma once
#include <boost/multi_index/composite_key.hpp>
#include <graphene/chain/protocol/types.hpp>
#include <graphene/chain/sidechain_defs.hpp>

View file

@ -1,4 +1,5 @@
#pragma once
#include <graphene/chain/protocol/asset.hpp>
#include <graphene/chain/protocol/types.hpp>
#include <graphene/chain/sidechain_defs.hpp>

View file

@ -1,4 +1,5 @@
#pragma once
#include <graphene/chain/protocol/asset.hpp>
#include <graphene/chain/protocol/types.hpp>
#include <graphene/chain/sidechain_defs.hpp>

View file

@ -30,6 +30,7 @@ object_id_type create_son_wallet_deposit_evaluator::do_apply(const son_wallet_de
swto.sidechain_transaction_id = op.sidechain_transaction_id;
swto.sidechain_from = op.sidechain_from;
swto.sidechain_to = op.sidechain_to;
swto.sidechain_currency = op.sidechain_currency;
swto.sidechain_amount = op.sidechain_amount;
swto.peerplays_from = op.peerplays_from;
swto.peerplays_to = op.peerplays_to;
@ -73,47 +74,7 @@ void_result process_son_wallet_deposit_evaluator::do_evaluate(const son_wallet_d
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 deposit not found");
const database& d = db();
const account_object& from_account = itr->peerplays_to(d); // reversed, for deposit
const account_object& to_account = itr->peerplays_from(d); // reversed, for deposit
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) );
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }
object_id_type process_son_wallet_deposit_evaluator::do_apply(const son_wallet_deposit_process_operation& op)
@ -126,12 +87,6 @@ object_id_type process_son_wallet_deposit_evaluator::do_apply(const son_wallet_d
db().modify(*itr, [&op](son_wallet_deposit_object &swto) {
swto.processed = true;
});
const account_id_type from_account = itr->peerplays_to; // reversed, for deposit
const account_id_type to_account = itr->peerplays_from; // reversed, for deposit
db().adjust_balance( from_account, -itr->peerplays_asset );
db().adjust_balance( to_account, itr->peerplays_asset );
}
}
return op.son_wallet_deposit_id;

View file

@ -5,6 +5,11 @@
#include <boost/program_options.hpp>
#include <fc/signals.hpp>
#include <graphene/chain/global_property_object.hpp>
#include <graphene/chain/sidechain_address_object.hpp>
#include <graphene/chain/sidechain_transaction_object.hpp>
#include <graphene/chain/son_wallet_deposit_object.hpp>
#include <graphene/chain/son_wallet_withdraw_object.hpp>
#include <graphene/peerplays_sidechain/defs.hpp>
#include <graphene/peerplays_sidechain/peerplays_sidechain_plugin.hpp>

View file

@ -7,8 +7,6 @@
#include <fc/network/http/connection.hpp>
#include <fc/signals.hpp>
#include <graphene/chain/son_wallet_deposit_object.hpp>
#include <graphene/chain/son_wallet_withdraw_object.hpp>
namespace graphene { namespace peerplays_sidechain {

View file

@ -351,6 +351,8 @@ void peerplays_sidechain_plugin_impl::son_processing() {
process_withdrawals();
process_sidechain_transactions();
send_sidechain_transactions();
}
}

View file

@ -1,10 +1,5 @@
#include <graphene/peerplays_sidechain/sidechain_net_handler.hpp>
#include <graphene/chain/sidechain_address_object.hpp>
#include <graphene/chain/sidechain_transaction_object.hpp>
#include <graphene/chain/son_wallet_deposit_object.hpp>
#include <graphene/chain/son_wallet_withdraw_object.hpp>
#include <fc/log/logger.hpp>
namespace graphene { namespace peerplays_sidechain {
@ -210,7 +205,7 @@ void sidechain_net_handler::process_deposits() {
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()));
ilog("sidechain_net_handler: sending proposal for deposit sidechain transaction create operation failed with exception ${e}", ("e", e.what()));
}
});
}
@ -264,7 +259,7 @@ void sidechain_net_handler::process_withdrawals() {
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()));
ilog("sidechain_net_handler: sending proposal for withdrawal sidechain transaction create operation failed with exception ${e}", ("e", e.what()));
}
});
}
@ -297,7 +292,7 @@ void sidechain_net_handler::process_sidechain_transactions() {
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()));
ilog("sidechain_net_handler: sending proposal for sidechain transaction sign operation failed with exception ${e}", ("e", e.what()));
}
});
}
@ -327,7 +322,7 @@ void sidechain_net_handler::send_sidechain_transactions() {
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()));
ilog("sidechain_net_handler: sending proposal for sidechain transaction send operation failed with exception ${e}", ("e", e.what()));
}
});
}

View file

@ -12,10 +12,7 @@
#include <fc/network/ip.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/protocol/sidechain_transaction.hpp>
#include <graphene/chain/protocol/son_wallet.hpp>
#include <graphene/chain/sidechain_address_object.hpp>
#include <graphene/chain/sidechain_transaction_object.hpp>
#include <graphene/chain/son_info.hpp>
#include <graphene/chain/son_wallet_object.hpp>

View file

@ -13,7 +13,6 @@
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/protocol/son_wallet.hpp>
#include <graphene/chain/sidechain_address_object.hpp>
#include <graphene/chain/son_info.hpp>
#include <graphene/chain/son_wallet_object.hpp>
@ -35,16 +34,45 @@ std::string sidechain_net_handler_peerplays::recreate_primary_wallet() {
}
std::string sidechain_net_handler_peerplays::process_deposit(const son_wallet_deposit_object &swdo) {
return "";
std::string res = "";
const chain::global_property_object &gpo = database.get_global_properties();
transfer_operation t_op;
t_op.fee = asset(2000000);
t_op.from = swdo.peerplays_to; // GRAPHENE_SON_ACCOUNT
t_op.to = swdo.peerplays_from;
t_op.amount = swdo.peerplays_asset;
proposal_create_operation proposal_op;
proposal_op.fee_paying_account = plugin.get_son_object(plugin.get_current_son_id()).son_account;
proposal_op.proposed_ops.emplace_back(op_wrapper(t_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);
signed_transaction trx = plugin.database().create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), proposal_op);
trx.validate();
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));
res = trx.id().str();
} catch (fc::exception e) {
ilog("sidechain_net_handler_peerplays: sending proposal for transfer operation failed with exception ${e}", ("e", e.what()));
}
return res;
}
std::string sidechain_net_handler_peerplays::process_withdrawal(const son_wallet_withdraw_object &swwo) {
return "";
return "Withdraw not supported";
}
std::string sidechain_net_handler_peerplays::process_sidechain_transaction(const sidechain_transaction_object &sto, bool &complete) {
complete = true;
return "";
return sto.transaction;
;
}
bool sidechain_net_handler_peerplays::send_sidechain_transaction(const sidechain_transaction_object &sto) {