diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_eth.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_eth.hpp index a690bc40..2c89aa50 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_eth.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_eth.hpp @@ -10,7 +10,6 @@ #include #include -#include #include #include @@ -120,6 +119,8 @@ public: bool walletpassphrase(const std::string &passphrase, uint32_t timeout = 60); std::string chain_id;//256 bit value + std::vector owners; + std::string safe_account_addr; private: class ethereum_function_call_encoder { public: @@ -137,8 +138,6 @@ private: uint64_t t_id; std::string account_address; std::string transaction_id; - std::string safe_account_addr; - std::vector owners; uint32_t threshold; std::unordered_map m_requests; std::string balance; @@ -186,7 +185,6 @@ private: std::unique_ptr eth_client; fc::future on_changed_objects_task; - bitcoin::bitcoin_address::network network_type; std::mutex event_handler_mutex; typedef std::lock_guard scoped_lock; @@ -202,10 +200,12 @@ private: std::string send_transaction(const sidechain_transaction_object &sto); void handle_event(const std::string &event_data); - std::string get_redeemscript_for_userdeposit(const std::string &user_address); std::vector extract_info_from_block(const std::string &_block); void on_changed_objects(const vector &ids, const flat_set &accounts); void on_changed_objects_cb(const vector &ids, const flat_set &accounts); + + std::vector parse_hex(const std::string &str); + fc::ecc::public_key_data create_public_key_data(const std::vector &public_key); }; }} // namespace graphene::peerplays_sidechain diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_eth.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_eth.cpp index 0abd9ba7..caa88650 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_eth.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_eth.cpp @@ -20,6 +20,8 @@ #include #include +#include + #include extern "C" { #include @@ -774,8 +776,8 @@ void sidechain_net_handler_eth::process_primary_wallet() { const auto &active_sw = swi.rbegin(); if (active_sw != swi.rend()) { - if ((active_sw->addresses.find(sidechain_type::bitcoin) == active_sw->addresses.end()) || - (active_sw->addresses.at(sidechain_type::bitcoin).empty())) { + if ((active_sw->addresses.find(sidechain_type::ethereum) == active_sw->addresses.end()) || + (active_sw->addresses.at(sidechain_type::ethereum).empty())) { if (proposal_exists(chain::operation::tag::value, active_sw->id)) { return; @@ -787,6 +789,9 @@ void sidechain_net_handler_eth::process_primary_wallet() { string reply_str = create_primary_wallet_address(active_sons); std::stringstream active_pw_ss(reply_str); + + ilog("### process_primary_wallet: ${reply}", ("reply", reply_str)); + boost::property_tree::ptree active_pw_pt; boost::property_tree::read_json(active_pw_ss, active_pw_pt); if (active_pw_pt.count("error") && active_pw_pt.get_child("error").empty()) { @@ -805,7 +810,7 @@ void sidechain_net_handler_eth::process_primary_wallet() { son_wallet_update_operation swu_op; swu_op.payer = gpo.parameters.son_account(); swu_op.son_wallet_id = active_sw->id; - swu_op.sidechain = sidechain_type::bitcoin; + swu_op.sidechain = sidechain_type::ethereum; swu_op.address = res.str(); proposal_op.proposed_ops.emplace_back(swu_op); @@ -842,12 +847,11 @@ void sidechain_net_handler_eth::process_primary_wallet() { } void sidechain_net_handler_eth::process_sidechain_addresses() { - using namespace bitcoin; - +/* const chain::global_property_object &gpo = database.get_global_properties(); std::vector> pubkeys; for (auto &son : gpo.active_sons) { - std::string pub_key_str = son.sidechain_public_keys.at(sidechain_type::bitcoin); + std::string pub_key_str = son.sidechain_public_keys.at(sidechain_type::ethereum); auto pubkey = fc::ecc::public_key(create_public_key_data(parse_hex(pub_key_str))); pubkeys.push_back(std::make_pair(pubkey, son.weight)); } @@ -896,6 +900,7 @@ void sidechain_net_handler_eth::process_sidechain_addresses() { } return retval; }); +*/ } bool sidechain_net_handler_eth::process_deposit(const son_wallet_deposit_object &swdo) { @@ -998,22 +1003,31 @@ bool sidechain_net_handler_eth::settle_sidechain_transaction(const sidechain_tra return false; } +std::vector sidechain_net_handler_eth::parse_hex(const std::string &str) { + std::vector vec(str.size() / 2); + fc::from_hex(str, vec.data(), vec.size()); + return vec; +} + std::string sidechain_net_handler_eth::create_primary_wallet_address(const std::vector &son_pubkeys) { - using namespace bitcoin; - - std::vector> pubkey_weights; - for (auto &son : son_pubkeys) { - std::string pub_key_str = son.sidechain_public_keys.at(sidechain_type::bitcoin); - auto pub_key = fc::ecc::public_key(create_public_key_data(parse_hex(pub_key_str))); - pubkey_weights.push_back(std::make_pair(pub_key, son.weight)); - } - - btc_weighted_multisig_address addr(pubkey_weights, network_type); - std::stringstream ss; - ss << "{\"result\": {\"address\": \"" << addr.get_address() << "\", \"redeemScript\": \"" << fc::to_hex(addr.get_redeem_script()) << "\"" - << "}, \"error\":null}"; + ss << "{\"result\": {\"address\": \"" << eth_client->safe_account_addr << "\"" << "}, "; + ss << "\"onwers\": ["; + for (auto &owner : eth_client->owners){ + ss << "\"" << owner << "\","; + } + ss.seekp(-1, std::ios_base::end); + ss << "], keys: ["; + + for (auto &son : son_pubkeys) { + std::string pub_key_str = son.sidechain_public_keys.at(sidechain_type::ethereum); + ss << "\"" << pub_key_str << "\","; + } + ss.seekp(-1, std::ios_base::end); + ss << "], "; + + ss << "\"error\":null}"; std::string res = ss.str(); return res; @@ -1063,31 +1077,6 @@ std::string sidechain_net_handler_eth::send_transaction(const sidechain_transact void sidechain_net_handler_eth::handle_event(const std::string &event_data) { } -std::string sidechain_net_handler_eth::get_redeemscript_for_userdeposit(const std::string &user_address) { - using namespace bitcoin; - const auto &sidechain_addresses_idx = database.get_index_type().indices().get(); - const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sidechain, user_address, time_point_sec::maximum())); - if (addr_itr == sidechain_addresses_idx.end()) { - return ""; - } - - const auto &idx = database.get_index_type().indices().get(); - auto obj = idx.rbegin(); - if (obj == idx.rend() || obj->addresses.find(sidechain_type::bitcoin) == obj->addresses.end()) { - return ""; - } - - std::vector> pubkey_weights; - for (auto &son : obj->sons) { - std::string pub_key_str = son.sidechain_public_keys.at(sidechain_type::bitcoin); - auto pub_key = fc::ecc::public_key(create_public_key_data(parse_hex(pub_key_str))); - pubkey_weights.push_back(std::make_pair(pub_key, son.weight)); - } - auto user_pub_key = fc::ecc::public_key(create_public_key_data(parse_hex(addr_itr->deposit_public_key))); - btc_one_or_weighted_multisig_address deposit_addr(user_pub_key, pubkey_weights, network_type); - return fc::to_hex(deposit_addr.get_redeem_script()); -} - std::vector sidechain_net_handler_eth::extract_info_from_block(const std::string &_block) { std::stringstream ss(_block); boost::property_tree::ptree block; @@ -1113,5 +1102,14 @@ void sidechain_net_handler_eth::on_changed_objects(const vector void sidechain_net_handler_eth::on_changed_objects_cb(const vector &ids, const flat_set &accounts) { } +fc::ecc::public_key_data sidechain_net_handler_eth::create_public_key_data(const std::vector &public_key) { + FC_ASSERT(public_key.size() == 33); + fc::ecc::public_key_data key; + for (size_t i = 0; i < 33; i++) { + key.at(i) = public_key[i]; + } + return key; +} + // ============================================================================= }} // namespace graphene::peerplays_sidechain