withdraw transaction

This commit is contained in:
Vlad Dobromyslov 2022-08-05 11:29:21 +03:00
parent 212e5bc7ad
commit 46ac4d79a3
4 changed files with 72 additions and 90 deletions

View file

@ -6,7 +6,7 @@
namespace graphene { namespace peerplays_sidechain { namespace ethereum { namespace graphene { namespace peerplays_sidechain { namespace ethereum {
//! base_encoder //! base_encoder
std::string base_encoder::encode_uint256(uint64_t value) std::string base_encoder::encode_uint256(boost::multiprecision::uint256_t value)
{ {
return (boost::format("%x") % boost::io::group(std::setw(64), std::setfill('0'), value)).str(); return (boost::format("%x") % boost::io::group(std::setw(64), std::setfill('0'), value)).str();
} }
@ -41,5 +41,17 @@ std::string update_owners_encoder::encode(const std::vector<std::pair<std::strin
return data; return data;
} }
//! withdrawal_encoder
std::string withdrawal_encoder::encode(const std::string& to, boost::multiprecision::uint256_t amount, const std::string& object_id) const
{
std::string data = "0x" + function_signature;
data += base_encoder::encode_address(to);
data += base_encoder::encode_uint256(amount);
data += base_encoder::encode_uint256(32*3);
data += base_encoder::encode_string(object_id);
return data;
}
}}} // namespace graphene::peerplays_sidechain::ethereum }}} // namespace graphene::peerplays_sidechain::ethereum

View file

@ -2,12 +2,13 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include <boost/multiprecision/cpp_int.hpp>
namespace graphene { namespace peerplays_sidechain { namespace ethereum { namespace graphene { namespace peerplays_sidechain { namespace ethereum {
class base_encoder { class base_encoder {
public: public:
static std::string encode_uint256(uint64_t value); static std::string encode_uint256(boost::multiprecision::uint256_t value);
static std::string encode_address(const std::string& value); static std::string encode_address(const std::string& value);
static std::string encode_string(const std::string& value); static std::string encode_string(const std::string& value);
}; };
@ -19,6 +20,13 @@ public:
std::string encode(const std::vector<std::pair<std::string, uint16_t>>& owners_weights, const std::string& object_id) const; std::string encode(const std::vector<std::pair<std::string, uint16_t>>& owners_weights, const std::string& object_id) const;
}; };
class withdrawal_encoder {
public:
const std::string function_signature = "e088747b"; //! withdraw(address,uint256,string)
std::string encode(const std::string& to, boost::multiprecision::uint256_t amount, const std::string& object_id) const;
};
/*class ethereum_function_call_encoder { /*class ethereum_function_call_encoder {
public: public:
enum operation_t { enum operation_t {

View file

@ -25,7 +25,6 @@ public:
std::string send_transaction(const std::string& params); std::string send_transaction(const std::string& params);
std::string get_transaction_receipt(const std::string& params); std::string get_transaction_receipt(const std::string& params);
//std::string withdraw();
}; };
class sidechain_net_handler_ethereum : public sidechain_net_handler { class sidechain_net_handler_ethereum : public sidechain_net_handler {

View file

@ -62,11 +62,6 @@ std::string ethereum_rpc_client::get_transaction_receipt(const std::string& para
return send_post_request("eth_getTransactionReceipt", "[\"" + params + "\"]", debug_rpc_calls); return send_post_request("eth_getTransactionReceipt", "[\"" + params + "\"]", debug_rpc_calls);
} }
/*std::string ethereum_rpc_client::withdraw() {
const std::string params = "[ { \"from\": \"0x5FbBb31BE52608D2F52247E8400B7fCaA9E0bC12\", \"to\": \"0x3E84f248Cd00A2FDaaDfa0dC5c3ff64D8767Fb01\", \"data\": \"0xe088747b00000000000000000000000009ee460834498a4ee361beb819470061b7381b490000000000000000000000000000000000000000000000000de0b6b3a764000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000006312e33362e330000000000000000000000000000000000000000000000000000\" } ]";
return send_post_request("eth_sendTransaction", params, debug_rpc_calls);
}*/
sidechain_net_handler_ethereum::sidechain_net_handler_ethereum(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) : sidechain_net_handler_ethereum::sidechain_net_handler_ethereum(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) :
sidechain_net_handler(_plugin, options) { sidechain_net_handler(_plugin, options) {
sidechain = sidechain_type::ethereum; sidechain = sidechain_type::ethereum;
@ -275,81 +270,48 @@ bool sidechain_net_handler_ethereum::process_proposal(const proposal_object &po)
const auto &idx = database.get_index_type<son_wallet_withdraw_index>().indices().get<by_id>(); const auto &idx = database.get_index_type<son_wallet_withdraw_index>().indices().get<by_id>();
const auto swwo = idx.find(swwo_id); const auto swwo = idx.find(swwo_id);
if (swwo != idx.end()) { if (swwo != idx.end()) {
uint32_t swwo_block_num = swwo->block_num;
std::string swwo_peerplays_transaction_id = swwo->peerplays_transaction_id;
uint32_t swwo_op_idx = std::stoll(swwo->peerplays_uid.substr(swwo->peerplays_uid.find_last_of("-") + 1));
//uint32_t swwo_block_num = swwo->block_num; const auto &block = database.fetch_block_by_number(swwo_block_num);
//std::string swwo_peerplays_transaction_id = swwo->peerplays_transaction_id;
//uint32_t swwo_op_idx = std::stoll(swwo->peerplays_uid.substr(swwo->peerplays_uid.find_last_of("-") + 1)); for (const auto &tx : block->transactions) {
// if (tx.id().str() == swwo_peerplays_transaction_id) {
//const auto &block = database.fetch_block_by_number(swwo_block_num); operation op = tx.operations[swwo_op_idx];
// transfer_operation t_op = op.get<transfer_operation>();
//for (const auto &tx : block->transactions) {
// if (tx.id().str() == swwo_peerplays_transaction_id) { price asset_price = database.get<asset_object>(t_op.amount.asset_id).options.core_exchange_rate;
// operation op = tx.operations[swwo_op_idx]; asset peerplays_asset = asset(t_op.amount.amount * asset_price.base.amount / asset_price.quote.amount);
// transfer_operation t_op = op.get<transfer_operation>();
// process_ok = (t_op.to == gpo.parameters.son_account()) &&
// price asset_price = database.get<asset_object>(t_op.amount.asset_id).options.core_exchange_rate; (swwo->peerplays_from == t_op.from) &&
// asset peerplays_asset = asset(t_op.amount.amount * asset_price.base.amount / asset_price.quote.amount); (swwo->peerplays_asset == peerplays_asset);
// break;
// process_ok = (t_op.to == gpo.parameters.son_account()) && }
// (swwo->peerplays_from == t_op.from) && }
// (swwo->peerplays_asset == peerplays_asset);
// break; object_id_type object_id = op_obj_idx_1.get<sidechain_transaction_create_operation>().object_id;
// } std::string op_tx_str = op_obj_idx_1.get<sidechain_transaction_create_operation>().transaction;
//}
// const auto &st_idx = database.get_index_type<sidechain_transaction_index>().indices().get<by_object_id>();
//object_id_type object_id = op_obj_idx_1.get<sidechain_transaction_create_operation>().object_id; const auto st = st_idx.find(object_id);
//std::string op_tx_str = op_obj_idx_1.get<sidechain_transaction_create_operation>().transaction; if (st == st_idx.end()) {
//
//const auto &st_idx = database.get_index_type<sidechain_transaction_index>().indices().get<by_object_id>(); std::string tx_str = "";
//const auto st = st_idx.find(object_id);
//if (st == st_idx.end()) { if (object_id.is<son_wallet_withdraw_id_type>()) {
// const auto &idx = database.get_index_type<son_wallet_withdraw_index>().indices().get<by_id>();
// std::string tx_str = ""; const auto swwo = idx.find(object_id);
// if (swwo != idx.end()) {
// if (object_id.is<son_wallet_withdraw_id_type>()) { tx_str = create_withdrawal_transaction(*swwo);
// const auto &idx = database.get_index_type<son_wallet_withdraw_index>().indices().get<by_id>(); }
// const auto swwo = idx.find(object_id); }
// if (swwo != idx.end()) {
// transaction_ok = (op_tx_str == tx_str);
// std::stringstream ss_trx(boost::algorithm::unhex(op_tx_str)); }
// hive::signed_transaction op_trx;
// fc::raw::unpack(ss_trx, op_trx, 1000);
//
// uint64_t symbol = 0;
// if (swwo->withdraw_currency == "HBD") {
// symbol = hive::asset::hbd_symbol_ser;
// }
// if (swwo->withdraw_currency == "HIVE") {
// symbol = hive::asset::hive_symbol_ser;
// }
//
// hive::transfer_operation t_op;
// t_op.from = wallet_account_name;
// t_op.to = swwo->withdraw_address;
// t_op.amount.amount = swwo->withdraw_amount;
// t_op.amount.symbol = symbol;
// t_op.memo = "";
//
// hive::signed_transaction htrx;
// htrx.ref_block_num = op_trx.ref_block_num;
// htrx.ref_block_prefix = op_trx.ref_block_prefix;
// htrx.set_expiration(op_trx.expiration);
//
// htrx.operations.push_back(t_op);
//
// std::stringstream ss;
// fc::raw::pack(ss, htrx, 1000);
// tx_str = boost::algorithm::hex(ss.str());
// }
// }
//
// transaction_ok = (op_tx_str == tx_str);
//}
} }
process_ok = true;
transaction_ok = true;
should_approve = process_ok && should_approve = process_ok &&
transaction_ok; transaction_ok;
break; break;
@ -588,18 +550,17 @@ bool sidechain_net_handler_ethereum::settle_sidechain_transaction(const sidechai
return false; return false;
} }
for(const auto &entry_receipt : json_receipt.get_child("result.logs")) { if( "0x1" == json_receipt.get<std::string>("result.status") )
if( boost::algorithm::to_lower_copy(wallet_contract_address) == entry_receipt.second.get<std::string>("address") ) { {
count += 1; count += 1;
//! Fixme - compare data somehow? //! Fixme - compare data somehow?
//if( sto.transaction == entry_receipt.second.get<std::string>("data") ) { //if( sto.transaction == entry_receipt.second.get<std::string>("data") ) {
//} //}
}
} }
} }
//! Check that we have all transactions //! Check that we have all transactions
if(count != json.count("result_array")) { if(count != json.get_child("result_array").size()) {
wlog("Not all receipts received for transaction ${id}", ("id", sto.id)); wlog("Not all receipts received for transaction ${id}", ("id", sto.id));
return false; return false;
} }
@ -617,7 +578,6 @@ std::string sidechain_net_handler_ethereum::create_primary_wallet_transaction(co
owners_weights.emplace_back(std::make_pair(pub_key_str, son.weight)); owners_weights.emplace_back(std::make_pair(pub_key_str, son.weight));
} }
//! Create data of transaction
ethereum::transaction transaction; ethereum::transaction transaction;
ethereum::update_owners_encoder encoder; ethereum::update_owners_encoder encoder;
transaction.data = encoder.encode(owners_weights, object_id); transaction.data = encoder.encode(owners_weights, object_id);
@ -629,7 +589,10 @@ 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) { std::string sidechain_net_handler_ethereum::create_withdrawal_transaction(const son_wallet_withdraw_object &swwo) {
return "Withdrawal-Transaction"; 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();
} }
std::string sidechain_net_handler_ethereum::sign_transaction(const sidechain_transaction_object &sto) { std::string sidechain_net_handler_ethereum::sign_transaction(const sidechain_transaction_object &sto) {