SON wallet transfer object and operations, for tracking assets deposit/withdrawal
This commit is contained in:
parent
6055576aa4
commit
775fdf8980
10 changed files with 68 additions and 26 deletions
|
|
@ -135,7 +135,7 @@ else( WIN32 ) # Apple AND Linux
|
||||||
endif( APPLE )
|
endif( APPLE )
|
||||||
|
|
||||||
if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" )
|
if( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" )
|
||||||
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-memcmp -Wno-parentheses -Wno-invalid-offsetof" )
|
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-builtin-memcmp -Wno-parentheses -Wno-invalid-offsetof -Wno-terminate -Wno-sign-compare" )
|
||||||
elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" )
|
elseif( "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" )
|
||||||
if( CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.0.0 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0.0 )
|
if( CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL 4.0.0 OR CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 4.0.0 )
|
||||||
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-partial-specialization" )
|
set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-invalid-partial-specialization" )
|
||||||
|
|
|
||||||
|
|
@ -475,13 +475,13 @@ void database::update_active_sons()
|
||||||
const auto& idx_swi = get_index_type<son_wallet_index>().indices().get<by_id>();
|
const auto& idx_swi = get_index_type<son_wallet_index>().indices().get<by_id>();
|
||||||
auto obj = idx_swi.rbegin();
|
auto obj = idx_swi.rbegin();
|
||||||
if (obj != idx_swi.rend()) {
|
if (obj != idx_swi.rend()) {
|
||||||
modify(*obj, [&, &obj](son_wallet_object &swo) {
|
modify(*obj, [&, obj](son_wallet_object &swo) {
|
||||||
swo.expires = head_block_time();
|
swo.expires = head_block_time();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new son_wallet_object, to initiate wallet recreation
|
// Create new son_wallet_object, to initiate wallet recreation
|
||||||
const auto& new_son_wallet_object = create<son_wallet_object>( [&]( son_wallet_object& obj ){
|
create<son_wallet_object>( [&]( son_wallet_object& obj ) {
|
||||||
obj.valid_from = head_block_time();
|
obj.valid_from = head_block_time();
|
||||||
obj.expires = time_point_sec::maximum();
|
obj.expires = time_point_sec::maximum();
|
||||||
obj.sons.insert(obj.sons.end(), new_active_sons.begin(), new_active_sons.end());
|
obj.sons.insert(obj.sons.end(), new_active_sons.begin(), new_active_sons.end());
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ object_id_type close_son_wallet_evaluator::do_apply(const son_wallet_close_opera
|
||||||
auto itr = idx.find(op.son_wallet_id);
|
auto itr = idx.find(op.son_wallet_id);
|
||||||
if(itr != idx.end())
|
if(itr != idx.end())
|
||||||
{
|
{
|
||||||
db().modify(*itr, [&, &op](son_wallet_object &swo) {
|
db().modify(*itr, [&, op](son_wallet_object &swo) {
|
||||||
swo.expires = db().head_block_time();
|
swo.expires = db().head_block_time();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,7 @@
|
||||||
|
|
||||||
#include <graphene/app/plugin.hpp>
|
#include <graphene/app/plugin.hpp>
|
||||||
|
|
||||||
#include <graphene/chain/account_object.hpp>
|
|
||||||
#include <graphene/chain/son_object.hpp>
|
#include <graphene/chain/son_object.hpp>
|
||||||
#include <graphene/chain/database.hpp>
|
|
||||||
|
|
||||||
#include <graphene/peerplays_sidechain/defs.hpp>
|
|
||||||
|
|
||||||
namespace graphene { namespace peerplays_sidechain {
|
namespace graphene { namespace peerplays_sidechain {
|
||||||
using namespace chain;
|
using namespace chain;
|
||||||
|
|
@ -30,6 +26,10 @@ class peerplays_sidechain_plugin : public graphene::app::plugin
|
||||||
virtual void plugin_startup() override;
|
virtual void plugin_startup() override;
|
||||||
|
|
||||||
std::unique_ptr<detail::peerplays_sidechain_plugin_impl> my;
|
std::unique_ptr<detail::peerplays_sidechain_plugin_impl> my;
|
||||||
|
|
||||||
|
son_id_type get_son_id();
|
||||||
|
son_object get_son_object();
|
||||||
|
std::map<chain::public_key_type, fc::ecc::private_key> get_private_keys();
|
||||||
};
|
};
|
||||||
|
|
||||||
} } //graphene::peerplays_sidechain
|
} } //graphene::peerplays_sidechain
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,13 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <graphene/peerplays_sidechain/defs.hpp>
|
|
||||||
#include <graphene/peerplays_sidechain/peerplays_sidechain_plugin.hpp>
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <boost/program_options.hpp>
|
#include <boost/program_options.hpp>
|
||||||
|
|
||||||
|
#include <fc/signals.hpp>
|
||||||
|
#include <graphene/peerplays_sidechain/defs.hpp>
|
||||||
|
#include <graphene/peerplays_sidechain/peerplays_sidechain_plugin.hpp>
|
||||||
|
|
||||||
namespace graphene { namespace peerplays_sidechain {
|
namespace graphene { namespace peerplays_sidechain {
|
||||||
|
|
||||||
class sidechain_net_handler {
|
class sidechain_net_handler {
|
||||||
|
|
@ -20,13 +21,13 @@ public:
|
||||||
virtual son_wallet_update_operation recreate_primary_wallet() = 0;
|
virtual son_wallet_update_operation recreate_primary_wallet() = 0;
|
||||||
virtual string recreate_primary_wallet(const vector<string>& participants) = 0;
|
virtual string recreate_primary_wallet(const vector<string>& participants) = 0;
|
||||||
|
|
||||||
|
fc::signal<void(const sidechain_event_data&)> sidechain_event_data_received;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
peerplays_sidechain_plugin& plugin;
|
peerplays_sidechain_plugin& plugin;
|
||||||
graphene::chain::database& database;
|
graphene::chain::database& database;
|
||||||
graphene::peerplays_sidechain::sidechain_type sidechain;
|
graphene::peerplays_sidechain::sidechain_type sidechain;
|
||||||
|
|
||||||
void sidechain_event_data_received(const sidechain_event_data& sed);
|
|
||||||
|
|
||||||
virtual std::string create_multisignature_wallet( const std::vector<std::string> public_keys ) = 0;
|
virtual std::string create_multisignature_wallet( const std::vector<std::string> public_keys ) = 0;
|
||||||
virtual std::string transfer( const std::string& from, const std::string& to, const uint64_t amount ) = 0;
|
virtual std::string transfer( const std::string& from, const std::string& to, const uint64_t amount ) = 0;
|
||||||
virtual std::string sign_transaction( const std::string& transaction ) = 0;
|
virtual std::string sign_transaction( const std::string& transaction ) = 0;
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ public:
|
||||||
sidechain_net_manager(peerplays_sidechain_plugin& _plugin);
|
sidechain_net_manager(peerplays_sidechain_plugin& _plugin);
|
||||||
virtual ~sidechain_net_manager();
|
virtual ~sidechain_net_manager();
|
||||||
|
|
||||||
bool create_handler(peerplays_sidechain::sidechain_type sidechain, const boost::program_options::variables_map& options);
|
std::unique_ptr<sidechain_net_handler> create_handler(peerplays_sidechain::sidechain_type sidechain, const boost::program_options::variables_map& options);
|
||||||
signed_transaction recreate_primary_wallet();
|
signed_transaction recreate_primary_wallet();
|
||||||
string recreate_primary_wallet(peerplays_sidechain::sidechain_type sidechain, const vector<string>& participants);
|
string recreate_primary_wallet(peerplays_sidechain::sidechain_type sidechain, const vector<string>& participants);
|
||||||
private:
|
private:
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,9 @@
|
||||||
|
|
||||||
#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_object.hpp>
|
||||||
#include <graphene/chain/son_wallet_object.hpp>
|
#include <graphene/chain/son_wallet_object.hpp>
|
||||||
|
#include <graphene/chain/protocol/types.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>
|
||||||
|
|
||||||
|
|
@ -31,6 +33,10 @@ class peerplays_sidechain_plugin_impl
|
||||||
void plugin_initialize(const boost::program_options::variables_map& options);
|
void plugin_initialize(const boost::program_options::variables_map& options);
|
||||||
void plugin_startup();
|
void plugin_startup();
|
||||||
|
|
||||||
|
son_id_type get_son_id();
|
||||||
|
son_object get_son_object();
|
||||||
|
std::map<chain::public_key_type, fc::ecc::private_key> get_private_keys();
|
||||||
|
|
||||||
void schedule_heartbeat_loop();
|
void schedule_heartbeat_loop();
|
||||||
void heartbeat_loop();
|
void heartbeat_loop();
|
||||||
void create_son_down_proposals();
|
void create_son_down_proposals();
|
||||||
|
|
@ -132,6 +138,9 @@ 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); } );
|
||||||
|
plugin.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));
|
||||||
|
|
||||||
config_ready_bitcoin = options.count( "bitcoin-node-ip" ) &&
|
config_ready_bitcoin = options.count( "bitcoin-node-ip" ) &&
|
||||||
|
|
@ -139,7 +148,7 @@ void peerplays_sidechain_plugin_impl::plugin_initialize(const boost::program_opt
|
||||||
options.count( "bitcoin-node-rpc-user" ) && options.count( "bitcoin-node-rpc-password" ) &&
|
options.count( "bitcoin-node-rpc-user" ) && options.count( "bitcoin-node-rpc-password" ) &&
|
||||||
options.count( "bitcoin-address" ) && options.count( "bitcoin-public-key" ) && options.count( "bitcoin-private-key" );
|
options.count( "bitcoin-address" ) && options.count( "bitcoin-public-key" ) && options.count( "bitcoin-private-key" );
|
||||||
if (config_ready_bitcoin) {
|
if (config_ready_bitcoin) {
|
||||||
net_manager->create_handler(sidechain_type::bitcoin, options);
|
std::unique_ptr<sidechain_net_handler> h = net_manager->create_handler(sidechain_type::bitcoin, options);
|
||||||
ilog("Bitcoin sidechain handler created");
|
ilog("Bitcoin sidechain handler created");
|
||||||
} else {
|
} else {
|
||||||
wlog("Haven't set up Bitcoin sidechain parameters");
|
wlog("Haven't set up Bitcoin sidechain parameters");
|
||||||
|
|
@ -180,6 +189,25 @@ void peerplays_sidechain_plugin_impl::plugin_startup()
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
son_id_type peerplays_sidechain_plugin_impl::get_son_id()
|
||||||
|
{
|
||||||
|
return *(_sons.begin());
|
||||||
|
}
|
||||||
|
|
||||||
|
son_object peerplays_sidechain_plugin_impl::get_son_object()
|
||||||
|
{
|
||||||
|
const auto& idx = plugin.database().get_index_type<chain::son_index>().indices().get<by_id>();
|
||||||
|
auto son_obj = idx.find( get_son_id() );
|
||||||
|
if (son_obj == idx.end())
|
||||||
|
return {};
|
||||||
|
return *son_obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<chain::public_key_type, fc::ecc::private_key> peerplays_sidechain_plugin_impl::get_private_keys()
|
||||||
|
{
|
||||||
|
return _private_keys;
|
||||||
|
}
|
||||||
|
|
||||||
void peerplays_sidechain_plugin_impl::schedule_heartbeat_loop()
|
void peerplays_sidechain_plugin_impl::schedule_heartbeat_loop()
|
||||||
{
|
{
|
||||||
fc::time_point now = fc::time_point::now();
|
fc::time_point now = fc::time_point::now();
|
||||||
|
|
@ -421,8 +449,6 @@ void peerplays_sidechain_plugin::plugin_initialize(const boost::program_options:
|
||||||
{
|
{
|
||||||
ilog("peerplays sidechain plugin: plugin_initialize()");
|
ilog("peerplays sidechain plugin: plugin_initialize()");
|
||||||
my->plugin_initialize(options);
|
my->plugin_initialize(options);
|
||||||
database().applied_block.connect( [&]( const signed_block& b){ my->on_block_applied(b); } );
|
|
||||||
database().new_objects.connect([this](const vector<object_id_type>& ids, const flat_set<account_id_type>& impacted_accounts) { my->on_objects_new(ids); });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void peerplays_sidechain_plugin::plugin_startup()
|
void peerplays_sidechain_plugin::plugin_startup()
|
||||||
|
|
@ -431,5 +457,20 @@ void peerplays_sidechain_plugin::plugin_startup()
|
||||||
my->plugin_startup();
|
my->plugin_startup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
son_id_type peerplays_sidechain_plugin::get_son_id()
|
||||||
|
{
|
||||||
|
return my->get_son_id();
|
||||||
|
}
|
||||||
|
|
||||||
|
son_object peerplays_sidechain_plugin::get_son_object()
|
||||||
|
{
|
||||||
|
return my->get_son_object();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<chain::public_key_type, fc::ecc::private_key> peerplays_sidechain_plugin::get_private_keys()
|
||||||
|
{
|
||||||
|
return my->get_private_keys();
|
||||||
|
}
|
||||||
|
|
||||||
} } // graphene::peerplays_sidechain
|
} } // graphene::peerplays_sidechain
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -276,7 +276,7 @@ son_wallet_update_operation sidechain_net_handler_bitcoin::recreate_primary_wall
|
||||||
ilog(__FUNCTION__);
|
ilog(__FUNCTION__);
|
||||||
|
|
||||||
son_wallet_update_operation op;
|
son_wallet_update_operation op;
|
||||||
op.payer = database.get_global_properties().parameters.get_son_btc_account_id();
|
op.payer = plugin.get_son_object().son_account;
|
||||||
op.son_wallet_id = (*obj).id;
|
op.son_wallet_id = (*obj).id;
|
||||||
op.sidechain = sidechain_type::bitcoin;
|
op.sidechain = sidechain_type::bitcoin;
|
||||||
op.address = ss.str();
|
op.address = ss.str();
|
||||||
|
|
|
||||||
|
|
@ -7,8 +7,8 @@
|
||||||
namespace graphene { namespace peerplays_sidechain {
|
namespace graphene { namespace peerplays_sidechain {
|
||||||
|
|
||||||
sidechain_net_manager::sidechain_net_manager(peerplays_sidechain_plugin& _plugin) :
|
sidechain_net_manager::sidechain_net_manager(peerplays_sidechain_plugin& _plugin) :
|
||||||
plugin(_plugin),
|
plugin(_plugin),
|
||||||
database(_plugin.database())
|
database(_plugin.database())
|
||||||
{
|
{
|
||||||
ilog(__FUNCTION__);
|
ilog(__FUNCTION__);
|
||||||
}
|
}
|
||||||
|
|
@ -17,17 +17,16 @@ sidechain_net_manager::~sidechain_net_manager() {
|
||||||
ilog(__FUNCTION__);
|
ilog(__FUNCTION__);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool sidechain_net_manager::create_handler(peerplays_sidechain::sidechain_type sidechain, const boost::program_options::variables_map& options) {
|
std::unique_ptr<sidechain_net_handler> sidechain_net_manager::create_handler(peerplays_sidechain::sidechain_type sidechain, const boost::program_options::variables_map& options) {
|
||||||
ilog(__FUNCTION__);
|
ilog(__FUNCTION__);
|
||||||
|
|
||||||
bool ret_val = false;
|
std::unique_ptr<sidechain_net_handler> ret_val = nullptr;
|
||||||
|
|
||||||
switch (sidechain) {
|
switch (sidechain) {
|
||||||
case sidechain_type::bitcoin: {
|
case sidechain_type::bitcoin: {
|
||||||
std::unique_ptr<sidechain_net_handler> h = std::unique_ptr<sidechain_net_handler>(new sidechain_net_handler_bitcoin(plugin, options));
|
ret_val = std::unique_ptr<sidechain_net_handler>(new sidechain_net_handler_bitcoin(plugin, options));
|
||||||
net_handlers.push_back(std::move(h));
|
net_handlers.push_back(std::move(ret_val));
|
||||||
ret_val = true;
|
break;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
assert(false);
|
assert(false);
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@
|
||||||
#include <graphene/chain/game_object.hpp>
|
#include <graphene/chain/game_object.hpp>
|
||||||
#include <graphene/chain/son_object.hpp>
|
#include <graphene/chain/son_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/chain/sidechain_address_object.hpp>
|
#include <graphene/chain/sidechain_address_object.hpp>
|
||||||
|
|
||||||
#include <fc/smart_ref_impl.hpp>
|
#include <fc/smart_ref_impl.hpp>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue