big multiprecision values and serialize an Ethereum transaction for RPC
This commit is contained in:
parent
cd235455cc
commit
a2c0793c48
2 changed files with 39 additions and 0 deletions
|
|
@ -19,6 +19,16 @@
|
||||||
|
|
||||||
#include <fc/thread/thread.hpp>
|
#include <fc/thread/thread.hpp>
|
||||||
|
|
||||||
|
#include <boost/multiprecision/cpp_int.hpp>
|
||||||
|
|
||||||
|
using namespace boost::multiprecision::literals;
|
||||||
|
using u256 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void>>;
|
||||||
|
using s256 = boost::multiprecision::number<boost::multiprecision::cpp_int_backend<256, 256, boost::multiprecision::signed_magnitude, boost::multiprecision::unchecked, void>>;
|
||||||
|
u256 constexpr Invalid256 = 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff_cppui256;
|
||||||
|
using byte = uint8_t;
|
||||||
|
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;
|
||||||
|
|
@ -124,6 +134,29 @@ namespace graphene { namespace peerplays_sidechain {
|
||||||
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
|
||||||
|
class Transaction
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/// 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);
|
||||||
|
protected:
|
||||||
|
/// Type of transaction.
|
||||||
|
enum Type
|
||||||
|
{
|
||||||
|
NullTransaction, ///< Null transaction.
|
||||||
|
ContractCreation, ///< Transaction to create contracts - receiveAddress() is ignored.
|
||||||
|
MessageCall ///< Transaction to invoke a message call - receiveAddress() is used.
|
||||||
|
};
|
||||||
|
|
||||||
|
Type m_type = NullTransaction; ///< Is this a contract-creation transaction or a message-call transaction?
|
||||||
|
u256 m_nonce; ///< The transaction-count of the sender.
|
||||||
|
u256 m_value; ///< The amount of ETH to be transferred by this transaction. Called 'endowment' for contract-creation transactions.
|
||||||
|
u256 m_gasPrice; ///< The base fee and thus the implied exchange rate of ETH to GAS.
|
||||||
|
u256 m_gas; ///< The total gas to convert, paid for from sender's account. Any unused gas gets refunded once the contract is ended.
|
||||||
|
bytes m_data; ///< The data associated with the transaction, or the initialiser if it's a creation transaction.
|
||||||
|
};
|
||||||
|
|
||||||
class ethereum_function_call_encoder {
|
class ethereum_function_call_encoder {
|
||||||
public:
|
public:
|
||||||
enum operation_t {
|
enum operation_t {
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,12 @@ 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 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());
|
||||||
|
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;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue