Add redeem_script to son_wallet_object
This commit is contained in:
parent
f3e8dabaa4
commit
d93f5e66b1
7 changed files with 28 additions and 15 deletions
|
|
@ -27,6 +27,7 @@ namespace graphene { namespace chain {
|
|||
son_wallet_id_type son_wallet_id;
|
||||
graphene::peerplays_sidechain::sidechain_type sidechain;
|
||||
string address;
|
||||
graphene::peerplays_sidechain::bytes redeem_script;
|
||||
|
||||
account_id_type fee_payer()const { return payer; }
|
||||
share_type calculate_fee(const fee_parameters_type& k)const { return 0; }
|
||||
|
|
@ -37,4 +38,4 @@ namespace graphene { namespace chain {
|
|||
FC_REFLECT(graphene::chain::son_wallet_recreate_operation::fee_parameters_type, (fee) )
|
||||
FC_REFLECT(graphene::chain::son_wallet_recreate_operation, (fee)(payer)(sons) )
|
||||
FC_REFLECT(graphene::chain::son_wallet_update_operation::fee_parameters_type, (fee) )
|
||||
FC_REFLECT(graphene::chain::son_wallet_update_operation, (fee)(payer)(son_wallet_id)(sidechain)(address) )
|
||||
FC_REFLECT(graphene::chain::son_wallet_update_operation, (fee)(payer)(son_wallet_id)(sidechain)(address)(redeem_script) )
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ namespace graphene { namespace chain {
|
|||
time_point_sec expires;
|
||||
|
||||
flat_map<peerplays_sidechain::sidechain_type, string> addresses;
|
||||
flat_map<peerplays_sidechain::sidechain_type, peerplays_sidechain::bytes> redeem_scripts;
|
||||
vector<son_info> sons;
|
||||
};
|
||||
|
||||
|
|
@ -44,4 +45,4 @@ namespace graphene { namespace chain {
|
|||
} } // graphene::chain
|
||||
|
||||
FC_REFLECT_DERIVED( graphene::chain::son_wallet_object, (graphene::db::object),
|
||||
(valid_from) (expires) (addresses) (sons) )
|
||||
(valid_from) (expires) (addresses) (redeem_scripts) (sons) )
|
||||
|
|
|
|||
|
|
@ -72,6 +72,7 @@ object_id_type update_son_wallet_evaluator::do_apply(const son_wallet_update_ope
|
|||
if (itr->addresses.find(op.sidechain) == itr->addresses.end()) {
|
||||
db().modify(*itr, [&op](son_wallet_object &swo) {
|
||||
swo.addresses[op.sidechain] = op.address;
|
||||
swo.redeem_scripts[op.sidechain] = op.redeem_script;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -351,7 +351,7 @@ void add_number_to_script(bytes &script, unsigned char data) {
|
|||
add_data_to_script(script, {data});
|
||||
}
|
||||
|
||||
bytes generate_redeem_script(std::vector<std::pair<fc::ecc::public_key, int>> key_data) {
|
||||
bytes generate_redeem_script(std::vector<std::pair<fc::ecc::public_key, uint64_t>> key_data) {
|
||||
int total_weight = 0;
|
||||
bytes result;
|
||||
add_number_to_script(result, 0);
|
||||
|
|
@ -366,7 +366,7 @@ bytes generate_redeem_script(std::vector<std::pair<fc::ecc::public_key, int>> ke
|
|||
result.push_back(OP_ADD);
|
||||
result.push_back(OP_ENDIF);
|
||||
}
|
||||
int threshold_weight = 2 * total_weight / 3;
|
||||
uint64_t threshold_weight = 2 * total_weight / 3;
|
||||
add_number_to_script(result, static_cast<unsigned char>(threshold_weight));
|
||||
result.push_back(OP_GREATERTHAN);
|
||||
return result;
|
||||
|
|
@ -768,11 +768,19 @@ bytes add_signatures_to_unsigned_tx(const bytes &unsigned_tx, const std::vector<
|
|||
|
||||
std::string get_weighted_multisig_address(const std::vector<std::pair<std::string, uint64_t> > &public_keys)
|
||||
{
|
||||
std::vector<std::pair<fc::ecc::public_key, int>> key_data;
|
||||
std::vector<std::pair<fc::ecc::public_key, uint64_t>> key_data;
|
||||
for(auto p: public_keys)
|
||||
key_data.push_back(std::make_pair(fc::ecc::public_key::from_base58(p.first), p.second));
|
||||
bytes redeem_script = generate_redeem_script(key_data);
|
||||
return p2wsh_address_from_redeem_script(redeem_script);
|
||||
}
|
||||
|
||||
bytes get_weighted_multisig_redeem_script(std::vector<std::pair<std::string, uint64_t> > public_keys)
|
||||
{
|
||||
std::vector<std::pair<fc::ecc::public_key, uint64_t>> key_data;
|
||||
for(auto p: public_keys)
|
||||
key_data.push_back(std::make_pair(fc::ecc::public_key::from_base58(p.first), p.second));
|
||||
return generate_redeem_script(key_data);
|
||||
}
|
||||
|
||||
}} // namespace graphene::peerplays_sidechain
|
||||
|
|
|
|||
|
|
@ -10,12 +10,13 @@ enum bitcoin_network {
|
|||
regtest
|
||||
};
|
||||
|
||||
bytes generate_redeem_script(std::vector<std::pair<fc::ecc::public_key, int>> key_data);
|
||||
bytes generate_redeem_script(std::vector<std::pair<fc::ecc::public_key, uint64_t>> key_data);
|
||||
std::string p2wsh_address_from_redeem_script(const bytes &script, bitcoin_network network = mainnet);
|
||||
bytes lock_script_for_redeem_script(const bytes &script);
|
||||
bytes lock_script_from_pw_address(const std::string &address);
|
||||
|
||||
std::string get_weighted_multisig_address(const std::vector<std::pair<std::string, uint64_t>>& public_keys);
|
||||
bytes get_weighted_multisig_redeem_script(std::vector<std::pair<std::string, uint64_t> > public_keys);
|
||||
|
||||
std::vector<bytes> signatures_for_raw_transaction(const bytes &unsigned_tx,
|
||||
std::vector<uint64_t> in_amounts,
|
||||
|
|
|
|||
|
|
@ -637,6 +637,7 @@ void sidechain_net_handler_bitcoin::recreate_primary_wallet() {
|
|||
op.son_wallet_id = (*active_sw).id;
|
||||
op.sidechain = sidechain_type::bitcoin;
|
||||
op.address = address;
|
||||
op.redeem_script = redeem_script;
|
||||
|
||||
proposal_create_operation proposal_op;
|
||||
proposal_op.fee_paying_account = plugin.get_son_object(plugin.get_current_son_id()).son_account;
|
||||
|
|
@ -658,7 +659,7 @@ void sidechain_net_handler_bitcoin::recreate_primary_wallet() {
|
|||
if (prev_sw != swi.rend()) {
|
||||
std::string prev_pw_address = prev_sw->addresses.at(sidechain_type::bitcoin);
|
||||
std::string active_pw_address = address;
|
||||
bytes prev_redeem_script;
|
||||
bytes prev_redeem_script = prev_sw->redeem_scripts.at(sidechain_type::bitcoin);
|
||||
transfer_all_btc(prev_pw_address, prev_redeem_script, active_pw_address);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ BOOST_AUTO_TEST_CASE(pw_transfer)
|
|||
for(auto& key: priv_old)
|
||||
pub_old.push_back(key.get_public_key());
|
||||
// old key weights
|
||||
std::vector<std::pair<fc::ecc::public_key, int> > weights_old;
|
||||
std::vector<std::pair<fc::ecc::public_key, uint64_t> > weights_old;
|
||||
for(unsigned i = 0; i < 15; ++i)
|
||||
weights_old.push_back(std::make_pair(pub_old[i], i + 1));
|
||||
// redeem script for old PW
|
||||
|
|
@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE(pw_transfer)
|
|||
for(auto& key: priv_new)
|
||||
pub_new.push_back(key.get_public_key());
|
||||
// new key weights
|
||||
std::vector<std::pair<fc::ecc::public_key, int> > weights_new;
|
||||
std::vector<std::pair<fc::ecc::public_key, uint64_t> > weights_new;
|
||||
for(unsigned i = 0; i < 15; ++i)
|
||||
weights_new.push_back(std::make_pair(pub_new[i], 16 - i));
|
||||
// redeem script for new PW
|
||||
|
|
@ -145,7 +145,7 @@ BOOST_AUTO_TEST_CASE(pw_separate_sign)
|
|||
for(auto& key: priv_old)
|
||||
pub_old.push_back(key.get_public_key());
|
||||
// old key weights
|
||||
std::vector<std::pair<fc::ecc::public_key, int> > weights_old;
|
||||
std::vector<std::pair<fc::ecc::public_key, uint64_t> > weights_old;
|
||||
for(unsigned i = 0; i < 15; ++i)
|
||||
weights_old.push_back(std::make_pair(pub_old[i], i + 1));
|
||||
// redeem script for old PW
|
||||
|
|
@ -170,7 +170,7 @@ BOOST_AUTO_TEST_CASE(pw_separate_sign)
|
|||
for(auto& key: priv_new)
|
||||
pub_new.push_back(key.get_public_key());
|
||||
// new key weights
|
||||
std::vector<std::pair<fc::ecc::public_key, int> > weights_new;
|
||||
std::vector<std::pair<fc::ecc::public_key, uint64_t> > weights_new;
|
||||
for(unsigned i = 0; i < 15; ++i)
|
||||
weights_new.push_back(std::make_pair(pub_new[i], 16 - i));
|
||||
// redeem script for new PW
|
||||
|
|
@ -243,7 +243,7 @@ BOOST_AUTO_TEST_CASE(pw_separate_sign2)
|
|||
for(auto& key: priv_old)
|
||||
pub_old.push_back(key.get_public_key());
|
||||
// old key weights
|
||||
std::vector<std::pair<fc::ecc::public_key, int> > weights_old;
|
||||
std::vector<std::pair<fc::ecc::public_key, uint64_t> > weights_old;
|
||||
for(unsigned i = 0; i < 15; ++i)
|
||||
weights_old.push_back(std::make_pair(pub_old[i], i + 1));
|
||||
// redeem script for old PW
|
||||
|
|
@ -268,7 +268,7 @@ BOOST_AUTO_TEST_CASE(pw_separate_sign2)
|
|||
for(auto& key: priv_new)
|
||||
pub_new.push_back(key.get_public_key());
|
||||
// new key weights
|
||||
std::vector<std::pair<fc::ecc::public_key, int> > weights_new;
|
||||
std::vector<std::pair<fc::ecc::public_key, uint64_t> > weights_new;
|
||||
for(unsigned i = 0; i < 15; ++i)
|
||||
weights_new.push_back(std::make_pair(pub_new[i], 16 - i));
|
||||
// redeem script for new PW
|
||||
|
|
@ -345,7 +345,7 @@ BOOST_AUTO_TEST_CASE(pw_partially_sign)
|
|||
for(auto& key: priv_old)
|
||||
pub_old.push_back(key.get_public_key());
|
||||
// old key weights
|
||||
std::vector<std::pair<fc::ecc::public_key, int> > weights_old;
|
||||
std::vector<std::pair<fc::ecc::public_key, uint64_t> > weights_old;
|
||||
for(unsigned i = 0; i < 15; ++i)
|
||||
weights_old.push_back(std::make_pair(pub_old[i], i + 1));
|
||||
// redeem script for old PW
|
||||
|
|
@ -370,7 +370,7 @@ BOOST_AUTO_TEST_CASE(pw_partially_sign)
|
|||
for(auto& key: priv_new)
|
||||
pub_new.push_back(key.get_public_key());
|
||||
// new key weights
|
||||
std::vector<std::pair<fc::ecc::public_key, int> > weights_new;
|
||||
std::vector<std::pair<fc::ecc::public_key, uint64_t> > weights_new;
|
||||
for(unsigned i = 0; i < 15; ++i)
|
||||
weights_new.push_back(std::make_pair(pub_new[i], 16 - i));
|
||||
// redeem script for new PW
|
||||
|
|
|
|||
Loading…
Reference in a new issue