create_primary_wallet_address, create_public_key_data
This commit is contained in:
parent
61fe72fb15
commit
1a684df3f2
2 changed files with 47 additions and 49 deletions
|
|
@ -10,7 +10,6 @@
|
|||
#include <mutex>
|
||||
|
||||
#include <fc/network/http/connection.hpp>
|
||||
#include <graphene/peerplays_sidechain/bitcoin/bitcoin_address.hpp>
|
||||
|
||||
#include <fc/api.hpp>
|
||||
#include <fc/log/logger.hpp>
|
||||
|
|
@ -120,6 +119,8 @@ public:
|
|||
bool walletpassphrase(const std::string &passphrase, uint32_t timeout = 60);
|
||||
|
||||
std::string chain_id;//256 bit value
|
||||
std::vector<std::string> 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<std::string> owners;
|
||||
uint32_t threshold;
|
||||
std::unordered_map<uint64_t, req_t> m_requests;
|
||||
std::string balance;
|
||||
|
|
@ -186,7 +185,6 @@ private:
|
|||
std::unique_ptr<eth_rpc_client> eth_client;
|
||||
|
||||
fc::future<void> on_changed_objects_task;
|
||||
bitcoin::bitcoin_address::network network_type;
|
||||
|
||||
std::mutex event_handler_mutex;
|
||||
typedef std::lock_guard<decltype(event_handler_mutex)> 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<info_for_vin> extract_info_from_block(const std::string &_block);
|
||||
void on_changed_objects(const vector<object_id_type> &ids, const flat_set<account_id_type> &accounts);
|
||||
void on_changed_objects_cb(const vector<object_id_type> &ids, const flat_set<account_id_type> &accounts);
|
||||
|
||||
std::vector<char> parse_hex(const std::string &str);
|
||||
fc::ecc::public_key_data create_public_key_data(const std::vector<char> &public_key);
|
||||
};
|
||||
|
||||
}} // namespace graphene::peerplays_sidechain
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@
|
|||
#include <graphene/utilities/key_conversion.hpp>
|
||||
#include <graphene/peerplays_sidechain/ethereum/transaction.hpp>
|
||||
|
||||
#include <fc/crypto/hex.hpp>
|
||||
|
||||
#include <fc/io/json.hpp>
|
||||
extern "C" {
|
||||
#include <sha3.h>
|
||||
|
|
@ -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<chain::son_wallet_update_operation>::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<std::pair<fc::ecc::public_key, uint16_t>> 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<char> sidechain_net_handler_eth::parse_hex(const std::string &str) {
|
||||
std::vector<char> 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_info> &son_pubkeys) {
|
||||
using namespace bitcoin;
|
||||
|
||||
std::vector<std::pair<fc::ecc::public_key, uint16_t>> 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<sidechain_address_index>().indices().get<by_sidechain_and_deposit_address_and_expires>();
|
||||
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<son_wallet_index>().indices().get<by_id>();
|
||||
auto obj = idx.rbegin();
|
||||
if (obj == idx.rend() || obj->addresses.find(sidechain_type::bitcoin) == obj->addresses.end()) {
|
||||
return "";
|
||||
}
|
||||
|
||||
std::vector<std::pair<fc::ecc::public_key, uint16_t>> 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<info_for_vin> 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<object_id_type>
|
|||
void sidechain_net_handler_eth::on_changed_objects_cb(const vector<object_id_type> &ids, const flat_set<account_id_type> &accounts) {
|
||||
}
|
||||
|
||||
fc::ecc::public_key_data sidechain_net_handler_eth::create_public_key_data(const std::vector<char> &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
|
||||
|
|
|
|||
Loading…
Reference in a new issue