Collecting Hive SONs signatures

This commit is contained in:
serkixenos 2021-03-24 11:59:38 +01:00
parent 7fc964103e
commit 44f81d4d08
7 changed files with 81 additions and 36 deletions

View file

@ -1,5 +1,7 @@
#include <graphene/peerplays_sidechain/hive/transaction.hpp>
#include <boost/algorithm/hex.hpp>
#include <fc/bitutil.hpp>
#include <fc/io/raw.hpp>
@ -28,7 +30,23 @@ void signed_transaction::clear() {
const signature_type &signed_transaction::sign(const hive::private_key_type &key, const hive::chain_id_type &chain_id) {
digest_type h = sig_digest(chain_id);
signatures.push_back(key.sign_compact(h, true));
auto sig = key.sign_compact(h, true);
ilog("Signing1: chain_id = ${chain_id}", ("chain_id", chain_id));
ilog("Signing1: key = ${key}", ("key", key));
ilog("Signing1: this = ${this}", ("this", *this));
ilog("Signing1: h = ${h}", ("h", h));
ilog("Signing1: signature = ${sig}", ("sig", sig));
std::stringstream ss_st;
fc::raw::pack(ss_st, chain_id);
ilog("Signing: ${ss_st}", ("ss_st", boost::algorithm::hex(ss_st.str())));
ss_st.str("");
fc::raw::pack(ss_st, *this);
ilog("Signing: ${ss_st}", ("ss_st", boost::algorithm::hex(ss_st.str())));
signatures.push_back(sig);
return signatures.back();
}

View file

@ -19,8 +19,6 @@ public_key_type::public_key_type(const fc::ecc::public_key &pubkey) :
key_data(pubkey){};
public_key_type::public_key_type(const std::string &base58str) {
// TODO: Refactor syntactic checks into static is_valid()
// to make public_key_type API more similar to address API
std::string prefix(ADDRESS_PREFIX);
const size_t prefix_len = prefix.size();

View file

@ -21,7 +21,7 @@ struct authority {
};
uint32_t weight_threshold = 0;
fc::flat_map<std::string, uint16_t> account_auths;
fc::flat_map<account_name_type, uint16_t> account_auths;
fc::flat_map<public_key_type, uint16_t> key_auths;
};

View file

@ -16,7 +16,6 @@ struct transaction {
fc::time_point_sec expiration;
std::vector<hive_operation> operations;
extensions_type extensions;
std::vector<fc::ecc::compact_signature> signatures;
digest_type sig_digest(const chain_id_type &chain_id) const;

View file

@ -12,7 +12,7 @@ typedef fc::flat_set<future_extensions> extensions_type;
typedef fc::ecc::private_key private_key_type;
typedef fc::sha256 chain_id_type;
//typedef fixed_string<16> account_name_type;
typedef std::string account_name_type;
typedef fc::ripemd160 block_id_type;
//typedef fc::ripemd160 checksum_type;
//typedef fc::ripemd160 transaction_id_type;

View file

@ -8,6 +8,7 @@
#include <fc/signals.hpp>
#include <graphene/peerplays_sidechain/common/rpc_client.hpp>
#include <graphene/peerplays_sidechain/hive/types.hpp>
namespace graphene { namespace peerplays_sidechain {
@ -66,6 +67,8 @@ private:
std::string wallet_rpc_password;
hive_wallet_rpc_client *wallet_rpc_client;
hive::chain_id_type chain_id;
uint64_t last_block_received;
fc::future<void> _listener_task;
fc::signal<void(const std::string &)> event_received;

View file

@ -40,7 +40,7 @@ std::string hive_node_rpc_client::database_api_get_dynamic_global_properties() {
}
std::string hive_node_rpc_client::database_api_get_version() {
return send_post_request("database_api.get_version", "", true);
return send_post_request("database_api.get_version", "", false);
}
std::string hive_node_rpc_client::get_chain_id() {
@ -160,6 +160,9 @@ sidechain_net_handler_hive::sidechain_net_handler_hive(peerplays_sidechain_plugi
wallet_rpc_client = new hive_wallet_rpc_client(wallet_ip, wallet_rpc_port, wallet_rpc_user, wallet_rpc_password);
std::string chain_id_str = node_rpc_client->get_chain_id();
chain_id = chain_id_type(chain_id_str);
last_block_received = 0;
schedule_hive_listener();
event_received.connect([this](const std::string &event_data) {
@ -296,12 +299,12 @@ void sidechain_net_handler_hive::process_primary_wallet() {
htrx.operations.push_back(auo);
ilog("TRX: ${htrx}", ("htrx", htrx));
std::string chain_id_str = node_rpc_client->get_chain_id();
const hive::chain_id_type chain_id(chain_id_str);
// create sidechain transaction for wallet update, to collect SON signatures
return; // temporary
std::stringstream ss;
fc::raw::pack(ss, htrx, 1000);
std::string tx_str = boost::algorithm::hex(ss.str());
if (tx_str.empty()) {
return;
}
proposal_create_operation proposal_op;
proposal_op.fee_paying_account = plugin.get_current_son_object().son_account;
@ -316,6 +319,15 @@ void sidechain_net_handler_hive::process_primary_wallet() {
proposal_op.proposed_ops.emplace_back(swu_op);
sidechain_transaction_create_operation stc_op;
stc_op.payer = gpo.parameters.son_account();
stc_op.object_id = active_sw->id;
stc_op.sidechain = sidechain;
stc_op.transaction = tx_str;
stc_op.signers = gpo.active_sons;
proposal_op.proposed_ops.emplace_back(stc_op);
signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), proposal_op);
try {
trx.validate();
@ -426,37 +438,52 @@ bool sidechain_net_handler_hive::process_withdrawal(const son_wallet_withdraw_ob
std::string sidechain_net_handler_hive::process_sidechain_transaction(const sidechain_transaction_object &sto) {
// std::stringstream ss_trx(boost::algorithm::unhex(sto.transaction));
// signed_transaction trx;
// fc::raw::unpack(ss_trx, trx, 1000);
//
// fc::optional<fc::ecc::private_key> privkey = graphene::utilities::wif_to_key(get_private_key(plugin.get_current_son_object().sidechain_public_keys.at(sidechain)));
// signature_type st = trx.sign(*privkey, database.get_chain_id());
//
std::stringstream ss_trx(boost::algorithm::unhex(sto.transaction));
hive::signed_transaction htrx;
fc::raw::unpack(ss_trx, htrx, 1000);
// temp
// sign_transaction {"ref_block_num":0,"ref_block_prefix":0,"expiration":"1970-01-01T00:00:0","operations":[["account_update",{"account":"son-account","active":{"weight_threshold":1,"account_auths":[["sonaccount01",1],["sonaccount02",1],["sonaccount03",1],["sonaccount04",1],["sonaccount05",1],["sonaccount06",1],["sonaccount07",1],["sonaccount08",1],["sonaccount09",1],["sonaccount10",1],["sonaccount11",1],["sonaccount12",1],["sonaccount13",1],["sonaccount14",1],["sonaccount15",1]],"key_auths":[]},"memo_key":"TST78bZV5JsuNKUVM7WDVKBnuiuXBTR8gsPEaev2fj96iXqq5R13u","json_metadata":""}]],"extensions":[]} false
htrx.set_reference_block(block_id_type("0000d68fd4d7abb7e8975398b9e93f93db990ac8"));
htrx.set_expiration(fc::time_point::from_iso_string("2021-03-23T19:21:24"));
// temp
ilog("TRX: ${htrx}", ("htrx", htrx));
ilog("EXP: {\"ref_block_num\":54927,\"ref_block_prefix\":3081492436,\"expiration\":\"2021-03-23T19:21:24\",\"operations\":[{\"type\":\"account_update_operation\",\"value\":{\"account\":\"son-account\",\"active\":{\"weight_threshold\":1,\"account_auths\":[[\"sonaccount01\",1],[\"sonaccount02\",1],[\"sonaccount03\",1],[\"sonaccount04\",1],[\"sonaccount05\",1],[\"sonaccount06\",1],[\"sonaccount07\",1],[\"sonaccount08\",1],[\"sonaccount09\",1],[\"sonaccount10\",1],[\"sonaccount11\",1],[\"sonaccount12\",1],[\"sonaccount13\",1],[\"sonaccount14\",1],[\"sonaccount15\",1]],\"key_auths\":[]},\"memo_key\":\"TST1111111111111111111111111111111114T1Anm\",\"json_metadata\":\"\"}}],\"extensions\":[],\"signatures\":[\"1f323561e46aa7703850d6afc5fdf00b338424eed695c9513568135bb5dbc051f3242a463f29d17257d982ae616214239b5405073ae7771469a7ea9e36c1577c45\"]}");
std::string chain_id_str = node_rpc_client->get_chain_id();
const hive::chain_id_type chain_id(chain_id_str);
fc::optional<fc::ecc::private_key> privkey = graphene::utilities::wif_to_key(get_private_key(plugin.get_current_son_object().sidechain_public_keys.at(sidechain)));
signature_type st = htrx.sign(*privkey, chain_id);
ilog("TRX: ${htrx}", ("htrx", htrx));
ilog("EXP: {\"ref_block_num\":54927,\"ref_block_prefix\":3081492436,\"expiration\":\"2021-03-23T19:21:24\",\"operations\":[{\"type\":\"account_update_operation\",\"value\":{\"account\":\"son-account\",\"active\":{\"weight_threshold\":1,\"account_auths\":[[\"sonaccount01\",1],[\"sonaccount02\",1],[\"sonaccount03\",1],[\"sonaccount04\",1],[\"sonaccount05\",1],[\"sonaccount06\",1],[\"sonaccount07\",1],[\"sonaccount08\",1],[\"sonaccount09\",1],[\"sonaccount10\",1],[\"sonaccount11\",1],[\"sonaccount12\",1],[\"sonaccount13\",1],[\"sonaccount14\",1],[\"sonaccount15\",1]],\"key_auths\":[]},\"memo_key\":\"TST1111111111111111111111111111111114T1Anm\",\"json_metadata\":\"\"}}],\"extensions\":[],\"signatures\":[\"1f323561e46aa7703850d6afc5fdf00b338424eed695c9513568135bb5dbc051f3242a463f29d17257d982ae616214239b5405073ae7771469a7ea9e36c1577c45\"]}");
std::stringstream ss_st;
// fc::raw::pack(ss_st, st, 1000);
fc::raw::pack(ss_st, st, 1000);
std::string st_str = boost::algorithm::hex(ss_st.str());
st_str = "";
return st_str;
}
std::string sidechain_net_handler_hive::send_sidechain_transaction(const sidechain_transaction_object &sto) {
// std::stringstream ss_trx(boost::algorithm::unhex(sto.transaction));
// signed_transaction trx;
// fc::raw::unpack(ss_trx, trx, 1000);
//
// for (auto signature : sto.signatures) {
// if (!signature.second.empty()) {
// std::stringstream ss_st(boost::algorithm::unhex(signature.second));
// signature_type st;
// fc::raw::unpack(ss_st, st, 1000);
//
// trx.signatures.push_back(st);
// trx.signees.clear();
// }
// }
//
std::stringstream ss_trx(boost::algorithm::unhex(sto.transaction));
hive::signed_transaction htrx;
fc::raw::unpack(ss_trx, htrx, 1000);
for (auto signature : sto.signatures) {
if (!signature.second.empty()) {
std::stringstream ss_st(boost::algorithm::unhex(signature.second));
signature_type st;
fc::raw::unpack(ss_st, st, 1000);
htrx.signatures.push_back(st);
}
}
ilog("HTRX: ${htrx}", ("htrx", htrx));
// try {
// trx.validate();
// database.push_transaction(trx, database::validation_steps::skip_block_size_check);