#308 - delete sidechain_type map for public_key in son_info (we store son_info as map itself)

This commit is contained in:
Vlad Dobromyslov 2022-03-28 16:01:00 +03:00
parent cbca83a90e
commit 32d67b2c30
5 changed files with 16 additions and 29 deletions

View file

@ -787,13 +787,14 @@ void database::update_active_sons()
flat_map<sidechain_type, vector<son_info> > new_active_sons;
const auto &acc = get(gpo.parameters.son_account());
for( const auto& sidechain_sons : sons ){
const auto& sidechain = sidechain_sons.first;
for( const son_object& son : sidechain_sons.second ) {
son_info swi;
swi.son_id = son.id;
swi.weight = acc.active.account_auths.at(son.son_account);
swi.signing_key = son.signing_key;
swi.sidechain_public_keys = son.sidechain_public_keys;
new_active_sons[sidechain_sons.first].push_back(swi);
swi.public_key = son.sidechain_public_keys.at(sidechain);
new_active_sons[sidechain].push_back(swi);
}
}

View file

@ -14,26 +14,15 @@ namespace graphene { namespace chain {
son_id_type son_id;
weight_type weight = 0;
public_key_type signing_key;
flat_map<sidechain_type, string> sidechain_public_keys; //! Fixme - delete map from here
string public_key;
bool operator==(const son_info& rhs) const {
bool son_sets_equal =
(son_id == rhs.son_id) &&
(weight == rhs.weight) &&
(signing_key == rhs.signing_key) &&
(sidechain_public_keys.size() == rhs.sidechain_public_keys.size());
(public_key == rhs.public_key);
if (son_sets_equal) {
bool sidechain_public_keys_equal = true;
for (size_t i = 0; i < sidechain_public_keys.size(); i++) {
const auto lhs_scpk = sidechain_public_keys.nth(i);
const auto rhs_scpk = rhs.sidechain_public_keys.nth(i);
sidechain_public_keys_equal = sidechain_public_keys_equal &&
(lhs_scpk->first == rhs_scpk->first) &&
(lhs_scpk->second == rhs_scpk->second);
}
son_sets_equal = son_sets_equal && sidechain_public_keys_equal;
}
return son_sets_equal;
}
};
@ -44,4 +33,4 @@ FC_REFLECT( graphene::chain::son_info,
(son_id)
(weight)
(signing_key)
(sidechain_public_keys) )
(public_key) )

View file

@ -1040,7 +1040,7 @@ bool sidechain_net_handler_bitcoin::process_proposal(const proposal_object &po)
const auto& active_sons = gpo.active_sons.at(sidechain);
vector<string> son_pubkeys_bitcoin;
for (const son_info &si : active_sons) {
son_pubkeys_bitcoin.push_back(si.sidechain_public_keys.at(sidechain));
son_pubkeys_bitcoin.push_back(si.public_key);
}
string reply_str = create_primary_wallet_address(active_sons);
@ -1346,8 +1346,7 @@ void sidechain_net_handler_bitcoin::process_sidechain_addresses() {
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.at(sidechain)) {
std::string pub_key_str = son.sidechain_public_keys.at(sidechain);
auto pubkey = fc::ecc::public_key(create_public_key_data(parse_hex(pub_key_str)));
auto pubkey = fc::ecc::public_key(create_public_key_data(parse_hex(son.public_key)));
pubkeys.push_back(std::make_pair(pubkey, son.weight));
}
@ -1518,8 +1517,8 @@ bool sidechain_net_handler_bitcoin::settle_sidechain_transaction(const sidechain
using namespace bitcoin;
std::vector<std::pair<fc::ecc::public_key, uint16_t>> pubkey_weights;
for (auto si : sto.signers) {
std::string pub_key_str = si.sidechain_public_keys.at(sidechain);
auto pub_key = fc::ecc::public_key(create_public_key_data(parse_hex(pub_key_str)));
//! Fixme - check public_key here
auto pub_key = fc::ecc::public_key(create_public_key_data(parse_hex(si.public_key)));
pubkey_weights.push_back(std::make_pair(pub_key, si.weight));
}
btc_weighted_multisig_address addr(pubkey_weights, network_type);
@ -1559,8 +1558,7 @@ std::string sidechain_net_handler_bitcoin::create_primary_wallet_address(const s
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);
auto pub_key = fc::ecc::public_key(create_public_key_data(parse_hex(pub_key_str)));
auto pub_key = fc::ecc::public_key(create_public_key_data(parse_hex(son.public_key)));
pubkey_weights.push_back(std::make_pair(pub_key, son.weight));
}
@ -1854,8 +1852,7 @@ std::string sidechain_net_handler_bitcoin::get_redeemscript_for_userdeposit(cons
std::vector<std::pair<fc::ecc::public_key, uint16_t>> pubkey_weights;
for (auto &son : obj->sons.at(sidechain)) {
std::string pub_key_str = son.sidechain_public_keys.at(sidechain);
auto pub_key = fc::ecc::public_key(create_public_key_data(parse_hex(pub_key_str)));
auto pub_key = fc::ecc::public_key(create_public_key_data(parse_hex(son.public_key)));
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)));

View file

@ -252,7 +252,7 @@ bool sidechain_net_handler_hive::process_proposal(const proposal_object &po) {
uint32_t total_weight = 0;
for (const auto &wallet_son : wallet_sons) {
total_weight = total_weight + wallet_son.weight;
account_auths[wallet_son.sidechain_public_keys.at(sidechain)] = wallet_son.weight;
account_auths[wallet_son.public_key] = wallet_son.weight;
}
std::string memo_key = node_rpc_client->get_account_memo_key("son-account");
@ -493,7 +493,7 @@ void sidechain_net_handler_hive::process_primary_wallet() {
uint32_t total_weight = 0;
for (const auto &active_son : active_sons) {
total_weight = total_weight + active_son.weight;
account_auths[active_son.sidechain_public_keys.at(sidechain)] = active_son.weight;
account_auths[active_son.public_key] = active_son.weight;
}
std::string memo_key = node_rpc_client->get_account_memo_key("son-account");

View file

@ -160,7 +160,7 @@ BOOST_AUTO_TEST_CASE( son_wallet_recreate_test ) {
si.son_id = son_id_type(0);
si.weight = 1000;
si.signing_key = alice_public_key;
si.sidechain_public_keys[sidechain_type::bitcoin] = "";
si.public_key = "";
op.sons[sidechain_type::bitcoin].push_back(si);
}
@ -169,7 +169,7 @@ BOOST_AUTO_TEST_CASE( son_wallet_recreate_test ) {
si.son_id = son_id_type(1);
si.weight = 1000;
si.signing_key = bob_public_key;
si.sidechain_public_keys[sidechain_type::bitcoin] = "";
si.public_key = "";
op.sons[sidechain_type::bitcoin].push_back(si);
}