Merge branch 'bug/484-multiple-eth-withdrawals' into 'develop'

#484 multiple eth withdrawals

See merge request PBSA/peerplays!189
This commit is contained in:
serkixenos 2022-12-08 14:03:14 +00:00
commit 1bf5c82101
6 changed files with 57 additions and 22 deletions

View file

@ -210,8 +210,8 @@ std::string signed_transaction::serialize() const {
rlp_encoder::encode(remove_0x(value)) + rlp_encoder::encode(remove_0x(value)) +
rlp_encoder::encode(remove_0x(data)) + rlp_encoder::encode(remove_0x(data)) +
rlp_encoder::encode(remove_0x(v)) + rlp_encoder::encode(remove_0x(v)) +
rlp_encoder::encode(remove_0x(r)) + rlp_encoder::encode(remove_leading_00(remove_0x(r))) +
rlp_encoder::encode(remove_0x(s)); rlp_encoder::encode(remove_leading_00(remove_0x(s)));
return add_0x(bytes2hex(rlp_encoder::encode_length(serialized.size(), 192) + serialized)); 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); boost::algorithm::to_lower(data);
v = add_0x(rlp_array.at(6)); v = add_0x(rlp_array.at(6));
boost::algorithm::to_lower(v); 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); 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); boost::algorithm::to_lower(s);
} }

View file

@ -49,4 +49,24 @@ std::string remove_0x(const std::string &s) {
return 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 }}} // namespace graphene::peerplays_sidechain::ethereum

View file

@ -14,6 +14,10 @@ std::string add_0x(const std::string &s);
std::string remove_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> template <typename T>
std::string to_hex(const T &val, bool add_front_zero = true) { std::string to_hex(const T &val, bool add_front_zero = true) {
std::stringstream stream; std::stringstream stream;

View file

@ -20,10 +20,11 @@ public:
sidechain_net_handler(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options); sidechain_net_handler(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options);
virtual ~sidechain_net_handler(); virtual ~sidechain_net_handler();
sidechain_type get_sidechain(); sidechain_type get_sidechain() const;
std::vector<std::string> get_sidechain_deposit_addresses(); std::vector<std::string> get_sidechain_deposit_addresses() const;
std::vector<std::string> get_sidechain_withdraw_addresses(); std::vector<std::string> get_sidechain_withdraw_addresses() const;
std::string get_private_key(std::string public_key); 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 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); bool signer_expected(const sidechain_transaction_object &sto, son_id_type signer);

View file

@ -21,11 +21,11 @@ sidechain_net_handler::sidechain_net_handler(peerplays_sidechain_plugin &_plugin
sidechain_net_handler::~sidechain_net_handler() { sidechain_net_handler::~sidechain_net_handler() {
} }
sidechain_type sidechain_net_handler::get_sidechain() { sidechain_type sidechain_net_handler::get_sidechain() const {
return sidechain; 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; std::vector<std::string> result;
const auto &sidechain_addresses_idx = database.get_index_type<sidechain_address_index>(); 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; 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; std::vector<std::string> result;
const auto &sidechain_addresses_idx = database.get_index_type<sidechain_address_index>(); 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; 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); auto private_key_itr = private_keys.find(public_key);
if (private_key_itr != private_keys.end()) { if (private_key_itr != private_keys.end()) {
return private_key_itr->second; return private_key_itr->second;
@ -473,10 +486,9 @@ void sidechain_net_handler::process_withdrawals() {
} }
void sidechain_net_handler::process_sidechain_transactions() { 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 stos = get_sidechain_transaction_objects(sidechain_transaction_status::valid);
const auto &idx_range = idx.equal_range(std::make_tuple(sidechain, 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))) { if ((sto.id == object_id_type(0, 0, 0)) || !signer_expected(sto, plugin.get_current_son_id(sidechain))) {
return; return;
} }
@ -520,10 +532,9 @@ void sidechain_net_handler::process_sidechain_transactions() {
} }
void sidechain_net_handler::send_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 stos = get_sidechain_transaction_objects(sidechain_transaction_status::complete);
const auto &idx_range = idx.equal_range(std::make_tuple(sidechain, 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)) { if (sto.id == object_id_type(0, 0, 0)) {
return; return;
} }
@ -555,10 +566,9 @@ void sidechain_net_handler::send_sidechain_transactions() {
} }
void sidechain_net_handler::settle_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 stos = get_sidechain_transaction_objects(sidechain_transaction_status::sent);
const auto &idx_range = idx.equal_range(std::make_tuple(sidechain, 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)) { if (sto.id == object_id_type(0, 0, 0)) {
return; return;
} }

View file

@ -76,7 +76,7 @@ std::string ethereum_rpc_client::get_network_id() {
} }
std::string ethereum_rpc_client::get_nonce(const std::string &address) { 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, ""); const auto nonce_string = retrieve_value_from_reply(reply_str, "");
if (!nonce_string.empty()) { if (!nonce_string.empty()) {
const auto nonce_val = ethereum::from_hex<boost::multiprecision::uint256_t>(nonce_string); const auto nonce_val = ethereum::from_hex<boost::multiprecision::uint256_t>(nonce_string);