Refactor tracked_assets
This commit is contained in:
parent
ca1e68c13f
commit
11b64ffb8a
6 changed files with 24 additions and 111 deletions
|
|
@ -43,23 +43,7 @@ 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);
|
||||
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);
|
||||
signatures.push_back(key.sign_compact(h, true));
|
||||
return signatures.back();
|
||||
}
|
||||
|
||||
|
|
@ -67,15 +51,7 @@ signature_type signed_transaction::sign(const hive::private_key_type &key, const
|
|||
digest_type::encoder enc;
|
||||
fc::raw::pack(enc, chain_id);
|
||||
fc::raw::pack(enc, *this);
|
||||
auto sig = key.sign_compact(enc.result(), true);
|
||||
|
||||
ilog("Signing2: chain_id = ${chain_id}", ("chain_id", chain_id));
|
||||
ilog("Signing2: key = ${key}", ("key", key));
|
||||
ilog("Signing2: this = ${this}", ("this", *this));
|
||||
ilog("Signing2: h = ${h}", ("h", enc.result()));
|
||||
ilog("Signing2: signature = ${sig}", ("sig", sig));
|
||||
|
||||
return sig;
|
||||
return key.sign_compact(enc.result(), true);
|
||||
}
|
||||
|
||||
}}} // namespace graphene::peerplays_sidechain::hive
|
||||
|
|
|
|||
|
|
@ -55,8 +55,6 @@ protected:
|
|||
|
||||
std::map<std::string, std::string> private_keys;
|
||||
|
||||
std::vector<asset_id_type> tracked_assets;
|
||||
bool is_tracked_asset(asset_id_type asset_id);
|
||||
void on_applied_block(const signed_block &b);
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -35,12 +35,6 @@ public:
|
|||
hive_wallet_rpc_client(std::string _ip, uint32_t _port, std::string _user, std::string _password);
|
||||
|
||||
std::string get_account(std::string account);
|
||||
std::string info();
|
||||
std::string lock();
|
||||
std::string unlock(std::string password);
|
||||
std::string update_account_auth_key(std::string account_name, std::string type, std::string public_key, std::string weight);
|
||||
std::string update_account_auth_account(std::string account_name, std::string type, std::string auth_account, std::string weight);
|
||||
std::string update_account_auth_threshold(std::string account_name, std::string type, std::string threshold);
|
||||
|
||||
std::string get_account_memo_key(std::string account);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -180,19 +180,10 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_
|
|||
((sed.sidechain == sidechain_type::hive) && (sed.sidechain_currency.compare("HIVE") == 0)) ||
|
||||
enable_peerplays_asset_deposits);
|
||||
|
||||
bool is_tracked_asset = false;
|
||||
if (sed.sidechain == sidechain_type::peerplays) {
|
||||
for (const auto &asset_id : tracked_assets) {
|
||||
std::string asset_id_str = asset_id_to_string(asset_id);
|
||||
if (sed.sidechain_currency == asset_id_str) {
|
||||
is_tracked_asset = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool withdraw_condition = (sed.peerplays_to == gpo.parameters.son_account()) && (sed.sidechain == sidechain_type::peerplays) &&
|
||||
is_tracked_asset;
|
||||
((sed.sidechain_currency == asset_id_to_string(gpo.parameters.btc_asset())) ||
|
||||
(sed.sidechain_currency == asset_id_to_string(gpo.parameters.hbd_asset())) ||
|
||||
(sed.sidechain_currency == asset_id_to_string(gpo.parameters.hive_asset())));
|
||||
|
||||
// Deposit request
|
||||
if (deposit_condition) {
|
||||
|
|
@ -600,18 +591,10 @@ void sidechain_net_handler::settle_sidechain_transactions() {
|
|||
});
|
||||
}
|
||||
|
||||
bool sidechain_net_handler::is_tracked_asset(asset_id_type asset_id) {
|
||||
bool is_tracked_asset = false;
|
||||
for (const auto &tracked_asset_id : tracked_assets) {
|
||||
if (asset_id == tracked_asset_id) {
|
||||
is_tracked_asset = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return is_tracked_asset;
|
||||
}
|
||||
|
||||
void sidechain_net_handler::on_applied_block(const signed_block &b) {
|
||||
|
||||
const chain::global_property_object &gpo = plugin.database().get_global_properties();
|
||||
|
||||
for (const auto &trx : b.transactions) {
|
||||
size_t operation_index = -1;
|
||||
for (auto op : trx.operations) {
|
||||
|
|
@ -619,11 +602,16 @@ void sidechain_net_handler::on_applied_block(const signed_block &b) {
|
|||
if (op.which() == operation::tag<transfer_operation>::value) {
|
||||
transfer_operation transfer_op = op.get<transfer_operation>();
|
||||
|
||||
if (transfer_op.to != plugin.database().get_global_properties().parameters.son_account()) {
|
||||
if (transfer_op.to != gpo.parameters.son_account()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!is_tracked_asset(transfer_op.amount.asset_id)) {
|
||||
bool is_tracked_asset =
|
||||
((sidechain == sidechain_type::bitcoin) && (transfer_op.amount.asset_id == gpo.parameters.btc_asset())) ||
|
||||
((sidechain == sidechain_type::hive) && (transfer_op.amount.asset_id == gpo.parameters.hbd_asset())) ||
|
||||
((sidechain == sidechain_type::hive) && (transfer_op.amount.asset_id == gpo.parameters.hive_asset()));
|
||||
|
||||
if (!is_tracked_asset) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -910,7 +910,6 @@ void zmq_listener::handle_zmq() {
|
|||
sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) :
|
||||
sidechain_net_handler(_plugin, options) {
|
||||
sidechain = sidechain_type::bitcoin;
|
||||
tracked_assets.push_back(database.get_global_properties().parameters.btc_asset());
|
||||
|
||||
ip = options.at("bitcoin-node-ip").as<std::string>();
|
||||
zmq_port = options.at("bitcoin-node-zmq-port").as<uint32_t>();
|
||||
|
|
@ -990,7 +989,7 @@ sidechain_net_handler_bitcoin::~sidechain_net_handler_bitcoin() {
|
|||
|
||||
bool sidechain_net_handler_bitcoin::process_proposal(const proposal_object &po) {
|
||||
|
||||
ilog("Proposal to process: ${po}, SON id ${son_id}", ("po", po.id)("son_id", plugin.get_current_son_id()));
|
||||
//ilog("Proposal to process: ${po}, SON id ${son_id}", ("po", po.id)("son_id", plugin.get_current_son_id()));
|
||||
|
||||
bool should_approve = false;
|
||||
|
||||
|
|
@ -1379,7 +1378,7 @@ void sidechain_net_handler_bitcoin::process_sidechain_addresses() {
|
|||
plugin.app().p2p_node()->broadcast(net::trx_message(trx));
|
||||
retval = true;
|
||||
} catch (fc::exception &e) {
|
||||
elog("Sending proposal for deposit sidechain transaction create operation failed with exception ${e}", ("e", e.what()));
|
||||
elog("Sending transaction for sidechain address update operation failed with exception ${e}", ("e", e.what()));
|
||||
retval = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,12 +34,12 @@ hive_node_rpc_client::hive_node_rpc_client(std::string _ip, uint32_t _port, std:
|
|||
|
||||
std::string hive_node_rpc_client::account_history_api_get_transaction(std::string transaction_id) {
|
||||
std::string params = "{ \"id\": \"" + transaction_id + "\" }";
|
||||
return send_post_request("account_history_api.get_transaction", params, true);
|
||||
return send_post_request("account_history_api.get_transaction", params, false);
|
||||
}
|
||||
|
||||
std::string hive_node_rpc_client::block_api_get_block(uint32_t block_number) {
|
||||
std::string params = "{ \"block_num\": " + std::to_string(block_number) + " }";
|
||||
return send_post_request("block_api.get_block", params, true);
|
||||
return send_post_request("block_api.get_block", params, false);
|
||||
}
|
||||
|
||||
std::string hive_node_rpc_client::condenser_api_get_config() {
|
||||
|
|
@ -57,7 +57,7 @@ std::string hive_node_rpc_client::database_api_get_version() {
|
|||
|
||||
std::string hive_node_rpc_client::network_broadcast_api_broadcast_transaction(std::string htrx) {
|
||||
std::string params = "{ \"trx\": " + htrx + ", \"max_block_age\": -1 }";
|
||||
return send_post_request("network_broadcast_api.broadcast_transaction", params, true);
|
||||
return send_post_request("network_broadcast_api.broadcast_transaction", params, false);
|
||||
}
|
||||
|
||||
std::string hive_node_rpc_client::get_chain_id() {
|
||||
|
|
@ -91,35 +91,7 @@ hive_wallet_rpc_client::hive_wallet_rpc_client(std::string _ip, uint32_t _port,
|
|||
|
||||
std::string hive_wallet_rpc_client::get_account(std::string account) {
|
||||
std::string params = "[\"" + account + "\"]";
|
||||
return send_post_request("get_account", params, true);
|
||||
}
|
||||
|
||||
std::string hive_wallet_rpc_client::lock() {
|
||||
return send_post_request("lock", "", true);
|
||||
}
|
||||
|
||||
std::string hive_wallet_rpc_client::info() {
|
||||
return send_post_request("info", "", true);
|
||||
}
|
||||
|
||||
std::string hive_wallet_rpc_client::unlock(std::string password) {
|
||||
std::string params = "[\"" + password + "\"]";
|
||||
return send_post_request("unlock", params, true);
|
||||
}
|
||||
|
||||
std::string hive_wallet_rpc_client::update_account_auth_key(std::string account_name, std::string type, std::string public_key, std::string weight) {
|
||||
std::string params = "[\"" + account_name + "\", \"" + type + "\", \"" + public_key + "\", " + weight + "]";
|
||||
return send_post_request("update_account_auth_key", params, true);
|
||||
}
|
||||
|
||||
std::string hive_wallet_rpc_client::update_account_auth_account(std::string account_name, std::string type, std::string auth_account, std::string weight) {
|
||||
std::string params = "[\"" + account_name + "\", \"" + type + "\", \"" + auth_account + "\", " + weight + "]";
|
||||
return send_post_request("update_account_auth_account", params, true);
|
||||
}
|
||||
|
||||
std::string hive_wallet_rpc_client::update_account_auth_threshold(std::string account_name, std::string type, std::string threshold) {
|
||||
std::string params = "[\"" + account_name + "\", \"" + type + "\", " + threshold + "]";
|
||||
return send_post_request("update_account_auth_account", params, true);
|
||||
return send_post_request("get_account", params, false);
|
||||
}
|
||||
|
||||
std::string hive_wallet_rpc_client::get_account_memo_key(std::string account) {
|
||||
|
|
@ -130,8 +102,6 @@ std::string hive_wallet_rpc_client::get_account_memo_key(std::string account) {
|
|||
sidechain_net_handler_hive::sidechain_net_handler_hive(peerplays_sidechain_plugin &_plugin, const boost::program_options::variables_map &options) :
|
||||
sidechain_net_handler(_plugin, options) {
|
||||
sidechain = sidechain_type::hive;
|
||||
tracked_assets.push_back(database.get_global_properties().parameters.hbd_asset());
|
||||
tracked_assets.push_back(database.get_global_properties().parameters.hive_asset());
|
||||
|
||||
node_ip = options.at("hive-node-ip").as<std::string>();
|
||||
node_rpc_port = options.at("hive-node-rpc-port").as<uint32_t>();
|
||||
|
|
@ -214,7 +184,7 @@ sidechain_net_handler_hive::~sidechain_net_handler_hive() {
|
|||
|
||||
bool sidechain_net_handler_hive::process_proposal(const proposal_object &po) {
|
||||
|
||||
ilog("Proposal to process: ${po}, SON id ${son_id}", ("po", po.id)("son_id", plugin.get_current_son_id()));
|
||||
//ilog("Proposal to process: ${po}, SON id ${son_id}", ("po", po.id)("son_id", plugin.get_current_son_id()));
|
||||
|
||||
bool should_approve = false;
|
||||
|
||||
|
|
@ -280,7 +250,6 @@ bool sidechain_net_handler_hive::process_proposal(const proposal_object &po) {
|
|||
std::stringstream ss_trx(boost::algorithm::unhex(op_tx_str));
|
||||
hive::signed_transaction op_trx;
|
||||
fc::raw::unpack(ss_trx, op_trx, 1000);
|
||||
ilog("TRX: ${op_trx}", ("op_trx", op_trx));
|
||||
|
||||
fc::flat_map<std::string, uint16_t> account_auths;
|
||||
uint32_t total_weight = 0;
|
||||
|
|
@ -306,7 +275,6 @@ bool sidechain_net_handler_hive::process_proposal(const proposal_object &po) {
|
|||
htrx.set_expiration(op_trx.expiration);
|
||||
|
||||
htrx.operations.push_back(auo);
|
||||
ilog("TRX: ${htrx}", ("htrx", htrx));
|
||||
|
||||
std::stringstream ss;
|
||||
fc::raw::pack(ss, htrx, 1000);
|
||||
|
|
@ -428,7 +396,6 @@ bool sidechain_net_handler_hive::process_proposal(const proposal_object &po) {
|
|||
std::stringstream ss_trx(boost::algorithm::unhex(op_tx_str));
|
||||
hive::signed_transaction op_trx;
|
||||
fc::raw::unpack(ss_trx, op_trx, 1000);
|
||||
ilog("TRX: ${op_trx}", ("op_trx", op_trx));
|
||||
|
||||
uint64_t symbol = 0;
|
||||
if (swwo->withdraw_currency == "HBD") {
|
||||
|
|
@ -451,7 +418,6 @@ bool sidechain_net_handler_hive::process_proposal(const proposal_object &po) {
|
|||
htrx.set_expiration(op_trx.expiration);
|
||||
|
||||
htrx.operations.push_back(t_op);
|
||||
ilog("TRX: ${htrx}", ("htrx", htrx));
|
||||
|
||||
std::stringstream ss;
|
||||
fc::raw::pack(ss, htrx, 1000);
|
||||
|
|
@ -552,7 +518,6 @@ void sidechain_net_handler_hive::process_primary_wallet() {
|
|||
htrx.set_expiration(head_block_time + fc::seconds(90));
|
||||
|
||||
htrx.operations.push_back(auo);
|
||||
ilog("TRX: ${htrx}", ("htrx", htrx));
|
||||
|
||||
std::stringstream ss;
|
||||
fc::raw::pack(ss, htrx, 1000);
|
||||
|
|
@ -625,7 +590,7 @@ void sidechain_net_handler_hive::process_sidechain_addresses() {
|
|||
plugin.app().p2p_node()->broadcast(net::trx_message(trx));
|
||||
retval = true;
|
||||
} catch (fc::exception &e) {
|
||||
elog("Sending transaction for update deposit address operation failed with exception ${e}", ("e", e.what()));
|
||||
elog("Sending transaction for sidechain address update operation failed with exception ${e}", ("e", e.what()));
|
||||
retval = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -713,7 +678,6 @@ bool sidechain_net_handler_hive::process_withdrawal(const son_wallet_withdraw_ob
|
|||
htrx.set_expiration(head_block_time + fc::seconds(90));
|
||||
|
||||
htrx.operations.push_back(t_op);
|
||||
ilog("TRX: ${htrx}", ("htrx", htrx));
|
||||
|
||||
std::stringstream ss;
|
||||
fc::raw::pack(ss, htrx, 1000);
|
||||
|
|
@ -750,7 +714,7 @@ bool sidechain_net_handler_hive::process_withdrawal(const son_wallet_withdraw_ob
|
|||
plugin.app().p2p_node()->broadcast(net::trx_message(trx));
|
||||
return true;
|
||||
} catch (fc::exception &e) {
|
||||
elog("Sending proposal for deposit sidechain transaction create operation failed with exception ${e}", ("e", e.what()));
|
||||
elog("Sending proposal for withdraw sidechain transaction create operation failed with exception ${e}", ("e", e.what()));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -763,16 +727,12 @@ std::string sidechain_net_handler_hive::process_sidechain_transaction(const side
|
|||
hive::signed_transaction htrx;
|
||||
fc::raw::unpack(ss_trx, htrx, 1000);
|
||||
|
||||
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);
|
||||
|
||||
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));
|
||||
|
||||
std::stringstream ss_st;
|
||||
fc::raw::pack(ss_st, st, 1000);
|
||||
std::string st_str = boost::algorithm::hex(ss_st.str());
|
||||
|
|
@ -794,10 +754,8 @@ std::string sidechain_net_handler_hive::send_sidechain_transaction(const sidecha
|
|||
htrx.signatures.push_back(st);
|
||||
}
|
||||
}
|
||||
ilog("HTRX: ${htrx}", ("htrx", htrx));
|
||||
|
||||
std::string params = fc::json::to_string(htrx);
|
||||
ilog("HTRX: ${htrx}", ("htrx", params));
|
||||
node_rpc_client->network_broadcast_api_broadcast_transaction(params);
|
||||
|
||||
return htrx.id().str();
|
||||
|
|
|
|||
Loading…
Reference in a new issue