From f3e8dabaa4094cc7f1e82f55d0ee973fbaab1b98 Mon Sep 17 00:00:00 2001 From: gladcow Date: Sun, 1 Mar 2020 23:27:28 +0300 Subject: [PATCH] add initial signatures to bitcoin_transaction_send_operation --- .../sidechain_net_handler_bitcoin.hpp | 2 +- .../sidechain_net_handler_bitcoin.cpp | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp index 1d9e359b..70b0c907 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_bitcoin.hpp @@ -105,7 +105,7 @@ private: std::string send_transaction(const std::string &transaction); std::string sign_and_send_transaction_with_wallet(const std::string &tx_json); std::string create_weighted_multisignature_wallet( const std::vector>& public_keys ); - void transfer_all_btc(const std::string &from_address, const std::string &to_address); + void transfer_all_btc(const std::string& from_address, const bytes& from_redeem_script, const std::string& to_address); std::string transfer_deposit_to_primary_wallet(const son_wallet_deposit_object &swdo); std::string transfer_withdrawal_from_primary_wallet(const son_wallet_withdraw_object &swwo); diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp index ef3b7ad6..62c58d16 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_bitcoin.cpp @@ -658,8 +658,8 @@ 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; - - transfer_all_btc(prev_pw_address, active_pw_address); + bytes prev_redeem_script; + transfer_all_btc(prev_pw_address, prev_redeem_script, active_pw_address); } } } @@ -724,7 +724,8 @@ std::string sidechain_net_handler_bitcoin::sign_and_send_transaction_with_wallet return reply_str; } -void sidechain_net_handler_bitcoin::transfer_all_btc(const std::string &from_address, const std::string &to_address) { +void sidechain_net_handler_bitcoin::transfer_all_btc(const std::string& from_address, const bytes& from_redeem_script, const std::string& to_address) +{ uint64_t fee_rate = bitcoin_client->estimatesmartfee(); uint64_t min_fee_rate = 1000; fee_rate = std::max(fee_rate, min_fee_rate); @@ -751,15 +752,25 @@ void sidechain_net_handler_bitcoin::transfer_all_btc(const std::string &from_add tx.hasWitness = true; tx.nVersion = 2; tx.nLockTime = 0; + std::vector amounts; for(const auto& utx: unspent_utxo) { tx.vin.push_back(btc_in(utx.txid_, utx.out_num_)); + amounts.push_back(uint64_t(utx.amount_ * 100000000.0)); } tx.vout.push_back(btc_out(to_address, uint64_t((total_amount - min_amount) * 100000000.0))); bitcoin_transaction_send_operation op; op.payer = GRAPHENE_SON_ACCOUNT; tx.to_bytes(op.unsigned_tx); + // add signatures for owned SONs + std::set sons = plugin.get_sons(); + for(auto sid: sons) + { + fc::ecc::private_key k = plugin.get_private_key(sid); + std::vector signatures = signatures_for_raw_transaction(op.unsigned_tx, amounts, from_redeem_script, k); + op.signatures[sid] = signatures; + } const chain::global_property_object& gpo = database.get_global_properties(); proposal_create_operation proposal_op;