1) get_nonce
2) get_gas_price 3) get_gas_limit
This commit is contained in:
parent
e3098c3fb6
commit
adc6743ef0
2 changed files with 45 additions and 8 deletions
|
|
@ -19,12 +19,17 @@ public:
|
|||
std::string eth_get_block_by_number(std::string block_number, bool full_block);
|
||||
std::string eth_get_logs(std::string wallet_contract_address);
|
||||
std::string net_version();
|
||||
std::string eth_get_transaction_count(const std::string& params);
|
||||
std::string eth_gas_price();
|
||||
|
||||
std::string get_chain_id();
|
||||
std::string get_network_id();
|
||||
std::string get_nonce(const std::string& address);
|
||||
std::string get_gas_price();
|
||||
std::string get_gas_limit();
|
||||
|
||||
std::string send_transaction(const std::string& params);
|
||||
std::string get_transaction_receipt(const std::string& params);
|
||||
std::string eth_send_transaction(const std::string& params);
|
||||
std::string eth_get_transaction_receipt(const std::string& params);
|
||||
};
|
||||
|
||||
class sidechain_net_handler_ethereum : public sidechain_net_handler {
|
||||
|
|
|
|||
|
|
@ -44,6 +44,14 @@ std::string ethereum_rpc_client::net_version() {
|
|||
return send_post_request("net_version", "", debug_rpc_calls);
|
||||
}
|
||||
|
||||
std::string ethereum_rpc_client::eth_get_transaction_count(const std::string& params) {
|
||||
return send_post_request("eth_getTransactionCount", params, debug_rpc_calls);
|
||||
}
|
||||
|
||||
std::string ethereum_rpc_client::eth_gas_price() {
|
||||
return send_post_request("eth_gasPrice", "", debug_rpc_calls);
|
||||
}
|
||||
|
||||
std::string ethereum_rpc_client::get_chain_id() {
|
||||
std::string reply_str = net_version();
|
||||
return retrieve_value_from_reply(reply_str, "");
|
||||
|
|
@ -54,11 +62,35 @@ std::string ethereum_rpc_client::get_network_id() {
|
|||
return retrieve_value_from_reply(reply_str, "protocols.eth.network");
|
||||
}
|
||||
|
||||
std::string ethereum_rpc_client::send_transaction(const std::string& params) {
|
||||
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, "");
|
||||
}
|
||||
|
||||
std::string ethereum_rpc_client::get_gas_price() {
|
||||
std::string reply_str = eth_gas_price();
|
||||
return retrieve_value_from_reply(reply_str, "");
|
||||
}
|
||||
|
||||
std::string ethereum_rpc_client::get_gas_limit() {
|
||||
std::string reply_str = eth_get_block_by_number("latest", false);
|
||||
if (!reply_str.empty()) {
|
||||
std::stringstream ss(reply_str);
|
||||
boost::property_tree::ptree json;
|
||||
boost::property_tree::read_json(ss, json);
|
||||
if (json.count("result")) {
|
||||
std::string gas_limit_s = json.get<std::string>("result.gasLimit");
|
||||
return gas_limit_s;
|
||||
}
|
||||
}
|
||||
return std::string{};
|
||||
}
|
||||
|
||||
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::get_transaction_receipt(const std::string& params) {
|
||||
std::string ethereum_rpc_client::eth_get_transaction_receipt(const std::string& params) {
|
||||
return send_post_request("eth_getTransactionReceipt", "[\"" + params + "\"]", debug_rpc_calls);
|
||||
}
|
||||
|
||||
|
|
@ -504,7 +536,7 @@ 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->send_transaction(transaction);
|
||||
const std::string sidechain_transaction = rpc_client->eth_send_transaction(transaction);
|
||||
|
||||
std::stringstream ss_tx(sidechain_transaction);
|
||||
boost::property_tree::ptree tx_json;
|
||||
|
|
@ -517,8 +549,8 @@ std::string sidechain_net_handler_ethereum::send_sidechain_transaction(const sid
|
|||
}
|
||||
else {
|
||||
//! Fixme
|
||||
//! How should we proceed with error in send_transaction
|
||||
elog("Error in send_transaction for transaction ${id}, transaction ${transaction}", ("id", sto.id) ("transaction", transaction));
|
||||
//! 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));
|
||||
}
|
||||
}
|
||||
pt.add_child("result_array", pt_array);
|
||||
|
|
@ -539,7 +571,7 @@ bool sidechain_net_handler_ethereum::settle_sidechain_transaction(const sidechai
|
|||
|
||||
size_t count = 0;
|
||||
for(const auto &entry : json.get_child("result_array")) {
|
||||
const std::string receipt = rpc_client->get_transaction_receipt( entry.second.get<std::string>("transaction_receipt") );
|
||||
const std::string receipt = rpc_client->eth_get_transaction_receipt( entry.second.get<std::string>("transaction_receipt") );
|
||||
|
||||
std::stringstream ss_receipt(receipt);
|
||||
boost::property_tree::ptree json_receipt;
|
||||
|
|
|
|||
Loading…
Reference in a new issue