Skeleton of sidechain_net_handler_peerplays

This commit is contained in:
Srdjan Obucina 2020-02-14 01:25:24 +01:00
parent 75626254fa
commit b927ffa4d0
7 changed files with 107 additions and 8 deletions

1
libraries/plugins/peerplays_sidechain/CMakeLists.txt Normal file → Executable file
View file

@ -5,6 +5,7 @@ add_library( peerplays_sidechain
sidechain_net_manager.cpp
sidechain_net_handler.cpp
sidechain_net_handler_bitcoin.cpp
sidechain_net_handler_peerplays.cpp
)
if (SUPPORT_MULTIPLE_SONS)

View file

@ -7,7 +7,6 @@
#include <fc/signals.hpp>
#include <fc/network/http/connection.hpp>
#include <graphene/chain/database.hpp>
namespace graphene { namespace peerplays_sidechain {
@ -62,8 +61,6 @@ public:
void recreate_primary_wallet();
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 );

View file

@ -0,0 +1,30 @@
#pragma once
#include <graphene/peerplays_sidechain/sidechain_net_handler.hpp>
#include <string>
#include <fc/signals.hpp>
namespace graphene { namespace peerplays_sidechain {
class sidechain_net_handler_peerplays : public sidechain_net_handler {
public:
sidechain_net_handler_peerplays(peerplays_sidechain_plugin& _plugin, const boost::program_options::variables_map& options);
virtual ~sidechain_net_handler_peerplays();
void recreate_primary_wallet();
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:
void handle_event( const std::string& event_data );
};
} } // graphene::peerplays_sidechain

View file

@ -55,6 +55,7 @@ class peerplays_sidechain_plugin_impl
bool config_ready_son;
bool config_ready_bitcoin;
bool config_ready_peerplays;
std::unique_ptr<peerplays_sidechain::sidechain_net_manager> net_manager;
std::map<chain::public_key_type, fc::ecc::private_key> _private_keys;
@ -67,6 +68,7 @@ peerplays_sidechain_plugin_impl::peerplays_sidechain_plugin_impl(peerplays_sidec
plugin(_plugin),
config_ready_son(false),
config_ready_bitcoin(false),
config_ready_peerplays(false),
net_manager(nullptr)
{
}
@ -177,6 +179,14 @@ void peerplays_sidechain_plugin_impl::plugin_initialize(const boost::program_opt
// wlog("Haven't set up Ethereum sidechain parameters");
//}
config_ready_peerplays = true;
if (config_ready_peerplays) {
net_manager->create_handler(sidechain_type::peerplays, options);
ilog("Peerplays sidechain handler created");
} else {
wlog("Haven't set up Peerplays sidechain parameters");
}
if (!(config_ready_bitcoin /*&& config_ready_ethereum*/)) {
wlog("Haven't set up any sidechain parameters");
throw;
@ -200,6 +210,10 @@ void peerplays_sidechain_plugin_impl::plugin_startup()
//if (config_ready_ethereum) {
// ilog("Ethereum sidechain handler running");
//}
if (config_ready_peerplays) {
ilog("Peerplays sidechain handler running");
}
}
std::set<chain::son_id_type>& peerplays_sidechain_plugin_impl::get_sons()

View file

@ -308,11 +308,6 @@ void sidechain_net_handler_bitcoin::recreate_primary_wallet() {
}
}
bool sidechain_net_handler_bitcoin::connection_is_not_defined() const
{
return listener->connection_is_not_defined() && bitcoin_client->connection_is_not_defined();
}
std::string sidechain_net_handler_bitcoin::create_multisignature_wallet( const std::vector<std::string> public_keys )
{
return bitcoin_client->add_multisig_address(public_keys);

View file

@ -0,0 +1,55 @@
#include <graphene/peerplays_sidechain/sidechain_net_handler_peerplays.hpp>
#include <algorithm>
#include <thread>
#include <boost/algorithm/hex.hpp>
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <fc/crypto/base64.hpp>
#include <fc/log/logger.hpp>
#include <fc/network/ip.hpp>
#include <graphene/chain/account_object.hpp>
#include <graphene/chain/sidechain_address_object.hpp>
#include <graphene/chain/son_info.hpp>
#include <graphene/chain/son_wallet_object.hpp>
#include <graphene/chain/protocol/son_wallet.hpp>
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;
}
sidechain_net_handler_peerplays::~sidechain_net_handler_peerplays() {
}
void sidechain_net_handler_peerplays::recreate_primary_wallet() {
}
std::string sidechain_net_handler_peerplays::create_multisignature_wallet( const std::vector<std::string> public_keys ) {
return "";
}
std::string sidechain_net_handler_peerplays::transfer( const std::string& from, const std::string& to, const uint64_t amount ) {
return "";
}
std::string sidechain_net_handler_peerplays::sign_transaction( const std::string& transaction ) {
return "";
}
std::string sidechain_net_handler_peerplays::send_transaction( const std::string& transaction ) {
return "";
}
void sidechain_net_handler_peerplays::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));
}
} } // graphene::peerplays_sidechain

View file

@ -3,6 +3,7 @@
#include <fc/log/logger.hpp>
#include <graphene/chain/son_wallet_object.hpp>
#include <graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp>
#include <graphene/peerplays_sidechain/sidechain_net_handler_peerplays.hpp>
namespace graphene { namespace peerplays_sidechain {
@ -26,6 +27,12 @@ bool sidechain_net_manager::create_handler(peerplays_sidechain::sidechain_type s
ret_val = true;
break;
}
case sidechain_type::peerplays: {
std::unique_ptr<sidechain_net_handler> h = std::unique_ptr<sidechain_net_handler>(new sidechain_net_handler_peerplays(plugin, options));
net_handlers.push_back(std::move(h));
ret_val = true;
break;
}
default:
assert(false);
}