#484 multiple eth withdrawals
This commit is contained in:
parent
440e4fbb43
commit
4883dfe38d
6 changed files with 57 additions and 22 deletions
|
|
@ -210,8 +210,8 @@ std::string signed_transaction::serialize() const {
|
|||
rlp_encoder::encode(remove_0x(value)) +
|
||||
rlp_encoder::encode(remove_0x(data)) +
|
||||
rlp_encoder::encode(remove_0x(v)) +
|
||||
rlp_encoder::encode(remove_0x(r)) +
|
||||
rlp_encoder::encode(remove_0x(s));
|
||||
rlp_encoder::encode(remove_leading_00(remove_0x(r))) +
|
||||
rlp_encoder::encode(remove_leading_00(remove_0x(s)));
|
||||
|
||||
return add_0x(bytes2hex(rlp_encoder::encode_length(serialized.size(), 192) + serialized));
|
||||
}
|
||||
|
|
@ -234,9 +234,9 @@ void signed_transaction::deserialize(const std::string &raw_tx) {
|
|||
boost::algorithm::to_lower(data);
|
||||
v = add_0x(rlp_array.at(6));
|
||||
boost::algorithm::to_lower(v);
|
||||
r = add_0x(rlp_array.at(7));
|
||||
r = add_0x(add_leading_00(rlp_array.at(7)));
|
||||
boost::algorithm::to_lower(r);
|
||||
s = add_0x(rlp_array.at(8));
|
||||
s = add_0x(add_leading_00(rlp_array.at(8)));
|
||||
boost::algorithm::to_lower(s);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -49,4 +49,24 @@ std::string remove_0x(const std::string &s) {
|
|||
return s;
|
||||
}
|
||||
|
||||
std::string add_leading_00(const std::string &s) {
|
||||
std::string result = s;
|
||||
|
||||
while (result.size() < 64) {
|
||||
result = "00" + result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string remove_leading_00(const std::string &s) {
|
||||
std::string result = s;
|
||||
|
||||
while (result.size() > 1 && result.substr(0, 2) == "00") {
|
||||
result = result.substr(2);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
}}} // namespace graphene::peerplays_sidechain::ethereum
|
||||
|
|
|
|||
|
|
@ -14,6 +14,10 @@ std::string add_0x(const std::string &s);
|
|||
|
||||
std::string remove_0x(const std::string &s);
|
||||
|
||||
std::string add_leading_00(const std::string &s);
|
||||
|
||||
std::string remove_leading_00(const std::string &s);
|
||||
|
||||
template <typename T>
|
||||
std::string to_hex(const T &val, bool add_front_zero = true) {
|
||||
std::stringstream stream;
|
||||
|
|
|
|||
|
|
@ -20,10 +20,11 @@ public:
|
|||
sidechain_net_handler(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options);
|
||||
virtual ~sidechain_net_handler();
|
||||
|
||||
sidechain_type get_sidechain();
|
||||
std::vector<std::string> get_sidechain_deposit_addresses();
|
||||
std::vector<std::string> get_sidechain_withdraw_addresses();
|
||||
std::string get_private_key(std::string public_key);
|
||||
sidechain_type get_sidechain() const;
|
||||
std::vector<std::string> get_sidechain_deposit_addresses() const;
|
||||
std::vector<std::string> get_sidechain_withdraw_addresses() const;
|
||||
std::vector<sidechain_transaction_object> get_sidechain_transaction_objects(sidechain_transaction_status status) const;
|
||||
std::string get_private_key(std::string public_key) const;
|
||||
|
||||
bool proposal_exists(int32_t operation_tag, const object_id_type &object_id, boost::optional<chain::operation &> proposal_op = boost::none);
|
||||
bool signer_expected(const sidechain_transaction_object &sto, son_id_type signer);
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ sidechain_net_handler::sidechain_net_handler(peerplays_sidechain_plugin &_plugin
|
|||
sidechain_net_handler::~sidechain_net_handler() {
|
||||
}
|
||||
|
||||
sidechain_type sidechain_net_handler::get_sidechain() {
|
||||
sidechain_type sidechain_net_handler::get_sidechain() const {
|
||||
return sidechain;
|
||||
}
|
||||
|
||||
std::vector<std::string> sidechain_net_handler::get_sidechain_deposit_addresses() {
|
||||
std::vector<std::string> sidechain_net_handler::get_sidechain_deposit_addresses() const {
|
||||
std::vector<std::string> result;
|
||||
|
||||
const auto &sidechain_addresses_idx = database.get_index_type<sidechain_address_index>();
|
||||
|
|
@ -38,7 +38,7 @@ std::vector<std::string> sidechain_net_handler::get_sidechain_deposit_addresses(
|
|||
return result;
|
||||
}
|
||||
|
||||
std::vector<std::string> sidechain_net_handler::get_sidechain_withdraw_addresses() {
|
||||
std::vector<std::string> sidechain_net_handler::get_sidechain_withdraw_addresses() const {
|
||||
std::vector<std::string> result;
|
||||
|
||||
const auto &sidechain_addresses_idx = database.get_index_type<sidechain_address_index>();
|
||||
|
|
@ -51,7 +51,20 @@ std::vector<std::string> sidechain_net_handler::get_sidechain_withdraw_addresses
|
|||
return result;
|
||||
}
|
||||
|
||||
std::string sidechain_net_handler::get_private_key(std::string public_key) {
|
||||
std::vector<sidechain_transaction_object> sidechain_net_handler::get_sidechain_transaction_objects(sidechain_transaction_status status) const {
|
||||
std::vector<sidechain_transaction_object> result;
|
||||
|
||||
const auto &idx = database.get_index_type<sidechain_transaction_index>().indices().get<by_sidechain_and_status>();
|
||||
const auto &idx_range = idx.equal_range(std::make_tuple(sidechain, status));
|
||||
std::for_each(idx_range.first, idx_range.second,
|
||||
[&result](const sidechain_transaction_object &sto) {
|
||||
result.push_back(sto);
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string sidechain_net_handler::get_private_key(std::string public_key) const {
|
||||
auto private_key_itr = private_keys.find(public_key);
|
||||
if (private_key_itr != private_keys.end()) {
|
||||
return private_key_itr->second;
|
||||
|
|
@ -473,10 +486,9 @@ void sidechain_net_handler::process_withdrawals() {
|
|||
}
|
||||
|
||||
void sidechain_net_handler::process_sidechain_transactions() {
|
||||
const auto &idx = database.get_index_type<sidechain_transaction_index>().indices().get<by_sidechain_and_status>();
|
||||
const auto &idx_range = idx.equal_range(std::make_tuple(sidechain, sidechain_transaction_status::valid));
|
||||
const auto stos = get_sidechain_transaction_objects(sidechain_transaction_status::valid);
|
||||
|
||||
std::for_each(idx_range.first, idx_range.second, [&](const sidechain_transaction_object &sto) {
|
||||
std::for_each(stos.cbegin(), stos.cend(), [&](const sidechain_transaction_object &sto) {
|
||||
if ((sto.id == object_id_type(0, 0, 0)) || !signer_expected(sto, plugin.get_current_son_id(sidechain))) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -520,10 +532,9 @@ void sidechain_net_handler::process_sidechain_transactions() {
|
|||
}
|
||||
|
||||
void sidechain_net_handler::send_sidechain_transactions() {
|
||||
const auto &idx = database.get_index_type<sidechain_transaction_index>().indices().get<by_sidechain_and_status>();
|
||||
const auto &idx_range = idx.equal_range(std::make_tuple(sidechain, sidechain_transaction_status::complete));
|
||||
const auto stos = get_sidechain_transaction_objects(sidechain_transaction_status::complete);
|
||||
|
||||
std::for_each(idx_range.first, idx_range.second, [&](const sidechain_transaction_object &sto) {
|
||||
std::for_each(stos.cbegin(), stos.cend(), [&](const sidechain_transaction_object &sto) {
|
||||
if (sto.id == object_id_type(0, 0, 0)) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -555,10 +566,9 @@ void sidechain_net_handler::send_sidechain_transactions() {
|
|||
}
|
||||
|
||||
void sidechain_net_handler::settle_sidechain_transactions() {
|
||||
const auto &idx = database.get_index_type<sidechain_transaction_index>().indices().get<by_sidechain_and_status>();
|
||||
const auto &idx_range = idx.equal_range(std::make_tuple(sidechain, sidechain_transaction_status::sent));
|
||||
const auto stos = get_sidechain_transaction_objects(sidechain_transaction_status::sent);
|
||||
|
||||
std::for_each(idx_range.first, idx_range.second, [&](const sidechain_transaction_object &sto) {
|
||||
std::for_each(stos.cbegin(), stos.cend(), [&](const sidechain_transaction_object &sto) {
|
||||
if (sto.id == object_id_type(0, 0, 0)) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,7 +76,7 @@ std::string ethereum_rpc_client::get_network_id() {
|
|||
}
|
||||
|
||||
std::string ethereum_rpc_client::get_nonce(const std::string &address) {
|
||||
const std::string reply_str = eth_get_transaction_count("[\"" + address + "\", \"latest\"]");
|
||||
const std::string reply_str = eth_get_transaction_count("[\"" + address + "\", \"pending\"]");
|
||||
const auto nonce_string = retrieve_value_from_reply(reply_str, "");
|
||||
if (!nonce_string.empty()) {
|
||||
const auto nonce_val = ethereum::from_hex<boost::multiprecision::uint256_t>(nonce_string);
|
||||
|
|
|
|||
Loading…
Reference in a new issue