process tx signing

This commit is contained in:
gladcow 2020-03-04 15:21:13 +03:00
parent d710b320c0
commit 682f64c8fc
9 changed files with 76 additions and 51 deletions

View file

@ -27,6 +27,7 @@ public:
virtual void recreate_primary_wallet() = 0; virtual void recreate_primary_wallet() = 0;
virtual void process_deposit(const son_wallet_deposit_object &swdo) = 0; virtual void process_deposit(const son_wallet_deposit_object &swdo) = 0;
virtual void process_withdrawal(const son_wallet_withdraw_object &swwo) = 0; virtual void process_withdrawal(const son_wallet_withdraw_object &swwo) = 0;
virtual void process_signing() = 0;
protected: protected:
peerplays_sidechain_plugin &plugin; peerplays_sidechain_plugin &plugin;

View file

@ -83,9 +83,10 @@ public:
sidechain_net_handler_bitcoin(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options); sidechain_net_handler_bitcoin(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options);
virtual ~sidechain_net_handler_bitcoin(); virtual ~sidechain_net_handler_bitcoin();
void recreate_primary_wallet(); void recreate_primary_wallet() override;
void process_deposit(const son_wallet_deposit_object &swdo); void process_deposit(const son_wallet_deposit_object &swdo) override;
void process_withdrawal(const son_wallet_withdraw_object &swwo); void process_withdrawal(const son_wallet_withdraw_object &swwo) override;
void process_signing() override;
private: private:
std::string ip; std::string ip;
@ -99,10 +100,10 @@ private:
std::unique_ptr<bitcoin_rpc_client> bitcoin_client; std::unique_ptr<bitcoin_rpc_client> bitcoin_client;
std::unique_ptr<zmq_listener> listener; std::unique_ptr<zmq_listener> listener;
std::string create_multisignature_wallet(const std::vector<std::string> public_keys); std::string create_multisignature_wallet(const std::vector<std::string> public_keys) override;
std::string transfer(const std::string &from, const std::string &to, const uint64_t amount); std::string transfer(const std::string &from, const std::string &to, const uint64_t amount) override;
std::string sign_transaction(const std::string &transaction); std::string sign_transaction(const std::string &transaction) override;
std::string send_transaction(const std::string &transaction); std::string send_transaction(const std::string &transaction) override;
std::string sign_and_send_transaction_with_wallet(const std::string &tx_json); std::string sign_and_send_transaction_with_wallet(const std::string &tx_json);
std::string create_weighted_multisignature_wallet( const std::vector<std::pair<std::string, uint64_t>>& public_keys ); std::string create_weighted_multisignature_wallet( const std::vector<std::pair<std::string, uint64_t>>& public_keys );
void transfer_all_btc(const std::string& from_address, const vector<son_info>& from_sons, const std::string& to_address); void transfer_all_btc(const std::string& from_address, const vector<son_info>& from_sons, const std::string& to_address);

View file

@ -13,15 +13,16 @@ public:
sidechain_net_handler_peerplays(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options); sidechain_net_handler_peerplays(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options);
virtual ~sidechain_net_handler_peerplays(); virtual ~sidechain_net_handler_peerplays();
void recreate_primary_wallet(); void recreate_primary_wallet() override;
void process_deposit(const son_wallet_deposit_object &swdo); void process_deposit(const son_wallet_deposit_object &swdo) override;
void process_withdrawal(const son_wallet_withdraw_object &swwo); void process_withdrawal(const son_wallet_withdraw_object &swwo) override;
void process_signing() override;
private: private:
std::string create_multisignature_wallet(const std::vector<std::string> public_keys); std::string create_multisignature_wallet(const std::vector<std::string> public_keys) override;
std::string transfer(const std::string &from, const std::string &to, const uint64_t amount); std::string transfer(const std::string &from, const std::string &to, const uint64_t amount) override;
std::string sign_transaction(const std::string &transaction); std::string sign_transaction(const std::string &transaction) override;
std::string send_transaction(const std::string &transaction); std::string send_transaction(const std::string &transaction) override;
void on_applied_block(const signed_block &b); void on_applied_block(const signed_block &b);
}; };

View file

@ -19,6 +19,7 @@ public:
void recreate_primary_wallet(); void recreate_primary_wallet();
void process_deposits(); void process_deposits();
void process_withdrawals(); void process_withdrawals();
void process_signing();
private: private:
peerplays_sidechain_plugin &plugin; peerplays_sidechain_plugin &plugin;

View file

@ -51,6 +51,7 @@ public:
void recreate_primary_wallet(); void recreate_primary_wallet();
void process_deposits(); void process_deposits();
void process_withdrawals(); void process_withdrawals();
void process_signing();
private: private:
peerplays_sidechain_plugin &plugin; peerplays_sidechain_plugin &plugin;
@ -332,6 +333,7 @@ void peerplays_sidechain_plugin_impl::son_processing() {
// Tasks that are executed by all active SONs, no matter if scheduled // Tasks that are executed by all active SONs, no matter if scheduled
// E.g. sending approvals and signing // E.g. sending approvals and signing
approve_proposals(); approve_proposals();
process_signing();
// Tasks that are executed by scheduled and active SON // Tasks that are executed by scheduled and active SON
if (sons.find(next_son_id) != sons.end()) { if (sons.find(next_son_id) != sons.end()) {
@ -347,9 +349,14 @@ void peerplays_sidechain_plugin_impl::son_processing() {
process_deposits(); process_deposits();
process_withdrawals(); process_withdrawals();
} }
} }
void peerplays_sidechain_plugin_impl::process_signing() {
net_manager->process_signing();
}
void peerplays_sidechain_plugin_impl::approve_proposals() { void peerplays_sidechain_plugin_impl::approve_proposals() {
auto approve_proposal = [&](const chain::son_id_type &son_id, const chain::proposal_id_type &proposal_id) { auto approve_proposal = [&](const chain::son_id_type &son_id, const chain::proposal_id_type &proposal_id) {
@ -430,6 +437,11 @@ void peerplays_sidechain_plugin_impl::approve_proposals() {
approve_proposal(son_id, proposal.id); approve_proposal(son_id, proposal.id);
continue; continue;
} }
if (proposal.proposed_transaction.operations.size() == 1 && proposal.proposed_transaction.operations[0].which() == chain::operation::tag<chain::bitcoin_transaction_send_operation>::value) {
approve_proposal(son_id, proposal.id);
continue;
}
} }
} }
} }
@ -519,42 +531,6 @@ void peerplays_sidechain_plugin_impl::create_son_deregister_proposals() {
}); });
fut.wait(fc::seconds(10)); fut.wait(fc::seconds(10));
} }
if(proposal->proposed_transaction.operations.size() == 1
&& proposal->proposed_transaction.operations[0].which() == chain::operation::tag<chain::bitcoin_transaction_send_operation>::value) {
approve_proposal( son_id, proposal->id );
continue;
}
}
}
if( object_id.is<chain::bitcoin_transaction_object>() ) {
const object* obj = plugin.database().find_object(object_id);
const chain::bitcoin_transaction_object* tx_object = dynamic_cast<const chain::bitcoin_transaction_object*>(obj);
for (son_id_type son_id : _sons) {
auto it = tx_object->signatures.find(son_id);
if (it == tx_object->signatures.end())
continue;
if (it->second.empty())
{
bitcoin_transaction_sign_operation op;
son_object s_obj= get_son_object(son_id);
op.payer = s_obj.son_account;
op.tx_id = tx_object->id;
fc::ecc::private_key k = get_private_key(son_id);
op.signatures = signatures_for_raw_transaction(tx_object->unsigned_tx, tx_object->in_amounts, tx_object->redeem_script, k);
signed_transaction trx = plugin.database().create_signed_transaction(k, op);
try {
plugin.database().push_transaction(trx, database::validation_steps::skip_block_size_check);
if(plugin.app().p2p_node())
plugin.app().p2p_node()->broadcast(net::trx_message(trx));
} catch(fc::exception e){
ilog("sidechain_net_handler: sending proposal for son wallet update operation failed with exception ${e}",("e", e.what()));
return;
}
}
} }
} }
} }

View file

@ -1,8 +1,10 @@
#include <graphene/peerplays_sidechain/sidechain_net_handler.hpp> #include <graphene/peerplays_sidechain/sidechain_net_handler.hpp>
#include <graphene/chain/sidechain_address_object.hpp> #include <graphene/chain/sidechain_address_object.hpp>
#include <graphene/chain/sidechain_transaction_object.hpp>
#include <graphene/chain/son_wallet_deposit_object.hpp> #include <graphene/chain/son_wallet_deposit_object.hpp>
#include <graphene/chain/son_wallet_withdraw_object.hpp> #include <graphene/chain/son_wallet_withdraw_object.hpp>
#include <graphene/peerplays_sidechain/bitcoin_utils.hpp>
#include <fc/log/logger.hpp> #include <fc/log/logger.hpp>

View file

@ -16,6 +16,7 @@
#include <graphene/chain/account_object.hpp> #include <graphene/chain/account_object.hpp>
#include <graphene/chain/protocol/son_wallet.hpp> #include <graphene/chain/protocol/son_wallet.hpp>
#include <graphene/chain/sidechain_address_object.hpp> #include <graphene/chain/sidechain_address_object.hpp>
#include <graphene/chain/sidechain_transaction_object.hpp>
#include <graphene/chain/son_info.hpp> #include <graphene/chain/son_info.hpp>
#include <graphene/chain/son_wallet_object.hpp> #include <graphene/chain/son_wallet_object.hpp>
@ -628,7 +629,6 @@ void sidechain_net_handler_bitcoin::recreate_primary_wallet() {
} }
string address = create_weighted_multisignature_wallet(son_pubkeys_bitcoin); string address = create_weighted_multisignature_wallet(son_pubkeys_bitcoin);
bytes redeem_script = get_weighted_multisig_redeem_script(son_pubkeys_bitcoin);
ilog(address); ilog(address);
@ -673,6 +673,40 @@ void sidechain_net_handler_bitcoin::process_withdrawal(const son_wallet_withdraw
transfer_withdrawal_from_primary_wallet(swwo); transfer_withdrawal_from_primary_wallet(swwo);
} }
void sidechain_net_handler_bitcoin::process_signing() {
const auto &idx = plugin.database().get_index_type<bitcoin_transaction_index>().indices().get<by_processed>();
const auto &idx_range = idx.equal_range(false);
std::for_each(idx_range.first, idx_range.second,
[&](const bitcoin_transaction_object &tx_object) {
auto sons = plugin.get_sons();
for (son_id_type son_id : sons) {
auto it = tx_object.signatures.find(son_id);
if (it == tx_object.signatures.end())
continue;
if (it->second.empty())
{
bitcoin_transaction_sign_operation op;
son_object s_obj= plugin.get_son_object(son_id);
op.payer = s_obj.son_account;
op.tx_id = tx_object.id;
fc::ecc::private_key k = plugin.get_private_key(son_id);
op.signatures = signatures_for_raw_transaction(tx_object.unsigned_tx, tx_object.in_amounts, tx_object.redeem_script, k);
signed_transaction trx = plugin.database().create_signed_transaction(k, op);
try {
plugin.database().push_transaction(trx, database::validation_steps::skip_block_size_check);
if(plugin.app().p2p_node())
plugin.app().p2p_node()->broadcast(net::trx_message(trx));
} catch(fc::exception e){
ilog("sidechain_net_handler: bitcoin transaction signing failed with exception ${e}",("e", e.what()));
return;
}
}
}
});
}
std::string sidechain_net_handler_bitcoin::create_multisignature_wallet(const std::vector<std::string> public_keys) { std::string sidechain_net_handler_bitcoin::create_multisignature_wallet(const std::vector<std::string> public_keys) {
return bitcoin_client->addmultisigaddress(public_keys); return bitcoin_client->addmultisigaddress(public_keys);
} }

View file

@ -39,6 +39,9 @@ void sidechain_net_handler_peerplays::process_deposit(const son_wallet_deposit_o
void sidechain_net_handler_peerplays::process_withdrawal(const son_wallet_withdraw_object &swwo) { void sidechain_net_handler_peerplays::process_withdrawal(const son_wallet_withdraw_object &swwo) {
} }
void sidechain_net_handler_peerplays::process_signing() {
}
std::string sidechain_net_handler_peerplays::create_multisignature_wallet(const std::vector<std::string> public_keys) { std::string sidechain_net_handler_peerplays::create_multisignature_wallet(const std::vector<std::string> public_keys) {
return ""; return "";
} }

View file

@ -57,4 +57,10 @@ void sidechain_net_manager::process_withdrawals() {
} }
} }
void sidechain_net_manager::process_signing() {
for (size_t i = 0; i < net_handlers.size(); i++) {
net_handlers.at(i)->process_signing();
}
}
}} // namespace graphene::peerplays_sidechain }} // namespace graphene::peerplays_sidechain