Merge branch 'feature/son-for-ethereum' into bug/issue416_corrected
This commit is contained in:
commit
27c8126b3f
13 changed files with 197 additions and 258 deletions
|
|
@ -51,7 +51,6 @@ 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
|
||||
|
|
|
|||
|
|
@ -84,9 +84,9 @@ sudo apt-get install \
|
|||
|
||||
Install Boost libraries from source
|
||||
```
|
||||
wget -c 'http://sourceforge.net/projects/boost/files/boost/1.67.0/boost_1_67_0.tar.bz2/download' -O boost_1_67_0.tar.bz2
|
||||
tar xjf boost_1_67_0.tar.bz2
|
||||
cd boost_1_67_0/
|
||||
wget -c 'https://boostorg.jfrog.io/artifactory/main/release/1.71.0/source/boost_1_71_0.tar.bz2' -O boost_1_71_0.tar.bz2
|
||||
tar xjf boost_1_71_0.tar.bz2
|
||||
cd boost_1_71_0/
|
||||
./bootstrap.sh
|
||||
sudo ./b2 install
|
||||
```
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@ namespace graphene { namespace peerplays_sidechain { namespace ethereum {
|
|||
|
||||
//! rlp_decoder
|
||||
|
||||
namespace
|
||||
{
|
||||
namespace {
|
||||
const signed char p_util_hexdigit[256] =
|
||||
{-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
|
||||
|
|
@ -28,21 +27,18 @@ const signed char p_util_hexdigit[256] =
|
|||
-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
|
||||
}
|
||||
|
||||
std::vector<std::string> rlp_decoder::decode(const std::string& str)
|
||||
{
|
||||
std::vector<std::string> rlp_decoder::decode(const std::string &str) {
|
||||
size_t consumed = 0;
|
||||
const auto raw_vec = parse_hex(str);
|
||||
const std::vector<std::string> rlp_array = decode_rlp(raw_vec.data(), raw_vec.size(), consumed);
|
||||
std::vector<std::string> result_array;
|
||||
for(const auto& rlp : decode_rlp(raw_vec.data(), raw_vec.size(), consumed))
|
||||
{
|
||||
for (const auto &rlp : decode_rlp(raw_vec.data(), raw_vec.size(), consumed)) {
|
||||
result_array.emplace_back(bytes2hex(rlp));
|
||||
}
|
||||
return result_array;
|
||||
}
|
||||
|
||||
std::vector<std::string> rlp_decoder::decode_rlp(const unsigned char *raw, size_t len, size_t& consumed)
|
||||
{
|
||||
std::vector<std::string> rlp_decoder::decode_rlp(const unsigned char *raw, size_t len, size_t &consumed) {
|
||||
std::vector<std::string> rlp_result;
|
||||
|
||||
consumed = 0;
|
||||
|
|
@ -51,14 +47,12 @@ std::vector<std::string> rlp_decoder::decode_rlp(const unsigned char *raw, size_
|
|||
const size_t prefixlen = 1;
|
||||
unsigned char ch = *raw;
|
||||
|
||||
if (len < 1)
|
||||
{
|
||||
if (len < 1) {
|
||||
return rlp_result;
|
||||
}
|
||||
|
||||
// Case 1: [prefix is 1-byte data buffer]
|
||||
if (ch <= 0x7f)
|
||||
{
|
||||
if (ch <= 0x7f) {
|
||||
const unsigned char *tok_start = raw;
|
||||
const unsigned char *tok_end = tok_start + prefixlen;
|
||||
FC_ASSERT(tok_end <= end);
|
||||
|
|
@ -70,8 +64,7 @@ std::vector<std::string> rlp_decoder::decode_rlp(const unsigned char *raw, size_
|
|||
consumed = buf.size();
|
||||
}
|
||||
// Case 2: [prefix, including buffer length][data]
|
||||
else if ((ch >= 0x80) && (ch <= 0xb7))
|
||||
{
|
||||
else if ((ch >= 0x80) && (ch <= 0xb7)) {
|
||||
const size_t blen = ch - 0x80;
|
||||
const size_t expected = prefixlen + blen;
|
||||
|
||||
|
|
@ -93,8 +86,7 @@ std::vector<std::string> rlp_decoder::decode_rlp(const unsigned char *raw, size_
|
|||
consumed = expected;
|
||||
}
|
||||
// Case 3: [prefix][buffer length][data]
|
||||
else if ((ch >= 0xb8) && (ch <= 0xbf))
|
||||
{
|
||||
else if ((ch >= 0xb8) && (ch <= 0xbf)) {
|
||||
const size_t uintlen = ch - 0xb7;
|
||||
size_t expected = prefixlen + uintlen;
|
||||
|
||||
|
|
@ -124,8 +116,7 @@ std::vector<std::string> rlp_decoder::decode_rlp(const unsigned char *raw, size_
|
|||
consumed = expected;
|
||||
}
|
||||
// Case 4: [prefix][list]
|
||||
else if ((ch >= 0xc0) && (ch <= 0xf7))
|
||||
{
|
||||
else if ((ch >= 0xc0) && (ch <= 0xf7)) {
|
||||
const size_t payloadlen = ch - 0xc0;
|
||||
const size_t expected = prefixlen + payloadlen;
|
||||
|
||||
|
|
@ -136,8 +127,7 @@ std::vector<std::string> rlp_decoder::decode_rlp(const unsigned char *raw, size_
|
|||
consumed = expected;
|
||||
}
|
||||
// Case 5: [prefix][list length][list]
|
||||
else
|
||||
{
|
||||
else {
|
||||
FC_ASSERT((ch >= 0xf8) && (ch <= 0xff));
|
||||
|
||||
const size_t uintlen = ch - 0xf7;
|
||||
|
|
@ -169,8 +159,7 @@ std::vector<std::string> rlp_decoder::decode_rlp(const unsigned char *raw, size_
|
|||
return rlp_result;
|
||||
}
|
||||
|
||||
std::vector<std::string> rlp_decoder::decode_array(const unsigned char *raw, size_t len, size_t uintlen, size_t payloadlen)
|
||||
{
|
||||
std::vector<std::string> rlp_decoder::decode_array(const unsigned char *raw, size_t len, size_t uintlen, size_t payloadlen) {
|
||||
std::vector<std::string> rlp_result;
|
||||
const size_t prefixlen = 1;
|
||||
|
||||
|
|
@ -183,8 +172,7 @@ std::vector<std::string> rlp_decoder::decode_array(const unsigned char *raw, siz
|
|||
const unsigned char *list_ent = raw + prefixlen + uintlen;
|
||||
|
||||
// recursively read until payloadlen bytes parsed, or error
|
||||
while (child_len > 0)
|
||||
{
|
||||
while (child_len > 0) {
|
||||
size_t child_consumed = 0;
|
||||
|
||||
const auto val = decode_rlp(list_ent, child_len, child_consumed);
|
||||
|
|
@ -197,8 +185,7 @@ std::vector<std::string> rlp_decoder::decode_array(const unsigned char *raw, siz
|
|||
return rlp_result;
|
||||
}
|
||||
|
||||
uint64_t rlp_decoder::to_int(const unsigned char *raw, size_t len)
|
||||
{
|
||||
uint64_t rlp_decoder::to_int(const unsigned char *raw, size_t len) {
|
||||
if (len == 0)
|
||||
return 0;
|
||||
else if (len == 1)
|
||||
|
|
@ -207,17 +194,14 @@ uint64_t rlp_decoder::to_int(const unsigned char *raw, size_t len)
|
|||
return (raw[len - 1]) + (to_int(raw, len - 1) * 256);
|
||||
}
|
||||
|
||||
std::vector<unsigned char> rlp_decoder::parse_hex(const std::string& str)
|
||||
{
|
||||
std::vector<unsigned char> rlp_decoder::parse_hex(const std::string &str) {
|
||||
return parse_hex(str.c_str());
|
||||
}
|
||||
|
||||
std::vector<unsigned char> rlp_decoder::parse_hex(const char* psz)
|
||||
{
|
||||
std::vector<unsigned char> rlp_decoder::parse_hex(const char *psz) {
|
||||
// convert hex dump to vector
|
||||
std::vector<unsigned char> vch;
|
||||
while (true)
|
||||
{
|
||||
while (true) {
|
||||
while (isspace(*psz))
|
||||
psz++;
|
||||
signed char c = hex_digit(*psz++);
|
||||
|
|
@ -233,8 +217,7 @@ std::vector<unsigned char> rlp_decoder::parse_hex(const char* psz)
|
|||
return vch;
|
||||
}
|
||||
|
||||
signed char rlp_decoder::hex_digit(char c)
|
||||
{
|
||||
signed char rlp_decoder::hex_digit(char c) {
|
||||
return p_util_hexdigit[(unsigned char)c];
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,41 +1,35 @@
|
|||
#include <graphene/peerplays_sidechain/ethereum/encoders.hpp>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <boost/algorithm/hex.hpp>
|
||||
#include <boost/format.hpp>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <graphene/peerplays_sidechain/ethereum/utils.hpp>
|
||||
|
||||
namespace graphene { namespace peerplays_sidechain { namespace ethereum {
|
||||
|
||||
//! base_encoder
|
||||
std::string base_encoder::encode_uint256(boost::multiprecision::uint256_t value)
|
||||
{
|
||||
std::string base_encoder::encode_uint256(boost::multiprecision::uint256_t value) {
|
||||
return (boost::format("%x") % boost::io::group(std::setw(64), std::setfill('0'), value)).str();
|
||||
}
|
||||
|
||||
std::string base_encoder::encode_address(const std::string& value)
|
||||
{
|
||||
std::string base_encoder::encode_address(const std::string &value) {
|
||||
return (boost::format("%x") % boost::io::group(std::setw(64), std::setfill('0'), value)).str();
|
||||
}
|
||||
|
||||
std::string base_encoder::encode_string(const std::string& value)
|
||||
{
|
||||
std::string base_encoder::encode_string(const std::string &value) {
|
||||
std::string data = (boost::format("%x") % boost::io::group(std::setw(64), std::setfill('0'), value.size())).str();
|
||||
data += boost::algorithm::hex(value) + std::string((64 - value.size() * 2 % 64), '0');
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
//! update_owners_encoder
|
||||
std::string update_owners_encoder::encode(const std::vector<std::pair<std::string, uint16_t>>& owners_weights, const std::string& object_id) const
|
||||
{
|
||||
std::string update_owners_encoder::encode(const std::vector<std::pair<std::string, uint16_t>> &owners_weights, const std::string &object_id) const {
|
||||
std::string data = "0x" + function_signature;
|
||||
data += base_encoder::encode_uint256(64);
|
||||
data += base_encoder::encode_uint256((owners_weights.size() * 2 + 3) * 32);
|
||||
data += base_encoder::encode_uint256(owners_weights.size());
|
||||
for(const auto& owner : owners_weights)
|
||||
{
|
||||
for (const auto &owner : owners_weights) {
|
||||
data += base_encoder::encode_address(owner.first);
|
||||
data += base_encoder::encode_uint256(owner.second);
|
||||
}
|
||||
|
|
@ -45,8 +39,7 @@ std::string update_owners_encoder::encode(const std::vector<std::pair<std::strin
|
|||
}
|
||||
|
||||
//! withdrawal_encoder
|
||||
std::string withdrawal_encoder::encode(const std::string& to, boost::multiprecision::uint256_t amount, const std::string& object_id) const
|
||||
{
|
||||
std::string withdrawal_encoder::encode(const std::string &to, boost::multiprecision::uint256_t amount, const std::string &object_id) const {
|
||||
std::string data = "0x" + function_signature;
|
||||
data += base_encoder::encode_address(to);
|
||||
data += base_encoder::encode_uint256(amount);
|
||||
|
|
@ -56,23 +49,17 @@ std::string withdrawal_encoder::encode(const std::string& to, boost::multiprecis
|
|||
return data;
|
||||
}
|
||||
|
||||
|
||||
//! rlp_encoder
|
||||
std::string rlp_encoder::encode(const std::string& s)
|
||||
{
|
||||
std::string rlp_encoder::encode(const std::string &s) {
|
||||
return encode_rlp(hex2bytes(s));
|
||||
}
|
||||
|
||||
std::string rlp_encoder::encode_length(int len, int offset)
|
||||
{
|
||||
if(len<56)
|
||||
{
|
||||
std::string rlp_encoder::encode_length(int len, int offset) {
|
||||
if (len < 56) {
|
||||
std::string temp;
|
||||
temp = (char)(len + offset);
|
||||
return temp;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
const std::string hexLength = to_hex(len);
|
||||
const int lLength = hexLength.size() / 2;
|
||||
const std::string fByte = to_hex(offset + 55 + lLength);
|
||||
|
|
@ -80,24 +67,21 @@ std::string rlp_encoder::encode_length(int len, int offset)
|
|||
}
|
||||
}
|
||||
|
||||
std::string rlp_encoder::hex2bytes(const std::string& s)
|
||||
{
|
||||
std::string rlp_encoder::hex2bytes(const std::string &s) {
|
||||
std::string dest;
|
||||
dest.resize(s.size() / 2);
|
||||
hex2bin(s.c_str(), &dest[0]);
|
||||
return dest;
|
||||
}
|
||||
|
||||
std::string rlp_encoder::encode_rlp(const std::string& s)
|
||||
{
|
||||
std::string rlp_encoder::encode_rlp(const std::string &s) {
|
||||
if (s.size() == 1 && (unsigned char)s[0] < 128)
|
||||
return s;
|
||||
else
|
||||
return encode_length(s.size(), 128) + s;
|
||||
}
|
||||
|
||||
int rlp_encoder::char2int(char input)
|
||||
{
|
||||
int rlp_encoder::char2int(char input) {
|
||||
if (input >= '0' && input <= '9')
|
||||
return input - '0';
|
||||
if (input >= 'A' && input <= 'F')
|
||||
|
|
@ -108,10 +92,8 @@ int rlp_encoder::char2int(char input)
|
|||
return -1;
|
||||
}
|
||||
|
||||
void rlp_encoder::hex2bin(const char* src, char* target)
|
||||
{
|
||||
while(*src && src[1])
|
||||
{
|
||||
void rlp_encoder::hex2bin(const char *src, char *target) {
|
||||
while (*src && src[1]) {
|
||||
*(target++) = char2int(*src) * 16 + char2int(src[1]);
|
||||
src += 2;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,14 +10,13 @@
|
|||
#include <fc/crypto/elliptic.hpp>
|
||||
#include <fc/crypto/hex.hpp>
|
||||
|
||||
#include <graphene/peerplays_sidechain/ethereum/encoders.hpp>
|
||||
#include <graphene/peerplays_sidechain/ethereum/decoders.hpp>
|
||||
#include <graphene/peerplays_sidechain/ethereum/encoders.hpp>
|
||||
#include <graphene/peerplays_sidechain/ethereum/types.hpp>
|
||||
#include <graphene/peerplays_sidechain/ethereum/utils.hpp>
|
||||
|
||||
namespace graphene { namespace peerplays_sidechain { namespace ethereum {
|
||||
|
||||
|
||||
const secp256k1_context *eth_context() {
|
||||
static secp256k1_context *ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY | SECP256K1_CONTEXT_SIGN);
|
||||
return ctx;
|
||||
|
|
@ -25,13 +24,11 @@ const secp256k1_context *eth_context() {
|
|||
|
||||
//! transaction
|
||||
|
||||
const transaction& transaction::sign(const std::string& private_key) const
|
||||
{
|
||||
const transaction &transaction::sign(const std::string &private_key) const {
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string transaction::serialize() const
|
||||
{
|
||||
std::string transaction::serialize() const {
|
||||
boost::property_tree::ptree pt;
|
||||
pt.put("from", from);
|
||||
pt.put("to", to);
|
||||
|
|
@ -42,8 +39,7 @@ std::string transaction::serialize() const
|
|||
return ss.str();
|
||||
}
|
||||
|
||||
void transaction::deserialize(const std::string& raw_tx)
|
||||
{
|
||||
void transaction::deserialize(const std::string &raw_tx) {
|
||||
std::stringstream ss_tx(raw_tx);
|
||||
boost::property_tree::ptree tx_json;
|
||||
boost::property_tree::read_json(ss_tx, tx_json);
|
||||
|
|
@ -58,8 +54,7 @@ void transaction::deserialize(const std::string& raw_tx)
|
|||
|
||||
//! raw_transaction
|
||||
|
||||
signed_transaction raw_transaction::sign(const std::string& private_key) const
|
||||
{
|
||||
signed_transaction raw_transaction::sign(const std::string &private_key) const {
|
||||
//! Prepare signed transaction
|
||||
signed_transaction tr;
|
||||
tr.nonce = nonce;
|
||||
|
|
@ -98,8 +93,7 @@ signed_transaction raw_transaction::sign(const std::string& private_key) const
|
|||
return tr;
|
||||
}
|
||||
|
||||
std::string raw_transaction::serialize() const
|
||||
{
|
||||
std::string raw_transaction::serialize() const {
|
||||
rlp_encoder encoder;
|
||||
const std::string serialized = encoder.encode(remove_0x(nonce)) +
|
||||
encoder.encode(remove_0x(gas_price)) +
|
||||
|
|
@ -114,8 +108,7 @@ std::string raw_transaction::serialize() const
|
|||
return add_0x(bytes2hex(encoder.encode_length(serialized.size(), 192) + serialized));
|
||||
}
|
||||
|
||||
void raw_transaction::deserialize(const std::string& raw_tx)
|
||||
{
|
||||
void raw_transaction::deserialize(const std::string &raw_tx) {
|
||||
rlp_decoder decoder;
|
||||
const auto rlp_array = decoder.decode(remove_0x(raw_tx));
|
||||
FC_ASSERT(rlp_array.size() >= 7, "Wrong rlp format");
|
||||
|
|
@ -131,8 +124,7 @@ void raw_transaction::deserialize(const std::string& raw_tx)
|
|||
|
||||
//! signed_transaction
|
||||
|
||||
std::string signed_transaction::serialize() const
|
||||
{
|
||||
std::string signed_transaction::serialize() const {
|
||||
rlp_encoder encoder;
|
||||
const std::string serialized = encoder.encode(remove_0x(nonce)) +
|
||||
encoder.encode(remove_0x(gas_price)) +
|
||||
|
|
@ -147,8 +139,7 @@ std::string signed_transaction::serialize() const
|
|||
return add_0x(bytes2hex(encoder.encode_length(serialized.size(), 192) + serialized));
|
||||
}
|
||||
|
||||
void signed_transaction::deserialize(const std::string& raw_tx)
|
||||
{
|
||||
void signed_transaction::deserialize(const std::string &raw_tx) {
|
||||
rlp_decoder decoder;
|
||||
const auto rlp_array = decoder.decode(remove_0x(raw_tx));
|
||||
FC_ASSERT(rlp_array.size() >= 9, "Wrong rlp format");
|
||||
|
|
|
|||
|
|
@ -10,8 +10,7 @@ bytes parse_hex(const std::string &str) {
|
|||
return vec;
|
||||
}
|
||||
|
||||
std::string bytes2hex(const std::string& s)
|
||||
{
|
||||
std::string bytes2hex(const std::string &s) {
|
||||
std::string dest;
|
||||
for (const auto &i : s)
|
||||
dest += uchar2Hex((unsigned char)i);
|
||||
|
|
@ -19,14 +18,12 @@ std::string bytes2hex(const std::string& s)
|
|||
return dest;
|
||||
}
|
||||
|
||||
std::string uchar2Hex(unsigned char n)
|
||||
{
|
||||
std::string uchar2Hex(unsigned char n) {
|
||||
std::string dest;
|
||||
dest.resize(2);
|
||||
sprintf(&dest[0], "%X", n);
|
||||
|
||||
if(n < (unsigned char)16)
|
||||
{
|
||||
if (n < (unsigned char)16) {
|
||||
dest[1] = dest[0];
|
||||
dest[0] = '0';
|
||||
}
|
||||
|
|
@ -34,8 +31,7 @@ std::string uchar2Hex(unsigned char n)
|
|||
return dest;
|
||||
}
|
||||
|
||||
std::string add_0x(const std::string& s)
|
||||
{
|
||||
std::string add_0x(const std::string &s) {
|
||||
if (s.size() > 1) {
|
||||
if (s.substr(0, 2) == "0x")
|
||||
return s;
|
||||
|
|
@ -44,8 +40,7 @@ std::string add_0x(const std::string& s)
|
|||
return "0x" + s;
|
||||
}
|
||||
|
||||
std::string remove_0x(const std::string& s)
|
||||
{
|
||||
std::string remove_0x(const std::string &s) {
|
||||
if (s.size() > 1) {
|
||||
if (s.substr(0, 2) == "0x")
|
||||
return s.substr(2);
|
||||
|
|
|
|||
|
|
@ -7,8 +7,7 @@ namespace graphene { namespace peerplays_sidechain { namespace ethereum {
|
|||
|
||||
class rlp_decoder {
|
||||
private:
|
||||
enum RLP_constants
|
||||
{
|
||||
enum RLP_constants {
|
||||
RLP_maxUintLen = 8,
|
||||
RLP_bufferLenStart = 0x80,
|
||||
RLP_listStart = 0xc0,
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <boost/multiprecision/cpp_int.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <boost/multiprecision/cpp_int.hpp>
|
||||
|
||||
namespace graphene { namespace peerplays_sidechain { namespace ethereum {
|
||||
|
||||
|
|
|
|||
|
|
@ -6,14 +6,12 @@
|
|||
|
||||
namespace graphene { namespace peerplays_sidechain { namespace ethereum {
|
||||
|
||||
class base_transaction
|
||||
{
|
||||
class base_transaction {
|
||||
virtual std::string serialize() const = 0;
|
||||
virtual void deserialize(const std::string &raw_tx) = 0;
|
||||
};
|
||||
|
||||
class transaction : base_transaction
|
||||
{
|
||||
class transaction : base_transaction {
|
||||
public:
|
||||
std::string from;
|
||||
std::string to;
|
||||
|
|
@ -26,8 +24,7 @@ public:
|
|||
};
|
||||
|
||||
class signed_transaction;
|
||||
class raw_transaction : base_transaction
|
||||
{
|
||||
class raw_transaction : base_transaction {
|
||||
public:
|
||||
std::string nonce;
|
||||
std::string gas_price;
|
||||
|
|
@ -43,8 +40,7 @@ public:
|
|||
virtual void deserialize(const std::string &raw_tx) override;
|
||||
};
|
||||
|
||||
class signed_transaction : base_transaction
|
||||
{
|
||||
class signed_transaction : base_transaction {
|
||||
public:
|
||||
std::string nonce;
|
||||
std::string gas_price;
|
||||
|
|
|
|||
|
|
@ -15,8 +15,7 @@ std::string add_0x(const std::string& s);
|
|||
std::string remove_0x(const std::string &s);
|
||||
|
||||
template <typename T>
|
||||
std::string to_hex( const T& val )
|
||||
{
|
||||
std::string to_hex(const T &val) {
|
||||
std::stringstream stream;
|
||||
stream << std::hex << val;
|
||||
std::string result(stream.str());
|
||||
|
|
@ -26,8 +25,7 @@ std::string to_hex( const T& val )
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
T from_hex( const std::string& s )
|
||||
{
|
||||
T from_hex(const std::string &s) {
|
||||
T val;
|
||||
std::stringstream stream;
|
||||
stream << std::hex << s;
|
||||
|
|
|
|||
|
|
@ -245,22 +245,14 @@ void peerplays_sidechain_plugin_impl::plugin_initialize(const boost::program_opt
|
|||
}
|
||||
|
||||
#ifdef ENABLE_PEERPLAYS_ASSET_DEPOSITS
|
||||
sidechain_enabled_peerplays = true; //options.at("peerplays-sidechain-enabled").as<bool>();
|
||||
sidechain_enabled_peerplays = true;
|
||||
#else
|
||||
sidechain_enabled_peerplays = false;
|
||||
#endif
|
||||
config_ready_peerplays = true;
|
||||
if (!config_ready_peerplays) {
|
||||
if (sidechain_enabled_peerplays && !config_ready_peerplays) {
|
||||
wlog("Haven't set up Peerplays sidechain parameters");
|
||||
}
|
||||
|
||||
if (!(config_ready_bitcoin &&
|
||||
config_ready_ethereum &&
|
||||
config_ready_hive &&
|
||||
config_ready_peerplays)) {
|
||||
wlog("Haven't set up any sidechain parameters");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
void peerplays_sidechain_plugin_impl::plugin_startup() {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
#include <graphene/peerplays_sidechain/ethereum/transaction.hpp>
|
||||
#include <graphene/peerplays_sidechain/ethereum/utils.hpp>
|
||||
|
||||
//#define SEND_RAW_TRANSACTION 1
|
||||
#define SEND_RAW_TRANSACTION 1
|
||||
|
||||
namespace graphene { namespace peerplays_sidechain {
|
||||
|
||||
|
|
@ -67,7 +67,8 @@ std::string ethereum_rpc_client::get_network_id() {
|
|||
|
||||
std::string ethereum_rpc_client::get_nonce(const std::string &address) {
|
||||
std::string reply_str = eth_get_transaction_count("[\"" + address + "\", \"latest\"]");
|
||||
return retrieve_value_from_reply(reply_str, "");
|
||||
const auto nonce_val = ethereum::from_hex<boost::multiprecision::uint256_t>(retrieve_value_from_reply(reply_str, ""));
|
||||
return nonce_val == 0 ? ethereum::add_0x("0") : ethereum::add_0x(ethereum::to_hex(nonce_val));
|
||||
}
|
||||
|
||||
std::string ethereum_rpc_client::get_gas_price() {
|
||||
|
|
@ -543,6 +544,11 @@ std::string sidechain_net_handler_ethereum::send_sidechain_transaction(const sid
|
|||
boost::property_tree::ptree pt_array;
|
||||
for (const auto &signature : sto.signatures) {
|
||||
const auto &transaction = signature.second;
|
||||
|
||||
//! Check if we have this signed transaction, if not, don't send it
|
||||
if(transaction.empty())
|
||||
continue;
|
||||
|
||||
#ifdef SEND_RAW_TRANSACTION
|
||||
const std::string sidechain_transaction = rpc_client->eth_send_raw_transaction(transaction);
|
||||
#else
|
||||
|
|
@ -557,11 +563,11 @@ std::string sidechain_net_handler_ethereum::send_sidechain_transaction(const sid
|
|||
node.put("transaction", transaction);
|
||||
node.put("transaction_receipt", tx_json.get<std::string>("result"));
|
||||
pt_array.push_back(std::make_pair("", node));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
//! Fixme
|
||||
//! How should we proceed with error in eth_send_transaction
|
||||
elog("Error in eth_send_transaction for transaction ${id}, transaction ${transaction}", ("id", sto.id)("transaction", transaction));
|
||||
return std::string{}; //! Return empty string, as we have error in sending
|
||||
}
|
||||
}
|
||||
pt.add_child("result_array", pt_array);
|
||||
|
|
@ -593,8 +599,7 @@ bool sidechain_net_handler_ethereum::settle_sidechain_transaction(const sidechai
|
|||
return false;
|
||||
}
|
||||
|
||||
if( "0x1" == json_receipt.get<std::string>("result.status") )
|
||||
{
|
||||
if ("0x1" == json_receipt.get<std::string>("result.status")) {
|
||||
count += 1;
|
||||
//! Fixme - compare data somehow?
|
||||
//if( sto.transaction == entry_receipt.second.get<std::string>("data") ) {
|
||||
|
|
@ -606,8 +611,7 @@ bool sidechain_net_handler_ethereum::settle_sidechain_transaction(const sidechai
|
|||
if (count != json.get_child("result_array").size()) {
|
||||
wlog("Not all receipts received for transaction ${id}", ("id", sto.id));
|
||||
return false;
|
||||
}
|
||||
else
|
||||
} else
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
|
@ -642,7 +646,7 @@ std::string sidechain_net_handler_ethereum::sign_transaction(const sidechain_tra
|
|||
|
||||
#ifdef SEND_RAW_TRANSACTION
|
||||
ethereum::raw_transaction raw_tr;
|
||||
raw_tr.nonce = ethereum::to_hex( ethereum::from_hex<boost::multiprecision::uint256_t>( rpc_client->get_nonce( ethereum::add_0x(public_key) ) ) + 1 );
|
||||
raw_tr.nonce = rpc_client->get_nonce(ethereum::add_0x(public_key));
|
||||
raw_tr.gas_price = rpc_client->get_gas_price();
|
||||
raw_tr.gas_limit = rpc_client->get_gas_limit();
|
||||
raw_tr.to = wallet_contract_address;
|
||||
|
|
|
|||
Loading…
Reference in a new issue