Enable SON Hive withdrawal without registering sidechain address
This commit is contained in:
parent
d0e59a1c60
commit
2a4a4b8dc5
3 changed files with 23 additions and 6 deletions
|
|
@ -30,7 +30,7 @@ namespace graphene { namespace chain {
|
||||||
void memo_data::set_message(const fc::ecc::private_key& priv, const fc::ecc::public_key& pub,
|
void memo_data::set_message(const fc::ecc::private_key& priv, const fc::ecc::public_key& pub,
|
||||||
const string& msg, uint64_t custom_nonce)
|
const string& msg, uint64_t custom_nonce)
|
||||||
{
|
{
|
||||||
if( priv != fc::ecc::private_key() && public_key_type(pub) != public_key_type() )
|
if( priv != fc::ecc::private_key() && pub.valid() )
|
||||||
{
|
{
|
||||||
from = priv.get_public_key();
|
from = priv.get_public_key();
|
||||||
to = pub;
|
to = pub;
|
||||||
|
|
@ -57,7 +57,7 @@ void memo_data::set_message(const fc::ecc::private_key& priv, const fc::ecc::pub
|
||||||
string memo_data::get_message(const fc::ecc::private_key& priv,
|
string memo_data::get_message(const fc::ecc::private_key& priv,
|
||||||
const fc::ecc::public_key& pub)const
|
const fc::ecc::public_key& pub)const
|
||||||
{
|
{
|
||||||
if( from != public_key_type() )
|
if( from != public_key_type() && pub.valid() )
|
||||||
{
|
{
|
||||||
auto secret = priv.get_shared_secret(pub);
|
auto secret = priv.get_shared_secret(pub);
|
||||||
auto nonce_plus_secret = fc::sha512::hash(fc::to_string(nonce) + secret.str());
|
auto nonce_plus_secret = fc::sha512::hash(fc::to_string(nonce) + secret.str());
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,7 @@
|
||||||
#include <graphene/peerplays_sidechain/sidechain_net_handler.hpp>
|
#include <graphene/peerplays_sidechain/sidechain_net_handler.hpp>
|
||||||
|
|
||||||
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
#include <fc/log/logger.hpp>
|
#include <fc/log/logger.hpp>
|
||||||
#include <graphene/chain/chain_property_object.hpp>
|
#include <graphene/chain/chain_property_object.hpp>
|
||||||
#include <graphene/chain/proposal_object.hpp>
|
#include <graphene/chain/proposal_object.hpp>
|
||||||
|
|
@ -223,10 +225,14 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_
|
||||||
|
|
||||||
// Withdrawal request
|
// Withdrawal request
|
||||||
if (withdraw_condition) {
|
if (withdraw_condition) {
|
||||||
|
std::string withdraw_address = "";
|
||||||
const auto &sidechain_addresses_idx = database.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain_and_expires>();
|
const auto &sidechain_addresses_idx = database.get_index_type<sidechain_address_index>().indices().get<by_account_and_sidechain_and_expires>();
|
||||||
const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sed.peerplays_from, sidechain, time_point_sec::maximum()));
|
const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sed.peerplays_from, sidechain, time_point_sec::maximum()));
|
||||||
if (addr_itr == sidechain_addresses_idx.end())
|
if (addr_itr != sidechain_addresses_idx.end()) {
|
||||||
return;
|
withdraw_address = addr_itr->withdraw_address;
|
||||||
|
} else {
|
||||||
|
withdraw_address = sed.sidechain_from;
|
||||||
|
}
|
||||||
|
|
||||||
std::string withdraw_currency = "";
|
std::string withdraw_currency = "";
|
||||||
price withdraw_currency_price = {};
|
price withdraw_currency_price = {};
|
||||||
|
|
@ -260,7 +266,7 @@ void sidechain_net_handler::sidechain_event_data_received(const sidechain_event_
|
||||||
op.peerplays_from = sed.peerplays_from;
|
op.peerplays_from = sed.peerplays_from;
|
||||||
op.peerplays_asset = sed.peerplays_asset;
|
op.peerplays_asset = sed.peerplays_asset;
|
||||||
op.withdraw_sidechain = sidechain;
|
op.withdraw_sidechain = sidechain;
|
||||||
op.withdraw_address = addr_itr->withdraw_address;
|
op.withdraw_address = withdraw_address;
|
||||||
op.withdraw_currency = withdraw_currency;
|
op.withdraw_currency = withdraw_currency;
|
||||||
op.withdraw_amount = sed.peerplays_asset.amount * withdraw_currency_price.quote.amount / withdraw_currency_price.base.amount;
|
op.withdraw_amount = sed.peerplays_asset.amount * withdraw_currency_price.quote.amount / withdraw_currency_price.base.amount;
|
||||||
|
|
||||||
|
|
@ -636,6 +642,16 @@ void sidechain_net_handler::on_applied_block(const signed_block &b) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string sidechain_from = account_id_to_string(transfer_op.from);
|
||||||
|
std::string memo = "";
|
||||||
|
if (transfer_op.memo) {
|
||||||
|
memo = transfer_op.memo->get_message(fc::ecc::private_key(), public_key_type());
|
||||||
|
boost::trim(memo);
|
||||||
|
if (!memo.empty()) {
|
||||||
|
sidechain_from = memo;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "peerplays"
|
ss << "peerplays"
|
||||||
<< "-" << trx.id().str() << "-" << operation_index;
|
<< "-" << trx.id().str() << "-" << operation_index;
|
||||||
|
|
@ -647,7 +663,7 @@ void sidechain_net_handler::on_applied_block(const signed_block &b) {
|
||||||
sed.sidechain = sidechain_type::peerplays;
|
sed.sidechain = sidechain_type::peerplays;
|
||||||
sed.sidechain_uid = sidechain_uid;
|
sed.sidechain_uid = sidechain_uid;
|
||||||
sed.sidechain_transaction_id = trx.id().str();
|
sed.sidechain_transaction_id = trx.id().str();
|
||||||
sed.sidechain_from = account_id_to_string(transfer_op.from);
|
sed.sidechain_from = sidechain_from;
|
||||||
sed.sidechain_to = account_id_to_string(transfer_op.to);
|
sed.sidechain_to = account_id_to_string(transfer_op.to);
|
||||||
sed.sidechain_currency = asset_id_to_string(transfer_op.amount.asset_id);
|
sed.sidechain_currency = asset_id_to_string(transfer_op.amount.asset_id);
|
||||||
sed.sidechain_amount = transfer_op.amount.amount;
|
sed.sidechain_amount = transfer_op.amount.amount;
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
#include <graphene/chain/protocol/son_wallet.hpp>
|
#include <graphene/chain/protocol/son_wallet.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>
|
||||||
|
#include <graphene/peerplays_sidechain/common/utils.hpp>
|
||||||
#include <graphene/peerplays_sidechain/hive/asset.hpp>
|
#include <graphene/peerplays_sidechain/hive/asset.hpp>
|
||||||
#include <graphene/peerplays_sidechain/hive/operations.hpp>
|
#include <graphene/peerplays_sidechain/hive/operations.hpp>
|
||||||
#include <graphene/peerplays_sidechain/hive/transaction.hpp>
|
#include <graphene/peerplays_sidechain/hive/transaction.hpp>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue