From 854e5ccb44c5eb533de27c6e3d35543280bde1ad Mon Sep 17 00:00:00 2001 From: Pavel Baykov Date: Fri, 3 Jun 2022 09:17:10 -0300 Subject: [PATCH] ethereum_function_call_encoder --- CMakeLists.txt | 1 + libraries/fc | 2 +- .../sidechain_net_handler_eth.hpp | 9 ++- .../sidechain_net_handler_eth.cpp | 58 ++++++++++++++++++- 4 files changed, 66 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 695881be..1d4c2f1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,7 @@ if(CMAKE_SYSTEM_NAME MATCHES "Linux") list(GET arg_list 0 output) message("Ubuntu version is: ${output}") add_definitions(-DPEERPLAYS_UBUNTU_VERSION=${output}) + endif() # function to help with cUrl diff --git a/libraries/fc b/libraries/fc index e7369949..c24b2df9 160000 --- a/libraries/fc +++ b/libraries/fc @@ -1 +1 @@ -Subproject commit e7369949bea26f3201d8442ba78286a88df74762 +Subproject commit c24b2df96d949f25ff85ca0aae5e17da111bde79 diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_eth.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_eth.hpp index 95d333cd..505bc3a4 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_eth.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_eth.hpp @@ -66,7 +66,6 @@ public: std::string label; }; -public: eth_rpc_client(const std::string &url, const std::string &user_name, const std::string &password, bool debug_rpc_calls); void start(std::string uri); @@ -121,6 +120,14 @@ public: bool walletpassphrase(const std::string &passphrase, uint32_t timeout = 60); private: + class ethereum_function_call_encoder { + std::string encode_function_signature(const std::string& function_signature); + std::string encode_address(const std::string& addr); + std::string encode_uint256(const std::string& value); + std::string encode_uint8(uint8_t value); + std::string encode_bytes(const std::string& values); + }; + std::string geth_url; uint64_t t_id; std::string account_address; diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_eth.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_eth.cpp index 97540024..25464be8 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_eth.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_eth.cpp @@ -20,9 +20,49 @@ #include #include +extern "C" { +#include +} namespace graphene { namespace peerplays_sidechain { // ============================================================================= +std::string eth_rpc_client::ethereum_function_call_encoder::encode_function_signature(const std::string& function_signature) { + sha3_context c; + uint8_t *hash; + + sha3_Init256(static_cast(&c)); + sha3_Update(&c, "abc", 3); + hash = (uint8_t*)sha3_Finalize(&c); + +// 'hash' points to a buffer inside 'c' +// with the value of SHA3-256 +// + return ""; +}; + +std::string eth_rpc_client::ethereum_function_call_encoder::encode_address(const std::string& addr) { + FC_ASSERT(20 == addr.length()); + std::string output = str(boost::format("%012u") % 0) + addr; + return output; +} + +std::string eth_rpc_client::ethereum_function_call_encoder::encode_uint256(const std::string& value) { + FC_ASSERT(value.length() <= 64); + std::string output = std::string(64 - value.length(), '0') + value; + return output; +} + +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'); + return output; +} + +std::string eth_rpc_client::ethereum_function_call_encoder::encode_bytes(const std::string& values) { + size_t len = values.length(); + std::string output = encode_uint256((boost::format("%x") % len).str()) + values + std::string(64 - len, '0'); + return output; +} + eth_rpc_client::eth_rpc_client(const std::string &url, const std::string &user_name, const std::string &password, bool debug_rpc_calls) { geth_url = url; @@ -983,9 +1023,23 @@ std::string sidechain_net_handler_eth::create_transaction() { } std::string sidechain_net_handler_eth::sign_transaction(const sidechain_transaction_object &sto) { - std::string tx_signature;// = write_transaction_signatures(sigs); +/* + std::stringstream ss_trx(boost::algorithm::unhex(sto.transaction)); + hive::signed_transaction htrx; + fc::raw::unpack(ss_trx, htrx, 1000); + + std::string chain_id_str = node_rpc_client->get_chain_id(); + const hive::chain_id_type chain_id(chain_id_str); + + fc::optional privkey = graphene::utilities::wif_to_key(get_private_key(plugin.get_current_son_object().sidechain_public_keys.at(sidechain))); + signature_type st = htrx.sign(*privkey, chain_id); + + std::stringstream ss_st; + fc::raw::pack(ss_st, st, 1000); + std::string st_str = boost::algorithm::hex(ss_st.str()); +*/ + return "";//st_str; - return tx_signature; } std::string sidechain_net_handler_eth::send_transaction(const sidechain_transaction_object &sto) {