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

@ -29,7 +29,7 @@ public:
void set_expiration(fc::time_point_sec expiration_time); void set_expiration(fc::time_point_sec expiration_time);
void set_reference_block(const block_id_type &reference_block); void set_reference_block(const block_id_type &reference_block);
/* /*
/// Serialises this transaction to an RLPStream. /// Serialises this transaction to an RLPStream.
/// @throws TransactionIsUnsigned if including signature was requested but it was not initialized /// @throws TransactionIsUnsigned if including signature was requested but it was not initialized
void streamRLP(RLPStream& _s, IncludeSignature _sig = WithSignature, bool _forEip155hash = false) const; void streamRLP(RLPStream& _s, IncludeSignature _sig = WithSignature, bool _forEip155hash = false) const;

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,22 +28,21 @@ 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::placeholders::_1; using websocketpp::lib::bind;
using websocketpp::lib::placeholders::_2; using websocketpp::lib::placeholders::_1;
using websocketpp::lib::bind; using websocketpp::lib::placeholders::_2;
// 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;
typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context> context_ptr; typedef websocketpp::lib::shared_ptr<boost::asio::ssl::context> context_ptr;
typedef client::connection_ptr connection_ptr; typedef client::connection_ptr connection_ptr;
class eth_rpc_client { class eth_rpc_client {
public: public:
typedef eth_rpc_client type; typedef eth_rpc_client type;
enum req_t { enum req_t {
@ -88,18 +87,18 @@ namespace graphene { namespace peerplays_sidechain {
void on_close(websocketpp::connection_hdl); void on_close(websocketpp::connection_hdl);
uint64_t get_chain_id(); uint64_t get_chain_id();
uint64_t eth_getTransactionReceipt(const std::string& tx_id); uint64_t eth_getTransactionReceipt(const std::string &tx_id);
uint64_t eth_call(const std::string& to, const std::string& data); uint64_t eth_call(const std::string &to, const std::string &data);
uint64_t eth_sendTransaction(const std::string& from, const std::string& to, const std::string& data); uint64_t eth_sendTransaction(const std::string &from, const std::string &to, const std::string &data);
uint64_t eth_sendRawTransaction(const std::string& params); uint64_t eth_sendRawTransaction(const std::string &params);
uint64_t eth_getCode(const std::string& addr); uint64_t eth_getCode(const std::string &addr);
uint64_t eth_getBalance(const std::string& addr); uint64_t eth_getBalance(const std::string &addr);
uint64_t eth_sign(const string& addr, const string& message); uint64_t eth_sign(const string &addr, const string &message);
uint64_t eth_coinbase(); uint64_t eth_coinbase();
uint64_t get_list_owners(const std::string& safe_account); uint64_t get_list_owners(const std::string &safe_account);
uint64_t add_owner(const std::string& addr ); uint64_t add_owner(const std::string &addr);
uint64_t remove_owner(const std::string& addr, uint32_t threshold); uint64_t remove_owner(const std::string &addr, uint32_t threshold);
std::string addmultisigaddress(const uint32_t nrequired, const std::vector<std::string> public_keys); std::string addmultisigaddress(const uint32_t nrequired, const std::vector<std::string> public_keys);
std::string combinepsbt(const vector<std::string> &psbts); std::string combinepsbt(const vector<std::string> &psbts);
@ -130,20 +129,20 @@ namespace graphene { namespace peerplays_sidechain {
std::string walletprocesspsbt(std::string const &tx_psbt); std::string walletprocesspsbt(std::string const &tx_psbt);
bool walletpassphrase(const std::string &passphrase, uint32_t timeout = 60); bool walletpassphrase(const std::string &passphrase, uint32_t timeout = 60);
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.
@ -164,25 +163,25 @@ namespace graphene { namespace peerplays_sidechain {
OPERATION_DELEGATE_CALL OPERATION_DELEGATE_CALL
}; };
static constexpr const char*const default_prev_addr = "0000000000000000000000000000000000000001"; static constexpr const char *const default_prev_addr = "0000000000000000000000000000000000000001";
std::string encode_function_signature(const std::string& function_signature); std::string encode_function_signature(const std::string &function_signature);
std::string encode_address(const std::string& addr); std::string encode_address(const std::string &addr);
std::string encode_uint256(const std::string& value); std::string encode_uint256(const std::string &value);
std::string encode_uint8(uint8_t value); std::string encode_uint8(uint8_t value);
std::string encode_bytes(const std::string& values); std::string encode_bytes(const std::string &values);
}; };
class safe_transaction_encoder { class safe_transaction_encoder {
public: public:
static constexpr const char*const default_safe_tx_gas = "0"; static constexpr const char *const default_safe_tx_gas = "0";
static constexpr const char*const default_data_gas = "0"; static constexpr const char *const default_data_gas = "0";
static constexpr const char*const default_gas_price = "0"; static constexpr const char *const default_gas_price = "0";
static constexpr const char*const default_gas_token = "0000000000000000000000000000000000000000"; static constexpr const char *const default_gas_token = "0000000000000000000000000000000000000000";
static constexpr const char*const default_refund_receiver = "0000000000000000000000000000000000000000"; static constexpr const char *const default_refund_receiver = "0000000000000000000000000000000000000000";
std::string create_safe_address(const std::vector<std::string>& owner_addresses, uint32_t threshold); std::string create_safe_address(const std::vector<std::string> &owner_addresses, uint32_t threshold);
std::string build_transaction(const std::string& safe_account_addr, const std::string& value, const std::string& data, uint8_t operation, const std::string& safeTxGas, const std::string& dataGas, const std::string& gasPrice, const std::string& gasToken, const std::string& refundReceiver); std::string build_transaction(const std::string &safe_account_addr, const std::string &value, const std::string &data, uint8_t operation, const std::string &safeTxGas, const std::string &dataGas, const std::string &gasPrice, const std::string &gasToken, const std::string &refundReceiver);
private: private:
ethereum_function_call_encoder m_ethereum_function_call_encoder; ethereum_function_call_encoder m_ethereum_function_call_encoder;
@ -214,14 +213,14 @@ namespace graphene { namespace peerplays_sidechain {
client m_endpoint; client m_endpoint;
websocketpp::connection_hdl m_hdl; websocketpp::connection_hdl m_hdl;
}; };
// ============================================================================= // =============================================================================
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();
@ -232,7 +231,7 @@ namespace graphene { namespace peerplays_sidechain {
std::string send_sidechain_transaction(const sidechain_transaction_object &sto); std::string send_sidechain_transaction(const sidechain_transaction_object &sto);
bool settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount); bool settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount);
private: private:
std::string url; std::string url;
uint32_t rpc_port; uint32_t rpc_port;
@ -265,6 +264,6 @@ namespace graphene { namespace peerplays_sidechain {
std::vector<char> parse_hex(const std::string &str); std::vector<char> parse_hex(const std::string &str);
fc::ecc::public_key_data create_public_key_data(const std::vector<char> &public_key); fc::ecc::public_key_data create_public_key_data(const std::vector<char> &public_key);
}; };
}} // namespace graphene::peerplays_sidechain }} // namespace graphene::peerplays_sidechain

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>
@ -28,51 +28,51 @@ extern "C" {
} }
namespace graphene { namespace peerplays_sidechain { namespace graphene { namespace peerplays_sidechain {
std::string eth_rpc_client::Transaction::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) { std::string eth_rpc_client::Transaction::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) {
std::string m_data_str(m_data.begin(), m_data.end()); std::string m_data_str(m_data.begin(), m_data.end());
std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\":\"account_signTransaction\",\"params\":[{\"from\": \"%1%\", \"gas\": \"%2%\", \"gasPrice\": \"%3%\", \"input\": \"%4%\", \"nonce\": \"%5%\", \"to\": \"%6%\", \"value\": \"%7%\" }],\"id\":%8%}") % from.c_str() % m_gas.str() % m_gasPrice.str() % m_data_str % m_nonce.str() % to.c_str() % m_value.str() % tx_id.c_str()); std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\":\"account_signTransaction\",\"params\":[{\"from\": \"%1%\", \"gas\": \"%2%\", \"gasPrice\": \"%3%\", \"input\": \"%4%\", \"nonce\": \"%5%\", \"to\": \"%6%\", \"value\": \"%7%\" }],\"id\":%8%}") % from.c_str() % m_gas.str() % m_gasPrice.str() % m_data_str % m_nonce.str() % to.c_str() % m_value.str() % tx_id.c_str());
return req; return req;
} }
// ============================================================================= // =============================================================================
std::string eth_rpc_client::ethereum_function_call_encoder::encode_function_signature(const std::string& function_signature) { std::string eth_rpc_client::ethereum_function_call_encoder::encode_function_signature(const std::string &function_signature) {
sha3_context c; sha3_context c;
char *hash; char *hash;
sha3_Init256(static_cast<void*>(&c)); sha3_Init256(static_cast<void *>(&c));
sha3_SetFlags(&c, SHA3_FLAGS_KECCAK); sha3_SetFlags(&c, SHA3_FLAGS_KECCAK);
sha3_Update(&c, "abc", 3); sha3_Update(&c, "abc", 3);
hash = (char*)sha3_Finalize(&c); hash = (char *)sha3_Finalize(&c);
std::string output(hash); std::string output(hash);
output = output.substr(0,8); output = output.substr(0, 8);
return output; return output;
}; };
std::string eth_rpc_client::ethereum_function_call_encoder::encode_address(const std::string& addr) { std::string eth_rpc_client::ethereum_function_call_encoder::encode_address(const std::string &addr) {
FC_ASSERT(40 == addr.length()); FC_ASSERT(40 == addr.length());
std::string output = str(boost::format("%024u") % 0) + addr; std::string output = str(boost::format("%024u") % 0) + addr;
return output; return output;
} }
std::string eth_rpc_client::ethereum_function_call_encoder::encode_uint256(const std::string& value) { std::string eth_rpc_client::ethereum_function_call_encoder::encode_uint256(const std::string &value) {
FC_ASSERT(value.length() <= 64); FC_ASSERT(value.length() <= 64);
std::string output = std::string(64 - value.length(), '0') + value; std::string output = std::string(64 - value.length(), '0') + value;
return output; return output;
} }
std::string eth_rpc_client::ethereum_function_call_encoder::encode_uint8(uint8_t value) { std::string eth_rpc_client::ethereum_function_call_encoder::encode_uint8(uint8_t value) {
std::string output = str(boost::format("%02X") % value) + std::string(62, '0'); std::string output = str(boost::format("%02X") % value) + std::string(62, '0');
return output; return output;
} }
std::string eth_rpc_client::ethereum_function_call_encoder::encode_bytes(const std::string& values) { std::string eth_rpc_client::ethereum_function_call_encoder::encode_bytes(const std::string &values) {
size_t len = values.length(); size_t len = values.length();
std::string output = encode_uint256((boost::format("%x") % len).str()) + values + std::string(64 - len, '0'); std::string output = encode_uint256((boost::format("%x") % len).str()) + values + std::string(64 - len, '0');
return output; return output;
} }
std::string eth_rpc_client::safe_transaction_encoder::create_safe_address(const std::vector<std::string>& owner_addresses, uint32_t threshold) { std::string eth_rpc_client::safe_transaction_encoder::create_safe_address(const std::vector<std::string> &owner_addresses, uint32_t threshold) {
//createProxyWithNonce(address,bytes,uint256) //createProxyWithNonce(address,bytes,uint256)
std::string method_id = m_ethereum_function_call_encoder.encode_function_signature("createProxyWithNonce(address,bytes,uint256)"); std::string method_id = m_ethereum_function_call_encoder.encode_function_signature("createProxyWithNonce(address,bytes,uint256)");
FC_ASSERT("1688f0b9" == method_id); FC_ASSERT("1688f0b9" == method_id);
@ -80,9 +80,9 @@ namespace graphene { namespace peerplays_sidechain {
std::string data = "0x1688f0b9000000000000000000000000d9db270c1b5e3bd161e8c8503c55ceabee70955200000000000000000000000000000000000000000000000000000000000000604fa262bd05cdef2e3d5261787ee66d9447a4036324990e04380339bec83b4c7a0000000000000000000000000000000000000000000000000000000000000264b63e800d0000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000220000000000000000000000000f48f2b2d2a534e402487b3ee7c18c33aec0fe5e400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000005FbBb31BE52608D2F52247E8400B7fCaA9E0bC1200000000000000000000000076ce31BD03f601c3fC13732deF921c5Bac28267600000000000000000000000009EE460834498a4ee361beB819470061B7381B490000000000000000000000006AEFbd09209e1eE2e0a589d31e732F69B77713D2000000000000000000000000631e128b16f9aDCF1bB6385112B1519C917D77a7000000000000000000000000cD5C788e84220E8b8934Ea4F1dC6a12009bCc91D0000000000000000000000003627C1B31525887CB9441130C831e3588765030500000000000000000000000003A13a989AF30C92AD7ABD1E6210308A6c96f3730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"; std::string data = "0x1688f0b9000000000000000000000000d9db270c1b5e3bd161e8c8503c55ceabee70955200000000000000000000000000000000000000000000000000000000000000604fa262bd05cdef2e3d5261787ee66d9447a4036324990e04380339bec83b4c7a0000000000000000000000000000000000000000000000000000000000000264b63e800d0000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000220000000000000000000000000f48f2b2d2a534e402487b3ee7c18c33aec0fe5e400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000005FbBb31BE52608D2F52247E8400B7fCaA9E0bC1200000000000000000000000076ce31BD03f601c3fC13732deF921c5Bac28267600000000000000000000000009EE460834498a4ee361beB819470061B7381B490000000000000000000000006AEFbd09209e1eE2e0a589d31e732F69B77713D2000000000000000000000000631e128b16f9aDCF1bB6385112B1519C917D77a7000000000000000000000000cD5C788e84220E8b8934Ea4F1dC6a12009bCc91D0000000000000000000000003627C1B31525887CB9441130C831e3588765030500000000000000000000000003A13a989AF30C92AD7ABD1E6210308A6c96f3730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
return data; return data;
} }
std::string eth_rpc_client::safe_transaction_encoder::build_transaction(const std::string& safe_account_addr, const std::string& value, const std::string& data, uint8_t operation, const std::string& safeTxGas, const std::string& dataGas, const std::string& gasPrice, const std::string& gasToken, const std::string& refundReceiver){ std::string eth_rpc_client::safe_transaction_encoder::build_transaction(const std::string &safe_account_addr, const std::string &value, const std::string &data, uint8_t operation, const std::string &safeTxGas, const std::string &dataGas, const std::string &gasPrice, const std::string &gasToken, const std::string &refundReceiver) {
//execTransaction method of smart contract , using safe-account address //execTransaction method of smart contract , using safe-account address
//execTransaction(address to, uint256 value, bytes data, uint8 operation, uint256 safeTxGas, uint256 dataGas, uint256 gasPrice, address gasToken, address refundReceiver, bytes signatures) //execTransaction(address to, uint256 value, bytes data, uint8 operation, uint256 safeTxGas, uint256 dataGas, uint256 gasPrice, address gasToken, address refundReceiver, bytes signatures)
std::string method_id = m_ethereum_function_call_encoder.encode_function_signature("execTransaction(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,bytes)"); std::string method_id = m_ethereum_function_call_encoder.encode_function_signature("execTransaction(address,uint256,bytes,uint8,uint256,uint256,uint256,address,address,bytes)");
@ -107,10 +107,10 @@ namespace graphene { namespace peerplays_sidechain {
std::string message = method_id + to + value_encoded + data + operation_encoded + safeTxGas_encoded + dataGas_encoded + gasPrice_encoded + gasToken_encoded + refundReceiver_encoded; std::string message = method_id + to + value_encoded + data + operation_encoded + safeTxGas_encoded + dataGas_encoded + gasPrice_encoded + gasToken_encoded + refundReceiver_encoded;
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;
@ -127,23 +127,22 @@ namespace graphene { namespace peerplays_sidechain {
m_endpoint.init_asio(); m_endpoint.init_asio();
// Register our handlers // Register our handlers
m_endpoint.set_socket_init_handler(bind(&type::on_socket_init,this,::_1)); m_endpoint.set_socket_init_handler(bind(&type::on_socket_init, this, ::_1));
m_endpoint.set_message_handler(bind(&type::on_message,this,::_1,::_2)); m_endpoint.set_message_handler(bind(&type::on_message, this, ::_1, ::_2));
m_endpoint.set_open_handler(bind(&type::on_open,this,::_1)); m_endpoint.set_open_handler(bind(&type::on_open, this, ::_1));
m_endpoint.set_close_handler(bind(&type::on_close,this,::_1)); m_endpoint.set_close_handler(bind(&type::on_close, this, ::_1));
m_endpoint.set_fail_handler(bind(&type::on_fail,this,::_1)); m_endpoint.set_fail_handler(bind(&type::on_fail, this, ::_1));
} }
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();
if (ec) { if (ec) {
m_endpoint.get_alog().write(websocketpp::log::alevel::app,ec.message()); m_endpoint.get_alog().write(websocketpp::log::alevel::app, ec.message());
return; return;
} }
@ -152,28 +151,28 @@ namespace graphene { namespace peerplays_sidechain {
// Start the ASIO io_service run loop // Start the ASIO io_service run loop
m_endpoint.run(); m_endpoint.run();
}); });
} }
void eth_rpc_client::stop() { void eth_rpc_client::stop() {
m_endpoint.close(m_hdl,websocketpp::close::status::normal,""); m_endpoint.close(m_hdl, websocketpp::close::status::normal, "");
} }
void eth_rpc_client::on_socket_init(websocketpp::connection_hdl) { void eth_rpc_client::on_socket_init(websocketpp::connection_hdl) {
} }
void eth_rpc_client::on_fail(websocketpp::connection_hdl hdl) { void eth_rpc_client::on_fail(websocketpp::connection_hdl hdl) {
client::connection_ptr con = m_endpoint.get_con_from_hdl(hdl); client::connection_ptr con = m_endpoint.get_con_from_hdl(hdl);
elog("Ethereum websocket fail"); elog("Ethereum websocket fail");
//elog("get_state: ${state}", ("state", con->get_state() ) ); //elog("get_state: ${state}", ("state", con->get_state() ) );
elog("get_local_close_code: ${code}", ("code", con->get_local_close_code())); elog("get_local_close_code: ${code}", ("code", con->get_local_close_code()));
elog("get_local_close_reason: ${close}", ("close",con->get_local_close_reason())); elog("get_local_close_reason: ${close}", ("close", con->get_local_close_reason()));
elog("get_remote_close_code: ${close}", ("close", con->get_remote_close_code())); elog("get_remote_close_code: ${close}", ("close", con->get_remote_close_code()));
elog("get_remote_close_reason: ${close}", ("close", con->get_remote_close_reason())); elog("get_remote_close_reason: ${close}", ("close", con->get_remote_close_reason()));
elog("get_ec().message(): ${ec}", ("ec", con->get_ec().message())); elog("get_ec().message(): ${ec}", ("ec", con->get_ec().message()));
} }
void eth_rpc_client::on_open(websocketpp::connection_hdl hdl) { void eth_rpc_client::on_open(websocketpp::connection_hdl hdl) {
std::string str = "{\"jsonrpc\":\"2.0\",\"method\":\"eth_chainId\",\"params\":[],\"id\":84}"; std::string str = "{\"jsonrpc\":\"2.0\",\"method\":\"eth_chainId\",\"params\":[],\"id\":84}";
ilog("on_open: ${str}", ("str", str)); ilog("on_open: ${str}", ("str", str));
m_endpoint.send(hdl, str.c_str(), websocketpp::frame::opcode::text); m_endpoint.send(hdl, str.c_str(), websocketpp::frame::opcode::text);
@ -181,35 +180,35 @@ namespace graphene { namespace peerplays_sidechain {
vector<std::string> owner_addresses; vector<std::string> owner_addresses;
std::string private_key = ""; std::string private_key = "";
createmultisig(5, owner_addresses, private_key); createmultisig(5, owner_addresses, private_key);
} }
void eth_rpc_client::on_message(websocketpp::connection_hdl hdl, message_ptr msg) { void eth_rpc_client::on_message(websocketpp::connection_hdl hdl, message_ptr msg) {
ilog("on_message: ${msg}", ("msg", msg->get_payload())); ilog("on_message: ${msg}", ("msg", msg->get_payload()));
fc::variants list = fc::json::variants_from_string( msg->get_payload() ); fc::variants list = fc::json::variants_from_string(msg->get_payload());
ilog("json reposnse: ${list}", ("list", list)); ilog("json reposnse: ${list}", ("list", list));
const auto& b_obj = list[0].get_object().find( "id" ); const auto &b_obj = list[0].get_object().find("id");
if (true == list[0].get_object().contains( "error" )){ if (true == list[0].get_object().contains("error")) {
elog("error in json reposnse: ${list}", ("list", list)); elog("error in json reposnse: ${list}", ("list", list));
return; return;
} }
std::string result_str = list[0].get_object().find( "result" )->value().as<std::string>(1); std::string result_str = list[0].get_object().find("result")->value().as<std::string>(1);
uint32_t num_owners = 0; uint32_t num_owners = 0;
uint32_t i = 0; uint32_t i = 0;
fc::variant v; fc::variant v;
switch(b_obj->value().as<uint32_t>(1)){ switch (b_obj->value().as<uint32_t>(1)) {
case ETH_CHAIN_ID: case ETH_CHAIN_ID:
chain_id = result_str; chain_id = result_str;
break; break;
case ETH_GET_TRANSACTION_RECEIPT: case ETH_GET_TRANSACTION_RECEIPT:
list = fc::json::variants_from_string( result_str ); list = fc::json::variants_from_string(result_str);
v = list[0].get_object().find( "logs" )->value(); v = list[0].get_object().find("logs")->value();
safe_account_addr = v.get_object().find( "address" )->value().as<std::string>(1); safe_account_addr = v.get_object().find("address")->value().as<std::string>(1);
break; break;
case ETH_CALL: case ETH_CALL:
break; break;
@ -233,8 +232,8 @@ namespace graphene { namespace peerplays_sidechain {
case GET_LIST_OWNERS: case GET_LIST_OWNERS:
num_owners = (uint32_t)strtol(result_str.substr(2 + 32 + 32 - 4, 4).c_str(), NULL, 16); num_owners = (uint32_t)strtol(result_str.substr(2 + 32 + 32 - 4, 4).c_str(), NULL, 16);
owners.clear(); owners.clear();
for (i = 0; i < num_owners; ++i){ for (i = 0; i < num_owners; ++i) {
owners.push_back("0x" + result_str.substr(2 + 32 + 32 + 12 + 32 * i,20)); owners.push_back("0x" + result_str.substr(2 + 32 + 32 + 12 + 32 * i, 20));
} }
break; break;
case ADD_OWNER: case ADD_OWNER:
@ -242,97 +241,97 @@ namespace graphene { namespace peerplays_sidechain {
case REMOVE_OWNER: case REMOVE_OWNER:
break; break;
} }
} }
void eth_rpc_client::on_close(websocketpp::connection_hdl) { void eth_rpc_client::on_close(websocketpp::connection_hdl) {
ilog("Ethereum websocket close"); ilog("Ethereum websocket close");
} }
uint64_t eth_rpc_client::get_chain_id() { uint64_t eth_rpc_client::get_chain_id() {
std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\":\"eth_chainId\",\"params\":[],\"id\":%1%}") % t_id); std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\":\"eth_chainId\",\"params\":[],\"id\":%1%}") % t_id);
ilog("get_chain_id: ${req}", ("req", req.c_str())); ilog("get_chain_id: ${req}", ("req", req.c_str()));
m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text); m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text);
m_requests[t_id] = req_t::ETH_CHAIN_ID; m_requests[t_id] = req_t::ETH_CHAIN_ID;
return t_id++; return t_id++;
} }
uint64_t eth_rpc_client::eth_getTransactionReceipt(const std::string& tx_id) { uint64_t eth_rpc_client::eth_getTransactionReceipt(const std::string &tx_id) {
std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\":\"eth_getTransactionReceipt\",\"params\":[\"%1%\"],\"id\":%2%}") % tx_id.c_str() % t_id); std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\":\"eth_getTransactionReceipt\",\"params\":[\"%1%\"],\"id\":%2%}") % tx_id.c_str() % t_id);
ilog("eth_getTransactionReceipt: ${req}", ("req", req.c_str())); ilog("eth_getTransactionReceipt: ${req}", ("req", req.c_str()));
m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text); m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text);
m_requests[t_id] = req_t::ETH_GET_TRANSACTION_RECEIPT; m_requests[t_id] = req_t::ETH_GET_TRANSACTION_RECEIPT;
return t_id++; return t_id++;
} }
uint64_t eth_rpc_client::eth_call(const std::string& to, const std::string& data) { uint64_t eth_rpc_client::eth_call(const std::string &to, const std::string &data) {
std::string req = str(boost::format("{\"jsonrpc\": \"2.0\", \"method\": \"eth_call\", \"params\": [{\"to\": \"%1%\", \"data\": \"%2%\"}, \"latest\"], \"id\": %3%}") % to.c_str() % data.c_str() % t_id); std::string req = str(boost::format("{\"jsonrpc\": \"2.0\", \"method\": \"eth_call\", \"params\": [{\"to\": \"%1%\", \"data\": \"%2%\"}, \"latest\"], \"id\": %3%}") % to.c_str() % data.c_str() % t_id);
ilog("eth_call: ${req}", ("req", req.c_str())); ilog("eth_call: ${req}", ("req", req.c_str()));
m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text); m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text);
m_requests[t_id] = req_t::ETH_CALL; m_requests[t_id] = req_t::ETH_CALL;
return t_id++; return t_id++;
} }
uint64_t eth_rpc_client::eth_sendTransaction(const std::string& from, const std::string& to, const std::string& data) { uint64_t eth_rpc_client::eth_sendTransaction(const std::string &from, const std::string &to, const std::string &data) {
std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\": \"eth_sendTransaction\", \"params\": [{\"from\": \"%1%\", \"to\": \"%2%\", \"data\": \"%3%\"}], \"id\": %4%}") % from.c_str() % to.c_str() % data.c_str() % t_id); std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\": \"eth_sendTransaction\", \"params\": [{\"from\": \"%1%\", \"to\": \"%2%\", \"data\": \"%3%\"}], \"id\": %4%}") % from.c_str() % to.c_str() % data.c_str() % t_id);
ilog("eth_sendTransaction: ${req}", ("req", req.c_str())); ilog("eth_sendTransaction: ${req}", ("req", req.c_str()));
m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text); m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text);
m_requests[t_id] = req_t::ETH_SEND_TRANSACTION; m_requests[t_id] = req_t::ETH_SEND_TRANSACTION;
return t_id++; return t_id++;
} }
uint64_t eth_rpc_client::eth_sendRawTransaction(const std::string& params) { uint64_t eth_rpc_client::eth_sendRawTransaction(const std::string &params) {
std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\":\"eth_sendRawTransaction\",\"params\":[\"%1%\"],\"id\":%2%}") % params.c_str() % t_id); std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\":\"eth_sendRawTransaction\",\"params\":[\"%1%\"],\"id\":%2%}") % params.c_str() % t_id);
ilog("eth_sendRawTransaction: ${req}", ("req", req.c_str())); ilog("eth_sendRawTransaction: ${req}", ("req", req.c_str()));
m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text); m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text);
m_requests[t_id] = req_t::ETH_SEND_RAW_TRANSACTION; m_requests[t_id] = req_t::ETH_SEND_RAW_TRANSACTION;
return t_id++; return t_id++;
} }
uint64_t eth_rpc_client::eth_getCode(const std::string& addr) { uint64_t eth_rpc_client::eth_getCode(const std::string &addr) {
std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\": \"eth_getCode\", \"params\": [\"%1%\",\"latest\"], \"id\": %2%}") % addr.c_str() % t_id); std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\": \"eth_getCode\", \"params\": [\"%1%\",\"latest\"], \"id\": %2%}") % addr.c_str() % t_id);
ilog("eth_getCode: ${req}", ("req", req.c_str())); ilog("eth_getCode: ${req}", ("req", req.c_str()));
m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text); m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text);
m_requests[t_id] = req_t::ETH_GET_CODE; m_requests[t_id] = req_t::ETH_GET_CODE;
return t_id++; return t_id++;
} }
uint64_t eth_rpc_client::eth_getBalance(const std::string& addr) { uint64_t eth_rpc_client::eth_getBalance(const std::string &addr) {
std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\": \"eth_getBalance\", \"params\": [\"%1%\",\"latest\"], \"id\": %2%}") % addr.c_str() % t_id); std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\": \"eth_getBalance\", \"params\": [\"%1%\",\"latest\"], \"id\": %2%}") % addr.c_str() % t_id);
ilog("eth_getBalance: ${req}", ("req", req.c_str())); ilog("eth_getBalance: ${req}", ("req", req.c_str()));
m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text); m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text);
m_requests[t_id] = req_t::ETH_GET_BALANCE; m_requests[t_id] = req_t::ETH_GET_BALANCE;
return t_id++; return t_id++;
} }
uint64_t eth_rpc_client::eth_sign(const string& addr, const string& message) { uint64_t eth_rpc_client::eth_sign(const string &addr, const string &message) {
std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\": \"eth_sign\", \"params\": [\"%1%\",\"%2%\"], \"id\": %2%}") % addr.c_str() % message.c_str() % t_id); std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\": \"eth_sign\", \"params\": [\"%1%\",\"%2%\"], \"id\": %2%}") % addr.c_str() % message.c_str() % t_id);
ilog("eth_sign: ${req}", ("req", req.c_str())); ilog("eth_sign: ${req}", ("req", req.c_str()));
m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text); m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text);
m_requests[t_id] = req_t::ETH_SIGN; m_requests[t_id] = req_t::ETH_SIGN;
return t_id++; return t_id++;
} }
uint64_t eth_rpc_client::eth_coinbase() { uint64_t eth_rpc_client::eth_coinbase() {
std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\":\"eth_coinbase\",\"params\":[],\"id\":%1%}") % t_id); std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\":\"eth_coinbase\",\"params\":[],\"id\":%1%}") % t_id);
ilog("eth_coinbase: ${req}", ("req", req.c_str())); ilog("eth_coinbase: ${req}", ("req", req.c_str()));
m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text); m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text);
m_requests[t_id] = req_t::ETH_COINBASE; m_requests[t_id] = req_t::ETH_COINBASE;
return t_id++; return t_id++;
} }
uint64_t eth_rpc_client::get_list_owners(const std::string& safe_account) { uint64_t eth_rpc_client::get_list_owners(const std::string &safe_account) {
//getOwners() //getOwners()
std::string method_id = m_ethereum_function_call_encoder.encode_function_signature("getOwners()"); std::string method_id = m_ethereum_function_call_encoder.encode_function_signature("getOwners()");
FC_ASSERT("a0e67e2b" == method_id); FC_ASSERT("a0e67e2b" == method_id);
return eth_call(safe_account.c_str(), method_id); return eth_call(safe_account.c_str(), method_id);
} }
uint64_t eth_rpc_client::add_owner(const std::string& addr ) { uint64_t eth_rpc_client::add_owner(const std::string &addr) {
if (std::count(owners.begin(), owners.end(), addr)){ if (std::count(owners.begin(), owners.end(), addr)) {
FC_THROW_EXCEPTION(fc::exception, "Owners allready have addr: ${addr}", ("addr", addr)); FC_THROW_EXCEPTION(fc::exception, "Owners allready have addr: ${addr}", ("addr", addr));
} }
@ -349,14 +348,14 @@ namespace graphene { namespace peerplays_sidechain {
m_requests[t_id] = req_t::ADD_OWNER; m_requests[t_id] = req_t::ADD_OWNER;
return 0; return 0;
} }
uint64_t eth_rpc_client::remove_owner(const std::string& addr, uint32_t threshold) { uint64_t eth_rpc_client::remove_owner(const std::string &addr, uint32_t threshold) {
if (!std::count(owners.begin(), owners.end(), addr)){ if (!std::count(owners.begin(), owners.end(), addr)) {
FC_THROW_EXCEPTION(fc::exception, "Owners does not have addr: ${addr}", ("addr", addr)); FC_THROW_EXCEPTION(fc::exception, "Owners does not have addr: ${addr}", ("addr", addr));
} }
if (threshold == owners.size()){ if (threshold == owners.size()) {
FC_THROW_EXCEPTION(fc::exception, "Owners size does not meet threshold: ${th}", ("th", threshold)); FC_THROW_EXCEPTION(fc::exception, "Owners size does not meet threshold: ${th}", ("th", threshold));
} }
@ -372,17 +371,17 @@ namespace graphene { namespace peerplays_sidechain {
m_requests[t_id] = req_t::REMOVE_OWNER; m_requests[t_id] = req_t::REMOVE_OWNER;
return 0; return 0;
} }
std::string eth_rpc_client::addmultisigaddress(const uint32_t nrequired, const std::vector<std::string> public_keys) { std::string eth_rpc_client::addmultisigaddress(const uint32_t nrequired, const std::vector<std::string> public_keys) {
return ""; return "";
} }
std::string eth_rpc_client::combinepsbt(const vector<std::string> &psbts) { std::string eth_rpc_client::combinepsbt(const vector<std::string> &psbts) {
return ""; return "";
} }
uint64_t eth_rpc_client::createmultisig(const uint32_t nrequired, const std::vector<std::string> owner_addresses, const std::string &private_key) { uint64_t eth_rpc_client::createmultisig(const uint32_t nrequired, const std::vector<std::string> owner_addresses, const std::string &private_key) {
ilog("createmultisig: ${key}", ("key", private_key.c_str())); ilog("createmultisig: ${key}", ("key", private_key.c_str()));
//That's will create //That's will create
@ -395,107 +394,106 @@ 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);
return eth_sendTransaction(from, to, data); return eth_sendTransaction(from, to, data);
} }
std::string eth_rpc_client::createpsbt() { std::string eth_rpc_client::createpsbt() {
} }
std::string eth_rpc_client::createrawtransaction() { std::string eth_rpc_client::createrawtransaction() {
return ""; return "";
} }
std::string eth_rpc_client::createwallet(const std::string &wallet_name) { std::string eth_rpc_client::createwallet(const std::string &wallet_name) {
return ""; return "";
} }
std::string eth_rpc_client::decodepsbt(std::string const &tx_psbt) { std::string eth_rpc_client::decodepsbt(std::string const &tx_psbt) {
return ""; return "";
} }
std::string eth_rpc_client::decoderawtransaction(std::string const &tx_hex) { std::string eth_rpc_client::decoderawtransaction(std::string const &tx_hex) {
return ""; return "";
} }
std::string eth_rpc_client::encryptwallet(const std::string &passphrase) { std::string eth_rpc_client::encryptwallet(const std::string &passphrase) {
return ""; return "";
} }
uint64_t eth_rpc_client::estimatesmartfee(uint16_t conf_target) { uint64_t eth_rpc_client::estimatesmartfee(uint16_t conf_target) {
return 20000; return 20000;
} }
std::string eth_rpc_client::finalizepsbt(std::string const &tx_psbt) { std::string eth_rpc_client::finalizepsbt(std::string const &tx_psbt) {
return ""; return "";
} }
std::string eth_rpc_client::getaddressinfo(const std::string &address) { std::string eth_rpc_client::getaddressinfo(const std::string &address) {
return ""; return "";
} }
std::string eth_rpc_client::getblock(const std::string &block_hash, int32_t verbosity) { std::string eth_rpc_client::getblock(const std::string &block_hash, int32_t verbosity) {
return ""; return "";
} }
std::string eth_rpc_client::getnetworkinfo() { std::string eth_rpc_client::getnetworkinfo() {
return ""; return "";
} }
std::string eth_rpc_client::getrawtransaction(const std::string &txid, const bool verbose) { std::string eth_rpc_client::getrawtransaction(const std::string &txid, const bool verbose) {
return ""; return "";
} }
std::string eth_rpc_client::gettransaction(const std::string &txid, const bool include_watch_only) { std::string eth_rpc_client::gettransaction(const std::string &txid, const bool include_watch_only) {
return ""; return "";
} }
std::string eth_rpc_client::getblockchaininfo() { std::string eth_rpc_client::getblockchaininfo() {
return ""; return "";
} }
void eth_rpc_client::importaddress(const std::string &address_or_script, const std::string &label, const bool rescan, const bool p2sh) { void eth_rpc_client::importaddress(const std::string &address_or_script, const std::string &label, const bool rescan, const bool p2sh) {
return; return;
} }
void eth_rpc_client::importmulti(const std::vector<multi_params> &address_or_script_array, const bool rescan) { void eth_rpc_client::importmulti(const std::vector<multi_params> &address_or_script_array, const bool rescan) {
} }
std::string eth_rpc_client::loadwallet(const std::string &filename) { std::string eth_rpc_client::loadwallet(const std::string &filename) {
return ""; return "";
} }
std::string eth_rpc_client::sendrawtransaction(const std::string &tx_hex) { std::string eth_rpc_client::sendrawtransaction(const std::string &tx_hex) {
return ""; return "";
} }
std::string eth_rpc_client::signrawtransactionwithwallet(const std::string &tx_hash) { std::string eth_rpc_client::signrawtransactionwithwallet(const std::string &tx_hash) {
return ""; return "";
} }
std::string eth_rpc_client::unloadwallet(const std::string &filename) { std::string eth_rpc_client::unloadwallet(const std::string &filename) {
return ""; return "";
} }
std::string eth_rpc_client::walletlock() { std::string eth_rpc_client::walletlock() {
return ""; return "";
} }
std::string eth_rpc_client::walletprocesspsbt(std::string const &tx_psbt) { std::string eth_rpc_client::walletprocesspsbt(std::string const &tx_psbt) {
return ""; return "";
} }
bool eth_rpc_client::walletpassphrase(const std::string &passphrase, uint32_t timeout) { bool eth_rpc_client::walletpassphrase(const std::string &passphrase, uint32_t timeout) {
return false; return false;
} }
// ============================================================================= // =============================================================================
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()));
/* /*
@ -819,10 +817,10 @@ elog("==================================================");
return should_approve; 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,32 +1044,33 @@ 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 << "\",";
} }
ss.seekp(-1, std::ios_base::end); ss.seekp(-1, std::ios_base::end);
@ -1090,31 +1089,31 @@ 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));
ethereum::signed_transaction htrx; ethereum::signed_transaction htrx;
fc::raw::unpack(ss_trx, htrx, 1000); fc::raw::unpack(ss_trx, htrx, 1000);
std::string chain_id_str = eth_client->chain_id;//eth_rpc_client->get_chain_id(); std::string chain_id_str = eth_client->chain_id; //eth_rpc_client->get_chain_id();
const ethereum::chain_id_type chain_id(chain_id_str); const ethereum::chain_id_type chain_id(chain_id_str);
fc::optional<fc::ecc::private_key> privkey = graphene::utilities::wif_to_key(get_private_key(plugin.get_current_son_object().sidechain_public_keys.at(sidechain))); fc::optional<fc::ecc::private_key> privkey = graphene::utilities::wif_to_key(get_private_key(plugin.get_current_son_object().sidechain_public_keys.at(sidechain)));
@ -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++) {