Skip to content

[HARDFORK] Feature/asset disable limit order create flag #1611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions libraries/chain/include/graphene/chain/asset_object.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ namespace graphene { namespace chain {
bool is_transfer_restricted()const { return options.flags & transfer_restricted; }
bool can_override()const { return options.flags & override_authority; }
bool allow_confidential()const { return !(options.flags & asset_issuer_permission_flags::disable_confidential); }
/// @return true if limit orders can only be created by the issuer
bool only_issuer_limit_orders_allowed()const {return options.flags & asset_issuer_permission_flags::only_issuer_limit_orders_allowed; }

/// Helper function to get an asset object with the given amount in this asset's type
asset amount(share_type a)const { return asset(a, id); }
Expand Down
8 changes: 5 additions & 3 deletions libraries/chain/include/graphene/chain/protocol/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,12 @@ namespace graphene { namespace chain {
global_settle = 0x20, /**< allow the bitasset issuer to force a global settling -- this may be set in permissions, but not flags */
disable_confidential = 0x40, /**< allow the asset to be used with confidential transactions */
witness_fed_asset = 0x80, /**< allow the asset to be fed by witnesses */
committee_fed_asset = 0x100 /**< allow the asset to be fed by the committee */
committee_fed_asset = 0x100,/**< allow the asset to be fed by the committee */
only_issuer_limit_orders_allowed = 0x200/**< allow limit orders only to be created by the issuer */
};
const static uint32_t ASSET_ISSUER_PERMISSION_MASK = charge_market_fee|white_list|override_authority|transfer_restricted|disable_force_settle|global_settle|disable_confidential
|witness_fed_asset|committee_fed_asset;
const static uint32_t UIA_ASSET_ISSUER_PERMISSION_MASK = charge_market_fee|white_list|override_authority|transfer_restricted|disable_confidential;
|witness_fed_asset|committee_fed_asset|only_issuer_limit_orders_allowed;
const static uint32_t UIA_ASSET_ISSUER_PERMISSION_MASK = charge_market_fee|white_list|override_authority|transfer_restricted|disable_confidential|only_issuer_limit_orders_allowed;

enum reserved_spaces
{
Expand Down Expand Up @@ -417,4 +418,5 @@ FC_REFLECT_ENUM( graphene::chain::asset_issuer_permission_flags,
(disable_confidential)
(witness_fed_asset)
(committee_fed_asset)
(only_issuer_limit_orders_allowed)
)
1 change: 0 additions & 1 deletion libraries/chain/is_authorized_asset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ bool _is_authorized_asset(
if( asset_obj.options.blacklist_authorities.find(id) != asset_obj.options.blacklist_authorities.end() )
return false;
}

if( d.head_block_time() > HARDFORK_415_TIME )
{
if( asset_obj.options.whitelist_authorities.size() == 0 )
Expand Down
3 changes: 3 additions & 0 deletions libraries/chain/market_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ void_result limit_order_create_evaluator::do_evaluate(const limit_order_create_o
FC_ASSERT( _sell_asset->options.blacklist_markets.find(_receive_asset->id)
== _sell_asset->options.blacklist_markets.end(),
"This market has been blacklisted." );

if( _sell_asset->options.flags & only_issuer_limit_orders_allowed && _seller->get_id() != _sell_asset->issuer )
FC_ASSERT( false, "limit order forbidden by asset permission flag" );

FC_ASSERT( is_authorized_asset( d, *_seller, *_sell_asset ) );
FC_ASSERT( is_authorized_asset( d, *_seller, *_receive_asset ) );
Expand Down
2 changes: 1 addition & 1 deletion libraries/fc
Submodule fc updated 58 files
+4 −12 .travis.yml
+1 −3 CMakeLists.txt
+4 −4 include/fc/asio.hpp
+1 −6 include/fc/config.hpp
+12 −0 include/fc/container/deque.hpp
+18 −21 include/fc/container/flat.hpp
+4 −4 include/fc/container/flat_fwd.hpp
+1 −0 include/fc/crypto/rand.hpp
+0 −5 include/fc/crypto/sha1.hpp
+27 −0 include/fc/interprocess/container.hpp
+2 −0 include/fc/io/json.hpp
+51 −27 include/fc/io/raw.hpp
+3 −0 include/fc/io/raw_fwd.hpp
+3 −3 include/fc/io/raw_variant.hpp
+58 −20 include/fc/io/varint.hpp
+1 −1 include/fc/log/file_appender.hpp
+1 −1 include/fc/log/gelf_appender.hpp
+0 −10 include/fc/reflect/reflect.hpp
+2 −28 include/fc/reflect/typename.hpp
+0 −2 include/fc/rpc/cli.hpp
+52 −198 include/fc/static_variant.hpp
+2 −3 include/fc/thread/future.hpp
+0 −106 include/fc/thread/parallel.hpp
+0 −2 include/fc/thread/task.hpp
+4 −24 include/fc/thread/thread.hpp
+4 −6 include/fc/variant.hpp
+11 −10 src/asio.cpp
+1 −5 src/crypto/openssl.cpp
+10 −0 src/crypto/rand.cpp
+10 −17 src/filesystem.cpp
+1 −7 src/io/fstream.cpp
+1 −1 src/io/json.cpp
+3 −1 src/io/varint.cpp
+22 −17 src/log/file_appender.cpp
+0 −7 src/network/http/websocket.cpp
+12 −30 src/rpc/cli.cpp
+2 −2 src/stacktrace.cpp
+0 −31 src/static_variant.cpp
+1 −6 src/thread/context.hpp
+0 −202 src/thread/parallel.cpp
+51 −52 src/thread/thread.cpp
+3 −22 src/thread/thread_d.hpp
+0 −1 src/variant.cpp
+0 −2 tests/CMakeLists.txt
+2 −2 tests/crypto/dh_test.cpp
+14 −0 tests/crypto/rand_test.cpp
+2 −2 tests/io/json_tests.cpp
+30 −30 tests/io/stream_tests.cpp
+4 −0 tests/io/tcp_test.cpp
+0 −98 tests/io/varint_tests.cpp
+1 −1 tests/network/http/websocket_test.cpp
+7 −19 tests/run-parallel-tests.sh
+0 −20 tests/serialization_test.cpp
+2 −40 tests/stacktrace_test.cpp
+0 −342 tests/thread/parallel_tests.cpp
+0 −49 tests/variant_test.cpp
+1 −1 vendor/editline
+1 −1 vendor/websocketpp
93 changes: 93 additions & 0 deletions tests/tests/operation_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2357,6 +2357,99 @@ BOOST_AUTO_TEST_CASE( vesting_balance_withdraw_test )
// TODO: Test with non-core asset and Bob account
} FC_LOG_AND_RETHROW() }

BOOST_AUTO_TEST_CASE( asset_only_issuer_limit_orders_allowed_test )
{
ACTORS( (alice) (bob) );

signed_transaction trx;
asset_object test_asset;
asset_id_type test_asset_id;

generate_blocks( HARDFORK_572_TIME + fc::seconds(20) );
generate_block();

#define EDUMP(X) edump((X));

EDUMP( "creating a test asset with only_issuer_limit_orders_allowed" );
{
asset_options a_opt;
a_opt.max_supply = 1000;
a_opt.core_exchange_rate = price( asset( 4, asset_id_type(1) ), asset( 4, asset_id_type() ) );
a_opt.flags = only_issuer_limit_orders_allowed;

asset_create_operation acop;
acop.fee = asset(0);
acop.issuer = alice_id;
acop.symbol = "TST";
acop.common_options = a_opt;

set_expiration( db, trx );
trx.operations.push_back( acop );
PUSH_TX( db, trx, ~0 );

test_asset = *db.get_index_type<asset_index>().indices().get<by_symbol>().find("TST");
test_asset_id = test_asset.get_id();

BOOST_CHECK( test_asset.only_issuer_limit_orders_allowed() );
}

EDUMP( "creating a limit order with alice acc" );
{
// issue the asset
asset_issue_operation aiop;
aiop.fee = asset(0);
aiop.issuer = alice_id;
aiop.issue_to_account = alice_id;
aiop.asset_to_issue = asset( test_asset.options.max_supply, test_asset_id );

trx = signed_transaction();
set_expiration( db, trx );
trx.operations.push_back( aiop );
PUSH_TX( db, trx, ~0 );

// create limit order
limit_order_create_operation locop;
locop.fee = asset(0);
locop.seller = alice_id;
locop.amount_to_sell = asset( 100, test_asset_id );
locop.min_to_receive = asset( 100 );

trx = signed_transaction();
set_expiration( db, trx );
trx.operations.push_back( locop );

PUSH_TX( db, trx, ~0 );
}

EDUMP( "creating a limit order with bob acc" );
{
// transfer test_asset to bob
transfer_operation top;
top.fee = asset(0);
top.amount = asset( 200, test_asset_id );
top.from = alice_id;
top.to = bob_id;

trx = signed_transaction();
set_expiration( db, trx );
trx.operations.push_back( top );

PUSH_TX( db, trx, ~0 );

// create limit order
limit_order_create_operation locop;
locop.fee = asset(0);
locop.seller = bob_id;
locop.amount_to_sell = asset( 100, test_asset_id );
locop.min_to_receive = asset( 100 );

trx = signed_transaction();
set_expiration( db, trx );
trx.operations.push_back( locop );

GRAPHENE_REQUIRE_THROW( PUSH_TX( db, trx, ~0 ), fc::assert_exception );
}
}
// TODO: Write linear VBO tests

BOOST_AUTO_TEST_SUITE_END()