Send RPC command to bitcoin node to recreate multisig wallet
This commit is contained in:
parent
23cb5310b0
commit
c25108f228
7 changed files with 78 additions and 2 deletions
|
|
@ -14,8 +14,11 @@ public:
|
||||||
sidechain_net_handler(std::shared_ptr<graphene::chain::database> db, const boost::program_options::variables_map& options);
|
sidechain_net_handler(std::shared_ptr<graphene::chain::database> db, const boost::program_options::variables_map& options);
|
||||||
virtual ~sidechain_net_handler();
|
virtual ~sidechain_net_handler();
|
||||||
|
|
||||||
|
graphene::peerplays_sidechain::sidechain_type get_sidechain();
|
||||||
std::vector<std::string> get_sidechain_addresses();
|
std::vector<std::string> get_sidechain_addresses();
|
||||||
|
|
||||||
|
virtual void recreate_primary_wallet(const vector<string>& participants) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::shared_ptr<graphene::chain::database> database;
|
std::shared_ptr<graphene::chain::database> database;
|
||||||
graphene::peerplays_sidechain::sidechain_type sidechain;
|
graphene::peerplays_sidechain::sidechain_type sidechain;
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ public:
|
||||||
bool receive_mempool_entry_tx( const std::string& tx_hash );
|
bool receive_mempool_entry_tx( const std::string& tx_hash );
|
||||||
uint64_t receive_estimated_fee();
|
uint64_t receive_estimated_fee();
|
||||||
void send_btc_tx( const std::string& tx_hex );
|
void send_btc_tx( const std::string& tx_hex );
|
||||||
|
std::string add_multisig_address( const std::vector<std::string> public_keys );
|
||||||
bool connection_is_not_defined() const;
|
bool connection_is_not_defined() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
@ -59,6 +60,8 @@ public:
|
||||||
sidechain_net_handler_bitcoin(std::shared_ptr<graphene::chain::database> db, const boost::program_options::variables_map& options);
|
sidechain_net_handler_bitcoin(std::shared_ptr<graphene::chain::database> db, const boost::program_options::variables_map& options);
|
||||||
virtual ~sidechain_net_handler_bitcoin();
|
virtual ~sidechain_net_handler_bitcoin();
|
||||||
|
|
||||||
|
void recreate_primary_wallet(const vector<string>& participants);
|
||||||
|
|
||||||
bool connection_is_not_defined() const;
|
bool connection_is_not_defined() const;
|
||||||
|
|
||||||
std::string create_multisignature_wallet( const std::vector<std::string> public_keys );
|
std::string create_multisignature_wallet( const std::vector<std::string> public_keys );
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,7 @@ public:
|
||||||
virtual ~sidechain_net_manager();
|
virtual ~sidechain_net_manager();
|
||||||
|
|
||||||
bool create_handler(peerplays_sidechain::sidechain_type sidechain, const boost::program_options::variables_map& options);
|
bool create_handler(peerplays_sidechain::sidechain_type sidechain, const boost::program_options::variables_map& options);
|
||||||
|
void recreate_primary_wallet(peerplays_sidechain::sidechain_type sidechain, const vector<string>& participants);
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<graphene::chain::database> database;
|
std::shared_ptr<graphene::chain::database> database;
|
||||||
std::vector<std::unique_ptr<sidechain_net_handler>> net_handlers;
|
std::vector<std::unique_ptr<sidechain_net_handler>> net_handlers;
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,10 @@
|
||||||
|
|
||||||
#include <fc/log/logger.hpp>
|
#include <fc/log/logger.hpp>
|
||||||
#include <fc/smart_ref_impl.hpp>
|
#include <fc/smart_ref_impl.hpp>
|
||||||
#include <graphene/chain/sidechain_address_object.hpp>
|
|
||||||
#include <graphene/chain/proposal_object.hpp>
|
#include <graphene/chain/proposal_object.hpp>
|
||||||
|
#include <graphene/chain/sidechain_address_object.hpp>
|
||||||
|
#include <graphene/chain/son_wallet_object.hpp>
|
||||||
#include <graphene/peerplays_sidechain/sidechain_net_manager.hpp>
|
#include <graphene/peerplays_sidechain/sidechain_net_manager.hpp>
|
||||||
#include <graphene/utilities/key_conversion.hpp>
|
#include <graphene/utilities/key_conversion.hpp>
|
||||||
|
|
||||||
|
|
@ -25,13 +27,16 @@ class peerplays_sidechain_plugin_impl
|
||||||
boost::program_options::options_description& cfg);
|
boost::program_options::options_description& cfg);
|
||||||
void plugin_initialize(const boost::program_options::variables_map& options);
|
void plugin_initialize(const boost::program_options::variables_map& options);
|
||||||
void plugin_startup();
|
void plugin_startup();
|
||||||
|
|
||||||
void schedule_heartbeat_loop();
|
void schedule_heartbeat_loop();
|
||||||
void heartbeat_loop();
|
void heartbeat_loop();
|
||||||
void schedule_son_event_processing_loop();
|
void schedule_son_event_processing_loop();
|
||||||
void son_event_processing_loop();
|
void son_event_processing_loop();
|
||||||
|
void recreate_primary_wallet();
|
||||||
chain::proposal_create_operation create_son_down_proposal(chain::son_id_type son_id, fc::time_point_sec last_active_ts);
|
chain::proposal_create_operation create_son_down_proposal(chain::son_id_type son_id, fc::time_point_sec last_active_ts);
|
||||||
void on_block_applied( const signed_block& b );
|
void on_block_applied( const signed_block& b );
|
||||||
void on_objects_new(const vector<object_id_type>& new_object_ids);
|
void on_objects_new(const vector<object_id_type>& new_object_ids);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
peerplays_sidechain_plugin& plugin;
|
peerplays_sidechain_plugin& plugin;
|
||||||
|
|
||||||
|
|
@ -43,6 +48,7 @@ class peerplays_sidechain_plugin_impl
|
||||||
std::set<chain::son_id_type> _sons;
|
std::set<chain::son_id_type> _sons;
|
||||||
fc::future<void> _heartbeat_task;
|
fc::future<void> _heartbeat_task;
|
||||||
fc::future<void> _son_event_processing_task;
|
fc::future<void> _son_event_processing_task;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
peerplays_sidechain_plugin_impl::peerplays_sidechain_plugin_impl(peerplays_sidechain_plugin& _plugin) :
|
peerplays_sidechain_plugin_impl::peerplays_sidechain_plugin_impl(peerplays_sidechain_plugin& _plugin) :
|
||||||
|
|
@ -245,6 +251,26 @@ void peerplays_sidechain_plugin_impl::son_event_processing_loop()
|
||||||
schedule_son_event_processing_loop();
|
schedule_son_event_processing_loop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void peerplays_sidechain_plugin_impl::recreate_primary_wallet()
|
||||||
|
{
|
||||||
|
chain::database& d = plugin.database();
|
||||||
|
|
||||||
|
const auto& idx_swi = d.get_index_type<son_wallet_index>().indices().get<by_id>();
|
||||||
|
auto obj = idx_swi.rbegin();
|
||||||
|
if (obj != idx_swi.rend()) {
|
||||||
|
|
||||||
|
if (obj->addresses.at(sidechain_type::bitcoin).empty()) {
|
||||||
|
auto active_sons = d.get_global_properties().active_sons;
|
||||||
|
vector<string> son_pubkeys_bitcoin;
|
||||||
|
for ( const son_info& si : active_sons ) {
|
||||||
|
son_pubkeys_bitcoin.push_back(si.sidechain_public_keys.at(sidechain_type::bitcoin));
|
||||||
|
}
|
||||||
|
net_manager->recreate_primary_wallet(sidechain_type::bitcoin, son_pubkeys_bitcoin);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
chain::proposal_create_operation peerplays_sidechain_plugin_impl::create_son_down_proposal(chain::son_id_type son_id, fc::time_point_sec last_active_ts)
|
chain::proposal_create_operation peerplays_sidechain_plugin_impl::create_son_down_proposal(chain::son_id_type son_id, fc::time_point_sec last_active_ts)
|
||||||
{
|
{
|
||||||
chain::database& d = plugin.database();
|
chain::database& d = plugin.database();
|
||||||
|
|
@ -268,6 +294,9 @@ chain::proposal_create_operation peerplays_sidechain_plugin_impl::create_son_dow
|
||||||
|
|
||||||
void peerplays_sidechain_plugin_impl::on_block_applied( const signed_block& b )
|
void peerplays_sidechain_plugin_impl::on_block_applied( const signed_block& b )
|
||||||
{
|
{
|
||||||
|
|
||||||
|
recreate_primary_wallet();
|
||||||
|
|
||||||
chain::database& d = plugin.database();
|
chain::database& d = plugin.database();
|
||||||
chain::son_id_type my_son_id = *(_sons.begin());
|
chain::son_id_type my_son_id = *(_sons.begin());
|
||||||
const chain::global_property_object& gpo = d.get_global_properties();
|
const chain::global_property_object& gpo = d.get_global_properties();
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,10 @@ sidechain_net_handler::sidechain_net_handler(std::shared_ptr<graphene::chain::da
|
||||||
sidechain_net_handler::~sidechain_net_handler() {
|
sidechain_net_handler::~sidechain_net_handler() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
graphene::peerplays_sidechain::sidechain_type sidechain_net_handler::get_sidechain() {
|
||||||
|
return sidechain;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<std::string> sidechain_net_handler::get_sidechain_addresses() {
|
std::vector<std::string> sidechain_net_handler::get_sidechain_addresses() {
|
||||||
std::vector<std::string> result;
|
std::vector<std::string> result;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -129,6 +129,28 @@ void bitcoin_rpc_client::send_btc_tx( const std::string& tx_hex )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string bitcoin_rpc_client::add_multisig_address( const std::vector<std::string> public_keys )
|
||||||
|
{
|
||||||
|
std::string body = std::string("{\"jsonrpc\": \"1.0\", \"id\":\"addmultisigaddress\", \"method\": \"addmultisigaddress\", \"params\": [");
|
||||||
|
std::string params = "2, \"[";
|
||||||
|
std::string pubkeys = "";
|
||||||
|
for (std::string pubkey : public_keys) {
|
||||||
|
if (!pubkeys.empty()) {
|
||||||
|
pubkeys = pubkeys + ", ";
|
||||||
|
}
|
||||||
|
pubkeys = pubkeys + std::string("\"") + pubkey + std::string("\"");
|
||||||
|
}
|
||||||
|
params = params + pubkeys + std::string("]\"");
|
||||||
|
body = body + params + std::string("] }");
|
||||||
|
|
||||||
|
ilog(body);
|
||||||
|
|
||||||
|
//const auto reply = send_post_request( body );
|
||||||
|
|
||||||
|
return "";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
bool bitcoin_rpc_client::connection_is_not_defined() const
|
bool bitcoin_rpc_client::connection_is_not_defined() const
|
||||||
{
|
{
|
||||||
return ip.empty() || rpc_port == 0 || user.empty() || password.empty();
|
return ip.empty() || rpc_port == 0 || user.empty() || password.empty();
|
||||||
|
|
@ -215,6 +237,11 @@ sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(std::shared_ptr<gra
|
||||||
sidechain_net_handler_bitcoin::~sidechain_net_handler_bitcoin() {
|
sidechain_net_handler_bitcoin::~sidechain_net_handler_bitcoin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sidechain_net_handler_bitcoin::recreate_primary_wallet( const vector<string>& participants ) {
|
||||||
|
ilog(__FUNCTION__);
|
||||||
|
string result = create_multisignature_wallet(participants);
|
||||||
|
}
|
||||||
|
|
||||||
bool sidechain_net_handler_bitcoin::connection_is_not_defined() const
|
bool sidechain_net_handler_bitcoin::connection_is_not_defined() const
|
||||||
{
|
{
|
||||||
return listener->connection_is_not_defined() && bitcoin_client->connection_is_not_defined();
|
return listener->connection_is_not_defined() && bitcoin_client->connection_is_not_defined();
|
||||||
|
|
@ -222,7 +249,7 @@ bool sidechain_net_handler_bitcoin::connection_is_not_defined() const
|
||||||
|
|
||||||
std::string sidechain_net_handler_bitcoin::create_multisignature_wallet( const std::vector<std::string> public_keys )
|
std::string sidechain_net_handler_bitcoin::create_multisignature_wallet( const std::vector<std::string> public_keys )
|
||||||
{
|
{
|
||||||
return "";
|
return bitcoin_client->add_multisig_address(public_keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string sidechain_net_handler_bitcoin::transfer( const std::string& from, const std::string& to, const uint64_t amount )
|
std::string sidechain_net_handler_bitcoin::transfer( const std::string& from, const std::string& to, const uint64_t amount )
|
||||||
|
|
|
||||||
|
|
@ -34,5 +34,14 @@ bool sidechain_net_manager::create_handler(peerplays_sidechain::sidechain_type s
|
||||||
return ret_val;
|
return ret_val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void 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) {
|
||||||
|
net_handlers.at(i)->recreate_primary_wallet(participants);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} } // graphene::peerplays_sidechain
|
} } // graphene::peerplays_sidechain
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue