|
|
|
|
@ -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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*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(_plugin, options) {
|
|
|
|
|
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 swwo = idx.find(swwo_id);
|
|
|
|
|
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;
|
|
|
|
|
//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));
|
|
|
|
|
//
|
|
|
|
|
//const auto &block = database.fetch_block_by_number(swwo_block_num);
|
|
|
|
|
//
|
|
|
|
|
//for (const auto &tx : block->transactions) {
|
|
|
|
|
// if (tx.id().str() == swwo_peerplays_transaction_id) {
|
|
|
|
|
// operation op = tx.operations[swwo_op_idx];
|
|
|
|
|
// transfer_operation t_op = op.get<transfer_operation>();
|
|
|
|
|
//
|
|
|
|
|
// price asset_price = database.get<asset_object>(t_op.amount.asset_id).options.core_exchange_rate;
|
|
|
|
|
// asset peerplays_asset = asset(t_op.amount.amount * asset_price.base.amount / asset_price.quote.amount);
|
|
|
|
|
//
|
|
|
|
|
// 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>();
|
|
|
|
|
//const auto st = st_idx.find(object_id);
|
|
|
|
|
//if (st == st_idx.end()) {
|
|
|
|
|
//
|
|
|
|
|
// std::string tx_str = "";
|
|
|
|
|
//
|
|
|
|
|
// if (object_id.is<son_wallet_withdraw_id_type>()) {
|
|
|
|
|
// 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()) {
|
|
|
|
|
//
|
|
|
|
|
// 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);
|
|
|
|
|
//}
|
|
|
|
|
const auto &block = database.fetch_block_by_number(swwo_block_num);
|
|
|
|
|
|
|
|
|
|
for (const auto &tx : block->transactions) {
|
|
|
|
|
if (tx.id().str() == swwo_peerplays_transaction_id) {
|
|
|
|
|
operation op = tx.operations[swwo_op_idx];
|
|
|
|
|
transfer_operation t_op = op.get<transfer_operation>();
|
|
|
|
|
|
|
|
|
|
price asset_price = database.get<asset_object>(t_op.amount.asset_id).options.core_exchange_rate;
|
|
|
|
|
asset peerplays_asset = asset(t_op.amount.amount * asset_price.base.amount / asset_price.quote.amount);
|
|
|
|
|
|
|
|
|
|
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>();
|
|
|
|
|
const auto st = st_idx.find(object_id);
|
|
|
|
|
if (st == st_idx.end()) {
|
|
|
|
|
|
|
|
|
|
std::string tx_str = "";
|
|
|
|
|
|
|
|
|
|
if (object_id.is<son_wallet_withdraw_id_type>()) {
|
|
|
|
|
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()) {
|
|
|
|
|
tx_str = create_withdrawal_transaction(*swwo);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
transaction_ok = (op_tx_str == tx_str);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
process_ok = true;
|
|
|
|
|
transaction_ok = true;
|
|
|
|
|
|
|
|
|
|
should_approve = process_ok &&
|
|
|
|
|
transaction_ok;
|
|
|
|
|
break;
|
|
|
|
|
@ -588,18 +550,17 @@ bool sidechain_net_handler_ethereum::settle_sidechain_transaction(const sidechai
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for(const auto &entry_receipt : json_receipt.get_child("result.logs")) {
|
|
|
|
|
if( boost::algorithm::to_lower_copy(wallet_contract_address) == entry_receipt.second.get<std::string>("address") ) {
|
|
|
|
|
count += 1;
|
|
|
|
|
//! Fixme - compare data somehow?
|
|
|
|
|
//if( sto.transaction == entry_receipt.second.get<std::string>("data") ) {
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
if( "0x1" == json_receipt.get<std::string>("result.status") )
|
|
|
|
|
{
|
|
|
|
|
count += 1;
|
|
|
|
|
//! Fixme - compare data somehow?
|
|
|
|
|
//if( sto.transaction == entry_receipt.second.get<std::string>("data") ) {
|
|
|
|
|
//}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//! 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));
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//! Create data of transaction
|
|
|
|
|
ethereum::transaction transaction;
|
|
|
|
|
ethereum::update_owners_encoder encoder;
|
|
|
|
|
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) {
|
|
|
|
|
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) {
|
|
|
|
|
|