Update source code to last designs
This commit is contained in:
parent
75106ee5e8
commit
c1b3ce7a5e
6 changed files with 62 additions and 15 deletions
|
|
@ -8,8 +8,14 @@ class sidechain_net_handler {
|
||||||
public:
|
public:
|
||||||
sidechain_net_handler(const boost::program_options::variables_map& options);
|
sidechain_net_handler(const boost::program_options::variables_map& options);
|
||||||
virtual ~sidechain_net_handler();
|
virtual ~sidechain_net_handler();
|
||||||
|
|
||||||
|
virtual std::string create_multisignature_wallet( const std::vector<std::string> public_keys ) = 0;
|
||||||
|
virtual std::string transfer( const std::string& from, const std::string& to, const uint64_t amount ) = 0;
|
||||||
|
virtual std::string sign_transaction( const std::string& transaction ) = 0;
|
||||||
|
virtual std::string send_transaction( const std::string& transaction ) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void handle_block( const std::string& block_hash ) = 0;
|
virtual void handle_event( const std::string& event_data ) = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ public:
|
||||||
zmq_listener( std::string _ip, uint32_t _zmq );
|
zmq_listener( std::string _ip, uint32_t _zmq );
|
||||||
bool connection_is_not_defined() const { return zmq_port == 0; }
|
bool connection_is_not_defined() const { return zmq_port == 0; }
|
||||||
|
|
||||||
fc::signal<void( const std::string& )> block_received;
|
fc::signal<void( const std::string& )> event_received;
|
||||||
private:
|
private:
|
||||||
void handle_zmq();
|
void handle_zmq();
|
||||||
std::vector<zmq::message_t> receive_multipart();
|
std::vector<zmq::message_t> receive_multipart();
|
||||||
|
|
@ -69,6 +69,11 @@ public:
|
||||||
|
|
||||||
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 transfer( const std::string& from, const std::string& to, const uint64_t amount );
|
||||||
|
std::string sign_transaction( const std::string& transaction );
|
||||||
|
std::string send_transaction( const std::string& transaction );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string ip;
|
std::string ip;
|
||||||
uint32_t zmq_port;
|
uint32_t zmq_port;
|
||||||
|
|
@ -80,7 +85,7 @@ private:
|
||||||
std::unique_ptr<bitcoin_rpc_client> bitcoin_client;
|
std::unique_ptr<bitcoin_rpc_client> bitcoin_client;
|
||||||
graphene::chain::database* db;
|
graphene::chain::database* db;
|
||||||
|
|
||||||
void handle_block( const std::string& block_hash );
|
void handle_event( const std::string& event_data);
|
||||||
|
|
||||||
//std::vector<info_for_vin> extract_info_from_block( const std::string& _block );
|
//std::vector<info_for_vin> extract_info_from_block( const std::string& _block );
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,17 +8,25 @@
|
||||||
|
|
||||||
namespace graphene { namespace peerplays_sidechain {
|
namespace graphene { namespace peerplays_sidechain {
|
||||||
|
|
||||||
enum networks {
|
enum network {
|
||||||
bitcoin,
|
bitcoin,
|
||||||
//ethereum
|
//ethereum
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct sidechain_event_data {
|
||||||
|
network sidechain;
|
||||||
|
std::string transaction_id;
|
||||||
|
std::string from;
|
||||||
|
std::string to;
|
||||||
|
int64_t amount;
|
||||||
|
};
|
||||||
|
|
||||||
class sidechain_net_manager {
|
class sidechain_net_manager {
|
||||||
public:
|
public:
|
||||||
sidechain_net_manager();
|
sidechain_net_manager();
|
||||||
virtual ~sidechain_net_manager();
|
virtual ~sidechain_net_manager();
|
||||||
|
|
||||||
bool create_handler(peerplays_sidechain::networks network, const boost::program_options::variables_map& options);
|
bool create_handler(peerplays_sidechain::network network, const boost::program_options::variables_map& options);
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::vector<std::unique_ptr<sidechain_net_handler>> net_handlers;
|
std::vector<std::unique_ptr<sidechain_net_handler>> net_handlers;
|
||||||
|
|
|
||||||
|
|
@ -57,11 +57,17 @@ void peerplays_sidechain_plugin::plugin_set_program_options(
|
||||||
//("bitcoin-node-rpc-port", bpo::value<uint32_t>()->implicit_value(18332), "RPC port of Bitcoin node")
|
//("bitcoin-node-rpc-port", bpo::value<uint32_t>()->implicit_value(18332), "RPC port of Bitcoin node")
|
||||||
//("bitcoin-node-rpc-user", bpo::value<string>(), "Bitcoin RPC user")
|
//("bitcoin-node-rpc-user", bpo::value<string>(), "Bitcoin RPC user")
|
||||||
//("bitcoin-node-rpc-password", bpo::value<string>(), "Bitcoin RPC password")
|
//("bitcoin-node-rpc-password", bpo::value<string>(), "Bitcoin RPC password")
|
||||||
|
//("bitcoin-address", bpo::value<string>(), "Bitcoin address")
|
||||||
|
//("bitcoin-public-key", bpo::value<string>(), "Bitcoin public key")
|
||||||
|
//("bitcoin-private-key", bpo::value<string>(), "Bitcoin private key")
|
||||||
("bitcoin-node-ip", bpo::value<string>()->implicit_value("99.79.189.95"), "IP address of Bitcoin node")
|
("bitcoin-node-ip", bpo::value<string>()->implicit_value("99.79.189.95"), "IP address of Bitcoin node")
|
||||||
("bitcoin-node-zmq-port", bpo::value<uint32_t>()->implicit_value(11111), "ZMQ port of Bitcoin node")
|
("bitcoin-node-zmq-port", bpo::value<uint32_t>()->implicit_value(11111), "ZMQ port of Bitcoin node")
|
||||||
("bitcoin-node-rpc-port", bpo::value<uint32_t>()->implicit_value(22222), "RPC port of Bitcoin node")
|
("bitcoin-node-rpc-port", bpo::value<uint32_t>()->implicit_value(22222), "RPC port of Bitcoin node")
|
||||||
("bitcoin-node-rpc-user", bpo::value<string>()->implicit_value("1"), "Bitcoin RPC user")
|
("bitcoin-node-rpc-user", bpo::value<string>()->implicit_value("1"), "Bitcoin RPC user")
|
||||||
("bitcoin-node-rpc-password", bpo::value<string>()->implicit_value("1"), "Bitcoin RPC password")
|
("bitcoin-node-rpc-password", bpo::value<string>()->implicit_value("1"), "Bitcoin RPC password")
|
||||||
|
("bitcoin-address", bpo::value<string>()->implicit_value("2N911a7smwDzUGARg8s7Q1ViizFCw6gWcbR"), "Bitcoin address")
|
||||||
|
("bitcoin-public-key", bpo::value<string>()->implicit_value("02d0f137e717fb3aab7aff99904001d49a0a636c5e1342f8927a4ba2eaee8e9772"), "Bitcoin public key")
|
||||||
|
("bitcoin-private-key", bpo::value<string>()->implicit_value("cVN31uC9sTEr392DLVUEjrtMgLA8Yb3fpYmTRj7bomTm6nn2ANPr"), "Bitcoin private key")
|
||||||
;
|
;
|
||||||
cfg.add(cli);
|
cfg.add(cli);
|
||||||
}
|
}
|
||||||
|
|
@ -71,9 +77,10 @@ void peerplays_sidechain_plugin::plugin_initialize(const boost::program_options:
|
||||||
ilog("peerplays sidechain plugin: plugin_initialize()");
|
ilog("peerplays sidechain plugin: plugin_initialize()");
|
||||||
|
|
||||||
if( options.count( "bitcoin-node-ip" ) && options.count( "bitcoin-node-zmq-port" ) && options.count( "bitcoin-node-rpc-port" )
|
if( options.count( "bitcoin-node-ip" ) && options.count( "bitcoin-node-zmq-port" ) && options.count( "bitcoin-node-rpc-port" )
|
||||||
&& options.count( "bitcoin-node-rpc-user" ) && options.count( "bitcoin-node-rpc-password" ) )
|
&& 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" ) )
|
||||||
{
|
{
|
||||||
my->_net_manager.create_handler(networks::bitcoin, options);
|
my->_net_manager.create_handler(network::bitcoin, options);
|
||||||
} else {
|
} else {
|
||||||
wlog("Haven't set up bitcoin sidechain parameters");
|
wlog("Haven't set up bitcoin sidechain parameters");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,7 @@ std::vector<zmq::message_t> zmq_listener::receive_multipart() {
|
||||||
|
|
||||||
void zmq_listener::handle_zmq() {
|
void zmq_listener::handle_zmq() {
|
||||||
socket.setsockopt( ZMQ_SUBSCRIBE, "hashblock", 0 );
|
socket.setsockopt( ZMQ_SUBSCRIBE, "hashblock", 0 );
|
||||||
|
//socket.setsockopt( ZMQ_SUBSCRIBE, "hashtx", 0 );
|
||||||
socket.connect( "tcp://" + ip + ":" + std::to_string( zmq_port ) );
|
socket.connect( "tcp://" + ip + ":" + std::to_string( zmq_port ) );
|
||||||
|
|
||||||
while ( true ) {
|
while ( true ) {
|
||||||
|
|
@ -174,7 +175,7 @@ void zmq_listener::handle_zmq() {
|
||||||
const auto header = std::string( static_cast<char*>( msg[0].data() ), msg[0].size() );
|
const auto header = std::string( static_cast<char*>( msg[0].data() ), msg[0].size() );
|
||||||
const auto hash = boost::algorithm::hex( std::string( static_cast<char*>( msg[1].data() ), msg[1].size() ) );
|
const auto hash = boost::algorithm::hex( std::string( static_cast<char*>( msg[1].data() ), msg[1].size() ) );
|
||||||
|
|
||||||
block_received( hash );
|
event_received( hash );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -200,8 +201,8 @@ sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(const boost::progra
|
||||||
bitcoin_client = std::unique_ptr<bitcoin_rpc_client>( new bitcoin_rpc_client( ip, rpc_port, rpc_user, rpc_password ) );
|
bitcoin_client = std::unique_ptr<bitcoin_rpc_client>( new bitcoin_rpc_client( ip, rpc_port, rpc_user, rpc_password ) );
|
||||||
//db = _db;
|
//db = _db;
|
||||||
|
|
||||||
listener->block_received.connect([this]( const std::string& block_hash ) {
|
listener->event_received.connect([this]( const std::string& event_data ) {
|
||||||
std::thread( &sidechain_net_handler_bitcoin::handle_block, this, block_hash ).detach();
|
std::thread( &sidechain_net_handler_bitcoin::handle_event, this, event_data ).detach();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
//db->send_btc_tx.connect([this]( const sidechain::bitcoin_transaction& trx ) {
|
//db->send_btc_tx.connect([this]( const sidechain::bitcoin_transaction& trx ) {
|
||||||
|
|
@ -271,9 +272,29 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sidechain_net_handler_bitcoin::handle_block( const std::string& block_hash ) {
|
std::string sidechain_net_handler_bitcoin::create_multisignature_wallet( const std::vector<std::string> public_keys )
|
||||||
ilog("peerplays sidechain plugin: sidechain_net_handler_bitcoin::handle_block");
|
{
|
||||||
ilog(" block_hash: ${block_hash}", ("block_hash", block_hash));
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string sidechain_net_handler_bitcoin::transfer( const std::string& from, const std::string& to, const uint64_t amount )
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string sidechain_net_handler_bitcoin::sign_transaction( const std::string& transaction )
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string sidechain_net_handler_bitcoin::send_transaction( const std::string& transaction )
|
||||||
|
{
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
void sidechain_net_handler_bitcoin::handle_event( const std::string& event_data ) {
|
||||||
|
ilog("peerplays sidechain plugin: sidechain_net_handler_bitcoin::handle_event");
|
||||||
|
ilog(" event_data: ${event_data}", ("event_data", event_data));
|
||||||
//update_tx_approvals();
|
//update_tx_approvals();
|
||||||
//update_estimated_fee();
|
//update_estimated_fee();
|
||||||
//update_tx_infos( block_hash );
|
//update_tx_infos( block_hash );
|
||||||
|
|
|
||||||
|
|
@ -13,13 +13,13 @@ sidechain_net_manager::~sidechain_net_manager() {
|
||||||
ilog(__FUNCTION__);
|
ilog(__FUNCTION__);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sidechain_net_manager::create_handler(peerplays_sidechain::networks network, const boost::program_options::variables_map& options) {
|
bool sidechain_net_manager::create_handler(peerplays_sidechain::network network, const boost::program_options::variables_map& options) {
|
||||||
ilog(__FUNCTION__);
|
ilog(__FUNCTION__);
|
||||||
|
|
||||||
bool ret_val = false;
|
bool ret_val = false;
|
||||||
|
|
||||||
switch (network) {
|
switch (network) {
|
||||||
case networks::bitcoin: {
|
case network::bitcoin: {
|
||||||
std::unique_ptr<sidechain_net_handler> h = std::unique_ptr<sidechain_net_handler>(new sidechain_net_handler_bitcoin(options));
|
std::unique_ptr<sidechain_net_handler> h = std::unique_ptr<sidechain_net_handler>(new sidechain_net_handler_bitcoin(options));
|
||||||
net_handlers.push_back(std::move(h));
|
net_handlers.push_back(std::move(h));
|
||||||
ret_val = true;
|
ret_val = true;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue