Collecting Hive SONs signatures
This commit is contained in:
parent
7fc964103e
commit
44f81d4d08
7 changed files with 81 additions and 36 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
#include <graphene/peerplays_sidechain/hive/transaction.hpp>
|
#include <graphene/peerplays_sidechain/hive/transaction.hpp>
|
||||||
|
|
||||||
|
#include <boost/algorithm/hex.hpp>
|
||||||
|
|
||||||
#include <fc/bitutil.hpp>
|
#include <fc/bitutil.hpp>
|
||||||
#include <fc/io/raw.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) {
|
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);
|
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();
|
return signatures.back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -19,8 +19,6 @@ public_key_type::public_key_type(const fc::ecc::public_key &pubkey) :
|
||||||
key_data(pubkey){};
|
key_data(pubkey){};
|
||||||
|
|
||||||
public_key_type::public_key_type(const std::string &base58str) {
|
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);
|
std::string prefix(ADDRESS_PREFIX);
|
||||||
|
|
||||||
const size_t prefix_len = prefix.size();
|
const size_t prefix_len = prefix.size();
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ struct authority {
|
||||||
};
|
};
|
||||||
|
|
||||||
uint32_t weight_threshold = 0;
|
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;
|
fc::flat_map<public_key_type, uint16_t> key_auths;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ struct transaction {
|
||||||
fc::time_point_sec expiration;
|
fc::time_point_sec expiration;
|
||||||
std::vector<hive_operation> operations;
|
std::vector<hive_operation> operations;
|
||||||
extensions_type extensions;
|
extensions_type extensions;
|
||||||
std::vector<fc::ecc::compact_signature> signatures;
|
|
||||||
|
|
||||||
digest_type sig_digest(const chain_id_type &chain_id) const;
|
digest_type sig_digest(const chain_id_type &chain_id) const;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ typedef fc::flat_set<future_extensions> extensions_type;
|
||||||
|
|
||||||
typedef fc::ecc::private_key private_key_type;
|
typedef fc::ecc::private_key private_key_type;
|
||||||
typedef fc::sha256 chain_id_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 block_id_type;
|
||||||
//typedef fc::ripemd160 checksum_type;
|
//typedef fc::ripemd160 checksum_type;
|
||||||
//typedef fc::ripemd160 transaction_id_type;
|
//typedef fc::ripemd160 transaction_id_type;
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#include <fc/signals.hpp>
|
#include <fc/signals.hpp>
|
||||||
|
|
||||||
#include <graphene/peerplays_sidechain/common/rpc_client.hpp>
|
#include <graphene/peerplays_sidechain/common/rpc_client.hpp>
|
||||||
|
#include <graphene/peerplays_sidechain/hive/types.hpp>
|
||||||
|
|
||||||
namespace graphene { namespace peerplays_sidechain {
|
namespace graphene { namespace peerplays_sidechain {
|
||||||
|
|
||||||
|
|
@ -66,6 +67,8 @@ private:
|
||||||
std::string wallet_rpc_password;
|
std::string wallet_rpc_password;
|
||||||
hive_wallet_rpc_client *wallet_rpc_client;
|
hive_wallet_rpc_client *wallet_rpc_client;
|
||||||
|
|
||||||
|
hive::chain_id_type chain_id;
|
||||||
|
|
||||||
uint64_t last_block_received;
|
uint64_t last_block_received;
|
||||||
fc::future<void> _listener_task;
|
fc::future<void> _listener_task;
|
||||||
fc::signal<void(const std::string &)> event_received;
|
fc::signal<void(const std::string &)> event_received;
|
||||||
|
|
|
||||||
|
|
@ -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() {
|
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() {
|
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);
|
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;
|
last_block_received = 0;
|
||||||
schedule_hive_listener();
|
schedule_hive_listener();
|
||||||
event_received.connect([this](const std::string &event_data) {
|
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);
|
htrx.operations.push_back(auo);
|
||||||
ilog("TRX: ${htrx}", ("htrx", htrx));
|
ilog("TRX: ${htrx}", ("htrx", htrx));
|
||||||
|
|
||||||
std::string chain_id_str = node_rpc_client->get_chain_id();
|
std::stringstream ss;
|
||||||
const hive::chain_id_type chain_id(chain_id_str);
|
fc::raw::pack(ss, htrx, 1000);
|
||||||
|
std::string tx_str = boost::algorithm::hex(ss.str());
|
||||||
// create sidechain transaction for wallet update, to collect SON signatures
|
if (tx_str.empty()) {
|
||||||
|
return;
|
||||||
return; // temporary
|
}
|
||||||
|
|
||||||
proposal_create_operation proposal_op;
|
proposal_create_operation proposal_op;
|
||||||
proposal_op.fee_paying_account = plugin.get_current_son_object().son_account;
|
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);
|
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);
|
signed_transaction trx = database.create_signed_transaction(plugin.get_private_key(plugin.get_current_son_id()), proposal_op);
|
||||||
try {
|
try {
|
||||||
trx.validate();
|
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::string sidechain_net_handler_hive::process_sidechain_transaction(const sidechain_transaction_object &sto) {
|
||||||
|
|
||||||
// std::stringstream ss_trx(boost::algorithm::unhex(sto.transaction));
|
std::stringstream ss_trx(boost::algorithm::unhex(sto.transaction));
|
||||||
// signed_transaction trx;
|
hive::signed_transaction htrx;
|
||||||
// fc::raw::unpack(ss_trx, trx, 1000);
|
fc::raw::unpack(ss_trx, htrx, 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)));
|
// temp
|
||||||
// signature_type st = trx.sign(*privkey, database.get_chain_id());
|
// 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;
|
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());
|
std::string st_str = boost::algorithm::hex(ss_st.str());
|
||||||
|
|
||||||
|
st_str = "";
|
||||||
return st_str;
|
return st_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string sidechain_net_handler_hive::send_sidechain_transaction(const sidechain_transaction_object &sto) {
|
std::string sidechain_net_handler_hive::send_sidechain_transaction(const sidechain_transaction_object &sto) {
|
||||||
|
|
||||||
// std::stringstream ss_trx(boost::algorithm::unhex(sto.transaction));
|
std::stringstream ss_trx(boost::algorithm::unhex(sto.transaction));
|
||||||
// signed_transaction trx;
|
hive::signed_transaction htrx;
|
||||||
// fc::raw::unpack(ss_trx, trx, 1000);
|
fc::raw::unpack(ss_trx, htrx, 1000);
|
||||||
//
|
|
||||||
// for (auto signature : sto.signatures) {
|
for (auto signature : sto.signatures) {
|
||||||
// if (!signature.second.empty()) {
|
if (!signature.second.empty()) {
|
||||||
// std::stringstream ss_st(boost::algorithm::unhex(signature.second));
|
std::stringstream ss_st(boost::algorithm::unhex(signature.second));
|
||||||
// signature_type st;
|
signature_type st;
|
||||||
// fc::raw::unpack(ss_st, st, 1000);
|
fc::raw::unpack(ss_st, st, 1000);
|
||||||
//
|
htrx.signatures.push_back(st);
|
||||||
// trx.signatures.push_back(st);
|
}
|
||||||
// trx.signees.clear();
|
}
|
||||||
// }
|
ilog("HTRX: ${htrx}", ("htrx", htrx));
|
||||||
// }
|
|
||||||
//
|
|
||||||
// try {
|
// try {
|
||||||
// trx.validate();
|
// trx.validate();
|
||||||
// database.push_transaction(trx, database::validation_steps::skip_block_size_check);
|
// database.push_transaction(trx, database::validation_steps::skip_block_size_check);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue