Added check for approving son_wallet_deposit_process_operation

- Calculating exchange rates fixed
- Fix depositing Peerplays assets
This commit is contained in:
Srdjan Obucina 2020-04-03 05:13:31 +02:00
parent 94fcedabb4
commit 110676d8dd
4 changed files with 244 additions and 182 deletions

View file

@ -1873,15 +1873,24 @@ void perform_son_tasks(database& db)
const asset_object& btc_asset =
db.create<asset_object>( [&gpo, &dyn_asset]( asset_object& a ) {
a.symbol = "BTC";
a.options.max_supply = GRAPHENE_MAX_SHARE_SUPPLY;
a.precision = 8;
a.options.flags = 0;
a.options.issuer_permissions = 0;
a.issuer = gpo.parameters.son_account();
a.options.core_exchange_rate.base.amount = 1;
a.options.max_supply = GRAPHENE_MAX_SHARE_SUPPLY;
a.options.market_fee_percent = 500; // 5%
a.options.issuer_permissions = UIA_ASSET_ISSUER_PERMISSION_MASK;
a.options.flags = asset_issuer_permission_flags::charge_market_fee |
//asset_issuer_permission_flags::white_list |
asset_issuer_permission_flags::override_authority |
asset_issuer_permission_flags::transfer_restricted |
asset_issuer_permission_flags::disable_confidential;
a.options.core_exchange_rate.base.amount = 100000;
a.options.core_exchange_rate.base.asset_id = asset_id_type(0);
a.options.core_exchange_rate.quote.amount = 1;
a.options.core_exchange_rate.quote.amount = 2500; // CoinMarketCap approx value
a.options.core_exchange_rate.quote.asset_id = asset_id_type(0);
a.options.whitelist_authorities.clear(); // accounts allowed to use asset, if not empty
a.options.blacklist_authorities.clear(); // accounts who can blacklist other accounts to use asset, if white_list flag is set
a.options.whitelist_markets.clear(); // might be traded with
a.options.blacklist_markets.clear(); // might not be traded with
a.dynamic_asset_data_id = dyn_asset.id;
});
db.modify( gpo, [&btc_asset]( global_property_object& gpo ) {

View file

@ -90,8 +90,13 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_
const chain::global_property_object &gpo = database.get_global_properties();
asset_id_type btc_asset_id = database.get_global_properties().parameters.btc_asset();
std::string btc_asset_id_str = fc::to_string(btc_asset_id.space_id) + "." +
fc::to_string(btc_asset_id.type_id) + "." +
fc::to_string((uint64_t)btc_asset_id.instance);
// Deposit request
if ((sed.peerplays_from == gpo.parameters.son_account()) && (sed.sidechain_currency != fc::variant(gpo.parameters.btc_asset(), 1).as<std::string>(1))) {
if ((sed.peerplays_to == gpo.parameters.son_account()) && (sed.sidechain_currency.compare(btc_asset_id_str) != 0)) {
for (son_id_type son_id : plugin.get_sons()) {
if (plugin.is_active_son(son_id)) {
@ -126,7 +131,7 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_
}
// Withdrawal request
if ((sed.peerplays_to == gpo.parameters.son_account()) && (sed.sidechain_currency == fc::variant(gpo.parameters.btc_asset(), 1).as<std::string>(1))) {
if ((sed.peerplays_to == gpo.parameters.son_account()) && (sed.sidechain_currency.compare(btc_asset_id_str) == 0)) {
// BTC Payout only (for now)
const auto &sidechain_addresses_idx = database.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain>();
const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sed.peerplays_from, sidechain_type::bitcoin));
@ -146,10 +151,12 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_
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; // BTC payout only (for now)
// BTC payout only (for now)
op.withdraw_sidechain = sidechain_type::bitcoin;
op.withdraw_address = addr_itr->withdraw_address;
op.withdraw_currency = "BTC";
price btc_price = database.get<asset_object>(database.get_global_properties().parameters.btc_asset()).options.core_exchange_rate;
op.withdraw_amount = sed.peerplays_asset.amount * btc_price.quote.amount / btc_price.base.amount;
signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(son_id), op);
try {
@ -187,72 +194,71 @@ void sidechain_net_handler::process_proposals() {
bool should_process = false;
int32_t op_idx_0 = -1;
chain::operation op_obj_idx_0;
int32_t op_idx_1 = -1;
chain::operation op_obj_idx_1;
if (po->proposed_transaction.operations.size() >= 1) {
int32_t op_idx_0 = po->proposed_transaction.operations[0].which();
chain::operation op = po->proposed_transaction.operations[0];
ilog("Proposal operation[0]: ${op}", ("op", op));
switch (op_idx_0) {
case chain::operation::tag<chain::son_wallet_update_operation>::value: {
should_process = true;
break;
}
case chain::operation::tag<chain::son_wallet_deposit_process_operation>::value: {
son_wallet_deposit_id_type swdo_id = op.get<son_wallet_deposit_process_operation>().son_wallet_deposit_id;
const auto &idx = database.get_index_type<son_wallet_deposit_index>().indices().get<by_id>();
const auto swdo = idx.find(swdo_id);
if (swdo != idx.end()) {
should_process = (swdo->sidechain == sidechain);
}
break;
}
case chain::operation::tag<chain::son_wallet_withdraw_process_operation>::value: {
son_wallet_withdraw_id_type swwo_id = op.get<son_wallet_withdraw_process_operation>().son_wallet_withdraw_id;
const auto &idx = database.get_index_type<son_wallet_withdraw_index>().indices().get<by_id>();
const auto swwo = idx.find(swwo_id);
if (swwo != idx.end()) {
should_process = (swwo->sidechain == sidechain);
}
break;
}
case chain::operation::tag<chain::sidechain_transaction_create_operation>::value: {
sidechain_type sc = op.get<sidechain_transaction_create_operation>().sidechain;
should_process = (sc == sidechain);
break;
}
default:
should_process = false;
ilog("==================================================");
ilog("Proposal not processed ${po}", ("po", *po));
ilog("==================================================");
}
op_idx_0 = po->proposed_transaction.operations[0].which();
op_obj_idx_0 = po->proposed_transaction.operations[0];
}
//if (po->proposed_transaction.operations.size() == 2) {
// int32_t op_idx_0 = proposal.proposed_transaction.operations[0].which();
// int32_t op_idx_1 = proposal.proposed_transaction.operations[1].which();
//
// if ((op_idx_0 == chain::operation::tag<chain::son_wallet_deposit_process_operation>::value) &&
// (op_idx_1 == chain::operation::tag<chain::asset_issue_operation>::value)) {
// return true;
// }
// if ((op_idx_0 == chain::operation::tag<chain::son_wallet_withdraw_process_operation>::value) &&
// (op_idx_1 == chain::operation::tag<chain::asset_reserve_operation>::value)) {
// return true;
// }
//}
if (po->proposed_transaction.operations.size() >= 2) {
op_idx_1 = po->proposed_transaction.operations[1].which();
op_obj_idx_1 = po->proposed_transaction.operations[1];
}
switch (op_idx_0) {
case chain::operation::tag<chain::son_wallet_update_operation>::value: {
should_process = true;
break;
}
case chain::operation::tag<chain::son_wallet_deposit_process_operation>::value: {
son_wallet_deposit_id_type swdo_id = op_obj_idx_0.get<son_wallet_deposit_process_operation>().son_wallet_deposit_id;
const auto &idx = database.get_index_type<son_wallet_deposit_index>().indices().get<by_id>();
const auto swdo = idx.find(swdo_id);
if (swdo != idx.end()) {
should_process = (swdo->sidechain == sidechain);
}
break;
}
case chain::operation::tag<chain::son_wallet_withdraw_process_operation>::value: {
son_wallet_withdraw_id_type swwo_id = op_obj_idx_0.get<son_wallet_withdraw_process_operation>().son_wallet_withdraw_id;
const auto &idx = database.get_index_type<son_wallet_withdraw_index>().indices().get<by_id>();
const auto swwo = idx.find(swwo_id);
if (swwo != idx.end()) {
should_process = (swwo->sidechain == sidechain);
}
break;
}
case chain::operation::tag<chain::sidechain_transaction_create_operation>::value: {
sidechain_type sc = op_obj_idx_0.get<sidechain_transaction_create_operation>().sidechain;
should_process = (sc == sidechain);
break;
}
default:
should_process = false;
ilog("==================================================");
ilog("Proposal not processed ${po}", ("po", *po));
ilog("==================================================");
}
if (should_process) {
ilog("Proposal ${po} will be processed by sidechain handler ${sidechain}", ("po", (*po).id)("sidechain", sidechain));
bool should_approve = process_proposal(*po);
if (should_approve) {
ilog("Proposal ${po} will be approved", ("po", *po));
approve_proposal(po->id, plugin.get_current_son_id());
} else {
ilog("Proposal ${po} is not approved", ("po", (*po).id));
}
} else {
ilog("Proposal ${po} will not be processed by sidechain handler ${sidechain}", ("po", (*po).id)("sidechain", sidechain));
}
}
}
@ -286,16 +292,17 @@ void sidechain_net_handler::process_deposits() {
swdp_op.payer = gpo.parameters.son_account();
swdp_op.son_wallet_deposit_id = swdo.id;
asset_issue_operation i_op;
i_op.fee = asset(2001000);
i_op.issuer = gpo.parameters.son_account();
i_op.asset_to_issue = swdo.peerplays_asset;
i_op.issue_to_account = swdo.peerplays_to;
asset_issue_operation ai_op;
ai_op.fee = asset(2001000);
ai_op.issuer = gpo.parameters.son_account();
price btc_price = database.get<asset_object>(database.get_global_properties().parameters.btc_asset()).options.core_exchange_rate;
ai_op.asset_to_issue = asset(swdo.peerplays_asset.amount * btc_price.quote.amount / btc_price.base.amount, database.get_global_properties().parameters.btc_asset());
ai_op.issue_to_account = swdo.peerplays_from;
proposal_create_operation proposal_op;
proposal_op.fee_paying_account = plugin.get_current_son_object().son_account;
proposal_op.proposed_ops.emplace_back(swdp_op);
proposal_op.proposed_ops.emplace_back(i_op);
proposal_op.proposed_ops.emplace_back(ai_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);
@ -306,7 +313,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) {
elog("Sending proposal for deposit sidechain transaction create operation failed with exception ${e}", ("e", e.what()));
elog("Sending proposal for son wallet deposit process operation failed with exception ${e}", ("e", e.what()));
}
});
}
@ -335,16 +342,15 @@ void sidechain_net_handler::process_withdrawals() {
swwp_op.payer = gpo.parameters.son_account();
swwp_op.son_wallet_withdraw_id = swwo.id;
asset_reserve_operation r_op;
r_op.fee = asset(2001000);
r_op.payer = gpo.parameters.son_account();
asset_object btc_asset_obj = gpo.parameters.btc_asset()(database);
r_op.amount_to_reserve = btc_asset_obj.amount(swwo.withdraw_amount);
asset_reserve_operation ar_op;
ar_op.fee = asset(2001000);
ar_op.payer = gpo.parameters.son_account();
ar_op.amount_to_reserve = asset(swwo.withdraw_amount, database.get_global_properties().parameters.btc_asset());
proposal_create_operation proposal_op;
proposal_op.fee_paying_account = plugin.get_current_son_object().son_account;
proposal_op.proposed_ops.emplace_back(swwp_op);
proposal_op.proposed_ops.emplace_back(r_op);
proposal_op.proposed_ops.emplace_back(ar_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);
@ -355,7 +361,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) {
elog("Sending proposal for withdraw sidechain transaction create operation failed with exception ${e}", ("e", e.what()));
elog("Sending proposal for son wallet withdraw process operation failed with exception ${e}", ("e", e.what()));
}
});
}

View file

@ -874,74 +874,84 @@ bool sidechain_net_handler_bitcoin::process_proposal(const proposal_object &po)
const chain::global_property_object &gpo = database.get_global_properties();
if (po.proposed_transaction.operations.size() == 1) {
int32_t op_idx_0 = po.proposed_transaction.operations[0].which();
chain::operation op = po.proposed_transaction.operations[0];
int32_t op_idx_0 = -1;
chain::operation op_obj_idx_0;
//int32_t op_idx_1 = -1;
//chain::operation op_obj_idx_1;
switch (op_idx_0) {
if (po.proposed_transaction.operations.size() >= 1) {
op_idx_0 = po.proposed_transaction.operations[0].which();
op_obj_idx_0 = po.proposed_transaction.operations[0];
}
case chain::operation::tag<chain::son_wallet_update_operation>::value: {
should_approve = true;
break;
}
if (po.proposed_transaction.operations.size() >= 2) {
//op_idx_1 = po.proposed_transaction.operations[1].which();
//op_obj_idx_1 = po.proposed_transaction.operations[1];
}
case chain::operation::tag<chain::son_wallet_deposit_process_operation>::value: {
son_wallet_deposit_id_type swdo_id = op.get<son_wallet_deposit_process_operation>().son_wallet_deposit_id;
const auto &idx = database.get_index_type<son_wallet_deposit_index>().indices().get<by_id>();
const auto swdo = idx.find(swdo_id);
if (swdo != idx.end()) {
switch (op_idx_0) {
std::string swdo_txid = swdo->sidechain_transaction_id;
std::string swdo_address = swdo->sidechain_to;
uint64_t swdo_amount = swdo->sidechain_amount.value;
uint64_t swdo_vout = std::stoll(swdo->sidechain_uid.substr(swdo->sidechain_uid.find_last_of("-") + 1));
case chain::operation::tag<chain::son_wallet_update_operation>::value: {
should_approve = true;
break;
}
std::string tx_str = bitcoin_client->gettransaction(swdo_txid);
std::stringstream tx_ss(tx_str);
boost::property_tree::ptree tx_json;
boost::property_tree::read_json(tx_ss, tx_json);
case chain::operation::tag<chain::son_wallet_deposit_process_operation>::value: {
son_wallet_deposit_id_type swdo_id = op_obj_idx_0.get<son_wallet_deposit_process_operation>().son_wallet_deposit_id;
const auto &idx = database.get_index_type<son_wallet_deposit_index>().indices().get<by_id>();
const auto swdo = idx.find(swdo_id);
if (swdo != idx.end()) {
if (tx_json.count("error") && tx_json.get_child("error").empty()) {
std::string swdo_txid = swdo->sidechain_transaction_id;
std::string swdo_address = swdo->sidechain_to;
uint64_t swdo_amount = swdo->sidechain_amount.value;
uint64_t swdo_vout = std::stoll(swdo->sidechain_uid.substr(swdo->sidechain_uid.find_last_of("-") + 1));
std::string tx_txid = tx_json.get<std::string>("result.txid");
uint32_t tx_confirmations = tx_json.get<uint32_t>("result.confirmations");
std::string tx_address = "";
uint64_t tx_amount = 0;
uint64_t tx_vout = 0;
std::string tx_str = bitcoin_client->gettransaction(swdo_txid);
std::stringstream tx_ss(tx_str);
boost::property_tree::ptree tx_json;
boost::property_tree::read_json(tx_ss, tx_json);
for (auto &input : tx_json.get_child("result.details")) {
tx_address = input.second.get<std::string>("address");
std::string tx_amount_s = input.second.get<std::string>("amount");
tx_amount_s.erase(std::remove(tx_amount_s.begin(), tx_amount_s.end(), '.'), tx_amount_s.end());
tx_amount = std::stoll(tx_amount_s);
std::string tx_vout_s = input.second.get<std::string>("vout");
tx_vout = std::stoll(tx_vout_s);
break;
}
if (tx_json.count("error") && tx_json.get_child("error").empty()) {
should_approve = (swdo_txid == tx_txid) &&
(swdo_address == tx_address) &&
(swdo_amount == tx_amount) &&
(swdo_vout == tx_vout) &&
(gpo.parameters.son_bitcoin_min_tx_confirmations() <= tx_confirmations);
std::string tx_txid = tx_json.get<std::string>("result.txid");
uint32_t tx_confirmations = tx_json.get<uint32_t>("result.confirmations");
std::string tx_address = "";
uint64_t tx_amount = 0;
uint64_t tx_vout = 0;
for (auto &input : tx_json.get_child("result.details")) {
tx_address = input.second.get<std::string>("address");
std::string tx_amount_s = input.second.get<std::string>("amount");
tx_amount_s.erase(std::remove(tx_amount_s.begin(), tx_amount_s.end(), '.'), tx_amount_s.end());
tx_amount = std::stoll(tx_amount_s);
std::string tx_vout_s = input.second.get<std::string>("vout");
tx_vout = std::stoll(tx_vout_s);
break;
}
should_approve = (swdo_txid == tx_txid) &&
(swdo_address == tx_address) &&
(swdo_amount == tx_amount) &&
(swdo_vout == tx_vout) &&
(gpo.parameters.son_bitcoin_min_tx_confirmations() <= tx_confirmations);
}
break;
}
break;
}
case chain::operation::tag<chain::son_wallet_withdraw_process_operation>::value: {
should_approve = true;
break;
}
case chain::operation::tag<chain::son_wallet_withdraw_process_operation>::value: {
should_approve = true;
break;
}
case chain::operation::tag<chain::sidechain_transaction_create_operation>::value: {
should_approve = true;
break;
}
case chain::operation::tag<chain::sidechain_transaction_create_operation>::value: {
should_approve = true;
break;
}
default:
should_approve = false;
}
default:
should_approve = false;
}
return should_approve;
@ -1518,11 +1528,10 @@ void sidechain_net_handler_bitcoin::handle_event(const std::string &event_data)
sed.sidechain_to = v.address;
sed.sidechain_currency = "BTC";
sed.sidechain_amount = v.out.amount;
sed.peerplays_from = database.get_global_properties().parameters.son_account();
sed.peerplays_to = addr_itr->sidechain_address_account;
asset_id_type btc_asset_id = database.get_global_properties().parameters.btc_asset();
asset_object btc_asset = btc_asset_id(database);
sed.peerplays_asset = btc_asset.amount(sed.sidechain_amount);
sed.peerplays_from = addr_itr->sidechain_address_account;
sed.peerplays_to = database.get_global_properties().parameters.son_account();
price btc_price = database.get<asset_object>(database.get_global_properties().parameters.btc_asset()).options.core_exchange_rate;
sed.peerplays_asset = asset(sed.sidechain_amount * btc_price.base.amount / btc_price.quote.amount);
sidechain_event_data_received(sed);
}
}

View file

@ -37,57 +37,97 @@ bool sidechain_net_handler_peerplays::process_proposal(const proposal_object &po
const chain::global_property_object &gpo = database.get_global_properties();
if (po.proposed_transaction.operations.size() == 1) {
int32_t op_idx_0 = po.proposed_transaction.operations[0].which();
chain::operation op = po.proposed_transaction.operations[0];
int32_t op_idx_0 = -1;
chain::operation op_obj_idx_0;
//int32_t op_idx_1 = -1;
//chain::operation op_obj_idx_1;
switch (op_idx_0) {
if (po.proposed_transaction.operations.size() >= 1) {
op_idx_0 = po.proposed_transaction.operations[0].which();
op_obj_idx_0 = po.proposed_transaction.operations[0];
}
case chain::operation::tag<chain::son_wallet_update_operation>::value: {
should_approve = true;
break;
}
if (po.proposed_transaction.operations.size() >= 2) {
//op_idx_1 = po.proposed_transaction.operations[1].which();
//op_obj_idx_1 = po.proposed_transaction.operations[1];
}
case chain::operation::tag<chain::son_wallet_deposit_process_operation>::value: {
should_approve = true;
break;
}
switch (op_idx_0) {
case chain::operation::tag<chain::son_wallet_withdraw_process_operation>::value: {
son_wallet_withdraw_id_type swwo_id = op.get<son_wallet_withdraw_process_operation>().son_wallet_withdraw_id;
const auto &idx = database.get_index_type<son_wallet_withdraw_index>().indices().get<by_id>();
const auto swwo = idx.find(swwo_id);
if (swwo != idx.end()) {
case chain::operation::tag<chain::son_wallet_update_operation>::value: {
should_approve = true;
break;
}
uint32_t swwo_block_num = swwo->block_num;
std::string swwo_peerplays_transaction_id = swwo->peerplays_transaction_id;
uint32_t swwo_op_idx = std::stoll(swwo->peerplays_uid.substr(swwo->peerplays_uid.find_last_of("-") + 1));
case chain::operation::tag<chain::son_wallet_deposit_process_operation>::value: {
son_wallet_deposit_id_type swdo_id = op_obj_idx_0.get<son_wallet_deposit_process_operation>().son_wallet_deposit_id;
const auto &idx = database.get_index_type<son_wallet_deposit_index>().indices().get<by_id>();
const auto swdo = idx.find(swdo_id);
if (swdo != idx.end()) {
const auto &block = database.fetch_block_by_number(swwo_block_num);
uint32_t swdo_block_num = swdo->block_num;
std::string swdo_sidechain_transaction_id = swdo->sidechain_transaction_id;
uint32_t swdo_op_idx = std::stoll(swdo->sidechain_uid.substr(swdo->sidechain_uid.find_last_of("-") + 1));
for (const auto &tx : block->transactions) {
if (tx.id().str() == swwo_peerplays_transaction_id) {
operation op = tx.operations[swwo_op_idx];
transfer_operation t_op = op.get<transfer_operation>();
const auto &block = database.fetch_block_by_number(swdo_block_num);
should_approve = (t_op.to == gpo.parameters.son_account()) &&
(swwo->peerplays_from == t_op.from) &&
(swwo->peerplays_asset == t_op.amount);
break;
}
for (const auto &tx : block->transactions) {
if (tx.id().str() == swdo_sidechain_transaction_id) {
operation op = tx.operations[swdo_op_idx];
transfer_operation t_op = op.get<transfer_operation>();
asset sidechain_asset = asset(swdo->sidechain_amount, fc::variant(swdo->sidechain_currency, 1).as<asset_id_type>(1));
price sidechain_asset_price = database.get<asset_object>(sidechain_asset.asset_id).options.core_exchange_rate;
asset peerplays_asset = asset(sidechain_asset.amount * sidechain_asset_price.base.amount / sidechain_asset_price.quote.amount);
should_approve = (gpo.parameters.son_account() == t_op.to) &&
(swdo->peerplays_from == t_op.from) &&
(sidechain_asset == t_op.amount) &&
(swdo->peerplays_asset == peerplays_asset);
break;
}
}
break;
}
break;
}
case chain::operation::tag<chain::sidechain_transaction_create_operation>::value: {
should_approve = true;
break;
}
case chain::operation::tag<chain::son_wallet_withdraw_process_operation>::value: {
son_wallet_withdraw_id_type swwo_id = op_obj_idx_0.get<son_wallet_withdraw_process_operation>().son_wallet_withdraw_id;
const auto &idx = database.get_index_type<son_wallet_withdraw_index>().indices().get<by_id>();
const auto swwo = idx.find(swwo_id);
if (swwo != idx.end()) {
default:
should_approve = false;
uint32_t swwo_block_num = swwo->block_num;
std::string swwo_peerplays_transaction_id = swwo->peerplays_transaction_id;
uint32_t swwo_op_idx = std::stoll(swwo->peerplays_uid.substr(swwo->peerplays_uid.find_last_of("-") + 1));
const auto &block = database.fetch_block_by_number(swwo_block_num);
for (const auto &tx : block->transactions) {
if (tx.id().str() == swwo_peerplays_transaction_id) {
operation op = tx.operations[swwo_op_idx];
transfer_operation t_op = op.get<transfer_operation>();
price asset_price = database.get<asset_object>(t_op.amount.asset_id).options.core_exchange_rate;
asset peerplays_asset = asset(t_op.amount.amount * asset_price.base.amount / asset_price.quote.amount);
should_approve = (t_op.to == gpo.parameters.son_account()) &&
(swwo->peerplays_from == t_op.from) &&
(swwo->peerplays_asset == peerplays_asset);
break;
}
}
}
break;
}
case chain::operation::tag<chain::sidechain_transaction_create_operation>::value: {
should_approve = true;
break;
}
default:
should_approve = false;
}
return should_approve;
@ -125,9 +165,6 @@ void sidechain_net_handler_peerplays::on_applied_block(const signed_block &b) {
if (transfer_op.to != plugin.database().get_global_properties().parameters.son_account()) {
continue;
}
// only bitcoin withdraws acepted for now
if (transfer_op.amount.asset_id != plugin.database().get_global_properties().parameters.btc_asset())
continue;
std::stringstream ss;
ss << "peerplays"
@ -142,11 +179,12 @@ void sidechain_net_handler_peerplays::on_applied_block(const signed_block &b) {
sed.sidechain_transaction_id = trx.id().str();
sed.sidechain_from = fc::to_string(transfer_op.from.space_id) + "." + fc::to_string(transfer_op.from.type_id) + "." + fc::to_string((uint64_t)transfer_op.from.instance);
sed.sidechain_to = fc::to_string(transfer_op.to.space_id) + "." + fc::to_string(transfer_op.to.type_id) + "." + fc::to_string((uint64_t)transfer_op.to.instance);
sed.sidechain_currency = fc::to_string(transfer_op.amount.asset_id.space_id) + "." + fc::to_string(transfer_op.amount.asset_id.type_id) + "." + fc::to_string((uint64_t)transfer_op.amount.asset_id.instance); //transfer_op.amount.asset_id(database).symbol;
sed.sidechain_currency = fc::to_string(transfer_op.amount.asset_id.space_id) + "." + fc::to_string(transfer_op.amount.asset_id.type_id) + "." + fc::to_string((uint64_t)transfer_op.amount.asset_id.instance);
sed.sidechain_amount = transfer_op.amount.amount;
sed.peerplays_from = transfer_op.from;
sed.peerplays_to = transfer_op.to;
sed.peerplays_asset = transfer_op.amount;
price asset_price = database.get<asset_object>(transfer_op.amount.asset_id).options.core_exchange_rate;
sed.peerplays_asset = asset(transfer_op.amount.amount * asset_price.base.amount / asset_price.quote.amount);
sidechain_event_data_received(sed);
}
}