[SON-349, SON-350] Delay BTC asset issue/reserve until tx confirmed on sidchain
This commit is contained in:
parent
6a8cd25878
commit
c77c19563c
9 changed files with 97 additions and 1 deletions
|
|
@ -34,6 +34,7 @@ public:
|
|||
void process_withdrawals();
|
||||
void process_sidechain_transactions();
|
||||
void send_sidechain_transactions();
|
||||
void process_sidechain_transaction_results();
|
||||
|
||||
virtual bool process_proposal(const proposal_object &po) = 0;
|
||||
virtual void process_primary_wallet() = 0;
|
||||
|
|
@ -41,6 +42,7 @@ public:
|
|||
virtual bool process_withdrawal(const son_wallet_withdraw_object &swwo) = 0;
|
||||
virtual std::string process_sidechain_transaction(const sidechain_transaction_object &sto) = 0;
|
||||
virtual std::string send_sidechain_transaction(const sidechain_transaction_object &sto) = 0;
|
||||
virtual std::string process_sidechain_transaction_result(const sidechain_transaction_object &sto) = 0;
|
||||
|
||||
protected:
|
||||
peerplays_sidechain_plugin &plugin;
|
||||
|
|
|
|||
|
|
@ -91,6 +91,7 @@ public:
|
|||
bool process_withdrawal(const son_wallet_withdraw_object &swwo);
|
||||
std::string process_sidechain_transaction(const sidechain_transaction_object &sto);
|
||||
std::string send_sidechain_transaction(const sidechain_transaction_object &sto);
|
||||
std::string process_sidechain_transaction_result(const sidechain_transaction_object &sto);
|
||||
|
||||
private:
|
||||
std::string ip;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@ public:
|
|||
bool process_withdrawal(const son_wallet_withdraw_object &swwo);
|
||||
std::string process_sidechain_transaction(const sidechain_transaction_object &sto);
|
||||
std::string send_sidechain_transaction(const sidechain_transaction_object &sto);
|
||||
std::string process_sidechain_transaction_result(const sidechain_transaction_object &sto);
|
||||
|
||||
private:
|
||||
void on_applied_block(const signed_block &b);
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ public:
|
|||
void process_withdrawals();
|
||||
void process_sidechain_transactions();
|
||||
void send_sidechain_transactions();
|
||||
void process_sidechain_transaction_results();
|
||||
|
||||
private:
|
||||
peerplays_sidechain_plugin &plugin;
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ public:
|
|||
void process_withdrawals();
|
||||
void process_sidechain_transactions();
|
||||
void send_sidechain_transactions();
|
||||
void process_sidechain_transaction_results();
|
||||
|
||||
private:
|
||||
peerplays_sidechain_plugin &plugin;
|
||||
|
|
@ -401,6 +402,8 @@ void peerplays_sidechain_plugin_impl::son_processing() {
|
|||
process_sidechain_transactions();
|
||||
|
||||
send_sidechain_transactions();
|
||||
|
||||
process_sidechain_transaction_results();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -586,6 +589,10 @@ void peerplays_sidechain_plugin_impl::send_sidechain_transactions() {
|
|||
net_manager->send_sidechain_transactions();
|
||||
}
|
||||
|
||||
void peerplays_sidechain_plugin_impl::process_sidechain_transaction_results() {
|
||||
net_manager->process_sidechain_transaction_results();
|
||||
}
|
||||
|
||||
void peerplays_sidechain_plugin_impl::on_applied_block(const signed_block &b) {
|
||||
if (first_block_skipped) {
|
||||
schedule_son_processing();
|
||||
|
|
|
|||
|
|
@ -366,7 +366,6 @@ void sidechain_net_handler::process_sidechain_transactions() {
|
|||
std::for_each(idx_range.first, idx_range.second, [&](const sidechain_transaction_object &sto) {
|
||||
ilog("Sidechain transaction to process: ${sto}", ("sto", sto.id));
|
||||
|
||||
bool complete = false;
|
||||
std::string processed_sidechain_tx = process_sidechain_transaction(sto);
|
||||
|
||||
if (processed_sidechain_tx.empty()) {
|
||||
|
|
@ -422,6 +421,37 @@ void sidechain_net_handler::send_sidechain_transactions() {
|
|||
});
|
||||
}
|
||||
|
||||
void sidechain_net_handler::process_sidechain_transaction_results() {
|
||||
const auto &idx = database.get_index_type<sidechain_transaction_index>().indices().get<by_sidechain_and_complete_and_sent>();
|
||||
const auto &idx_range = idx.equal_range(std::make_tuple(sidechain, true, true));
|
||||
|
||||
std::for_each(idx_range.first, idx_range.second, [&](const sidechain_transaction_object &sto) {
|
||||
ilog("Sidechain transaction to send: ${sto}", ("sto", sto.id));
|
||||
|
||||
std::string sidechain_transaction = process_sidechain_transaction_result(sto);
|
||||
|
||||
if (sidechain_transaction.empty()) {
|
||||
wlog("Sidechain transaction not sent: ${sto}", ("sto", sto.id));
|
||||
return;
|
||||
}
|
||||
|
||||
sidechain_transaction_send_operation sts_op;
|
||||
sts_op.payer = plugin.get_current_son_object().son_account;
|
||||
sts_op.sidechain_transaction_id = sto.id;
|
||||
sts_op.sidechain_transaction = sidechain_transaction;
|
||||
|
||||
signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), sts_op);
|
||||
trx.validate();
|
||||
try {
|
||||
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) {
|
||||
elog("Sending proposal for sidechain transaction send operation failed with exception ${e}", ("e", e.what()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
bool sidechain_net_handler::process_proposal(const proposal_object &po) {
|
||||
FC_ASSERT(false, "process_proposal not implemented");
|
||||
}
|
||||
|
|
@ -446,4 +476,8 @@ std::string sidechain_net_handler::send_sidechain_transaction(const sidechain_tr
|
|||
FC_ASSERT(false, "send_sidechain_transaction not implemented");
|
||||
}
|
||||
|
||||
std::string sidechain_net_handler::process_sidechain_transaction_result(const sidechain_transaction_object &sto) {
|
||||
FC_ASSERT(false, "process_sidechain_transaction_result not implemented");
|
||||
}
|
||||
|
||||
}} // namespace graphene::peerplays_sidechain
|
||||
|
|
|
|||
|
|
@ -1238,6 +1238,46 @@ std::string sidechain_net_handler_bitcoin::send_sidechain_transaction(const side
|
|||
return send_transaction(sto);
|
||||
}
|
||||
|
||||
std::string sidechain_net_handler_bitcoin::process_sidechain_transaction_result(const sidechain_transaction_object &sto) {
|
||||
|
||||
if (sto.sidechain_transaction.empty()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string tx_str = bitcoin_client->gettransaction(sto.sidechain_transaction);
|
||||
std::stringstream tx_ss(tx_str);
|
||||
boost::property_tree::ptree tx_json;
|
||||
boost::property_tree::read_json(tx_ss, tx_json);
|
||||
|
||||
if ((tx_json.count("error")) && (!tx_json.get_child("error").empty())) {
|
||||
return "";
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
if (sto.object_id.is<son_wallet_deposit_id_type>()) {
|
||||
}
|
||||
|
||||
if (sto.object_id.is<son_wallet_withdraw_id_type>()) {
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string sidechain_net_handler_bitcoin::create_primary_wallet_transaction() {
|
||||
const auto &swi = database.get_index_type<son_wallet_index>().indices().get<by_id>();
|
||||
const auto &active_sw = swi.rbegin();
|
||||
|
|
|
|||
|
|
@ -149,6 +149,10 @@ std::string sidechain_net_handler_peerplays::send_sidechain_transaction(const si
|
|||
return sto.transaction;
|
||||
}
|
||||
|
||||
std::string sidechain_net_handler_peerplays::process_sidechain_transaction_result(const sidechain_transaction_object &sto) {
|
||||
return sto.transaction;
|
||||
}
|
||||
|
||||
void sidechain_net_handler_peerplays::on_applied_block(const signed_block &b) {
|
||||
for (const auto &trx : b.transactions) {
|
||||
size_t operation_index = -1;
|
||||
|
|
|
|||
|
|
@ -75,4 +75,10 @@ void sidechain_net_manager::send_sidechain_transactions() {
|
|||
}
|
||||
}
|
||||
|
||||
void sidechain_net_manager::process_sidechain_transaction_results() {
|
||||
for (size_t i = 0; i < net_handlers.size(); i++) {
|
||||
net_handlers.at(i)->process_sidechain_transaction_results();
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace graphene::peerplays_sidechain
|
||||
|
|
|
|||
Loading…
Reference in a new issue