eth_send_raw_transaction + eth_send_transaction
This commit is contained in:
parent
34df0c0754
commit
b43d5b4224
3 changed files with 41 additions and 17 deletions
|
|
@ -72,7 +72,7 @@ signed_transaction raw_transaction::sign(const std::string& private_key) const
|
|||
//! Calculate keccak hash of transaction
|
||||
bytes hash;
|
||||
hash.resize(32);
|
||||
const auto transaction_string = boost::algorithm::unhex( serialize() );
|
||||
const auto transaction_string = boost::algorithm::unhex( remove_0x( serialize() ) );
|
||||
keccak_256((const unsigned char *) transaction_string.data(), transaction_string.size(), (unsigned char *) hash.data());
|
||||
|
||||
const bytes priv_key = parse_hex(private_key);
|
||||
|
|
@ -111,13 +111,13 @@ std::string raw_transaction::serialize() const
|
|||
encoder.encode("") +
|
||||
encoder.encode("");
|
||||
|
||||
return bytes2hex( encoder.encode_length(serialized.size(), 192) + serialized );
|
||||
return add_0x( bytes2hex( encoder.encode_length(serialized.size(), 192) + serialized ) );
|
||||
}
|
||||
|
||||
void raw_transaction::deserialize(const std::string& raw_tx)
|
||||
{
|
||||
rlp_decoder decoder;
|
||||
const auto rlp_array = decoder.decode(raw_tx);
|
||||
const auto rlp_array = decoder.decode(remove_0x(raw_tx));
|
||||
FC_ASSERT(rlp_array.size() >= 7, "Wrong rlp format");
|
||||
|
||||
nonce = add_0x(rlp_array.at(0));
|
||||
|
|
@ -144,13 +144,13 @@ std::string signed_transaction::serialize() const
|
|||
encoder.encode(remove_0x(r)) +
|
||||
encoder.encode(remove_0x(s));
|
||||
|
||||
return bytes2hex( encoder.encode_length(serialized.size(), 192) + serialized );
|
||||
return add_0x( bytes2hex( encoder.encode_length(serialized.size(), 192) + serialized ) );
|
||||
}
|
||||
|
||||
void signed_transaction::deserialize(const std::string& raw_tx)
|
||||
{
|
||||
rlp_decoder decoder;
|
||||
const auto rlp_array = decoder.decode(raw_tx);
|
||||
const auto rlp_array = decoder.decode(remove_0x(raw_tx));
|
||||
FC_ASSERT(rlp_array.size() >= 9, "Wrong rlp format");
|
||||
|
||||
nonce = add_0x(rlp_array.at(0));
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ public:
|
|||
std::string get_gas_limit();
|
||||
|
||||
std::string eth_send_transaction(const std::string& params);
|
||||
std::string eth_send_raw_transaction(const std::string& params);
|
||||
std::string eth_get_transaction_receipt(const std::string& params);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -18,6 +18,9 @@
|
|||
#include <graphene/chain/son_wallet_object.hpp>
|
||||
#include <graphene/peerplays_sidechain/ethereum/encoders.hpp>
|
||||
#include <graphene/peerplays_sidechain/ethereum/transaction.hpp>
|
||||
#include <graphene/peerplays_sidechain/ethereum/utils.hpp>
|
||||
|
||||
//#define SEND_RAW_TRANSACTION 1
|
||||
|
||||
namespace graphene { namespace peerplays_sidechain {
|
||||
|
||||
|
|
@ -90,6 +93,10 @@ std::string ethereum_rpc_client::eth_send_transaction(const std::string& params)
|
|||
return send_post_request("eth_sendTransaction", "[" + params + "]", debug_rpc_calls);
|
||||
}
|
||||
|
||||
std::string ethereum_rpc_client::eth_send_raw_transaction(const std::string& params) {
|
||||
return send_post_request("eth_sendRawTransaction", "[ \"" + params + "\" ]", debug_rpc_calls);
|
||||
}
|
||||
|
||||
std::string ethereum_rpc_client::eth_get_transaction_receipt(const std::string& params) {
|
||||
return send_post_request("eth_getTransactionReceipt", "[\"" + params + "\"]", debug_rpc_calls);
|
||||
}
|
||||
|
|
@ -536,7 +543,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;
|
||||
const std::string sidechain_transaction = rpc_client->eth_send_transaction(transaction);
|
||||
#ifdef SEND_RAW_TRANSACTION
|
||||
const std::string sidechain_transaction = rpc_client->eth_send_raw_transaction(transaction);
|
||||
#else
|
||||
const std::string sidechain_transaction = rpc_client->eth_send_transaction(transaction);
|
||||
#endif
|
||||
|
||||
std::stringstream ss_tx(sidechain_transaction);
|
||||
boost::property_tree::ptree tx_json;
|
||||
|
|
@ -610,10 +621,8 @@ std::string sidechain_net_handler_ethereum::create_primary_wallet_transaction(co
|
|||
owners_weights.emplace_back(std::make_pair(pub_key_str, son.weight));
|
||||
}
|
||||
|
||||
ethereum::transaction transaction;
|
||||
ethereum::update_owners_encoder encoder;
|
||||
transaction.data = encoder.encode(owners_weights, object_id);
|
||||
return transaction.serialize();
|
||||
return encoder.encode(owners_weights, object_id);
|
||||
}
|
||||
|
||||
std::string sidechain_net_handler_ethereum::create_deposit_transaction(const son_wallet_deposit_object &swdo) {
|
||||
|
|
@ -621,21 +630,35 @@ std::string sidechain_net_handler_ethereum::create_deposit_transaction(const son
|
|||
}
|
||||
|
||||
std::string sidechain_net_handler_ethereum::create_withdrawal_transaction(const son_wallet_withdraw_object &swwo) {
|
||||
ethereum::transaction transaction;
|
||||
ethereum::withdrawal_encoder encoder;
|
||||
transaction.data = encoder.encode(swwo.withdraw_address.substr(2), swwo.withdraw_amount.value*10000000000, swwo.id.operator std::string());
|
||||
return transaction.serialize();
|
||||
return encoder.encode(swwo.withdraw_address.substr(2), swwo.withdraw_amount.value*10000000000, swwo.id.operator std::string());
|
||||
}
|
||||
|
||||
std::string sidechain_net_handler_ethereum::sign_transaction(const sidechain_transaction_object &sto) {
|
||||
const auto& current_son = plugin.get_current_son_object();
|
||||
FC_ASSERT(current_son.sidechain_public_keys.contains(sidechain_type::ethereum), "No public keys for current son: ${account_id}", ("account_id", current_son.son_account));
|
||||
|
||||
ethereum::transaction sign_transaction;
|
||||
sign_transaction.deserialize(sto.transaction);
|
||||
sign_transaction.to = wallet_contract_address;
|
||||
sign_transaction.from = "0x" + current_son.sidechain_public_keys.at(sidechain);
|
||||
return sign_transaction.sign(get_private_key(plugin.get_current_son_object().sidechain_public_keys.at(sidechain))).serialize();
|
||||
const auto& public_key = current_son.sidechain_public_keys.at(sidechain);
|
||||
|
||||
#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.gas_price = rpc_client->get_gas_price();
|
||||
raw_tr.gas_limit = rpc_client->get_gas_limit();
|
||||
raw_tr.to = wallet_contract_address;
|
||||
raw_tr.value = "";
|
||||
raw_tr.data = sto.transaction;
|
||||
raw_tr.chain_id = ethereum::add_0x(ethereum::to_hex(chain_id));
|
||||
|
||||
const auto sign_tr = raw_tr.sign(get_private_key(public_key));
|
||||
return sign_tr.serialize();
|
||||
#else
|
||||
ethereum::transaction sign_transaction;
|
||||
sign_transaction.data = sto.transaction;
|
||||
sign_transaction.to = wallet_contract_address;
|
||||
sign_transaction.from = "0x" + public_key;
|
||||
return sign_transaction.sign(get_private_key(public_key)).serialize();
|
||||
#endif
|
||||
}
|
||||
|
||||
void sidechain_net_handler_ethereum::schedule_ethereum_listener() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue