WIP: User sidechain address mappings

This commit is contained in:
Srdjan Obucina 2019-12-09 00:25:34 +01:00
parent 4935246caf
commit 0ecffdd4a8
22 changed files with 401 additions and 27 deletions

View file

@ -14,7 +14,7 @@ add_library( graphene_app
# need to link graphene_debug_witness because plugins aren't sufficiently isolated #246 # need to link graphene_debug_witness because plugins aren't sufficiently isolated #246
#target_link_libraries( graphene_app graphene_market_history graphene_account_history graphene_chain fc graphene_db graphene_net graphene_utilities graphene_debug_witness ) #target_link_libraries( graphene_app graphene_market_history graphene_account_history graphene_chain fc graphene_db graphene_net graphene_utilities graphene_debug_witness )
target_link_libraries( graphene_app graphene_market_history graphene_account_history graphene_accounts_list graphene_affiliate_stats graphene_chain fc graphene_db graphene_net graphene_time graphene_utilities graphene_debug_witness graphene_bookie ) target_link_libraries( graphene_app graphene_market_history graphene_account_history graphene_accounts_list graphene_affiliate_stats graphene_chain fc graphene_db graphene_net graphene_time graphene_utilities graphene_debug_witness graphene_bookie peerplays_sidechain )
target_include_directories( graphene_app target_include_directories( graphene_app
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include"
"${CMAKE_CURRENT_SOURCE_DIR}/../egenesis/include" ) "${CMAKE_CURRENT_SOURCE_DIR}/../egenesis/include" )

View file

@ -443,6 +443,11 @@ namespace graphene { namespace app {
assert( aobj != nullptr ); assert( aobj != nullptr );
accounts.insert( aobj->son_account ); accounts.insert( aobj->son_account );
break; break;
} case sidechain_address_object_type:{
const auto& aobj = dynamic_cast<const sidechain_address_object*>(obj);
assert( aobj != nullptr );
accounts.insert( aobj->sidechain_address_account );
break;
} }
case sport_object_type: case sport_object_type:
case event_group_object_type: case event_group_object_type:

View file

@ -152,6 +152,12 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
map<string, son_id_type> lookup_son_accounts(const string& lower_bound_name, uint32_t limit)const; map<string, son_id_type> lookup_son_accounts(const string& lower_bound_name, uint32_t limit)const;
uint64_t get_son_count()const; uint64_t get_son_count()const;
// Sidechain addresses
vector<optional<sidechain_address_object>> get_sidechain_addresses(const vector<sidechain_address_id_type>& sidechain_address_ids)const;
vector<optional<sidechain_address_object>> get_sidechain_addresses_by_account(account_id_type account)const;
fc::optional<sidechain_address_object> get_sidechain_addresses_by_account_and_sidechain(account_id_type account, peerplays_sidechain::sidechain_type sidechain)const;
uint64_t get_sidechain_addresses_count()const;
// Votes // Votes
vector<variant> lookup_vote_ids( const vector<vote_id_type>& votes )const; vector<variant> lookup_vote_ids( const vector<vote_id_type>& votes )const;
@ -1763,6 +1769,61 @@ uint64_t database_api_impl::get_son_count()const
return _db.get_index_type<son_index>().indices().size(); return _db.get_index_type<son_index>().indices().size();
} }
//////////////////////////////////////////////////////////////////////
// //
// Sidechain Accounts //
// //
//////////////////////////////////////////////////////////////////////
vector<optional<sidechain_address_object>> database_api::get_sidechain_addresses(const vector<sidechain_address_id_type>& sidechain_address_ids)const
{
return my->get_sidechain_addresses( sidechain_address_ids );
}
vector<optional<sidechain_address_object>> database_api_impl::get_sidechain_addresses(const vector<sidechain_address_id_type>& sidechain_address_ids)const
{
vector<optional<sidechain_address_object>> result; result.reserve(sidechain_address_ids.size());
std::transform(sidechain_address_ids.begin(), sidechain_address_ids.end(), std::back_inserter(result),
[this](sidechain_address_id_type id) -> optional<sidechain_address_object> {
if(auto o = _db.find(id))
return *o;
return {};
});
return result;
}
vector<optional<sidechain_address_object>> database_api::get_sidechain_addresses_by_account(account_id_type account)const
{
return my->get_sidechain_addresses_by_account( account );
}
vector<optional<sidechain_address_object>> database_api_impl::get_sidechain_addresses_by_account(account_id_type account)const
{
vector<optional<sidechain_address_object>> result;
return result;
}
fc::optional<sidechain_address_object> database_api::get_sidechain_addresses_by_account_and_sidechain(account_id_type account, peerplays_sidechain::sidechain_type sidechain)const
{
return my->get_sidechain_addresses_by_account_and_sidechain( account, sidechain );
}
fc::optional<sidechain_address_object> database_api_impl::get_sidechain_addresses_by_account_and_sidechain(account_id_type account, peerplays_sidechain::sidechain_type sidechain)const
{
sidechain_address_object result;
return result;
}
uint64_t database_api::get_sidechain_addresses_count()const
{
return my->get_sidechain_addresses_count();
}
uint64_t database_api_impl::get_sidechain_addresses_count()const
{
return 0;
}
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// // // //
// Votes // // Votes //

View file

@ -307,6 +307,15 @@ struct get_impacted_account_visitor
void operator()( const son_delete_operation& op ){ void operator()( const son_delete_operation& op ){
_impacted.insert( op.owner_account ); _impacted.insert( op.owner_account );
} }
void operator()( const sidechain_address_add_operation& op ){
_impacted.insert( op.sidechain_address_account );
}
void operator()( const sidechain_address_update_operation& op ){
_impacted.insert( op.sidechain_address_account );
}
void operator()( const sidechain_address_delete_operation& op ){
_impacted.insert( op.sidechain_address_account );
}
}; };
void operation_get_impacted_accounts( const operation& op, flat_set<account_id_type>& result ) void operation_get_impacted_accounts( const operation& op, flat_set<account_id_type>& result )

View file

@ -44,6 +44,7 @@
#include <graphene/chain/betting_market_object.hpp> #include <graphene/chain/betting_market_object.hpp>
#include <graphene/chain/global_betting_statistics_object.hpp> #include <graphene/chain/global_betting_statistics_object.hpp>
#include <graphene/chain/son_object.hpp> #include <graphene/chain/son_object.hpp>
#include <graphene/chain/sidechain_address_object.hpp>
#include <graphene/chain/worker_object.hpp> #include <graphene/chain/worker_object.hpp>
#include <graphene/chain/witness_object.hpp> #include <graphene/chain/witness_object.hpp>
@ -602,6 +603,39 @@ class database_api
*/ */
uint64_t get_son_count()const; uint64_t get_son_count()const;
/////////////////////////
// Sidechain Addresses //
/////////////////////////
/**
* @brief Get a list of sidechain addresses
* @param sidechain_address_ids IDs of the sidechain accounts to retrieve
* @return The sidechain accounts corresponding to the provided IDs
*
* This function has semantics identical to @ref get_objects
*/
vector<optional<sidechain_address_object>> get_sidechain_addresses(const vector<sidechain_address_id_type>& sidechain_address_ids)const;
/**
* @brief Get the sidechain addresses for a given account
* @param account The ID of the account whose sidechain addresses should be retrieved
* @return The sidechain addresses objects, or null if the account does not have a sidechain addresses
*/
vector<optional<sidechain_address_object>> get_sidechain_addresses_by_account(account_id_type account)const;
/**
* @brief Get the sidechain addresses for a given account and sidechain
* @param account The ID of the account whose sidechain addresses should be retrieved
* @param sidechain Sidechain for which address should be retrieved
* @return The sidechain addresses objects, or null if the account does not have a sidechain addresses for a given network
*/
fc::optional<sidechain_address_object> get_sidechain_addresses_by_account_and_sidechain(account_id_type account, peerplays_sidechain::sidechain_type sidechain)const;
/**
* @brief Get the total number of sidechain addresses registered with the blockchain
*/
uint64_t get_sidechain_addresses_count()const;
/// WORKERS /// WORKERS
/** /**

View file

@ -116,13 +116,15 @@ add_library( graphene_chain
son_evaluator.cpp son_evaluator.cpp
son_object.cpp son_object.cpp
sidechain_address_evaluator.cpp
${HEADERS} ${HEADERS}
${PROTOCOL_HEADERS} ${PROTOCOL_HEADERS}
"${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp" "${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp"
) )
add_dependencies( graphene_chain build_hardfork_hpp ) add_dependencies( graphene_chain build_hardfork_hpp )
target_link_libraries( graphene_chain fc graphene_db ) target_link_libraries( graphene_chain fc graphene_db peerplays_sidechain )
target_include_directories( graphene_chain target_include_directories( graphene_chain
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include" ) PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include" )

View file

@ -56,6 +56,7 @@
#include <graphene/chain/global_betting_statistics_object.hpp> #include <graphene/chain/global_betting_statistics_object.hpp>
#include <graphene/chain/son_object.hpp> #include <graphene/chain/son_object.hpp>
#include <graphene/chain/son_proposal_object.hpp> #include <graphene/chain/son_proposal_object.hpp>
#include <graphene/chain/sidechain_address_object.hpp>
#include <graphene/chain/account_evaluator.hpp> #include <graphene/chain/account_evaluator.hpp>
#include <graphene/chain/asset_evaluator.hpp> #include <graphene/chain/asset_evaluator.hpp>
@ -78,6 +79,7 @@
#include <graphene/chain/betting_market_evaluator.hpp> #include <graphene/chain/betting_market_evaluator.hpp>
#include <graphene/chain/tournament_evaluator.hpp> #include <graphene/chain/tournament_evaluator.hpp>
#include <graphene/chain/son_evaluator.hpp> #include <graphene/chain/son_evaluator.hpp>
#include <graphene/chain/sidechain_address_evaluator.hpp>
#include <graphene/chain/protocol/fee_schedule.hpp> #include <graphene/chain/protocol/fee_schedule.hpp>
@ -247,6 +249,9 @@ void database::initialize_evaluators()
register_evaluator<create_son_evaluator>(); register_evaluator<create_son_evaluator>();
register_evaluator<update_son_evaluator>(); register_evaluator<update_son_evaluator>();
register_evaluator<delete_son_evaluator>(); register_evaluator<delete_son_evaluator>();
register_evaluator<add_sidechain_address_evaluator>();
register_evaluator<update_sidechain_address_evaluator>();
register_evaluator<delete_sidechain_address_evaluator>();
} }
void database::initialize_indexes() void database::initialize_indexes()
@ -291,6 +296,8 @@ void database::initialize_indexes()
add_index< primary_index<game_index> >(); add_index< primary_index<game_index> >();
add_index< primary_index<son_proposal_index> >(); add_index< primary_index<son_proposal_index> >();
add_index< primary_index<sidechain_address_index> >();
//Implementation object indexes //Implementation object indexes
add_index< primary_index<transaction_index > >(); add_index< primary_index<transaction_index > >();

View file

@ -294,6 +294,15 @@ struct get_impacted_account_visitor
void operator()( const son_delete_operation& op ) { void operator()( const son_delete_operation& op ) {
_impacted.insert( op.owner_account ); _impacted.insert( op.owner_account );
} }
void operator()( const sidechain_address_add_operation& op ) {
_impacted.insert( op.sidechain_address_account );
}
void operator()( const sidechain_address_update_operation& op ) {
_impacted.insert( op.sidechain_address_account );
}
void operator()( const sidechain_address_delete_operation& op ) {
_impacted.insert( op.sidechain_address_account );
}
}; };
void operation_get_impacted_accounts( const operation& op, flat_set<account_id_type>& result ) void operation_get_impacted_accounts( const operation& op, flat_set<account_id_type>& result )
@ -387,6 +396,11 @@ void get_relevant_accounts( const object* obj, flat_set<account_id_type>& accoun
assert( aobj != nullptr ); assert( aobj != nullptr );
accounts.insert( aobj->son_account ); accounts.insert( aobj->son_account );
break; break;
/*} case sidechain_address_object_type:{
const auto& aobj = dynamic_cast<const sidechain_address_object*>(obj);
assert( aobj != nullptr );
accounts.insert( aobj->sidechain_address_account );
break;*/
} }
} }
} }

View file

@ -46,6 +46,7 @@
#include <graphene/chain/protocol/betting_market.hpp> #include <graphene/chain/protocol/betting_market.hpp>
#include <graphene/chain/protocol/tournament.hpp> #include <graphene/chain/protocol/tournament.hpp>
#include <graphene/chain/protocol/son.hpp> #include <graphene/chain/protocol/son.hpp>
#include <graphene/chain/protocol/sidechain_address.hpp>
namespace graphene { namespace chain { namespace graphene { namespace chain {
@ -139,7 +140,10 @@ namespace graphene { namespace chain {
sweeps_vesting_claim_operation, sweeps_vesting_claim_operation,
son_create_operation, son_create_operation,
son_update_operation, son_update_operation,
son_delete_operation son_delete_operation,
sidechain_address_add_operation,
sidechain_address_update_operation,
sidechain_address_delete_operation
> operation; > operation;
/// @} // operations group /// @} // operations group

View file

@ -0,0 +1,63 @@
#pragma once
#include <graphene/chain/protocol/base.hpp>
#include <graphene/peerplays_sidechain/defs.hpp>
namespace graphene { namespace chain {
struct sidechain_address_add_operation : public base_operation
{
struct fee_parameters_type { uint64_t fee = 0; };
asset fee;
account_id_type sidechain_address_account;
graphene::peerplays_sidechain::sidechain_type sidechain;
string address;
string private_key;
string public_key;
account_id_type fee_payer()const { return sidechain_address_account; }
share_type calculate_fee(const fee_parameters_type& k)const { return 0; }
};
struct sidechain_address_update_operation : public base_operation
{
struct fee_parameters_type { uint64_t fee = 0; };
asset fee;
sidechain_address_id_type sidechain_address_id;
account_id_type sidechain_address_account;
graphene::peerplays_sidechain::sidechain_type sidechain;
optional<string> address;
optional<string> private_key;
optional<string> public_key;
account_id_type fee_payer()const { return sidechain_address_account; }
share_type calculate_fee(const fee_parameters_type& k)const { return 0; }
};
struct sidechain_address_delete_operation : public base_operation
{
struct fee_parameters_type { uint64_t fee = 0; };
asset fee;
sidechain_address_id_type sidechain_address_id;
account_id_type sidechain_address_account;
graphene::peerplays_sidechain::sidechain_type sidechain;
account_id_type fee_payer()const { return sidechain_address_account; }
share_type calculate_fee(const fee_parameters_type& k)const { return 0; }
};
} } // namespace graphene::chain
FC_REFLECT(graphene::chain::sidechain_address_add_operation::fee_parameters_type, (fee) )
FC_REFLECT(graphene::chain::sidechain_address_add_operation, (fee)(sidechain_address_account)(sidechain)
(address)(private_key)(public_key) )
FC_REFLECT(graphene::chain::sidechain_address_update_operation::fee_parameters_type, (fee) )
//FC_REFLECT(graphene::chain::sidechain_address_update_operation, (fee)(sidechain_address_id)(sidechain_address_account)/*(sidechain)*/
// (address)(private_key)(public_key) )
FC_REFLECT(graphene::chain::sidechain_address_delete_operation::fee_parameters_type, (fee) )
//FC_REFLECT(graphene::chain::sidechain_address_delete_operation, (fee)(sidechain_address_id)(sidechain_address_account)/*(sidechain)*/ )

View file

@ -147,6 +147,7 @@ namespace graphene { namespace chain {
bet_object_type, bet_object_type,
son_object_type, son_object_type,
son_proposal_object_type, son_proposal_object_type,
sidechain_address_object_type,
OBJECT_TYPE_COUNT ///< Sentry value which contains the number of different object types OBJECT_TYPE_COUNT ///< Sentry value which contains the number of different object types
}; };
@ -209,6 +210,7 @@ namespace graphene { namespace chain {
class bet_object; class bet_object;
class son_object; class son_object;
class son_proposal_object; class son_proposal_object;
class sidechain_address_object;
typedef object_id< protocol_ids, account_object_type, account_object> account_id_type; typedef object_id< protocol_ids, account_object_type, account_object> account_id_type;
typedef object_id< protocol_ids, asset_object_type, asset_object> asset_id_type; typedef object_id< protocol_ids, asset_object_type, asset_object> asset_id_type;
@ -237,6 +239,7 @@ namespace graphene { namespace chain {
typedef object_id< protocol_ids, bet_object_type, bet_object> bet_id_type; typedef object_id< protocol_ids, bet_object_type, bet_object> bet_id_type;
typedef object_id< protocol_ids, son_object_type, son_object> son_id_type; typedef object_id< protocol_ids, son_object_type, son_object> son_id_type;
typedef object_id< protocol_ids, son_proposal_object_type, son_proposal_object> son_proposal_id_type; typedef object_id< protocol_ids, son_proposal_object_type, son_proposal_object> son_proposal_id_type;
typedef object_id< protocol_ids, sidechain_address_object_type, sidechain_address_object> sidechain_address_id_type;
// implementation types // implementation types
class global_property_object; class global_property_object;
@ -421,6 +424,7 @@ FC_REFLECT_ENUM( graphene::chain::object_type,
(bet_object_type) (bet_object_type)
(son_object_type) (son_object_type)
(son_proposal_object_type) (son_proposal_object_type)
(sidechain_address_object_type)
(OBJECT_TYPE_COUNT) (OBJECT_TYPE_COUNT)
) )
FC_REFLECT_ENUM( graphene::chain::impl_object_type, FC_REFLECT_ENUM( graphene::chain::impl_object_type,
@ -493,6 +497,7 @@ FC_REFLECT_TYPENAME( graphene::chain::global_betting_statistics_id_type )
FC_REFLECT_TYPENAME( graphene::chain::tournament_details_id_type ) FC_REFLECT_TYPENAME( graphene::chain::tournament_details_id_type )
FC_REFLECT_TYPENAME( graphene::chain::son_id_type ) FC_REFLECT_TYPENAME( graphene::chain::son_id_type )
FC_REFLECT_TYPENAME( graphene::chain::son_proposal_id_type ) FC_REFLECT_TYPENAME( graphene::chain::son_proposal_id_type )
FC_REFLECT_TYPENAME( graphene::chain::sidechain_address_id_type )
FC_REFLECT( graphene::chain::void_t, ) FC_REFLECT( graphene::chain::void_t, )

View file

@ -0,0 +1,34 @@
#pragma once
#include <graphene/chain/evaluator.hpp>
#include <graphene/chain/protocol/sidechain_address.hpp>
namespace graphene { namespace chain {
class add_sidechain_address_evaluator : public evaluator<add_sidechain_address_evaluator>
{
public:
typedef sidechain_address_add_operation operation_type;
void_result do_evaluate(const sidechain_address_add_operation& o);
object_id_type do_apply(const sidechain_address_add_operation& o);
};
class update_sidechain_address_evaluator : public evaluator<update_sidechain_address_evaluator>
{
public:
typedef sidechain_address_update_operation operation_type;
void_result do_evaluate(const sidechain_address_update_operation& o);
object_id_type do_apply(const sidechain_address_update_operation& o);
};
class delete_sidechain_address_evaluator : public evaluator<delete_sidechain_address_evaluator>
{
public:
typedef sidechain_address_delete_operation operation_type;
void_result do_evaluate(const sidechain_address_delete_operation& o);
void_result do_apply(const sidechain_address_delete_operation& o);
};
} } // namespace graphene::chain

View file

@ -0,0 +1,63 @@
#pragma once
#include <graphene/chain/protocol/types.hpp>
#include <graphene/db/object.hpp>
#include <graphene/db/generic_index.hpp>
#include <graphene/peerplays_sidechain/defs.hpp>
namespace graphene { namespace chain {
using namespace graphene::db;
/**
* @class sidechain_address_object
* @brief tracks information about a sidechain addresses for user accounts.
* @ingroup object
*/
class sidechain_address_object : public abstract_object<sidechain_address_object>
{
public:
static const uint8_t space_id = protocol_ids;
static const uint8_t type_id = sidechain_address_object_type;
account_id_type sidechain_address_account;
graphene::peerplays_sidechain::sidechain_type sidechain;
string address;
string private_key;
string public_key;
sidechain_address_object() :
sidechain(graphene::peerplays_sidechain::sidechain_type::bitcoin),
address(""),
private_key(""),
public_key("") {}
};
struct by_account;
struct by_network;
struct by_account_and_network;
using sidechain_address_multi_index_type = multi_index_container<
sidechain_address_object,
indexed_by<
ordered_unique< tag<by_id>,
member<object, object_id_type, &object::id>
>,
ordered_unique< tag<by_account>,
member<sidechain_address_object, account_id_type, &sidechain_address_object::sidechain_address_account>
>,
ordered_unique< tag<by_network>,
member<sidechain_address_object, const peerplays_sidechain::sidechain_type, &sidechain_address_object::sidechain>
>,
ordered_unique< tag<by_account_and_network>,
composite_key<sidechain_address_object,
member<sidechain_address_object, account_id_type, &sidechain_address_object::sidechain_address_account>,
member<sidechain_address_object, peerplays_sidechain::sidechain_type, &sidechain_address_object::sidechain>
>
>
>
>;
using sidechain_address_index = generic_index<sidechain_address_object, sidechain_address_multi_index_type>;
} } // graphene::chain
FC_REFLECT_DERIVED( graphene::chain::sidechain_address_object, (graphene::db::object),
(sidechain_address_account)/*(sidechain)*/(address)(private_key)(public_key) )

View file

@ -0,0 +1,70 @@
#include <graphene/chain/sidechain_address_evaluator.hpp>
#include <graphene/chain/database.hpp>
#include <graphene/chain/sidechain_address_object.hpp>
#include <graphene/chain/hardfork.hpp>
namespace graphene { namespace chain {
void_result add_sidechain_address_evaluator::do_evaluate(const sidechain_address_add_operation& op)
{ try{
const auto& idx = db().get_index_type<sidechain_address_index>().indices().get<by_account_and_network>();
FC_ASSERT( idx.find(boost::make_tuple(op.sidechain_address_account, op.sidechain)) == idx.end(), "Duplicated item" );
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }
object_id_type add_sidechain_address_evaluator::do_apply(const sidechain_address_add_operation& op)
{ try {
const auto& new_sidechain_address_object = db().create<sidechain_address_object>( [&]( sidechain_address_object& obj ){
obj.sidechain_address_account = op.sidechain_address_account;
obj.sidechain = op.sidechain;
obj.address = op.address;
obj.private_key = op.private_key;
obj.public_key = op.public_key;
});
return new_sidechain_address_object.id;
} FC_CAPTURE_AND_RETHROW( (op) ) }
void_result update_sidechain_address_evaluator::do_evaluate(const sidechain_address_update_operation& op)
{ try {
FC_ASSERT(db().get(op.sidechain_address_id).sidechain_address_account == op.sidechain_address_account);
const auto& idx = db().get_index_type<sidechain_address_index>().indices().get<by_id>();
FC_ASSERT( idx.find(op.sidechain_address_id) != idx.end() );
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }
object_id_type update_sidechain_address_evaluator::do_apply(const sidechain_address_update_operation& op)
{ try {
const auto& idx = db().get_index_type<sidechain_address_index>().indices().get<by_id>();
auto itr = idx.find(op.sidechain_address_id);
if(itr != idx.end())
{
db().modify(*itr, [&op](sidechain_address_object &sao) {
if(op.address.valid()) sao.address = *op.address;
if(op.private_key.valid()) sao.private_key = *op.private_key;
if(op.public_key.valid()) sao.public_key = *op.public_key;
});
}
return op.sidechain_address_id;
} FC_CAPTURE_AND_RETHROW( (op) ) }
void_result delete_sidechain_address_evaluator::do_evaluate(const sidechain_address_delete_operation& op)
{ try {
FC_ASSERT(db().get(op.sidechain_address_id).sidechain_address_account == op.sidechain_address_account);
const auto& idx = db().get_index_type<sidechain_address_index>().indices().get<by_id>();
FC_ASSERT( idx.find(op.sidechain_address_id) != idx.end() );
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }
void_result delete_sidechain_address_evaluator::do_apply(const sidechain_address_delete_operation& op)
{ try {
const auto& idx = db().get_index_type<sidechain_address_index>().indices().get<by_id>();
auto sidechain_address = idx.find(op.sidechain_address_id);
if(sidechain_address != idx.end()) {
db().remove(*sidechain_address);
}
return void_result();
} FC_CAPTURE_AND_RETHROW( (op) ) }
} } // namespace graphene::chain

View file

@ -8,9 +8,10 @@
namespace graphene { namespace peerplays_sidechain { namespace graphene { namespace peerplays_sidechain {
enum network { enum class sidechain_type {
bitcoin, bitcoin,
//ethereum //ethereum,
//eos
}; };
using bytes = std::vector<char>; using bytes = std::vector<char>;
@ -59,7 +60,7 @@ struct info_for_vin
}; };
struct sidechain_event_data { struct sidechain_event_data {
network sidechain; sidechain_type sidechain;
std::string transaction_id; std::string transaction_id;
std::string from; std::string from;
std::string to; std::string to;

View file

@ -5,6 +5,8 @@
#include <graphene/chain/account_object.hpp> #include <graphene/chain/account_object.hpp>
#include <graphene/chain/database.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;

View file

@ -16,7 +16,7 @@ public:
std::vector<std::string> get_user_sidechain_address_mapping(); std::vector<std::string> get_user_sidechain_address_mapping();
protected: protected:
graphene::peerplays_sidechain::network network; graphene::peerplays_sidechain::sidechain_type sidechain;
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;

View file

@ -14,7 +14,7 @@ public:
sidechain_net_manager(); sidechain_net_manager();
virtual ~sidechain_net_manager(); virtual ~sidechain_net_manager();
bool create_handler(peerplays_sidechain::network network, const boost::program_options::variables_map& options); bool create_handler(peerplays_sidechain::sidechain_type sidechain, const boost::program_options::variables_map& options);
private: private:
std::vector<std::unique_ptr<sidechain_net_handler>> net_handlers; std::vector<std::unique_ptr<sidechain_net_handler>> net_handlers;

View file

@ -80,7 +80,7 @@ void peerplays_sidechain_plugin::plugin_initialize(const boost::program_options:
&& 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" ) )
{ {
my->_net_manager.create_handler(network::bitcoin, options); my->_net_manager.create_handler(sidechain_type::bitcoin, options);
} else { } else {
wlog("Haven't set up bitcoin sidechain parameters"); wlog("Haven't set up bitcoin sidechain parameters");
} }

View file

@ -11,8 +11,8 @@ sidechain_net_handler::~sidechain_net_handler() {
std::vector<std::string> sidechain_net_handler::get_user_sidechain_address_mapping() { std::vector<std::string> sidechain_net_handler::get_user_sidechain_address_mapping() {
std::vector<std::string> result; std::vector<std::string> result;
switch (network) { switch (sidechain) {
case network::bitcoin: case sidechain_type::bitcoin:
result.push_back("2N5aFW5WFaYZLuJWx9RGziHBdEMj9Zf8s3J"); result.push_back("2N5aFW5WFaYZLuJWx9RGziHBdEMj9Zf8s3J");
result.push_back("2MxAnE469fhhdvUqUB7daU997VSearb2mn7"); result.push_back("2MxAnE469fhhdvUqUB7daU997VSearb2mn7");
result.push_back("2NAYptFvTU8vJ1pC7CxvVA9R7D3NdBJHpwL"); result.push_back("2NAYptFvTU8vJ1pC7CxvVA9R7D3NdBJHpwL");

View file

@ -188,7 +188,7 @@ void zmq_listener::handle_zmq() {
sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(const boost::program_options::variables_map& options) : sidechain_net_handler_bitcoin::sidechain_net_handler_bitcoin(const boost::program_options::variables_map& options) :
sidechain_net_handler(options) { sidechain_net_handler(options) {
network = peerplays_sidechain::network::bitcoin; sidechain = sidechain_type::bitcoin;
ip = options.at("bitcoin-node-ip").as<std::string>(); ip = options.at("bitcoin-node-ip").as<std::string>();
zmq_port = options.at("bitcoin-node-zmq-port").as<uint32_t>(); zmq_port = options.at("bitcoin-node-zmq-port").as<uint32_t>();

View file

@ -13,13 +13,13 @@ sidechain_net_manager::~sidechain_net_manager() {
ilog(__FUNCTION__); ilog(__FUNCTION__);
} }
bool sidechain_net_manager::create_handler(peerplays_sidechain::network network, const boost::program_options::variables_map& options) { bool 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; bool ret_val = false;
switch (network) { switch (sidechain) {
case network::bitcoin: { case sidechain_type::bitcoin: {
std::unique_ptr<sidechain_net_handler> h = std::unique_ptr<sidechain_net_handler>(new sidechain_net_handler_bitcoin(options)); std::unique_ptr<sidechain_net_handler> h = std::unique_ptr<sidechain_net_handler>(new sidechain_net_handler_bitcoin(options));
net_handlers.push_back(std::move(h)); net_handlers.push_back(std::move(h));
ret_val = true; ret_val = true;