Skip to content

Commit

Permalink
Merge pull request #2469 from bitshares/pr-2351-samet-fund
Browse files Browse the repository at this point in the history
Implement no-collateral funding
  • Loading branch information
abitmore authored Jun 14, 2021
2 parents 3f15b32 + 7c77425 commit 8fa5eeb
Show file tree
Hide file tree
Showing 48 changed files with 3,118 additions and 612 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/build-and-test.ubuntu-debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,19 @@ jobs:
run: |
_build/tests/app_test -l test_suite
df -h
rm -rf /tmp/graphene*
curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings \
-d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }'
echo
_build/tests/es_test -l test_suite
df -h
rm -rf /tmp/graphene*
libraries/fc/tests/run-parallel-tests.sh _build/tests/chain_test -l test_suite
df -h
rm -rf /tmp/graphene*
_build/tests/cli_test -l test_suite
df -h
rm -rf /tmp/graphene*
- name: Quick test for program arguments
run: |
_build/programs/witness_node/witness_node --version
Expand Down
56 changes: 41 additions & 15 deletions .github/workflows/sonar-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,6 @@ jobs:
du -hs _build/libraries/* _build/programs/* _build/tests/*
du -hs _build/*
du -hs /_build/*
- name: Unit-Tests
run: |
_build/tests/app_test -l test_suite
df -h
curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings \
-d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }'
echo
_build/tests/es_test -l test_suite
df -h
libraries/fc/tests/run-parallel-tests.sh _build/tests/chain_test -l test_suite
_build/tests/cli_test -l test_suite
df -h
echo "Cleanup"
rm -rf /tmp/graphene*
df -h
- name: Quick test for program arguments
run: |
_build/programs/witness_node/witness_node --version
Expand Down Expand Up @@ -156,6 +141,38 @@ jobs:
else \
echo "Pass: got expected error."; \
fi
- name: Remove binaries that we no longer need
run: |
df -h
echo "Cleanup"
rm -rf _build/programs/witness_node/witness_node
rm -rf _build/programs/cli_wallet/cli_wallet
rm -rf _build/programs/network_mapper/network_mapper
rm -rf _build/programs/js_operation_serializer/js_operation_serializer
rm -rf _build/programs/genesis_util/get_dev_key
df -h
- name: Unit-Tests
run: |
_build/tests/app_test -l test_suite
df -h
echo "Cleanup"
rm -rf /tmp/graphene*
curl -XPUT -H "Content-Type: application/json" http://localhost:9200/_cluster/settings \
-d '{ "transient": { "cluster.routing.allocation.disk.threshold_enabled": false } }'
echo
_build/tests/es_test -l test_suite
df -h
echo "Cleanup"
rm -rf /tmp/graphene*
libraries/fc/tests/run-parallel-tests.sh _build/tests/chain_test -l test_suite
df -h
echo "Cleanup"
rm -rf /tmp/graphene*
_build/tests/cli_test -l test_suite
df -h
echo "Cleanup"
rm -rf /tmp/graphene*
df -h
- name: Prepare for scanning with SonarScanner
run: |
mkdir -p sonar_cache
Expand Down Expand Up @@ -183,3 +200,12 @@ jobs:
run: |
sonar-scanner \
-Dsonar.login=${{ secrets.SONAR_TOKEN }}
- name: Cleanup
run: |
df -h
echo "Final cleanup"
rm -rf _build/tests/app_test
rm -rf _build/tests/chain_test
rm -rf _build/tests/cli_test
rm -rf _build/tests/es_test
df -h
5 changes: 5 additions & 0 deletions libraries/app/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ void application_impl::set_api_limit() {
_app_options.api_limit_get_liquidity_pool_history =
_options->at("api-limit-get-liquidity-pool-history").as<uint64_t>();
}
if(_options->count("api-limit-get-samet-funds") > 0) {
_app_options.api_limit_get_samet_funds = _options->at("api-limit-get-samet-funds").as<uint64_t>();
}
}

graphene::chain::genesis_state_type application_impl::initialize_genesis_state() const
Expand Down Expand Up @@ -1188,6 +1191,8 @@ void application::set_program_options(boost::program_options::options_descriptio
"Set maximum limit value for database APIs which query for liquidity pools")
("api-limit-get-liquidity-pool-history", boost::program_options::value<uint64_t>()->default_value(101),
"Set maximum limit value for APIs which query for history of liquidity pools")
("api-limit-get-samet-funds", boost::program_options::value<uint64_t>()->default_value(101),
"Set maximum limit value for database APIs which query for SameT Funds")
;
command_line_options.add(configuration_file_options);
command_line_options.add_options()
Expand Down
123 changes: 123 additions & 0 deletions libraries/app/database_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2075,6 +2075,129 @@ vector<extended_liquidity_pool_object> database_api_impl::get_liquidity_pools_by
return results;
}

//////////////////////////////////////////////////////////////////////
// //
// SameT Funds //
// //
//////////////////////////////////////////////////////////////////////

vector<samet_fund_object> database_api::list_samet_funds(
const optional<uint32_t>& limit,
const optional<samet_fund_id_type>& start_id )const
{
return my->list_samet_funds( limit, start_id );
}

vector<samet_fund_object> database_api_impl::list_samet_funds(
const optional<uint32_t>& olimit,
const optional<samet_fund_id_type>& ostart_id )const
{
uint32_t limit = olimit.valid() ? *olimit : 101;

FC_ASSERT( _app_options, "Internal error" );
const auto configured_limit = _app_options->api_limit_get_samet_funds;
FC_ASSERT( limit <= configured_limit,
"limit can not be greater than ${configured_limit}",
("configured_limit", configured_limit) );

vector<samet_fund_object> results;

samet_fund_id_type start_id = ostart_id.valid() ? *ostart_id : samet_fund_id_type();

const auto& idx = _db.get_index_type<samet_fund_index>().indices().get<by_id>();
auto lower_itr = idx.lower_bound( start_id );
auto upper_itr = idx.end();

results.reserve( limit );
for ( ; lower_itr != upper_itr && results.size() < limit; ++lower_itr )
{
results.emplace_back( *lower_itr );
}

return results;
}

vector<samet_fund_object> database_api::get_samet_funds_by_owner(
const std::string& account_name_or_id,
const optional<uint32_t>& limit,
const optional<samet_fund_id_type>& start_id )const
{
return my->get_samet_funds_by_owner( account_name_or_id, limit, start_id );
}

vector<samet_fund_object> database_api_impl::get_samet_funds_by_owner(
const std::string& account_name_or_id,
const optional<uint32_t>& olimit,
const optional<samet_fund_id_type>& ostart_id )const
{
uint32_t limit = olimit.valid() ? *olimit : 101;

FC_ASSERT( _app_options, "Internal error" );
const auto configured_limit = _app_options->api_limit_get_samet_funds;
FC_ASSERT( limit <= configured_limit,
"limit can not be greater than ${configured_limit}",
("configured_limit", configured_limit) );

account_id_type owner = get_account_from_string(account_name_or_id)->id;

vector<samet_fund_object> results;

samet_fund_id_type start_id = ostart_id.valid() ? *ostart_id : samet_fund_id_type();

const auto& idx = _db.get_index_type<samet_fund_index>().indices().get<by_owner>();
auto lower_itr = idx.lower_bound( std::make_tuple( owner, start_id ) );
auto upper_itr = idx.upper_bound( owner );

results.reserve( limit );
for ( ; lower_itr != upper_itr && results.size() < limit; ++lower_itr )
{
results.emplace_back( *lower_itr );
}

return results;
}

vector<samet_fund_object> database_api::get_samet_funds_by_asset(
const std::string& asset_symbol_or_id,
const optional<uint32_t>& limit,
const optional<samet_fund_id_type>& start_id )const
{
return my->get_samet_funds_by_asset( asset_symbol_or_id, limit, start_id );
}

vector<samet_fund_object> database_api_impl::get_samet_funds_by_asset(
const std::string& asset_symbol_or_id,
const optional<uint32_t>& olimit,
const optional<samet_fund_id_type>& ostart_id )const
{
uint32_t limit = olimit.valid() ? *olimit : 101;

FC_ASSERT( _app_options, "Internal error" );
const auto configured_limit = _app_options->api_limit_get_samet_funds;
FC_ASSERT( limit <= configured_limit,
"limit can not be greater than ${configured_limit}",
("configured_limit", configured_limit) );

asset_id_type asset_type = get_asset_from_string(asset_symbol_or_id)->id;

vector<samet_fund_object> results;

samet_fund_id_type start_id = ostart_id.valid() ? *ostart_id : samet_fund_id_type();

const auto& idx = _db.get_index_type<samet_fund_index>().indices().get<by_asset_type>();
auto lower_itr = idx.lower_bound( std::make_tuple( asset_type, start_id ) );
auto upper_itr = idx.upper_bound( asset_type );

results.reserve( limit );
for ( ; lower_itr != upper_itr && results.size() < limit; ++lower_itr )
{
results.emplace_back( *lower_itr );
}

return results;
}


//////////////////////////////////////////////////////////////////////
// //
// Witnesses //
Expand Down
13 changes: 13 additions & 0 deletions libraries/app/database_api_impl.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,19 @@ class database_api_impl : public std::enable_shared_from_this<database_api_impl>
optional<asset_id_type> start_id = optional<asset_id_type>(),
optional<bool> with_statistics = false )const;

// SameT Funds
vector<samet_fund_object> list_samet_funds(
const optional<uint32_t>& limit = 101,
const optional<samet_fund_id_type>& start_id = optional<samet_fund_id_type>() )const;
vector<samet_fund_object> get_samet_funds_by_owner(
const std::string& account_name_or_id,
const optional<uint32_t>& limit = 101,
const optional<samet_fund_id_type>& start_id = optional<samet_fund_id_type>() )const;
vector<samet_fund_object> get_samet_funds_by_asset(
const std::string& asset_symbol_or_id,
const optional<uint32_t>& limit = 101,
const optional<samet_fund_id_type>& start_id = optional<samet_fund_id_type>() )const;

// Witnesses
vector<optional<witness_object>> get_witnesses(const vector<witness_id_type>& witness_ids)const;
fc::optional<witness_object> get_witness_by_account(const std::string account_id_or_name)const;
Expand Down
1 change: 1 addition & 0 deletions libraries/app/include/graphene/app/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ namespace graphene { namespace app {
uint64_t api_limit_get_tickets = 101;
uint64_t api_limit_get_liquidity_pools = 101;
uint64_t api_limit_get_liquidity_pool_history = 101;
uint64_t api_limit_get_samet_funds = 101;
};

class application
Expand Down
65 changes: 62 additions & 3 deletions libraries/app/include/graphene/app/database_api.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,15 @@
#include <graphene/chain/chain_property_object.hpp>
#include <graphene/chain/committee_member_object.hpp>
#include <graphene/chain/confidential_object.hpp>
#include <graphene/chain/liquidity_pool_object.hpp>
#include <graphene/chain/operation_history_object.hpp>
#include <graphene/chain/samet_fund_object.hpp>
#include <graphene/chain/ticket_object.hpp>
#include <graphene/chain/worker_object.hpp>
#include <graphene/chain/witness_object.hpp>

#include <fc/api.hpp>
#include <fc/variant_object.hpp>

#include <fc/network/ip.hpp>

#include <boost/container/flat_set.hpp>

#include <functional>
Expand Down Expand Up @@ -788,6 +786,62 @@ class database_api
optional<asset_id_type> start_id = optional<asset_id_type>(),
optional<bool> with_statistics = false )const;

/////////////////////
// SameT Funds //
/////////////////////

/**
* @brief Get a list of SameT Funds
* @param limit The limitation of items each query can fetch, not greater than a configured value
* @param start_id Start SameT Fund id, fetch items whose IDs are greater than or equal to this ID
* @return The SameT Funds
*
* @note
* 1. @p limit can be omitted or be null, if so the default value 101 will be used
* 2. @p start_id can be omitted or be null, if so the api will return the "first page" of data
* 3. can only omit one or more arguments in the end of the list, but not one or more in the middle
*/
vector<samet_fund_object> list_samet_funds(
const optional<uint32_t>& limit = 101,
const optional<samet_fund_id_type>& start_id = optional<samet_fund_id_type>() )const;

/**
* @brief Get a list of SameT Funds by the name or ID of the owner account
* @param account_name_or_id name or ID of the owner account
* @param limit The limitation of items each query can fetch, not greater than a configured value
* @param start_id Start Samet Fund id, fetch items whose IDs are greater than or equal to this ID
* @return The SameT Funds
*
* @note
* 1. if @p account_name_or_id cannot be tied to an account, an error will be returned
* 2. @p limit can be omitted or be null, if so the default value 101 will be used
* 3. @p start_id can be omitted or be null, if so the api will return the "first page" of data
* 4. can only omit one or more arguments in the end of the list, but not one or more in the middle
*/
vector<samet_fund_object> get_samet_funds_by_owner(
const std::string& account_name_or_id,
const optional<uint32_t>& limit = 101,
const optional<samet_fund_id_type>& start_id = optional<samet_fund_id_type>() )const;

/**
* @brief Get a list of SameT Funds by the symbole or ID of the asset type
* @param asset_symbol_or_id symbol or ID of the asset type
* @param limit The limitation of items each query can fetch, not greater than a configured value
* @param start_id Start Samet Fund id, fetch items whose IDs are greater than or equal to this ID
* @return The SameT Funds
*
* @note
* 1. if @p asset_symbol_or_id cannot be tied to an asset, an error will be returned
* 2. @p limit can be omitted or be null, if so the default value 101 will be used
* 3. @p start_id can be omitted or be null, if so the api will return the "first page" of data
* 4. can only omit one or more arguments in the end of the list, but not one or more in the middle
*/
vector<samet_fund_object> get_samet_funds_by_asset(
const std::string& asset_symbol_or_id,
const optional<uint32_t>& limit = 101,
const optional<samet_fund_id_type>& start_id = optional<samet_fund_id_type>() )const;


///////////////
// Witnesses //
///////////////
Expand Down Expand Up @@ -1205,6 +1259,11 @@ FC_API(graphene::app::database_api,
(get_liquidity_pools_by_share_asset)
(get_liquidity_pools_by_owner)

// SameT Funds
(list_samet_funds)
(get_samet_funds_by_owner)
(get_samet_funds_by_asset)

// Witnesses
(get_witnesses)
(get_witness_by_account)
Expand Down
5 changes: 4 additions & 1 deletion libraries/chain/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ if( GRAPHENE_DISABLE_UNITY_BUILD )
db_balance.cpp
db_block.cpp
db_debug.cpp
db_genesis.cpp
db_getter.cpp
db_init.cpp
db_maint.cpp
db_management.cpp
db_market.cpp
db_notify.cpp
db_update.cpp
db_witness_schedule.cpp
db_notify.cpp
)
message( STATUS "Graphene database unity build disabled" )
else( GRAPHENE_DISABLE_UNITY_BUILD )
Expand All @@ -37,6 +38,7 @@ add_library( graphene_chain

evaluator.cpp
liquidity_pool_evaluator.cpp
samet_fund_evaluator.cpp
balance_evaluator.cpp
account_evaluator.cpp
assert_evaluator.cpp
Expand Down Expand Up @@ -80,6 +82,7 @@ target_include_directories( graphene_chain

set( GRAPHENE_CHAIN_BIG_FILES
db_init.cpp
db_genesis.cpp
db_block.cpp
db_maint.cpp
db_market.cpp
Expand Down
Loading

0 comments on commit 8fa5eeb

Please sign in to comment.