diff --git a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp index ca46c6d56..be34f7cab 100644 --- a/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp +++ b/libraries/plugins/peerplays_sidechain/peerplays_sidechain_plugin.cpp @@ -428,10 +428,6 @@ bool peerplays_sidechain_plugin_impl::is_valid_son_proposal(const chain::proposa return true; } - if (op_idx_0 == chain::operation::tag::value) { - return true; - } - if (op_idx_0 == chain::operation::tag::value) { return true; } @@ -440,9 +436,14 @@ bool peerplays_sidechain_plugin_impl::is_valid_son_proposal(const chain::proposa int32_t op_idx_1 = proposal.proposed_transaction.operations[1].which(); if ((op_idx_0 == chain::operation::tag::value) && - (op_idx_1 == chain::operation::tag::value)) { + (op_idx_1 == chain::operation::tag::value)) { return true; } + if ((op_idx_0 == chain::operation::tag::value) && + (op_idx_1 == chain::operation::tag::value)) { + return true; + } + } return false; diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp index b43d6097f..be69f699c 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler.cpp @@ -68,7 +68,7 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_ const chain::global_property_object &gpo = database.get_global_properties(); // Deposit request - if ((sed.peerplays_to == gpo.parameters.son_account()) && (sed.sidechain_currency.compare("1.3.0") != 0)) { + if ((sed.peerplays_from == gpo.parameters.son_account()) && (sed.sidechain_currency != fc::variant(gpo.parameters.btc_asset(), 1).as(1))) { for (son_id_type son_id : plugin.get_sons()) { if (plugin.is_active_son(son_id)) { @@ -102,7 +102,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.compare("1.3.0") == 0)) { + if ((sed.peerplays_to == gpo.parameters.son_account()) && (sed.sidechain_currency == fc::variant(gpo.parameters.btc_asset(), 1).as(1))) { // BTC Payout only (for now) const auto &sidechain_addresses_idx = database.get_index_type().indices().get(); const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sed.peerplays_from, sidechain_type::bitcoin)); @@ -124,7 +124,7 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_ 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) + op.withdraw_amount = sed.peerplays_asset.amount; // BTC payout only (for now) signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(son_id), op); try { @@ -166,16 +166,16 @@ void sidechain_net_handler::process_deposits() { swdp_op.payer = gpo.parameters.son_account(); swdp_op.son_wallet_deposit_id = swdo.id; - transfer_operation t_op; - t_op.fee = asset(2000000); - t_op.from = swdo.peerplays_to; // gpo.parameters.son_account() - t_op.to = swdo.peerplays_from; - t_op.amount = swdo.peerplays_asset; + 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; 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(t_op); + proposal_op.proposed_ops.emplace_back(i_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); @@ -215,9 +215,16 @@ 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); + 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); 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); diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp index cc23610da..1e0c01914 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp @@ -1410,9 +1410,11 @@ 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 = addr_itr->sidechain_address_account; - sed.peerplays_to = database.get_global_properties().parameters.son_account(); - sed.peerplays_asset = asset(sed.sidechain_amount / 1000); // For Bitcoin, the exchange rate is 1:1, for others, get the exchange rate from market + 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); sidechain_event_data_received(sed); } } diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp index 3f6b777d9..5d0315a5f 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_peerplays.cpp @@ -61,6 +61,9 @@ 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" @@ -78,8 +81,7 @@ void sidechain_net_handler_peerplays::on_applied_block(const signed_block &b) { sed.sidechain_amount = transfer_op.amount.amount; sed.peerplays_from = transfer_op.from; sed.peerplays_to = transfer_op.to; - // We should calculate exchange rate between CORE/TEST and other Peerplays asset - sed.peerplays_asset = asset(transfer_op.amount.amount / transfer_op.amount.asset_id(database).options.core_exchange_rate.quote.amount); + sed.peerplays_asset = transfer_op.amount; sidechain_event_data_received(sed); } }