Issue tokens to the user who deposited Bitcoin, WIP...
This commit is contained in:
parent
23458ee917
commit
01f1b6137a
5 changed files with 38 additions and 10 deletions
|
|
@ -25,13 +25,11 @@ namespace graphene { namespace chain {
|
||||||
int64_t amount;
|
int64_t amount;
|
||||||
|
|
||||||
bool processed;
|
bool processed;
|
||||||
|
|
||||||
flat_map<peerplays_sidechain::sidechain_type, string> addresses;
|
|
||||||
vector<son_info> sons;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct by_uid;
|
struct by_uid;
|
||||||
struct by_sidechain;
|
struct by_sidechain;
|
||||||
|
struct by_processed;
|
||||||
struct by_sidechain_and_processed;
|
struct by_sidechain_and_processed;
|
||||||
using son_wallet_transfer_multi_index_type = multi_index_container<
|
using son_wallet_transfer_multi_index_type = multi_index_container<
|
||||||
son_wallet_transfer_object,
|
son_wallet_transfer_object,
|
||||||
|
|
@ -45,6 +43,9 @@ namespace graphene { namespace chain {
|
||||||
ordered_non_unique< tag<by_sidechain>,
|
ordered_non_unique< tag<by_sidechain>,
|
||||||
member<son_wallet_transfer_object, peerplays_sidechain::sidechain_type, &son_wallet_transfer_object::sidechain>
|
member<son_wallet_transfer_object, peerplays_sidechain::sidechain_type, &son_wallet_transfer_object::sidechain>
|
||||||
>,
|
>,
|
||||||
|
ordered_non_unique< tag<by_processed>,
|
||||||
|
member<son_wallet_transfer_object, bool, &son_wallet_transfer_object::processed>
|
||||||
|
>,
|
||||||
ordered_non_unique< tag<by_sidechain_and_processed>,
|
ordered_non_unique< tag<by_sidechain_and_processed>,
|
||||||
composite_key<son_wallet_transfer_object,
|
composite_key<son_wallet_transfer_object,
|
||||||
member<son_wallet_transfer_object, peerplays_sidechain::sidechain_type, &son_wallet_transfer_object::sidechain>,
|
member<son_wallet_transfer_object, peerplays_sidechain::sidechain_type, &son_wallet_transfer_object::sidechain>,
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,9 @@ namespace graphene { namespace chain {
|
||||||
void_result create_son_wallet_transfer_evaluator::do_evaluate(const son_wallet_transfer_create_operation& op)
|
void_result create_son_wallet_transfer_evaluator::do_evaluate(const son_wallet_transfer_create_operation& op)
|
||||||
{ try{
|
{ try{
|
||||||
FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK");
|
FC_ASSERT(db().head_block_time() >= HARDFORK_SON_TIME, "Not allowed until SON HARDFORK");
|
||||||
FC_ASSERT(db().get_global_properties().parameters.get_son_btc_account_id() != GRAPHENE_NULL_ACCOUNT, "SON paying account not set.");
|
//FC_ASSERT(db().get_global_properties().parameters.get_son_btc_account_id() != GRAPHENE_NULL_ACCOUNT, "SON paying account not set.");
|
||||||
|
FC_ASSERT( op.payer == db().get_global_properties().parameters.get_son_btc_account_id() );
|
||||||
|
|
||||||
const auto& idx = db().get_index_type<son_wallet_transfer_index>().indices().get<by_uid>();
|
const auto& idx = db().get_index_type<son_wallet_transfer_index>().indices().get<by_uid>();
|
||||||
FC_ASSERT(idx.find(op.uid) == idx.end(), "Already registered " + op.uid);
|
FC_ASSERT(idx.find(op.uid) == idx.end(), "Already registered " + op.uid);
|
||||||
return void_result();
|
return void_result();
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@
|
||||||
#include <fc/time.hpp>
|
#include <fc/time.hpp>
|
||||||
#include <fc/crypto/sha256.hpp>
|
#include <fc/crypto/sha256.hpp>
|
||||||
|
|
||||||
|
#include <graphene/chain/protocol/types.hpp>
|
||||||
|
|
||||||
namespace graphene { namespace peerplays_sidechain {
|
namespace graphene { namespace peerplays_sidechain {
|
||||||
|
|
||||||
enum class sidechain_type {
|
enum class sidechain_type {
|
||||||
|
|
@ -67,7 +69,9 @@ struct sidechain_event_data {
|
||||||
sidechain_type sidechain;
|
sidechain_type sidechain;
|
||||||
std::string transaction_id;
|
std::string transaction_id;
|
||||||
std::string from;
|
std::string from;
|
||||||
|
chain::account_id_type peerplays_from;
|
||||||
std::string to;
|
std::string to;
|
||||||
|
chain::account_id_type peerplays_to;
|
||||||
int64_t amount;
|
int64_t amount;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
#include <graphene/chain/proposal_object.hpp>
|
#include <graphene/chain/proposal_object.hpp>
|
||||||
#include <graphene/chain/sidechain_address_object.hpp>
|
#include <graphene/chain/sidechain_address_object.hpp>
|
||||||
#include <graphene/chain/son_wallet_object.hpp>
|
#include <graphene/chain/son_wallet_object.hpp>
|
||||||
|
#include <graphene/chain/son_wallet_transfer_object.hpp>
|
||||||
#include <graphene/peerplays_sidechain/sidechain_net_manager.hpp>
|
#include <graphene/peerplays_sidechain/sidechain_net_manager.hpp>
|
||||||
#include <graphene/utilities/key_conversion.hpp>
|
#include <graphene/utilities/key_conversion.hpp>
|
||||||
|
|
||||||
|
|
@ -47,6 +48,7 @@ class peerplays_sidechain_plugin_impl
|
||||||
|
|
||||||
private:
|
private:
|
||||||
peerplays_sidechain_plugin& plugin;
|
peerplays_sidechain_plugin& plugin;
|
||||||
|
graphene::chain::database& database;
|
||||||
|
|
||||||
bool config_ready_son;
|
bool config_ready_son;
|
||||||
bool config_ready_bitcoin;
|
bool config_ready_bitcoin;
|
||||||
|
|
@ -59,7 +61,8 @@ class peerplays_sidechain_plugin_impl
|
||||||
};
|
};
|
||||||
|
|
||||||
peerplays_sidechain_plugin_impl::peerplays_sidechain_plugin_impl(peerplays_sidechain_plugin& _plugin) :
|
peerplays_sidechain_plugin_impl::peerplays_sidechain_plugin_impl(peerplays_sidechain_plugin& _plugin) :
|
||||||
plugin( _plugin ),
|
plugin(_plugin),
|
||||||
|
database(_plugin.database()),
|
||||||
config_ready_son(false),
|
config_ready_son(false),
|
||||||
config_ready_bitcoin(false),
|
config_ready_bitcoin(false),
|
||||||
net_manager(nullptr)
|
net_manager(nullptr)
|
||||||
|
|
@ -137,8 +140,8 @@ void peerplays_sidechain_plugin_impl::plugin_initialize(const boost::program_opt
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
plugin.database().applied_block.connect( [&] (const signed_block& b) { on_block_applied(b); } );
|
database.applied_block.connect( [&] (const signed_block& b) { on_block_applied(b); } );
|
||||||
plugin.database().new_objects.connect( [&] (const vector<object_id_type>& ids, const flat_set<account_id_type>& impacted_accounts) { on_objects_new(ids); } );
|
database.new_objects.connect( [&] (const vector<object_id_type>& ids, const flat_set<account_id_type>& impacted_accounts) { on_objects_new(ids); } );
|
||||||
|
|
||||||
net_manager = std::unique_ptr<sidechain_net_manager>(new sidechain_net_manager(plugin));
|
net_manager = std::unique_ptr<sidechain_net_manager>(new sidechain_net_manager(plugin));
|
||||||
|
|
||||||
|
|
@ -195,7 +198,7 @@ son_id_type peerplays_sidechain_plugin_impl::get_son_id()
|
||||||
|
|
||||||
son_object peerplays_sidechain_plugin_impl::get_son_object()
|
son_object peerplays_sidechain_plugin_impl::get_son_object()
|
||||||
{
|
{
|
||||||
const auto& idx = plugin.database().get_index_type<chain::son_index>().indices().get<by_id>();
|
const auto& idx = database.get_index_type<chain::son_index>().indices().get<by_id>();
|
||||||
auto son_obj = idx.find( get_son_id() );
|
auto son_obj = idx.find( get_son_id() );
|
||||||
if (son_obj == idx.end())
|
if (son_obj == idx.end())
|
||||||
return {};
|
return {};
|
||||||
|
|
@ -204,12 +207,12 @@ son_object peerplays_sidechain_plugin_impl::get_son_object()
|
||||||
|
|
||||||
bool peerplays_sidechain_plugin_impl::is_active_son()
|
bool peerplays_sidechain_plugin_impl::is_active_son()
|
||||||
{
|
{
|
||||||
const auto& idx = plugin.database().get_index_type<chain::son_index>().indices().get<by_id>();
|
const auto& idx = database.get_index_type<chain::son_index>().indices().get<by_id>();
|
||||||
auto son_obj = idx.find( get_son_id() );
|
auto son_obj = idx.find( get_son_id() );
|
||||||
if (son_obj == idx.end())
|
if (son_obj == idx.end())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const chain::global_property_object& gpo = plugin.database().get_global_properties();
|
const chain::global_property_object& gpo = database.get_global_properties();
|
||||||
vector<son_id_type> active_son_ids;
|
vector<son_id_type> active_son_ids;
|
||||||
active_son_ids.reserve(gpo.active_sons.size());
|
active_son_ids.reserve(gpo.active_sons.size());
|
||||||
std::transform(gpo.active_sons.begin(), gpo.active_sons.end(),
|
std::transform(gpo.active_sons.begin(), gpo.active_sons.end(),
|
||||||
|
|
@ -343,6 +346,15 @@ void peerplays_sidechain_plugin_impl::recreate_primary_wallet()
|
||||||
}
|
}
|
||||||
|
|
||||||
void peerplays_sidechain_plugin_impl::process_deposits() {
|
void peerplays_sidechain_plugin_impl::process_deposits() {
|
||||||
|
|
||||||
|
const auto& idx = database.get_index_type<son_wallet_transfer_index>().indices().get<by_processed>();
|
||||||
|
const auto& idx_range = idx.equal_range(false);
|
||||||
|
|
||||||
|
std::for_each(idx_range.first, idx_range.second,
|
||||||
|
[&] (const son_wallet_transfer_object& swto) {
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
//void peerplays_sidechain_plugin_impl::process_withdrawals() {
|
//void peerplays_sidechain_plugin_impl::process_withdrawals() {
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#include <fc/log/logger.hpp>
|
#include <fc/log/logger.hpp>
|
||||||
#include <fc/network/ip.hpp>
|
#include <fc/network/ip.hpp>
|
||||||
|
|
||||||
|
#include <graphene/chain/account_object.hpp>
|
||||||
#include <graphene/chain/sidechain_address_object.hpp>
|
#include <graphene/chain/sidechain_address_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>
|
||||||
|
|
@ -337,6 +338,12 @@ void sidechain_net_handler_bitcoin::handle_event( const std::string& event_data
|
||||||
if( block != "" ) {
|
if( block != "" ) {
|
||||||
const auto& vins = extract_info_from_block( block );
|
const auto& vins = extract_info_from_block( block );
|
||||||
|
|
||||||
|
account_id_type peerplays_to = GRAPHENE_NULL_ACCOUNT;
|
||||||
|
const auto& account_idx = database.get_index_type<account_index>().indices().get<by_name>();
|
||||||
|
const auto& account_itr = account_idx.find("nathan");
|
||||||
|
if (account_itr != account_idx.end())
|
||||||
|
peerplays_to = (*account_itr).id;
|
||||||
|
|
||||||
const auto& sidechain_addresses_idx = database.get_index_type<sidechain_address_index>().indices().get<by_sidechain_and_address>();
|
const auto& sidechain_addresses_idx = database.get_index_type<sidechain_address_index>().indices().get<by_sidechain_and_address>();
|
||||||
|
|
||||||
for( const auto& v : vins ) {
|
for( const auto& v : vins ) {
|
||||||
|
|
@ -352,7 +359,9 @@ void sidechain_net_handler_bitcoin::handle_event( const std::string& event_data
|
||||||
sed.sidechain = addr_itr->sidechain;
|
sed.sidechain = addr_itr->sidechain;
|
||||||
sed.transaction_id = v.out.hash_tx;
|
sed.transaction_id = v.out.hash_tx;
|
||||||
sed.from = "";
|
sed.from = "";
|
||||||
|
sed.peerplays_from = addr_itr->sidechain_address_account;
|
||||||
sed.to = v.address;
|
sed.to = v.address;
|
||||||
|
sed.peerplays_to = peerplays_to;
|
||||||
sed.amount = v.out.amount;
|
sed.amount = v.out.amount;
|
||||||
sidechain_event_data_received(sed);
|
sidechain_event_data_received(sed);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue