Integrate PW wallet fund moving
This commit is contained in:
parent
71c9483798
commit
e2ef5a6db1
4 changed files with 45 additions and 34 deletions
|
|
@ -26,7 +26,7 @@ public:
|
|||
|
||||
private:
|
||||
|
||||
void on_block_applied(const signed_block& b);
|
||||
void on_applied_block(const signed_block& b);
|
||||
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -63,8 +63,8 @@ class peerplays_sidechain_plugin_impl
|
|||
std::set<chain::son_id_type> _sons;
|
||||
fc::future<void> _heartbeat_task;
|
||||
|
||||
void on_block_applied( const signed_block& b );
|
||||
void on_objects_new(const vector<object_id_type>& new_object_ids);
|
||||
void on_applied_block( const signed_block& b );
|
||||
void on_new_objects(const vector<object_id_type>& new_object_ids);
|
||||
|
||||
};
|
||||
|
||||
|
|
@ -162,8 +162,8 @@ void peerplays_sidechain_plugin_impl::plugin_initialize(const boost::program_opt
|
|||
throw;
|
||||
}
|
||||
|
||||
plugin.database().applied_block.connect( [&] (const signed_block& b) { on_block_applied(b); } );
|
||||
plugin.database().new_objects.connect( [&] (const vector<object_id_type>& ids, const flat_set<account_id_type>& impacted_accounts) { on_objects_new(ids); } );
|
||||
plugin.database().applied_block.connect( [&] (const signed_block& b) { on_applied_block(b); } );
|
||||
plugin.database().new_objects.connect( [&] (const vector<object_id_type>& ids, const flat_set<account_id_type>& impacted_accounts) { on_new_objects(ids); } );
|
||||
|
||||
net_manager = std::unique_ptr<sidechain_net_manager>(new sidechain_net_manager(plugin));
|
||||
|
||||
|
|
@ -396,7 +396,7 @@ void peerplays_sidechain_plugin_impl::process_withdrawals()
|
|||
net_manager->process_withdrawals();
|
||||
}
|
||||
|
||||
void peerplays_sidechain_plugin_impl::on_block_applied( const signed_block& b )
|
||||
void peerplays_sidechain_plugin_impl::on_applied_block( const signed_block& b )
|
||||
{
|
||||
chain::database& d = plugin.database();
|
||||
const chain::global_property_object& gpo = d.get_global_properties();
|
||||
|
|
@ -424,7 +424,7 @@ void peerplays_sidechain_plugin_impl::on_block_applied( const signed_block& b )
|
|||
}
|
||||
}
|
||||
|
||||
void peerplays_sidechain_plugin_impl::on_objects_new(const vector<object_id_type>& new_object_ids)
|
||||
void peerplays_sidechain_plugin_impl::on_new_objects(const vector<object_id_type>& new_object_ids)
|
||||
{
|
||||
|
||||
auto approve_proposal = [ & ]( const chain::son_id_type& son_id, const chain::proposal_id_type& proposal_id )
|
||||
|
|
|
|||
|
|
@ -418,12 +418,12 @@ sidechain_net_handler_bitcoin::~sidechain_net_handler_bitcoin() {
|
|||
}
|
||||
|
||||
void sidechain_net_handler_bitcoin::recreate_primary_wallet() {
|
||||
const auto& idx_swi = database.get_index_type<son_wallet_index>().indices().get<by_id>();
|
||||
auto obj = idx_swi.rbegin();
|
||||
if (obj != idx_swi.rend()) {
|
||||
const auto& swi = database.get_index_type<son_wallet_index>().indices().get<by_id>();
|
||||
const auto &active_sw = swi.rbegin();
|
||||
if (active_sw != swi.rend()) {
|
||||
|
||||
if ((obj->addresses.find(sidechain_type::bitcoin) == obj->addresses.end()) ||
|
||||
(obj->addresses.at(sidechain_type::bitcoin).empty())) {
|
||||
if ((active_sw->addresses.find(sidechain_type::bitcoin) == active_sw->addresses.end()) ||
|
||||
(active_sw->addresses.at(sidechain_type::bitcoin).empty())) {
|
||||
|
||||
const chain::global_property_object& gpo = database.get_global_properties();
|
||||
|
||||
|
|
@ -436,35 +436,46 @@ void sidechain_net_handler_bitcoin::recreate_primary_wallet() {
|
|||
|
||||
ilog(reply_str);
|
||||
|
||||
std::stringstream ss(reply_str);
|
||||
boost::property_tree::ptree pt;
|
||||
boost::property_tree::read_json( ss, pt );
|
||||
if( pt.count( "error" ) && pt.get_child( "error" ).empty() ) {
|
||||
std::stringstream active_pw_ss(reply_str);
|
||||
boost::property_tree::ptree active_pw_pt;
|
||||
boost::property_tree::read_json( active_pw_ss, active_pw_pt );
|
||||
if( active_pw_pt.count( "error" ) && active_pw_pt.get_child( "error" ).empty() ) {
|
||||
|
||||
std::stringstream res;
|
||||
boost::property_tree::json_parser::write_json(res, pt.get_child("result"));
|
||||
boost::property_tree::json_parser::write_json(res, active_pw_pt.get_child("result"));
|
||||
|
||||
son_wallet_update_operation op;
|
||||
op.payer = GRAPHENE_SON_ACCOUNT;
|
||||
op.son_wallet_id = (*obj).id;
|
||||
op.son_wallet_id = (*active_sw).id;
|
||||
op.sidechain = sidechain_type::bitcoin;
|
||||
op.address = res.str();
|
||||
|
||||
for (son_id_type son_id : plugin.get_sons()) {
|
||||
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_wrapper( 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 );
|
||||
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( 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);
|
||||
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){
|
||||
ilog("sidechain_net_handler: sending proposal for son wallet update operation failed with exception ${e}",("e", e.what()));
|
||||
}
|
||||
signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), proposal_op);
|
||||
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){
|
||||
ilog("sidechain_net_handler: sending proposal for son wallet update operation failed with exception ${e}",("e", e.what()));
|
||||
return;
|
||||
}
|
||||
|
||||
const auto &prev_sw = std::next(active_sw);
|
||||
if (prev_sw != swi.rend()) {
|
||||
std::stringstream prev_sw_ss(prev_sw->addresses.at(sidechain_type::bitcoin));
|
||||
boost::property_tree::ptree prev_sw_pt;
|
||||
boost::property_tree::read_json( prev_sw_ss, prev_sw_pt );
|
||||
|
||||
std::string active_pw_address = active_pw_pt.get_child("result").get<std::string>("address");
|
||||
std::string prev_pw_address = prev_sw_pt.get<std::string>("address");
|
||||
|
||||
transfer_all_btc(prev_pw_address, active_pw_address);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ namespace graphene { namespace peerplays_sidechain {
|
|||
sidechain_net_handler_peerplays::sidechain_net_handler_peerplays(peerplays_sidechain_plugin& _plugin, const boost::program_options::variables_map& options) :
|
||||
sidechain_net_handler(_plugin, options) {
|
||||
sidechain = sidechain_type::peerplays;
|
||||
plugin.database().applied_block.connect( [&] (const signed_block& b) { on_block_applied(b); } );
|
||||
plugin.database().applied_block.connect( [&] (const signed_block& b) { on_applied_block(b); } );
|
||||
}
|
||||
|
||||
sidechain_net_handler_peerplays::~sidechain_net_handler_peerplays() {
|
||||
|
|
@ -61,7 +61,7 @@ std::string sidechain_net_handler_peerplays::send_transaction( const std::string
|
|||
return "";
|
||||
}
|
||||
|
||||
void sidechain_net_handler_peerplays::on_block_applied(const signed_block& b) {
|
||||
void sidechain_net_handler_peerplays::on_applied_block(const signed_block& b) {
|
||||
for (const auto& trx: b.transactions) {
|
||||
size_t operation_index = -1;
|
||||
for (auto op: trx.operations) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue