Merge branch graphene/develop into bitshares at commit '447018b319668deddf4d55baac168c1afc0a5e21'
Conflicts: libraries/chain/include/graphene/chain/hardfork.hpp libraries/fc
This commit is contained in:
commit
d6863a587c
55 changed files with 1139 additions and 570 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -8,6 +8,7 @@ Makefile
|
||||||
compile_commands.json
|
compile_commands.json
|
||||||
moc_*
|
moc_*
|
||||||
*.moc
|
*.moc
|
||||||
|
hardfork.hpp
|
||||||
|
|
||||||
libraries/utilities/git_revision.cpp
|
libraries/utilities/git_revision.cpp
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,11 @@
|
||||||
#include <graphene/chain/get_config.hpp>
|
#include <graphene/chain/get_config.hpp>
|
||||||
#include <graphene/utilities/key_conversion.hpp>
|
#include <graphene/utilities/key_conversion.hpp>
|
||||||
#include <graphene/chain/protocol/fee_schedule.hpp>
|
#include <graphene/chain/protocol/fee_schedule.hpp>
|
||||||
#include <graphene/chain/withdraw_permission_object.hpp>
|
#include <graphene/chain/confidential_object.hpp>
|
||||||
#include <graphene/chain/worker_evaluator.hpp>
|
#include <graphene/chain/market_object.hpp>
|
||||||
#include <graphene/chain/transaction_object.hpp>
|
#include <graphene/chain/transaction_object.hpp>
|
||||||
#include <graphene/chain/confidential_evaluator.hpp>
|
#include <graphene/chain/withdraw_permission_object.hpp>
|
||||||
|
#include <graphene/chain/worker_object.hpp>
|
||||||
|
|
||||||
#include <fc/crypto/hex.hpp>
|
#include <fc/crypto/hex.hpp>
|
||||||
#include <fc/smart_ref_impl.hpp>
|
#include <fc/smart_ref_impl.hpp>
|
||||||
|
|
@ -90,6 +91,10 @@ namespace graphene { namespace app {
|
||||||
{
|
{
|
||||||
_network_node_api = std::make_shared< network_node_api >( std::ref(_app) );
|
_network_node_api = std::make_shared< network_node_api >( std::ref(_app) );
|
||||||
}
|
}
|
||||||
|
else if( api_name == "crypto_api" )
|
||||||
|
{
|
||||||
|
_crypto_api = std::make_shared< crypto_api >();
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -200,6 +205,12 @@ namespace graphene { namespace app {
|
||||||
return *_history_api;
|
return *_history_api;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fc::api<crypto_api> login_api::crypto() const
|
||||||
|
{
|
||||||
|
FC_ASSERT(_crypto_api);
|
||||||
|
return *_crypto_api;
|
||||||
|
}
|
||||||
|
|
||||||
vector<account_id_type> get_relevant_accounts( const object* obj )
|
vector<account_id_type> get_relevant_accounts( const object* obj )
|
||||||
{
|
{
|
||||||
vector<account_id_type> result;
|
vector<account_id_type> result;
|
||||||
|
|
@ -245,6 +256,7 @@ namespace graphene { namespace app {
|
||||||
result.push_back( aobj->borrower );
|
result.push_back( aobj->borrower );
|
||||||
break;
|
break;
|
||||||
} case custom_object_type:{
|
} case custom_object_type:{
|
||||||
|
break;
|
||||||
} case proposal_object_type:{
|
} case proposal_object_type:{
|
||||||
const auto& aobj = dynamic_cast<const proposal_object*>(obj);
|
const auto& aobj = dynamic_cast<const proposal_object*>(obj);
|
||||||
assert( aobj != nullptr );
|
assert( aobj != nullptr );
|
||||||
|
|
@ -279,6 +291,7 @@ namespace graphene { namespace app {
|
||||||
break;
|
break;
|
||||||
} case balance_object_type:{
|
} case balance_object_type:{
|
||||||
/** these are free from any accounts */
|
/** these are free from any accounts */
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -286,13 +299,17 @@ namespace graphene { namespace app {
|
||||||
{
|
{
|
||||||
switch( (impl_object_type)obj->id.type() )
|
switch( (impl_object_type)obj->id.type() )
|
||||||
{
|
{
|
||||||
case impl_global_property_object_type:{
|
case impl_global_property_object_type:
|
||||||
} case impl_dynamic_global_property_object_type:{
|
|
||||||
} case impl_reserved0_object_type:{
|
|
||||||
} case impl_asset_dynamic_data_type:{
|
|
||||||
} case impl_asset_bitasset_data_type:{
|
|
||||||
break;
|
break;
|
||||||
} case impl_account_balance_object_type:{
|
case impl_dynamic_global_property_object_type:
|
||||||
|
break;
|
||||||
|
case impl_reserved0_object_type:
|
||||||
|
break;
|
||||||
|
case impl_asset_dynamic_data_type:
|
||||||
|
break;
|
||||||
|
case impl_asset_bitasset_data_type:
|
||||||
|
break;
|
||||||
|
case impl_account_balance_object_type:{
|
||||||
const auto& aobj = dynamic_cast<const account_balance_object*>(obj);
|
const auto& aobj = dynamic_cast<const account_balance_object*>(obj);
|
||||||
assert( aobj != nullptr );
|
assert( aobj != nullptr );
|
||||||
result.push_back( aobj->owner );
|
result.push_back( aobj->owner );
|
||||||
|
|
@ -317,12 +334,16 @@ namespace graphene { namespace app {
|
||||||
for( const auto& a : aobj->owner.account_auths )
|
for( const auto& a : aobj->owner.account_auths )
|
||||||
result.push_back( a.first );
|
result.push_back( a.first );
|
||||||
break;
|
break;
|
||||||
} case impl_block_summary_object_type:{
|
} case impl_block_summary_object_type:
|
||||||
} case impl_account_transaction_history_object_type:{
|
break;
|
||||||
} case impl_chain_property_object_type: {
|
case impl_account_transaction_history_object_type:
|
||||||
} case impl_witness_schedule_object_type: {
|
break;
|
||||||
} case impl_budget_record_object_type: {
|
case impl_chain_property_object_type:
|
||||||
}
|
break;
|
||||||
|
case impl_witness_schedule_object_type:
|
||||||
|
break;
|
||||||
|
case impl_budget_record_object_type:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -407,5 +428,75 @@ namespace graphene { namespace app {
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} FC_CAPTURE_AND_RETHROW( (a)(b)(bucket_seconds)(start)(end) ) }
|
} FC_CAPTURE_AND_RETHROW( (a)(b)(bucket_seconds)(start)(end) ) }
|
||||||
|
|
||||||
|
crypto_api::crypto_api(){};
|
||||||
|
|
||||||
|
blind_signature crypto_api::blind_sign( const extended_private_key_type& key, const blinded_hash& hash, int i )
|
||||||
|
{
|
||||||
|
return fc::ecc::extended_private_key( key ).blind_sign( hash, i );
|
||||||
|
}
|
||||||
|
|
||||||
|
signature_type crypto_api::unblind_signature( const extended_private_key_type& key,
|
||||||
|
const extended_public_key_type& bob,
|
||||||
|
const blind_signature& sig,
|
||||||
|
const fc::sha256& hash,
|
||||||
|
int i )
|
||||||
|
{
|
||||||
|
return fc::ecc::extended_private_key( key ).unblind_signature( extended_public_key( bob ), sig, hash, i );
|
||||||
|
}
|
||||||
|
|
||||||
|
commitment_type crypto_api::blind( const blind_factor_type& blind, uint64_t value )
|
||||||
|
{
|
||||||
|
return fc::ecc::blind( blind, value );
|
||||||
|
}
|
||||||
|
|
||||||
|
blind_factor_type crypto_api::blind_sum( const std::vector<blind_factor_type>& blinds_in, uint32_t non_neg )
|
||||||
|
{
|
||||||
|
return fc::ecc::blind_sum( blinds_in, non_neg );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool crypto_api::verify_sum( const std::vector<commitment_type>& commits_in, const std::vector<commitment_type>& neg_commits_in, int64_t excess )
|
||||||
|
{
|
||||||
|
return fc::ecc::verify_sum( commits_in, neg_commits_in, excess );
|
||||||
|
}
|
||||||
|
|
||||||
|
verify_range_result crypto_api::verify_range( const commitment_type& commit, const std::vector<char>& proof )
|
||||||
|
{
|
||||||
|
verify_range_result result;
|
||||||
|
result.success = fc::ecc::verify_range( result.min_val, result.max_val, commit, proof );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<char> crypto_api::range_proof_sign( uint64_t min_value,
|
||||||
|
const commitment_type& commit,
|
||||||
|
const blind_factor_type& commit_blind,
|
||||||
|
const blind_factor_type& nonce,
|
||||||
|
int8_t base10_exp,
|
||||||
|
uint8_t min_bits,
|
||||||
|
uint64_t actual_value )
|
||||||
|
{
|
||||||
|
return fc::ecc::range_proof_sign( min_value, commit, commit_blind, nonce, base10_exp, min_bits, actual_value );
|
||||||
|
}
|
||||||
|
|
||||||
|
verify_range_proof_rewind_result crypto_api::verify_range_proof_rewind( const blind_factor_type& nonce,
|
||||||
|
const commitment_type& commit,
|
||||||
|
const std::vector<char>& proof )
|
||||||
|
{
|
||||||
|
verify_range_proof_rewind_result result;
|
||||||
|
result.success = fc::ecc::verify_range_proof_rewind( result.blind_out,
|
||||||
|
result.value_out,
|
||||||
|
result.message_out,
|
||||||
|
nonce,
|
||||||
|
result.min_val,
|
||||||
|
result.max_val,
|
||||||
|
const_cast< commitment_type& >( commit ),
|
||||||
|
proof );
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
range_proof_info crypto_api::range_get_info( const std::vector<char>& proof )
|
||||||
|
{
|
||||||
|
return fc::ecc::range_get_info( proof );
|
||||||
|
}
|
||||||
|
|
||||||
} } // graphene::app
|
} } // graphene::app
|
||||||
|
|
|
||||||
|
|
@ -433,6 +433,7 @@ namespace detail {
|
||||||
wild_access.allowed_apis.push_back( "database_api" );
|
wild_access.allowed_apis.push_back( "database_api" );
|
||||||
wild_access.allowed_apis.push_back( "network_broadcast_api" );
|
wild_access.allowed_apis.push_back( "network_broadcast_api" );
|
||||||
wild_access.allowed_apis.push_back( "history_api" );
|
wild_access.allowed_apis.push_back( "history_api" );
|
||||||
|
wild_access.allowed_apis.push_back( "crypto_api" );
|
||||||
_apiaccess.permission_map["*"] = wild_access;
|
_apiaccess.permission_map["*"] = wild_access;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -577,7 +577,7 @@ std::map<std::string, full_account> database_api_impl::get_full_accounts( const
|
||||||
|
|
||||||
|
|
||||||
// Add the account's balances
|
// Add the account's balances
|
||||||
auto balance_range = _db.get_index_type<account_balance_index>().indices().get<by_account>().equal_range(account->id);
|
auto balance_range = _db.get_index_type<account_balance_index>().indices().get<by_account_asset>().equal_range(boost::make_tuple(account->id));
|
||||||
//vector<account_balance_object> balances;
|
//vector<account_balance_object> balances;
|
||||||
std::for_each(balance_range.first, balance_range.second,
|
std::for_each(balance_range.first, balance_range.second,
|
||||||
[&acnt](const account_balance_object& balance) {
|
[&acnt](const account_balance_object& balance) {
|
||||||
|
|
@ -711,7 +711,7 @@ vector<asset> database_api_impl::get_account_balances(account_id_type acnt, cons
|
||||||
{
|
{
|
||||||
// if the caller passes in an empty list of assets, return balances for all assets the account owns
|
// if the caller passes in an empty list of assets, return balances for all assets the account owns
|
||||||
const account_balance_index& balance_index = _db.get_index_type<account_balance_index>();
|
const account_balance_index& balance_index = _db.get_index_type<account_balance_index>();
|
||||||
auto range = balance_index.indices().get<by_account>().equal_range(acnt);
|
auto range = balance_index.indices().get<by_account_asset>().equal_range(boost::make_tuple(acnt));
|
||||||
for (const account_balance_object& balance : boost::make_iterator_range(range.first, range.second))
|
for (const account_balance_object& balance : boost::make_iterator_range(range.first, range.second))
|
||||||
result.push_back(asset(balance.get_balance()));
|
result.push_back(asset(balance.get_balance()));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@
|
||||||
#include <graphene/app/database_api.hpp>
|
#include <graphene/app/database_api.hpp>
|
||||||
|
|
||||||
#include <graphene/chain/protocol/types.hpp>
|
#include <graphene/chain/protocol/types.hpp>
|
||||||
|
#include <graphene/chain/protocol/confidential.hpp>
|
||||||
|
|
||||||
#include <graphene/market_history/market_history_plugin.hpp>
|
#include <graphene/market_history/market_history_plugin.hpp>
|
||||||
|
|
||||||
|
|
@ -33,6 +34,7 @@
|
||||||
|
|
||||||
#include <fc/api.hpp>
|
#include <fc/api.hpp>
|
||||||
#include <fc/optional.hpp>
|
#include <fc/optional.hpp>
|
||||||
|
#include <fc/crypto/elliptic.hpp>
|
||||||
#include <fc/network/ip.hpp>
|
#include <fc/network/ip.hpp>
|
||||||
|
|
||||||
#include <boost/container/flat_set.hpp>
|
#include <boost/container/flat_set.hpp>
|
||||||
|
|
@ -45,10 +47,27 @@
|
||||||
namespace graphene { namespace app {
|
namespace graphene { namespace app {
|
||||||
using namespace graphene::chain;
|
using namespace graphene::chain;
|
||||||
using namespace graphene::market_history;
|
using namespace graphene::market_history;
|
||||||
|
using namespace fc::ecc;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
class application;
|
class application;
|
||||||
|
|
||||||
|
struct verify_range_result
|
||||||
|
{
|
||||||
|
bool success;
|
||||||
|
uint64_t min_val;
|
||||||
|
uint64_t max_val;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct verify_range_proof_rewind_result
|
||||||
|
{
|
||||||
|
bool success;
|
||||||
|
uint64_t min_val;
|
||||||
|
uint64_t max_val;
|
||||||
|
uint64_t value_out;
|
||||||
|
fc::ecc::blind_factor_type blind_out;
|
||||||
|
string message_out;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The history_api class implements the RPC API for account history
|
* @brief The history_api class implements the RPC API for account history
|
||||||
|
|
@ -176,6 +195,44 @@ namespace graphene { namespace app {
|
||||||
private:
|
private:
|
||||||
application& _app;
|
application& _app;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class crypto_api
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
crypto_api();
|
||||||
|
|
||||||
|
fc::ecc::blind_signature blind_sign( const extended_private_key_type& key, const fc::ecc::blinded_hash& hash, int i );
|
||||||
|
|
||||||
|
signature_type unblind_signature( const extended_private_key_type& key,
|
||||||
|
const extended_public_key_type& bob,
|
||||||
|
const fc::ecc::blind_signature& sig,
|
||||||
|
const fc::sha256& hash,
|
||||||
|
int i );
|
||||||
|
|
||||||
|
fc::ecc::commitment_type blind( const fc::ecc::blind_factor_type& blind, uint64_t value );
|
||||||
|
|
||||||
|
fc::ecc::blind_factor_type blind_sum( const std::vector<blind_factor_type>& blinds_in, uint32_t non_neg );
|
||||||
|
|
||||||
|
bool verify_sum( const std::vector<commitment_type>& commits_in, const std::vector<commitment_type>& neg_commits_in, int64_t excess );
|
||||||
|
|
||||||
|
verify_range_result verify_range( const fc::ecc::commitment_type& commit, const std::vector<char>& proof );
|
||||||
|
|
||||||
|
std::vector<char> range_proof_sign( uint64_t min_value,
|
||||||
|
const commitment_type& commit,
|
||||||
|
const blind_factor_type& commit_blind,
|
||||||
|
const blind_factor_type& nonce,
|
||||||
|
int8_t base10_exp,
|
||||||
|
uint8_t min_bits,
|
||||||
|
uint64_t actual_value );
|
||||||
|
|
||||||
|
|
||||||
|
verify_range_proof_rewind_result verify_range_proof_rewind( const blind_factor_type& nonce,
|
||||||
|
const fc::ecc::commitment_type& commit,
|
||||||
|
const std::vector<char>& proof );
|
||||||
|
|
||||||
|
|
||||||
|
range_proof_info range_get_info( const std::vector<char>& proof );
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The login_api class implements the bottom layer of the RPC API
|
* @brief The login_api class implements the bottom layer of the RPC API
|
||||||
|
|
@ -206,6 +263,8 @@ namespace graphene { namespace app {
|
||||||
fc::api<history_api> history()const;
|
fc::api<history_api> history()const;
|
||||||
/// @brief Retrieve the network node API
|
/// @brief Retrieve the network node API
|
||||||
fc::api<network_node_api> network_node()const;
|
fc::api<network_node_api> network_node()const;
|
||||||
|
/// @brief Retrieve the cryptography API
|
||||||
|
fc::api<crypto_api> crypto()const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// @brief Called to enable an API, not reflected.
|
/// @brief Called to enable an API, not reflected.
|
||||||
|
|
@ -216,12 +275,19 @@ namespace graphene { namespace app {
|
||||||
optional< fc::api<network_broadcast_api> > _network_broadcast_api;
|
optional< fc::api<network_broadcast_api> > _network_broadcast_api;
|
||||||
optional< fc::api<network_node_api> > _network_node_api;
|
optional< fc::api<network_node_api> > _network_node_api;
|
||||||
optional< fc::api<history_api> > _history_api;
|
optional< fc::api<history_api> > _history_api;
|
||||||
|
optional< fc::api<crypto_api> > _crypto_api;
|
||||||
};
|
};
|
||||||
|
|
||||||
}} // graphene::app
|
}} // graphene::app
|
||||||
|
|
||||||
FC_REFLECT( graphene::app::network_broadcast_api::transaction_confirmation,
|
FC_REFLECT( graphene::app::network_broadcast_api::transaction_confirmation,
|
||||||
(id)(block_num)(trx_num)(trx) )
|
(id)(block_num)(trx_num)(trx) )
|
||||||
|
FC_REFLECT( graphene::app::verify_range_result,
|
||||||
|
(success)(min_val)(max_val) )
|
||||||
|
FC_REFLECT( graphene::app::verify_range_proof_rewind_result,
|
||||||
|
(success)(min_val)(max_val)(value_out)(blind_out)(message_out) )
|
||||||
|
//FC_REFLECT_TYPENAME( fc::ecc::compact_signature );
|
||||||
|
//FC_REFLECT_TYPENAME( fc::ecc::commitment_type );
|
||||||
|
|
||||||
FC_API(graphene::app::history_api,
|
FC_API(graphene::app::history_api,
|
||||||
(get_account_history)
|
(get_account_history)
|
||||||
|
|
@ -242,10 +308,22 @@ FC_API(graphene::app::network_node_api,
|
||||||
(get_advanced_node_parameters)
|
(get_advanced_node_parameters)
|
||||||
(set_advanced_node_parameters)
|
(set_advanced_node_parameters)
|
||||||
)
|
)
|
||||||
|
FC_API(graphene::app::crypto_api,
|
||||||
|
(blind_sign)
|
||||||
|
(unblind_signature)
|
||||||
|
(blind)
|
||||||
|
(blind_sum)
|
||||||
|
(verify_sum)
|
||||||
|
(verify_range)
|
||||||
|
(range_proof_sign)
|
||||||
|
(verify_range_proof_rewind)
|
||||||
|
(range_get_info)
|
||||||
|
)
|
||||||
FC_API(graphene::app::login_api,
|
FC_API(graphene::app::login_api,
|
||||||
(login)
|
(login)
|
||||||
(network_broadcast)
|
(network_broadcast)
|
||||||
(database)
|
(database)
|
||||||
(history)
|
(history)
|
||||||
(network_node)
|
(network_node)
|
||||||
|
(crypto)
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -34,12 +34,12 @@
|
||||||
#include <graphene/chain/balance_object.hpp>
|
#include <graphene/chain/balance_object.hpp>
|
||||||
#include <graphene/chain/chain_property_object.hpp>
|
#include <graphene/chain/chain_property_object.hpp>
|
||||||
#include <graphene/chain/committee_member_object.hpp>
|
#include <graphene/chain/committee_member_object.hpp>
|
||||||
#include <graphene/chain/market_evaluator.hpp>
|
#include <graphene/chain/confidential_object.hpp>
|
||||||
|
#include <graphene/chain/market_object.hpp>
|
||||||
#include <graphene/chain/operation_history_object.hpp>
|
#include <graphene/chain/operation_history_object.hpp>
|
||||||
#include <graphene/chain/proposal_object.hpp>
|
#include <graphene/chain/proposal_object.hpp>
|
||||||
#include <graphene/chain/worker_evaluator.hpp>
|
#include <graphene/chain/worker_object.hpp>
|
||||||
#include <graphene/chain/witness_object.hpp>
|
#include <graphene/chain/witness_object.hpp>
|
||||||
#include <graphene/chain/confidential_evaluator.hpp>
|
|
||||||
|
|
||||||
#include <graphene/market_history/market_history_plugin.hpp>
|
#include <graphene/market_history/market_history_plugin.hpp>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,39 @@
|
||||||
|
|
||||||
|
add_custom_target( build_hardfork_hpp
|
||||||
|
COMMAND cat-parts hardfork.d "${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp" )
|
||||||
|
set_source_files_properties( "${CMAKE_CURRENT_BINARY_DIR}/include/graphene/chain/hardfork.hpp" PROPERTIES GENERATED TRUE )
|
||||||
|
|
||||||
|
add_dependencies( build_hardfork_hpp cat-parts )
|
||||||
|
|
||||||
file(GLOB HEADERS "include/graphene/chain/*.hpp")
|
file(GLOB HEADERS "include/graphene/chain/*.hpp")
|
||||||
|
|
||||||
|
if( GRAPHENE_DISABLE_UNITY_BUILD )
|
||||||
|
set( GRAPHENE_DB_FILES
|
||||||
|
db_balance.cpp
|
||||||
|
db_block.cpp
|
||||||
|
db_debug.cpp
|
||||||
|
db_getter.cpp
|
||||||
|
db_init.cpp
|
||||||
|
db_maint.cpp
|
||||||
|
db_management.cpp
|
||||||
|
db_market.cpp
|
||||||
|
db_update.cpp
|
||||||
|
db_witness_schedule.cpp
|
||||||
|
)
|
||||||
|
message( STATUS "Graphene database unity build disabled" )
|
||||||
|
else( GRAPHENE_DISABLE_UNITY_BUILD )
|
||||||
|
set( GRAPHENE_DB_FILES
|
||||||
|
database.cpp )
|
||||||
|
message( STATUS "Graphene database unity build enabled" )
|
||||||
|
endif( GRAPHENE_DISABLE_UNITY_BUILD )
|
||||||
|
|
||||||
## SORT .cpp by most likely to change / break compile
|
## SORT .cpp by most likely to change / break compile
|
||||||
add_library( graphene_chain
|
add_library( graphene_chain
|
||||||
|
|
||||||
# As database takes the longest to compile, start it first
|
# As database takes the longest to compile, start it first
|
||||||
database.cpp
|
${GRAPHENE_DB_FILES}
|
||||||
fork_database.cpp
|
fork_database.cpp
|
||||||
|
|
||||||
# db_balance.cpp
|
|
||||||
# db_block.cpp
|
|
||||||
# db_debug.cpp
|
|
||||||
# db_getter.cpp
|
|
||||||
# db_init.cpp
|
|
||||||
# db_maint.cpp
|
|
||||||
# db_management.cpp
|
|
||||||
# db_market.cpp
|
|
||||||
# db_update.cpp
|
|
||||||
# db_witness_schedule.cpp
|
|
||||||
|
|
||||||
protocol/types.cpp
|
protocol/types.cpp
|
||||||
protocol/address.cpp
|
protocol/address.cpp
|
||||||
protocol/authority.cpp
|
protocol/authority.cpp
|
||||||
|
|
@ -69,11 +85,13 @@ add_library( graphene_chain
|
||||||
block_database.cpp
|
block_database.cpp
|
||||||
|
|
||||||
${HEADERS}
|
${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 )
|
||||||
target_include_directories( graphene_chain
|
target_include_directories( graphene_chain
|
||||||
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )
|
PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_BINARY_DIR}/include" )
|
||||||
|
|
||||||
if(MSVC)
|
if(MSVC)
|
||||||
set_source_files_properties( db_init.cpp db_block.cpp database.cpp block_database.cpp PROPERTIES COMPILE_FLAGS "/bigobj" )
|
set_source_files_properties( db_init.cpp db_block.cpp database.cpp block_database.cpp PROPERTIES COMPILE_FLAGS "/bigobj" )
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
#include <graphene/chain/asset_evaluator.hpp>
|
#include <graphene/chain/asset_evaluator.hpp>
|
||||||
#include <graphene/chain/asset_object.hpp>
|
#include <graphene/chain/asset_object.hpp>
|
||||||
#include <graphene/chain/account_object.hpp>
|
#include <graphene/chain/account_object.hpp>
|
||||||
#include <graphene/chain/market_evaluator.hpp>
|
#include <graphene/chain/market_object.hpp>
|
||||||
#include <graphene/chain/database.hpp>
|
#include <graphene/chain/database.hpp>
|
||||||
#include <graphene/chain/exceptions.hpp>
|
#include <graphene/chain/exceptions.hpp>
|
||||||
#include <graphene/chain/hardfork.hpp>
|
#include <graphene/chain/hardfork.hpp>
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
#include <graphene/chain/exceptions.hpp>
|
#include <graphene/chain/exceptions.hpp>
|
||||||
#include <graphene/chain/protocol/confidential.hpp>
|
#include <graphene/chain/protocol/confidential.hpp>
|
||||||
#include <graphene/chain/confidential_evaluator.hpp>
|
#include <graphene/chain/confidential_evaluator.hpp>
|
||||||
|
#include <graphene/chain/confidential_object.hpp>
|
||||||
#include <graphene/chain/database.hpp>
|
#include <graphene/chain/database.hpp>
|
||||||
|
|
||||||
namespace graphene { namespace chain {
|
namespace graphene { namespace chain {
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,7 @@ namespace graphene { namespace chain {
|
||||||
|
|
||||||
asset database::get_balance(account_id_type owner, asset_id_type asset_id) const
|
asset database::get_balance(account_id_type owner, asset_id_type asset_id) const
|
||||||
{
|
{
|
||||||
auto& index = get_index_type<account_balance_index>().indices().get<by_balance>();
|
auto& index = get_index_type<account_balance_index>().indices().get<by_account_asset>();
|
||||||
auto itr = index.find(boost::make_tuple(owner, asset_id));
|
auto itr = index.find(boost::make_tuple(owner, asset_id));
|
||||||
if( itr == index.end() )
|
if( itr == index.end() )
|
||||||
return asset(0, asset_id);
|
return asset(0, asset_id);
|
||||||
|
|
@ -55,7 +55,7 @@ void database::adjust_balance(account_id_type account, asset delta )
|
||||||
if( delta.amount == 0 )
|
if( delta.amount == 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto& index = get_index_type<account_balance_index>().indices().get<by_balance>();
|
auto& index = get_index_type<account_balance_index>().indices().get<by_account_asset>();
|
||||||
auto itr = index.find(boost::make_tuple(account, delta.asset_id));
|
auto itr = index.find(boost::make_tuple(account, delta.asset_id));
|
||||||
if(itr == index.end())
|
if(itr == index.end())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -571,7 +571,7 @@ processed_transaction database::_apply_transaction(const signed_transaction& trx
|
||||||
{ try {
|
{ try {
|
||||||
uint32_t skip = get_node_properties().skip_flags;
|
uint32_t skip = get_node_properties().skip_flags;
|
||||||
|
|
||||||
if( !(skip&skip_validate) )
|
if( true || !(skip&skip_validate) ) /* issue #505 explains why this skip_flag is disabled */
|
||||||
trx.validate();
|
trx.validate();
|
||||||
|
|
||||||
auto& trx_idx = get_mutable_index_type<transaction_index>();
|
auto& trx_idx = get_mutable_index_type<transaction_index>();
|
||||||
|
|
@ -631,8 +631,8 @@ processed_transaction database::_apply_transaction(const signed_transaction& trx
|
||||||
ptrx.operation_results = std::move(eval_state.operation_results);
|
ptrx.operation_results = std::move(eval_state.operation_results);
|
||||||
|
|
||||||
//Make sure the temp account has no non-zero balances
|
//Make sure the temp account has no non-zero balances
|
||||||
const auto& index = get_index_type<account_balance_index>().indices().get<by_account>();
|
const auto& index = get_index_type<account_balance_index>().indices().get<by_account_asset>();
|
||||||
auto range = index.equal_range(GRAPHENE_TEMP_ACCOUNT);
|
auto range = index.equal_range( boost::make_tuple( GRAPHENE_TEMP_ACCOUNT ) );
|
||||||
std::for_each(range.first, range.second, [](const account_balance_object& b) { FC_ASSERT(b.balance == 0); });
|
std::for_each(range.first, range.second, [](const account_balance_object& b) { FC_ASSERT(b.balance == 0); });
|
||||||
|
|
||||||
return ptrx;
|
return ptrx;
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
#include <graphene/chain/account_object.hpp>
|
#include <graphene/chain/account_object.hpp>
|
||||||
#include <graphene/chain/asset_object.hpp>
|
#include <graphene/chain/asset_object.hpp>
|
||||||
#include <graphene/chain/market_evaluator.hpp>
|
#include <graphene/chain/market_object.hpp>
|
||||||
#include <graphene/chain/vesting_balance_object.hpp>
|
#include <graphene/chain/vesting_balance_object.hpp>
|
||||||
#include <graphene/chain/witness_object.hpp>
|
#include <graphene/chain/witness_object.hpp>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,8 @@
|
||||||
#include <graphene/chain/chain_property_object.hpp>
|
#include <graphene/chain/chain_property_object.hpp>
|
||||||
#include <graphene/chain/global_property_object.hpp>
|
#include <graphene/chain/global_property_object.hpp>
|
||||||
|
|
||||||
|
#include <fc/smart_ref_impl.hpp>
|
||||||
|
|
||||||
namespace graphene { namespace chain {
|
namespace graphene { namespace chain {
|
||||||
|
|
||||||
const asset_object& database::get_core_asset() const
|
const asset_object& database::get_core_asset() const
|
||||||
|
|
|
||||||
|
|
@ -31,19 +31,25 @@
|
||||||
#include <graphene/chain/budget_record_object.hpp>
|
#include <graphene/chain/budget_record_object.hpp>
|
||||||
#include <graphene/chain/chain_property_object.hpp>
|
#include <graphene/chain/chain_property_object.hpp>
|
||||||
#include <graphene/chain/committee_member_object.hpp>
|
#include <graphene/chain/committee_member_object.hpp>
|
||||||
|
#include <graphene/chain/confidential_object.hpp>
|
||||||
#include <graphene/chain/global_property_object.hpp>
|
#include <graphene/chain/global_property_object.hpp>
|
||||||
|
#include <graphene/chain/market_object.hpp>
|
||||||
|
#include <graphene/chain/operation_history_object.hpp>
|
||||||
#include <graphene/chain/proposal_object.hpp>
|
#include <graphene/chain/proposal_object.hpp>
|
||||||
#include <graphene/chain/transaction_object.hpp>
|
#include <graphene/chain/transaction_object.hpp>
|
||||||
#include <graphene/chain/vesting_balance_object.hpp>
|
#include <graphene/chain/vesting_balance_object.hpp>
|
||||||
#include <graphene/chain/withdraw_permission_object.hpp>
|
#include <graphene/chain/withdraw_permission_object.hpp>
|
||||||
#include <graphene/chain/witness_object.hpp>
|
#include <graphene/chain/witness_object.hpp>
|
||||||
#include <graphene/chain/witness_schedule_object.hpp>
|
#include <graphene/chain/witness_schedule_object.hpp>
|
||||||
|
#include <graphene/chain/worker_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>
|
||||||
#include <graphene/chain/assert_evaluator.hpp>
|
#include <graphene/chain/assert_evaluator.hpp>
|
||||||
#include <graphene/chain/custom_evaluator.hpp>
|
#include <graphene/chain/balance_evaluator.hpp>
|
||||||
#include <graphene/chain/committee_member_evaluator.hpp>
|
#include <graphene/chain/committee_member_evaluator.hpp>
|
||||||
|
#include <graphene/chain/confidential_evaluator.hpp>
|
||||||
|
#include <graphene/chain/custom_evaluator.hpp>
|
||||||
#include <graphene/chain/market_evaluator.hpp>
|
#include <graphene/chain/market_evaluator.hpp>
|
||||||
#include <graphene/chain/proposal_evaluator.hpp>
|
#include <graphene/chain/proposal_evaluator.hpp>
|
||||||
#include <graphene/chain/transfer_evaluator.hpp>
|
#include <graphene/chain/transfer_evaluator.hpp>
|
||||||
|
|
@ -51,11 +57,10 @@
|
||||||
#include <graphene/chain/withdraw_permission_evaluator.hpp>
|
#include <graphene/chain/withdraw_permission_evaluator.hpp>
|
||||||
#include <graphene/chain/witness_evaluator.hpp>
|
#include <graphene/chain/witness_evaluator.hpp>
|
||||||
#include <graphene/chain/worker_evaluator.hpp>
|
#include <graphene/chain/worker_evaluator.hpp>
|
||||||
#include <graphene/chain/balance_evaluator.hpp>
|
|
||||||
#include <graphene/chain/confidential_evaluator.hpp>
|
|
||||||
|
|
||||||
#include <graphene/chain/protocol/fee_schedule.hpp>
|
#include <graphene/chain/protocol/fee_schedule.hpp>
|
||||||
|
|
||||||
|
#include <fc/smart_ref_impl.hpp>
|
||||||
#include <fc/uint128.hpp>
|
#include <fc/uint128.hpp>
|
||||||
#include <fc/crypto/digest.hpp>
|
#include <fc/crypto/digest.hpp>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,11 +31,13 @@
|
||||||
|
|
||||||
#include <graphene/chain/account_object.hpp>
|
#include <graphene/chain/account_object.hpp>
|
||||||
#include <graphene/chain/asset_object.hpp>
|
#include <graphene/chain/asset_object.hpp>
|
||||||
|
#include <graphene/chain/budget_record_object.hpp>
|
||||||
|
#include <graphene/chain/chain_property_object.hpp>
|
||||||
#include <graphene/chain/committee_member_object.hpp>
|
#include <graphene/chain/committee_member_object.hpp>
|
||||||
#include <graphene/chain/global_property_object.hpp>
|
#include <graphene/chain/global_property_object.hpp>
|
||||||
#include <graphene/chain/vesting_balance_object.hpp>
|
#include <graphene/chain/vesting_balance_object.hpp>
|
||||||
#include <graphene/chain/witness_object.hpp>
|
#include <graphene/chain/witness_object.hpp>
|
||||||
#include <graphene/chain/worker_evaluator.hpp>
|
#include <graphene/chain/worker_object.hpp>
|
||||||
|
|
||||||
namespace graphene { namespace chain {
|
namespace graphene { namespace chain {
|
||||||
|
|
||||||
|
|
@ -110,15 +112,15 @@ void database::pay_workers( share_type& budget )
|
||||||
get_index_type<worker_index>().inspect_all_objects([this, &active_workers](const object& o) {
|
get_index_type<worker_index>().inspect_all_objects([this, &active_workers](const object& o) {
|
||||||
const worker_object& w = static_cast<const worker_object&>(o);
|
const worker_object& w = static_cast<const worker_object&>(o);
|
||||||
auto now = head_block_time();
|
auto now = head_block_time();
|
||||||
if( w.is_active(now) && w.approving_stake(_vote_tally_buffer) > 0 )
|
if( w.is_active(now) && w.approving_stake() > 0 )
|
||||||
active_workers.emplace_back(w);
|
active_workers.emplace_back(w);
|
||||||
});
|
});
|
||||||
|
|
||||||
// worker with more votes is preferred
|
// worker with more votes is preferred
|
||||||
// if two workers exactly tie for votes, worker with lower ID is preferred
|
// if two workers exactly tie for votes, worker with lower ID is preferred
|
||||||
std::sort(active_workers.begin(), active_workers.end(), [this](const worker_object& wa, const worker_object& wb) {
|
std::sort(active_workers.begin(), active_workers.end(), [this](const worker_object& wa, const worker_object& wb) {
|
||||||
share_type wa_vote = wa.approving_stake(_vote_tally_buffer);
|
share_type wa_vote = wa.approving_stake();
|
||||||
share_type wb_vote = wb.approving_stake(_vote_tally_buffer);
|
share_type wb_vote = wb.approving_stake();
|
||||||
if( wa_vote != wb_vote )
|
if( wa_vote != wb_vote )
|
||||||
return wa_vote > wb_vote;
|
return wa_vote > wb_vote;
|
||||||
return wa.id < wb.id;
|
return wa.id < wb.id;
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@
|
||||||
#include <graphene/chain/account_object.hpp>
|
#include <graphene/chain/account_object.hpp>
|
||||||
#include <graphene/chain/asset_object.hpp>
|
#include <graphene/chain/asset_object.hpp>
|
||||||
#include <graphene/chain/hardfork.hpp>
|
#include <graphene/chain/hardfork.hpp>
|
||||||
#include <graphene/chain/market_evaluator.hpp>
|
#include <graphene/chain/market_object.hpp>
|
||||||
|
|
||||||
#include <fc/uint128.hpp>
|
#include <fc/uint128.hpp>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,12 @@
|
||||||
|
|
||||||
#include <graphene/chain/asset_object.hpp>
|
#include <graphene/chain/asset_object.hpp>
|
||||||
#include <graphene/chain/global_property_object.hpp>
|
#include <graphene/chain/global_property_object.hpp>
|
||||||
|
#include <graphene/chain/market_object.hpp>
|
||||||
#include <graphene/chain/proposal_object.hpp>
|
#include <graphene/chain/proposal_object.hpp>
|
||||||
#include <graphene/chain/transaction_object.hpp>
|
#include <graphene/chain/transaction_object.hpp>
|
||||||
#include <graphene/chain/market_evaluator.hpp>
|
|
||||||
#include <graphene/chain/withdraw_permission_object.hpp>
|
#include <graphene/chain/withdraw_permission_object.hpp>
|
||||||
#include <graphene/chain/witness_object.hpp>
|
#include <graphene/chain/witness_object.hpp>
|
||||||
|
|
||||||
#include <graphene/chain/protocol/fee_schedule.hpp>
|
#include <graphene/chain/protocol/fee_schedule.hpp>
|
||||||
|
|
||||||
#include <fc/uint128.hpp>
|
#include <fc/uint128.hpp>
|
||||||
|
|
@ -277,26 +278,48 @@ void database::clear_expired_orders()
|
||||||
{
|
{
|
||||||
asset_id_type current_asset = settlement_index.begin()->settlement_asset_id();
|
asset_id_type current_asset = settlement_index.begin()->settlement_asset_id();
|
||||||
asset max_settlement_volume;
|
asset max_settlement_volume;
|
||||||
|
bool extra_dump = false;
|
||||||
|
|
||||||
auto next_asset = [¤t_asset, &settlement_index] {
|
auto next_asset = [¤t_asset, &settlement_index, &extra_dump] {
|
||||||
auto bound = settlement_index.upper_bound(current_asset);
|
auto bound = settlement_index.upper_bound(current_asset);
|
||||||
if( bound == settlement_index.end() )
|
if( bound == settlement_index.end() )
|
||||||
|
{
|
||||||
|
if( extra_dump )
|
||||||
|
{
|
||||||
|
ilog( "next_asset() returning false" );
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
if( extra_dump )
|
||||||
|
{
|
||||||
|
ilog( "next_asset returning true, bound is ${b}", ("b", *bound) );
|
||||||
|
}
|
||||||
current_asset = bound->settlement_asset_id();
|
current_asset = bound->settlement_asset_id();
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
uint32_t count = 0;
|
||||||
|
|
||||||
// At each iteration, we either consume the current order and remove it, or we move to the next asset
|
// At each iteration, we either consume the current order and remove it, or we move to the next asset
|
||||||
for( auto itr = settlement_index.lower_bound(current_asset);
|
for( auto itr = settlement_index.lower_bound(current_asset);
|
||||||
itr != settlement_index.end();
|
itr != settlement_index.end();
|
||||||
itr = settlement_index.lower_bound(current_asset) )
|
itr = settlement_index.lower_bound(current_asset) )
|
||||||
{
|
{
|
||||||
|
++count;
|
||||||
const force_settlement_object& order = *itr;
|
const force_settlement_object& order = *itr;
|
||||||
auto order_id = order.id;
|
auto order_id = order.id;
|
||||||
current_asset = order.settlement_asset_id();
|
current_asset = order.settlement_asset_id();
|
||||||
const asset_object& mia_object = get(current_asset);
|
const asset_object& mia_object = get(current_asset);
|
||||||
const asset_bitasset_data_object& mia = mia_object.bitasset_data(*this);
|
const asset_bitasset_data_object& mia = mia_object.bitasset_data(*this);
|
||||||
|
|
||||||
|
extra_dump = ((count >= 1000) && (count <= 1020));
|
||||||
|
|
||||||
|
if( extra_dump )
|
||||||
|
{
|
||||||
|
wlog( "clear_expired_orders() dumping extra data for iteration ${c}", ("c", count) );
|
||||||
|
ilog( "head_block_num is ${hb} current_asset is ${a}", ("hb", head_block_num())("a", current_asset) );
|
||||||
|
}
|
||||||
|
|
||||||
if( mia.has_settlement() )
|
if( mia.has_settlement() )
|
||||||
{
|
{
|
||||||
ilog( "Canceling a force settlement because of black swan" );
|
ilog( "Canceling a force settlement because of black swan" );
|
||||||
|
|
@ -308,7 +331,13 @@ void database::clear_expired_orders()
|
||||||
if( order.settlement_date > head_block_time() )
|
if( order.settlement_date > head_block_time() )
|
||||||
{
|
{
|
||||||
if( next_asset() )
|
if( next_asset() )
|
||||||
|
{
|
||||||
|
if( extra_dump )
|
||||||
|
{
|
||||||
|
ilog( "next_asset() returned true when order.settlement_date > head_block_time()" );
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// Can we still settle in this asset?
|
// Can we still settle in this asset?
|
||||||
|
|
@ -329,7 +358,13 @@ void database::clear_expired_orders()
|
||||||
("settled_volume", mia.force_settled_volume)("max_volume", max_settlement_volume));
|
("settled_volume", mia.force_settled_volume)("max_volume", max_settlement_volume));
|
||||||
*/
|
*/
|
||||||
if( next_asset() )
|
if( next_asset() )
|
||||||
|
{
|
||||||
|
if( extra_dump )
|
||||||
|
{
|
||||||
|
ilog( "next_asset() returned true when mia.force_settled_volume >= max_settlement_volume.amount" );
|
||||||
|
}
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,6 @@
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <graphene/chain/database.hpp>
|
#include <graphene/chain/database.hpp>
|
||||||
#include <graphene/chain/global_property_object.hpp>
|
#include <graphene/chain/global_property_object.hpp>
|
||||||
|
|
|
||||||
10
libraries/chain/hardfork.d/000-200-preamble.hf
Normal file
10
libraries/chain/hardfork.d/000-200-preamble.hf
Normal file
|
|
@ -0,0 +1,10 @@
|
||||||
|
/*****************************************
|
||||||
|
* *
|
||||||
|
* This file is automatically generated. *
|
||||||
|
* To create new hardfork, please modify *
|
||||||
|
* the .hf files in hardfork.d instead *
|
||||||
|
* of modifying this file. *
|
||||||
|
* *
|
||||||
|
*****************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
4
libraries/chain/hardfork.d/357.hf
Normal file
4
libraries/chain/hardfork.d/357.hf
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
// #357 Disallow publishing certain malformed price feeds
|
||||||
|
#ifndef HARDFORK_357_TIME
|
||||||
|
#define HARDFORK_357_TIME (fc::time_point_sec( 1444416300 ))
|
||||||
|
#endif
|
||||||
4
libraries/chain/hardfork.d/359.hf
Normal file
4
libraries/chain/hardfork.d/359.hf
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
// #359 Allow digits in asset name
|
||||||
|
#ifndef HARDFORK_359_TIME
|
||||||
|
#define HARDFORK_359_TIME (fc::time_point_sec( 1444416300 ))
|
||||||
|
#endif
|
||||||
4
libraries/chain/hardfork.d/409.hf
Normal file
4
libraries/chain/hardfork.d/409.hf
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
// #409 Allow creation of sub-assets
|
||||||
|
#ifndef HARDFORK_409_TIME
|
||||||
|
#define HARDFORK_409_TIME (fc::time_point_sec( 1446652800 ))
|
||||||
|
#endif
|
||||||
4
libraries/chain/hardfork.d/413.hf
Normal file
4
libraries/chain/hardfork.d/413.hf
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
// #413 Add operation to claim asset fees
|
||||||
|
#ifndef HARDFORK_413_TIME
|
||||||
|
#define HARDFORK_413_TIME (fc::time_point_sec( 1446652800 ))
|
||||||
|
#endif
|
||||||
4
libraries/chain/hardfork.d/415.hf
Normal file
4
libraries/chain/hardfork.d/415.hf
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
// #415 Default accept policy for asset with no whitelist authorities
|
||||||
|
#ifndef HARDFORK_415_TIME
|
||||||
|
#define HARDFORK_415_TIME (fc::time_point_sec( 1446652800 ))
|
||||||
|
#endif
|
||||||
4
libraries/chain/hardfork.d/416.hf
Normal file
4
libraries/chain/hardfork.d/416.hf
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
// #416 enforce_white_list is inconsistently applied
|
||||||
|
#ifndef HARDFORK_416_TIME
|
||||||
|
#define HARDFORK_416_TIME (fc::time_point_sec( 1446652800 ))
|
||||||
|
#endif
|
||||||
4
libraries/chain/hardfork.d/419.hf
Normal file
4
libraries/chain/hardfork.d/419.hf
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
// #419 Account can pay fees in blacklisted asset
|
||||||
|
#ifndef HARDFORK_419_TIME
|
||||||
|
#define HARDFORK_419_TIME (fc::time_point_sec( 1446652800 ))
|
||||||
|
#endif
|
||||||
4
libraries/chain/hardfork.d/436.hf
Normal file
4
libraries/chain/hardfork.d/436.hf
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
// #436 Prevent margin call from being triggered unless feed < call price
|
||||||
|
#ifndef HARDFORK_436_TIME
|
||||||
|
#define HARDFORK_436_TIME (fc::time_point_sec( 1450288800 ))
|
||||||
|
#endif
|
||||||
4
libraries/chain/hardfork.d/445.hf
Normal file
4
libraries/chain/hardfork.d/445.hf
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
// #445 Refund create order fees on cancel
|
||||||
|
#ifndef HARDFORK_445_TIME
|
||||||
|
#define HARDFORK_445_TIME (fc::time_point_sec( 1450288800 ))
|
||||||
|
#endif
|
||||||
4
libraries/chain/hardfork.d/453.hf
Normal file
4
libraries/chain/hardfork.d/453.hf
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
// #453 Hardfork to retroactively correct referral percentages
|
||||||
|
#ifndef HARDFORK_453_TIME
|
||||||
|
#define HARDFORK_453_TIME (fc::time_point_sec( 1450288800 ))
|
||||||
|
#endif
|
||||||
4
libraries/chain/hardfork.d/480.hf
Normal file
4
libraries/chain/hardfork.d/480.hf
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
// #480 Fix non-BTS MIA core_exchange_rate check
|
||||||
|
#ifndef HARDFORK_480_TIME
|
||||||
|
#define HARDFORK_480_TIME (fc::time_point_sec( 1450378800 ))
|
||||||
|
#endif
|
||||||
4
libraries/chain/hardfork.d/483.hf
Normal file
4
libraries/chain/hardfork.d/483.hf
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
// #483 Operation history numbering change
|
||||||
|
#ifndef HARDFORK_483_TIME
|
||||||
|
#define HARDFORK_483_TIME (fc::time_point_sec( 1450378800 ))
|
||||||
|
#endif
|
||||||
|
|
@ -289,9 +289,8 @@ namespace graphene { namespace chain {
|
||||||
map< account_id_type, set<account_id_type> > referred_by;
|
map< account_id_type, set<account_id_type> > referred_by;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct by_asset;
|
struct by_account_asset;
|
||||||
struct by_account;
|
struct by_asset_balance;
|
||||||
struct by_balance;
|
|
||||||
/**
|
/**
|
||||||
* @ingroup object_index
|
* @ingroup object_index
|
||||||
*/
|
*/
|
||||||
|
|
@ -299,13 +298,26 @@ namespace graphene { namespace chain {
|
||||||
account_balance_object,
|
account_balance_object,
|
||||||
indexed_by<
|
indexed_by<
|
||||||
ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
|
ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
|
||||||
ordered_unique< tag<by_balance>, composite_key<
|
ordered_unique< tag<by_account_asset>,
|
||||||
account_balance_object,
|
composite_key<
|
||||||
member<account_balance_object, account_id_type, &account_balance_object::owner>,
|
account_balance_object,
|
||||||
member<account_balance_object, asset_id_type, &account_balance_object::asset_type> >
|
member<account_balance_object, account_id_type, &account_balance_object::owner>,
|
||||||
|
member<account_balance_object, asset_id_type, &account_balance_object::asset_type>
|
||||||
|
>
|
||||||
>,
|
>,
|
||||||
ordered_non_unique< tag<by_account>, member<account_balance_object, account_id_type, &account_balance_object::owner> >,
|
ordered_unique< tag<by_asset_balance>,
|
||||||
ordered_non_unique< tag<by_asset>, member<account_balance_object, asset_id_type, &account_balance_object::asset_type> >
|
composite_key<
|
||||||
|
account_balance_object,
|
||||||
|
member<account_balance_object, asset_id_type, &account_balance_object::asset_type>,
|
||||||
|
member<account_balance_object, share_type, &account_balance_object::balance>,
|
||||||
|
member<account_balance_object, account_id_type, &account_balance_object::owner>
|
||||||
|
>,
|
||||||
|
composite_key_compare<
|
||||||
|
std::less< asset_id_type >,
|
||||||
|
std::greater< share_type >,
|
||||||
|
std::less< account_id_type >
|
||||||
|
>
|
||||||
|
>
|
||||||
>
|
>
|
||||||
> account_balance_object_multi_index_type;
|
> account_balance_object_multi_index_type;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,44 +23,12 @@
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <graphene/chain/evaluator.hpp>
|
#include <graphene/chain/evaluator.hpp>
|
||||||
#include <graphene/db/object.hpp>
|
|
||||||
#include <graphene/db/generic_index.hpp>
|
|
||||||
|
|
||||||
namespace graphene { namespace chain {
|
namespace graphene { namespace chain {
|
||||||
|
|
||||||
/**
|
class transfer_to_blind_operation;
|
||||||
* @class blinded_balance_object
|
class transfer_from_blind_operation;
|
||||||
* @brief tracks a blinded balance commitment
|
class blind_transfer_operation;
|
||||||
* @ingroup object
|
|
||||||
* @ingroup protocol
|
|
||||||
*/
|
|
||||||
class blinded_balance_object : public graphene::db::abstract_object<blinded_balance_object>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static const uint8_t space_id = implementation_ids;
|
|
||||||
static const uint8_t type_id = impl_blinded_balance_object_type;
|
|
||||||
|
|
||||||
fc::ecc::commitment_type commitment;
|
|
||||||
asset_id_type asset_id;
|
|
||||||
authority owner;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct by_asset;
|
|
||||||
struct by_owner;
|
|
||||||
struct by_commitment;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @ingroup object_index
|
|
||||||
*/
|
|
||||||
typedef multi_index_container<
|
|
||||||
blinded_balance_object,
|
|
||||||
indexed_by<
|
|
||||||
ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
|
|
||||||
ordered_unique< tag<by_commitment>, member<blinded_balance_object, commitment_type, &blinded_balance_object::commitment> >
|
|
||||||
>
|
|
||||||
> blinded_balance_object_multi_index_type;
|
|
||||||
typedef generic_index<blinded_balance_object, blinded_balance_object_multi_index_type> blinded_balance_index;
|
|
||||||
|
|
||||||
|
|
||||||
class transfer_to_blind_evaluator : public evaluator<transfer_to_blind_evaluator>
|
class transfer_to_blind_evaluator : public evaluator<transfer_to_blind_evaluator>
|
||||||
{
|
{
|
||||||
|
|
@ -90,5 +58,3 @@ class blind_transfer_evaluator : public evaluator<blind_transfer_evaluator>
|
||||||
};
|
};
|
||||||
|
|
||||||
} } // namespace graphene::chain
|
} } // namespace graphene::chain
|
||||||
|
|
||||||
FC_REFLECT_DERIVED( graphene::chain::blinded_balance_object, (graphene::db::object), (commitment)(asset_id)(owner) )
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 Cryptonomex, Inc., and contributors.
|
||||||
|
*
|
||||||
|
* The MIT License
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <graphene/chain/protocol/authority.hpp>
|
||||||
|
#include <graphene/chain/protocol/types.hpp>
|
||||||
|
|
||||||
|
#include <graphene/db/object.hpp>
|
||||||
|
#include <graphene/db/generic_index.hpp>
|
||||||
|
|
||||||
|
#include <fc/crypto/elliptic.hpp>
|
||||||
|
|
||||||
|
namespace graphene { namespace chain {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class blinded_balance_object
|
||||||
|
* @brief tracks a blinded balance commitment
|
||||||
|
* @ingroup object
|
||||||
|
* @ingroup protocol
|
||||||
|
*/
|
||||||
|
class blinded_balance_object : public graphene::db::abstract_object<blinded_balance_object>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static const uint8_t space_id = implementation_ids;
|
||||||
|
static const uint8_t type_id = impl_blinded_balance_object_type;
|
||||||
|
|
||||||
|
fc::ecc::commitment_type commitment;
|
||||||
|
asset_id_type asset_id;
|
||||||
|
authority owner;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct by_asset;
|
||||||
|
struct by_owner;
|
||||||
|
struct by_commitment;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @ingroup object_index
|
||||||
|
*/
|
||||||
|
typedef multi_index_container<
|
||||||
|
blinded_balance_object,
|
||||||
|
indexed_by<
|
||||||
|
ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
|
||||||
|
ordered_unique< tag<by_commitment>, member<blinded_balance_object, commitment_type, &blinded_balance_object::commitment> >
|
||||||
|
>
|
||||||
|
> blinded_balance_object_multi_index_type;
|
||||||
|
typedef generic_index<blinded_balance_object, blinded_balance_object_multi_index_type> blinded_balance_index;
|
||||||
|
|
||||||
|
} } // graphene::chain
|
||||||
|
|
||||||
|
FC_REFLECT_DERIVED( graphene::chain::blinded_balance_object, (graphene::db::object), (commitment)(asset_id)(owner) )
|
||||||
|
|
@ -1,49 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2015 Cryptonomex, Inc., and contributors.
|
|
||||||
*
|
|
||||||
* The MIT License
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#define HARDFORK_357_TIME (fc::time_point_sec( 1444416300 ))
|
|
||||||
#define HARDFORK_359_TIME (fc::time_point_sec( 1444416300 ))
|
|
||||||
#define HARDFORK_385_TIME (fc::time_point_sec( 1445558400 )) // October 23 enforce PARENT.CHILD and allow short names
|
|
||||||
#define HARDFORK_393_TIME (fc::time_point_sec( 2445558400 )) // Refund order creation fee on cancel
|
|
||||||
#define HARDFORK_409_TIME (fc::time_point_sec( 1446652800 ))
|
|
||||||
#define HARDFORK_413_TIME (fc::time_point_sec( 1446652800 ))
|
|
||||||
#define HARDFORK_415_TIME (fc::time_point_sec( 1446652800 ))
|
|
||||||
#define HARDFORK_416_TIME (fc::time_point_sec( 1446652800 ))
|
|
||||||
#define HARDFORK_419_TIME (fc::time_point_sec( 1446652800 ))
|
|
||||||
|
|
||||||
// #436 Prevent margin call from being triggered unless feed < call price
|
|
||||||
#define HARDFORK_436_TIME (fc::time_point_sec( 1450288800 ))
|
|
||||||
|
|
||||||
// #445 Refund create order fees on cancel
|
|
||||||
#define HARDFORK_445_TIME (fc::time_point_sec( 1450288800 ))
|
|
||||||
|
|
||||||
// #453 Hardfork to retroactively correct referral percentages
|
|
||||||
#define HARDFORK_453_TIME (fc::time_point_sec( 1450288800 ))
|
|
||||||
|
|
||||||
// #480 Fix non-CORE MIA core_exchange_rate check
|
|
||||||
#define HARDFORK_480_TIME (fc::time_point_sec( 1450378800 ))
|
|
||||||
|
|
||||||
// #483 Operation history numbering change
|
|
||||||
#define HARDFORK_483_TIME (fc::time_point_sec( 1450378800 ))
|
|
||||||
|
|
@ -22,166 +22,18 @@
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <graphene/chain/protocol/operations.hpp>
|
|
||||||
#include <graphene/chain/evaluator.hpp>
|
#include <graphene/chain/evaluator.hpp>
|
||||||
#include <graphene/chain/database.hpp>
|
#include <graphene/chain/protocol/types.hpp>
|
||||||
|
|
||||||
namespace graphene { namespace chain {
|
namespace graphene { namespace chain {
|
||||||
|
|
||||||
using namespace graphene::db;
|
class account_object;
|
||||||
|
class asset_object;
|
||||||
/**
|
class asset_bitasset_data_object;
|
||||||
* @brief an offer to sell a amount of a asset at a specified exchange rate by a certain time
|
class call_order_object;
|
||||||
* @ingroup object
|
class call_order_update_operation;
|
||||||
* @ingroup protocol
|
class limit_order_cancel_operation;
|
||||||
* @ingroup market
|
class limit_order_create_operation;
|
||||||
*
|
|
||||||
* This limit_order_objects are indexed by @ref expiration and is automatically deleted on the first block after expiration.
|
|
||||||
*/
|
|
||||||
class limit_order_object : public abstract_object<limit_order_object>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static const uint8_t space_id = protocol_ids;
|
|
||||||
static const uint8_t type_id = limit_order_object_type;
|
|
||||||
|
|
||||||
time_point_sec expiration;
|
|
||||||
account_id_type seller;
|
|
||||||
share_type for_sale; ///< asset id is sell_price.base.asset_id
|
|
||||||
price sell_price;
|
|
||||||
share_type deferred_fee;
|
|
||||||
|
|
||||||
pair<asset_id_type,asset_id_type> get_market()const
|
|
||||||
{
|
|
||||||
auto tmp = std::make_pair( sell_price.base.asset_id, sell_price.quote.asset_id );
|
|
||||||
if( tmp.first > tmp.second ) std::swap( tmp.first, tmp.second );
|
|
||||||
return tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
asset amount_for_sale()const { return asset( for_sale, sell_price.base.asset_id ); }
|
|
||||||
asset amount_to_receive()const { return amount_for_sale() * sell_price; }
|
|
||||||
};
|
|
||||||
|
|
||||||
struct by_id;
|
|
||||||
struct by_price;
|
|
||||||
struct by_expiration;
|
|
||||||
struct by_account;
|
|
||||||
typedef multi_index_container<
|
|
||||||
limit_order_object,
|
|
||||||
indexed_by<
|
|
||||||
ordered_unique< tag<by_id>,
|
|
||||||
member< object, object_id_type, &object::id > >,
|
|
||||||
ordered_non_unique< tag<by_expiration>, member< limit_order_object, time_point_sec, &limit_order_object::expiration> >,
|
|
||||||
ordered_unique< tag<by_price>,
|
|
||||||
composite_key< limit_order_object,
|
|
||||||
member< limit_order_object, price, &limit_order_object::sell_price>,
|
|
||||||
member< object, object_id_type, &object::id>
|
|
||||||
>,
|
|
||||||
composite_key_compare< std::greater<price>, std::less<object_id_type> >
|
|
||||||
>,
|
|
||||||
ordered_non_unique< tag<by_account>, member<limit_order_object, account_id_type, &limit_order_object::seller>>
|
|
||||||
>
|
|
||||||
> limit_order_multi_index_type;
|
|
||||||
|
|
||||||
typedef generic_index<limit_order_object, limit_order_multi_index_type> limit_order_index;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @class call_order_object
|
|
||||||
* @brief tracks debt and call price information
|
|
||||||
*
|
|
||||||
* There should only be one call_order_object per asset pair per account and
|
|
||||||
* they will all have the same call price.
|
|
||||||
*/
|
|
||||||
class call_order_object : public abstract_object<call_order_object>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static const uint8_t space_id = protocol_ids;
|
|
||||||
static const uint8_t type_id = call_order_object_type;
|
|
||||||
|
|
||||||
asset get_collateral()const { return asset( collateral, call_price.base.asset_id ); }
|
|
||||||
asset get_debt()const { return asset( debt, debt_type() ); }
|
|
||||||
asset amount_to_receive()const { return get_debt(); }
|
|
||||||
asset_id_type debt_type()const { return call_price.quote.asset_id; }
|
|
||||||
price collateralization()const { return get_collateral() / get_debt(); }
|
|
||||||
|
|
||||||
account_id_type borrower;
|
|
||||||
share_type collateral; ///< call_price.base.asset_id, access via get_collateral
|
|
||||||
share_type debt; ///< call_price.quote.asset_id, access via get_collateral
|
|
||||||
price call_price; ///< Debt / Collateral
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief tracks bitassets scheduled for force settlement at some point in the future.
|
|
||||||
*
|
|
||||||
* On the @ref settlement_date the @ref balance will be converted to the collateral asset
|
|
||||||
* and paid to @ref owner and then this object will be deleted.
|
|
||||||
*/
|
|
||||||
class force_settlement_object : public abstract_object<force_settlement_object>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static const uint8_t space_id = protocol_ids;
|
|
||||||
static const uint8_t type_id = force_settlement_object_type;
|
|
||||||
|
|
||||||
account_id_type owner;
|
|
||||||
asset balance;
|
|
||||||
time_point_sec settlement_date;
|
|
||||||
|
|
||||||
asset_id_type settlement_asset_id()const
|
|
||||||
{ return balance.asset_id; }
|
|
||||||
};
|
|
||||||
|
|
||||||
struct by_collateral;
|
|
||||||
struct by_account;
|
|
||||||
struct by_price;
|
|
||||||
typedef multi_index_container<
|
|
||||||
call_order_object,
|
|
||||||
indexed_by<
|
|
||||||
ordered_unique< tag<by_id>,
|
|
||||||
member< object, object_id_type, &object::id > >,
|
|
||||||
ordered_unique< tag<by_price>,
|
|
||||||
composite_key< call_order_object,
|
|
||||||
member< call_order_object, price, &call_order_object::call_price>,
|
|
||||||
member< object, object_id_type, &object::id>
|
|
||||||
>,
|
|
||||||
composite_key_compare< std::less<price>, std::less<object_id_type> >
|
|
||||||
>,
|
|
||||||
ordered_unique< tag<by_account>,
|
|
||||||
composite_key< call_order_object,
|
|
||||||
member< call_order_object, account_id_type, &call_order_object::borrower >,
|
|
||||||
const_mem_fun< call_order_object, asset_id_type, &call_order_object::debt_type>
|
|
||||||
>
|
|
||||||
>,
|
|
||||||
ordered_unique< tag<by_collateral>,
|
|
||||||
composite_key< call_order_object,
|
|
||||||
const_mem_fun< call_order_object, price, &call_order_object::collateralization >,
|
|
||||||
member< object, object_id_type, &object::id >
|
|
||||||
>
|
|
||||||
>
|
|
||||||
>
|
|
||||||
> call_order_multi_index_type;
|
|
||||||
|
|
||||||
struct by_expiration;
|
|
||||||
typedef multi_index_container<
|
|
||||||
force_settlement_object,
|
|
||||||
indexed_by<
|
|
||||||
ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
|
|
||||||
ordered_non_unique< tag<by_account>,
|
|
||||||
member<force_settlement_object, account_id_type, &force_settlement_object::owner>
|
|
||||||
>,
|
|
||||||
ordered_non_unique< tag<by_expiration>,
|
|
||||||
composite_key< force_settlement_object,
|
|
||||||
const_mem_fun<force_settlement_object, asset_id_type, &force_settlement_object::settlement_asset_id>,
|
|
||||||
member<force_settlement_object, time_point_sec, &force_settlement_object::settlement_date>
|
|
||||||
>
|
|
||||||
>
|
|
||||||
>
|
|
||||||
> force_settlement_object_multi_index_type;
|
|
||||||
|
|
||||||
|
|
||||||
typedef generic_index<call_order_object, call_order_multi_index_type> call_order_index;
|
|
||||||
typedef generic_index<force_settlement_object, force_settlement_object_multi_index_type> force_settlement_index;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class limit_order_create_evaluator : public evaluator<limit_order_create_evaluator>
|
class limit_order_create_evaluator : public evaluator<limit_order_create_evaluator>
|
||||||
{
|
{
|
||||||
|
|
@ -232,13 +84,3 @@ namespace graphene { namespace chain {
|
||||||
};
|
};
|
||||||
|
|
||||||
} } // graphene::chain
|
} } // graphene::chain
|
||||||
|
|
||||||
FC_REFLECT_DERIVED( graphene::chain::limit_order_object,
|
|
||||||
(graphene::db::object),
|
|
||||||
(expiration)(seller)(for_sale)(sell_price)(deferred_fee)
|
|
||||||
)
|
|
||||||
|
|
||||||
FC_REFLECT_DERIVED( graphene::chain::call_order_object, (graphene::db::object),
|
|
||||||
(borrower)(collateral)(debt)(call_price) )
|
|
||||||
|
|
||||||
FC_REFLECT( graphene::chain::force_settlement_object, (owner)(balance)(settlement_date) )
|
|
||||||
|
|
|
||||||
197
libraries/chain/include/graphene/chain/market_object.hpp
Normal file
197
libraries/chain/include/graphene/chain/market_object.hpp
Normal file
|
|
@ -0,0 +1,197 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 Cryptonomex, Inc., and contributors.
|
||||||
|
*
|
||||||
|
* The MIT License
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <graphene/chain/protocol/asset.hpp>
|
||||||
|
#include <graphene/chain/protocol/types.hpp>
|
||||||
|
#include <graphene/db/generic_index.hpp>
|
||||||
|
#include <graphene/db/object.hpp>
|
||||||
|
|
||||||
|
#include <boost/multi_index/composite_key.hpp>
|
||||||
|
|
||||||
|
namespace graphene { namespace chain {
|
||||||
|
|
||||||
|
using namespace graphene::db;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief an offer to sell a amount of a asset at a specified exchange rate by a certain time
|
||||||
|
* @ingroup object
|
||||||
|
* @ingroup protocol
|
||||||
|
* @ingroup market
|
||||||
|
*
|
||||||
|
* This limit_order_objects are indexed by @ref expiration and is automatically deleted on the first block after expiration.
|
||||||
|
*/
|
||||||
|
class limit_order_object : public abstract_object<limit_order_object>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static const uint8_t space_id = protocol_ids;
|
||||||
|
static const uint8_t type_id = limit_order_object_type;
|
||||||
|
|
||||||
|
time_point_sec expiration;
|
||||||
|
account_id_type seller;
|
||||||
|
share_type for_sale; ///< asset id is sell_price.base.asset_id
|
||||||
|
price sell_price;
|
||||||
|
share_type deferred_fee;
|
||||||
|
|
||||||
|
pair<asset_id_type,asset_id_type> get_market()const
|
||||||
|
{
|
||||||
|
auto tmp = std::make_pair( sell_price.base.asset_id, sell_price.quote.asset_id );
|
||||||
|
if( tmp.first > tmp.second ) std::swap( tmp.first, tmp.second );
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
asset amount_for_sale()const { return asset( for_sale, sell_price.base.asset_id ); }
|
||||||
|
asset amount_to_receive()const { return amount_for_sale() * sell_price; }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct by_id;
|
||||||
|
struct by_price;
|
||||||
|
struct by_expiration;
|
||||||
|
struct by_account;
|
||||||
|
typedef multi_index_container<
|
||||||
|
limit_order_object,
|
||||||
|
indexed_by<
|
||||||
|
ordered_unique< tag<by_id>,
|
||||||
|
member< object, object_id_type, &object::id > >,
|
||||||
|
ordered_non_unique< tag<by_expiration>, member< limit_order_object, time_point_sec, &limit_order_object::expiration> >,
|
||||||
|
ordered_unique< tag<by_price>,
|
||||||
|
composite_key< limit_order_object,
|
||||||
|
member< limit_order_object, price, &limit_order_object::sell_price>,
|
||||||
|
member< object, object_id_type, &object::id>
|
||||||
|
>,
|
||||||
|
composite_key_compare< std::greater<price>, std::less<object_id_type> >
|
||||||
|
>,
|
||||||
|
ordered_non_unique< tag<by_account>, member<limit_order_object, account_id_type, &limit_order_object::seller>>
|
||||||
|
>
|
||||||
|
> limit_order_multi_index_type;
|
||||||
|
|
||||||
|
typedef generic_index<limit_order_object, limit_order_multi_index_type> limit_order_index;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class call_order_object
|
||||||
|
* @brief tracks debt and call price information
|
||||||
|
*
|
||||||
|
* There should only be one call_order_object per asset pair per account and
|
||||||
|
* they will all have the same call price.
|
||||||
|
*/
|
||||||
|
class call_order_object : public abstract_object<call_order_object>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static const uint8_t space_id = protocol_ids;
|
||||||
|
static const uint8_t type_id = call_order_object_type;
|
||||||
|
|
||||||
|
asset get_collateral()const { return asset( collateral, call_price.base.asset_id ); }
|
||||||
|
asset get_debt()const { return asset( debt, debt_type() ); }
|
||||||
|
asset amount_to_receive()const { return get_debt(); }
|
||||||
|
asset_id_type debt_type()const { return call_price.quote.asset_id; }
|
||||||
|
price collateralization()const { return get_collateral() / get_debt(); }
|
||||||
|
|
||||||
|
account_id_type borrower;
|
||||||
|
share_type collateral; ///< call_price.base.asset_id, access via get_collateral
|
||||||
|
share_type debt; ///< call_price.quote.asset_id, access via get_collateral
|
||||||
|
price call_price; ///< Debt / Collateral
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief tracks bitassets scheduled for force settlement at some point in the future.
|
||||||
|
*
|
||||||
|
* On the @ref settlement_date the @ref balance will be converted to the collateral asset
|
||||||
|
* and paid to @ref owner and then this object will be deleted.
|
||||||
|
*/
|
||||||
|
class force_settlement_object : public abstract_object<force_settlement_object>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static const uint8_t space_id = protocol_ids;
|
||||||
|
static const uint8_t type_id = force_settlement_object_type;
|
||||||
|
|
||||||
|
account_id_type owner;
|
||||||
|
asset balance;
|
||||||
|
time_point_sec settlement_date;
|
||||||
|
|
||||||
|
asset_id_type settlement_asset_id()const
|
||||||
|
{ return balance.asset_id; }
|
||||||
|
};
|
||||||
|
|
||||||
|
struct by_collateral;
|
||||||
|
struct by_account;
|
||||||
|
struct by_price;
|
||||||
|
typedef multi_index_container<
|
||||||
|
call_order_object,
|
||||||
|
indexed_by<
|
||||||
|
ordered_unique< tag<by_id>,
|
||||||
|
member< object, object_id_type, &object::id > >,
|
||||||
|
ordered_unique< tag<by_price>,
|
||||||
|
composite_key< call_order_object,
|
||||||
|
member< call_order_object, price, &call_order_object::call_price>,
|
||||||
|
member< object, object_id_type, &object::id>
|
||||||
|
>,
|
||||||
|
composite_key_compare< std::less<price>, std::less<object_id_type> >
|
||||||
|
>,
|
||||||
|
ordered_unique< tag<by_account>,
|
||||||
|
composite_key< call_order_object,
|
||||||
|
member< call_order_object, account_id_type, &call_order_object::borrower >,
|
||||||
|
const_mem_fun< call_order_object, asset_id_type, &call_order_object::debt_type>
|
||||||
|
>
|
||||||
|
>,
|
||||||
|
ordered_unique< tag<by_collateral>,
|
||||||
|
composite_key< call_order_object,
|
||||||
|
const_mem_fun< call_order_object, price, &call_order_object::collateralization >,
|
||||||
|
member< object, object_id_type, &object::id >
|
||||||
|
>
|
||||||
|
>
|
||||||
|
>
|
||||||
|
> call_order_multi_index_type;
|
||||||
|
|
||||||
|
struct by_expiration;
|
||||||
|
typedef multi_index_container<
|
||||||
|
force_settlement_object,
|
||||||
|
indexed_by<
|
||||||
|
ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
|
||||||
|
ordered_non_unique< tag<by_account>,
|
||||||
|
member<force_settlement_object, account_id_type, &force_settlement_object::owner>
|
||||||
|
>,
|
||||||
|
ordered_non_unique< tag<by_expiration>,
|
||||||
|
composite_key< force_settlement_object,
|
||||||
|
const_mem_fun<force_settlement_object, asset_id_type, &force_settlement_object::settlement_asset_id>,
|
||||||
|
member<force_settlement_object, time_point_sec, &force_settlement_object::settlement_date>
|
||||||
|
>
|
||||||
|
>
|
||||||
|
>
|
||||||
|
> force_settlement_object_multi_index_type;
|
||||||
|
|
||||||
|
|
||||||
|
typedef generic_index<call_order_object, call_order_multi_index_type> call_order_index;
|
||||||
|
typedef generic_index<force_settlement_object, force_settlement_object_multi_index_type> force_settlement_index;
|
||||||
|
|
||||||
|
} } // graphene::chain
|
||||||
|
|
||||||
|
FC_REFLECT_DERIVED( graphene::chain::limit_order_object,
|
||||||
|
(graphene::db::object),
|
||||||
|
(expiration)(seller)(for_sale)(sell_price)(deferred_fee)
|
||||||
|
)
|
||||||
|
|
||||||
|
FC_REFLECT_DERIVED( graphene::chain::call_order_object, (graphene::db::object),
|
||||||
|
(borrower)(collateral)(debt)(call_price) )
|
||||||
|
|
||||||
|
FC_REFLECT( graphene::chain::force_settlement_object, (owner)(balance)(settlement_date) )
|
||||||
|
|
@ -251,16 +251,67 @@ namespace graphene { namespace chain {
|
||||||
bool is_valid_v1( const std::string& base58str );
|
bool is_valid_v1( const std::string& base58str );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct extended_public_key_type
|
||||||
|
{
|
||||||
|
struct binary_key
|
||||||
|
{
|
||||||
|
binary_key() {}
|
||||||
|
uint32_t check = 0;
|
||||||
|
fc::ecc::extended_key_data data;
|
||||||
|
};
|
||||||
|
|
||||||
|
fc::ecc::extended_key_data key_data;
|
||||||
|
|
||||||
|
extended_public_key_type();
|
||||||
|
extended_public_key_type( const fc::ecc::extended_key_data& data );
|
||||||
|
extended_public_key_type( const fc::ecc::extended_public_key& extpubkey );
|
||||||
|
explicit extended_public_key_type( const std::string& base58str );
|
||||||
|
operator fc::ecc::extended_public_key() const;
|
||||||
|
explicit operator std::string() const;
|
||||||
|
friend bool operator == ( const extended_public_key_type& p1, const fc::ecc::extended_public_key& p2);
|
||||||
|
friend bool operator == ( const extended_public_key_type& p1, const extended_public_key_type& p2);
|
||||||
|
friend bool operator != ( const extended_public_key_type& p1, const extended_public_key_type& p2);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct extended_private_key_type
|
||||||
|
{
|
||||||
|
struct binary_key
|
||||||
|
{
|
||||||
|
binary_key() {}
|
||||||
|
uint32_t check = 0;
|
||||||
|
fc::ecc::extended_key_data data;
|
||||||
|
};
|
||||||
|
|
||||||
|
fc::ecc::extended_key_data key_data;
|
||||||
|
|
||||||
|
extended_private_key_type();
|
||||||
|
extended_private_key_type( const fc::ecc::extended_key_data& data );
|
||||||
|
extended_private_key_type( const fc::ecc::extended_private_key& extprivkey );
|
||||||
|
explicit extended_private_key_type( const std::string& base58str );
|
||||||
|
operator fc::ecc::extended_private_key() const;
|
||||||
|
explicit operator std::string() const;
|
||||||
|
friend bool operator == ( const extended_private_key_type& p1, const fc::ecc::extended_private_key& p2);
|
||||||
|
friend bool operator == ( const extended_private_key_type& p1, const extended_private_key_type& p2);
|
||||||
|
friend bool operator != ( const extended_private_key_type& p1, const extended_private_key_type& p2);
|
||||||
|
};
|
||||||
} } // graphene::chain
|
} } // graphene::chain
|
||||||
|
|
||||||
namespace fc
|
namespace fc
|
||||||
{
|
{
|
||||||
void to_variant( const graphene::chain::public_key_type& var, fc::variant& vo );
|
void to_variant( const graphene::chain::public_key_type& var, fc::variant& vo );
|
||||||
void from_variant( const fc::variant& var, graphene::chain::public_key_type& vo );
|
void from_variant( const fc::variant& var, graphene::chain::public_key_type& vo );
|
||||||
|
void to_variant( const graphene::chain::extended_public_key_type& var, fc::variant& vo );
|
||||||
|
void from_variant( const fc::variant& var, graphene::chain::extended_public_key_type& vo );
|
||||||
|
void to_variant( const graphene::chain::extended_private_key_type& var, fc::variant& vo );
|
||||||
|
void from_variant( const fc::variant& var, graphene::chain::extended_private_key_type& vo );
|
||||||
}
|
}
|
||||||
|
|
||||||
FC_REFLECT( graphene::chain::public_key_type, (key_data) )
|
FC_REFLECT( graphene::chain::public_key_type, (key_data) )
|
||||||
FC_REFLECT( graphene::chain::public_key_type::binary_key, (data)(check) )
|
FC_REFLECT( graphene::chain::public_key_type::binary_key, (data)(check) )
|
||||||
|
FC_REFLECT( graphene::chain::extended_public_key_type, (key_data) )
|
||||||
|
FC_REFLECT( graphene::chain::extended_public_key_type::binary_key, (check)(data) )
|
||||||
|
FC_REFLECT( graphene::chain::extended_private_key_type, (key_data) )
|
||||||
|
FC_REFLECT( graphene::chain::extended_private_key_type::binary_key, (check)(data) )
|
||||||
|
|
||||||
FC_REFLECT_ENUM( graphene::chain::object_type,
|
FC_REFLECT_ENUM( graphene::chain::object_type,
|
||||||
(null_object_type)
|
(null_object_type)
|
||||||
|
|
|
||||||
|
|
@ -26,137 +26,6 @@
|
||||||
|
|
||||||
namespace graphene { namespace chain {
|
namespace graphene { namespace chain {
|
||||||
|
|
||||||
/**
|
|
||||||
* @defgroup worker_types Implementations of the various worker types in the system
|
|
||||||
*
|
|
||||||
* The system has various worker types, which do different things with the money they are paid. These worker types
|
|
||||||
* and their semantics are specified here.
|
|
||||||
*
|
|
||||||
* All worker types exist as a struct containing the data this worker needs to evaluate, as well as a method
|
|
||||||
* pay_worker, which takes a pay amount and a non-const database reference, and applies the worker's specific pay
|
|
||||||
* semantics to the worker_type struct and/or the database. Furthermore, all worker types have an initializer,
|
|
||||||
* which is a struct containing the data needed to create that kind of worker.
|
|
||||||
*
|
|
||||||
* Each initializer type has a method, init, which takes a non-const database reference, a const reference to the
|
|
||||||
* worker object being created, and a non-const reference to the specific *_worker_type object to initialize. The
|
|
||||||
* init method creates any further objects, and initializes the worker_type object as necessary according to the
|
|
||||||
* semantics of that particular worker type.
|
|
||||||
*
|
|
||||||
* To create a new worker type, define a my_new_worker_type struct with a pay_worker method which updates the
|
|
||||||
* my_new_worker_type object and/or the database. Create a my_new_worker_type::initializer struct with an init
|
|
||||||
* method and any data members necessary to create a new worker of this type. Reflect my_new_worker_type and
|
|
||||||
* my_new_worker_type::initializer into FC's type system, and add them to @ref worker_type and @ref
|
|
||||||
* worker_initializer respectively. Make sure the order of types in @ref worker_type and @ref worker_initializer
|
|
||||||
* remains the same.
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* @brief A worker who returns all of his pay to the reserve
|
|
||||||
*
|
|
||||||
* This worker type pays everything he receives back to the network's reserve funds pool.
|
|
||||||
*/
|
|
||||||
struct refund_worker_type
|
|
||||||
{
|
|
||||||
/// Record of how much this worker has burned in his lifetime
|
|
||||||
share_type total_burned;
|
|
||||||
|
|
||||||
void pay_worker(share_type pay, database&);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief A worker who sends his pay to a vesting balance
|
|
||||||
*
|
|
||||||
* This worker type takes all of his pay and places it into a vesting balance
|
|
||||||
*/
|
|
||||||
struct vesting_balance_worker_type
|
|
||||||
{
|
|
||||||
/// The balance this worker pays into
|
|
||||||
vesting_balance_id_type balance;
|
|
||||||
|
|
||||||
void pay_worker(share_type pay, database& db);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief A worker who permanently destroys all of his pay
|
|
||||||
*
|
|
||||||
* This worker sends all pay he receives to the null account.
|
|
||||||
*/
|
|
||||||
struct burn_worker_type
|
|
||||||
{
|
|
||||||
/// Record of how much this worker has burned in his lifetime
|
|
||||||
share_type total_burned;
|
|
||||||
|
|
||||||
void pay_worker(share_type pay, database&);
|
|
||||||
};
|
|
||||||
///@}
|
|
||||||
|
|
||||||
// The ordering of types in these two static variants MUST be the same.
|
|
||||||
typedef static_variant<
|
|
||||||
refund_worker_type,
|
|
||||||
vesting_balance_worker_type,
|
|
||||||
burn_worker_type
|
|
||||||
> worker_type;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Worker object contains the details of a blockchain worker. See @ref workers for details.
|
|
||||||
*/
|
|
||||||
class worker_object : public abstract_object<worker_object>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
static const uint8_t space_id = protocol_ids;
|
|
||||||
static const uint8_t type_id = worker_object_type;
|
|
||||||
|
|
||||||
/// ID of the account which owns this worker
|
|
||||||
account_id_type worker_account;
|
|
||||||
/// Time at which this worker begins receiving pay, if elected
|
|
||||||
time_point_sec work_begin_date;
|
|
||||||
/// Time at which this worker will cease to receive pay. Worker will be deleted at this time
|
|
||||||
time_point_sec work_end_date;
|
|
||||||
/// Amount in CORE this worker will be paid each day
|
|
||||||
share_type daily_pay;
|
|
||||||
/// ID of this worker's pay balance
|
|
||||||
worker_type worker;
|
|
||||||
/// Human-readable name for the worker
|
|
||||||
string name;
|
|
||||||
/// URL to a web page representing this worker
|
|
||||||
string url;
|
|
||||||
|
|
||||||
/// Voting ID which represents approval of this worker
|
|
||||||
vote_id_type vote_for;
|
|
||||||
/// Voting ID which represents disapproval of this worker
|
|
||||||
vote_id_type vote_against;
|
|
||||||
|
|
||||||
uint64_t total_votes_for = 0;
|
|
||||||
uint64_t total_votes_against = 0;
|
|
||||||
|
|
||||||
bool is_active(fc::time_point_sec now)const {
|
|
||||||
return now >= work_begin_date && now <= work_end_date;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// TODO: remove unused argument
|
|
||||||
share_type approving_stake(const vector<uint64_t>& stake_vote_tallies)const {
|
|
||||||
return int64_t( total_votes_for ) - int64_t( total_votes_against );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
struct by_account;
|
|
||||||
struct by_vote_for;
|
|
||||||
struct by_vote_against;
|
|
||||||
typedef multi_index_container<
|
|
||||||
worker_object,
|
|
||||||
indexed_by<
|
|
||||||
ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
|
|
||||||
ordered_non_unique< tag<by_account>, member< worker_object, account_id_type, &worker_object::worker_account > >,
|
|
||||||
ordered_unique< tag<by_vote_for>, member< worker_object, vote_id_type, &worker_object::vote_for > >,
|
|
||||||
ordered_unique< tag<by_vote_against>, member< worker_object, vote_id_type, &worker_object::vote_against > >
|
|
||||||
>
|
|
||||||
> worker_object_multi_index_type;
|
|
||||||
|
|
||||||
//typedef flat_index<worker_object> worker_index;
|
|
||||||
using worker_index = generic_index<worker_object, worker_object_multi_index_type>;
|
|
||||||
|
|
||||||
class worker_create_evaluator : public evaluator<worker_create_evaluator>
|
class worker_create_evaluator : public evaluator<worker_create_evaluator>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
@ -167,21 +36,3 @@ namespace graphene { namespace chain {
|
||||||
};
|
};
|
||||||
|
|
||||||
} } // graphene::chain
|
} } // graphene::chain
|
||||||
|
|
||||||
FC_REFLECT( graphene::chain::refund_worker_type, (total_burned) )
|
|
||||||
FC_REFLECT( graphene::chain::vesting_balance_worker_type, (balance) )
|
|
||||||
FC_REFLECT( graphene::chain::burn_worker_type, (total_burned) )
|
|
||||||
FC_REFLECT_TYPENAME( graphene::chain::worker_type )
|
|
||||||
FC_REFLECT_DERIVED( graphene::chain::worker_object, (graphene::db::object),
|
|
||||||
(worker_account)
|
|
||||||
(work_begin_date)
|
|
||||||
(work_end_date)
|
|
||||||
(daily_pay)
|
|
||||||
(worker)
|
|
||||||
(vote_for)
|
|
||||||
(vote_against)
|
|
||||||
(total_votes_for)
|
|
||||||
(total_votes_against)
|
|
||||||
(name)
|
|
||||||
(url)
|
|
||||||
)
|
|
||||||
|
|
|
||||||
177
libraries/chain/include/graphene/chain/worker_object.hpp
Normal file
177
libraries/chain/include/graphene/chain/worker_object.hpp
Normal file
|
|
@ -0,0 +1,177 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2015 Cryptonomex, Inc., and contributors.
|
||||||
|
*
|
||||||
|
* The MIT License
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
* of this software and associated documentation files (the "Software"), to deal
|
||||||
|
* in the Software without restriction, including without limitation the rights
|
||||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
* copies of the Software, and to permit persons to whom the Software is
|
||||||
|
* furnished to do so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in
|
||||||
|
* all copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
* THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
#pragma once
|
||||||
|
#include <graphene/db/object.hpp>
|
||||||
|
#include <graphene/db/generic_index.hpp>
|
||||||
|
|
||||||
|
namespace graphene { namespace chain {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @defgroup worker_types Implementations of the various worker types in the system
|
||||||
|
*
|
||||||
|
* The system has various worker types, which do different things with the money they are paid. These worker types
|
||||||
|
* and their semantics are specified here.
|
||||||
|
*
|
||||||
|
* All worker types exist as a struct containing the data this worker needs to evaluate, as well as a method
|
||||||
|
* pay_worker, which takes a pay amount and a non-const database reference, and applies the worker's specific pay
|
||||||
|
* semantics to the worker_type struct and/or the database. Furthermore, all worker types have an initializer,
|
||||||
|
* which is a struct containing the data needed to create that kind of worker.
|
||||||
|
*
|
||||||
|
* Each initializer type has a method, init, which takes a non-const database reference, a const reference to the
|
||||||
|
* worker object being created, and a non-const reference to the specific *_worker_type object to initialize. The
|
||||||
|
* init method creates any further objects, and initializes the worker_type object as necessary according to the
|
||||||
|
* semantics of that particular worker type.
|
||||||
|
*
|
||||||
|
* To create a new worker type, define a my_new_worker_type struct with a pay_worker method which updates the
|
||||||
|
* my_new_worker_type object and/or the database. Create a my_new_worker_type::initializer struct with an init
|
||||||
|
* method and any data members necessary to create a new worker of this type. Reflect my_new_worker_type and
|
||||||
|
* my_new_worker_type::initializer into FC's type system, and add them to @ref worker_type and @ref
|
||||||
|
* worker_initializer respectively. Make sure the order of types in @ref worker_type and @ref worker_initializer
|
||||||
|
* remains the same.
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @brief A worker who returns all of his pay to the reserve
|
||||||
|
*
|
||||||
|
* This worker type pays everything he receives back to the network's reserve funds pool.
|
||||||
|
*/
|
||||||
|
struct refund_worker_type
|
||||||
|
{
|
||||||
|
/// Record of how much this worker has burned in his lifetime
|
||||||
|
share_type total_burned;
|
||||||
|
|
||||||
|
void pay_worker(share_type pay, database&);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief A worker who sends his pay to a vesting balance
|
||||||
|
*
|
||||||
|
* This worker type takes all of his pay and places it into a vesting balance
|
||||||
|
*/
|
||||||
|
struct vesting_balance_worker_type
|
||||||
|
{
|
||||||
|
/// The balance this worker pays into
|
||||||
|
vesting_balance_id_type balance;
|
||||||
|
|
||||||
|
void pay_worker(share_type pay, database& db);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief A worker who permanently destroys all of his pay
|
||||||
|
*
|
||||||
|
* This worker sends all pay he receives to the null account.
|
||||||
|
*/
|
||||||
|
struct burn_worker_type
|
||||||
|
{
|
||||||
|
/// Record of how much this worker has burned in his lifetime
|
||||||
|
share_type total_burned;
|
||||||
|
|
||||||
|
void pay_worker(share_type pay, database&);
|
||||||
|
};
|
||||||
|
///@}
|
||||||
|
|
||||||
|
// The ordering of types in these two static variants MUST be the same.
|
||||||
|
typedef static_variant<
|
||||||
|
refund_worker_type,
|
||||||
|
vesting_balance_worker_type,
|
||||||
|
burn_worker_type
|
||||||
|
> worker_type;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Worker object contains the details of a blockchain worker. See @ref workers for details.
|
||||||
|
*/
|
||||||
|
class worker_object : public abstract_object<worker_object>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static const uint8_t space_id = protocol_ids;
|
||||||
|
static const uint8_t type_id = worker_object_type;
|
||||||
|
|
||||||
|
/// ID of the account which owns this worker
|
||||||
|
account_id_type worker_account;
|
||||||
|
/// Time at which this worker begins receiving pay, if elected
|
||||||
|
time_point_sec work_begin_date;
|
||||||
|
/// Time at which this worker will cease to receive pay. Worker will be deleted at this time
|
||||||
|
time_point_sec work_end_date;
|
||||||
|
/// Amount in CORE this worker will be paid each day
|
||||||
|
share_type daily_pay;
|
||||||
|
/// ID of this worker's pay balance
|
||||||
|
worker_type worker;
|
||||||
|
/// Human-readable name for the worker
|
||||||
|
string name;
|
||||||
|
/// URL to a web page representing this worker
|
||||||
|
string url;
|
||||||
|
|
||||||
|
/// Voting ID which represents approval of this worker
|
||||||
|
vote_id_type vote_for;
|
||||||
|
/// Voting ID which represents disapproval of this worker
|
||||||
|
vote_id_type vote_against;
|
||||||
|
|
||||||
|
uint64_t total_votes_for = 0;
|
||||||
|
uint64_t total_votes_against = 0;
|
||||||
|
|
||||||
|
bool is_active(fc::time_point_sec now)const {
|
||||||
|
return now >= work_begin_date && now <= work_end_date;
|
||||||
|
}
|
||||||
|
|
||||||
|
share_type approving_stake()const {
|
||||||
|
return int64_t( total_votes_for ) - int64_t( total_votes_against );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct by_account;
|
||||||
|
struct by_vote_for;
|
||||||
|
struct by_vote_against;
|
||||||
|
typedef multi_index_container<
|
||||||
|
worker_object,
|
||||||
|
indexed_by<
|
||||||
|
ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
|
||||||
|
ordered_non_unique< tag<by_account>, member< worker_object, account_id_type, &worker_object::worker_account > >,
|
||||||
|
ordered_unique< tag<by_vote_for>, member< worker_object, vote_id_type, &worker_object::vote_for > >,
|
||||||
|
ordered_unique< tag<by_vote_against>, member< worker_object, vote_id_type, &worker_object::vote_against > >
|
||||||
|
>
|
||||||
|
> worker_object_multi_index_type;
|
||||||
|
|
||||||
|
//typedef flat_index<worker_object> worker_index;
|
||||||
|
using worker_index = generic_index<worker_object, worker_object_multi_index_type>;
|
||||||
|
|
||||||
|
} } // graphene::chain
|
||||||
|
|
||||||
|
FC_REFLECT( graphene::chain::refund_worker_type, (total_burned) )
|
||||||
|
FC_REFLECT( graphene::chain::vesting_balance_worker_type, (balance) )
|
||||||
|
FC_REFLECT( graphene::chain::burn_worker_type, (total_burned) )
|
||||||
|
FC_REFLECT_TYPENAME( graphene::chain::worker_type )
|
||||||
|
FC_REFLECT_DERIVED( graphene::chain::worker_object, (graphene::db::object),
|
||||||
|
(worker_account)
|
||||||
|
(work_begin_date)
|
||||||
|
(work_end_date)
|
||||||
|
(daily_pay)
|
||||||
|
(worker)
|
||||||
|
(vote_for)
|
||||||
|
(vote_against)
|
||||||
|
(total_votes_for)
|
||||||
|
(total_votes_against)
|
||||||
|
(name)
|
||||||
|
(url)
|
||||||
|
)
|
||||||
|
|
@ -22,12 +22,14 @@
|
||||||
* THE SOFTWARE.
|
* THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include <graphene/chain/account_object.hpp>
|
#include <graphene/chain/account_object.hpp>
|
||||||
|
#include <graphene/chain/asset_object.hpp>
|
||||||
|
#include <graphene/chain/database.hpp>
|
||||||
#include <graphene/chain/exceptions.hpp>
|
#include <graphene/chain/exceptions.hpp>
|
||||||
#include <graphene/chain/hardfork.hpp>
|
#include <graphene/chain/hardfork.hpp>
|
||||||
#include <graphene/chain/market_evaluator.hpp>
|
#include <graphene/chain/market_evaluator.hpp>
|
||||||
|
#include <graphene/chain/market_object.hpp>
|
||||||
|
|
||||||
#include <fc/smart_ref_impl.hpp>
|
#include <graphene/chain/protocol/market.hpp>
|
||||||
#include <graphene/chain/protocol/fee_schedule.hpp>
|
|
||||||
|
|
||||||
#include <fc/uint128.hpp>
|
#include <fc/uint128.hpp>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -111,6 +111,114 @@ namespace graphene { namespace chain {
|
||||||
{
|
{
|
||||||
return p1.key_data != p2.key_data;
|
return p1.key_data != p2.key_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// extended_public_key_type
|
||||||
|
|
||||||
|
extended_public_key_type::extended_public_key_type():key_data(){};
|
||||||
|
|
||||||
|
extended_public_key_type::extended_public_key_type( const fc::ecc::extended_key_data& data )
|
||||||
|
:key_data( data ){};
|
||||||
|
|
||||||
|
extended_public_key_type::extended_public_key_type( const fc::ecc::extended_public_key& extpubkey )
|
||||||
|
{
|
||||||
|
key_data = extpubkey.serialize_extended();
|
||||||
|
};
|
||||||
|
|
||||||
|
extended_public_key_type::extended_public_key_type( const std::string& base58str )
|
||||||
|
{
|
||||||
|
std::string prefix( GRAPHENE_ADDRESS_PREFIX );
|
||||||
|
|
||||||
|
const size_t prefix_len = prefix.size();
|
||||||
|
FC_ASSERT( base58str.size() > prefix_len );
|
||||||
|
FC_ASSERT( base58str.substr( 0, prefix_len ) == prefix , "", ("base58str", base58str) );
|
||||||
|
auto bin = fc::from_base58( base58str.substr( prefix_len ) );
|
||||||
|
auto bin_key = fc::raw::unpack<binary_key>(bin);
|
||||||
|
FC_ASSERT( fc::ripemd160::hash( bin_key.data.data, bin_key.data.size() )._hash[0] == bin_key.check );
|
||||||
|
key_data = bin_key.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
extended_public_key_type::operator fc::ecc::extended_public_key() const
|
||||||
|
{
|
||||||
|
return fc::ecc::extended_public_key::deserialize( key_data );
|
||||||
|
}
|
||||||
|
|
||||||
|
extended_public_key_type::operator std::string() const
|
||||||
|
{
|
||||||
|
binary_key k;
|
||||||
|
k.data = key_data;
|
||||||
|
k.check = fc::ripemd160::hash( k.data.data, k.data.size() )._hash[0];
|
||||||
|
auto data = fc::raw::pack( k );
|
||||||
|
return GRAPHENE_ADDRESS_PREFIX + fc::to_base58( data.data(), data.size() );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator == ( const extended_public_key_type& p1, const fc::ecc::extended_public_key& p2)
|
||||||
|
{
|
||||||
|
return p1.key_data == p2.serialize_extended();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator == ( const extended_public_key_type& p1, const extended_public_key_type& p2)
|
||||||
|
{
|
||||||
|
return p1.key_data == p2.key_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator != ( const extended_public_key_type& p1, const extended_public_key_type& p2)
|
||||||
|
{
|
||||||
|
return p1.key_data != p2.key_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
// extended_private_key_type
|
||||||
|
|
||||||
|
extended_private_key_type::extended_private_key_type():key_data(){};
|
||||||
|
|
||||||
|
extended_private_key_type::extended_private_key_type( const fc::ecc::extended_key_data& data )
|
||||||
|
:key_data( data ){};
|
||||||
|
|
||||||
|
extended_private_key_type::extended_private_key_type( const fc::ecc::extended_private_key& extprivkey )
|
||||||
|
{
|
||||||
|
key_data = extprivkey.serialize_extended();
|
||||||
|
};
|
||||||
|
|
||||||
|
extended_private_key_type::extended_private_key_type( const std::string& base58str )
|
||||||
|
{
|
||||||
|
std::string prefix( GRAPHENE_ADDRESS_PREFIX );
|
||||||
|
|
||||||
|
const size_t prefix_len = prefix.size();
|
||||||
|
FC_ASSERT( base58str.size() > prefix_len );
|
||||||
|
FC_ASSERT( base58str.substr( 0, prefix_len ) == prefix , "", ("base58str", base58str) );
|
||||||
|
auto bin = fc::from_base58( base58str.substr( prefix_len ) );
|
||||||
|
auto bin_key = fc::raw::unpack<binary_key>(bin);
|
||||||
|
FC_ASSERT( fc::ripemd160::hash( bin_key.data.data, bin_key.data.size() )._hash[0] == bin_key.check );
|
||||||
|
key_data = bin_key.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
extended_private_key_type::operator fc::ecc::extended_private_key() const
|
||||||
|
{
|
||||||
|
return fc::ecc::extended_private_key::deserialize( key_data );
|
||||||
|
}
|
||||||
|
|
||||||
|
extended_private_key_type::operator std::string() const
|
||||||
|
{
|
||||||
|
binary_key k;
|
||||||
|
k.data = key_data;
|
||||||
|
k.check = fc::ripemd160::hash( k.data.data, k.data.size() )._hash[0];
|
||||||
|
auto data = fc::raw::pack( k );
|
||||||
|
return GRAPHENE_ADDRESS_PREFIX + fc::to_base58( data.data(), data.size() );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator == ( const extended_private_key_type& p1, const fc::ecc::extended_public_key& p2)
|
||||||
|
{
|
||||||
|
return p1.key_data == p2.serialize_extended();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator == ( const extended_private_key_type& p1, const extended_private_key_type& p2)
|
||||||
|
{
|
||||||
|
return p1.key_data == p2.key_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool operator != ( const extended_private_key_type& p1, const extended_private_key_type& p2)
|
||||||
|
{
|
||||||
|
return p1.key_data != p2.key_data;
|
||||||
|
}
|
||||||
|
|
||||||
} } // graphene::chain
|
} } // graphene::chain
|
||||||
|
|
||||||
|
|
@ -119,12 +227,31 @@ namespace fc
|
||||||
using namespace std;
|
using namespace std;
|
||||||
void to_variant( const graphene::chain::public_key_type& var, fc::variant& vo )
|
void to_variant( const graphene::chain::public_key_type& var, fc::variant& vo )
|
||||||
{
|
{
|
||||||
vo = std::string(var);
|
vo = std::string( var );
|
||||||
}
|
}
|
||||||
|
|
||||||
void from_variant( const fc::variant& var, graphene::chain::public_key_type& vo )
|
void from_variant( const fc::variant& var, graphene::chain::public_key_type& vo )
|
||||||
{
|
{
|
||||||
vo = graphene::chain::public_key_type( var.as_string() );
|
vo = graphene::chain::public_key_type( var.as_string() );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void to_variant( const graphene::chain::extended_public_key_type& var, fc::variant& vo )
|
||||||
|
{
|
||||||
|
vo = std::string( var );
|
||||||
|
}
|
||||||
|
|
||||||
|
void from_variant( const fc::variant& var, graphene::chain::extended_public_key_type& vo )
|
||||||
|
{
|
||||||
|
vo = graphene::chain::extended_public_key_type( var.as_string() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void to_variant( const graphene::chain::extended_private_key_type& var, fc::variant& vo )
|
||||||
|
{
|
||||||
|
vo = std::string( var );
|
||||||
|
}
|
||||||
|
|
||||||
|
void from_variant( const fc::variant& var, graphene::chain::extended_private_key_type& vo )
|
||||||
|
{
|
||||||
|
vo = graphene::chain::extended_private_key_type( var.as_string() );
|
||||||
|
}
|
||||||
} // fc
|
} // fc
|
||||||
|
|
|
||||||
|
|
@ -23,8 +23,11 @@
|
||||||
*/
|
*/
|
||||||
#include <graphene/chain/database.hpp>
|
#include <graphene/chain/database.hpp>
|
||||||
#include <graphene/chain/worker_evaluator.hpp>
|
#include <graphene/chain/worker_evaluator.hpp>
|
||||||
#include <graphene/chain/vesting_balance_object.hpp>
|
|
||||||
#include <graphene/chain/account_object.hpp>
|
#include <graphene/chain/account_object.hpp>
|
||||||
|
#include <graphene/chain/vesting_balance_object.hpp>
|
||||||
|
#include <graphene/chain/worker_object.hpp>
|
||||||
|
|
||||||
#include <graphene/chain/protocol/vote.hpp>
|
#include <graphene/chain/protocol/vote.hpp>
|
||||||
|
|
||||||
namespace graphene { namespace chain {
|
namespace graphene { namespace chain {
|
||||||
|
|
@ -40,7 +43,7 @@ void_result worker_create_evaluator::do_evaluate(const worker_create_evaluator::
|
||||||
} FC_CAPTURE_AND_RETHROW( (o) ) }
|
} FC_CAPTURE_AND_RETHROW( (o) ) }
|
||||||
|
|
||||||
|
|
||||||
struct worker_init_visitor
|
struct worker_init_visitor
|
||||||
{
|
{
|
||||||
typedef void result_type;
|
typedef void result_type;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1 +1 @@
|
||||||
Subproject commit 6495004302239ae0c775f05a0e78780c3b189502
|
Subproject commit 8eec508b8cd418f0719a58f10a11d7850e87b992
|
||||||
|
|
@ -22,7 +22,7 @@ else()
|
||||||
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/api_documentation_standin.cpp )
|
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/api_documentation_standin.cpp )
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_library( graphene_wallet cache.cpp wallet.cpp ${CMAKE_CURRENT_BINARY_DIR}/api_documentation.cpp ${HEADERS} )
|
add_library( graphene_wallet wallet.cpp ${CMAKE_CURRENT_BINARY_DIR}/api_documentation.cpp ${HEADERS} )
|
||||||
target_link_libraries( graphene_wallet PRIVATE graphene_app graphene_net graphene_chain graphene_utilities fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} )
|
target_link_libraries( graphene_wallet PRIVATE graphene_app graphene_net graphene_chain graphene_utilities fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} )
|
||||||
target_include_directories( graphene_db PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )
|
target_include_directories( graphene_db PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" )
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,95 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2015 Cryptonomex, Inc., and contributors.
|
|
||||||
*
|
|
||||||
* The MIT License
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <graphene/chain/account_object.hpp>
|
|
||||||
#include <graphene/chain/asset_object.hpp>
|
|
||||||
#include <graphene/chain/committee_member_object.hpp>
|
|
||||||
#include <graphene/chain/witness_object.hpp>
|
|
||||||
#include <graphene/chain/market_evaluator.hpp>
|
|
||||||
#include <graphene/chain/proposal_object.hpp>
|
|
||||||
#include <graphene/chain/operation_history_object.hpp>
|
|
||||||
#include <graphene/chain/withdraw_permission_object.hpp>
|
|
||||||
|
|
||||||
using namespace fc;
|
|
||||||
using namespace graphene::chain;
|
|
||||||
|
|
||||||
namespace graphene { namespace wallet {
|
|
||||||
|
|
||||||
template< typename ObjectType >
|
|
||||||
object* create_object_of_type( const variant& v )
|
|
||||||
{
|
|
||||||
return new ObjectType( v.as<ObjectType>() );
|
|
||||||
}
|
|
||||||
|
|
||||||
object* create_object( const variant& v )
|
|
||||||
{
|
|
||||||
const variant_object& obj = v.get_object();
|
|
||||||
object_id_type obj_id = obj["id"].as< object_id_type >();
|
|
||||||
|
|
||||||
FC_ASSERT( obj_id.type() == protocol_ids );
|
|
||||||
|
|
||||||
//
|
|
||||||
// Sufficiently clever template metaprogramming might
|
|
||||||
// be able to convince the compiler to emit this switch
|
|
||||||
// instead of creating it explicitly.
|
|
||||||
//
|
|
||||||
switch( obj_id.space() )
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
case null_object_type:
|
|
||||||
return nullptr;
|
|
||||||
case base_object_type:
|
|
||||||
return create_object_of_type< base_object >( v );
|
|
||||||
*/
|
|
||||||
case account_object_type:
|
|
||||||
return create_object_of_type< account_object >( v );
|
|
||||||
case asset_object_type:
|
|
||||||
return create_object_of_type< asset_object >( v );
|
|
||||||
case force_settlement_object_type:
|
|
||||||
return create_object_of_type< force_settlement_object >( v );
|
|
||||||
case committee_member_object_type:
|
|
||||||
return create_object_of_type< committee_member_object >( v );
|
|
||||||
case witness_object_type:
|
|
||||||
return create_object_of_type< witness_object >( v );
|
|
||||||
case limit_order_object_type:
|
|
||||||
return create_object_of_type< limit_order_object >( v );
|
|
||||||
case call_order_object_type:
|
|
||||||
return create_object_of_type< call_order_object >( v );
|
|
||||||
/*
|
|
||||||
case custom_object_type:
|
|
||||||
return create_object_of_type< custom_object >( v );
|
|
||||||
*/
|
|
||||||
case proposal_object_type:
|
|
||||||
return create_object_of_type< proposal_object >( v );
|
|
||||||
case operation_history_object_type:
|
|
||||||
return create_object_of_type< operation_history_object >( v );
|
|
||||||
case withdraw_permission_object_type:
|
|
||||||
return create_object_of_type< withdraw_permission_object >( v );
|
|
||||||
default:
|
|
||||||
;
|
|
||||||
}
|
|
||||||
FC_ASSERT( false, "unknown type_id" );
|
|
||||||
}
|
|
||||||
|
|
||||||
} }
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
add_subdirectory( build_helpers )
|
||||||
add_subdirectory( cli_wallet )
|
add_subdirectory( cli_wallet )
|
||||||
add_subdirectory( genesis_util )
|
add_subdirectory( genesis_util )
|
||||||
add_subdirectory( witness_node )
|
add_subdirectory( witness_node )
|
||||||
|
|
|
||||||
8
programs/build_helpers/CMakeLists.txt
Normal file
8
programs/build_helpers/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
|
||||||
|
add_executable( cat-parts cat-parts.cpp )
|
||||||
|
if( UNIX AND NOT APPLE )
|
||||||
|
set(rt_library rt )
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# we only actually need Boost, but link against FC for now so we don't duplicate it.
|
||||||
|
target_link_libraries( cat-parts PRIVATE fc ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} )
|
||||||
77
programs/build_helpers/cat-parts.cpp
Normal file
77
programs/build_helpers/cat-parts.cpp
Normal file
|
|
@ -0,0 +1,77 @@
|
||||||
|
|
||||||
|
#include <boost/filesystem.hpp>
|
||||||
|
#include <boost/filesystem/fstream.hpp>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
#include <sstream>
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
int main( int argc, char** argv, char** envp )
|
||||||
|
{
|
||||||
|
if( argc != 3 )
|
||||||
|
{
|
||||||
|
std::cerr << "syntax: cat-parts DIR OUTFILE" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
boost::filesystem::path p(argv[1]);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
std::vector< boost::filesystem::path > v;
|
||||||
|
|
||||||
|
for( boost::filesystem::directory_iterator it(p);
|
||||||
|
it != boost::filesystem::directory_iterator();
|
||||||
|
++it )
|
||||||
|
{
|
||||||
|
boost::filesystem::path pit = it->path();
|
||||||
|
std::string spit = pit.generic_string();
|
||||||
|
size_t n = spit.length();
|
||||||
|
if( n <= 3 )
|
||||||
|
continue;
|
||||||
|
if( spit.substr(n-3, 3) != ".hf" )
|
||||||
|
continue;
|
||||||
|
v.push_back( pit );
|
||||||
|
}
|
||||||
|
std::sort( v.begin(), v.end() );
|
||||||
|
|
||||||
|
// open each file and grab its contents, concatenating into single stringstream
|
||||||
|
std::stringstream ss_data;
|
||||||
|
for( const boost::filesystem::path& p : v )
|
||||||
|
{
|
||||||
|
boost::filesystem::ifstream ifs(p);
|
||||||
|
ss_data << ifs.rdbuf();
|
||||||
|
}
|
||||||
|
std::string new_data = ss_data.str();
|
||||||
|
|
||||||
|
boost::filesystem::path opath(argv[2]);
|
||||||
|
|
||||||
|
if( boost::filesystem::exists( opath ) )
|
||||||
|
{
|
||||||
|
boost::filesystem::ifstream ifs(opath);
|
||||||
|
std::stringstream ss_old_data;
|
||||||
|
ss_old_data << ifs.rdbuf();
|
||||||
|
std::string old_data = ss_old_data.str();
|
||||||
|
if( old_data == new_data )
|
||||||
|
{
|
||||||
|
std::cerr << "File " << opath << " up-to-date with .d directory" << std::endl;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
boost::filesystem::ofstream ofs(opath);
|
||||||
|
ofs.write( new_data.c_str(), new_data.length() );
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cerr << "Built " << opath << " from .d directory" << std::endl;
|
||||||
|
}
|
||||||
|
catch( const boost::filesystem::filesystem_error& e )
|
||||||
|
{
|
||||||
|
std::cout << e.what() << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -32,7 +32,7 @@
|
||||||
#include <graphene/chain/account_object.hpp>
|
#include <graphene/chain/account_object.hpp>
|
||||||
#include <graphene/chain/asset_object.hpp>
|
#include <graphene/chain/asset_object.hpp>
|
||||||
#include <graphene/chain/committee_member_object.hpp>
|
#include <graphene/chain/committee_member_object.hpp>
|
||||||
#include <graphene/chain/market_evaluator.hpp>
|
#include <graphene/chain/market_object.hpp>
|
||||||
#include <graphene/chain/vesting_balance_object.hpp>
|
#include <graphene/chain/vesting_balance_object.hpp>
|
||||||
#include <graphene/chain/witness_object.hpp>
|
#include <graphene/chain/witness_object.hpp>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
#include <graphene/chain/asset_object.hpp>
|
#include <graphene/chain/asset_object.hpp>
|
||||||
#include <graphene/chain/committee_member_object.hpp>
|
#include <graphene/chain/committee_member_object.hpp>
|
||||||
#include <graphene/chain/proposal_object.hpp>
|
#include <graphene/chain/proposal_object.hpp>
|
||||||
#include <graphene/chain/market_evaluator.hpp>
|
#include <graphene/chain/market_object.hpp>
|
||||||
|
|
||||||
#include <graphene/utilities/tempdir.hpp>
|
#include <graphene/utilities/tempdir.hpp>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@
|
||||||
#include <fc/smart_ref_impl.hpp>
|
#include <fc/smart_ref_impl.hpp>
|
||||||
#include <fc/uint128.hpp>
|
#include <fc/uint128.hpp>
|
||||||
#include <graphene/chain/hardfork.hpp>
|
#include <graphene/chain/hardfork.hpp>
|
||||||
#include <graphene/chain/market_evaluator.hpp>
|
#include <graphene/chain/market_object.hpp>
|
||||||
#include <graphene/chain/vesting_balance_object.hpp>
|
#include <graphene/chain/vesting_balance_object.hpp>
|
||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
#include <graphene/chain/account_object.hpp>
|
#include <graphene/chain/account_object.hpp>
|
||||||
#include <graphene/chain/asset_object.hpp>
|
#include <graphene/chain/asset_object.hpp>
|
||||||
#include <graphene/chain/committee_member_object.hpp>
|
#include <graphene/chain/committee_member_object.hpp>
|
||||||
#include <graphene/chain/market_evaluator.hpp>
|
#include <graphene/chain/market_object.hpp>
|
||||||
#include <graphene/chain/vesting_balance_object.hpp>
|
#include <graphene/chain/vesting_balance_object.hpp>
|
||||||
#include <graphene/chain/withdraw_permission_object.hpp>
|
#include <graphene/chain/withdraw_permission_object.hpp>
|
||||||
#include <graphene/chain/witness_object.hpp>
|
#include <graphene/chain/witness_object.hpp>
|
||||||
|
|
|
||||||
|
|
@ -31,12 +31,12 @@
|
||||||
#include <graphene/chain/account_object.hpp>
|
#include <graphene/chain/account_object.hpp>
|
||||||
#include <graphene/chain/balance_object.hpp>
|
#include <graphene/chain/balance_object.hpp>
|
||||||
#include <graphene/chain/budget_record_object.hpp>
|
#include <graphene/chain/budget_record_object.hpp>
|
||||||
#include <graphene/chain/witness_object.hpp>
|
|
||||||
#include <graphene/chain/committee_member_object.hpp>
|
#include <graphene/chain/committee_member_object.hpp>
|
||||||
#include <graphene/chain/market_evaluator.hpp>
|
#include <graphene/chain/market_object.hpp>
|
||||||
#include <graphene/chain/worker_evaluator.hpp>
|
|
||||||
#include <graphene/chain/vesting_balance_object.hpp>
|
#include <graphene/chain/vesting_balance_object.hpp>
|
||||||
#include <graphene/chain/withdraw_permission_object.hpp>
|
#include <graphene/chain/withdraw_permission_object.hpp>
|
||||||
|
#include <graphene/chain/witness_object.hpp>
|
||||||
|
#include <graphene/chain/worker_object.hpp>
|
||||||
|
|
||||||
#include <graphene/utilities/tempdir.hpp>
|
#include <graphene/utilities/tempdir.hpp>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@
|
||||||
|
|
||||||
|
|
||||||
#include <fc/crypto/digest.hpp>
|
#include <fc/crypto/digest.hpp>
|
||||||
|
#include <fc/crypto/elliptic.hpp>
|
||||||
#include <fc/reflect/variant.hpp>
|
#include <fc/reflect/variant.hpp>
|
||||||
|
|
||||||
#include "../common/database_fixture.hpp"
|
#include "../common/database_fixture.hpp"
|
||||||
|
|
@ -85,4 +86,40 @@ BOOST_AUTO_TEST_CASE( json_tests )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE( extended_private_key_type_test )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fc::ecc::extended_private_key key = fc::ecc::extended_private_key( fc::ecc::private_key::generate(),
|
||||||
|
fc::sha256(),
|
||||||
|
0, 0, 0 );
|
||||||
|
extended_private_key_type type = extended_private_key_type( key );
|
||||||
|
std::string packed = std::string( type );
|
||||||
|
extended_private_key_type unpacked = extended_private_key_type( packed );
|
||||||
|
BOOST_CHECK( type == unpacked );
|
||||||
|
} catch ( const fc::exception& e )
|
||||||
|
{
|
||||||
|
edump((e.to_detail_string()));
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE( extended_public_key_type_test )
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
fc::ecc::extended_public_key key = fc::ecc::extended_public_key( fc::ecc::private_key::generate().get_public_key(),
|
||||||
|
fc::sha256(),
|
||||||
|
0, 0, 0 );
|
||||||
|
extended_public_key_type type = extended_public_key_type( key );
|
||||||
|
std::string packed = std::string( type );
|
||||||
|
extended_public_key_type unpacked = extended_public_key_type( packed );
|
||||||
|
BOOST_CHECK( type == unpacked );
|
||||||
|
} catch ( const fc::exception& e )
|
||||||
|
{
|
||||||
|
edump((e.to_detail_string()));
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_SUITE_END()
|
BOOST_AUTO_TEST_SUITE_END()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue