WIP: User sidechain address mappings
This commit is contained in:
parent
4935246caf
commit
0ecffdd4a8
22 changed files with 401 additions and 27 deletions
|
|
@ -14,7 +14,7 @@ add_library( graphene_app
|
|||
|
||||
# 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_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
|
||||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include"
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../egenesis/include" )
|
||||
|
|
|
|||
|
|
@ -443,6 +443,11 @@ namespace graphene { namespace app {
|
|||
assert( aobj != nullptr );
|
||||
accounts.insert( aobj->son_account );
|
||||
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 event_group_object_type:
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
|
|||
uint64_t get_asset_count()const;
|
||||
|
||||
// Peerplays
|
||||
vector<sport_object> list_sports() const;
|
||||
vector<sport_object> list_sports() const;
|
||||
vector<event_group_object> list_event_groups(sport_id_type sport_id) const;
|
||||
vector<event_object> list_events_in_group(event_group_id_type event_group_id) const;
|
||||
vector<betting_market_group_object> list_betting_market_groups(event_id_type) const;
|
||||
|
|
@ -115,14 +115,14 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
|
|||
vector<asset_object> get_lotteries( asset_id_type stop = asset_id_type(),
|
||||
unsigned limit = 100,
|
||||
asset_id_type start = asset_id_type() )const;
|
||||
vector<asset_object> get_account_lotteries( account_id_type issuer,
|
||||
vector<asset_object> get_account_lotteries( account_id_type issuer,
|
||||
asset_id_type stop,
|
||||
unsigned limit,
|
||||
asset_id_type start )const;
|
||||
asset get_lottery_balance( asset_id_type lottery_id )const;
|
||||
sweeps_vesting_balance_object get_sweeps_vesting_balance_object( account_id_type account )const;
|
||||
asset get_sweeps_vesting_balance_available_for_claim( account_id_type account )const;
|
||||
|
||||
|
||||
// Markets / feeds
|
||||
vector<limit_order_object> get_limit_orders(asset_id_type a, asset_id_type b, uint32_t limit)const;
|
||||
vector<call_order_object> get_call_orders(asset_id_type a, uint32_t limit)const;
|
||||
|
|
@ -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;
|
||||
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
|
||||
vector<variant> lookup_vote_ids( const vector<vote_id_type>& votes )const;
|
||||
|
||||
|
|
@ -528,11 +534,11 @@ vector<vector<account_id_type>> database_api::get_key_references( vector<public_
|
|||
vector<vector<account_id_type>> database_api_impl::get_key_references( vector<public_key_type> keys )const
|
||||
{
|
||||
wdump( (keys) );
|
||||
|
||||
|
||||
const auto& idx = _db.get_index_type<account_index>();
|
||||
const auto& aidx = dynamic_cast<const base_primary_index&>(idx);
|
||||
const auto& refs = aidx.get_secondary_index<graphene::chain::account_member_index>();
|
||||
|
||||
|
||||
vector< vector<account_id_type> > final_result;
|
||||
final_result.reserve(keys.size());
|
||||
|
||||
|
|
@ -648,7 +654,7 @@ std::map<std::string, full_account> database_api_impl::get_full_accounts( const
|
|||
const auto& proposal_idx = _db.get_index_type<proposal_index>();
|
||||
const auto& pidx = dynamic_cast<const base_primary_index&>(proposal_idx);
|
||||
const auto& proposals_by_account = pidx.get_secondary_index<graphene::chain::required_approval_index>();
|
||||
|
||||
|
||||
std::map<std::string, full_account> results;
|
||||
|
||||
for (const std::string& account_name_or_id : names_or_ids)
|
||||
|
|
@ -738,7 +744,7 @@ std::map<std::string, full_account> database_api_impl::get_full_accounts( const
|
|||
acnt.withdraws.emplace_back(withdraw);
|
||||
});
|
||||
|
||||
auto pending_payouts_range =
|
||||
auto pending_payouts_range =
|
||||
_db.get_index_type<pending_dividend_payout_balance_for_holder_object_index>().indices().get<by_account_dividend_payout>().equal_range(boost::make_tuple(account->id));
|
||||
|
||||
std::copy(pending_payouts_range.first, pending_payouts_range.second, std::back_inserter(acnt.pending_dividend_payments));
|
||||
|
|
@ -1058,7 +1064,7 @@ vector<asset_object> database_api_impl::get_lotteries( asset_id_type stop,
|
|||
|
||||
return result;
|
||||
}
|
||||
vector<asset_object> database_api::get_account_lotteries( account_id_type issuer,
|
||||
vector<asset_object> database_api::get_account_lotteries( account_id_type issuer,
|
||||
asset_id_type stop,
|
||||
unsigned limit,
|
||||
asset_id_type start )const
|
||||
|
|
@ -1066,7 +1072,7 @@ vector<asset_object> database_api::get_account_lotteries( account_id_type issuer
|
|||
return my->get_account_lotteries( issuer, stop, limit, start );
|
||||
}
|
||||
|
||||
vector<asset_object> database_api_impl::get_account_lotteries( account_id_type issuer,
|
||||
vector<asset_object> database_api_impl::get_account_lotteries( account_id_type issuer,
|
||||
asset_id_type stop,
|
||||
unsigned limit,
|
||||
asset_id_type start )const
|
||||
|
|
@ -1763,6 +1769,61 @@ uint64_t database_api_impl::get_son_count()const
|
|||
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 //
|
||||
|
|
@ -2164,7 +2225,7 @@ vector<tournament_object> database_api::get_tournaments(tournament_id_type stop,
|
|||
|
||||
vector<tournament_object> database_api_impl::get_tournaments(tournament_id_type stop,
|
||||
unsigned limit,
|
||||
tournament_id_type start)
|
||||
tournament_id_type start)
|
||||
{
|
||||
vector<tournament_object> result;
|
||||
const auto& tournament_idx = _db.get_index_type<tournament_index>().indices().get<by_id>();
|
||||
|
|
@ -2191,7 +2252,7 @@ vector<tournament_object> database_api_impl::get_tournaments_by_state(tournament
|
|||
unsigned limit,
|
||||
tournament_id_type start,
|
||||
tournament_state state)
|
||||
{
|
||||
{
|
||||
vector<tournament_object> result;
|
||||
const auto& tournament_idx = _db.get_index_type<tournament_index>().indices().get<by_id>();
|
||||
for (auto elem: tournament_idx) {
|
||||
|
|
@ -2320,7 +2381,7 @@ void database_api_impl::handle_object_changed(bool force_notify, bool full_objec
|
|||
/// if a connection hangs then this could get backed up and result in
|
||||
/// a failure to exit cleanly.
|
||||
//fc::async([capture_this,this,updates,market_broadcast_queue](){
|
||||
//if( _subscribe_callback )
|
||||
//if( _subscribe_callback )
|
||||
// _subscribe_callback( updates );
|
||||
|
||||
for(auto id : ids)
|
||||
|
|
|
|||
|
|
@ -307,6 +307,15 @@ struct get_impacted_account_visitor
|
|||
void operator()( const son_delete_operation& op ){
|
||||
_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 )
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@
|
|||
#include <graphene/chain/betting_market_object.hpp>
|
||||
#include <graphene/chain/global_betting_statistics_object.hpp>
|
||||
#include <graphene/chain/son_object.hpp>
|
||||
#include <graphene/chain/sidechain_address_object.hpp>
|
||||
|
||||
#include <graphene/chain/worker_object.hpp>
|
||||
#include <graphene/chain/witness_object.hpp>
|
||||
|
|
@ -602,6 +603,39 @@ class database_api
|
|||
*/
|
||||
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
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -116,13 +116,15 @@ add_library( graphene_chain
|
|||
son_evaluator.cpp
|
||||
son_object.cpp
|
||||
|
||||
sidechain_address_evaluator.cpp
|
||||
|
||||
${HEADERS}
|
||||
${PROTOCOL_HEADERS}
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/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
|
||||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include" )
|
||||
|
||||
|
|
|
|||
|
|
@ -56,6 +56,7 @@
|
|||
#include <graphene/chain/global_betting_statistics_object.hpp>
|
||||
#include <graphene/chain/son_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/asset_evaluator.hpp>
|
||||
|
|
@ -78,6 +79,7 @@
|
|||
#include <graphene/chain/betting_market_evaluator.hpp>
|
||||
#include <graphene/chain/tournament_evaluator.hpp>
|
||||
#include <graphene/chain/son_evaluator.hpp>
|
||||
#include <graphene/chain/sidechain_address_evaluator.hpp>
|
||||
|
||||
#include <graphene/chain/protocol/fee_schedule.hpp>
|
||||
|
||||
|
|
@ -247,6 +249,9 @@ void database::initialize_evaluators()
|
|||
register_evaluator<create_son_evaluator>();
|
||||
register_evaluator<update_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()
|
||||
|
|
@ -291,6 +296,8 @@ void database::initialize_indexes()
|
|||
add_index< primary_index<game_index> >();
|
||||
add_index< primary_index<son_proposal_index> >();
|
||||
|
||||
add_index< primary_index<sidechain_address_index> >();
|
||||
|
||||
//Implementation object indexes
|
||||
add_index< primary_index<transaction_index > >();
|
||||
|
||||
|
|
|
|||
|
|
@ -294,6 +294,15 @@ struct get_impacted_account_visitor
|
|||
void operator()( const son_delete_operation& op ) {
|
||||
_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 )
|
||||
|
|
@ -387,6 +396,11 @@ void get_relevant_accounts( const object* obj, flat_set<account_id_type>& accoun
|
|||
assert( aobj != nullptr );
|
||||
accounts.insert( aobj->son_account );
|
||||
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;*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,7 @@
|
|||
#include <graphene/chain/protocol/betting_market.hpp>
|
||||
#include <graphene/chain/protocol/tournament.hpp>
|
||||
#include <graphene/chain/protocol/son.hpp>
|
||||
#include <graphene/chain/protocol/sidechain_address.hpp>
|
||||
|
||||
namespace graphene { namespace chain {
|
||||
|
||||
|
|
@ -139,7 +140,10 @@ namespace graphene { namespace chain {
|
|||
sweeps_vesting_claim_operation,
|
||||
son_create_operation,
|
||||
son_update_operation,
|
||||
son_delete_operation
|
||||
son_delete_operation,
|
||||
sidechain_address_add_operation,
|
||||
sidechain_address_update_operation,
|
||||
sidechain_address_delete_operation
|
||||
> operation;
|
||||
|
||||
/// @} // operations group
|
||||
|
|
|
|||
|
|
@ -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)*/ )
|
||||
|
|
@ -147,6 +147,7 @@ namespace graphene { namespace chain {
|
|||
bet_object_type,
|
||||
son_object_type,
|
||||
son_proposal_object_type,
|
||||
sidechain_address_object_type,
|
||||
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 son_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, 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, 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, sidechain_address_object_type, sidechain_address_object> sidechain_address_id_type;
|
||||
|
||||
// implementation types
|
||||
class global_property_object;
|
||||
|
|
@ -421,6 +424,7 @@ FC_REFLECT_ENUM( graphene::chain::object_type,
|
|||
(bet_object_type)
|
||||
(son_object_type)
|
||||
(son_proposal_object_type)
|
||||
(sidechain_address_object_type)
|
||||
(OBJECT_TYPE_COUNT)
|
||||
)
|
||||
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::son_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, )
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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) )
|
||||
70
libraries/chain/sidechain_address_evaluator.cpp
Normal file
70
libraries/chain/sidechain_address_evaluator.cpp
Normal 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
|
||||
|
|
@ -8,9 +8,10 @@
|
|||
|
||||
namespace graphene { namespace peerplays_sidechain {
|
||||
|
||||
enum network {
|
||||
enum class sidechain_type {
|
||||
bitcoin,
|
||||
//ethereum
|
||||
//ethereum,
|
||||
//eos
|
||||
};
|
||||
|
||||
using bytes = std::vector<char>;
|
||||
|
|
@ -59,7 +60,7 @@ struct info_for_vin
|
|||
};
|
||||
|
||||
struct sidechain_event_data {
|
||||
network sidechain;
|
||||
sidechain_type sidechain;
|
||||
std::string transaction_id;
|
||||
std::string from;
|
||||
std::string to;
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@
|
|||
#include <graphene/chain/account_object.hpp>
|
||||
#include <graphene/chain/database.hpp>
|
||||
|
||||
#include <graphene/peerplays_sidechain/defs.hpp>
|
||||
|
||||
namespace graphene { namespace peerplays_sidechain {
|
||||
using namespace chain;
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ public:
|
|||
std::vector<std::string> get_user_sidechain_address_mapping();
|
||||
|
||||
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 transfer( const std::string& from, const std::string& to, const uint64_t amount ) = 0;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ public:
|
|||
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:
|
||||
|
||||
std::vector<std::unique_ptr<sidechain_net_handler>> net_handlers;
|
||||
|
|
|
|||
|
|
@ -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-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 {
|
||||
wlog("Haven't set up bitcoin sidechain parameters");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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> result;
|
||||
|
||||
switch (network) {
|
||||
case network::bitcoin:
|
||||
switch (sidechain) {
|
||||
case sidechain_type::bitcoin:
|
||||
result.push_back("2N5aFW5WFaYZLuJWx9RGziHBdEMj9Zf8s3J");
|
||||
result.push_back("2MxAnE469fhhdvUqUB7daU997VSearb2mn7");
|
||||
result.push_back("2NAYptFvTU8vJ1pC7CxvVA9R7D3NdBJHpwL");
|
||||
|
|
|
|||
|
|
@ -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(options) {
|
||||
network = peerplays_sidechain::network::bitcoin;
|
||||
sidechain = sidechain_type::bitcoin;
|
||||
|
||||
ip = options.at("bitcoin-node-ip").as<std::string>();
|
||||
zmq_port = options.at("bitcoin-node-zmq-port").as<uint32_t>();
|
||||
|
|
|
|||
|
|
@ -13,13 +13,13 @@ sidechain_net_manager::~sidechain_net_manager() {
|
|||
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__);
|
||||
|
||||
bool ret_val = false;
|
||||
|
||||
switch (network) {
|
||||
case network::bitcoin: {
|
||||
switch (sidechain) {
|
||||
case sidechain_type::bitcoin: {
|
||||
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));
|
||||
ret_val = true;
|
||||
|
|
|
|||
Loading…
Reference in a new issue