Code formatting

This commit is contained in:
serkixenos 2022-06-28 20:39:00 +02:00
parent 7689d5adc0
commit cfaf31e705
5 changed files with 887 additions and 890 deletions

View file

@ -57,7 +57,7 @@ typedef fc::static_variant<
delegate_vesting_shares_operation> delegate_vesting_shares_operation>
ethereum_operation; ethereum_operation;
}}} // namespace graphene::peerplays_sidechain::hive }}} // namespace graphene::peerplays_sidechain::ethereum
namespace fc { namespace fc {

View file

@ -14,8 +14,8 @@
#include <fc/api.hpp> #include <fc/api.hpp>
#include <fc/log/logger.hpp> #include <fc/log/logger.hpp>
#include <websocketpp/config/asio_client.hpp>
#include <websocketpp/client.hpp> #include <websocketpp/client.hpp>
#include <websocketpp/config/asio_client.hpp>
#include <fc/thread/thread.hpp> #include <fc/thread/thread.hpp>
@ -28,14 +28,13 @@ u256 constexpr Invalid256 = 0xffffffffffffffffffffffffffffffffffffffffffffffffff
using byte = uint8_t; using byte = uint8_t;
using bytes = std::vector<byte>; using bytes = std::vector<byte>;
namespace graphene { namespace peerplays_sidechain { namespace graphene { namespace peerplays_sidechain {
typedef websocketpp::client<websocketpp::config::asio_client> client; typedef websocketpp::client<websocketpp::config::asio_client> client;
using websocketpp::lib::bind;
using websocketpp::lib::placeholders::_1; using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2; using websocketpp::lib::placeholders::_2;
using websocketpp::lib::bind;
// pull out the type of messages sent by our config // pull out the type of messages sent by our config
typedef websocketpp::config::asio_tls_client::message_type::ptr message_ptr; typedef websocketpp::config::asio_tls_client::message_type::ptr message_ptr;
@ -133,17 +132,17 @@ namespace graphene { namespace peerplays_sidechain {
std::string chain_id; //256 bit value std::string chain_id; //256 bit value
std::vector<std::string> owners; std::vector<std::string> owners;
std::string safe_account_addr; std::string safe_account_addr;
private: private:
/// Encodes an Ethereum transaction for exporting in JSON /// Encodes an Ethereum transaction for exporting in JSON
class Transaction class Transaction {
{
public: public:
/// JSON serialization /// JSON serialization
std::string serialize(const std::string &from, const std::string &to, const std::string &tx_id, u256 const &_value, u256 const &_gasPrice, u256 const &_gas, bytes const &_data, u256 const &_nonce = Invalid256); std::string serialize(const std::string &from, const std::string &to, const std::string &tx_id, u256 const &_value, u256 const &_gasPrice, u256 const &_gas, bytes const &_data, u256 const &_nonce = Invalid256);
protected: protected:
/// Type of transaction. /// Type of transaction.
enum Type enum Type {
{
NullTransaction, ///< Null transaction. NullTransaction, ///< Null transaction.
ContractCreation, ///< Transaction to create contracts - receiveAddress() is ignored. ContractCreation, ///< Transaction to create contracts - receiveAddress() is ignored.
MessageCall ///< Transaction to invoke a message call - receiveAddress() is used. MessageCall ///< Transaction to invoke a message call - receiveAddress() is used.
@ -218,10 +217,10 @@ namespace graphene { namespace peerplays_sidechain {
// ============================================================================= // =============================================================================
class sidechain_net_handler_eth : public sidechain_net_handler { class sidechain_net_handler_ethereum : public sidechain_net_handler {
public: public:
sidechain_net_handler_eth(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options); sidechain_net_handler_ethereum(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options);
virtual ~sidechain_net_handler_eth(); virtual ~sidechain_net_handler_ethereum();
bool process_proposal(const proposal_object &po); bool process_proposal(const proposal_object &po);
void process_primary_wallet(); void process_primary_wallet();

View file

@ -3,8 +3,8 @@
#include <algorithm> #include <algorithm>
#include <thread> #include <thread>
#include <boost/format.hpp>
#include <boost/algorithm/hex.hpp> #include <boost/algorithm/hex.hpp>
#include <boost/format.hpp>
#include <boost/property_tree/json_parser.hpp> #include <boost/property_tree/json_parser.hpp>
#include <boost/property_tree/ptree.hpp> #include <boost/property_tree/ptree.hpp>
@ -17,8 +17,8 @@
#include <graphene/chain/sidechain_transaction_object.hpp> #include <graphene/chain/sidechain_transaction_object.hpp>
#include <graphene/chain/son_info.hpp> #include <graphene/chain/son_info.hpp>
#include <graphene/chain/son_wallet_object.hpp> #include <graphene/chain/son_wallet_object.hpp>
#include <graphene/utilities/key_conversion.hpp>
#include <graphene/peerplays_sidechain/ethereum/transaction.hpp> #include <graphene/peerplays_sidechain/ethereum/transaction.hpp>
#include <graphene/utilities/key_conversion.hpp>
#include <fc/crypto/hex.hpp> #include <fc/crypto/hex.hpp>
@ -109,8 +109,8 @@ namespace graphene { namespace peerplays_sidechain {
return message; return message;
} }
eth_rpc_client::eth_rpc_client(const std::string &url, const std::string &user_name, const std::string &password, bool debug_rpc_calls) :
eth_rpc_client::eth_rpc_client(const std::string &url, const std::string &user_name, const std::string &password, bool debug_rpc_calls) : _thread(std::make_shared<fc::thread>("eth_rpc_client")){ _thread(std::make_shared<fc::thread>("eth_rpc_client")) {
geth_url = url; geth_url = url;
user = user_name; user = user_name;
this->password = password; this->password = password;
@ -136,8 +136,7 @@ namespace graphene { namespace peerplays_sidechain {
void eth_rpc_client::start() { void eth_rpc_client::start() {
ilog("### eth_rpc_client::start uri: ${uri}", ("uri", geth_url)); ilog("### eth_rpc_client::start uri: ${uri}", ("uri", geth_url));
auto future = _thread->async([this] auto future = _thread->async([this] {
{
websocketpp::lib::error_code ec; websocketpp::lib::error_code ec;
client::connection_ptr con = m_endpoint.get_connection(this->geth_url, ec); client::connection_ptr con = m_endpoint.get_connection(this->geth_url, ec);
m_hdl = con->get_handle(); m_hdl = con->get_handle();
@ -395,7 +394,6 @@ namespace graphene { namespace peerplays_sidechain {
//0x3627C1B31525887CB9441130C831e35887650305 //0x3627C1B31525887CB9441130C831e35887650305
//0x03A13a989AF30C92AD7ABD1E6210308A6c96f373 //0x03A13a989AF30C92AD7ABD1E6210308A6c96f373
std::string from = "0xeE52b70e8D7AB5Fe661311D47e81228EAD6B06B9"; std::string from = "0xeE52b70e8D7AB5Fe661311D47e81228EAD6B06B9";
std::string to = "0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2"; std::string to = "0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2";
std::string data = m_safe_transaction_encoder.create_safe_address(owner_addresses, nrequired); std::string data = m_safe_transaction_encoder.create_safe_address(owner_addresses, nrequired);
@ -495,7 +493,7 @@ namespace graphene { namespace peerplays_sidechain {
// ============================================================================= // =============================================================================
sidechain_net_handler_eth::sidechain_net_handler_eth(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) : sidechain_net_handler_ethereum::sidechain_net_handler_ethereum(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) :
sidechain_net_handler(_plugin, options) { sidechain_net_handler(_plugin, options) {
sidechain = sidechain_type::ethereum; sidechain = sidechain_type::ethereum;
@ -512,7 +510,7 @@ namespace graphene { namespace peerplays_sidechain {
} }
std::thread(&sidechain_net_handler_eth::handle_event, this, event_data).detach(); std::thread(&sidechain_net_handler_ethereum::handle_event, this, event_data).detach();
}); });
database.changed_objects.connect([this](const vector<object_id_type> &ids, const flat_set<account_id_type> &accounts) { database.changed_objects.connect([this](const vector<object_id_type> &ids, const flat_set<account_id_type> &accounts) {
@ -521,7 +519,7 @@ namespace graphene { namespace peerplays_sidechain {
*/ */
} }
sidechain_net_handler_eth::~sidechain_net_handler_eth() { sidechain_net_handler_ethereum::~sidechain_net_handler_ethereum() {
try { try {
if (on_changed_objects_task.valid()) { if (on_changed_objects_task.valid()) {
on_changed_objects_task.cancel_and_wait(__FUNCTION__); on_changed_objects_task.cancel_and_wait(__FUNCTION__);
@ -533,7 +531,7 @@ sidechain_net_handler_eth::~sidechain_net_handler_eth() {
} }
} }
bool sidechain_net_handler_eth::process_proposal(const proposal_object &po) { bool sidechain_net_handler_ethereum::process_proposal(const proposal_object &po) {
ilog("Proposal to process: ${po}, SON id ${son_id}", ("po", po.id)("son_id", plugin.get_current_son_id())); ilog("Proposal to process: ${po}, SON id ${son_id}", ("po", po.id)("son_id", plugin.get_current_son_id()));
/* /*
@ -822,7 +820,7 @@ return should_approve;
return true; return true;
} }
void sidechain_net_handler_eth::process_primary_wallet() { void sidechain_net_handler_ethereum::process_primary_wallet() {
ilog("### process_primary_wallet:"); ilog("### process_primary_wallet:");
const auto &swi = database.get_index_type<son_wallet_index>().indices().get<by_id>(); const auto &swi = database.get_index_type<son_wallet_index>().indices().get<by_id>();
@ -899,7 +897,7 @@ void sidechain_net_handler_eth::process_primary_wallet() {
} }
} }
void sidechain_net_handler_eth::process_sidechain_addresses() { void sidechain_net_handler_ethereum::process_sidechain_addresses() {
/* /*
const chain::global_property_object &gpo = database.get_global_properties(); const chain::global_property_object &gpo = database.get_global_properties();
std::vector<std::pair<fc::ecc::public_key, uint16_t>> pubkeys; std::vector<std::pair<fc::ecc::public_key, uint16_t>> pubkeys;
@ -956,7 +954,7 @@ void sidechain_net_handler_eth::process_sidechain_addresses() {
*/ */
} }
bool sidechain_net_handler_eth::process_deposit(const son_wallet_deposit_object &swdo) { bool sidechain_net_handler_ethereum::process_deposit(const son_wallet_deposit_object &swdo) {
ilog("### process_deposit:"); ilog("### process_deposit:");
if (proposal_exists(chain::operation::tag<chain::son_wallet_deposit_process_operation>::value, swdo.id)) { if (proposal_exists(chain::operation::tag<chain::son_wallet_deposit_process_operation>::value, swdo.id)) {
@ -1001,7 +999,7 @@ bool sidechain_net_handler_eth::process_deposit(const son_wallet_deposit_object
return false; return false;
} }
bool sidechain_net_handler_eth::process_withdrawal(const son_wallet_withdraw_object &swwo) { bool sidechain_net_handler_ethereum::process_withdrawal(const son_wallet_withdraw_object &swwo) {
ilog("### process_withdrawal:"); ilog("### process_withdrawal:");
if (proposal_exists(chain::operation::tag<chain::son_wallet_withdraw_process_operation>::value, swwo.id)) { if (proposal_exists(chain::operation::tag<chain::son_wallet_withdraw_process_operation>::value, swwo.id)) {
@ -1046,30 +1044,31 @@ bool sidechain_net_handler_eth::process_withdrawal(const son_wallet_withdraw_obj
return false; return false;
} }
std::string sidechain_net_handler_eth::process_sidechain_transaction(const sidechain_transaction_object &sto) { std::string sidechain_net_handler_ethereum::process_sidechain_transaction(const sidechain_transaction_object &sto) {
ilog("### process_sidechain_transaction: "); ilog("### process_sidechain_transaction: ");
return sign_transaction(sto); return sign_transaction(sto);
} }
std::string sidechain_net_handler_eth::send_sidechain_transaction(const sidechain_transaction_object &sto) { std::string sidechain_net_handler_ethereum::send_sidechain_transaction(const sidechain_transaction_object &sto) {
ilog("### send_sidechain_transaction: "); ilog("### send_sidechain_transaction: ");
return send_transaction(sto); return send_transaction(sto);
} }
bool sidechain_net_handler_eth::settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount) { bool sidechain_net_handler_ethereum::settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount) {
return false; return false;
} }
std::vector<char> sidechain_net_handler_eth::parse_hex(const std::string &str) { std::vector<char> sidechain_net_handler_ethereum::parse_hex(const std::string &str) {
std::vector<char> vec(str.size() / 2); std::vector<char> vec(str.size() / 2);
fc::from_hex(str, vec.data(), vec.size()); fc::from_hex(str, vec.data(), vec.size());
return vec; return vec;
} }
std::string sidechain_net_handler_eth::create_primary_wallet_address(const std::vector<son_info> &son_pubkeys) { std::string sidechain_net_handler_ethereum::create_primary_wallet_address(const std::vector<son_info> &son_pubkeys) {
std::stringstream ss; std::stringstream ss;
ss << "{\"result\": {\"address\": \"" << eth_client->safe_account_addr << "\"" << "}, "; ss << "{\"result\": {\"address\": \"" << eth_client->safe_account_addr << "\""
<< "}, ";
ss << "\"onwers\": ["; ss << "\"onwers\": [";
for (auto &owner : eth_client->owners) { for (auto &owner : eth_client->owners) {
ss << "\"" << owner << "\","; ss << "\"" << owner << "\",";
@ -1090,24 +1089,24 @@ std::string sidechain_net_handler_eth::create_primary_wallet_address(const std::
return res; return res;
} }
std::string sidechain_net_handler_eth::create_primary_wallet_transaction(const son_wallet_object &prev_swo, std::string new_sw_address) { std::string sidechain_net_handler_ethereum::create_primary_wallet_transaction(const son_wallet_object &prev_swo, std::string new_sw_address) {
return ""; //create_transaction(inputs, outputs, prev_redeem_script); return ""; //create_transaction(inputs, outputs, prev_redeem_script);
} }
std::string sidechain_net_handler_eth::create_deposit_transaction(const son_wallet_deposit_object &swdo) { std::string sidechain_net_handler_ethereum::create_deposit_transaction(const son_wallet_deposit_object &swdo) {
return ""; //create_transaction(inputs, outputs, redeem_script); return ""; //create_transaction(inputs, outputs, redeem_script);
} }
std::string sidechain_net_handler_eth::create_withdrawal_transaction(const son_wallet_withdraw_object &swwo) { std::string sidechain_net_handler_ethereum::create_withdrawal_transaction(const son_wallet_withdraw_object &swwo) {
return ""; //create_transaction(inputs, outputs, redeem_script); return ""; //create_transaction(inputs, outputs, redeem_script);
} }
std::string sidechain_net_handler_eth::create_transaction() { std::string sidechain_net_handler_ethereum::create_transaction() {
std::string tx_raw; // = write_transaction_data(hex_tx, in_amounts, redeem_script); std::string tx_raw; // = write_transaction_data(hex_tx, in_amounts, redeem_script);
return tx_raw; return tx_raw;
} }
std::string sidechain_net_handler_eth::sign_transaction(const sidechain_transaction_object &sto) { std::string sidechain_net_handler_ethereum::sign_transaction(const sidechain_transaction_object &sto) {
ilog("### sign_transaction: "); ilog("### sign_transaction: ");
std::stringstream ss_trx(boost::algorithm::unhex(sto.transaction)); std::stringstream ss_trx(boost::algorithm::unhex(sto.transaction));
@ -1124,19 +1123,18 @@ std::string sidechain_net_handler_eth::sign_transaction(const sidechain_transact
fc::raw::pack(ss_st, st, 1000); fc::raw::pack(ss_st, st, 1000);
std::string st_str = boost::algorithm::hex(ss_st.str()); std::string st_str = boost::algorithm::hex(ss_st.str());
return st_str; return st_str;
} }
std::string sidechain_net_handler_eth::send_transaction(const sidechain_transaction_object &sto) { std::string sidechain_net_handler_ethereum::send_transaction(const sidechain_transaction_object &sto) {
std::string res; // = eth_client->sendrawtransaction(final_tx_hex); std::string res; // = eth_client->sendrawtransaction(final_tx_hex);
return res; return res;
} }
void sidechain_net_handler_eth::handle_event(const std::string &event_data) { void sidechain_net_handler_ethereum::handle_event(const std::string &event_data) {
} }
std::vector<info_for_vin> sidechain_net_handler_eth::extract_info_from_block(const std::string &_block) { std::vector<info_for_vin> sidechain_net_handler_ethereum::extract_info_from_block(const std::string &_block) {
std::stringstream ss(_block); std::stringstream ss(_block);
boost::property_tree::ptree block; boost::property_tree::ptree block;
boost::property_tree::read_json(ss, block); boost::property_tree::read_json(ss, block);
@ -1146,7 +1144,7 @@ std::vector<info_for_vin> sidechain_net_handler_eth::extract_info_from_block(con
return result; return result;
} }
void sidechain_net_handler_eth::on_changed_objects(const vector<object_id_type> &ids, const flat_set<account_id_type> &accounts) { void sidechain_net_handler_ethereum::on_changed_objects(const vector<object_id_type> &ids, const flat_set<account_id_type> &accounts) {
ilog("### on_changed_objects: "); ilog("### on_changed_objects: ");
fc::time_point now = fc::time_point::now(); fc::time_point now = fc::time_point::now();
@ -1160,10 +1158,10 @@ void sidechain_net_handler_eth::on_changed_objects(const vector<object_id_type>
next_wakeup, "SON Processing"); next_wakeup, "SON Processing");
} }
void sidechain_net_handler_eth::on_changed_objects_cb(const vector<object_id_type> &ids, const flat_set<account_id_type> &accounts) { void sidechain_net_handler_ethereum::on_changed_objects_cb(const vector<object_id_type> &ids, const flat_set<account_id_type> &accounts) {
} }
fc::ecc::public_key_data sidechain_net_handler_eth::create_public_key_data(const std::vector<char> &public_key) { fc::ecc::public_key_data sidechain_net_handler_ethereum::create_public_key_data(const std::vector<char> &public_key) {
FC_ASSERT(public_key.size() == 33); FC_ASSERT(public_key.size() == 33);
fc::ecc::public_key_data key; fc::ecc::public_key_data key;
for (size_t i = 0; i < 33; i++) { for (size_t i = 0; i < 33; i++) {