ethereum_function_call_encoder

This commit is contained in:
Pavel Baykov 2022-06-03 09:17:10 -03:00
parent 61923c797f
commit 854e5ccb44
4 changed files with 66 additions and 4 deletions

View file

@ -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

@ -1 +1 @@
Subproject commit e7369949bea26f3201d8442ba78286a88df74762
Subproject commit c24b2df96d949f25ff85ca0aae5e17da111bde79

View file

@ -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;

View file

@ -20,9 +20,49 @@
#include <graphene/utilities/key_conversion.hpp>
#include <fc/io/json.hpp>
extern "C" {
#include <sha3.h>
}
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<void*>(&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<fc::ecc::private_key> 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) {