* Created unit test for #325
* remove needless find()
* issue - 154: Don't allow to vote when vesting balance is 0
* Increase block creation timeout to 2500ms
* increase delay for node connection
* remove cache from cli get_account
* add cli tests framework
* Adjust newly merged code to new API
* Merged changes from Bitshares PR 1036
* GRPH-76 - Short-cut long sequences of missed blocks
Fixes database::update_global_dynamic_data to speed up counting missed blocks.
(This also fixes a minor issue with counting - the previous algorithm would skip missed blocks for the witness who signed the first block after the gap.)
* Improved resilience of block database against corruption
* Moved reindex logic into database / chain_database, make use of additional blocks in block_database
Fixed tests wrt db.open
* Enable undo + fork database for final blocks in a replay
Dont remove blocks from block db when popping blocks, handle edge case in replay wrt fork_db, adapted unit tests
* Log starting block number of replay
* Prevent unsigned integer underflow
* Fixed lock detection
* Dont leave _data_dir empty if db is locked
* Writing the object_database is now almost atomic
* Improved consistency check for block_log
* Cut back block_log index file if inconsistent
* Fixed undo_database
* Added test case for broken merge on empty undo_db
* exclude second undo_db.enable() call in some cases
* Add missing change
* change bitshares to core in message
* Merge pull request #938 from bitshares/fix-block-storing
Store correct block ID when switching forks
* Fixed integer overflow issue
* Fix for for history ID mismatch ( Bitshares PR #875 )
* Update the FC submodule with the changes for GRPH-4
* Merged Bitshares PR #1462 and compilation fixes
* Support/gitlab (#123)
* Updated gitlab process
* Fix undefined references in cli test
* Updated GitLab CI
* Fix #436 object_database created outside of witness data directory
* supplement more comments on database::_opened variable
* prevent segfault when destructing application obj
* Fixed test failures and compilation issue
* minor performance improvement
* Added comment
* Fix compilation in debug mode
* Fixed duplicate ops returned from get_account_history
* Fixed account_history_pagination test
* Removed unrelated comment
* Update to fixed version of fc
* Skip auth check when pushing self-generated blocks
* Extract public keys before pushing a transaction
* Dereference chain_database shared_ptr
* Updated transaction::signees to mutable
and
* updated get_signature_keys() to return a const reference,
* get_signature_keys() will update signees on first call,
* modified test cases and wallet.cpp accordingly,
* no longer construct a new signed_transaction object before pushing
* Added get_asset_count API
* No longer extract public keys before pushing a trx
and removed unused new added constructor and _get_signature_keys() function from signed_transaction struct
* changes to withdraw_vesting feature(for both cdd and GPOS)
* Comments update
* update to GPOS hardfork ref
* Remove leftover comment from merge
* fix for get_vesting_balance API call
* braces update
* Allow sufficient space for new undo_session
* Throw for deep nesting
* node.cpp: Check the attacker/buggy client before updating items ids
The peer is an attacker or buggy, which means the item_hashes_received is
not correct.
Move the check before updating items ids to save some time in this case.
* Create .gitlab-ci.yml
* Added cli_test to CI
* fixing build errors (#150)
* fixing build errors
vest type correction
* fixing build errors
vest type correction
* fixes
new Dockerfile
* vesting_balance_type correction
vesting_balance_type changed to normal
* gcc5 support to Dockerfile
gcc5 support to Dockerfile
* use random port numbers in app_test (#154)
* Changes to compiple with GCC 7(Ubuntu 18.04)
* proposal fail_reason bug fixed (#157)
* Added Sonarcloud code_quality to CI (#159)
* Added sonarcloud analysis (#158)
* changes to have separate methods and single withdrawl fee for multiple vest objects
* 163-fix, Return only non-zero vesting balances
* Support/gitlab develop (#168)
* Added code_quality to CI
* Update .gitlab-ci.yml
* Point to PBSA/peerplays-fc commit f13d063 (#167)
* [GRPH-3] Additional cli tests (#155)
* Additional cli tests
* Compatible with latest fc changes
* Fixed Spacing issues
* [GRPH-106] Added voting tests (#136)
* Added more voting tests
* Added additional option
* Adjust p2p log level (#180)
* merge gpos to develop (#186)
* issue - 154: Don't allow to vote when vesting balance is 0
* changes to withdraw_vesting feature(for both cdd and GPOS)
* Comments update
* update to GPOS hardfork ref
* fix for get_vesting_balance API call
* braces update
* Create .gitlab-ci.yml
* fixing build errors (#150)
* fixing build errors
vest type correction
* fixing build errors
vest type correction
* fixes
new Dockerfile
* vesting_balance_type correction
vesting_balance_type changed to normal
* gcc5 support to Dockerfile
gcc5 support to Dockerfile
* Changes to compiple with GCC 7(Ubuntu 18.04)
* changes to have separate methods and single withdrawl fee for multiple vest objects
* 163-fix, Return only non-zero vesting balances
* Revert "Revert "GPOS protocol""
This reverts commit 67616417b7.
* add new line needed to gpos hardfork file
* comment temporally cli_vote_for_2_witnesses until refactor or delete
* fix gpos tests
* fix gitlab-ci conflict
* Fixed few error messages
* error message corrections at other places
* Updated FC repository to peerplays-network/peerplays-fc (#189)
Point to fc commit hash 6096e94 [latest-fc branch]
* Project name update in Doxyfile (#146)
* changes to allow user to vote in each sub-period
* Fixed GPOS vesting factor issue when proxy is set
* Added unit test for proxy voting
* Review changes
* changes to update last voting time
* resolve merge conflict
* unit test changes and also separated GPOS test suite
* delete unused variables
* removed witness check
* eliminate time gap between two consecutive vesting periods
* deleted GPOS specific test suite and updated gpos tests
* updated GPOS hf
* Fixed dividend distribution issue and added test case
* fix flag
* clean newlines gpos_tests
* adapt gpos_tests to changed flag
* Fix to roll in GPOS rules, carry votes from 6th sub-period
* check was already modified
* comments updated
* updated comments to the benefit of reviewer
* Added token symbol name in error messages
* Added token symbol name in error messages (#204)
* case 1: Fixed last voting time issue
* get_account bug fixed
* Fixed flag issue
* Fixed spelling issue
* remove non needed gcc5 changes to dockerfile
* GRPH134- High CPU Issue, websocket changes (#213)
* update submodule branch to refer to the latest commit on latest-fc branch (#214)
* Improve account maintenance performance (#130)
* Improve account maintenance performance
* merge fixes
* Fixed merge issue
* Fixed indentations and extra ';'
* Update CI for syncing gitmodules (#216)
* Added logging for the old update_expired_feeds bug
The old bug is https://github.com/cryptonomex/graphene/issues/615 .
Due to the bug, `update_median_feeds()` and `check_call_orders()`
will be called when a feed is not actually expired, normally this
should not affect consensus since calling them should not change
any data in the state.
However, the logging indicates that `check_call_orders()` did
change some data under certain circumstances, specifically, when
multiple limit order matching issue (#453) occurred at same block.
* https://github.com/bitshares/bitshares-core/issues/453
* Minor performance improvement for price::is_null()
* Use static refs in db_getter for immutable objects
* Minor performance improvement for db_maint
* Minor code updates for asset_evaluator.cpp
* changed an `assert()` to `FC_ASSERT()`
* replaced one `db.get(asset_id_type())` with `db.get_core_asset()`
* capture only required variables for lambda
* Improve update_expired_feeds performance #1093
* Change static refs to member pointers of db class
* Added getter for witness schedule object
* Added getter for core dynamic data object
* Use getters
* Removed unused variable
* Add comments for update_expired_feeds in db_block
* Minor refactory asset_create_evaluator::do_apply()
* Added FC_ASSERT for dynamic data id of core asset
* Added header inclusions in db_management.cpp
* fix global objects usage during replay
* Logging config parsing issue
* added new files
* compilation fix
* Simplified code in database::pay_workers()
* issue with withdrawl
* Added unit test for empty account history
* set extensions default values
* Update GPOS hardfork date and don't allow GPOS features before hardfork time
* refer to latest commit of latest-fc branch (#224)
* account name or id support in all database api
* asset id or name support in all asset APIs
* Fixed compilation issues
* Fixed alignment issues
* Externalized some API templates
* Externalize serialization of blocks, tx, ops
* Externalized db objects
* Externalized genesis serialization
* Externalized serialization in protocol library
* Undo superfluous change
* remove default value for extension parameter
* fix compilation issues
* GRPH-46-Quit_command_cliwallet
* removed multiple function definition
* Fixed chainparameter update proposal issue
* Move GPOS withdraw logic to have single transaction(also single fee) and update API
* Added log for authorization failure of proposal operations
* Votes consideration on GPOS activation
* bump fc version
* fix gpos tests
* Bump fc version
* Updated gpos/voting_tests
* Fixed withdraw vesting bug
* Added unit test
* Update hardfork date for TESTNET, sync fc module and update logs
* avoid wlog as it filling up space
* Beatrice hot fix(sync issue fix)
* gpos tests fix
* Set hardfork date to Jan5th on TESTNET
Co-authored-by: Peter Conrad <github.com@quisquis.de>
Co-authored-by: John M. Jones <jmjatlanta@gmail.com>
Co-authored-by: obucinac <obucinac@users.noreply.github.com>
Co-authored-by: Bobinson K B <bobinson@gmail.com>
Co-authored-by: Alfredo Garcia <oxarbitrage@gmail.com>
Co-authored-by: Miha Čančula <miha@noughmad.eu>
Co-authored-by: Abit <abitmore@users.noreply.github.com>
Co-authored-by: Roshan Syed <r.syed@pbsa.info>
Co-authored-by: Sandip Patel <sandip@knackroot.com>
Co-authored-by: RichardWeiYang <richard.weiyang@gmail.com>
Co-authored-by: gladcow <jahr@yandex.ru>
Co-authored-by: satyakoneru <satyakoneru.iiith@gmail.com>
857 lines
33 KiB
C++
857 lines
33 KiB
C++
/*
|
|
* 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 <cctype>
|
|
|
|
#include <graphene/app/api.hpp>
|
|
#include <graphene/app/api_access.hpp>
|
|
#include <graphene/app/application.hpp>
|
|
#include <graphene/app/impacted.hpp>
|
|
#include <graphene/chain/database.hpp>
|
|
#include <graphene/chain/get_config.hpp>
|
|
#include <graphene/utilities/key_conversion.hpp>
|
|
#include <graphene/chain/protocol/fee_schedule.hpp>
|
|
#include <graphene/chain/confidential_object.hpp>
|
|
#include <graphene/chain/market_object.hpp>
|
|
#include <graphene/chain/transaction_object.hpp>
|
|
#include <graphene/chain/withdraw_permission_object.hpp>
|
|
#include <graphene/chain/worker_object.hpp>
|
|
#include <graphene/chain/tournament_object.hpp>
|
|
|
|
#include <fc/crypto/hex.hpp>
|
|
#include <fc/smart_ref_impl.hpp>
|
|
#include <fc/rpc/api_connection.hpp>
|
|
#include <fc/thread/future.hpp>
|
|
|
|
template class fc::api<graphene::app::block_api>;
|
|
template class fc::api<graphene::app::network_broadcast_api>;
|
|
template class fc::api<graphene::app::network_node_api>;
|
|
template class fc::api<graphene::app::history_api>;
|
|
template class fc::api<graphene::app::crypto_api>;
|
|
template class fc::api<graphene::app::asset_api>;
|
|
template class fc::api<graphene::debug_witness::debug_api>;
|
|
template class fc::api<graphene::app::login_api>;
|
|
|
|
|
|
namespace graphene { namespace app {
|
|
|
|
login_api::login_api(application& a)
|
|
:_app(a)
|
|
{
|
|
}
|
|
|
|
login_api::~login_api()
|
|
{
|
|
}
|
|
|
|
bool login_api::login(const string& user, const string& password)
|
|
{
|
|
optional< api_access_info > acc = _app.get_api_access_info( user );
|
|
if( !acc.valid() )
|
|
return false;
|
|
if( acc->password_hash_b64 != "*" )
|
|
{
|
|
std::string password_salt = fc::base64_decode( acc->password_salt_b64 );
|
|
std::string acc_password_hash = fc::base64_decode( acc->password_hash_b64 );
|
|
|
|
fc::sha256 hash_obj = fc::sha256::hash( password + password_salt );
|
|
if( hash_obj.data_size() != acc_password_hash.length() )
|
|
return false;
|
|
if( memcmp( hash_obj.data(), acc_password_hash.c_str(), hash_obj.data_size() ) != 0 )
|
|
return false;
|
|
}
|
|
|
|
for( const std::string& api_name : acc->allowed_apis )
|
|
enable_api( api_name );
|
|
return true;
|
|
}
|
|
|
|
void login_api::enable_api( const std::string& api_name )
|
|
{
|
|
if( api_name == "database_api" )
|
|
{
|
|
_database_api = std::make_shared< database_api >( std::ref( *_app.chain_database() ) );
|
|
}
|
|
else if( api_name == "block_api" )
|
|
{
|
|
_block_api = std::make_shared< block_api >( std::ref( *_app.chain_database() ) );
|
|
}
|
|
else if( api_name == "network_broadcast_api" )
|
|
{
|
|
_network_broadcast_api = std::make_shared< network_broadcast_api >( std::ref( _app ) );
|
|
}
|
|
else if( api_name == "history_api" )
|
|
{
|
|
_history_api = std::make_shared< history_api >( _app );
|
|
}
|
|
else if( api_name == "network_node_api" )
|
|
{
|
|
_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 >();
|
|
}
|
|
else if( api_name == "asset_api" )
|
|
{
|
|
_asset_api = std::make_shared< asset_api >( _app );
|
|
}
|
|
else if( api_name == "debug_api" )
|
|
{
|
|
// can only enable this API if the plugin was loaded
|
|
if( _app.get_plugin( "debug_witness" ) )
|
|
_debug_api = std::make_shared< graphene::debug_witness::debug_api >( std::ref(_app) );
|
|
}
|
|
else if( api_name == "bookie_api" )
|
|
{
|
|
// can only enable this API if the plugin was loaded
|
|
if( _app.get_plugin( "bookie" ) )
|
|
_bookie_api = std::make_shared<graphene::bookie::bookie_api>(std::ref(_app));
|
|
}
|
|
else if( api_name == "affiliate_stats_api" )
|
|
{
|
|
// can only enable this API if the plugin was loaded
|
|
if( _app.get_plugin( "affiliate_stats" ) )
|
|
_affiliate_stats_api = std::make_shared<graphene::affiliate_stats::affiliate_stats_api>(std::ref(_app));
|
|
}
|
|
return;
|
|
}
|
|
|
|
// block_api
|
|
block_api::block_api(graphene::chain::database& db) : _db(db) { }
|
|
block_api::~block_api() { }
|
|
|
|
vector<optional<signed_block>> block_api::get_blocks(uint32_t block_num_from, uint32_t block_num_to)const
|
|
{
|
|
FC_ASSERT( block_num_to >= block_num_from );
|
|
vector<optional<signed_block>> res;
|
|
for(uint32_t block_num=block_num_from; block_num<=block_num_to; block_num++) {
|
|
res.push_back(_db.fetch_block_by_number(block_num));
|
|
}
|
|
return res;
|
|
}
|
|
|
|
network_broadcast_api::network_broadcast_api(application& a):_app(a)
|
|
{
|
|
_applied_block_connection = _app.chain_database()->applied_block.connect([this](const signed_block& b){ on_applied_block(b); });
|
|
}
|
|
|
|
void network_broadcast_api::on_applied_block( const signed_block& b )
|
|
{
|
|
if( _callbacks.size() )
|
|
{
|
|
/// we need to ensure the database_api is not deleted for the life of the async operation
|
|
auto capture_this = shared_from_this();
|
|
for( uint32_t trx_num = 0; trx_num < b.transactions.size(); ++trx_num )
|
|
{
|
|
const auto& trx = b.transactions[trx_num];
|
|
auto id = trx.id();
|
|
auto itr = _callbacks.find(id);
|
|
if( itr != _callbacks.end() )
|
|
{
|
|
auto block_num = b.block_num();
|
|
auto& callback = _callbacks.find(id)->second;
|
|
fc::async( [capture_this,this,id,block_num,trx_num,trx,callback]() {
|
|
callback( fc::variant( transaction_confirmation{ id, block_num, trx_num, trx },
|
|
GRAPHENE_MAX_NESTED_OBJECTS ) );
|
|
} );
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
void network_broadcast_api::broadcast_transaction(const signed_transaction& trx)
|
|
{
|
|
trx.validate();
|
|
database_api( *(_app.chain_database() ) ).check_transaction_for_duplicated_operations(trx);
|
|
_app.chain_database()->push_transaction(trx);
|
|
if( _app.p2p_node() != nullptr )
|
|
_app.p2p_node()->broadcast_transaction(trx);
|
|
}
|
|
|
|
fc::variant network_broadcast_api::broadcast_transaction_synchronous(const signed_transaction& trx)
|
|
{
|
|
database_api( *(_app.chain_database() ) ).check_transaction_for_duplicated_operations(trx);
|
|
|
|
fc::promise<fc::variant>::ptr prom( new fc::promise<fc::variant>() );
|
|
broadcast_transaction_with_callback( [=]( const fc::variant& v ){
|
|
prom->set_value(v);
|
|
}, trx );
|
|
|
|
return fc::future<fc::variant>(prom).wait();
|
|
}
|
|
|
|
void network_broadcast_api::broadcast_block( const signed_block& b )
|
|
{
|
|
_app.chain_database()->push_block(b);
|
|
if( _app.p2p_node() != nullptr )
|
|
_app.p2p_node()->broadcast( net::block_message( b ));
|
|
}
|
|
|
|
void network_broadcast_api::broadcast_transaction_with_callback(confirmation_callback cb, const signed_transaction& trx)
|
|
{
|
|
trx.validate();
|
|
_callbacks[trx.id()] = cb;
|
|
_app.chain_database()->push_transaction(trx);
|
|
if( _app.p2p_node() != nullptr )
|
|
_app.p2p_node()->broadcast_transaction(trx);
|
|
}
|
|
|
|
network_node_api::network_node_api( application& a ) : _app( a )
|
|
{
|
|
_pending_trx_connection = _app.chain_database()->on_pending_transaction.connect([this]( const signed_transaction& transaction ){
|
|
|
|
auto transaction_it = _pending_transactions.find(transaction.id());
|
|
if (_pending_transactions.end() == transaction_it)
|
|
{
|
|
_pending_transactions[transaction.id()] = transaction;
|
|
}
|
|
|
|
if (_on_pending_transaction)
|
|
{
|
|
_on_pending_transaction(fc::variant(transaction, GRAPHENE_MAX_NESTED_OBJECTS));
|
|
}
|
|
});
|
|
|
|
_applied_block_connection = _app.chain_database()->applied_block.connect([this]( const signed_block& block ){
|
|
for (const auto& transaction: block.transactions)
|
|
{
|
|
auto transaction_it = _pending_transactions.find(transaction.id());
|
|
if (_pending_transactions.end() != transaction_it)
|
|
{
|
|
_pending_transactions.erase(transaction_it);
|
|
}
|
|
}
|
|
|
|
/*
|
|
* Remove expired transactions from pending_transactions
|
|
*/
|
|
for (const auto& transaction: _pending_transactions)
|
|
{
|
|
if (transaction.second.expiration < block.timestamp)
|
|
{
|
|
auto transaction_it = _pending_transactions.find(transaction.second.id());
|
|
if (_pending_transactions.end() != transaction_it)
|
|
{
|
|
_pending_transactions.erase(transaction_it);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
fc::variant_object network_node_api::get_info() const
|
|
{
|
|
fc::mutable_variant_object result = _app.p2p_node()->network_get_info();
|
|
result["connection_count"] = _app.p2p_node()->get_connection_count();
|
|
return result;
|
|
}
|
|
|
|
void network_node_api::add_node(const fc::ip::endpoint& ep)
|
|
{
|
|
_app.p2p_node()->add_node(ep);
|
|
}
|
|
|
|
std::vector<net::peer_status> network_node_api::get_connected_peers() const
|
|
{
|
|
return _app.p2p_node()->get_connected_peers();
|
|
}
|
|
|
|
std::vector<net::potential_peer_record> network_node_api::get_potential_peers() const
|
|
{
|
|
return _app.p2p_node()->get_potential_peers();
|
|
}
|
|
|
|
fc::variant_object network_node_api::get_advanced_node_parameters() const
|
|
{
|
|
return _app.p2p_node()->get_advanced_node_parameters();
|
|
}
|
|
|
|
void network_node_api::set_advanced_node_parameters(const fc::variant_object& params)
|
|
{
|
|
return _app.p2p_node()->set_advanced_node_parameters(params);
|
|
}
|
|
|
|
map<transaction_id_type, signed_transaction> network_node_api::list_pending_transactions() const
|
|
{
|
|
return _pending_transactions;
|
|
}
|
|
|
|
void network_node_api::subscribe_to_pending_transactions( std::function<void(const variant&)> callback )
|
|
{
|
|
_on_pending_transaction = callback;
|
|
}
|
|
|
|
void network_node_api::unsubscribe_from_pending_transactions()
|
|
{
|
|
_on_pending_transaction = std::function<void(const variant&)>();
|
|
}
|
|
|
|
fc::api<network_broadcast_api> login_api::network_broadcast()const
|
|
{
|
|
FC_ASSERT(_network_broadcast_api);
|
|
return *_network_broadcast_api;
|
|
}
|
|
|
|
fc::api<block_api> login_api::block()const
|
|
{
|
|
FC_ASSERT(_block_api);
|
|
return *_block_api;
|
|
}
|
|
|
|
fc::api<network_node_api> login_api::network_node()const
|
|
{
|
|
FC_ASSERT(_network_node_api);
|
|
return *_network_node_api;
|
|
}
|
|
|
|
fc::api<database_api> login_api::database()const
|
|
{
|
|
FC_ASSERT(_database_api);
|
|
return *_database_api;
|
|
}
|
|
|
|
fc::api<history_api> login_api::history() const
|
|
{
|
|
FC_ASSERT(_history_api);
|
|
return *_history_api;
|
|
}
|
|
|
|
fc::api<crypto_api> login_api::crypto() const
|
|
{
|
|
FC_ASSERT(_crypto_api);
|
|
return *_crypto_api;
|
|
}
|
|
|
|
fc::api<asset_api> login_api::asset() const
|
|
{
|
|
FC_ASSERT(_asset_api);
|
|
return *_asset_api;
|
|
}
|
|
|
|
fc::api<graphene::debug_witness::debug_api> login_api::debug() const
|
|
{
|
|
FC_ASSERT(_debug_api);
|
|
return *_debug_api;
|
|
}
|
|
|
|
fc::api<graphene::bookie::bookie_api> login_api::bookie() const
|
|
{
|
|
FC_ASSERT(_bookie_api);
|
|
return *_bookie_api;
|
|
}
|
|
|
|
fc::api<graphene::affiliate_stats::affiliate_stats_api> login_api::affiliate_stats() const
|
|
{
|
|
FC_ASSERT(_affiliate_stats_api);
|
|
return *_affiliate_stats_api;
|
|
}
|
|
|
|
#if 0
|
|
vector<account_id_type> get_relevant_accounts( const object* obj )
|
|
{
|
|
vector<account_id_type> result;
|
|
if( obj->id.space() == protocol_ids )
|
|
{
|
|
switch( (object_type)obj->id.type() )
|
|
{
|
|
case null_object_type:
|
|
case base_object_type:
|
|
case OBJECT_TYPE_COUNT:
|
|
return result;
|
|
case account_object_type:{
|
|
result.push_back( obj->id );
|
|
break;
|
|
} case asset_object_type:{
|
|
const auto& aobj = dynamic_cast<const asset_object*>(obj);
|
|
assert( aobj != nullptr );
|
|
result.push_back( aobj->issuer );
|
|
break;
|
|
} case force_settlement_object_type:{
|
|
const auto& aobj = dynamic_cast<const force_settlement_object*>(obj);
|
|
assert( aobj != nullptr );
|
|
result.push_back( aobj->owner );
|
|
break;
|
|
} case committee_member_object_type:{
|
|
const auto& aobj = dynamic_cast<const committee_member_object*>(obj);
|
|
assert( aobj != nullptr );
|
|
result.push_back( aobj->committee_member_account );
|
|
break;
|
|
} case witness_object_type:{
|
|
const auto& aobj = dynamic_cast<const witness_object*>(obj);
|
|
assert( aobj != nullptr );
|
|
result.push_back( aobj->witness_account );
|
|
break;
|
|
} case limit_order_object_type:{
|
|
const auto& aobj = dynamic_cast<const limit_order_object*>(obj);
|
|
assert( aobj != nullptr );
|
|
result.push_back( aobj->seller );
|
|
break;
|
|
} case call_order_object_type:{
|
|
const auto& aobj = dynamic_cast<const call_order_object*>(obj);
|
|
assert( aobj != nullptr );
|
|
result.push_back( aobj->borrower );
|
|
break;
|
|
} case custom_object_type:{
|
|
break;
|
|
} case proposal_object_type:{
|
|
const auto& aobj = dynamic_cast<const proposal_object*>(obj);
|
|
assert( aobj != nullptr );
|
|
flat_set<account_id_type> impacted;
|
|
transaction_get_impacted_accounts( aobj->proposed_transaction, impacted );
|
|
result.reserve( impacted.size() );
|
|
for( auto& item : impacted ) result.emplace_back(item);
|
|
break;
|
|
} case operation_history_object_type:{
|
|
const auto& aobj = dynamic_cast<const operation_history_object*>(obj);
|
|
assert( aobj != nullptr );
|
|
flat_set<account_id_type> impacted;
|
|
operation_get_impacted_accounts( aobj->op, impacted );
|
|
result.reserve( impacted.size() );
|
|
for( auto& item : impacted ) result.emplace_back(item);
|
|
break;
|
|
} case withdraw_permission_object_type:{
|
|
const auto& aobj = dynamic_cast<const withdraw_permission_object*>(obj);
|
|
assert( aobj != nullptr );
|
|
result.push_back( aobj->withdraw_from_account );
|
|
result.push_back( aobj->authorized_account );
|
|
break;
|
|
} case vesting_balance_object_type:{
|
|
const auto& aobj = dynamic_cast<const vesting_balance_object*>(obj);
|
|
assert( aobj != nullptr );
|
|
result.push_back( aobj->owner );
|
|
break;
|
|
} case worker_object_type:{
|
|
const auto& aobj = dynamic_cast<const worker_object*>(obj);
|
|
assert( aobj != nullptr );
|
|
result.push_back( aobj->worker_account );
|
|
break;
|
|
} case balance_object_type:{
|
|
/** these are free from any accounts */
|
|
break;
|
|
}
|
|
case sport_object_type:
|
|
case event_group_object_type:
|
|
case event_object_type:
|
|
case betting_market_group_object_type:
|
|
case betting_market_object_type:
|
|
/** these are free from any accounts */
|
|
break;
|
|
case bet_object_type:{
|
|
const auto& aobj = dynamic_cast<const bet_object*>(obj);
|
|
assert( aobj != nullptr );
|
|
result.push_back( aobj->bettor_id );
|
|
} case tournament_object_type:{
|
|
const tournament_object* tournament_obj = dynamic_cast<const tournament_object*>(obj);
|
|
assert(tournament_obj);
|
|
const tournament_details_object& details = tournament_obj->tournament_details_id(*_app.chain_database());
|
|
flat_set<account_id_type> impacted = details.registered_players;
|
|
impacted.insert(tournament_obj->creator);
|
|
std::copy(impacted.begin(), impacted.end(), std::back_inserter(result));
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
else if( obj->id.space() == implementation_ids )
|
|
{
|
|
switch( (impl_object_type)obj->id.type() )
|
|
{
|
|
case impl_global_property_object_type:
|
|
break;
|
|
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);
|
|
assert( aobj != nullptr );
|
|
result.push_back( aobj->owner );
|
|
break;
|
|
} case impl_account_statistics_object_type:{
|
|
const auto& aobj = dynamic_cast<const account_statistics_object*>(obj);
|
|
assert( aobj != nullptr );
|
|
result.push_back( aobj->owner );
|
|
break;
|
|
} case impl_transaction_object_type:{
|
|
const auto& aobj = dynamic_cast<const transaction_object*>(obj);
|
|
assert( aobj != nullptr );
|
|
flat_set<account_id_type> impacted;
|
|
transaction_get_impacted_accounts( aobj->trx, impacted );
|
|
result.reserve( impacted.size() );
|
|
for( auto& item : impacted ) result.emplace_back(item);
|
|
break;
|
|
} case impl_blinded_balance_object_type:{
|
|
const auto& aobj = dynamic_cast<const blinded_balance_object*>(obj);
|
|
assert( aobj != nullptr );
|
|
result.reserve( aobj->owner.account_auths.size() );
|
|
for( const auto& a : aobj->owner.account_auths )
|
|
result.push_back( a.first );
|
|
break;
|
|
} case impl_block_summary_object_type:
|
|
break;
|
|
case impl_account_transaction_history_object_type:
|
|
break;
|
|
case impl_chain_property_object_type:
|
|
break;
|
|
case impl_witness_schedule_object_type:
|
|
break;
|
|
case impl_budget_record_object_type:
|
|
break;
|
|
case impl_special_authority_object_type:
|
|
break;
|
|
case impl_buyback_object_type:
|
|
break;
|
|
case impl_fba_accumulator_object_type:
|
|
break;
|
|
case impl_betting_market_position_object_type:
|
|
break;
|
|
case impl_global_betting_statistics_object_type:
|
|
break;
|
|
}
|
|
}
|
|
return result;
|
|
} // end get_relevant_accounts( obj )
|
|
#endif
|
|
|
|
vector<order_history_object> history_api::get_fill_order_history( std::string asset_a, std::string asset_b, uint32_t limit )const
|
|
{
|
|
FC_ASSERT(_app.chain_database());
|
|
const auto& db = *_app.chain_database();
|
|
asset_id_type a = database_api.get_asset_id_from_string( asset_a );
|
|
asset_id_type b = database_api.get_asset_id_from_string( asset_b );
|
|
if( a > b ) std::swap(a,b);
|
|
const auto& history_idx = db.get_index_type<graphene::market_history::history_index>().indices().get<by_key>();
|
|
history_key hkey;
|
|
hkey.base = a;
|
|
hkey.quote = b;
|
|
hkey.sequence = std::numeric_limits<int64_t>::min();
|
|
|
|
uint32_t count = 0;
|
|
auto itr = history_idx.lower_bound( hkey );
|
|
vector<order_history_object> result;
|
|
while( itr != history_idx.end() && count < limit)
|
|
{
|
|
if( itr->key.base != a || itr->key.quote != b ) break;
|
|
result.push_back( *itr );
|
|
++itr;
|
|
++count;
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
vector<operation_history_object> history_api::get_account_history( const std::string account_id_or_name,
|
|
operation_history_id_type stop,
|
|
unsigned limit,
|
|
operation_history_id_type start ) const
|
|
{
|
|
FC_ASSERT( _app.chain_database() );
|
|
const auto& db = *_app.chain_database();
|
|
FC_ASSERT( limit <= 100 );
|
|
vector<operation_history_object> result;
|
|
account_id_type account;
|
|
try {
|
|
account = database_api.get_account_id_from_string(account_id_or_name);
|
|
const account_transaction_history_object& node = account(db).statistics(db).most_recent_op(db);
|
|
if(start == operation_history_id_type() || start.instance.value > node.operation_id.instance.value)
|
|
start = node.operation_id;
|
|
} catch(...) { return result; }
|
|
|
|
const auto& hist_idx = db.get_index_type<account_transaction_history_index>();
|
|
const auto& by_op_idx = hist_idx.indices().get<by_op>();
|
|
auto index_start = by_op_idx.begin();
|
|
auto itr = by_op_idx.lower_bound(boost::make_tuple(account, start));
|
|
|
|
while(itr != index_start && itr->account == account && itr->operation_id.instance.value > stop.instance.value && result.size() < limit)
|
|
{
|
|
if(itr->operation_id.instance.value <= start.instance.value)
|
|
result.push_back(itr->operation_id(db));
|
|
--itr;
|
|
}
|
|
if(stop.instance.value == 0 && result.size() < limit && itr->account == account) {
|
|
result.push_back(itr->operation_id(db));
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
vector<operation_history_object> history_api::get_account_history_operations( const std::string account_id_or_name,
|
|
int operation_id,
|
|
operation_history_id_type start,
|
|
operation_history_id_type stop,
|
|
unsigned limit) const
|
|
{
|
|
FC_ASSERT( _app.chain_database() );
|
|
const auto& db = *_app.chain_database();
|
|
FC_ASSERT( limit <= 100 );
|
|
vector<operation_history_object> result;
|
|
account_id_type account;
|
|
try {
|
|
account = database_api.get_account_id_from_string(account_id_or_name);
|
|
} catch (...) { return result; }
|
|
|
|
const auto& stats = account(db).statistics(db);
|
|
if( stats.most_recent_op == account_transaction_history_id_type() ) return result;
|
|
const account_transaction_history_object* node = &stats.most_recent_op(db);
|
|
if( start == operation_history_id_type() )
|
|
start = node->operation_id;
|
|
|
|
while(node && node->operation_id.instance.value > stop.instance.value && result.size() < limit)
|
|
{
|
|
if( node->operation_id.instance.value <= start.instance.value ) {
|
|
|
|
if(node->operation_id(db).op.which() == operation_id)
|
|
result.push_back( node->operation_id(db) );
|
|
}
|
|
if( node->next == account_transaction_history_id_type() )
|
|
node = nullptr;
|
|
else node = &node->next(db);
|
|
}
|
|
if( stop.instance.value == 0 && result.size() < limit ) {
|
|
auto head = db.find(account_transaction_history_id_type());
|
|
if (head != nullptr && head->account == account && head->operation_id(db).op.which() == operation_id)
|
|
result.push_back(head->operation_id(db));
|
|
}
|
|
return result;
|
|
}
|
|
|
|
|
|
vector<operation_history_object> history_api::get_relative_account_history( const std::string account_id_or_name,
|
|
uint32_t stop,
|
|
unsigned limit,
|
|
uint32_t start) const
|
|
{
|
|
FC_ASSERT( _app.chain_database() );
|
|
const auto& db = *_app.chain_database();
|
|
FC_ASSERT(limit <= 100);
|
|
vector<operation_history_object> result;
|
|
account_id_type account;
|
|
try {
|
|
account = database_api.get_account_id_from_string(account_id_or_name);
|
|
} catch(...) { return result; }
|
|
const auto& stats = account(db).statistics(db);
|
|
if( start == 0 )
|
|
start = stats.total_ops;
|
|
else
|
|
start = min( stats.total_ops, start );
|
|
|
|
|
|
if( start >= stop && start > stats.removed_ops && limit > 0 )
|
|
{
|
|
const auto& hist_idx = db.get_index_type<account_transaction_history_index>();
|
|
const auto& by_seq_idx = hist_idx.indices().get<by_seq>();
|
|
|
|
auto itr = by_seq_idx.upper_bound( boost::make_tuple( account, start ) );
|
|
auto itr_stop = by_seq_idx.lower_bound( boost::make_tuple( account, stop ) );
|
|
|
|
do
|
|
{
|
|
--itr;
|
|
result.push_back( itr->operation_id(db) );
|
|
}
|
|
while ( itr != itr_stop && result.size() < limit );
|
|
}
|
|
return result;
|
|
}
|
|
|
|
vector<account_balance_object> history_api::list_core_accounts()const
|
|
{
|
|
auto list = _app.get_plugin<accounts_list_plugin>( "accounts_list" );
|
|
FC_ASSERT( list );
|
|
return list->list_accounts();
|
|
}
|
|
|
|
flat_set<uint32_t> history_api::get_market_history_buckets()const
|
|
{
|
|
auto hist = _app.get_plugin<market_history_plugin>( "market_history" );
|
|
FC_ASSERT( hist );
|
|
return hist->tracked_buckets();
|
|
}
|
|
|
|
vector<bucket_object> history_api::get_market_history( std::string asset_a, std::string asset_b,
|
|
uint32_t bucket_seconds, fc::time_point_sec start, fc::time_point_sec end )const
|
|
{ try {
|
|
FC_ASSERT(_app.chain_database());
|
|
const auto& db = *_app.chain_database();
|
|
asset_id_type a = database_api.get_asset_id_from_string( asset_a );
|
|
asset_id_type b = database_api.get_asset_id_from_string( asset_b );
|
|
vector<bucket_object> result;
|
|
result.reserve(200);
|
|
|
|
if( a > b ) std::swap(a,b);
|
|
|
|
const auto& bidx = db.get_index_type<bucket_index>();
|
|
const auto& by_key_idx = bidx.indices().get<by_key>();
|
|
|
|
auto itr = by_key_idx.lower_bound( bucket_key( a, b, bucket_seconds, start ) );
|
|
while( itr != by_key_idx.end() && itr->key.open <= end && result.size() < 200 )
|
|
{
|
|
if( !(itr->key.base == a && itr->key.quote == b && itr->key.seconds == bucket_seconds) )
|
|
{
|
|
return result;
|
|
}
|
|
result.push_back(*itr);
|
|
++itr;
|
|
}
|
|
return result;
|
|
} FC_CAPTURE_AND_RETHROW( (asset_a)(asset_b)(bucket_seconds)(start)(end) ) }
|
|
|
|
crypto_api::crypto_api(){};
|
|
|
|
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 );
|
|
}
|
|
|
|
// asset_api
|
|
asset_api::asset_api(graphene::app::application& app) :
|
|
_app(app),
|
|
_db( *app.chain_database()),
|
|
database_api( std::ref(*app.chain_database())) { }
|
|
asset_api::~asset_api() { }
|
|
|
|
vector<account_asset_balance> asset_api::get_asset_holders( std::string asset, uint32_t start, uint32_t limit ) const {
|
|
FC_ASSERT(limit <= 100);
|
|
|
|
asset_id_type asset_id = database_api.get_asset_id_from_string( asset );
|
|
const auto& bal_idx = _db.get_index_type< account_balance_index >().indices().get< by_asset_balance >();
|
|
auto range = bal_idx.equal_range( boost::make_tuple( asset_id ) );
|
|
|
|
vector<account_asset_balance> result;
|
|
|
|
uint32_t index = 0;
|
|
for( const account_balance_object& bal : boost::make_iterator_range( range.first, range.second ) )
|
|
{
|
|
if( result.size() >= limit )
|
|
break;
|
|
|
|
if( bal.balance.value == 0 )
|
|
continue;
|
|
|
|
if( index++ < start )
|
|
continue;
|
|
|
|
const auto account = _db.find(bal.owner);
|
|
|
|
account_asset_balance aab;
|
|
aab.name = account->name;
|
|
aab.account_id = account->id;
|
|
aab.amount = bal.balance.value;
|
|
|
|
result.push_back(aab);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
// get number of asset holders.
|
|
int asset_api::get_asset_holders_count( std::string asset ) const {
|
|
|
|
const auto& bal_idx = _db.get_index_type< account_balance_index >().indices().get< by_asset_balance >();
|
|
asset_id_type asset_id = database_api.get_asset_id_from_string( asset );
|
|
auto range = bal_idx.equal_range( boost::make_tuple( asset_id ) );
|
|
int count = boost::distance(range) - 1;
|
|
|
|
return count;
|
|
}
|
|
// function to get vector of system assets with holders count.
|
|
vector<asset_holders> asset_api::get_all_asset_holders() const {
|
|
|
|
vector<asset_holders> result;
|
|
|
|
vector<asset_id_type> total_assets;
|
|
for( const asset_object& asset_obj : _db.get_index_type<asset_index>().indices() )
|
|
{
|
|
const auto& dasset_obj = asset_obj.dynamic_asset_data_id(_db);
|
|
|
|
asset_id_type asset_id;
|
|
asset_id = dasset_obj.id;
|
|
|
|
const auto& bal_idx = _db.get_index_type< account_balance_index >().indices().get< by_asset_balance >();
|
|
auto range = bal_idx.equal_range( boost::make_tuple( asset_id ) );
|
|
|
|
int count = boost::distance(range) - 1;
|
|
|
|
asset_holders ah;
|
|
ah.asset_id = asset_id;
|
|
ah.count = count;
|
|
|
|
result.push_back(ah);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
} } // graphene::app
|