Refactor primary wallet recreation
This commit is contained in:
parent
d048873601
commit
f6c1da53df
8 changed files with 31 additions and 68 deletions
|
|
@ -28,7 +28,8 @@ void_result update_son_wallet_evaluator::do_evaluate(const son_wallet_update_ope
|
|||
const auto& idx = db().get_index_type<son_wallet_index>().indices().get<by_id>();
|
||||
FC_ASSERT( idx.find(op.son_wallet_id) != idx.end() );
|
||||
auto itr = idx.find(op.son_wallet_id);
|
||||
//FC_ASSERT( itr.addresses[op.sidechain] == "", "Sidechain wallet address already set");
|
||||
FC_ASSERT( itr->addresses.find(peerplays_sidechain::sidechain_type::bitcoin) == itr->addresses.end() ||
|
||||
itr->addresses.at(peerplays_sidechain::sidechain_type::bitcoin).empty(), "Sidechain wallet address already set");
|
||||
return void_result();
|
||||
} FC_CAPTURE_AND_RETHROW( (op) ) }
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class peerplays_sidechain_plugin : public graphene::app::plugin
|
|||
son_id_type get_son_id();
|
||||
son_object get_son_object();
|
||||
bool is_active_son();
|
||||
std::map<chain::public_key_type, fc::ecc::private_key> get_private_keys();
|
||||
std::map<chain::public_key_type, fc::ecc::private_key>& get_private_keys();
|
||||
};
|
||||
|
||||
} } //graphene::peerplays_sidechain
|
||||
|
|
|
|||
|
|
@ -20,8 +20,7 @@ public:
|
|||
|
||||
void sidechain_event_data_received(const sidechain_event_data& sed);
|
||||
|
||||
virtual son_wallet_update_operation recreate_primary_wallet() = 0;
|
||||
virtual string recreate_primary_wallet(const vector<string>& participants) = 0;
|
||||
virtual void recreate_primary_wallet() = 0;
|
||||
|
||||
protected:
|
||||
peerplays_sidechain_plugin& plugin;
|
||||
|
|
|
|||
|
|
@ -60,8 +60,7 @@ public:
|
|||
sidechain_net_handler_bitcoin(peerplays_sidechain_plugin& _plugin, const boost::program_options::variables_map& options);
|
||||
virtual ~sidechain_net_handler_bitcoin();
|
||||
|
||||
son_wallet_update_operation recreate_primary_wallet();
|
||||
string recreate_primary_wallet(const vector<string>& participants);
|
||||
void recreate_primary_wallet();
|
||||
|
||||
bool connection_is_not_defined() const;
|
||||
|
||||
|
|
|
|||
|
|
@ -15,9 +15,8 @@ public:
|
|||
sidechain_net_manager(peerplays_sidechain_plugin& _plugin);
|
||||
virtual ~sidechain_net_manager();
|
||||
|
||||
std::unique_ptr<sidechain_net_handler> create_handler(peerplays_sidechain::sidechain_type sidechain, const boost::program_options::variables_map& options);
|
||||
signed_transaction recreate_primary_wallet();
|
||||
string recreate_primary_wallet(peerplays_sidechain::sidechain_type sidechain, const vector<string>& participants);
|
||||
bool create_handler(peerplays_sidechain::sidechain_type sidechain, const boost::program_options::variables_map& options);
|
||||
void recreate_primary_wallet();
|
||||
private:
|
||||
peerplays_sidechain_plugin& plugin;
|
||||
graphene::chain::database& database;
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ class peerplays_sidechain_plugin_impl
|
|||
son_id_type get_son_id();
|
||||
son_object get_son_object();
|
||||
bool is_active_son();
|
||||
std::map<chain::public_key_type, fc::ecc::private_key> get_private_keys();
|
||||
std::map<chain::public_key_type, fc::ecc::private_key>& get_private_keys();
|
||||
|
||||
void schedule_heartbeat_loop();
|
||||
void heartbeat_loop();
|
||||
|
|
@ -149,7 +149,7 @@ void peerplays_sidechain_plugin_impl::plugin_initialize(const boost::program_opt
|
|||
options.count( "bitcoin-node-rpc-user" ) && options.count( "bitcoin-node-rpc-password" ) &&
|
||||
options.count( "bitcoin-address" ) && options.count( "bitcoin-public-key" ) && options.count( "bitcoin-private-key" );
|
||||
if (config_ready_bitcoin) {
|
||||
std::unique_ptr<sidechain_net_handler> h = net_manager->create_handler(sidechain_type::bitcoin, options);
|
||||
net_manager->create_handler(sidechain_type::bitcoin, options);
|
||||
ilog("Bitcoin sidechain handler created");
|
||||
} else {
|
||||
wlog("Haven't set up Bitcoin sidechain parameters");
|
||||
|
|
@ -225,7 +225,7 @@ bool peerplays_sidechain_plugin_impl::is_active_son()
|
|||
return (it != active_son_ids.end());
|
||||
}
|
||||
|
||||
std::map<chain::public_key_type, fc::ecc::private_key> peerplays_sidechain_plugin_impl::get_private_keys()
|
||||
std::map<chain::public_key_type, fc::ecc::private_key>& peerplays_sidechain_plugin_impl::get_private_keys()
|
||||
{
|
||||
return _private_keys;
|
||||
}
|
||||
|
|
@ -337,20 +337,7 @@ void peerplays_sidechain_plugin_impl::create_son_down_proposals()
|
|||
|
||||
void peerplays_sidechain_plugin_impl::recreate_primary_wallet()
|
||||
{
|
||||
chain::database& d = plugin.database();
|
||||
signed_transaction trx = net_manager->recreate_primary_wallet();
|
||||
auto dyn_props = d.get_dynamic_global_properties();
|
||||
trx.set_reference_block( dyn_props.head_block_id );
|
||||
trx.set_expiration( d.head_block_time() + d.get_global_properties().parameters.maximum_time_until_expiration );
|
||||
d.current_fee_schedule().set_fee( trx.operations.back() );
|
||||
|
||||
trx.sign(_private_keys.begin()->second, d.get_chain_id());
|
||||
|
||||
try {
|
||||
d.push_transaction(trx);
|
||||
} catch (fc::exception e) {
|
||||
ilog("peerplays_sidechain_plugin_impl: sending son wallet update operation failed with exception ${e}",("e", e.what()));
|
||||
}
|
||||
net_manager->recreate_primary_wallet();
|
||||
}
|
||||
|
||||
void peerplays_sidechain_plugin_impl::process_deposits() {
|
||||
|
|
@ -494,7 +481,7 @@ bool peerplays_sidechain_plugin::is_active_son()
|
|||
return my->is_active_son();
|
||||
}
|
||||
|
||||
std::map<chain::public_key_type, fc::ecc::private_key> peerplays_sidechain_plugin::get_private_keys()
|
||||
std::map<chain::public_key_type, fc::ecc::private_key>& peerplays_sidechain_plugin::get_private_keys()
|
||||
{
|
||||
return my->get_private_keys();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(peerplays_sidechain
|
|||
sidechain_net_handler_bitcoin::~sidechain_net_handler_bitcoin() {
|
||||
}
|
||||
|
||||
son_wallet_update_operation sidechain_net_handler_bitcoin::recreate_primary_wallet() {
|
||||
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()) {
|
||||
|
|
@ -275,23 +275,25 @@ son_wallet_update_operation sidechain_net_handler_bitcoin::recreate_primary_wall
|
|||
if( pt.count( "error" ) && pt.get_child( "error" ).empty() ) {
|
||||
ilog(__FUNCTION__);
|
||||
|
||||
std::stringstream res;
|
||||
boost::property_tree::json_parser::write_json(res, pt.get_child("result"));
|
||||
|
||||
son_wallet_update_operation op;
|
||||
op.payer = plugin.get_son_object().son_account;
|
||||
op.son_wallet_id = (*obj).id;
|
||||
op.sidechain = sidechain_type::bitcoin;
|
||||
op.address = ss.str();
|
||||
op.address = res.str();
|
||||
|
||||
return op;
|
||||
signed_transaction trx = database.create_signed_transaction(plugin.get_private_keys().begin()->second, op);
|
||||
|
||||
try {
|
||||
database.push_transaction(trx);
|
||||
} catch (fc::exception e) {
|
||||
ilog("sidechain_net_handler_bitcoin: sending son wallet update operation failed with exception ${e}",("e", e.what()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
string sidechain_net_handler_bitcoin::recreate_primary_wallet( const vector<string>& participants ) {
|
||||
ilog(__FUNCTION__);
|
||||
string result = create_multisignature_wallet(participants);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool sidechain_net_handler_bitcoin::connection_is_not_defined() const
|
||||
|
|
|
|||
|
|
@ -17,15 +17,16 @@ sidechain_net_manager::~sidechain_net_manager() {
|
|||
ilog(__FUNCTION__);
|
||||
}
|
||||
|
||||
std::unique_ptr<sidechain_net_handler> sidechain_net_manager::create_handler(peerplays_sidechain::sidechain_type sidechain, const boost::program_options::variables_map& options) {
|
||||
bool sidechain_net_manager::create_handler(peerplays_sidechain::sidechain_type sidechain, const boost::program_options::variables_map& options) {
|
||||
ilog(__FUNCTION__);
|
||||
|
||||
std::unique_ptr<sidechain_net_handler> ret_val = nullptr;
|
||||
bool ret_val = false;
|
||||
|
||||
switch (sidechain) {
|
||||
case sidechain_type::bitcoin: {
|
||||
ret_val = std::unique_ptr<sidechain_net_handler>(new sidechain_net_handler_bitcoin(plugin, options));
|
||||
net_handlers.push_back(std::move(ret_val));
|
||||
std::unique_ptr<sidechain_net_handler> h = std::unique_ptr<sidechain_net_handler>(new sidechain_net_handler_bitcoin(plugin, options));
|
||||
net_handlers.push_back(std::move(h));
|
||||
ret_val = true;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
|
@ -35,35 +36,10 @@ std::unique_ptr<sidechain_net_handler> sidechain_net_manager::create_handler(pee
|
|||
return ret_val;
|
||||
}
|
||||
|
||||
signed_transaction sidechain_net_manager::recreate_primary_wallet() {
|
||||
ilog(__FUNCTION__);
|
||||
|
||||
signed_transaction trx = {};
|
||||
|
||||
const auto& idx = database.get_index_type<son_wallet_index>().indices().get<by_id>();
|
||||
auto swo = idx.rbegin();
|
||||
|
||||
void sidechain_net_manager::recreate_primary_wallet() {
|
||||
for ( size_t i = 0; i < net_handlers.size(); i++ ) {
|
||||
son_wallet_update_operation op = net_handlers.at(i)->recreate_primary_wallet();
|
||||
|
||||
if (swo != idx.rend()) {
|
||||
if (op.son_wallet_id == swo->id) {
|
||||
trx.operations.push_back(op);
|
||||
}
|
||||
}
|
||||
net_handlers.at(i)->recreate_primary_wallet();
|
||||
}
|
||||
|
||||
return trx;
|
||||
}
|
||||
|
||||
string sidechain_net_manager::recreate_primary_wallet(peerplays_sidechain::sidechain_type sidechain, const vector<string>& participants) {
|
||||
ilog(__FUNCTION__);
|
||||
for ( size_t i = 0; i < net_handlers.size(); i++ ) {
|
||||
if (net_handlers.at(i)->get_sidechain() == sidechain) {
|
||||
return net_handlers.at(i)->recreate_primary_wallet(participants);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
} } // graphene::peerplays_sidechain
|
||||
|
|
|
|||
Loading…
Reference in a new issue