From 392e04119d133a58476f45dbb2f080987068c7cf Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 22 Nov 2019 08:06:28 +0100 Subject: [PATCH 01/59] Added stored_value class --- libraries/chain/CMakeLists.txt | 1 + .../include/graphene/chain/stored_value.hpp | 53 +++++++++++ libraries/chain/stored_value.cpp | 93 +++++++++++++++++++ 3 files changed, 147 insertions(+) create mode 100644 libraries/chain/include/graphene/chain/stored_value.hpp create mode 100644 libraries/chain/stored_value.cpp diff --git a/libraries/chain/CMakeLists.txt b/libraries/chain/CMakeLists.txt index df07034a28..bd514568dd 100644 --- a/libraries/chain/CMakeLists.txt +++ b/libraries/chain/CMakeLists.txt @@ -53,6 +53,7 @@ add_library( graphene_chain special_authority_evaluation.cpp buyback.cpp + stored_value.cpp account_object.cpp asset_object.cpp fba_object.cpp diff --git a/libraries/chain/include/graphene/chain/stored_value.hpp b/libraries/chain/include/graphene/chain/stored_value.hpp new file mode 100644 index 0000000000..661ec25038 --- /dev/null +++ b/libraries/chain/include/graphene/chain/stored_value.hpp @@ -0,0 +1,53 @@ +/* (C) 2019 Peter Conrad + * + * 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 + +namespace graphene { namespace chain { + class stored_value + { + graphene::protocol::asset_id_type _asset; + graphene::protocol::share_type _amount; + public: + explicit stored_value( const graphene::protocol::asset_id_type asset = graphene::protocol::asset_id_type() ); + ~stored_value(); + stored_value( const stored_value& copy ) = delete; + stored_value( stored_value& copy ) = delete; + stored_value( stored_value&& move ); + + stored_value& operator=( const stored_value& copy ) = delete; + stored_value& operator=( stored_value& copy ) = delete; + stored_value& operator=( stored_value&& move ); + + stored_value split( const graphene::protocol::share_type amount ); + stored_value& operator+=( stored_value&& other ); + + static stored_value issue( const graphene::protocol::asset_id_type asset, + const graphene::protocol::share_type amount ); + void burn(); + graphene::protocol::asset get_value()const; + }; +} } // graphene::chain + diff --git a/libraries/chain/stored_value.cpp b/libraries/chain/stored_value.cpp new file mode 100644 index 0000000000..715ca15149 --- /dev/null +++ b/libraries/chain/stored_value.cpp @@ -0,0 +1,93 @@ +/* (C) 2019 Peter Conrad + * + * 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 + +#include + +namespace graphene { namespace chain { + stored_value::stored_value( const graphene::protocol::asset_id_type asset ) + : _asset(asset), _amount(0) {} + + stored_value::~stored_value() + { + FC_ASSERT( _amount == 0, "Value leak detected: (${n],${a])!", ("n",_amount.value)("a",_asset) ); + } + + stored_value::stored_value( stored_value&& move ) + : _asset(move._asset), _amount(move._amount) + { + move._amount = 0; + } + + stored_value& stored_value::operator=( stored_value&& other ) + { + if( &other == this ) return *this; + FC_ASSERT( _amount.value == 0, "Can't overwrite (${n},${a}) with (${on},${oa})!", + ("on",other._amount.value)("oa",other._asset)("n",_amount.value)("a",_asset) ); + _asset = other._asset; + _amount = other._amount; + other._amount = 0; + return *this; + } + + stored_value stored_value::split( const graphene::protocol::share_type amount ) + { + FC_ASSERT( amount <= _amount, "Invalid split: want ${w} but have only ${n} of ${a}", + ("w",amount)("n",_amount)("a",_asset) ); + stored_value result( _asset ); + result._amount = amount; + _amount -= amount; + return result; + } + + stored_value& stored_value::operator+=( stored_value&& other ) + { + FC_ASSERT( other._asset == _asset, "Can't merge (${on},${oa}) with (${n},${a})!", + ("on",other._amount.value)("oa",other._asset)("n",_amount.value)("a",_asset) ); + FC_ASSERT( &other != this, "Can't merge (${n},${a}) with itself!", + ("n",_amount.value)("a",_asset) ); + _amount += other._amount; + other._amount = 0; + return *this; + } + + stored_value stored_value::issue( const graphene::protocol::asset_id_type asset, + const graphene::protocol::share_type amount ) + { + stored_value result( asset ); + result._amount = amount; + return result; + } + + void stored_value::burn() + { + _amount = 0; + } + + graphene::protocol::asset stored_value::get_value()const + { + return graphene::protocol::asset( _amount, _asset ); + } +} } // graphene::chain + From cb9ae90c42ce13b0346272a86b5aa4860e214db8 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 22 Nov 2019 13:05:35 +0100 Subject: [PATCH 02/59] Minor refactoring of undo --- libraries/db/include/graphene/db/object.hpp | 21 +++++++++++++------ libraries/db/undo_database.cpp | 23 ++++++++++++--------- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/libraries/db/include/graphene/db/object.hpp b/libraries/db/include/graphene/db/object.hpp index 254b43483d..7f47c19512 100644 --- a/libraries/db/include/graphene/db/object.hpp +++ b/libraries/db/include/graphene/db/object.hpp @@ -30,6 +30,7 @@ #define MAX_NESTING (200) namespace graphene { namespace db { + class undo_database; /** * @brief base for all database objects @@ -65,14 +66,21 @@ namespace graphene { namespace db { object(){} virtual ~object(){} + static const uint8_t space_id = 0; + static const uint8_t type_id = 0; + // serialized object_id_type id; /// these methods are implemented for derived classes by inheriting abstract_object - virtual unique_ptr clone()const = 0; - virtual void move_from( object& obj ) = 0; virtual variant to_variant()const = 0; virtual vector pack()const = 0; + + protected: + virtual unique_ptr backup()const = 0; + virtual void clear() {} + virtual void restore( object& obj ) = 0; + friend class undo_database; }; /** @@ -85,16 +93,17 @@ namespace graphene { namespace db { template class abstract_object : public object { - public: - virtual unique_ptr clone()const + protected: + virtual unique_ptr backup()const { - return unique_ptr(new DerivedClass( *static_cast(this) )); + return std::make_unique( *static_cast(this) ); } - virtual void move_from( object& obj ) + virtual void restore( object& obj ) { static_cast(*this) = std::move( static_cast(obj) ); } + public: virtual variant to_variant()const { return variant( static_cast(*this), MAX_NESTING ); } virtual vector pack()const { return fc::raw::pack( static_cast(*this) ); } }; diff --git a/libraries/db/undo_database.cpp b/libraries/db/undo_database.cpp index 3e340728e3..64c5886e4f 100644 --- a/libraries/db/undo_database.cpp +++ b/libraries/db/undo_database.cpp @@ -81,7 +81,7 @@ void undo_database::on_modify( const object& obj ) return; auto itr = state.old_values.find(obj.id); if( itr != state.old_values.end() ) return; - state.old_values[obj.id] = obj.clone(); + state.old_values[obj.id] = obj.backup(); } void undo_database::on_remove( const object& obj ) { @@ -102,7 +102,7 @@ void undo_database::on_remove( const object& obj ) return; } if( state.removed.count(obj.id) ) return; - state.removed[obj.id] = obj.clone(); + state.removed[obj.id] = obj.backup(); } void undo_database::undo() @@ -113,19 +113,17 @@ void undo_database::undo() auto& state = _stack.back(); for( auto& item : state.old_values ) - { - _db.modify( _db.get_object( item.second->id ), [&]( object& obj ){ obj.move_from( *item.second ); } ); - } + _db.modify( _db.get_object( item.second->id ), [&item]( object& obj ){ obj.restore( *item.second ); } ); for( auto ritr = state.new_ids.begin(); ritr != state.new_ids.end(); ++ritr ) { - _db.remove( _db.get_object(*ritr) ); + const auto& obj = _db.get_object(*ritr); + _db.modify( obj, [] ( object& o ) { o.clear(); } ); + _db.remove( obj ); } for( auto& item : state.old_index_next_ids ) - { _db.get_mutable_index( item.first.space(), item.first.type() ).set_next_id( item.second ); - } for( auto& item : state.removed ) _db.insert( std::move(*item.second) ); @@ -196,11 +194,13 @@ void undo_database::merge() if( prev_state.new_ids.find(obj.second->id) != prev_state.new_ids.end() ) { // new+upd -> new, type A + obj.second->clear(); continue; } if( prev_state.old_values.find(obj.second->id) != prev_state.old_values.end() ) { // upd(was=X) + upd(was=Y) -> upd(was=X), type A + obj.second->clear(); continue; } // del+upd -> N/A @@ -236,6 +236,7 @@ void undo_database::merge() if( prev_state.new_ids.find(obj.second->id) != prev_state.new_ids.end() ) { // new + del -> nop (type C) + obj.second->clear(); prev_state.new_ids.erase(obj.second->id); continue; } @@ -272,12 +273,14 @@ void undo_database::pop_commit() for( auto& item : state.old_values ) { - _db.modify( _db.get_object( item.second->id ), [&]( object& obj ){ obj.move_from( *item.second ); } ); + _db.modify( _db.get_object( item.second->id ), [&item]( object& obj ){ obj.restore( *item.second ); } ); } for( auto ritr = state.new_ids.begin(); ritr != state.new_ids.end(); ++ritr ) { - _db.remove( _db.get_object(*ritr) ); + const auto& obj = _db.get_object(*ritr); + _db.modify( obj, [] ( object& o ) { o.clear(); } ); + _db.remove( obj ); } for( auto& item : state.old_index_next_ids ) From 0cbfeb5c579a16a1fd615e990297be896c4ae4db Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 29 Nov 2019 10:58:51 +0100 Subject: [PATCH 03/59] Intermediate --- libraries/chain/account_object.cpp | 125 +++++++++++++----- libraries/chain/db_balance.cpp | 57 +++++--- libraries/chain/db_debug.cpp | 18 +-- libraries/chain/db_init.cpp | 13 +- libraries/chain/db_maint.cpp | 102 +++++++------- libraries/chain/fba_object.cpp | 33 ++++- .../include/graphene/chain/account_object.hpp | 57 +++++--- .../chain/include/graphene/chain/database.hpp | 5 +- .../include/graphene/chain/fba_object.hpp | 17 ++- .../include/graphene/chain/stored_value.hpp | 53 ++++++++ libraries/chain/small_objects.cpp | 4 - libraries/db/include/graphene/db/index.hpp | 7 +- .../include/graphene/db/object_database.hpp | 2 +- 13 files changed, 334 insertions(+), 159 deletions(-) diff --git a/libraries/chain/account_object.cpp b/libraries/chain/account_object.cpp index 1840916113..f10093c19b 100644 --- a/libraries/chain/account_object.cpp +++ b/libraries/chain/account_object.cpp @@ -27,9 +27,11 @@ #include #include +#include "include/graphene/chain/stored_value.hpp" + namespace graphene { namespace chain { -share_type cut_fee(share_type a, uint16_t p) +static share_type cut_fee(share_type a, uint16_t p) { if( a == 0 || p == 0 ) return 0; @@ -42,19 +44,49 @@ share_type cut_fee(share_type a, uint16_t p) return static_cast(r); } -void account_balance_object::adjust_balance(const asset& delta) +void account_balance_object::add_balance( stored_value&& delta ) +{ + balance += std::move( delta ); + if( balance.get_asset() == asset_id_type() ) // CORE asset + maintenance_flag = true; +} + +stored_value account_balance_object::reduce_balance( share_type delta ) { - assert(delta.asset_id == asset_type); - balance += delta.amount; - if( asset_type == asset_id_type() ) // CORE asset + if( balance.get_asset() == asset_id_type() ) // CORE asset maintenance_flag = true; + return balance.split( delta ); +} + +class account_balance_backup : public account_balance_object_master +{ + private: + account_balance_backup( const account_balance_object& original ) + : account_balance_object_master( original ) + { + balance = original.balance.get_value(); + } + asset balance; + friend class account_statistics_object; +}; + +unique_ptr account_balance_object::backup()const +{ + return std::make_unique( *this ); +} + +void account_balance_object::restore( object& obj ) +{ + const auto& backup = static_cast(obj); + balance.restore( backup.balance ); + static_cast(*this) = std::move( backup ); } void account_statistics_object::process_fees(const account_object& a, database& d) const { if( pending_fees > 0 || pending_vested_fees > 0 ) { - auto pay_out_fees = [&](const account_object& account, share_type core_fee_total, bool require_vesting) + auto pay_out_fees = [&d]( const account_object& account, stored_value&& core_fee, bool require_vesting ) { // Check the referrer -- if he's no longer a member, pay to the lifetime referrer instead. // No need to check the registrar; registrars are required to be lifetime members. @@ -76,40 +108,61 @@ void account_statistics_object::process_fees(const account_object& a, database& share_type lifetime_cut = cut_fee(core_fee_total, account.lifetime_referrer_fee_percentage); share_type referral = core_fee_total - network_cut - lifetime_cut; - d.modify( d.get_core_dynamic_data(), [network_cut](asset_dynamic_data_object& addo) { - addo.accumulated_fees += network_cut; + d.modify( d.get_core_dynamic_data(), [network_cut,&core_fee](asset_dynamic_data_object& addo) { + addo.accumulated_fees += core_fee.split( network_cut ); }); // Potential optimization: Skip some of this math and object lookups by special casing on the account type. // For example, if the account is a lifetime member, we can skip all this and just deposit the referral to // it directly. share_type referrer_cut = cut_fee(referral, account.referrer_rewards_percentage); - share_type registrar_cut = referral - referrer_cut; - d.deposit_cashback(d.get(account.lifetime_referrer), lifetime_cut, require_vesting); - d.deposit_cashback(d.get(account.referrer), referrer_cut, require_vesting); - d.deposit_cashback(d.get(account.registrar), registrar_cut, require_vesting); - - assert( referrer_cut + registrar_cut + accumulated + reserveed + lifetime_cut == core_fee_total ); + d.deposit_cashback(d.get(account.lifetime_referrer), core_fee.split( lifetime_cut ), require_vesting); + d.deposit_cashback(d.get(account.referrer), core_fee.split( referrer_cut ), require_vesting); + d.deposit_cashback(d.get(account.registrar), std::move( core_fee ), require_vesting); }; - pay_out_fees(a, pending_fees, true); - pay_out_fees(a, pending_vested_fees, false); - - d.modify(*this, [&](account_statistics_object& s) { - s.lifetime_fees_paid += pending_fees + pending_vested_fees; - s.pending_fees = 0; - s.pending_vested_fees = 0; + d.modify(*this, [](account_statistics_object& s) { + s.lifetime_fees_paid += s.pending_fees.get_amount() + s.pending_vested_fees.get_amount(); }); + pay_out_fees(a, std::move( pending_fees ), true); + pay_out_fees(a, std::move( pending_vested_fees ), false); } } -void account_statistics_object::pay_fee( share_type core_fee, share_type cashback_vesting_threshold ) +void account_statistics_object::pay_fee( stored_value&& core_fee, share_type cashback_vesting_threshold ) { - if( core_fee > cashback_vesting_threshold ) - pending_fees += core_fee; + if( core_fee.get_amount() > cashback_vesting_threshold ) + pending_fees += std::move( core_fee ); else - pending_vested_fees += core_fee; + pending_vested_fees += std::move( core_fee ); +} + +class account_statistics_backup : public account_statistics_object_master +{ + private: + account_statistics_backup( const account_statistics_object& original ) + : account_statistics_object_master( original ) + { + pending_fees = original.pending_fees.get_amount(); + pending_vested_fees = original.pending_vested_fees.get_amount(); + } + share_type pending_fees; + share_type pending_vested_fees; + friend class account_statistics_object; +}; + +unique_ptr account_statistics_object::backup()const +{ + return std::make_unique( *this ); +} + +void account_statistics_object::restore( object& obj ) +{ + const auto& backup = static_cast(obj); + pending_fees.restore( asset( asset_id_type(), backup.pending_fees ) ); + pending_vested_fees.restore( asset( asset_id_type(), backup.pending_fees ) ); + static_cast(*this) = std::move( backup ); } set account_member_index::get_account_members(const account_object& a)const @@ -268,14 +321,14 @@ void balances_by_account_index::object_inserted( const object& obj ) balances.resize( balances.size() + 1 ); balances.back().resize( 1ULL << bits ); } - balances[abo.owner.instance.value >> bits][abo.owner.instance.value & mask][abo.asset_type] = &abo; + balances[abo.owner.instance.value >> bits][abo.owner.instance.value & mask][abo.get_asset()] = &abo; } void balances_by_account_index::object_removed( const object& obj ) { const auto& abo = dynamic_cast< const account_balance_object& >( obj ); if( balances.size() < (abo.owner.instance.value >> bits) + 1 ) return; - balances[abo.owner.instance.value >> bits][abo.owner.instance.value & mask].erase( abo.asset_type ); + balances[abo.owner.instance.value >> bits][abo.owner.instance.value & mask].erase( abo.get_asset() ); } void balances_by_account_index::about_to_modify( const object& before ) @@ -320,12 +373,16 @@ FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::account_object, (allowed_assets) ) -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::account_balance_object, +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::account_balance_master, (graphene::db::object), - (owner)(asset_type)(balance)(maintenance_flag) ) + (owner)(asset_type)(maintenance_flag) ) -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::account_statistics_object, - (graphene::chain::object), +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::account_balance_object, + (graphene::chain::account_balance_master), + (balance) ) + +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::account_statistics_master, + (graphene::db::object), (owner)(name) (most_recent_op) (total_ops)(removed_ops) @@ -335,9 +392,15 @@ FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::account_statistics_object, (is_voting) (last_vote_time) (lifetime_fees_paid) + ) + +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::account_statistics_object, + (graphene::chain::account_statistics_object), (pending_fees)(pending_vested_fees) ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::account_object ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::account_balance_object_master ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::account_balance_object ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::account_statistics_object_master ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::account_statistics_object ) diff --git a/libraries/chain/db_balance.cpp b/libraries/chain/db_balance.cpp index a75464e474..0078f89111 100644 --- a/libraries/chain/db_balance.cpp +++ b/libraries/chain/db_balance.cpp @@ -51,36 +51,53 @@ string database::to_pretty_string( const asset& a )const return a.asset_id(*this).amount_to_pretty_string(a.amount); } -void database::adjust_balance(account_id_type account, asset delta ) +void database::add_balance(account_id_type account, stored_value&& what ) { try { - if( delta.amount == 0 ) + if( what.get_amount() == 0 ) return; + FC_ASSERT( what.get_amount() > 0, "Cannot add a negative amount!" ); auto& index = get_index_type< primary_index< account_balance_index > >().get_secondary_index(); - auto abo = index.get_account_balance( account, delta.asset_id ); + auto abo = index.get_account_balance( account, what.get_asset() ); if( !abo ) - { - FC_ASSERT( delta.amount > 0, "Insufficient Balance: ${a}'s balance of ${b} is less than required ${r}", - ("a",account(*this).name) - ("b",to_pretty_string(asset(0,delta.asset_id))) - ("r",to_pretty_string(-delta))); - create([account,&delta](account_balance_object& b) { + create([account,delta = std::move(what)](account_balance_object& b) mutable { b.owner = account; - b.asset_type = delta.asset_id; - b.balance = delta.amount.value; - if( b.asset_type == asset_id_type() ) // CORE asset + b.balance = std::move(delta); + if( b.balance.get_asset() == asset_id_type() ) // CORE asset b.maintenance_flag = true; }); - } else { - if( delta.amount < 0 ) - FC_ASSERT( abo->get_balance() >= -delta, "Insufficient Balance: ${a}'s balance of ${b} is less than required ${r}", - ("a",account(*this).name)("b",to_pretty_string(abo->get_balance()))("r",to_pretty_string(-delta))); - modify(*abo, [delta](account_balance_object& b) { - b.adjust_balance(delta); + else + modify(*abo, [delta = std::move(what)] (account_balance_object& b) mutable { + if( b.balance.get_asset() == asset_id_type() ) // CORE asset + b.maintenance_flag = true; + b.balance += std::move(delta); }); - } +} FC_CAPTURE_AND_RETHROW( (account)(what) ) } + +stored_value database::reduce_balance( account_id_type account, const asset& how_much ) +{ try { + if( how_much.amount == 0 ) + return stored_value( how_much.asset_id ); + FC_ASSERT( how_much.amount > 0, "Cannot reduce by a negative amount!" ); -} FC_CAPTURE_AND_RETHROW( (account)(delta) ) } + auto& index = get_index_type< primary_index< account_balance_index > >().get_secondary_index(); + auto abo = index.get_account_balance( account, how_much.asset_id ); + FC_ASSERT( abo, "Insufficient Balance: ${a}'s balance of ${b} is less than required ${r}", + ("a",account(*this).name) + ("b",to_pretty_string(asset(0,how_much.asset_id))) + ("r",to_pretty_string(how_much.amount))); + FC_ASSERT( abo->get_amount() >= how_much.amount, + "Insufficient Balance: ${a}'s balance of ${b} is less than required ${r}", + ("a",account(*this).name)("b",to_pretty_string(abo->get_balance())) + ("r",to_pretty_string(how_much.amount))); + stored_value result; + modify(*abo, [&how_much,&result] (account_balance_object& b) { + if( b.balance.get_asset() == asset_id_type() ) // CORE asset + b.maintenance_flag = true; + result = b.balance.split( how_much.amount ); + }); + return result; +} FC_CAPTURE_AND_RETHROW( (account)(how_much) ) } namespace detail { diff --git a/libraries/chain/db_debug.cpp b/libraries/chain/db_debug.cpp index e6ab40fb70..0030edb71d 100644 --- a/libraries/chain/db_debug.cpp +++ b/libraries/chain/db_debug.cpp @@ -53,8 +53,7 @@ void database::debug_dump() for( const account_balance_object& a : balance_index ) { - // idump(("balance")(a)); - total_balances[a.asset_type] += a.balance; + total_balances[a.get_asset()] += a.get_amount(); } for( const force_settlement_object& s : settle_index ) { @@ -63,24 +62,21 @@ void database::debug_dump() for( const vesting_balance_object& vbo : db.get_index_type< vesting_balance_index >().indices() ) total_balances[ vbo.balance.asset_id ] += vbo.balance.amount; for( const fba_accumulator_object& fba : db.get_index_type< simple_index< fba_accumulator_object > >() ) - total_balances[ asset_id_type() ] += fba.accumulated_fba_fees; + total_balances[ asset_id_type() ] += fba.accumulated_fba_fees.get_amount(); for( const account_statistics_object& s : statistics_index ) { - // idump(("statistics")(s)); reported_core_in_orders += s.total_core_in_orders; } for( const collateral_bid_object& b : bids ) total_balances[b.inv_swan_price.base.asset_id] += b.inv_swan_price.base.amount; for( const limit_order_object& o : db.get_index_type().indices() ) { - // idump(("limit_order")(o)); auto for_sale = o.amount_for_sale(); if( for_sale.asset_id == asset_id_type() ) core_in_orders += for_sale.amount; total_balances[for_sale.asset_id] += for_sale.amount; } for( const call_order_object& o : db.get_index_type().indices() ) { -// idump(("call_order")(o)); auto col = o.get_collateral(); if( col.asset_id == asset_id_type() ) core_in_orders += col.amount; total_balances[col.asset_id] += col.amount; @@ -90,7 +86,6 @@ void database::debug_dump() { total_balances[asset_obj.id] += asset_obj.dynamic_asset_data_id(db).accumulated_fees; total_balances[asset_id_type()] += asset_obj.dynamic_asset_data_id(db).fee_pool; -// edump((total_balances[asset_obj.id])(asset_obj.dynamic_asset_data_id(db).current_supply ) ); } if( total_balances[asset_id_type()].value != core_asset_data.current_supply.value ) @@ -99,15 +94,6 @@ void database::debug_dump() ("computed value",total_balances[asset_id_type()].value) ("current supply",core_asset_data.current_supply.value) ); } - - - /* - const auto& vbidx = db.get_index_type>(); - for( const auto& s : vbidx ) - { -// idump(("vesting_balance")(s)); - } - */ } void debug_apply_update( database& db, const fc::variant_object& vo ) diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 8f5d29b6f4..9fe58a7187 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -191,7 +191,7 @@ void database::init_genesis(const genesis_state_type& genesis_state) // Create blockchain accounts fc::ecc::private_key null_private_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key"))); create([](account_balance_object& b) { - b.balance = GRAPHENE_MAX_SHARE_SUPPLY; + b.balance = stored_value::issue( asset_id_type(), GRAPHENE_MAX_SHARE_SUPPLY ); }); const account_object& committee_account = create( [&](account_object& n) { @@ -530,7 +530,7 @@ void database::init_genesis(const genesis_state_type& genesis_state) if( total_supplies[ asset_id_type(0) ] > 0 ) { - adjust_balance(GRAPHENE_COMMITTEE_ACCOUNT, -get_balance(GRAPHENE_COMMITTEE_ACCOUNT,{})); + reduce_balance( GRAPHENE_COMMITTEE_ACCOUNT, -get_balance(GRAPHENE_COMMITTEE_ACCOUNT,{}) ).burn(); } else { @@ -636,28 +636,25 @@ void database::init_genesis(const genesis_state_type& genesis_state) }); // Create FBA counters - create([&]( fba_accumulator_object& acc ) + create([]( fba_accumulator_object& acc ) { FC_ASSERT( acc.id == fba_accumulator_id_type( fba_accumulator_id_transfer_to_blind ) ); - acc.accumulated_fba_fees = 0; #ifdef GRAPHENE_FBA_STEALTH_DESIGNATED_ASSET acc.designated_asset = GRAPHENE_FBA_STEALTH_DESIGNATED_ASSET; #endif }); - create([&]( fba_accumulator_object& acc ) + create([]( fba_accumulator_object& acc ) { FC_ASSERT( acc.id == fba_accumulator_id_type( fba_accumulator_id_blind_transfer ) ); - acc.accumulated_fba_fees = 0; #ifdef GRAPHENE_FBA_STEALTH_DESIGNATED_ASSET acc.designated_asset = GRAPHENE_FBA_STEALTH_DESIGNATED_ASSET; #endif }); - create([&]( fba_accumulator_object& acc ) + create([]( fba_accumulator_object& acc ) { FC_ASSERT( acc.id == fba_accumulator_id_type( fba_accumulator_id_transfer_from_blind ) ); - acc.accumulated_fba_fees = 0; #ifdef GRAPHENE_FBA_STEALTH_DESIGNATED_ASSET acc.designated_asset = GRAPHENE_FBA_STEALTH_DESIGNATED_ASSET; #endif diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index fdf756f184..7efbc064ca 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -587,7 +587,7 @@ void update_top_n_authorities( database& db ) assert( bal.asset_type == tha.asset ); if( bal.owner == acct.id ) continue; - vc.add( bal.owner, bal.balance.value ); + vc.add( bal.owner, bal.get_amount().value ); --num_needed; if( num_needed == 0 ) break; @@ -613,73 +613,67 @@ void split_fba_balance( { FC_ASSERT( uint32_t(network_pct) + uint32_t(designated_asset_buyback_pct) + uint32_t(designated_asset_issuer_pct) == GRAPHENE_100_PERCENT ); const fba_accumulator_object& fba = fba_accumulator_id_type( fba_id )(db); - if( fba.accumulated_fba_fees == 0 ) + if( fba.accumulated_fba_fees.get_amount() == 0 ) return; const asset_dynamic_data_object& core_dd = db.get_core_dynamic_data(); + stored_value fees_to_distribute; + db.modify( fba, [&fees_to_distribute]( fba_accumulator_object& _fba ) + { + fees_to_distribute = std::move(_fba.accumulated_fba_fees); + } ); + if( !fba.is_configured(db) ) { - ilog( "${n} core given to network at block ${b} due to non-configured FBA", ("n", fba.accumulated_fba_fees)("b", db.head_block_time()) ); - db.modify( core_dd, [&]( asset_dynamic_data_object& _core_dd ) - { - _core_dd.current_supply -= fba.accumulated_fba_fees; - } ); - db.modify( fba, [&]( fba_accumulator_object& _fba ) - { - _fba.accumulated_fba_fees = 0; - } ); - return; + ilog( "${n} core given to network at block ${b} due to non-configured FBA", + ("n", fees_to_distribute.get_amount())("b", db.head_block_time()) ); } - - fc::uint128_t buyback_amount_128 = fba.accumulated_fba_fees.value; - buyback_amount_128 *= designated_asset_buyback_pct; - buyback_amount_128 /= GRAPHENE_100_PERCENT; - share_type buyback_amount = static_cast(buyback_amount_128); - - fc::uint128_t issuer_amount_128 = fba.accumulated_fba_fees.value; - issuer_amount_128 *= designated_asset_issuer_pct; - issuer_amount_128 /= GRAPHENE_100_PERCENT; - share_type issuer_amount = static_cast(issuer_amount_128); - - // this assert should never fail - FC_ASSERT( buyback_amount + issuer_amount <= fba.accumulated_fba_fees ); - - share_type network_amount = fba.accumulated_fba_fees - (buyback_amount + issuer_amount); - - const asset_object& designated_asset = (*fba.designated_asset)(db); - - if( network_amount != 0 ) + else { - db.modify( core_dd, [&]( asset_dynamic_data_object& _core_dd ) + fc::uint128_t buyback_amount_128 = fees_to_distribute.get_amount().value; + buyback_amount_128 *= designated_asset_buyback_pct; + buyback_amount_128 /= GRAPHENE_100_PERCENT; + share_type buyback_amount = static_cast(buyback_amount_128); + + fc::uint128_t issuer_amount_128 = fees_to_distribute.get_amount().value; + issuer_amount_128 *= designated_asset_issuer_pct; + issuer_amount_128 /= GRAPHENE_100_PERCENT; + share_type issuer_amount = static_cast(issuer_amount_128); + + // this assert should never fail + FC_ASSERT( buyback_amount + issuer_amount <= fees_to_distribute.get_amount() ); + + const asset_object& designated_asset = (*fba.designated_asset)(db); + + fba_distribute_operation vop; + vop.account_id = *designated_asset.buyback_account; + vop.fba_id = fba.id; + vop.amount = buyback_amount; + if( vop.amount != 0 ) { - _core_dd.current_supply -= network_amount; - } ); - } + db.add_balance( *designated_asset.buyback_account, fees_to_distribute.split(buyback_amount) ); + db.push_applied_operation(vop); + } - fba_distribute_operation vop; - vop.account_id = *designated_asset.buyback_account; - vop.fba_id = fba.id; - vop.amount = buyback_amount; - if( vop.amount != 0 ) - { - db.adjust_balance( *designated_asset.buyback_account, asset(buyback_amount) ); - db.push_applied_operation(vop); + vop.account_id = designated_asset.issuer; + vop.fba_id = fba.id; + vop.amount = issuer_amount; + if( vop.amount != 0 ) + { + db.add_balance( designated_asset.issuer, fees_to_distribute.split(issuer_amount) ); + db.push_applied_operation(vop); + } } - vop.account_id = designated_asset.issuer; - vop.fba_id = fba.id; - vop.amount = issuer_amount; - if( vop.amount != 0 ) + if( fees_to_distribute.get_amount() != 0 ) { - db.adjust_balance( designated_asset.issuer, asset(issuer_amount) ); - db.push_applied_operation(vop); + db.modify( core_dd, [&fees_to_distribute]( asset_dynamic_data_object& _core_dd ) + { + _core_dd.current_supply -= fees_to_distribute.get_amount(); + } ); + fees_to_distribute.burn(); } - - db.modify( fba, [&]( fba_accumulator_object& _fba ) - { - _fba.accumulated_fba_fees = 0; - } ); } void distribute_fba_balances( database& db ) diff --git a/libraries/chain/fba_object.cpp b/libraries/chain/fba_object.cpp index 0ea3ab8318..52c90345bb 100644 --- a/libraries/chain/fba_object.cpp +++ b/libraries/chain/fba_object.cpp @@ -28,7 +28,7 @@ namespace graphene { namespace chain { -bool fba_accumulator_object::is_configured( const database& db )const +bool fba_accumulator_master::is_configured( const database& db )const { if( !designated_asset.valid() ) { @@ -100,4 +100,35 @@ bool fba_accumulator_object::is_configured( const database& db )const return true; } +class fba_accumulator_backup : public fba_accumulator_master +{ + private: + fba_accumulator_backup( const fba_accumulator_object& original ) + : fba_accumulator_master( original ) + { + accumulated_fba_fees = original.accumulated_fba_fees.get_amount(); + } + share_type accumulated_fba_fees; + friend class fba_accumulator_object; +}; + +unique_ptr fba_accumulator_object::backup()const +{ + return std::make_unique( *this ); +} + +void fba_accumulator_object::restore( object& obj ) +{ + const auto& backup = static_cast(obj); + accumulated_fba_fees.restore( asset( asset_id_type(), backup.accumulated_fba_fees ) ); + static_cast(*this) = std::move( backup ); +} + } } + +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::fba_accumulator_master, (graphene::db::object), + (designated_asset) ) +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::fba_accumulator_object, (graphene::chain::fba_accumulator_master), + (accumulated_fba_fees) ) + +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::fba_accumulator_object ) diff --git a/libraries/chain/include/graphene/chain/account_object.hpp b/libraries/chain/include/graphene/chain/account_object.hpp index 3e3e767e6f..87bb145f44 100644 --- a/libraries/chain/include/graphene/chain/account_object.hpp +++ b/libraries/chain/include/graphene/chain/account_object.hpp @@ -24,6 +24,7 @@ #pragma once #include +#include #include #include @@ -43,7 +44,7 @@ namespace graphene { namespace chain { * separating the account data that changes frequently from the account data that is mostly static, which will * minimize the amount of data that must be backed up as part of the undo history everytime a transfer is made. */ - class account_statistics_object : public graphene::db::abstract_object + class account_statistics_master : public graphene::db::abstract_object { public: static constexpr uint8_t space_id = implementation_ids; @@ -87,7 +88,11 @@ namespace graphene { namespace chain { * Tracks the total fees paid by this account for the purpose of calculating bulk discounts. */ share_type lifetime_fees_paid; + }; + class account_statistics_object : public account_statistics_master + { + public: /** * Tracks the fees paid by this account which have not been disseminated to the various parties that receive * them yet (registrar, referrer, lifetime referrer, network, etc). This is used as an optimization to avoid @@ -96,15 +101,17 @@ namespace graphene { namespace chain { * These fees will be paid out as vesting cash-back, and this counter will reset during the maintenance * interval. */ - share_type pending_fees; + stored_value pending_fees; /** * Same as @ref pending_fees, except these fees will be paid out as pre-vested cash-back (immediately * available for withdrawal) rather than requiring the normal vesting period. */ - share_type pending_vested_fees; + stored_value pending_vested_fees; /// Whether this account has pending fees, no matter vested or not - inline bool has_pending_fees() const { return pending_fees > 0 || pending_vested_fees > 0; } + inline bool has_pending_fees() const { + return pending_fees.get_amount() > 0 || pending_vested_fees.get_amount() > 0; + } /// Whether need to process this account during the maintenance interval inline bool need_maintenance() const { return has_some_core_voting() || has_pending_fees(); } @@ -115,7 +122,11 @@ namespace graphene { namespace chain { /** * Core fees are paid into the account_statistics_object by this method */ - void pay_fee( share_type core_fee, share_type cashback_vesting_threshold ); + void pay_fee( stored_value&& core_fee, share_type cashback_vesting_threshold ); + + protected: + virtual unique_ptr backup()const; + virtual void restore( graphene::db::object& obj ); }; /** @@ -125,21 +136,31 @@ namespace graphene { namespace chain { * This object is indexed on owner and asset_type so that black swan * events in asset_type can be processed quickly. */ - class account_balance_object : public abstract_object + class account_balance_master : public abstract_object { public: static constexpr uint8_t space_id = implementation_ids; static constexpr uint8_t type_id = impl_account_balance_object_type; account_id_type owner; - asset_id_type asset_type; - share_type balance; bool maintenance_flag = false; ///< Whether need to process this balance object in maintenance interval - - asset get_balance()const { return asset(balance, asset_type); } - void adjust_balance(const asset& delta); }; + class account_balance_object : public account_balance_master + { + public: + stored_value balance; + + asset get_balance()const { return balance.get_value(); } + asset_id_type get_asset()const { return balance.get_asset(); } + share_type get_amount()const { return balance.get_amount(); } + void add_balance( stored_value&& delta ); + stored_value reduce_balance( share_type delta ); + + protected: + virtual unique_ptr backup()const; + virtual void restore( graphene::db::object& obj ); + }; /** * @brief This class represents an account on the object graph @@ -358,13 +379,13 @@ namespace graphene { namespace chain { indexed_by< ordered_unique< tag, member< object, object_id_type, &object::id > >, ordered_non_unique< tag, - member< account_balance_object, bool, &account_balance_object::maintenance_flag > >, + member< account_balance_master, bool, &account_balance_master::maintenance_flag > >, ordered_unique< tag, composite_key< account_balance_object, - member, - member, - member + const_mem_fun, + const_mem_fun, + member >, composite_key_compare< std::less< asset_id_type >, @@ -409,12 +430,12 @@ namespace graphene { namespace chain { indexed_by< ordered_unique< tag, member< object, object_id_type, &object::id > >, ordered_unique< tag, - member< account_statistics_object, account_id_type, &account_statistics_object::owner > >, + member< account_statistics_master, account_id_type, &account_statistics_master::owner > >, ordered_unique< tag, composite_key< account_statistics_object, const_mem_fun, - member + member > > > @@ -436,5 +457,7 @@ FC_REFLECT_TYPENAME( graphene::chain::account_balance_object ) FC_REFLECT_TYPENAME( graphene::chain::account_statistics_object ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::account_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::account_balance_master ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::account_balance_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::account_statistics_master ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::account_statistics_object ) diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index a5444396d2..433fe6cc85 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -45,7 +45,6 @@ namespace graphene { namespace chain { using graphene::db::abstract_object; - using graphene::db::object; class op_evaluator; class transaction_evaluation_state; class proposal_object; @@ -57,6 +56,7 @@ namespace graphene { namespace chain { class limit_order_object; class collateral_bid_object; class call_order_object; + class stored_value; struct budget_record; enum class vesting_balance_type; @@ -312,7 +312,8 @@ namespace graphene { namespace chain { * @param account ID of account whose balance should be adjusted * @param delta Asset ID and amount to adjust balance by */ - void adjust_balance(account_id_type account, asset delta); + void add_balance( account_id_type account, stored_value&& what ); + stored_value reduce_balance( account_id_type account, const asset& delta ); void deposit_market_fee_vesting_balance(const account_id_type &account_id, const asset &delta); /** diff --git a/libraries/chain/include/graphene/chain/fba_object.hpp b/libraries/chain/include/graphene/chain/fba_object.hpp index 3b5b2f7eb1..8961e9425a 100644 --- a/libraries/chain/include/graphene/chain/fba_object.hpp +++ b/libraries/chain/include/graphene/chain/fba_object.hpp @@ -34,22 +34,35 @@ class database; * fba_accumulator_object accumulates fees to be paid out via buyback or other FBA mechanism. */ -class fba_accumulator_object : public graphene::db::abstract_object< fba_accumulator_object > +class fba_accumulator_master : public graphene::db::abstract_object< fba_accumulator_master > { public: static constexpr uint8_t space_id = implementation_ids; static constexpr uint8_t type_id = impl_fba_accumulator_object_type; - share_type accumulated_fba_fees; optional< asset_id_type > designated_asset; bool is_configured( const database& db )const; }; +class fba_accumulator_object : public fba_accumulator_master +{ + public: + static const uint8_t space_id = implementation_ids; + static const uint8_t type_id = impl_fba_accumulator_object_type; + + stored_value accumulated_fba_fees; + + protected: + virtual unique_ptr backup()const; + virtual void restore( graphene::db::object& obj ); +}; + } } // graphene::chain MAP_OBJECT_ID_TO_TYPE(graphene::chain::fba_accumulator_object) FC_REFLECT_TYPENAME( graphene::chain::fba_accumulator_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::fba_accumulator_master ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::fba_accumulator_object ) diff --git a/libraries/chain/include/graphene/chain/stored_value.hpp b/libraries/chain/include/graphene/chain/stored_value.hpp index 661ec25038..2eceff7ad9 100644 --- a/libraries/chain/include/graphene/chain/stored_value.hpp +++ b/libraries/chain/include/graphene/chain/stored_value.hpp @@ -48,6 +48,59 @@ namespace graphene { namespace chain { const graphene::protocol::share_type amount ); void burn(); graphene::protocol::asset get_value()const; + graphene::protocol::asset_id_type get_asset()const { return _asset; } + graphene::protocol::share_type get_amount()const { return _amount; } + protected: + void restore( const graphene::protocol::asset& backup ); + friend class object; }; } } // graphene::chain +namespace fc { +/* should be unused +template<> +void from_variant( const fc::variant& var, graphene::chain::stored_value& value, uint32_t max_depth ) +{ +} +*/ + +template<> +void to_variant( const graphene::chain::stored_value& value, fc::variant& var, uint32_t max_depth ) +{ + to_variant( value.get_value(), var, max_depth ); +} + +namespace raw { + +template< typename Stream > +void pack( Stream& stream, const graphene::chain::stored_value& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) +{ + FC_ASSERT( _max_depth > 0 ); + --_max_depth; + pack( stream, value.get_value(), _max_depth ); +} + + +template< typename Stream > +void unpack( Stream& s, graphene::chain::stored_value& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) +{ + FC_ASSERT( _max_depth > 0 ); + --_max_depth; + graphene::protocol::asset amount; + unpack( s, amount, _max_depth ); + value = graphene::chain::stored_value::issue( amount.asset_id, amount.amount ); +} + +} // fc::raw + +template<> +struct get_typename< graphene::chain::stored_value > +{ + static const char* name() + { + return "graphene::chain::stored_value"; + } +}; + + +} // fc diff --git a/libraries/chain/small_objects.cpp b/libraries/chain/small_objects.cpp index ed68a4eaef..f0c70152d6 100644 --- a/libraries/chain/small_objects.cpp +++ b/libraries/chain/small_objects.cpp @@ -91,9 +91,6 @@ FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::committee_member_object, (graph FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::blinded_balance_object, (graphene::db::object), (commitment)(asset_id)(owner) ) -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::fba_accumulator_object, (graphene::db::object), - (accumulated_fba_fees)(designated_asset) ) - FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::dynamic_global_property_object, (graphene::db::object), (head_block_number) (head_block_id) @@ -198,7 +195,6 @@ GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::immutable_chain_para GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::chain_property_object ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::committee_member_object ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::blinded_balance_object ) -GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::fba_accumulator_object ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::dynamic_global_property_object ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::global_property_object ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::htlc_object ) diff --git a/libraries/db/include/graphene/db/index.hpp b/libraries/db/include/graphene/db/index.hpp index b54e7266c7..bdcc67b509 100644 --- a/libraries/db/include/graphene/db/index.hpp +++ b/libraries/db/include/graphene/db/index.hpp @@ -120,13 +120,14 @@ namespace graphene { namespace db { /** * When forming your lambda to modify obj, it is natural to have Object& be the signature, but - * that is not compatible with the type erasue required by the virtual method. This method + * that is not compatible with the type erasure required by the virtual method. This method * provides a helper to wrap the lambda in a form compatible with the virtual modify call. * @note Lambda should have the signature: void(Object&) */ template - void modify( const Object& obj, const Lambda& l ) { - modify( static_cast(obj), std::function( [&]( object& o ){ l( static_cast(o) ); } ) ); + void modify( const Object& obj, Lambda&& l ) { + modify( static_cast(obj), + std::function( [&l]( object& o ){ l( static_cast(o) ); } ) ); } virtual void inspect_all_objects(std::function inspector)const = 0; diff --git a/libraries/db/include/graphene/db/object_database.hpp b/libraries/db/include/graphene/db/object_database.hpp index c7825572fb..9718b70716 100644 --- a/libraries/db/include/graphene/db/object_database.hpp +++ b/libraries/db/include/graphene/db/object_database.hpp @@ -87,7 +87,7 @@ namespace graphene { namespace db { const object& insert( object&& obj ) { return get_mutable_index(obj.id).insert( std::move(obj) ); } void remove( const object& obj ) { get_mutable_index(obj.id).remove( obj ); } template - void modify( const T& obj, const Lambda& m ) { + void modify( const T& obj, Lambda&& m ) { get_mutable_index(obj.id).modify(obj,m); } From b03ccccf7b9b6924a50f79fb7cb88aaeccae6b87 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 29 Nov 2019 16:57:17 +0100 Subject: [PATCH 04/59] Intermediate --- libraries/chain/db_debug.cpp | 2 +- libraries/chain/db_maint.cpp | 15 +++-- libraries/chain/db_market.cpp | 43 +++++++----- .../include/graphene/chain/market_object.hpp | 54 ++++++++++----- libraries/chain/market_object.cpp | 66 +++++++++++++++++-- 5 files changed, 134 insertions(+), 46 deletions(-) diff --git a/libraries/chain/db_debug.cpp b/libraries/chain/db_debug.cpp index 0030edb71d..8cc1713be1 100644 --- a/libraries/chain/db_debug.cpp +++ b/libraries/chain/db_debug.cpp @@ -68,7 +68,7 @@ void database::debug_dump() reported_core_in_orders += s.total_core_in_orders; } for( const collateral_bid_object& b : bids ) - total_balances[b.inv_swan_price.base.asset_id] += b.inv_swan_price.base.amount; + total_balances[b.collateral_offered.get_asset()] += b.collateral_offered.get_amount(); for( const limit_order_object& o : db.get_index_type().indices() ) { auto for_sale = o.amount_for_sale(); diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 7efbc064ca..1a819004c4 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -83,7 +83,7 @@ void database::perform_account_maintenance(Type tally_helper) const account_balance_object& bal_obj = *bal_itr; modify( get_account_stats_by_owner( bal_obj.owner ), [&bal_obj](account_statistics_object& aso) { - aso.core_in_balance = bal_obj.balance; + aso.core_in_balance = bal_obj.get_amount(); }); modify( bal_obj, []( account_balance_object& abo ) { @@ -704,8 +704,8 @@ void create_buyback_orders( database& db ) for( const auto& entry : bal_idx.get_account_balances( buyback_account.id ) ) { const auto* it = entry.second; - asset_id_type asset_to_sell = it->asset_type; - share_type amount_to_sell = it->balance; + asset_id_type asset_to_sell = it->get_asset(); + share_type amount_to_sell = it->get_amount(); if( asset_to_sell == asset_to_buy.id ) continue; if( amount_to_sell == 0 ) @@ -801,12 +801,13 @@ void database::process_bids( const asset_bitasset_data_object& bad ) while( covered < bdd.current_supply && itr != bid_idx.end() && itr->inv_swan_price.quote.asset_id == to_revive_id ) { const collateral_bid_object& bid = *itr; - asset debt_in_bid = bid.inv_swan_price.quote; + asset debt_in_bid = bid.debt_covered; if( debt_in_bid.amount > bdd.current_supply ) debt_in_bid.amount = bdd.current_supply; asset total_collateral = debt_in_bid * bad.settlement_price; - total_collateral += bid.inv_swan_price.base; - price call_price = price::call_price( debt_in_bid, total_collateral, bad.current_feed.maintenance_collateral_ratio ); + total_collateral += bid.collateral_offered.get_value(); + price call_price = price::call_price( debt_in_bid, total_collateral, + bad.current_feed.maintenance_collateral_ratio ); if( ~call_price >= bad.current_feed.settlement_price ) break; covered += debt_in_bid.amount; ++itr; @@ -820,7 +821,7 @@ void database::process_bids( const asset_bitasset_data_object& bad ) { const collateral_bid_object& bid = *itr; ++itr; - asset debt_in_bid = bid.inv_swan_price.quote; + asset debt_in_bid = bid.debt_covered; if( debt_in_bid.amount > bdd.current_supply ) debt_in_bid.amount = bdd.current_supply; share_type debt = debt_in_bid.amount; diff --git a/libraries/chain/db_market.cpp b/libraries/chain/db_market.cpp index 2a028dbe33..8c495f19c1 100644 --- a/libraries/chain/db_market.cpp +++ b/libraries/chain/db_market.cpp @@ -156,45 +156,54 @@ void database::_cancel_bids_and_revive_mpa( const asset_object& bitasset, const void database::cancel_bid(const collateral_bid_object& bid, bool create_virtual_op) { - adjust_balance(bid.bidder, bid.inv_swan_price.base); - + stored_value collateral; + modify( bid, [&collateral] ( collateral_bid_object& _bid ) { + collateral = std::move(_bid.collateral_offered); + }); if( create_virtual_op ) { bid_collateral_operation vop; vop.bidder = bid.bidder; - vop.additional_collateral = bid.inv_swan_price.base; - vop.debt_covered = asset( 0, bid.inv_swan_price.quote.asset_id ); + vop.additional_collateral = collateral.get_value(); + vop.debt_covered = asset( 0, bid.debt_covered.asset_id() ); push_applied_operation( vop ); } + add_balance( bid.bidder, std::move(collateral) ); remove(bid); } -void database::execute_bid( const collateral_bid_object& bid, share_type debt_covered, share_type collateral_from_fund, - const price_feed& current_feed ) +void database::execute_bid( const collateral_bid_object& bid, share_type debt_covered, + stored_value&& collateral_from_fund, const price_feed& current_feed ) { - const call_order_object& call_obj = create( [&](call_order_object& call ){ + stored_value collateral; + modify( bid, [&collateral] ( collateral_bid_object& _bid ) { + collateral = std::move(_bid.collateral_offered); + }); + const auto& call_obj = create( + [&bid,&collateral,debt_covered,¤t_feed] ( call_order_object& call ) { call.borrower = bid.bidder; - call.collateral = bid.inv_swan_price.base.amount + collateral_from_fund; + call.collateral = std::move(collateral); + call.collateral += std::move(collateral_from_fund); call.debt = debt_covered; // don't calculate call_price after core-1270 hard fork if( get_dynamic_global_properties().next_maintenance_time > HARDFORK_CORE_1270_TIME ) // bid.inv_swan_price is in collateral / debt - call.call_price = price( asset( 1, bid.inv_swan_price.base.asset_id ), - asset( 1, bid.inv_swan_price.quote.asset_id ) ); + call.call_price = price( asset( 1, bid.collateral_offered.get_asset() ), + asset( 1, bid.debt_covered.asset_id ) ); else - call.call_price = price::call_price( asset(debt_covered, bid.inv_swan_price.quote.asset_id), - asset(call.collateral, bid.inv_swan_price.base.asset_id), + call.call_price = price::call_price( asset( debt_covered, bid.debt_covered.asset_id), + call.collateral.get_value(), current_feed.maintenance_collateral_ratio ); }); // Note: CORE asset in collateral_bid_object is not counted in account_stats.total_core_in_orders - if( bid.inv_swan_price.base.asset_id == asset_id_type() ) - modify( get_account_stats_by_owner(bid.bidder), [&](account_statistics_object& stats) { - stats.total_core_in_orders += call_obj.collateral; + if( collateral.get_asset() == asset_id_type() ) + modify( get_account_stats_by_owner(bid.bidder), [&call_obj] ( account_statistics_object& stats ) { + stats.total_core_in_orders += call_obj.collateral.get_amount(); }); - push_applied_operation( execute_bid_operation( bid.bidder, asset( call_obj.collateral, bid.inv_swan_price.base.asset_id ), - asset( debt_covered, bid.inv_swan_price.quote.asset_id ) ) ); + push_applied_operation( execute_bid_operation( bid.bidder, call_obj.collateral.get_value(), + asset( debt_covered, bid.debt_covered.asset_id ) ) ); remove(bid); } diff --git a/libraries/chain/include/graphene/chain/market_object.hpp b/libraries/chain/include/graphene/chain/market_object.hpp index b68f05b5ad..0fa44ba1f5 100644 --- a/libraries/chain/include/graphene/chain/market_object.hpp +++ b/libraries/chain/include/graphene/chain/market_object.hpp @@ -107,21 +107,18 @@ typedef generic_index limit_or * 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 +class call_order_master : public abstract_object { public: static constexpr uint8_t space_id = protocol_ids; static constexpr 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; } asset_id_type collateral_type()const { return call_price.base.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_debt price call_price; ///< Collateral / Debt @@ -133,6 +130,15 @@ class call_order_object : public abstract_object if( tmp.first > tmp.second ) std::swap( tmp.first, tmp.second ); return tmp; } +}; + +class call_order_object : public call_order_master +{ + public: + stored_value collateral; + + asset get_collateral()const { return collateral.get_value(); } + price collateralization()const { return get_collateral() / get_debt(); } /** * Calculate maximum quantity of debt to cover to satisfy @ref target_collateral_ratio. @@ -148,6 +154,10 @@ class call_order_object : public abstract_object price feed_price, const uint16_t maintenance_collateral_ratio, const optional& maintenance_collateralization = optional() )const; + + protected: + virtual unique_ptr backup()const; + virtual void restore( graphene::db::object& obj ); }; /** @@ -177,18 +187,28 @@ class force_settlement_object : public abstract_object * There should only be one collateral_bid_object per asset per account, and * only for smartcoin assets that have a global settlement_price. */ -class collateral_bid_object : public abstract_object +class collateral_bid_master : public abstract_object { public: static constexpr uint8_t space_id = implementation_ids; static constexpr uint8_t type_id = impl_collateral_bid_object_type; - asset get_additional_collateral()const { return inv_swan_price.base; } - asset get_debt_covered()const { return inv_swan_price.quote; } - asset_id_type debt_type()const { return inv_swan_price.quote.asset_id; } + asset_id_type debt_type()const { return debt_covered.asset_id; } account_id_type bidder; - price inv_swan_price; // Collateral / Debt + asset debt_covered; +}; + +class collateral_bid_object : public collateral_bid_master +{ + public: + price get_inv_swan_price()const { return collateral_offered.get_value() / debt_covered; } + + stored_value collateral_offered; // Collateral / Debt + + protected: + virtual unique_ptr backup()const; + virtual void restore( graphene::db::object& obj ); }; struct by_collateral; @@ -201,15 +221,15 @@ typedef multi_index_container< member< object, object_id_type, &object::id > >, ordered_unique< tag, composite_key< call_order_object, - member< call_order_object, price, &call_order_object::call_price>, + member< call_order_master, price, &call_order_master::call_price>, member< object, object_id_type, &object::id> >, composite_key_compare< std::less, std::less > >, ordered_unique< tag, 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> + member< call_order_master, account_id_type, &call_order_master::borrower >, + const_mem_fun< call_order_master, asset_id_type, &call_order_master::debt_type> > >, ordered_unique< tag, @@ -249,14 +269,14 @@ typedef multi_index_container< member< object, object_id_type, &object::id > >, ordered_unique< tag, composite_key< collateral_bid_object, - const_mem_fun< collateral_bid_object, asset_id_type, &collateral_bid_object::debt_type>, - member< collateral_bid_object, account_id_type, &collateral_bid_object::bidder> + const_mem_fun< collateral_bid_master, asset_id_type, &collateral_bid_master::debt_type>, + member< collateral_bid_master, account_id_type, &collateral_bid_master::bidder> > >, ordered_unique< tag, composite_key< collateral_bid_object, - const_mem_fun< collateral_bid_object, asset_id_type, &collateral_bid_object::debt_type>, - member< collateral_bid_object, price, &collateral_bid_object::inv_swan_price >, + const_mem_fun< collateral_bid_master, asset_id_type, &collateral_bid_master::debt_type>, + const_mem_fun< collateral_bid_object, price, &collateral_bid_object::get_inv_swan_price >, member< object, object_id_type, &object::id > >, composite_key_compare< std::less, std::greater, std::less > @@ -281,6 +301,8 @@ FC_REFLECT_TYPENAME( graphene::chain::force_settlement_object ) FC_REFLECT_TYPENAME( graphene::chain::collateral_bid_object ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::limit_order_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::call_order_master ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::call_order_object ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::force_settlement_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::collateral_bid_master ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::collateral_bid_object ) diff --git a/libraries/chain/market_object.cpp b/libraries/chain/market_object.cpp index 0cd19b63f5..4a35df4573 100644 --- a/libraries/chain/market_object.cpp +++ b/libraries/chain/market_object.cpp @@ -29,7 +29,7 @@ #include -using namespace graphene::chain; +namespace graphene { namespace chain { /* target_CR = max( target_CR, MCR ) @@ -303,23 +303,79 @@ share_type call_order_object::get_max_debt_to_cover( price match_price, } FC_CAPTURE_AND_RETHROW( (*this)(feed_price)(match_price)(maintenance_collateral_ratio) ) } +class call_order_backup : public call_order_master +{ + private: + call_order_backup( const call_order_object& original ) + : call_order_master( original ) + { + collateral = original.collateral.get_amount(); + } + asset collateral; + friend class call_order_object; +}; + +unique_ptr call_order_object::backup()const +{ + return std::make_unique( *this ); +} + +void call_order_object::restore( object& obj ) +{ + const auto& backup = static_cast(obj); + collateral.restore( backup.collateral ) ); + static_cast(*this) = std::move( backup ); +} + +class collateral_bid_backup : public collateral_bid_master +{ + private: + collateral_bid_backup( const collateral_bid_object& original ) + : collateral_bid_master( original ) + { + collateral_covered = original.collateral_covered.get_amount(); + } + asset collateral_covered; + friend class collateral_bid_object; +}; + +unique_ptr collateral_bid_object::backup()const +{ + return std::make_unique( *this ); +} + +void collateral_bid_object::restore( object& obj ) +{ + const auto& backup = static_cast(obj); + collateral_offered.restore( backup.collateral_offered ) ); + static_cast(*this) = std::move( backup ); +} + +} } // graphene::chain + FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::limit_order_object, (graphene::db::object), (expiration)(seller)(for_sale)(sell_price)(deferred_fee)(deferred_paid_fee) ) -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::call_order_object, (graphene::db::object), - (borrower)(collateral)(debt)(call_price)(target_collateral_ratio) ) +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::call_order_master, (graphene::db::object), + (borrower)(debt)(call_price)(target_collateral_ratio) ) +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::call_order_object, (graphene::chain::call_order_object), + (collateral) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::force_settlement_object, (graphene::db::object), (owner)(balance)(settlement_date) ) -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::collateral_bid_object, (graphene::db::object), - (bidder)(inv_swan_price) ) +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::collateral_bid_master, (graphene::db::object), + (bidder)(debt_covered) ) +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::collateral_bid_object, + (graphene::chain::collateral_bid_master), + (collateral_offered) ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::limit_order_object ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::call_order_object ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::force_settlement_object ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::collateral_bid_master ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::collateral_bid_object ) From a6e75fac6983e71970988fc761cb3c2981d31deb Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 30 Nov 2019 12:36:19 +0100 Subject: [PATCH 05/59] Intermediate --- libraries/chain/asset_object.cpp | 71 ++++++++- libraries/chain/db_balance.cpp | 59 +++---- libraries/chain/db_debug.cpp | 10 +- libraries/chain/db_init.cpp | 50 +++--- libraries/chain/db_maint.cpp | 145 +++++++++--------- libraries/chain/db_market.cpp | 10 +- .../include/graphene/chain/asset_object.hpp | 49 ++++-- .../chain/include/graphene/chain/database.hpp | 13 +- .../graphene/chain/global_property_object.hpp | 15 +- .../include/graphene/chain/stored_value.hpp | 87 ++++++++--- .../graphene/chain/vesting_balance_object.hpp | 36 +++-- .../include/graphene/chain/worker_object.hpp | 7 +- libraries/chain/small_objects.cpp | 35 ++++- libraries/chain/stored_value.cpp | 53 +++++-- libraries/chain/vesting_balance_object.cpp | 30 +++- libraries/chain/worker_evaluator.cpp | 18 +-- 16 files changed, 458 insertions(+), 230 deletions(-) diff --git a/libraries/chain/asset_object.cpp b/libraries/chain/asset_object.cpp index 50e874f858..140a2afc61 100644 --- a/libraries/chain/asset_object.cpp +++ b/libraries/chain/asset_object.cpp @@ -28,9 +28,39 @@ #include #include -using namespace graphene::chain; +namespace graphene { namespace chain { -share_type asset_bitasset_data_object::max_force_settlement_volume(share_type current_supply) const +class asset_dynamic_data_backup : public asset_dynamic_data_master +{ + private: + asset_dynamic_data_backup( const asset_dynamic_data_object& original ) + : asset_dynamic_data_master( original ) + { + current_supply = original.current_supply.get_value(); + accumulated_fees = original.accumulated_fees.get_amount(); + fee_pool = original.fee_pool.get_amount(); + } + asset current_supply; + share_type accumulated_fees; + share_type fee_pool; + friend class asset_dynamic_data_object; +}; + +unique_ptr asset_dynamic_data_object::backup()const +{ + return std::make_unique( *this ); +} + +void asset_dynamic_data_object::restore( object& obj ) +{ + const auto& backup = static_cast(obj); + current_supply.restore( backup.current_supply ) ); + accumulated_fees.restore( asset( backup.accumulated_fees, backup.current_supply.asset_id ) ); + fee_pool.restore( asset( backup.fee_pool ) ); + static_cast(*this) = std::move( backup ); +} + +share_type asset_bitasset_data_master::max_force_settlement_volume(share_type current_supply) const { if( options.maximum_force_settlement_volume == 0 ) return 0; @@ -44,7 +74,7 @@ share_type asset_bitasset_data_object::max_force_settlement_volume(share_type cu return static_cast(volume); } -void graphene::chain::asset_bitasset_data_object::update_median_feeds( time_point_sec current_time, +void graphene::chain::asset_bitasset_data_master::update_median_feeds( time_point_sec current_time, time_point_sec next_maintenance_time ) { bool after_core_hardfork_1270 = ( next_maintenance_time > HARDFORK_CORE_1270_TIME ); // call price caching issue @@ -105,6 +135,32 @@ void graphene::chain::asset_bitasset_data_object::update_median_feeds( time_poin current_maintenance_collateralization = current_feed.maintenance_collateralization(); } +class asset_bitasset_data_backup : public asset_bitasset_data_master +{ + private: + asset_bitasset_data_backup( const asset_bitasset_data_object& original ) + : asset_bitasset_data_master( original ) + { + settlement_fund = original.settlement_fund.get_amount(); + total_debt = original.total_debt.get_amount(); + } + share_type settlement_fund; + share_type total_debt; + friend class asset_bitasset_data_object; +}; + +unique_ptr asset_bitasset_data_object::backup()const +{ + return std::make_unique( *this ); +} + +void asset_bitasset_data_object::restore( object& obj ) +{ + const auto& backup = static_cast(obj); + settlement_fund.restore( asset( backup.settlement_fund, backup.options.short_backing_asset ) ); + total_debt.restore( asset( backup.total_debt, backup.asset_id ) ); + static_cast(*this) = std::move( backup ); +} asset asset_object::amount_from_string(string amount_string) const @@ -177,8 +233,13 @@ string asset_object::amount_to_string(share_type amount) const return result; } -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::asset_dynamic_data_object, (graphene::db::object), - (current_supply)(confidential_supply)(accumulated_fees)(fee_pool) ) +} } // graphene::chain + +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::asset_dynamic_data_master, (graphene::db::object), + (confidential_supply)(accumulated_fees)(fee_pool) ) +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::asset_dynamic_data_object, + (graphene::chain::asset_dynamic_data_master), + (current_supply) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::asset_bitasset_data_object, (graphene::db::object), (asset_id) diff --git a/libraries/chain/db_balance.cpp b/libraries/chain/db_balance.cpp index 0078f89111..e3021a9cda 100644 --- a/libraries/chain/db_balance.cpp +++ b/libraries/chain/db_balance.cpp @@ -60,17 +60,17 @@ void database::add_balance(account_id_type account, stored_value&& what ) auto& index = get_index_type< primary_index< account_balance_index > >().get_secondary_index(); auto abo = index.get_account_balance( account, what.get_asset() ); if( !abo ) - create([account,delta = std::move(what)](account_balance_object& b) mutable { + create([account,&what](account_balance_object& b) { b.owner = account; - b.balance = std::move(delta); + b.balance = std::move(what); if( b.balance.get_asset() == asset_id_type() ) // CORE asset b.maintenance_flag = true; }); else - modify(*abo, [delta = std::move(what)] (account_balance_object& b) mutable { + modify(*abo, [&what] (account_balance_object& b) { if( b.balance.get_asset() == asset_id_type() ) // CORE asset b.maintenance_flag = true; - b.balance += std::move(delta); + b.balance += std::move(what); }); } FC_CAPTURE_AND_RETHROW( (account)(what) ) } @@ -117,7 +117,7 @@ namespace detail { bool operator()(const vbo_mfs_key& k, const vesting_balance_object& vbo)const { return ( vbo.balance_type == vesting_balance_type::market_fee_sharing ) && - ( k.asset_id == vbo.balance.asset_id ) && + ( k.asset_id == vbo.balance.get_asset() ) && ( k.account_id == vbo.owner ); } @@ -138,18 +138,18 @@ asset database::get_market_fee_vesting_balance(const account_id_type &account_id { return asset(0, asset_id); } - return vbo_it->balance; + return vbo_it->balance.get_value(); } -void database::deposit_market_fee_vesting_balance(const account_id_type &account_id, const asset &delta) +void database::deposit_market_fee_vesting_balance(const account_id_type &account_id, stored_value&& delta) { try { - FC_ASSERT( delta.amount >= 0, "Invalid negative value for balance"); + FC_ASSERT( delta.get_amount() >= 0, "Invalid negative value for balance"); - if( delta.amount == 0 ) + if( delta.get_amount() == 0 ) return; auto& vesting_balances = get_index_type().indices().get(); - const auto& key = detail::vbo_mfs_key{account_id, delta.asset_id}; + const auto& key = detail::vbo_mfs_key{account_id, delta.get_asset()}; auto vbo_it = vesting_balances.find(key, key, key); auto block_time = head_block_time(); @@ -158,26 +158,26 @@ void database::deposit_market_fee_vesting_balance(const account_id_type &account { create([&account_id, &delta](vesting_balance_object &vbo) { vbo.owner = account_id; - vbo.balance = delta; + vbo.balance = std::move(delta); vbo.balance_type = vesting_balance_type::market_fee_sharing; vbo.policy = instant_vesting_policy{}; }); } else { modify( *vbo_it, [&block_time, &delta]( vesting_balance_object& vbo ) { - vbo.deposit_vested(block_time, delta); + vbo.deposit_vested(block_time, std::move(delta)); }); } } FC_CAPTURE_AND_RETHROW( (account_id)(delta) ) } optional< vesting_balance_id_type > database::deposit_lazy_vesting( const optional< vesting_balance_id_type >& ovbid, - share_type amount, uint32_t req_vesting_seconds, + stored_value&& amount, uint32_t req_vesting_seconds, vesting_balance_type balance_type, account_id_type req_owner, bool require_vesting ) { - if( amount == 0 ) + if( amount.get_amount() == 0 ) return optional< vesting_balance_id_type >(); fc::time_point_sec now = head_block_time(); @@ -193,25 +193,26 @@ optional< vesting_balance_id_type > database::deposit_lazy_vesting( break; if( vbo.policy.get< cdd_vesting_policy >().vesting_seconds != req_vesting_seconds ) break; - modify( vbo, [&]( vesting_balance_object& _vbo ) + modify( vbo, [require_vesting,now,&amount]( vesting_balance_object& _vbo ) { if( require_vesting ) - _vbo.deposit(now, amount); + _vbo.deposit(now, std::move(amount) ); else - _vbo.deposit_vested(now, amount); + _vbo.deposit_vested(now, std::move(amount) ); } ); return optional< vesting_balance_id_type >(); } - const vesting_balance_object& vbo = create< vesting_balance_object >( [&]( vesting_balance_object& _vbo ) + const vesting_balance_object& vbo = create< vesting_balance_object >( + [req_owner,&amount,balance_type,req_vesting_seconds,now,require_vesting]( vesting_balance_object& _vbo ) { _vbo.owner = req_owner; - _vbo.balance = amount; + _vbo.balance = std::move(amount); _vbo.balance_type = balance_type; cdd_vesting_policy policy; policy.vesting_seconds = req_vesting_seconds; - policy.coin_seconds_earned = require_vesting ? 0 : amount.value * policy.vesting_seconds; + policy.coin_seconds_earned = require_vesting ? 0 : _vbo.balance.get_amount().value * policy.vesting_seconds; policy.coin_seconds_earned_last_update = now; _vbo.policy = policy; @@ -220,12 +221,12 @@ optional< vesting_balance_id_type > database::deposit_lazy_vesting( return vbo.id; } -void database::deposit_cashback(const account_object& acct, share_type amount, bool require_vesting) +void database::deposit_cashback(const account_object& acct, stored_value&& amount, bool require_vesting) { // If we don't have a VBO, or if it has the wrong maturity // due to a policy change, cut it loose. - if( amount == 0 ) + if( amount.get_amount() == 0 ) return; if( acct.get_id() == GRAPHENE_COMMITTEE_ACCOUNT || acct.get_id() == GRAPHENE_WITNESS_ACCOUNT || @@ -233,15 +234,15 @@ void database::deposit_cashback(const account_object& acct, share_type amount, b acct.get_id() == GRAPHENE_TEMP_ACCOUNT ) { // The blockchain's accounts do not get cashback; it simply goes to the reserve pool. - modify( get_core_dynamic_data(), [amount](asset_dynamic_data_object& d) { - d.current_supply -= amount; + modify( get_core_dynamic_data(), [&amount](asset_dynamic_data_object& d) { + d.current_supply.burn( std::move(amount) ); }); return; } optional< vesting_balance_id_type > new_vbid = deposit_lazy_vesting( acct.cashback_vb, - amount, + std::move(amount), get_global_properties().parameters.cashback_vesting_period_seconds, vesting_balance_type::cashback, acct.id, @@ -262,14 +263,14 @@ void database::deposit_cashback(const account_object& acct, share_type amount, b return; } -void database::deposit_witness_pay(const witness_object& wit, share_type amount) +void database::deposit_witness_pay(const witness_object& wit, stored_value&& amount) { - if( amount == 0 ) + if( amount.get_amount() == 0 ) return; optional< vesting_balance_id_type > new_vbid = deposit_lazy_vesting( wit.pay_vb, - amount, + std::move(amount), get_global_properties().parameters.witness_pay_vesting_seconds, vesting_balance_type::witness, wit.witness_account, @@ -277,7 +278,7 @@ void database::deposit_witness_pay(const witness_object& wit, share_type amount) if( new_vbid.valid() ) { - modify( wit, [&]( witness_object& _wit ) + modify( wit, [&new_vbid]( witness_object& _wit ) { _wit.pay_vb = *new_vbid; } ); diff --git a/libraries/chain/db_debug.cpp b/libraries/chain/db_debug.cpp index 8cc1713be1..f6e4e0b4ea 100644 --- a/libraries/chain/db_debug.cpp +++ b/libraries/chain/db_debug.cpp @@ -60,7 +60,7 @@ void database::debug_dump() total_balances[s.balance.asset_id] += s.balance.amount; } for( const vesting_balance_object& vbo : db.get_index_type< vesting_balance_index >().indices() ) - total_balances[ vbo.balance.asset_id ] += vbo.balance.amount; + total_balances[ vbo.balance.get_asset() ] += vbo.balance.get_amount(); for( const fba_accumulator_object& fba : db.get_index_type< simple_index< fba_accumulator_object > >() ) total_balances[ asset_id_type() ] += fba.accumulated_fba_fees.get_amount(); for( const account_statistics_object& s : statistics_index ) @@ -84,15 +84,15 @@ void database::debug_dump() } for( const asset_object& asset_obj : db.get_index_type().indices() ) { - total_balances[asset_obj.id] += asset_obj.dynamic_asset_data_id(db).accumulated_fees; - total_balances[asset_id_type()] += asset_obj.dynamic_asset_data_id(db).fee_pool; + total_balances[asset_obj.id] += asset_obj.dynamic_asset_data_id(db).accumulated_fees.get_amount(); + total_balances[asset_id_type()] += asset_obj.dynamic_asset_data_id(db).fee_pool.get_amount(); } - if( total_balances[asset_id_type()].value != core_asset_data.current_supply.value ) + if( total_balances[asset_id_type()].value != core_asset_data.current_supply.get_amount() ) { FC_THROW( "computed balance of CORE mismatch", ("computed value",total_balances[asset_id_type()].value) - ("current supply",core_asset_data.current_supply.value) ); + ("current supply",core_asset_data.current_supply.get_amount()) ); } } diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 9fe58a7187..3bd1931e4d 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -190,9 +190,6 @@ void database::init_genesis(const genesis_state_type& genesis_state) // Create blockchain accounts fc::ecc::private_key null_private_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key"))); - create([](account_balance_object& b) { - b.balance = stored_value::issue( asset_id_type(), GRAPHENE_MAX_SHARE_SUPPLY ); - }); const account_object& committee_account = create( [&](account_object& n) { n.membership_expiration_date = time_point_sec::maximum(); @@ -204,7 +201,7 @@ void database::init_genesis(const genesis_state_type& genesis_state) n.statistics = create( [&n](account_statistics_object& s){ s.owner = n.id; s.name = n.name; - s.core_in_balance = GRAPHENE_MAX_SHARE_SUPPLY; + s.core_in_balance = 0; }).id; }); FC_ASSERT(committee_account.get_id() == GRAPHENE_COMMITTEE_ACCOUNT); @@ -300,7 +297,7 @@ void database::init_genesis(const genesis_state_type& genesis_state) // Create core asset const asset_dynamic_data_object& dyn_asset = create([](asset_dynamic_data_object& a) { - a.current_supply = GRAPHENE_MAX_SHARE_SUPPLY; + a.current_supply = stored_debt( asset_id_type() ); }); const asset_object& core_asset = create( [&genesis_state,&dyn_asset]( asset_object& a ) { @@ -318,7 +315,7 @@ void database::init_genesis(const genesis_state_type& genesis_state) }); FC_ASSERT( dyn_asset.id == asset_dynamic_data_id_type() ); FC_ASSERT( asset_id_type(core_asset.id) == asset().asset_id ); - FC_ASSERT( get_balance(account_id_type(), asset_id_type()) == asset(dyn_asset.current_supply) ); + FC_ASSERT( get_balance(account_id_type(), asset_id_type()) == dyn_asset.current_supply.get_value() ); _p_core_asset_obj = &core_asset; _p_core_dynamic_data_obj = &dyn_asset; // Create more special assets @@ -328,8 +325,9 @@ void database::init_genesis(const genesis_state_type& genesis_state) if( id >= genesis_state.immutable_parameters.num_special_assets ) break; const asset_dynamic_data_object& dyn_asset = - create([](asset_dynamic_data_object& a) { - a.current_supply = 0; + create([id](asset_dynamic_data_object& a) { + a.current_supply = stored_debt( asset_id_type(id) ); + a.accumulated_fees = stored_value( asset_id_type(id) ); }); const asset_object& asset_obj = create( [id,&dyn_asset]( asset_object& a ) { a.symbol = "SPECIAL" + std::to_string( id ); @@ -361,7 +359,6 @@ void database::init_genesis(const genesis_state_type& genesis_state) _p_dyn_global_prop_obj = & create([&genesis_state](dynamic_global_property_object& p) { p.time = genesis_state.initial_timestamp; p.dynamic_flags = 0; - p.witness_budget = 0; p.recent_slots_filled = std::numeric_limits::max(); }); @@ -453,12 +450,17 @@ void database::init_genesis(const genesis_state_type& genesis_state) o.total_core_in_orders = collateral_rec.collateral; }); - create([&](call_order_object& c) { + stored_value collateral; + modify( dyn_asset, [&collateral,&collateral_rec] ( asset_dynamic_data_object& core ) { + collateral = core.current_supply.issue( collateral_rec.collateral ); + }); + + create([owner_account_id,&collateral_rec,&core_asset,new_asset_id,&collateral](call_order_object& c) { c.borrower = owner_account_id; - c.collateral = collateral_rec.collateral; + c.collateral = std::move( collateral ); c.debt = collateral_rec.debt; c.call_price = price::call_price(chain::asset(c.debt, new_asset_id), - chain::asset(c.collateral, core_asset.id), + c.collateral.get_value(), GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO); }); @@ -474,8 +476,9 @@ void database::init_genesis(const genesis_state_type& genesis_state) }).id; } - dynamic_data_id = create([&asset](asset_dynamic_data_object& d) { - d.accumulated_fees = asset.accumulated_fees; + dynamic_data_id = create([&asset,new_asset_id](asset_dynamic_data_object& d) { + d.current_supply = stored_debt( new_asset_id ); + d.accumulated_fees = d.current_supply.issue( asset.accumulated_fees ); }).id; total_supplies[ new_asset_id ] += asset.accumulated_fees; @@ -528,14 +531,7 @@ void database::init_genesis(const genesis_state_type& genesis_state) total_supplies[ asset_id ] += vest.amount; } - if( total_supplies[ asset_id_type(0) ] > 0 ) - { - reduce_balance( GRAPHENE_COMMITTEE_ACCOUNT, -get_balance(GRAPHENE_COMMITTEE_ACCOUNT,{}) ).burn(); - } - else - { - total_supplies[ asset_id_type(0) ] = GRAPHENE_MAX_SHARE_SUPPLY; - } + FC_ASSERT( get_balance(GRAPHENE_COMMITTEE_ACCOUNT,{}).amount == 0 ); const auto& idx = get_index_type().indices().get(); auto it = idx.begin(); @@ -565,17 +561,13 @@ void database::init_genesis(const genesis_state_type& genesis_state) } FC_ASSERT( !has_imbalanced_assets ); - // Save tallied supplies + // Verify tallied supplies for( const auto& item : total_supplies ) { const auto asset_id = item.first; const auto total_supply = item.second; - - modify( get( asset_id ), [ & ]( asset_object& asset ) { - modify( get( asset.dynamic_asset_data_id ), [ & ]( asset_dynamic_data_object& asset_data ) { - asset_data.current_supply = total_supply; - } ); - } ); + const auto actual_supply = asset_id(*this).dynamic_asset_data_id(*this).current_supply.get_value(); + FC_ASSERT( actual_supply == asset( total_supply, asset_id ) ); } // Create special witness account diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 1a819004c4..810d93af60 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -116,18 +116,18 @@ void database::perform_account_maintenance(Type tally_helper) struct worker_pay_visitor { private: - share_type pay; + stored_value pay; database& db; public: - worker_pay_visitor(share_type pay, database& db) - : pay(pay), db(db) {} + worker_pay_visitor(stored_value&& pay, database& db) + : pay(std::move(pay)), db(db) {} typedef void result_type; template - void operator()(W& worker)const + void operator()(W& worker) { - worker.pay_worker(pay, db); + worker.pay_worker(std::move(pay), db); } }; @@ -148,7 +148,7 @@ void database::update_worker_votes() } } -void database::pay_workers( share_type& budget ) +void database::pay_workers( stored_value&& budget ) { const auto head_time = head_block_time(); // ilog("Processing payroll! Available budget is ${b}", ("b", budget)); @@ -174,7 +174,7 @@ void database::pay_workers( share_type& budget ) const auto passed_time_ms = head_time - last_budget_time; const auto passed_time_count = passed_time_ms.count(); const auto day_count = fc::days(1).count(); - for( uint32_t i = 0; i < active_workers.size() && budget > 0; ++i ) + for( uint32_t i = 0; i < active_workers.size() && budget.get_amount() > 0; ++i ) { const worker_object& active_worker = active_workers[i]; share_type requested_pay = active_worker.daily_pay; @@ -187,13 +187,10 @@ void database::pay_workers( share_type& budget ) pay /= day_count; requested_pay = static_cast(pay); - share_type actual_pay = std::min(budget, requested_pay); - //ilog(" ==> Paying ${a} to worker ${w}", ("w", active_worker.id)("a", actual_pay)); - modify(active_worker, [&](worker_object& w) { - w.worker.visit(worker_pay_visitor(actual_pay, *this)); + worker_pay_visitor vtor( budget.split( std::min(budget.get_amount(), requested_pay) ), *this ); + modify(active_worker, [&vtor](worker_object& w) { + w.worker.visit( vtor ); }); - - budget -= actual_pay; } } @@ -407,8 +404,8 @@ void database::initialize_budget_record( fc::time_point_sec now, budget_record& const asset_dynamic_data_object& core_dd = get_core_dynamic_data(); rec.from_initial_reserve = core.reserved(*this); - rec.from_accumulated_fees = core_dd.accumulated_fees; - rec.from_unused_witness_budget = dpo.witness_budget; + rec.from_accumulated_fees = core_dd.accumulated_fees.get_amount(); + rec.from_unused_witness_budget = dpo.witness_budget.get_amount(); if( (dpo.last_budget_time == fc::time_point_sec()) || (now <= dpo.last_budget_time) ) @@ -426,10 +423,10 @@ void database::initialize_budget_record( fc::time_point_sec now, budget_record& // end of the maintenance interval. Thus the accumulated_fees // are available for the budget at this point, but not included // in core.reserved(). - share_type reserve = rec.from_initial_reserve + core_dd.accumulated_fees; + share_type reserve = rec.from_initial_reserve + rec.from_accumulated_fees; // Similarly, we consider leftover witness_budget to be burned // at the BEGINNING of the maintenance interval. - reserve += dpo.witness_budget; + reserve += dpo.witness_budget.get_amount(); fc::uint128_t budget_u128 = reserve.value; budget_u128 *= uint64_t(dt); @@ -479,30 +476,44 @@ void database::process_budget() budget_record rec; initialize_budget_record( now, rec ); - share_type available_funds = rec.total_budget; - share_type witness_budget = gpo.parameters.witness_pay_per_block.value * blocks_to_maint; - rec.requested_witness_budget = witness_budget; - witness_budget = std::min(witness_budget, available_funds); - rec.witness_budget = witness_budget; - available_funds -= witness_budget; + rec.requested_witness_budget = gpo.parameters.witness_pay_per_block.value * blocks_to_maint; + rec.witness_budget = std::min(rec.requested_witness_budget, rec.total_budget); + + stored_value available_funds; + modify( core, [&available_funds,&rec,&dpo]( asset_dynamic_data_object& _core ) + { + available_funds = std::move(_core.accumulated_fees); + share_type required = rec.total_budget + - available_funds.get_amount() + - rec.witness_budget + + dpo.witness_budget.get_amount(); + if( required > 0 ) + available_funds += _core.current_supply.issue( required ); + }); + + modify(dpo, [now,&available_funds,&rec]( dynamic_global_property_object& _dpo ) + { + _dpo.last_budget_time = now; + if( _dpo.witness_budget.get_amount() > rec.witness_budget ) + available_funds += _dpo.witness_budget.split( _dpo.witness_budget.get_amount() - rec.witness_budget ); + else + _dpo.witness_budget += available_funds.split( rec.witness_budget - _dpo.witness_budget.get_amount() ); + }); fc::uint128_t worker_budget_u128 = gpo.parameters.worker_budget_per_day.value; worker_budget_u128 *= uint64_t(time_to_maint); worker_budget_u128 /= 60*60*24; - share_type worker_budget; - if( worker_budget_u128 >= static_cast(available_funds.value) ) - worker_budget = available_funds; + if( worker_budget_u128 >= static_cast(available_funds.get_amount().value) ) + rec.worker_budget = available_funds.get_amount(); else - worker_budget = static_cast(worker_budget_u128); - rec.worker_budget = worker_budget; - available_funds -= worker_budget; + rec.worker_budget = static_cast(worker_budget_u128); - share_type leftover_worker_funds = worker_budget; - pay_workers(leftover_worker_funds); - rec.leftover_worker_funds = leftover_worker_funds; - available_funds += leftover_worker_funds; + stored_value worker_budget = available_funds.split( rec.worker_budget ); + pay_workers( std::move(worker_budget) ); + rec.leftover_worker_funds = worker_budget.get_amount(); + available_funds += std::move( worker_budget ); rec.supply_delta = rec.witness_budget + rec.worker_budget @@ -510,37 +521,19 @@ void database::process_budget() - rec.from_accumulated_fees - rec.from_unused_witness_budget; - modify(core, [&]( asset_dynamic_data_object& _core ) - { - _core.current_supply = (_core.current_supply + rec.supply_delta ); - - assert( rec.supply_delta == - witness_budget - + worker_budget - - leftover_worker_funds - - _core.accumulated_fees - - dpo.witness_budget - ); - _core.accumulated_fees = 0; - }); - - modify(dpo, [&]( dynamic_global_property_object& _dpo ) - { - // Since initial witness_budget was rolled into - // available_funds, we replace it with witness_budget - // instead of adding it. - _dpo.witness_budget = witness_budget; - _dpo.last_budget_time = now; - }); + if( available_funds.get_amount() > 0 ) + // available_funds is money we could spend, but don't want to. + // we simply let it evaporate back into the reserve. + modify(core, [&available_funds]( asset_dynamic_data_object& _core ) + { + _core.current_supply.burn( std::move(available_funds) ); + }); - create< budget_record_object >( [&]( budget_record_object& _rec ) + create< budget_record_object >( [now,&rec]( budget_record_object& _rec ) { - _rec.time = head_block_time(); + _rec.time = now; _rec.record = rec; }); - - // available_funds is money we could spend, but don't want to. - // we simply let it evaporate back into the reserve. } FC_CAPTURE_AND_RETHROW() } @@ -670,9 +663,8 @@ void split_fba_balance( { db.modify( core_dd, [&fees_to_distribute]( asset_dynamic_data_object& _core_dd ) { - _core_dd.current_supply -= fees_to_distribute.get_amount(); + _core_dd.current_supply.burn( std::move(fees_to_distribute) ); } ); - fees_to_distribute.burn(); } } @@ -798,12 +790,12 @@ void database::process_bids( const asset_bitasset_data_object& bad ) share_type covered = 0; auto itr = start; - while( covered < bdd.current_supply && itr != bid_idx.end() && itr->inv_swan_price.quote.asset_id == to_revive_id ) + while( covered < bdd.current_supply.get_amount() && itr != bid_idx.end() && itr->debt_type() == to_revive_id ) { const collateral_bid_object& bid = *itr; asset debt_in_bid = bid.debt_covered; - if( debt_in_bid.amount > bdd.current_supply ) - debt_in_bid.amount = bdd.current_supply; + if( debt_in_bid.amount > bdd.current_supply.get_amount() ) + debt_in_bid.amount = bdd.current_supply.get_amount(); asset total_collateral = debt_in_bid * bad.settlement_price; total_collateral += bid.collateral_offered.get_value(); price call_price = price::call_price( debt_in_bid, total_collateral, @@ -812,30 +804,31 @@ void database::process_bids( const asset_bitasset_data_object& bad ) covered += debt_in_bid.amount; ++itr; } - if( covered < bdd.current_supply ) return; + if( covered < bdd.current_supply.get_amount() ) return; const auto end = itr; - share_type to_cover = bdd.current_supply; - share_type remaining_fund = bad.settlement_fund; + share_type to_cover = bdd.current_supply.get_amount(); + stored_value remaining_fund; + modify( bad, [&remaining_fund] ( asset_bitasset_data_object& _bad ) { + remaining_fund = std::move(_bad.settlement_fund); + }); for( itr = start; itr != end; ) { const collateral_bid_object& bid = *itr; ++itr; asset debt_in_bid = bid.debt_covered; - if( debt_in_bid.amount > bdd.current_supply ) - debt_in_bid.amount = bdd.current_supply; + if( debt_in_bid.amount > bdd.current_supply.get_amount() ) + debt_in_bid.amount = bdd.current_supply.get_amount(); share_type debt = debt_in_bid.amount; share_type collateral = (debt_in_bid * bad.settlement_price).amount; if( debt >= to_cover ) { debt = to_cover; - collateral = remaining_fund; + collateral = remaining_fund.get_amount(); } to_cover -= debt; - remaining_fund -= collateral; - execute_bid( bid, debt, collateral, bad.current_feed ); + execute_bid( bid, debt, remaining_fund.split(collateral), bad.current_feed ); } - FC_ASSERT( remaining_fund == 0 ); FC_ASSERT( to_cover == 0 ); _cancel_bids_and_revive_mpa( to_revive, bad ); @@ -949,7 +942,7 @@ void process_hf_1465( database& db ) for( auto asset_itr = asset_idx.lower_bound(true); asset_itr != asset_idx.end(); ++asset_itr ) { const auto& current_asset = *asset_itr; - graphene::chain::share_type current_supply = current_asset.dynamic_data(db).current_supply; + graphene::chain::share_type current_supply = current_asset.dynamic_data(db).current_supply.get_amount(); graphene::chain::share_type max_supply = current_asset.options.max_supply; if (current_supply > max_supply && max_supply != GRAPHENE_MAX_SHARE_SUPPLY) { @@ -1089,7 +1082,7 @@ void database::perform_chain_maintenance(const signed_block& next_block, const g : d.get(stake_account.options.voting_account); uint64_t voting_stake = stats.total_core_in_orders.value - + (stake_account.cashback_vb.valid() ? (*stake_account.cashback_vb)(d).balance.amount.value: 0) + + (stake_account.cashback_vb.valid() ? (*stake_account.cashback_vb)(d).balance.get_amount().value: 0) + stats.core_in_balance.value; for( vote_id_type id : opinion_account.options.votes ) diff --git a/libraries/chain/db_market.cpp b/libraries/chain/db_market.cpp index 8c495f19c1..c37a643c18 100644 --- a/libraries/chain/db_market.cpp +++ b/libraries/chain/db_market.cpp @@ -119,8 +119,8 @@ void database::revive_bitasset( const asset_object& bitasset ) // Create + execute a "bid" with 0 additional collateral const collateral_bid_object& pseudo_bid = create([&](collateral_bid_object& bid) { bid.bidder = bitasset.issuer; - bid.inv_swan_price = asset(0, bad.options.short_backing_asset) - / asset(bdd.current_supply, bitasset.id); + bid.collateral_offered = stored_value( bad.options.short_backing_asset ); + bid.debt_covered = asset( bdd.current_supply, bitasset.id ); }); execute_bid( pseudo_bid, bdd.current_supply, bad.settlement_fund, bad.current_feed ); } else @@ -140,7 +140,7 @@ void database::_cancel_bids_and_revive_mpa( const asset_object& bitasset, const auto itr = bid_idx.lower_bound( boost::make_tuple( bitasset.id, price::max( bad.options.short_backing_asset, bitasset.id ), collateral_bid_id_type() ) ); - while( itr != bid_idx.end() && itr->inv_swan_price.quote.asset_id == bitasset.id ) + while( itr != bid_idx.end() && itr->debt_type() == bitasset.id ) { const collateral_bid_object& bid = *itr; ++itr; @@ -148,7 +148,7 @@ void database::_cancel_bids_and_revive_mpa( const asset_object& bitasset, const } // revive - modify( bad, [&]( asset_bitasset_data_object& obj ){ + modify( bad, []( asset_bitasset_data_object& obj ){ obj.settlement_price = price(); obj.settlement_fund = 0; }); @@ -165,7 +165,7 @@ void database::cancel_bid(const collateral_bid_object& bid, bool create_virtual_ bid_collateral_operation vop; vop.bidder = bid.bidder; vop.additional_collateral = collateral.get_value(); - vop.debt_covered = asset( 0, bid.debt_covered.asset_id() ); + vop.debt_covered = asset( 0, bid.debt_type() ); push_applied_operation( vop ); } add_balance( bid.bidder, std::move(collateral) ); diff --git a/libraries/chain/include/graphene/chain/asset_object.hpp b/libraries/chain/include/graphene/chain/asset_object.hpp index 8264c20e1b..d9fd2d7c08 100644 --- a/libraries/chain/include/graphene/chain/asset_object.hpp +++ b/libraries/chain/include/graphene/chain/asset_object.hpp @@ -23,6 +23,7 @@ */ #pragma once #include +#include #include #include @@ -55,17 +56,26 @@ namespace graphene { namespace chain { * This object exists as an implementation detail and its ID should never be referenced by * a blockchain operation. */ - class asset_dynamic_data_object : public abstract_object + class asset_dynamic_data_master : public abstract_object { public: static constexpr uint8_t space_id = implementation_ids; static constexpr uint8_t type_id = impl_asset_dynamic_data_object_type; - /// The number of shares currently in existence - share_type current_supply; share_type confidential_supply; ///< total asset held in confidential balances - share_type accumulated_fees; ///< fees accumulate to be paid out over time - share_type fee_pool; ///< in core asset + }; + + class asset_dynamic_data_object : public asset_dynamic_data_master + { + public: + /// The number of shares currently in existence + stored_debt current_supply; + stored_value accumulated_fees; ///< fees accumulate to be paid out over time + stored_value fee_pool; ///< in core asset + + protected: + virtual unique_ptr backup()const; + virtual void restore( graphene::db::object& obj ); }; /** @@ -163,7 +173,7 @@ namespace graphene { namespace chain { */ template share_type reserved( const DB& db )const - { return options.max_supply - dynamic_data(db).current_supply; } + { return options.max_supply - dynamic_data(db).current_supply.get_amount(); } }; /** @@ -172,7 +182,7 @@ namespace graphene { namespace chain { * @ingroup object * @ingroup implementation */ - class asset_bitasset_data_object : public abstract_object + class asset_bitasset_data_master : public abstract_object { public: static constexpr uint8_t space_id = implementation_ids; @@ -217,8 +227,6 @@ namespace graphene { namespace chain { ///@{ /// Price at which force settlements of a black swanned asset will occur price settlement_price; - /// Amount of collateral which is available for force settlement - share_type settlement_fund; ///@} /// Track whether core_exchange_rate in corresponding asset_object has updated @@ -261,6 +269,21 @@ namespace graphene { namespace chain { void update_median_feeds(time_point_sec current_time, time_point_sec next_maintenance_time); }; + class asset_bitasset_data_object : public asset_bitasset_data_master + { + public: + ///@{ + /// Amount of collateral which is available for force settlement + stored_value settlement_fund; + /// Counterpart for individual debt positions + stored_value total_debt; + ///@} + + protected: + virtual unique_ptr backup()const; + virtual void restore( graphene::db::object& obj ); + }; + // key extractor for short backing asset struct bitasset_short_backing_asset_extractor { @@ -282,12 +305,12 @@ namespace graphene { namespace chain { ordered_non_unique< tag, bitasset_short_backing_asset_extractor >, ordered_unique< tag, composite_key< asset_bitasset_data_object, - const_mem_fun< asset_bitasset_data_object, time_point_sec, &asset_bitasset_data_object::feed_expiration_time >, - member< asset_bitasset_data_object, asset_id_type, &asset_bitasset_data_object::asset_id > + const_mem_fun< asset_bitasset_data_master, time_point_sec, &asset_bitasset_data_master::feed_expiration_time >, + member< asset_bitasset_data_master, asset_id_type, &asset_bitasset_data_master::asset_id > > >, ordered_non_unique< tag, - const_mem_fun< asset_bitasset_data_object, bool, &asset_bitasset_data_object::need_to_update_cer > + const_mem_fun< asset_bitasset_data_master, bool, &asset_bitasset_data_master::need_to_update_cer > > > > asset_bitasset_data_object_multi_index_type; @@ -337,5 +360,7 @@ FC_REFLECT_TYPENAME( graphene::chain::asset_bitasset_data_object ) FC_REFLECT_TYPENAME( graphene::chain::asset_dynamic_data_object ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::asset_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::asset_bitasset_data_master ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::asset_bitasset_data_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::asset_dynamic_data_master ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::asset_dynamic_data_object ) diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index 433fe6cc85..424d1f9ea5 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -315,7 +315,7 @@ namespace graphene { namespace chain { void add_balance( account_id_type account, stored_value&& what ); stored_value reduce_balance( account_id_type account, const asset& delta ); - void deposit_market_fee_vesting_balance(const account_id_type &account_id, const asset &delta); + void deposit_market_fee_vesting_balance(const account_id_type &account_id, stored_value&& delta); /** * @brief Retrieve a particular account's market fee vesting balance in a given asset * @param owner Account whose balance should be retrieved @@ -339,16 +339,16 @@ namespace graphene { namespace chain { */ optional< vesting_balance_id_type > deposit_lazy_vesting( const optional< vesting_balance_id_type >& ovbid, - share_type amount, + stored_value&& amount, uint32_t req_vesting_seconds, vesting_balance_type balance_type, account_id_type req_owner, bool require_vesting ); // helper to handle cashback rewards - void deposit_cashback(const account_object& acct, share_type amount, bool require_vesting = true); + void deposit_cashback(const account_object& acct, stored_value&& amount, bool require_vesting = true); // helper to handle witness pay - void deposit_witness_pay(const witness_object& wit, share_type amount); + void deposit_witness_pay(const witness_object& wit, stored_value&& amount); //////////////////// db_debug.cpp //////////////////// @@ -364,7 +364,8 @@ namespace graphene { namespace chain { void cancel_limit_order(const limit_order_object& order, bool create_virtual_op = true, bool skip_cancel_fee = false); void revive_bitasset( const asset_object& bitasset ); void cancel_bid(const collateral_bid_object& bid, bool create_virtual_op = true); - void execute_bid( const collateral_bid_object& bid, share_type debt_covered, share_type collateral_from_fund, const price_feed& current_feed ); + void execute_bid( const collateral_bid_object& bid, share_type debt_covered, + stored_value&& collateral_from_fund, const price_feed& current_feed ); /** * @brief Process a new limit order through the markets @@ -529,7 +530,7 @@ namespace graphene { namespace chain { void initialize_budget_record( fc::time_point_sec now, budget_record& rec )const; void process_budget(); - void pay_workers( share_type& budget ); + void pay_workers( stored_value&& budget ); void perform_chain_maintenance(const signed_block& next_block, const global_property_object& global_props); void update_active_witnesses(); void update_active_committee_members(); diff --git a/libraries/chain/include/graphene/chain/global_property_object.hpp b/libraries/chain/include/graphene/chain/global_property_object.hpp index 796f24fb72..ee9aee6c67 100644 --- a/libraries/chain/include/graphene/chain/global_property_object.hpp +++ b/libraries/chain/include/graphene/chain/global_property_object.hpp @@ -25,6 +25,7 @@ #include #include +#include #include namespace graphene { namespace chain { @@ -61,7 +62,7 @@ namespace graphene { namespace chain { * This is an implementation detail. The values here are calculated during normal chain operations and reflect the * current values of global blockchain properties. */ - class dynamic_global_property_object : public abstract_object + class dynamic_global_property_master : public abstract_object { public: static constexpr uint8_t space_id = implementation_ids; @@ -73,7 +74,6 @@ namespace graphene { namespace chain { witness_id_type current_witness; time_point_sec next_maintenance_time; time_point_sec last_budget_time; - share_type witness_budget; uint32_t accounts_registered_this_interval = 0; /** * Every time a block is missed this increases by @@ -118,6 +118,16 @@ namespace graphene { namespace chain { maintenance_flag = 0x01 }; }; + + class dynamic_global_property_object : public dynamic_global_property_master + { + public: + stored_value witness_budget; + + protected: + virtual unique_ptr backup()const; + virtual void restore( graphene::db::object& obj ); + }; }} MAP_OBJECT_ID_TO_TYPE(graphene::chain::dynamic_global_property_object) @@ -126,5 +136,6 @@ MAP_OBJECT_ID_TO_TYPE(graphene::chain::global_property_object) FC_REFLECT_TYPENAME( graphene::chain::dynamic_global_property_object ) FC_REFLECT_TYPENAME( graphene::chain::global_property_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::dynamic_global_property_master ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::dynamic_global_property_object ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::global_property_object ) diff --git a/libraries/chain/include/graphene/chain/stored_value.hpp b/libraries/chain/include/graphene/chain/stored_value.hpp index 2eceff7ad9..3c0261ca1e 100644 --- a/libraries/chain/include/graphene/chain/stored_value.hpp +++ b/libraries/chain/include/graphene/chain/stored_value.hpp @@ -26,44 +26,82 @@ #include namespace graphene { namespace chain { - class stored_value + class stored_value; + + class stored_debt { graphene::protocol::asset_id_type _asset; graphene::protocol::share_type _amount; public: - explicit stored_value( const graphene::protocol::asset_id_type asset = graphene::protocol::asset_id_type() ); - ~stored_value(); - stored_value( const stored_value& copy ) = delete; - stored_value( stored_value& copy ) = delete; - stored_value( stored_value&& move ); + explicit stored_debt( const graphene::protocol::asset_id_type asset = graphene::protocol::asset_id_type() ); + ~stored_debt(); - stored_value& operator=( const stored_value& copy ) = delete; - stored_value& operator=( stored_value& copy ) = delete; - stored_value& operator=( stored_value&& move ); + stored_debt( const stored_debt& copy ) = delete; + stored_debt( stored_debt& copy ) = delete; + stored_debt( stored_debt&& move ); - stored_value split( const graphene::protocol::share_type amount ); - stored_value& operator+=( stored_value&& other ); + stored_debt& operator=( const stored_debt& copy ) = delete; + stored_debt& operator=( stored_debt& copy ) = delete; + stored_debt& operator=( stored_debt&& move ); - static stored_value issue( const graphene::protocol::asset_id_type asset, - const graphene::protocol::share_type amount ); - void burn(); graphene::protocol::asset get_value()const; graphene::protocol::asset_id_type get_asset()const { return _asset; } graphene::protocol::share_type get_amount()const { return _amount; } + + stored_value issue( const graphene::protocol::share_type amount ); + void burn( stored_value&& amount ); + + template< typename Stream > + void unpack( Stream s, uint32_t _max_depth ) + { + graphene::protocol::asset amount; + unpack( s, amount, _max_depth ); + _asset = amount.asset_id; + _amount = amount.amount; + } + protected: void restore( const graphene::protocol::asset& backup ); friend class object; }; + + class stored_value : public stored_debt + { + public: + explicit stored_value( const graphene::protocol::asset_id_type asset = graphene::protocol::asset_id_type() ); + stored_value( stored_value&& move ) : stored_debt( std::move(move) ) {} + + stored_value& operator=( stored_value&& move ) { + this->stored_debt::operator=( std::move(move) ); + return *this; + } + + stored_value split( const graphene::protocol::share_type amount ); + stored_value& operator+=( stored_value&& other ); + + protected: + static stored_value issue( const graphene::protocol::asset_id_type asset, + const graphene::protocol::share_type amount ); + void burn(); + friend class stored_debt; + }; + } } // graphene::chain namespace fc { /* should be unused template<> -void from_variant( const fc::variant& var, graphene::chain::stored_value& value, uint32_t max_depth ) +void from_variant( const fc::variant& var, graphene::chain::stored_debt& value, uint32_t max_depth ) { } */ +template<> +void to_variant( const graphene::chain::stored_debt& value, fc::variant& var, uint32_t max_depth ) +{ + to_variant( value.get_value(), var, max_depth ); +} + template<> void to_variant( const graphene::chain::stored_value& value, fc::variant& var, uint32_t max_depth ) { @@ -73,26 +111,32 @@ void to_variant( const graphene::chain::stored_value& value, fc::variant& var, u namespace raw { template< typename Stream > -void pack( Stream& stream, const graphene::chain::stored_value& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) +void pack( Stream& stream, const graphene::chain::stored_debt& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; pack( stream, value.get_value(), _max_depth ); } - template< typename Stream > -void unpack( Stream& s, graphene::chain::stored_value& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) +void unpack( Stream& s, graphene::chain::stored_debt& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) { FC_ASSERT( _max_depth > 0 ); --_max_depth; - graphene::protocol::asset amount; - unpack( s, amount, _max_depth ); - value = graphene::chain::stored_value::issue( amount.asset_id, amount.amount ); + value.unpack( s, _max_depth ); } } // fc::raw +template<> +struct get_typename< graphene::chain::stored_debt > +{ + static const char* name() + { + return "graphene::chain::stored_debt"; + } +}; + template<> struct get_typename< graphene::chain::stored_value > { @@ -102,5 +146,4 @@ struct get_typename< graphene::chain::stored_value > } }; - } // fc diff --git a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp index 3e91d9cf9c..282f3be4ef 100644 --- a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp +++ b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp @@ -148,7 +148,7 @@ namespace graphene { namespace chain { /** * Vesting balance object is a balance that is locked by the blockchain for a period of time. */ - class vesting_balance_object : public abstract_object + class vesting_balance_master : public abstract_object { public: static constexpr uint8_t space_id = protocol_ids; @@ -156,22 +156,25 @@ namespace graphene { namespace chain { /// Account which owns and may withdraw from this vesting balance account_id_type owner; - /// Total amount remaining in this vesting balance - /// Includes the unvested funds, and the vested funds which have not yet been withdrawn - asset balance; /// The vesting policy stores details on when funds vest, and controls when they may be withdrawn vesting_policy policy; /// type of the vesting balance vesting_balance_type balance_type = vesting_balance_type::unspecified; + }; - vesting_balance_object() {} + class vesting_balance_object : public vesting_balance_master + { + public: + /// Total amount remaining in this vesting balance + /// Includes the unvested funds, and the vested funds which have not yet been withdrawn + stored_value balance; ///@brief Deposit amount into vesting balance, requiring it to vest before withdrawal - void deposit(const fc::time_point_sec& now, const asset& amount); + void deposit(const fc::time_point_sec& now, stored_value&& amount); bool is_deposit_allowed(const fc::time_point_sec& now, const asset& amount)const; /// @brief Deposit amount into vesting balance, making the new funds vest immediately - void deposit_vested(const fc::time_point_sec& now, const asset& amount); + void deposit_vested(const fc::time_point_sec& now, stored_value&& amount); bool is_deposit_vested_allowed(const fc::time_point_sec& now, const asset& amount)const; /** @@ -182,14 +185,19 @@ namespace graphene { namespace chain { * The money doesn't "go" anywhere; the caller is responsible for * crediting it to the proper account. */ - void withdraw(const fc::time_point_sec& now, const asset& amount); + stored_value withdraw(const fc::time_point_sec& now, const asset& amount); bool is_withdraw_allowed(const fc::time_point_sec& now, const asset& amount)const; /** * Get amount of allowed withdrawal. */ asset get_allowed_withdraw(const time_point_sec& now)const; + + protected: + virtual unique_ptr backup()const; + virtual void restore( graphene::db::object& obj ); }; + /** * @ingroup object_index */ @@ -221,7 +229,7 @@ namespace detail { { if ( vbo.balance_type == vesting_balance_type::market_fee_sharing ) { - return vbo_mfs_hash(vbo.owner, vbo.balance.asset_id); + return vbo_mfs_hash(vbo.owner, vbo.balance.get_asset()); } return hash_value(vbo.id); } @@ -241,7 +249,7 @@ namespace detail { if ( ( lhs.balance_type == vesting_balance_type::market_fee_sharing ) && ( lhs.balance_type == rhs.balance_type ) && ( lhs.owner == rhs.owner ) && - ( lhs.balance.asset_id == rhs.balance.asset_id) + ( lhs.balance.get_asset() == rhs.balance.get_asset()) ) { return true; @@ -257,7 +265,7 @@ namespace detail { ordered_unique< tag, member< object, object_id_type, &object::id > >, ordered_non_unique< tag, - member + member >, hashed_unique< tag, identity, @@ -293,12 +301,14 @@ FC_REFLECT_EMPTY( graphene::chain::instant_vesting_policy ) FC_REFLECT_TYPENAME( graphene::chain::vesting_policy ) -FC_REFLECT_DERIVED(graphene::chain::vesting_balance_object, (graphene::db::object), +FC_REFLECT_DERIVED(graphene::chain::vesting_balance_master, (graphene::db::object), (owner) - (balance) (policy) (balance_type) ) +FC_REFLECT_DERIVED(graphene::chain::vesting_balance_object, (graphene::chain::vesting_balance_master), + (balance) + ) FC_REFLECT_ENUM( graphene::chain::vesting_balance_type, (unspecified)(cashback)(worker)(witness)(market_fee_sharing) ) diff --git a/libraries/chain/include/graphene/chain/worker_object.hpp b/libraries/chain/include/graphene/chain/worker_object.hpp index 23243a02ae..5d0effc7a6 100644 --- a/libraries/chain/include/graphene/chain/worker_object.hpp +++ b/libraries/chain/include/graphene/chain/worker_object.hpp @@ -28,6 +28,7 @@ namespace graphene { namespace chain { class database; +class stored_value; /** * @defgroup worker_types Implementations of the various worker types in the system @@ -63,7 +64,7 @@ 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&); + void pay_worker(stored_value&& pay, database&); }; /** @@ -76,7 +77,7 @@ struct vesting_balance_worker_type /// The balance this worker pays into vesting_balance_id_type balance; - void pay_worker(share_type pay, database& db); + void pay_worker(stored_value&& pay, database& db); }; /** @@ -89,7 +90,7 @@ 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&); + void pay_worker(stored_value&& pay, database&); }; ///@} diff --git a/libraries/chain/small_objects.cpp b/libraries/chain/small_objects.cpp index f0c70152d6..2893de143d 100644 --- a/libraries/chain/small_objects.cpp +++ b/libraries/chain/small_objects.cpp @@ -44,6 +44,34 @@ #include +namespace graphene { namespace chain { + +class dynamic_global_property_backup : public dynamic_global_property_master +{ + private: + dynamic_global_property_backup( const dynamic_global_property_object& original ) + : dynamic_global_property_master( original ) + { + witness_budget = original.witness_budget.get_value(); + } + asset witness_budget; + friend class dynamic_global_property_object; +}; + +unique_ptr dynamic_global_property_object::backup()const +{ + return std::make_unique( *this ); +} + +void dynamic_global_property_object::restore( object& obj ) +{ + const auto& backup = static_cast(obj); + balance.restore( backup.witness_budget ) ); + static_cast(*this) = std::move( backup ); +} + +} } // graphene::chain + FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::balance_object, (graphene::db::object), (owner)(balance)(vesting_policy)(last_claim_date) ) @@ -91,14 +119,13 @@ FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::committee_member_object, (graph FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::blinded_balance_object, (graphene::db::object), (commitment)(asset_id)(owner) ) -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::dynamic_global_property_object, (graphene::db::object), +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::dynamic_global_property_master, (graphene::db::object), (head_block_number) (head_block_id) (time) (current_witness) (next_maintenance_time) (last_budget_time) - (witness_budget) (accounts_registered_this_interval) (recently_missed_count) (current_aslot) @@ -106,6 +133,9 @@ FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::dynamic_global_property_object, (dynamic_flags) (last_irreversible_block_num) ) +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::dynamic_global_property_object, (graphene::chain::dynamic_global_property_master), + (witness_budget) + ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::global_property_object, (graphene::db::object), (parameters) @@ -195,6 +225,7 @@ GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::immutable_chain_para GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::chain_property_object ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::committee_member_object ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::blinded_balance_object ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::dynamic_global_property_master ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::dynamic_global_property_object ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::global_property_object ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::htlc_object ) diff --git a/libraries/chain/stored_value.cpp b/libraries/chain/stored_value.cpp index 715ca15149..fc38f8bab5 100644 --- a/libraries/chain/stored_value.cpp +++ b/libraries/chain/stored_value.cpp @@ -26,24 +26,25 @@ #include namespace graphene { namespace chain { - stored_value::stored_value( const graphene::protocol::asset_id_type asset ) + stored_debt::stored_debt( const graphene::protocol::asset_id_type asset ) : _asset(asset), _amount(0) {} - stored_value::~stored_value() + stored_debt::~stored_debt() { FC_ASSERT( _amount == 0, "Value leak detected: (${n],${a])!", ("n",_amount.value)("a",_asset) ); } - stored_value::stored_value( stored_value&& move ) + stored_debt::stored_debt( stored_debt&& move ) : _asset(move._asset), _amount(move._amount) { move._amount = 0; } - stored_value& stored_value::operator=( stored_value&& other ) + stored_debt& stored_debt::operator=( stored_value&& other ) { if( &other == this ) return *this; - FC_ASSERT( _amount.value == 0, "Can't overwrite (${n},${a}) with (${on},${oa})!", + FC_ASSERT( _amount.value == 0 && (_asset == asset_id_type() || _asset == other._asset), + "Can't overwrite (${n},${a}) with (${on},${oa})!", ("on",other._amount.value)("oa",other._asset)("n",_amount.value)("a",_asset) ); _asset = other._asset; _amount = other._amount; @@ -51,6 +52,44 @@ namespace graphene { namespace chain { return *this; } + stored_value stored_debt::issue( const graphene::protocol::share_type amount ) + { + FC_ASSERT( amount >= 0, "Cannot issue a negative amount of ${a}", ("a",_asset) ); + _amount += amount; + return stored_value::issue( _asset, amount ); + } + + void stored_debt::burn( stored_value&& amount ) + { + FC_ASSERT( amount.get_amount() >= 0, "Cannot burn a negative amount of ${a}", ("a",_asset) ); + FC_ASSERT( _asset == amount.get_asset(), "Debt ${a} cannot burn ${n} of ${b}", + ("a",_asset)("n",amount.get_amount())("b",amount.get_asset()) ); + _amount -= amount.get_amount(); + amount.burn(); + } + + void stored_debt::restore( const graphene::protocol::asset& backup ) + { + FC_ASSERT( _asset == backup.asset_id, "Corrupted backup: ${a} != ${b}", + ("a",_asset)("b",backup.asset_id) ); + _amount = backup.amount; + } + + graphene::protocol::asset stored_debt::get_value()const + { + return graphene::protocol::asset( _amount, _asset ); + } + + void stored_debt::restore( const graphene::protocol::asset& backup ) + { + FC_ASSERT( _asset == backup.asset_id, "Corrupted backup: ${a} != ${b}", + ("a",_asset)("b",backup.asset_id) ); + _amount = backup.amount; + } + + + stored_value::stored_value( const graphene::protocol::asset_id_type asset ) : stored_debt( asset ) {} + stored_value stored_value::split( const graphene::protocol::share_type amount ) { FC_ASSERT( amount <= _amount, "Invalid split: want ${w} but have only ${n} of ${a}", @@ -85,9 +124,5 @@ namespace graphene { namespace chain { _amount = 0; } - graphene::protocol::asset stored_value::get_value()const - { - return graphene::protocol::asset( _amount, _asset ); - } } } // graphene::chain diff --git a/libraries/chain/vesting_balance_object.cpp b/libraries/chain/vesting_balance_object.cpp index 6c3f65a16e..f5bd392f5b 100644 --- a/libraries/chain/vesting_balance_object.cpp +++ b/libraries/chain/vesting_balance_object.cpp @@ -237,14 +237,14 @@ bool vesting_balance_object::is_withdraw_allowed(const time_point_sec& now, cons return result; } -void vesting_balance_object::deposit(const time_point_sec& now, const asset& amount) +void vesting_balance_object::deposit(const time_point_sec& now, stored_value&& amount) { on_deposit_visitor vtor(balance, now, amount); policy.visit(vtor); balance += amount; } -void vesting_balance_object::deposit_vested(const time_point_sec& now, const asset& amount) +void vesting_balance_object::deposit_vested(const time_point_sec& now, stored_value&& amount) { on_deposit_vested_visitor vtor(balance, now, amount); policy.visit(vtor); @@ -256,7 +256,7 @@ bool vesting_balance_object::is_deposit_vested_allowed(const time_point_sec& now return policy.visit(is_deposit_vested_allowed_visitor(balance, now, amount)); } -void vesting_balance_object::withdraw(const time_point_sec& now, const asset& amount) +stored_value vesting_balance_object::withdraw(const time_point_sec& now, const asset& amount) { assert(amount <= balance); on_withdraw_visitor vtor(balance, now, amount); @@ -270,6 +270,30 @@ asset vesting_balance_object::get_allowed_withdraw(const time_point_sec& now)con return policy.visit(get_allowed_withdraw_visitor(balance, now, amount)); } +class vesting_balance_backup : public vesting_balance_master +{ + private: + vesting_balance_backup( const vesting_balance_object& original ) + : vesting_balance_master( original ) + { + balance = original.balance.get_value(); + } + asset balance; + friend class vesting_balance_object; +}; + +unique_ptr vesting_balance_object::backup()const +{ + return std::make_unique( *this ); +} + +void vesting_balance_object::restore( object& obj ) +{ + const auto& backup = static_cast(obj); + balance.restore( backup.balance ) ); + static_cast(*this) = std::move( backup ); +} + } } // graphene::chain GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::linear_vesting_policy ) diff --git a/libraries/chain/worker_evaluator.cpp b/libraries/chain/worker_evaluator.cpp index a0463a738a..8174e395db 100644 --- a/libraries/chain/worker_evaluator.cpp +++ b/libraries/chain/worker_evaluator.cpp @@ -104,26 +104,26 @@ object_id_type worker_create_evaluator::do_apply(const worker_create_evaluator:: }).id; } FC_CAPTURE_AND_RETHROW( (o) ) } -void refund_worker_type::pay_worker(share_type pay, database& db) +void refund_worker_type::pay_worker(stored_value&& pay, database& db) { - total_burned += pay; - db.modify( db.get_core_dynamic_data(), [pay](asset_dynamic_data_object& d) { - d.current_supply -= pay; + total_burned += pay.get_amount(); + db.modify( db.get_core_dynamic_data(), [&pay](asset_dynamic_data_object& d) { + d.current_supply.burn( std::move(pay) ); }); } -void vesting_balance_worker_type::pay_worker(share_type pay, database& db) +void vesting_balance_worker_type::pay_worker(stored_value&& pay, database& db) { - db.modify(balance(db), [&](vesting_balance_object& b) { - b.deposit(db.head_block_time(), asset(pay)); + db.modify(balance(db), [&pay,&db](vesting_balance_object& b) { + b.deposit(db.head_block_time(), std::move(pay)); }); } -void burn_worker_type::pay_worker(share_type pay, database& db) +void burn_worker_type::pay_worker(stored_value&& pay, database& db) { total_burned += pay; - db.adjust_balance( GRAPHENE_NULL_ACCOUNT, pay ); + db.add_balance( GRAPHENE_NULL_ACCOUNT, std::move(pay) ); } } } // graphene::chain From b80b1f16d795be396aad589f4b9bc4236e49bb4f Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sun, 1 Dec 2019 17:23:41 +0100 Subject: [PATCH 06/59] Intermediate --- libraries/chain/db_debug.cpp | 2 +- libraries/chain/db_init.cpp | 17 +- libraries/chain/db_market.cpp | 428 +++++++++--------- .../chain/include/graphene/chain/database.hpp | 18 +- .../include/graphene/chain/market_object.hpp | 59 ++- libraries/chain/market_object.cpp | 78 +++- 6 files changed, 358 insertions(+), 244 deletions(-) diff --git a/libraries/chain/db_debug.cpp b/libraries/chain/db_debug.cpp index f6e4e0b4ea..e219ca5ed1 100644 --- a/libraries/chain/db_debug.cpp +++ b/libraries/chain/db_debug.cpp @@ -57,7 +57,7 @@ void database::debug_dump() } for( const force_settlement_object& s : settle_index ) { - total_balances[s.balance.asset_id] += s.balance.amount; + total_balances[s.balance.get_asset()] += s.balance.get_amount(); } for( const vesting_balance_object& vbo : db.get_index_type< vesting_balance_index >().indices() ) total_balances[ vbo.balance.get_asset() ] += vbo.balance.get_amount(); diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 3bd1931e4d..986fa3f666 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -436,6 +436,7 @@ void database::init_genesis(const genesis_state_type& genesis_state) { int collateral_holder_number = 0; total_debts[ new_asset_id ] = 0; + stored_value total_borrowed( new_asset_id ); for( const auto& collateral_rec : asset.collateral_records ) { account_create_operation cop; @@ -455,13 +456,14 @@ void database::init_genesis(const genesis_state_type& genesis_state) collateral = core.current_supply.issue( collateral_rec.collateral ); }); - create([owner_account_id,&collateral_rec,&core_asset,new_asset_id,&collateral](call_order_object& c) { + stored_value borrowed; + create([owner_account_id,&collateral_rec,&core_asset,&collateral,&total_borrowed](call_order_object& c) { c.borrower = owner_account_id; c.collateral = std::move( collateral ); - c.debt = collateral_rec.debt; - c.call_price = price::call_price(chain::asset(c.debt, new_asset_id), - c.collateral.get_value(), - GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO); + c.debt = stored_debt(total_borrowed.get_asset()); + total_borrowed += c.debt.issue( collateral_rec.debt ); + c.call_price = price::call_price( c.debt.get_value(), c.collateral.get_value(), + GRAPHENE_DEFAULT_MAINTENANCE_COLLATERAL_RATIO ); }); total_supplies[ asset_id_type(0) ] += collateral_rec.collateral; @@ -469,10 +471,11 @@ void database::init_genesis(const genesis_state_type& genesis_state) ++collateral_holder_number; } - bitasset_data_id = create([&core_asset,new_asset_id](asset_bitasset_data_object& b) { + bitasset_data_id = create([&core_asset,&total_borrowed](asset_bitasset_data_object& b) { b.options.short_backing_asset = core_asset.id; b.options.minimum_feeds = GRAPHENE_DEFAULT_MINIMUM_FEEDS; - b.asset_id = new_asset_id; + b.asset_id = total_borrowed.get_asset(); + b.total_debt = std::move(total_borrowed); }).id; } diff --git a/libraries/chain/db_market.cpp b/libraries/chain/db_market.cpp index c37a643c18..03df5f1618 100644 --- a/libraries/chain/db_market.cpp +++ b/libraries/chain/db_market.cpp @@ -59,11 +59,11 @@ void database::globally_settle_asset( const asset_object& mia, const price& sett const asset_bitasset_data_object& bitasset = mia.bitasset_data(*this); FC_ASSERT( !bitasset.has_settlement(), "black swan already occurred, it should not happen again" ); - const asset_object& backing_asset = bitasset.options.short_backing_asset(*this); - asset collateral_gathered = backing_asset.amount(0); - - const asset_dynamic_data_object& mia_dyn = mia.dynamic_asset_data_id(*this); - auto original_mia_supply = mia_dyn.current_supply; + stored_value collateral_gathered( bitasset.options.short_backing_asset ); + stored_value debt_pool; + modify( bitasset, [&debt_pool]( asset_bitasset_data_object& obj ){ + debt_pool = std::move(obj.total_debt); + }); const auto& call_price_index = get_index_type().indices().get(); @@ -83,26 +83,37 @@ void database::globally_settle_asset( const asset_object& mia, const price& sett if( pays > call_itr->get_collateral() ) pays = call_itr->get_collateral(); + asset receives = call_itr->get_debt(); - collateral_gathered += pays; const auto& order = *call_itr; ++call_itr; - FC_ASSERT( fill_call_order( order, pays, order.get_debt(), settlement_price, true ) ); // call order is maker - } + stored_value remaining_collateral; + modify( order, [&collateral_gathered,&debt_pool,&pays,&remaining_collateral] ( call_order_object& call ) { + collateral_gathered += call.collateral.split(pays.amount); + call.debt.burn( debt_pool.split(call.debt.get_amount()) ); + remaining_collateral = std::move(call.collateral); + }); - modify( bitasset, [&mia,original_mia_supply,&collateral_gathered]( asset_bitasset_data_object& obj ){ - obj.settlement_price = mia.amount(original_mia_supply) / collateral_gathered; - obj.settlement_fund = collateral_gathered.amount; - }); - - /// After all margin positions are closed, the current supply will be reported as 0, but - /// that is a lie, the supply didn't change. We need to capture the current supply before - /// filling all call orders and then restore it afterward. Then in the force settlement - /// evaluator reduce the supply - modify( mia_dyn, [original_mia_supply]( asset_dynamic_data_object& obj ){ - obj.current_supply = original_mia_supply; + // Update account statistics. We know that order.collateral_type() == pays.asset_id + if( pays.asset_id == asset_id_type() ) + modify( get_account_stats_by_owner(order.borrower), [&remaining_collateral,&pays]( account_statistics_object& b ){ + b.total_core_in_orders -= pays.amount; + b.total_core_in_orders -= remaining_collateral.get_amount(); }); + if( remaining_collateral.get_amount() > 0 ) + add_balance( order.borrower, std::move(remaining_collateral) ); + + push_applied_operation( fill_order_operation( order.id, order.borrower, pays, receives, + asset(0, pays.asset_id), settlement_price, true ) ); + remove( order ); + } + + const auto& add = mia.dynamic_asset_data_id(*this); + modify( bitasset, [&add,&collateral_gathered]( asset_bitasset_data_object& obj ){ + obj.settlement_price = add.current_supply.get_value() / collateral_gathered.get_value(); + obj.settlement_fund = std::move( collateral_gathered ); + }); } FC_CAPTURE_AND_RETHROW( (mia)(settlement_price) ) } void database::revive_bitasset( const asset_object& bitasset ) @@ -114,17 +125,18 @@ void database::revive_bitasset( const asset_object& bitasset ) FC_ASSERT( !bad.is_prediction_market ); FC_ASSERT( !bad.current_feed.settlement_price.is_null() ); - if( bdd.current_supply > 0 ) + if( bdd.current_supply.get_amount() > 0 ) { // Create + execute a "bid" with 0 additional collateral - const collateral_bid_object& pseudo_bid = create([&](collateral_bid_object& bid) { + const collateral_bid_object& pseudo_bid = create([&bitasset,&bad,&bdd](collateral_bid_object& bid) { bid.bidder = bitasset.issuer; bid.collateral_offered = stored_value( bad.options.short_backing_asset ); - bid.debt_covered = asset( bdd.current_supply, bitasset.id ); + bid.debt_covered = asset( bdd.current_supply.get_amount(), bitasset.id ); }); - execute_bid( pseudo_bid, bdd.current_supply, bad.settlement_fund, bad.current_feed ); - } else - FC_ASSERT( bad.settlement_fund == 0 ); + stored_value fund; + modify( bad, [&fund] ( asset_bitasset_data_object& _bad ) { fund = std::move(_bad.settlement_fund); }); + execute_bid( pseudo_bid, bdd.current_supply.get_amount(), std::move(fund), bad.current_feed ); + } _cancel_bids_and_revive_mpa( bitasset, bad ); } FC_CAPTURE_AND_RETHROW( (bitasset) ) } @@ -134,6 +146,7 @@ void database::_cancel_bids_and_revive_mpa( const asset_object& bitasset, const FC_ASSERT( bitasset.is_market_issued() ); FC_ASSERT( bad.has_settlement() ); FC_ASSERT( !bad.is_prediction_market ); + FC_ASSERT( bad.settlement_fund.get_amount() == 0 ); // cancel remaining bids const auto& bid_idx = get_index_type< collateral_bid_index >().indices().get(); @@ -148,10 +161,7 @@ void database::_cancel_bids_and_revive_mpa( const asset_object& bitasset, const } // revive - modify( bad, []( asset_bitasset_data_object& obj ){ - obj.settlement_price = price(); - obj.settlement_fund = 0; - }); + modify( bad, []( asset_bitasset_data_object& obj ){ obj.settlement_price = price(); }); } FC_CAPTURE_AND_RETHROW( (bitasset) ) } void database::cancel_bid(const collateral_bid_object& bid, bool create_virtual_op) @@ -179,20 +189,23 @@ void database::execute_bid( const collateral_bid_object& bid, share_type debt_co modify( bid, [&collateral] ( collateral_bid_object& _bid ) { collateral = std::move(_bid.collateral_offered); }); + collateral += std::move(collateral_from_fund); + stored_debt debt( bid.debt_covered.asset_id ); + modify( debt.get_asset()(*this).bitasset_data(*this), [&debt,debt_covered] ( asset_bitasset_data_object& bad ) { + bad.total_debt += debt.issue( debt_covered ); + }); const auto& call_obj = create( - [&bid,&collateral,debt_covered,¤t_feed] ( call_order_object& call ) { + [&bid,&collateral,&debt,¤t_feed,this] ( call_order_object& call ) { call.borrower = bid.bidder; call.collateral = std::move(collateral); - call.collateral += std::move(collateral_from_fund); - call.debt = debt_covered; + call.debt = std::move(debt); // don't calculate call_price after core-1270 hard fork if( get_dynamic_global_properties().next_maintenance_time > HARDFORK_CORE_1270_TIME ) // bid.inv_swan_price is in collateral / debt call.call_price = price( asset( 1, bid.collateral_offered.get_asset() ), asset( 1, bid.debt_covered.asset_id ) ); else - call.call_price = price::call_price( asset( debt_covered, bid.debt_covered.asset_id), - call.collateral.get_value(), + call.call_price = price::call_price( call.debt.get_value(), call.collateral.get_value(), current_feed.maintenance_collateral_ratio ); }); @@ -210,16 +223,20 @@ void database::execute_bid( const collateral_bid_object& bid, share_type debt_co void database::cancel_settle_order(const force_settlement_object& order, bool create_virtual_op) { - adjust_balance(order.owner, order.balance); + stored_value balance; + modify( order, [&balance] ( force_settlement_object& fso ) { balance = std::move(fso.balance); }); if( create_virtual_op ) { asset_settle_cancel_operation vop; vop.settlement = order.id; vop.account = order.owner; - vop.amount = order.balance; + vop.amount = balance.get_value(); push_applied_operation( vop ); } + + add_balance( order.owner, std::move(balance) ); + remove(order); } @@ -232,84 +249,89 @@ void database::cancel_limit_order( const limit_order_object& order, bool create_ const account_statistics_object* seller_acc_stats = nullptr; const asset_dynamic_data_object* fee_asset_dyn_data = nullptr; limit_order_cancel_operation vop; - share_type deferred_fee = order.deferred_fee; - asset deferred_paid_fee = order.deferred_paid_fee; + stored_value refunded; + stored_value deferred_fee; + stored_value deferred_paid_fee; + modify( order, [&refunded,&deferred_fee,&deferred_paid_fee] ( limit_order_object& loo ) { + refunded = std::move( loo.for_sale ); + deferred_fee = std::move( loo.deferred_fee ); + deferred_paid_fee = std::move( loo.deferred_paid_fee ); + }); if( create_virtual_op ) { vop.order = order.id; vop.fee_paying_account = order.seller; // only deduct fee if not skipping fee, and there is any fee deferred - if( !skip_cancel_fee && deferred_fee > 0 ) + if( !skip_cancel_fee && deferred_fee.get_amount() > 0 ) { - asset core_cancel_fee = current_fee_schedule().calculate_fee( vop ); + share_type core_cancel_fee_amount = current_fee_schedule().calculate_fee( vop ).amount; // cap the fee - if( core_cancel_fee.amount > deferred_fee ) - core_cancel_fee.amount = deferred_fee; + if( core_cancel_fee_amount > deferred_fee.get_amount() ) + core_cancel_fee_amount = deferred_fee.get_amount(); // if there is any CORE fee to deduct, redirect it to referral program - if( core_cancel_fee.amount > 0 ) + if( core_cancel_fee_amount > 0 ) { - seller_acc_stats = &order.seller( *this ).statistics( *this ); - modify( *seller_acc_stats, [&]( account_statistics_object& obj ) { - obj.pay_fee( core_cancel_fee.amount, get_global_properties().parameters.cashback_vesting_threshold ); - } ); - deferred_fee -= core_cancel_fee.amount; // handle originally paid fee if any: // to_deduct = round_up( paid_fee * core_cancel_fee / deferred_core_fee_before_deduct ) - if( deferred_paid_fee.amount == 0 ) + if( deferred_paid_fee.get_amount() == 0 ) { - vop.fee = core_cancel_fee; + vop.fee = asset( core_cancel_fee_amount ); } else { - fc::uint128_t fee128( deferred_paid_fee.amount.value ); - fee128 *= core_cancel_fee.amount.value; + fc::uint128_t fee128( deferred_paid_fee.get_amount().value ); + fee128 *= core_cancel_fee_amount.value; // to round up - fee128 += order.deferred_fee.value; + fee128 += deferred_fee.get_amount().value; fee128 -= 1; - fee128 /= order.deferred_fee.value; - share_type cancel_fee_amount = static_cast(fee128); + fee128 /= deferred_fee.get_amount().value; + // cancel_fee should be no more than deferred_paid_fee + stored_value cancel_fee = deferred_paid_fee.split( static_cast(fee128) ); + vop.fee = cancel_fee.get_value(); // cancel_fee should be positive, pay it to asset's accumulated_fees - fee_asset_dyn_data = &deferred_paid_fee.asset_id(*this).dynamic_asset_data_id(*this); - modify( *fee_asset_dyn_data, [&](asset_dynamic_data_object& addo) { - addo.accumulated_fees += cancel_fee_amount; + fee_asset_dyn_data = &deferred_paid_fee.get_asset()(*this).dynamic_asset_data_id(*this); + modify( *fee_asset_dyn_data, [&cancel_fee](asset_dynamic_data_object& addo) { + addo.accumulated_fees += std::move( cancel_fee ); }); - // cancel_fee should be no more than deferred_paid_fee - deferred_paid_fee.amount -= cancel_fee_amount; - vop.fee = asset( cancel_fee_amount, deferred_paid_fee.asset_id ); } + + stored_value core_cancel_fee = deferred_fee.split( core_cancel_fee_amount ); + seller_acc_stats = &order.seller( *this ).statistics( *this ); + modify( *seller_acc_stats, [&core_cancel_fee,this]( account_statistics_object& obj ) { + obj.pay_fee( std::move(core_cancel_fee), get_global_properties().parameters.cashback_vesting_threshold ); + } ); } } } // refund funds in order - auto refunded = order.amount_for_sale(); - if( refunded.asset_id == asset_id_type() ) + if( refunded.get_asset() == asset_id_type() ) { if( seller_acc_stats == nullptr ) seller_acc_stats = &order.seller( *this ).statistics( *this ); - modify( *seller_acc_stats, [&]( account_statistics_object& obj ) { - obj.total_core_in_orders -= refunded.amount; + modify( *seller_acc_stats, [&refunded]( account_statistics_object& obj ) { + obj.total_core_in_orders -= refunded.get_amount(); }); } - adjust_balance(order.seller, refunded); + add_balance( order.seller, std::move(refunded) ); // refund fee // could be virtual op or real op here - if( order.deferred_paid_fee.amount == 0 ) + if( deferred_paid_fee.get_amount() == 0 ) { // be here, order.create_time <= HARDFORK_CORE_604_TIME, or fee paid in CORE, or no fee to refund. // if order was created before hard fork 604 then cancelled no matter before or after hard fork 604, // see it as fee paid in CORE, deferred_fee should be refunded to order owner but not fee pool - adjust_balance( order.seller, deferred_fee ); + add_balance( order.seller, std::move(deferred_fee) ); } else // need to refund fee in originally paid asset { - adjust_balance(order.seller, deferred_paid_fee); + add_balance( order.seller, std::move(deferred_paid_fee) ); // be here, must have: fee_asset != CORE if( fee_asset_dyn_data == nullptr ) - fee_asset_dyn_data = &deferred_paid_fee.asset_id(*this).dynamic_asset_data_id(*this); - modify( *fee_asset_dyn_data, [&](asset_dynamic_data_object& addo) { - addo.fee_pool += deferred_fee; + fee_asset_dyn_data = &deferred_paid_fee.get_asset()(*this).dynamic_asset_data_id(*this); + modify( *fee_asset_dyn_data, [&deferred_fee](asset_dynamic_data_object& addo) { + addo.fee_pool += std::move(deferred_fee); }); } @@ -333,7 +355,7 @@ bool maybe_cull_small_order( database& db, const limit_order_object& order ) */ if( order.amount_to_receive().amount == 0 ) { - if( order.deferred_fee > 0 && db.head_block_time() <= HARDFORK_CORE_604_TIME ) + if( order.deferred_fee.get_amount() > 0 && db.head_block_time() <= HARDFORK_CORE_604_TIME ) { db.cancel_limit_order( order, true, true ); } @@ -569,7 +591,7 @@ int database::match( const limit_order_object& usd, const limit_order_object& co { FC_ASSERT( usd.sell_price.quote.asset_id == core.sell_price.base.asset_id ); FC_ASSERT( usd.sell_price.base.asset_id == core.sell_price.quote.asset_id ); - FC_ASSERT( usd.for_sale > 0 && core.for_sale > 0 ); + FC_ASSERT( usd.for_sale.get_amount() > 0 && core.for_sale.get_amount() > 0 ); auto usd_for_sale = usd.amount_for_sale(); auto core_for_sale = core.amount_for_sale(); @@ -626,8 +648,12 @@ int database::match( const limit_order_object& usd, const limit_order_object& co core_pays == core.amount_for_sale() ); int result = 0; - result |= fill_limit_order( usd, usd_pays, usd_receives, cull_taker, match_price, false ); // the first param is taker - result |= fill_limit_order( core, core_pays, core_receives, true, match_price, true ) << 1; // the second param is maker + stored_value transport; + modify( core, [&transport,&core_pays] ( limit_order_object& loo ) { + transport = loo.for_sale.split( core_pays.amount ); + }); + result |= fill_limit_order( usd, usd_pays, std::move(transport), cull_taker, match_price, false, false ); // the first param is taker + result |= fill_limit_order( core, core_pays, std::move(transport), true, match_price, true, true ) << 1; // the second param is maker FC_ASSERT( result != 0 ); return result; } @@ -638,7 +664,7 @@ int database::match( const limit_order_object& bid, const call_order_object& ask { FC_ASSERT( bid.sell_asset_id() == ask.debt_type() ); FC_ASSERT( bid.receive_asset_id() == ask.collateral_type() ); - FC_ASSERT( bid.for_sale > 0 && ask.debt > 0 && ask.collateral > 0 ); + FC_ASSERT( bid.for_sale.get_amount() > 0 && ask.debt.get_amount() > 0 && ask.collateral.get_amount() > 0 ); bool cull_taker = false; @@ -673,8 +699,12 @@ int database::match( const limit_order_object& bid, const call_order_object& ask order_pays = call_receives; int result = 0; - result |= fill_limit_order( bid, order_pays, order_receives, cull_taker, match_price, false ); // the limit order is taker - result |= fill_call_order( ask, call_pays, call_receives, match_price, true ) << 1; // the call order is maker + stored_value transport; + modify( ask, [&transport,&call_pays] ( call_order_object& coo ) { + transport = coo.collateral.split( call_pays.amount ); + }); + result |= fill_limit_order( bid, order_pays, std::move(transport), cull_taker, match_price, false, false ); // the limit order is taker + result |= fill_call_order( ask, call_pays, std::move(transport), match_price, true, true ) << 1; // the call order is maker // result can be 0 when call order has target_collateral_ratio option set. return result; @@ -687,13 +717,13 @@ asset database::match( const call_order_object& call, asset max_settlement, const price& fill_price ) { try { - FC_ASSERT(call.get_debt().asset_id == settle.balance.asset_id ); - FC_ASSERT(call.debt > 0 && call.collateral > 0 && settle.balance.amount > 0); + FC_ASSERT(call.get_debt().asset_id == settle.balance.get_asset() ); + FC_ASSERT(call.debt.get_amount() > 0 && call.collateral.get_amount() > 0 && settle.balance.get_amount() > 0); auto maint_time = get_dynamic_global_properties().next_maintenance_time; bool before_core_hardfork_342 = ( maint_time <= HARDFORK_CORE_342_TIME ); // better rounding - auto settle_for_sale = std::min(settle.balance, max_settlement); + auto settle_for_sale = std::min(settle.balance.get_value(), max_settlement); auto call_debt = call.get_debt(); asset call_receives = std::min(settle_for_sale, call_debt); @@ -712,13 +742,13 @@ asset database::match( const call_order_object& call, } else { - if( call_receives == settle.balance ) // the settle order is smaller + if( call_receives.amount == settle.balance.get_amount() ) // the settle order is smaller { cancel_settle_order( settle ); } // else do nothing: neither order will be completely filled, perhaps due to max_settlement too small - return asset( 0, settle.balance.asset_id ); + return asset( 0, settle.balance.get_asset() ); } } @@ -738,7 +768,7 @@ asset database::match( const call_order_object& call, // be here, we should have: call_pays <= call_collateral - if( call_receives == settle.balance ) // the settle order will be completely filled, assuming we need to cull it + if( call_receives.amount == settle.balance.get_amount() ) // the settle order will be completely filled, assuming we need to cull it cull_settle_order = true; // else do nothing, since we can't cull the settle order @@ -747,7 +777,7 @@ asset database::match( const call_order_object& call, // rounded up call_receives won't be greater than the // old call_receives. - if( call_receives == settle.balance ) // the settle order will be completely filled, no need to cull + if( call_receives.amount == settle.balance.get_amount() ) // the settle order will be completely filled, no need to cull cull_settle_order = false; // else do nothing, since we still need to cull the settle order or still can't cull the settle order } @@ -755,7 +785,6 @@ asset database::match( const call_order_object& call, } asset settle_pays = call_receives; - asset settle_receives = call_pays; /** * If the least collateralized call position lacks sufficient @@ -773,8 +802,12 @@ asset database::match( const call_order_object& call, } // else do nothing, since black swan event won't happen, and the assertion is no longer true - fill_call_order( call, call_pays, call_receives, fill_price, true ); // call order is maker - fill_settle_order( settle, settle_pays, settle_receives, fill_price, false ); // force settlement order is taker + stored_value transport; + modify( settle, [&transport,&settle_pays] ( force_settlement_object& fso ) { + transport = fso.balance.split( settle_pays.amount ); + }); + fill_call_order( call, call_pays, std::move(transport), fill_price, false, true ); // call order is maker + fill_settle_order( settle, settle_pays, std::move(transport), fill_price ); // force settlement order is always taker if( cull_settle_order ) cancel_settle_order( settle ); @@ -782,9 +815,11 @@ asset database::match( const call_order_object& call, return call_receives; } FC_CAPTURE_AND_RETHROW( (call)(settle)(match_price)(max_settlement) ) } -bool database::fill_limit_order( const limit_order_object& order, const asset& pays, const asset& receives, bool cull_if_small, - const price& fill_price, const bool is_maker ) +bool database::fill_limit_order( const limit_order_object& order, const asset& pays, stored_value&& transport, + bool cull_if_small, const price& fill_price, bool already_paid, const bool is_maker ) { try { + const auto receives = transport.get_value(); + cull_if_small |= (head_block_time() < HARDFORK_555_TIME); FC_ASSERT( order.amount_for_sale().asset_id == pays.asset_id ); @@ -793,69 +828,83 @@ bool database::fill_limit_order( const limit_order_object& order, const asset& p const account_object& seller = order.seller(*this); const asset_object& recv_asset = receives.asset_id(*this); - auto issuer_fees = pay_market_fees(&seller, recv_asset, receives); + auto issuer_fees = pay_market_fees( &seller, recv_asset, std::move(transport) ); - pay_order( seller, receives - issuer_fees, pays ); - - assert( pays.asset_id != receives.asset_id ); push_applied_operation( fill_order_operation( order.id, order.seller, pays, receives, issuer_fees, fill_price, is_maker ) ); + pay_order( seller, std::move(transport), pays ); + + stored_value deferred_fee; + stored_value deferred_paid_fee; + modify( order, [&pays,&transport,&deferred_fee,&deferred_paid_fee,already_paid] ( limit_order_object& loo ) { + deferred_fee = std::move(loo.deferred_fee); + deferred_paid_fee = std::move(loo.deferred_paid_fee); + if( !already_paid ) + transport = loo.for_sale.split( pays.amount ); + }); // conditional because cheap integer comparison may allow us to avoid two expensive modify() and object lookups - if( order.deferred_fee > 0 ) + if( deferred_fee.get_amount() > 0 ) { - modify( seller.statistics(*this), [&]( account_statistics_object& statistics ) + modify( seller.statistics(*this), [&deferred_fee,this]( account_statistics_object& statistics ) { - statistics.pay_fee( order.deferred_fee, get_global_properties().parameters.cashback_vesting_threshold ); + statistics.pay_fee( std::move(deferred_fee), get_global_properties().parameters.cashback_vesting_threshold ); } ); } - if( order.deferred_paid_fee.amount > 0 ) // implies head_block_time() > HARDFORK_CORE_604_TIME + if( deferred_paid_fee.get_amount() > 0 ) // implies head_block_time() > HARDFORK_CORE_604_TIME { - const auto& fee_asset_dyn_data = order.deferred_paid_fee.asset_id(*this).dynamic_asset_data_id(*this); - modify( fee_asset_dyn_data, [&](asset_dynamic_data_object& addo) { - addo.accumulated_fees += order.deferred_paid_fee.amount; + const auto& fee_asset_dyn_data = order.deferred_paid_fee.get_asset()(*this).dynamic_asset_data_id(*this); + modify( fee_asset_dyn_data, [&deferred_paid_fee](asset_dynamic_data_object& addo) { + addo.accumulated_fees += std::move(deferred_paid_fee); }); } - if( pays == order.amount_for_sale() ) + if( order.for_sale.get_amount() == 0 ) { remove( order ); return true; } - else - { - modify( order, [&]( limit_order_object& b ) { - b.for_sale -= pays.amount; - b.deferred_fee = 0; - b.deferred_paid_fee.amount = 0; - }); - if( cull_if_small ) - return maybe_cull_small_order( *this, order ); - return false; - } -} FC_CAPTURE_AND_RETHROW( (order)(pays)(receives) ) } + + if( cull_if_small ) + return maybe_cull_small_order( *this, order ); + + return false; +} FC_CAPTURE_AND_RETHROW( (order)(pays)(transport) ) } -bool database::fill_call_order( const call_order_object& order, const asset& pays, const asset& receives, - const price& fill_price, const bool is_maker ) +bool database::fill_call_order( const call_order_object& order, const asset& pays, stored_value&& transport, + const price& fill_price, bool already_paid, const bool is_maker ) { try { + const auto receives = transport.get_value(); + FC_ASSERT( order.debt_type() == receives.asset_id ); FC_ASSERT( order.collateral_type() == pays.asset_id ); - FC_ASSERT( order.collateral >= pays.amount ); + FC_ASSERT( order.collateral.get_amount() >= pays.amount ); // TODO pass in mia and bitasset_data for better performance const asset_object& mia = receives.asset_id(*this); FC_ASSERT( mia.is_market_issued() ); - optional collateral_freed; - modify( order, [&]( call_order_object& o ){ - o.debt -= receives.amount; - o.collateral -= pays.amount; - if( o.debt == 0 ) - { - collateral_freed = o.get_collateral(); - o.collateral = 0; - } + stored_value supply_to_burn = std::move(transport); + // update current supply + const asset_dynamic_data_object& mia_ddo = mia.dynamic_asset_data_id(*this); + modify( mia_ddo, [&supply_to_burn]( asset_dynamic_data_object& ao ){ + ao.current_supply.burn( std::move(supply_to_burn) ); + }); + + stored_value debt_to_burn; + const auto& bdo = (*mia.bitasset_data_id)(*this); + modify( bdo, [&receives,&debt_to_burn] ( asset_bitasset_data_object& _bdo ) { + debt_to_burn = _bdo.total_debt.split( receives.amount ); + }); + + stored_value collateral_freed( order.collateral_type() ); + modify( order, [&bdo,&pays,&debt_to_burn,&transport,&collateral_freed,already_paid,this]( call_order_object& o ){ + o.debt.burn( std::move(debt_to_burn) ); + if( !already_paid ) + transport = o.collateral.split( pays.amount ); + if( o.debt.get_amount() == 0 ) + collateral_freed = std::move( o.collateral ); else { auto maint_time = get_dynamic_global_properties().next_maintenance_time; @@ -864,67 +913,48 @@ bool database::fill_call_order( const call_order_object& order, const asset& pay if( maint_time <= HARDFORK_CORE_1270_TIME && maint_time > HARDFORK_CORE_343_TIME ) { o.call_price = price::call_price( o.get_debt(), o.get_collateral(), - mia.bitasset_data(*this).current_feed.maintenance_collateral_ratio ); + bdo.current_feed.maintenance_collateral_ratio ); } } }); - // update current supply - const asset_dynamic_data_object& mia_ddo = mia.dynamic_asset_data_id(*this); - - modify( mia_ddo, [&receives]( asset_dynamic_data_object& ao ){ - ao.current_supply -= receives.amount; - }); - - // Adjust balance - if( collateral_freed.valid() ) - adjust_balance( order.borrower, *collateral_freed ); - // Update account statistics. We know that order.collateral_type() == pays.asset_id if( pays.asset_id == asset_id_type() ) { modify( get_account_stats_by_owner(order.borrower), [&collateral_freed,&pays]( account_statistics_object& b ){ b.total_core_in_orders -= pays.amount; - if( collateral_freed.valid() ) - b.total_core_in_orders -= collateral_freed->amount; + b.total_core_in_orders -= collateral_freed.get_amount(); }); } + // Adjust balance + add_balance( order.borrower, std::move(collateral_freed) ); + push_applied_operation( fill_order_operation( order.id, order.borrower, pays, receives, asset(0, pays.asset_id), fill_price, is_maker ) ); - if( collateral_freed.valid() ) + bool filled = order.collateral.get_amount() == 0; + if( filled ) remove( order ); - return collateral_freed.valid(); -} FC_CAPTURE_AND_RETHROW( (order)(pays)(receives) ) } + return filled; +} FC_CAPTURE_AND_RETHROW( (order)(pays)(transport) ) } -bool database::fill_settle_order( const force_settlement_object& settle, const asset& pays, const asset& receives, - const price& fill_price, const bool is_maker ) +void database::fill_settle_order( const force_settlement_object& settle, const asset& paid, + stored_value&& receives, const price& fill_price ) { try { - bool filled = false; + const auto received = receives.get_value(); - auto issuer_fees = pay_market_fees( nullptr, get(receives.asset_id), receives); + auto issuer_fees = pay_market_fees( nullptr, get(receives.get_asset()), std::move(receives) ); - if( pays < settle.balance ) - { - modify(settle, [&pays](force_settlement_object& s) { - s.balance -= pays; - }); - filled = false; - } else { - filled = true; - } - adjust_balance(settle.owner, receives - issuer_fees); + add_balance( settle.owner, std::move(receives) ); - assert( pays.asset_id != receives.asset_id ); - push_applied_operation( fill_order_operation( settle.id, settle.owner, pays, receives, issuer_fees, fill_price, is_maker ) ); + assert( paid.asset_id != receives.asset_id ); + push_applied_operation( fill_order_operation( settle.id, settle.owner, paid, received, issuer_fees, fill_price, false ) ); - if (filled) + if( settle.balance.get_amount() == 0 ) remove(settle); - - return filled; -} FC_CAPTURE_AND_RETHROW( (settle)(pays)(receives) ) } +} FC_CAPTURE_AND_RETHROW( (settle)(paid)(receives) ) } /** * Starting with the least collateralized orders, fill them if their @@ -1116,8 +1146,12 @@ bool database::check_call_orders( const asset_object& mia, bool enable_black_swa if( filled_call && before_core_hardfork_343 ) ++call_price_itr; + stored_value transport; + modify( limit_order, [&transport,&order_pays] ( limit_order_object& loo ) { + transport = loo.for_sale.split(order_pays.amount); + }); // when for_new_limit_order is true, the call order is maker, otherwise the call order is taker - fill_call_order( call_order, call_pays, call_receives, match_price, for_new_limit_order ); + fill_call_order( call_order, call_pays, std::move(transport), match_price, false, for_new_limit_order ); if( !before_core_hardfork_1270 ) call_collateral_itr = call_collateral_index.lower_bound( call_min ); else if( !before_core_hardfork_343 ) @@ -1125,7 +1159,7 @@ bool database::check_call_orders( const asset_object& mia, bool enable_black_swa auto next_limit_itr = std::next( limit_itr ); // when for_new_limit_order is true, the limit order is taker, otherwise the limit order is maker - bool really_filled = fill_limit_order( limit_order, order_pays, order_receives, true, match_price, !for_new_limit_order ); + bool really_filled = fill_limit_order( limit_order, order_pays, std::move(transport), true, match_price, true, !for_new_limit_order ); if( really_filled || ( filled_limit && before_core_hardfork_453 ) ) limit_itr = next_limit_itr; @@ -1134,45 +1168,38 @@ bool database::check_call_orders( const asset_object& mia, bool enable_black_swa return margin_called; } FC_CAPTURE_AND_RETHROW() } -void database::pay_order( const account_object& receiver, const asset& receives, const asset& pays ) +void database::pay_order( const account_object& receiver, stored_value&& receives, const asset& pays ) { - const auto& balances = receiver.statistics(*this); - modify( balances, [&]( account_statistics_object& b ){ - if( pays.asset_id == asset_id_type() ) - { - b.total_core_in_orders -= pays.amount; - } - }); - adjust_balance(receiver.get_id(), receives); + if( receives.get_asset() == asset_id_type() ) + modify( receiver.statistics(*this), [&pays]( account_statistics_object& b ){ + b.total_core_in_orders -= pays.amount; + }); + add_balance( receiver.get_id(), std::move(receives) ); } -asset database::calculate_market_fee( const asset_object& trade_asset, const asset& trade_amount ) +share_type database::calculate_market_fee( const asset_object& trade_asset, const share_type trade_amount ) { - assert( trade_asset.id == trade_amount.asset_id ); - if( !trade_asset.charges_market_fees() ) - return trade_asset.amount(0); + return 0; if( trade_asset.options.market_fee_percent == 0 ) - return trade_asset.amount(0); + return 0; - auto value = detail::calculate_percent(trade_amount.amount, trade_asset.options.market_fee_percent); - asset percent_fee = trade_asset.amount(value); + auto percent_fee = detail::calculate_percent(trade_amount, trade_asset.options.market_fee_percent); - if( percent_fee.amount > trade_asset.options.max_market_fee ) - percent_fee.amount = trade_asset.options.max_market_fee; + if( percent_fee > trade_asset.options.max_market_fee ) + percent_fee = trade_asset.options.max_market_fee; return percent_fee; } -asset database::pay_market_fees(const account_object* seller, const asset_object& recv_asset, const asset& receives ) +asset database::pay_market_fees(const account_object* seller, const asset_object& recv_asset, stored_value&& receives ) { - const auto issuer_fees = calculate_market_fee( recv_asset, receives ); - FC_ASSERT( issuer_fees <= receives, "Market fee shouldn't be greater than receives"); + stored_value issuer_fees = receives.split( calculate_market_fee( recv_asset, receives.get_amount() ) ); + const asset result = issuer_fees.get_value(); //Don't dirty undo state if not actually collecting any fees - if ( issuer_fees.amount > 0 ) + if ( issuer_fees.get_amount() > 0 ) { // calculate and pay rewards - asset reward = recv_asset.amount(0); auto is_rewards_allowed = [&recv_asset, seller]() { if (seller == nullptr) @@ -1187,39 +1214,34 @@ asset database::pay_market_fees(const account_object* seller, const asset_object const auto reward_percent = recv_asset.options.extensions.value.reward_percent; if ( reward_percent && *reward_percent ) { - const auto reward_value = detail::calculate_percent(issuer_fees.amount, *reward_percent); + const auto reward_value = detail::calculate_percent( issuer_fees.get_amount(), *reward_percent ); if ( reward_value > 0 && is_authorized_asset(*this, seller->registrar(*this), recv_asset) ) { - reward = recv_asset.amount(reward_value); - FC_ASSERT( reward < issuer_fees, "Market reward should be less than issuer fees"); // cut referrer percent from reward - auto registrar_reward = reward; + auto registrar_reward = issuer_fees.split(reward_value); if( seller->referrer != seller->registrar ) { - const auto referrer_rewards_value = detail::calculate_percent( reward.amount, + const auto referrer_rewards_value = detail::calculate_percent( registrar_reward.get_amount(), seller->referrer_rewards_percentage ); if ( referrer_rewards_value > 0 && is_authorized_asset(*this, seller->referrer(*this), recv_asset) ) { - FC_ASSERT ( referrer_rewards_value <= reward.amount.value, - "Referrer reward shouldn't be greater than total reward" ); - const asset referrer_reward = recv_asset.amount(referrer_rewards_value); - registrar_reward -= referrer_reward; - deposit_market_fee_vesting_balance(seller->referrer, referrer_reward); + auto referrer_reward = registrar_reward.split( referrer_rewards_value ); + deposit_market_fee_vesting_balance(seller->referrer, std::move(referrer_reward) ); } } - deposit_market_fee_vesting_balance(seller->registrar, registrar_reward); + deposit_market_fee_vesting_balance( seller->registrar, std::move(registrar_reward) ); } } } const auto& recv_dyn_data = recv_asset.dynamic_asset_data_id(*this); - modify( recv_dyn_data, [&issuer_fees, &reward]( asset_dynamic_data_object& obj ){ - obj.accumulated_fees += issuer_fees.amount - reward.amount; + modify( recv_dyn_data, [&issuer_fees]( asset_dynamic_data_object& obj ){ + obj.accumulated_fees += std::move(issuer_fees); }); } - return issuer_fees; + return result; } } } diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index 424d1f9ea5..7c828cf4b3 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -408,21 +408,21 @@ namespace graphene { namespace chain { /** * @return true if the order was completely filled and thus freed. */ - bool fill_limit_order( const limit_order_object& order, const asset& pays, const asset& receives, bool cull_if_small, - const price& fill_price, const bool is_maker ); - bool fill_call_order( const call_order_object& order, const asset& pays, const asset& receives, - const price& fill_price, const bool is_maker ); - bool fill_settle_order( const force_settlement_object& settle, const asset& pays, const asset& receives, - const price& fill_price, const bool is_maker ); + bool fill_limit_order( const limit_order_object& order, const asset& pays, stored_value&& transport, + bool cull_if_small, const price& fill_price, bool already_paid, const bool is_maker ); + bool fill_call_order( const call_order_object& order, const asset& pays, stored_value&& transport, + const price& fill_price, bool already_paid, const bool is_maker ); + void fill_settle_order( const force_settlement_object& settle, const asset& pays, + stored_value&& receives, const price& fill_price ); bool check_call_orders( const asset_object& mia, bool enable_black_swan = true, bool for_new_limit_order = false, const asset_bitasset_data_object* bitasset_ptr = nullptr ); // helpers to fill_order - void pay_order( const account_object& receiver, const asset& receives, const asset& pays ); + void pay_order( const account_object& receiver, stored_value&& receives, const asset& pays ); - asset calculate_market_fee(const asset_object& recv_asset, const asset& trade_amount); - asset pay_market_fees(const account_object* seller, const asset_object& recv_asset, const asset& receives ); + share_type calculate_market_fee(const asset_object& recv_asset, const share_type trade_amount); + asset pay_market_fees(const account_object* seller, const asset_object& recv_asset, stored_value&& receives ); ///@} diff --git a/libraries/chain/include/graphene/chain/market_object.hpp b/libraries/chain/include/graphene/chain/market_object.hpp index 0fa44ba1f5..0cdfdd0343 100644 --- a/libraries/chain/include/graphene/chain/market_object.hpp +++ b/libraries/chain/include/graphene/chain/market_object.hpp @@ -29,6 +29,8 @@ #include +#include "stored_value.hpp" + namespace graphene { namespace chain { using namespace graphene::db; @@ -41,7 +43,7 @@ using namespace graphene::db; * * 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 +class limit_order_master : public abstract_object { public: static constexpr uint8_t space_id = protocol_ids; @@ -49,10 +51,7 @@ class limit_order_object : public abstract_object 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; ///< fee converted to CORE - asset deferred_paid_fee; ///< originally paid fee pair get_market()const { @@ -61,12 +60,25 @@ class limit_order_object : public abstract_object 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; } asset_id_type sell_asset_id()const { return sell_price.base.asset_id; } asset_id_type receive_asset_id()const { return sell_price.quote.asset_id; } }; +class limit_order_object : public limit_order_master +{ + public: + stored_value for_sale; ///< asset id is sell_price.base.asset_id + stored_value deferred_fee; ///< fee converted to CORE + stored_value deferred_paid_fee; ///< originally paid fee + + asset amount_for_sale()const { return for_sale.get_value(); } + asset amount_to_receive()const { return amount_for_sale() * sell_price; } + + protected: + virtual unique_ptr backup()const; + virtual void restore( graphene::db::object& obj ); +}; + struct by_price; struct by_expiration; struct by_account; @@ -76,21 +88,21 @@ typedef multi_index_container< ordered_unique< tag, member< object, object_id_type, &object::id > >, ordered_unique< tag, composite_key< limit_order_object, - member< limit_order_object, time_point_sec, &limit_order_object::expiration>, + member< limit_order_master, time_point_sec, &limit_order_master::expiration>, member< object, object_id_type, &object::id> > >, ordered_unique< tag, composite_key< limit_order_object, - member< limit_order_object, price, &limit_order_object::sell_price>, + member< limit_order_master, price, &limit_order_master::sell_price>, member< object, object_id_type, &object::id> >, composite_key_compare< std::greater, std::less > >, ordered_unique< tag, composite_key< limit_order_object, - member, - member, + member, + member, member >, composite_key_compare, std::greater, std::less> @@ -113,13 +125,10 @@ class call_order_master : public abstract_object static constexpr uint8_t space_id = protocol_ids; static constexpr uint8_t type_id = call_order_object_type; - 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; } asset_id_type collateral_type()const { return call_price.base.asset_id; } account_id_type borrower; - share_type debt; ///< call_price.quote.asset_id, access via get_debt price call_price; ///< Collateral / Debt optional target_collateral_ratio; ///< maximum CR to maintain when selling collateral on margin call @@ -135,8 +144,10 @@ class call_order_master : public abstract_object class call_order_object : public call_order_master { public: + stored_debt debt; stored_value collateral; + asset get_debt()const { return debt.get_value(); } asset get_collateral()const { return collateral.get_value(); } price collateralization()const { return get_collateral() / get_debt(); } @@ -166,18 +177,26 @@ class call_order_object : public call_order_master * 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 +class force_settlement_master : public abstract_object { public: static constexpr uint8_t space_id = protocol_ids; static constexpr uint8_t type_id = force_settlement_object_type; account_id_type owner; - asset balance; time_point_sec settlement_date; +}; + +class force_settlement_object : public force_settlement_master +{ + public: + stored_value balance; + + asset_id_type settlement_asset_id()const { return balance.get_asset(); } - asset_id_type settlement_asset_id()const - { return balance.asset_id; } + protected: + virtual unique_ptr backup()const; + virtual void restore( graphene::db::object& obj ); }; /** @@ -248,14 +267,14 @@ typedef multi_index_container< ordered_unique< tag, member< object, object_id_type, &object::id > >, ordered_unique< tag, composite_key< force_settlement_object, - member, + member, member< object, object_id_type, &object::id > > >, ordered_unique< tag, composite_key< force_settlement_object, const_mem_fun, - member, + member, member< object, object_id_type, &object::id > > > @@ -300,9 +319,11 @@ FC_REFLECT_TYPENAME( graphene::chain::call_order_object ) FC_REFLECT_TYPENAME( graphene::chain::force_settlement_object ) FC_REFLECT_TYPENAME( graphene::chain::collateral_bid_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::limit_order_master ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::limit_order_object ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::call_order_master ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::call_order_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::force_settlement_master ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::force_settlement_object ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::collateral_bid_master ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::collateral_bid_object ) diff --git a/libraries/chain/market_object.cpp b/libraries/chain/market_object.cpp index 4a35df4573..f9d7aef788 100644 --- a/libraries/chain/market_object.cpp +++ b/libraries/chain/market_object.cpp @@ -31,6 +31,36 @@ namespace graphene { namespace chain { +class limit_order_backup : public limit_order_master +{ + private: + limit_order_backup( const limit_order_object& original ) + : limit_order_master( original ) + { + for_sale = original.for_sale.get_amount(); + deferred_fee = original.deferred_fee.get_amount(); + deferred_paid_fee = original.deferred_paid_fee.get_value(); + } + share_type for_sale; + share_type deferred_fee; + asset deferred_paid_fee; + friend class limit_order_object; +}; + +unique_ptr limit_order_object::backup()const +{ + return std::make_unique( *this ); +} + +void limit_order_object::restore( object& obj ) +{ + const auto& backup = static_cast(obj); + for_sale.restore( asset( backup.for_sale, backup.sell_price.base.asset_id ) ); + deferred_fee.restore( asset( backup.deferred_fee ) ); + deferred_paid_fee.restore( backup.deferred_paid_fee ); + static_cast(*this) = std::move( backup ); +} + /* target_CR = max( target_CR, MCR ) @@ -309,8 +339,10 @@ class call_order_backup : public call_order_master call_order_backup( const call_order_object& original ) : call_order_master( original ) { + debt = original.debt.get_amount(); collateral = original.collateral.get_amount(); } + asset debt; asset collateral; friend class call_order_object; }; @@ -323,10 +355,35 @@ unique_ptr call_order_object::backup()const void call_order_object::restore( object& obj ) { const auto& backup = static_cast(obj); + debt.restore( backup.debt ) ); collateral.restore( backup.collateral ) ); static_cast(*this) = std::move( backup ); } +class force_settlement_backup : public force_settlement_master +{ + private: + force_settlement_backup( const force_settlement_object& original ) + : force_settlement_master( original ) + { + balance = original.balance.get_amount(); + } + asset balance; + friend class force_settlement_object; +}; + +unique_ptr force_settlement_object::backup()const +{ + return std::make_unique( *this ); +} + +void force_settlement_object::restore( object& obj ) +{ + const auto& backup = static_cast(obj); + balance.restore( backup.balance ) ); + static_cast(*this) = std::move( backup ); +} + class collateral_bid_backup : public collateral_bid_master { private: @@ -353,19 +410,27 @@ void collateral_bid_object::restore( object& obj ) } } // graphene::chain +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::limit_order_master, + (graphene::db::object), + (expiration)(seller)(sell_price) + ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::limit_order_object, (graphene::db::object), - (expiration)(seller)(for_sale)(sell_price)(deferred_fee)(deferred_paid_fee) + (for_sale)(deferred_fee)(deferred_paid_fee) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::call_order_master, (graphene::db::object), - (borrower)(debt)(call_price)(target_collateral_ratio) ) + (borrower)(call_price)(target_collateral_ratio) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::call_order_object, (graphene::chain::call_order_object), - (collateral) ) + (debt)(collateral) ) -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::force_settlement_object, +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::force_settlement_master, (graphene::db::object), - (owner)(balance)(settlement_date) + (owner)(settlement_date) + ) +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::force_settlement_object, + (graphene::chain::force_settlement_master), + (balance) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::collateral_bid_master, (graphene::db::object), @@ -374,8 +439,11 @@ FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::collateral_bid_object, (graphene::chain::collateral_bid_master), (collateral_offered) ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::limit_order_master ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::limit_order_object ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::call_order_master ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::call_order_object ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::force_settlement_master ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::force_settlement_object ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::collateral_bid_master ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::collateral_bid_object ) From 10970218112acd181abaa1db9cdd67c2aac4a5a8 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Mon, 2 Dec 2019 11:46:21 +0100 Subject: [PATCH 07/59] Intermediate --- libraries/chain/balance_evaluator.cpp | 20 +++--- libraries/chain/db_init.cpp | 16 +++-- libraries/chain/db_update.cpp | 32 +++++---- libraries/chain/evaluator.cpp | 54 ++++++-------- .../include/graphene/chain/balance_object.hpp | 26 ++++--- .../include/graphene/chain/evaluator.hpp | 31 ++++---- .../include/graphene/chain/htlc_object.hpp | 25 +++++-- libraries/chain/small_objects.cpp | 71 +++++++++++++++++-- 8 files changed, 174 insertions(+), 101 deletions(-) diff --git a/libraries/chain/balance_evaluator.cpp b/libraries/chain/balance_evaluator.cpp index 7c8b8b3ff1..030c4065c2 100644 --- a/libraries/chain/balance_evaluator.cpp +++ b/libraries/chain/balance_evaluator.cpp @@ -49,7 +49,7 @@ void_result balance_claim_evaluator::do_evaluate(const balance_claim_operation& { GRAPHENE_ASSERT( balance->vesting_policy->is_withdraw_allowed( - { balance->balance, + { balance->balance.get_value(), d.head_block_time(), op.total_claimed } ), balance_claim_invalid_claim_amount, @@ -64,7 +64,7 @@ void_result balance_claim_evaluator::do_evaluate(const balance_claim_operation& return {}; } - FC_ASSERT(op.total_claimed == balance->balance); + FC_ASSERT( op.total_claimed.amount == balance->balance.get_amount() ); return {}; } @@ -76,16 +76,16 @@ void_result balance_claim_evaluator::do_apply(const balance_claim_operation& op) { database& d = db(); - if( balance->is_vesting_balance() && op.total_claimed < balance->balance ) - d.modify(*balance, [&](balance_object& b) { - b.vesting_policy->on_withdraw({b.balance, d.head_block_time(), op.total_claimed}); - b.balance -= op.total_claimed; - b.last_claim_date = d.head_block_time(); - }); - else + stored_value claim; + d.modify(*balance, [&claim,&d,&op](balance_object& b) { + b.vesting_policy->on_withdraw({b.balance.get_value(), d.head_block_time(), op.total_claimed}); + claim = b.balance.split( op.total_claimed.amount ); + b.last_claim_date = d.head_block_time(); + }); + if( balance->balance.get_amount() == 0 ) d.remove(*balance); - d.adjust_balance(op.deposit_to_account, op.total_claimed); + d.add_balance( op.deposit_to_account, std::move(claim) ); return {}; } } } // namespace graphene::chain diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 986fa3f666..a2e5bf032d 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -506,8 +506,12 @@ void database::init_genesis(const genesis_state_type& genesis_state) for( const auto& handout : genesis_state.initial_balances ) { const auto asset_id = get_asset_id(handout.asset_symbol); - create([&handout,total_allocation,asset_id](balance_object& b) { - b.balance = asset(handout.amount, asset_id); + stored_value balance; + modify( asset_id(*this).dynamic_asset_data_id(*this), [&balance,&handout] ( asset_dynamic_data_object& add ) { + balance = add.current_supply.issue(handout.amount); + }); + create([&handout,&balance](balance_object& b) { + b.balance = std::move(balance); b.owner = handout.owner; }); @@ -518,9 +522,13 @@ void database::init_genesis(const genesis_state_type& genesis_state) for( const genesis_state_type::initial_vesting_balance_type& vest : genesis_state.initial_vesting_balances ) { const auto asset_id = get_asset_id(vest.asset_symbol); - create([&](balance_object& b) { + stored_value balance; + modify( asset_id(*this).dynamic_asset_data_id(*this), [&balance,&vest] ( asset_dynamic_data_object& add ) { + balance = add.current_supply.issue(vest.amount); + }); + create([&vest,&balance](balance_object& b) { b.owner = vest.owner; - b.balance = asset(vest.amount, asset_id); + b.balance = std::move(balance); linear_vesting_policy policy; policy.begin_timestamp = vest.begin_timestamp; diff --git a/libraries/chain/db_update.cpp b/libraries/chain/db_update.cpp index f98f09de6b..70ccf06144 100644 --- a/libraries/chain/db_update.cpp +++ b/libraries/chain/db_update.cpp @@ -84,18 +84,17 @@ void database::update_signing_witness(const witness_object& signing_witness, con { const global_property_object& gpo = get_global_properties(); const dynamic_global_property_object& dpo = get_dynamic_global_properties(); - uint64_t new_block_aslot = dpo.current_aslot + get_slot_at_time( new_block.timestamp ); + const uint64_t new_block_aslot = dpo.current_aslot + get_slot_at_time( new_block.timestamp ); - share_type witness_pay = std::min( gpo.parameters.witness_pay_per_block, dpo.witness_budget ); - - modify( dpo, [&]( dynamic_global_property_object& _dpo ) + stored_value witness_pay; + modify( dpo, [&witness_pay,&gpo]( dynamic_global_property_object& _dpo ) { - _dpo.witness_budget -= witness_pay; + witness_pay = _dpo.witness_budget.split( std::min( gpo.parameters.witness_pay_per_block, _dpo.witness_budget.get_amount() ) ); } ); - deposit_witness_pay( signing_witness, witness_pay ); + deposit_witness_pay( signing_witness, std::move(witness_pay) ); - modify( signing_witness, [&]( witness_object& _wit ) + modify( signing_witness, [&new_block,new_block_aslot]( witness_object& _wit ) { _wit.last_aslot = new_block_aslot; _wit.last_confirmed_block_num = new_block.block_num(); @@ -387,7 +386,7 @@ void database::clear_expired_orders() continue; } if( max_settlement_volume.asset_id != current_asset ) - max_settlement_volume = mia_object.amount(mia.max_force_settlement_volume(mia_object.dynamic_data(*this).current_supply)); + max_settlement_volume = mia_object.amount(mia.max_force_settlement_volume(mia_object.dynamic_data(*this).current_supply.get_amount())); // When current_asset_finished is true, this would be the 2nd time processing the same order. // In this case, we move to the next asset. if( mia.force_settled_volume >= max_settlement_volume.amount || current_asset_finished ) @@ -415,12 +414,12 @@ void database::clear_expired_orders() if( before_core_hardfork_342 ) { - auto& pays = order.balance; - auto receives = (order.balance * mia.current_feed.settlement_price); + auto pays = order.balance.get_value(); + auto receives = (pays * mia.current_feed.settlement_price); receives.amount = static_cast( fc::uint128_t(receives.amount.value) * (GRAPHENE_100_PERCENT - mia.options.force_settlement_offset_percent) / GRAPHENE_100_PERCENT ); - assert(receives <= order.balance * mia.current_feed.settlement_price); + assert(receives <= pays * mia.current_feed.settlement_price); settlement_price = pays / receives; } else if( settlement_price.base.asset_id != current_asset ) // only calculate once per asset @@ -437,7 +436,7 @@ void database::clear_expired_orders() assert(itr != call_index.end() && itr->debt_type() == mia_object.get_id()); asset max_settlement = max_settlement_volume - settled; - if( order.balance.amount == 0 ) + if( order.balance.get_amount() == 0 ) { wlog( "0 settlement detected" ); cancel_settle_order( order ); @@ -590,12 +589,15 @@ void database::clear_expired_htlcs() && htlc_idx.begin()->conditions.time_lock.expiration <= head_block_time() ) { const htlc_object& obj = *htlc_idx.begin(); - const auto amount = asset(obj.transfer.amount, obj.transfer.asset_id); - adjust_balance( obj.transfer.from, amount ); + stored_value refund; + modify( obj, [&refund] ( htlc_object& htlc ) { + refund = std::move(htlc.transfer.amount); + }); // notify related parties - htlc_refund_operation vop( obj.id, obj.transfer.from, obj.transfer.to, amount, + htlc_refund_operation vop( obj.id, obj.transfer.from, obj.transfer.to, refund.get_value(), obj.conditions.hash_lock.preimage_hash, obj.conditions.hash_lock.preimage_size ); push_applied_operation( vop ); + add_balance( obj.transfer.from, std::move(refund) ); remove( obj ); } } diff --git a/libraries/chain/evaluator.cpp b/libraries/chain/evaluator.cpp index a793163fe5..0f90b73467 100644 --- a/libraries/chain/evaluator.cpp +++ b/libraries/chain/evaluator.cpp @@ -51,13 +51,13 @@ database& generic_evaluator::db()const { return trx_state->db(); } void generic_evaluator::prepare_fee(account_id_type account_id, asset fee) { const database& d = db(); - fee_from_account = fee; FC_ASSERT( fee.amount >= 0 ); fee_paying_account = &account_id(d); fee_paying_account_statistics = &fee_paying_account->statistics(d); fee_asset = &fee.asset_id(d); - fee_asset_dyn_data = &fee_asset->dynamic_asset_data_id(d); + if( fee_asset->get_id() != asset_id_type() ) + fee_asset_dyn_data = &fee_asset->dynamic_asset_data_id(d); FC_ASSERT( is_authorized_asset( d, *fee_paying_account, *fee_asset ), "Account ${acct} '${name}' attempted to pay fee by using asset ${a} '${sym}', " @@ -65,41 +65,38 @@ database& generic_evaluator::db()const { return trx_state->db(); } ( "acct", fee_paying_account->id)("name", fee_paying_account->name)("a", fee_asset->id) ("sym", fee_asset->symbol) ); - if( fee_from_account.asset_id == asset_id_type() ) - core_fee_paid = fee_from_account.amount; + fee_from_account = db().reduce_balance( account_id, fee ); + if( fee.asset_id == asset_id_type() ) + fee_from_pool = 0; else { - asset fee_from_pool = fee_from_account * fee_asset->options.core_exchange_rate; - FC_ASSERT( fee_from_pool.asset_id == asset_id_type() ); - core_fee_paid = fee_from_pool.amount; - FC_ASSERT( core_fee_paid <= fee_asset_dyn_data->fee_pool, "Fee pool balance of '${b}' is less than the ${r} required to convert ${c}", - ("r", db().to_pretty_string( fee_from_pool))("b",db().to_pretty_string(fee_asset_dyn_data->fee_pool))("c",db().to_pretty_string(fee)) ); + asset pool_fee = fee_from_account.get_value() * fee_asset->options.core_exchange_rate; + FC_ASSERT( pool_fee.asset_id == asset_id_type() ); + fee_from_pool = pool_fee.amount; + FC_ASSERT( fee_from_pool <= fee_asset_dyn_data->fee_pool.get_amount(), + "Fee pool balance of '${b}' is less than the ${r} required to convert ${c}", + ("r",db().to_pretty_string(pool_fee)) + ("b",db().to_pretty_string(fee_asset_dyn_data->fee_pool.get_value())) + ("c",db().to_pretty_string(fee)) ); } } void generic_evaluator::convert_fee() { - if( !trx_state->skip_fee ) { - if( fee_asset->get_id() != asset_id_type() ) - { - db().modify(*fee_asset_dyn_data, [this](asset_dynamic_data_object& d) { - d.accumulated_fees += fee_from_account.amount; - d.fee_pool -= core_fee_paid; - }); - } - } + if( !trx_state->skip_fee && fee_asset->get_id() != asset_id_type() ) + db().modify(*fee_asset_dyn_data, [this](asset_dynamic_data_object& d) { + d.accumulated_fees += std::move(fee_from_account); + core_fee_paid = d.fee_pool.split( fee_from_pool ); + }); } void generic_evaluator::pay_fee() { try { - if( !trx_state->skip_fee ) { - database& d = db(); - /// TODO: db().pay_fee( account_id, core_fee ); - d.modify(*fee_paying_account_statistics, [&](account_statistics_object& s) + if( !trx_state->skip_fee ) + db().modify(*fee_paying_account_statistics, [this](account_statistics_object& s) { - s.pay_fee( core_fee_paid, d.get_global_properties().parameters.cashback_vesting_threshold ); + s.pay_fee( std::move(core_fee_paid), db().get_global_properties().parameters.cashback_vesting_threshold ); }); - } } FC_CAPTURE_AND_RETHROW() } void generic_evaluator::pay_fba_fee( uint64_t fba_id ) @@ -111,9 +108,9 @@ database& generic_evaluator::db()const { return trx_state->db(); } generic_evaluator::pay_fee(); return; } - d.modify( fba, [&]( fba_accumulator_object& _fba ) + d.modify( fba, [this]( fba_accumulator_object& _fba ) { - _fba.accumulated_fba_fees += core_fee_paid; + _fba.accumulated_fba_fees += std::move(core_fee_paid); } ); } @@ -121,9 +118,4 @@ database& generic_evaluator::db()const { return trx_state->db(); } { return db().current_fee_schedule().calculate_fee( op ).amount; } - void generic_evaluator::db_adjust_balance(const account_id_type& fee_payer, asset fee_from_account) - { - db().adjust_balance(fee_payer, fee_from_account); - } - } } diff --git a/libraries/chain/include/graphene/chain/balance_object.hpp b/libraries/chain/include/graphene/chain/balance_object.hpp index 478f78be39..17b3896bb2 100644 --- a/libraries/chain/include/graphene/chain/balance_object.hpp +++ b/libraries/chain/include/graphene/chain/balance_object.hpp @@ -27,7 +27,7 @@ namespace graphene { namespace chain { - class balance_object : public abstract_object + class balance_master : public abstract_object { public: static constexpr uint8_t space_id = protocol_ids; @@ -35,17 +35,24 @@ namespace graphene { namespace chain { bool is_vesting_balance()const { return vesting_policy.valid(); } - asset available(fc::time_point_sec now)const - { - return is_vesting_balance()? vesting_policy->get_allowed_withdraw({balance, now, {}}) - : balance; - } address owner; - asset balance; optional vesting_policy; time_point_sec last_claim_date; - asset_id_type asset_type()const { return balance.asset_id; } + }; + + class balance_object : public balance_master + { + public: + asset available(fc::time_point_sec now)const + { + return is_vesting_balance()? vesting_policy->get_allowed_withdraw({balance.get_value(), now, {}}) + : balance.get_value(); + } + + stored_value balance; + + asset_id_type asset_type()const { return balance.get_asset(); } }; struct by_owner; @@ -59,7 +66,7 @@ namespace graphene { namespace chain { ordered_unique< tag, member< object, object_id_type, &object::id > >, ordered_non_unique< tag, composite_key< balance_object, - member, + member, const_mem_fun > > > @@ -75,4 +82,5 @@ MAP_OBJECT_ID_TO_TYPE(graphene::chain::balance_object) FC_REFLECT_TYPENAME( graphene::chain::balance_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::balance_master ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::balance_object ) diff --git a/libraries/chain/include/graphene/chain/evaluator.hpp b/libraries/chain/include/graphene/chain/evaluator.hpp index 8fb356916d..167a760328 100644 --- a/libraries/chain/include/graphene/chain/evaluator.hpp +++ b/libraries/chain/include/graphene/chain/evaluator.hpp @@ -26,6 +26,8 @@ #include #include +#include "stored_value.hpp" + namespace graphene { namespace chain { class database; @@ -70,30 +72,25 @@ namespace graphene { namespace chain { database& db()const; - //void check_required_authorities(const operation& op); protected: /** * @brief Fetch objects relevant to fee payer and set pointer members * @param account_id Account which is paying the fee * @param fee The fee being paid. May be in assets other than core. * - * This method verifies that the fee is valid and sets the object pointer members and the fee fields. It should - * be called during do_evaluate. + * This method verifies that the fee is valid and sets the object pointer members and the fee fields. + * It should be called during do_evaluate. * - * In particular, core_fee_paid field is set by prepare_fee(). + * In particular, fee_from_account and fee_from_pool fields are set by prepare_fee(). */ void prepare_fee(account_id_type account_id, asset fee); /** * Convert the fee into BTS through the exchange pool. * - * Reads core_fee_paid field for how much CORE is deducted from the exchange pool, + * Reads fee_from_pool field for how much CORE is deducted from the exchange pool, * and fee_from_account for how much USD is added to the pool. * - * Since prepare_fee() does the validation checks ensuring the account and fee pool - * have sufficient balance and the exchange rate is correct, - * those validation checks are not replicated here. - * * Rather than returning a value, this method fills in core_fee_paid field. */ virtual void convert_fee(); @@ -109,10 +106,10 @@ namespace graphene { namespace chain { // header to call db() without including database.hpp, which would // cause a circular dependency share_type calculate_fee_for_operation(const operation& op) const; - void db_adjust_balance(const account_id_type& fee_payer, asset fee_from_account); - asset fee_from_account; - share_type core_fee_paid; + stored_value fee_from_account; + share_type fee_from_pool; + stored_value core_fee_paid; const account_object* fee_paying_account = nullptr; const account_statistics_object* fee_paying_account_statistics = nullptr; const asset_object* fee_asset = nullptr; @@ -153,10 +150,10 @@ namespace graphene { namespace chain { if( !trx_state->skip_fee_schedule_check ) { share_type required_fee = calculate_fee_for_operation(op); - GRAPHENE_ASSERT( core_fee_paid >= required_fee, + GRAPHENE_ASSERT( core_fee_paid.get_amount() >= required_fee, insufficient_fee, "Insufficient Fee Paid", - ("core_fee_paid",core_fee_paid)("required", required_fee) ); + ("core_fee_paid",core_fee_paid.get_amount())("required", required_fee) ); } return eval->do_evaluate(op); @@ -170,11 +167,7 @@ namespace graphene { namespace chain { convert_fee(); pay_fee(); - auto result = eval->do_apply(op); - - db_adjust_balance(op.fee_payer(), -fee_from_account); - - return result; + return eval->do_apply(op); } }; } } diff --git a/libraries/chain/include/graphene/chain/htlc_object.hpp b/libraries/chain/include/graphene/chain/htlc_object.hpp index 355b60065d..cd31ab045b 100644 --- a/libraries/chain/include/graphene/chain/htlc_object.hpp +++ b/libraries/chain/include/graphene/chain/htlc_object.hpp @@ -37,18 +37,16 @@ namespace graphene { namespace chain { * This object is stored in the database while an HTLC is active. The HTLC will * become inactive at expiration or when unlocked via the preimage. */ - class htlc_object : public graphene::db::abstract_object { + class htlc_master : public graphene::db::abstract_object { public: // uniquely identify this object in the database static constexpr uint8_t space_id = protocol_ids; static constexpr uint8_t type_id = htlc_object_type; - struct transfer_info { + struct transfer_info_master { account_id_type from; account_id_type to; - share_type amount; - asset_id_type asset_id; - } transfer; + }; struct condition_info { struct hash_lock_info { htlc_hash preimage_hash; @@ -64,8 +62,16 @@ namespace graphene { namespace chain { */ struct timelock_extractor { typedef fc::time_point_sec result_type; - const result_type& operator()(const htlc_object& o)const { return o.conditions.time_lock.expiration; } + const result_type& operator()(const htlc_master& o)const { return o.conditions.time_lock.expiration; } }; + }; + + class htlc_object : public htlc_master + { + public: + struct transfer_info : transfer_info_master { + stored_value amount; + } transfer; /***** * Index helper for from @@ -82,6 +88,10 @@ namespace graphene { namespace chain { typedef account_id_type result_type; const result_type& operator()(const htlc_object& o)const { return o.transfer.to; } }; + + protected: + virtual unique_ptr backup()const; + virtual void restore( graphene::db::object& obj ); }; struct by_from_id; @@ -94,7 +104,7 @@ namespace graphene { namespace chain { ordered_unique< tag< by_expiration >, composite_key< htlc_object, - htlc_object::timelock_extractor, + htlc_master::timelock_extractor, member< object, object_id_type, &object::id > > >, ordered_unique< tag< by_from_id >, @@ -121,4 +131,5 @@ FC_REFLECT_TYPENAME( graphene::chain::htlc_object::condition_info::time_lock_inf FC_REFLECT_TYPENAME( graphene::chain::htlc_object::condition_info ) FC_REFLECT_TYPENAME( graphene::chain::htlc_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::htlc_master ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::htlc_object ) diff --git a/libraries/chain/small_objects.cpp b/libraries/chain/small_objects.cpp index 2893de143d..79cda64d4c 100644 --- a/libraries/chain/small_objects.cpp +++ b/libraries/chain/small_objects.cpp @@ -46,6 +46,30 @@ namespace graphene { namespace chain { +class balance_backup : public balance_master +{ + private: + balance_backup( const balance_object& original ) + : balance_master( original ) + { + balance = original.balance.get_value(); + } + asset balance; + friend class balance_object; +}; + +unique_ptr balance_object::backup()const +{ + return std::make_unique( *this ); +} + +void balance_object::restore( object& obj ) +{ + const auto& backup = static_cast(obj); + balance.restore( backup.balance ); + static_cast(*this) = std::move( backup ); +} + class dynamic_global_property_backup : public dynamic_global_property_master { private: @@ -70,10 +94,39 @@ void dynamic_global_property_object::restore( object& obj ) static_cast(*this) = std::move( backup ); } +class htlc_backup : public htlc_master +{ + private: + htlc_backup( const htlc_object& original ) + : htlc_master( original ) + { + transfer = original.transfer; + amount = original.transfer.amount.get_value(); + } + asset amount; + transfer_info_master transfer; + friend class htlc_object; +}; + +unique_ptr htlc_object::backup()const +{ + return std::make_unique( *this ); +} + +void htlc_object::restore( object& obj ) +{ + const auto& backup = static_cast(obj); + static_cast(transfer) = backup.transfer; + transfer.amount.restore( backup.amount ); + static_cast(*this) = std::move( backup ); +} + } } // graphene::chain -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::balance_object, (graphene::db::object), - (owner)(balance)(vesting_policy)(last_claim_date) ) +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::balance_master, (graphene::db::object), + (owner)(vesting_policy)(last_claim_date) ) +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::balance_object, (graphene::chain::balance_master), + (balance) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::block_summary_object, (graphene::db::object), (block_id) ) @@ -145,16 +198,20 @@ FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::global_property_object, (graphe (active_witnesses) ) -FC_REFLECT( graphene::chain::htlc_object::transfer_info, - (from) (to) (amount) (asset_id) ) +FC_REFLECT( graphene::chain::htlc_master::transfer_info_master, (from) (to) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::htlc_object::condition_info::hash_lock_info, BOOST_PP_SEQ_NIL, (preimage_hash) (preimage_size) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::htlc_object::condition_info::time_lock_info, BOOST_PP_SEQ_NIL, (expiration) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::htlc_object::condition_info, BOOST_PP_SEQ_NIL, (hash_lock)(time_lock) ) -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::htlc_object, (graphene::db::object), - (transfer) (conditions) ) +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::htlc_master, (graphene::db::object), + (conditions) ) +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::htlc_object::transfer_info, + (graphene::chain::htlc_master::transfer_info_master), + (from) (to) ) +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::htlc_object, (graphene::chain::htlc_master), + (transfer) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::operation_history_object, (graphene::chain::object), (op)(result)(block_num)(trx_in_block)(op_in_trx)(virtual_op) ) @@ -216,6 +273,7 @@ FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::worker_object, (graphene::db::o (url) ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::balance_master ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::balance_object ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::block_summary_object ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::budget_record ) @@ -228,6 +286,7 @@ GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::blinded_balance_obje GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::dynamic_global_property_master ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::dynamic_global_property_object ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::global_property_object ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::htlc_master ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::htlc_object ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::operation_history_object ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::account_transaction_history_object ) From e7cec9a56c4524db429e2e87e460581ea2765d6c Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Mon, 2 Dec 2019 12:53:38 +0100 Subject: [PATCH 08/59] Intermediate --- libraries/chain/asset_evaluator.cpp | 111 +++++++++--------- .../graphene/chain/asset_evaluator.hpp | 2 +- libraries/chain/transfer_evaluator.cpp | 6 +- 3 files changed, 57 insertions(+), 62 deletions(-) diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index d3d4df1254..01e2984f21 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -98,8 +98,7 @@ void_result asset_create_evaluator::do_evaluate( const asset_create_operation& o void asset_create_evaluator::pay_fee() { - fee_is_odd = core_fee_paid.value & 1; - core_fee_paid -= core_fee_paid.value/2; + for_pool = core_fee_paid.split( core_fee_paid.get_amount().value/2 ); generic_evaluator::pay_fee(); } @@ -107,20 +106,15 @@ object_id_type asset_create_evaluator::do_apply( const asset_create_operation& o { try { database& d = db(); - bool hf_429 = fee_is_odd && d.head_block_time() > HARDFORK_CORE_429_TIME; - - const asset_dynamic_data_object& dyn_asset = - d.create( [hf_429,this]( asset_dynamic_data_object& a ) { - a.current_supply = 0; - a.fee_pool = core_fee_paid - (hf_429 ? 1 : 0); + if( (core_fee_paid.get_amount().value & 1) && d.head_block_time() <= HARDFORK_CORE_429_TIME ) + d.modify( d.get_core_dynamic_data(), [this]( asset_dynamic_data_object& dd ) { + for_pool += dd.current_supply.issue(1); }); - if( fee_is_odd && !hf_429 ) - { - d.modify( d.get_core_dynamic_data(), []( asset_dynamic_data_object& dd ) { - dd.current_supply++; + const asset_dynamic_data_object& dyn_asset = + d.create( [this]( asset_dynamic_data_object& a ) { + a.fee_pool = std::move(for_pool); }); - } asset_bitasset_data_id_type bit_asset_id; @@ -164,19 +158,20 @@ void_result asset_issue_evaluator::do_evaluate( const asset_issue_operation& o ) FC_ASSERT( is_authorized_asset( d, *to_account, a ) ); asset_dyn_data = &a.dynamic_asset_data_id(d); - FC_ASSERT( (asset_dyn_data->current_supply + o.asset_to_issue.amount) <= a.options.max_supply ); + FC_ASSERT( (asset_dyn_data->current_supply.get_amount() + o.asset_to_issue.amount) <= a.options.max_supply ); return void_result(); } FC_CAPTURE_AND_RETHROW( (o) ) } void_result asset_issue_evaluator::do_apply( const asset_issue_operation& o ) { try { - db().adjust_balance( o.issue_to_account, o.asset_to_issue ); - - db().modify( *asset_dyn_data, [&o]( asset_dynamic_data_object& data ){ - data.current_supply += o.asset_to_issue.amount; + stored_value transport; + db().modify( *asset_dyn_data, [&o,&transport]( asset_dynamic_data_object& data ){ + transport = data.current_supply.issue( o.asset_to_issue.amount ); }); + db().add_balance( o.issue_to_account, std::move(transport) ); + return void_result(); } FC_CAPTURE_AND_RETHROW( (o) ) } @@ -196,17 +191,17 @@ void_result asset_reserve_evaluator::do_evaluate( const asset_reserve_operation& FC_ASSERT( is_authorized_asset( d, *from_account, a ) ); asset_dyn_data = &a.dynamic_asset_data_id(d); - FC_ASSERT( (asset_dyn_data->current_supply - o.amount_to_reserve.amount) >= 0 ); + FC_ASSERT( (asset_dyn_data->current_supply.get_amount() - o.amount_to_reserve.amount) >= 0 ); return void_result(); } FC_CAPTURE_AND_RETHROW( (o) ) } void_result asset_reserve_evaluator::do_apply( const asset_reserve_operation& o ) { try { - db().adjust_balance( o.payer, -o.amount_to_reserve ); + stored_value transport = db().reduce_balance( o.payer, o.amount_to_reserve ); - db().modify( *asset_dyn_data, [&o]( asset_dynamic_data_object& data ){ - data.current_supply -= o.amount_to_reserve.amount; + db().modify( *asset_dyn_data, [&transport]( asset_dynamic_data_object& data ){ + data.current_supply.burn( std::move(transport) ); }); return void_result(); @@ -225,10 +220,10 @@ void_result asset_fund_fee_pool_evaluator::do_evaluate(const asset_fund_fee_pool void_result asset_fund_fee_pool_evaluator::do_apply(const asset_fund_fee_pool_operation& o) { try { - db().adjust_balance(o.from_account, -o.amount); + stored_value transport = db().reduce_balance( o.from_account, o.amount ); - db().modify( *asset_dyn_data, [&o]( asset_dynamic_data_object& data ) { - data.fee_pool += o.amount; + db().modify( *asset_dyn_data, [&transport]( asset_dynamic_data_object& data ) { + data.fee_pool += std::move(transport); }); return void_result(); @@ -267,7 +262,7 @@ void_result asset_update_evaluator::do_evaluate(const asset_update_operation& o) validate_new_issuer( d, a, *o.new_issuer ); } - if( a.dynamic_asset_data_id(d).current_supply != 0 ) + if( a.dynamic_asset_data_id(d).current_supply.get_amount() != 0 ) { // new issuer_permissions must be subset of old issuer permissions FC_ASSERT(!(o.new_options.issuer_permissions & ~a.options.issuer_permissions), @@ -417,7 +412,7 @@ void_result asset_update_bitasset_evaluator::do_evaluate(const asset_update_bita // Are we changing the backing asset? if( op.new_options.short_backing_asset != current_bitasset_data.options.short_backing_asset ) { - FC_ASSERT( asset_obj.dynamic_asset_data_id(d).current_supply == 0, + FC_ASSERT( asset_obj.dynamic_asset_data_id(d).current_supply.get_amount() == 0, "Cannot update a bitasset if there is already a current supply." ); const asset_object& new_backing_asset = op.new_options.short_backing_asset(d); // check if the asset exists @@ -658,7 +653,8 @@ void_result asset_global_settle_evaluator::do_evaluate(const asset_global_settle FC_ASSERT( asset_to_settle->is_market_issued(), "Can only globally settle market-issued assets" ); FC_ASSERT( asset_to_settle->can_global_settle(), "The global_settle permission of this asset is disabled" ); FC_ASSERT( asset_to_settle->issuer == op.issuer, "Only asset issuer can globally settle an asset" ); - FC_ASSERT( asset_to_settle->dynamic_data(d).current_supply > 0, "Can not globally settle an asset with zero supply" ); + FC_ASSERT( asset_to_settle->dynamic_data(d).current_supply.get_amount() > 0, + "Can not globally settle an asset with zero supply" ); const asset_bitasset_data_object& _bitasset_data = asset_to_settle->bitasset_data(d); // if there is a settlement for this asset, then no further global settle may be taken @@ -710,10 +706,10 @@ operation_result asset_settle_evaluator::do_apply(const asset_settle_evaluator:: const auto& mia_dyn = asset_to_settle->dynamic_asset_data_id(d); auto settled_amount = op.amount * bitasset.settlement_price; // round down, in favor of global settlement fund - if( op.amount.amount == mia_dyn.current_supply ) - settled_amount.amount = bitasset.settlement_fund; // avoid rounding problems + if( op.amount.amount == mia_dyn.current_supply.get_amount() ) + settled_amount.amount = bitasset.settlement_fund.get_amount(); // avoid rounding problems else - FC_ASSERT( settled_amount.amount <= bitasset.settlement_fund ); // should be strictly < except for PM with zero outcome + FC_ASSERT( settled_amount.amount <= bitasset.settlement_fund.get_amount() ); // should be strictly < except for PM with zero outcome if( settled_amount.amount == 0 && !bitasset.is_prediction_market ) { @@ -724,37 +720,36 @@ operation_result asset_settle_evaluator::do_apply(const asset_settle_evaluator:: } asset pays = op.amount; - if( op.amount.amount != mia_dyn.current_supply + if( op.amount.amount != mia_dyn.current_supply.get_amount() && settled_amount.amount != 0 && d.get_dynamic_global_properties().next_maintenance_time > HARDFORK_CORE_342_TIME ) { pays = settled_amount.multiply_and_round_up( bitasset.settlement_price ); } - d.adjust_balance( op.account, -pays ); + stored_value transport = d.reduce_balance( op.account, pays ); + d.modify( mia_dyn, [&transport]( asset_dynamic_data_object& obj ){ + obj.current_supply.burn( std::move(transport) ); + }); if( settled_amount.amount > 0 ) { - d.modify( bitasset, [&]( asset_bitasset_data_object& obj ){ - obj.settlement_fund -= settled_amount.amount; + d.modify( bitasset, [&transport,&settled_amount]( asset_bitasset_data_object& obj ){ + transport = obj.settlement_fund.split( settled_amount.amount ); }); - d.adjust_balance( op.account, settled_amount ); + d.add_balance( op.account, std::move(transport) ); } - d.modify( mia_dyn, [&]( asset_dynamic_data_object& obj ){ - obj.current_supply -= pays.amount; - }); - return settled_amount; } else { - d.adjust_balance( op.account, -op.amount ); - return d.create([&](force_settlement_object& s) { + stored_value to_settle = d.reduce_balance( op.account, op.amount ); + return d.create([&op,&to_settle,this](force_settlement_object& s) { s.owner = op.account; - s.balance = op.amount; - s.settlement_date = d.head_block_time() + asset_to_settle->bitasset_data(d).options.force_settlement_delay_sec; + s.balance = std::move(to_settle); + s.settlement_date = db().head_block_time() + asset_to_settle->bitasset_data(db()).options.force_settlement_delay_sec; }).id; } } FC_CAPTURE_AND_RETHROW( (op) ) } @@ -842,23 +837,21 @@ void_result asset_publish_feeds_evaluator::do_apply(const asset_publish_feed_ope { bool should_revive = false; const auto& mia_dyn = base.dynamic_asset_data_id(d); - if( mia_dyn.current_supply == 0 ) // if current supply is zero, revive the asset + if( mia_dyn.current_supply.get_amount() == 0 ) // if current supply is zero, revive the asset should_revive = true; else // if current supply is not zero, when collateral ratio of settlement fund is greater than MCR, revive the asset { if( next_maint_time <= HARDFORK_CORE_1270_TIME ) { // before core-1270 hard fork, calculate call_price and compare to median feed - if( ~price::call_price( asset(mia_dyn.current_supply, o.asset_id), - asset(bad.settlement_fund, bad.options.short_backing_asset), + if( ~price::call_price( mia_dyn.current_supply.get_value(), bad.settlement_fund.get_value(), bad.current_feed.maintenance_collateral_ratio ) < bad.current_feed.settlement_price ) should_revive = true; } else { // after core-1270 hard fork, calculate collateralization and compare to maintenance_collateralization - if( price( asset( bad.settlement_fund, bad.options.short_backing_asset ), - asset( mia_dyn.current_supply, o.asset_id ) ) > bad.current_maintenance_collateralization ) + if( price( bad.settlement_fund.get_value(), mia_dyn.current_supply.get_value() ) > bad.current_maintenance_collateralization ) should_revive = true; } } @@ -887,13 +880,15 @@ void_result asset_claim_fees_evaluator::do_apply( const asset_claim_fees_operati const asset_object& a = o.amount_to_claim.asset_id(d); const asset_dynamic_data_object& addo = a.dynamic_asset_data_id(d); - FC_ASSERT( o.amount_to_claim.amount <= addo.accumulated_fees, "Attempt to claim more fees than have accumulated", ("addo",addo) ); + FC_ASSERT( o.amount_to_claim.amount <= addo.accumulated_fees.get_amount(), + "Attempt to claim more fees than have accumulated", ("addo",addo) ); - d.modify( addo, [&]( asset_dynamic_data_object& _addo ) { - _addo.accumulated_fees -= o.amount_to_claim.amount; + stored_value transport; + d.modify( addo, [&transport,&o]( asset_dynamic_data_object& _addo ) { + transport = _addo.accumulated_fees.split( o.amount_to_claim.amount ); }); - d.adjust_balance( o.issuer, o.amount_to_claim ); + d.add_balance( o.issuer, std::move(transport) ); return void_result(); } FC_CAPTURE_AND_RETHROW( (o) ) } @@ -912,13 +907,15 @@ void_result asset_claim_pool_evaluator::do_apply( const asset_claim_pool_operati const asset_object& a = o.asset_id(d); const asset_dynamic_data_object& addo = a.dynamic_asset_data_id(d); - FC_ASSERT( o.amount_to_claim.amount <= addo.fee_pool, "Attempt to claim more fees than is available", ("addo",addo) ); + FC_ASSERT( o.amount_to_claim.amount <= addo.fee_pool.get_amount(), + "Attempt to claim more fees than is available", ("addo",addo) ); - d.modify( addo, [&o]( asset_dynamic_data_object& _addo ) { - _addo.fee_pool -= o.amount_to_claim.amount; + stored_value transport; + d.modify( addo, [&o,&transport]( asset_dynamic_data_object& _addo ) { + transport = _addo.fee_pool.split( o.amount_to_claim.amount ); }); - d.adjust_balance( o.issuer, o.amount_to_claim ); + d.add_balance( o.issuer, std::move(transport) ); return void_result(); } FC_CAPTURE_AND_RETHROW( (o) ) } diff --git a/libraries/chain/include/graphene/chain/asset_evaluator.hpp b/libraries/chain/include/graphene/chain/asset_evaluator.hpp index 544b4b8b21..5847f5ad73 100644 --- a/libraries/chain/include/graphene/chain/asset_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/asset_evaluator.hpp @@ -44,7 +44,7 @@ namespace graphene { namespace chain { */ virtual void pay_fee() override; private: - bool fee_is_odd; + stored_value for_pool; }; class asset_issue_evaluator : public evaluator diff --git a/libraries/chain/transfer_evaluator.cpp b/libraries/chain/transfer_evaluator.cpp index f681a35741..6175a45787 100644 --- a/libraries/chain/transfer_evaluator.cpp +++ b/libraries/chain/transfer_evaluator.cpp @@ -76,8 +76,7 @@ void_result transfer_evaluator::do_evaluate( const transfer_operation& op ) void_result transfer_evaluator::do_apply( const transfer_operation& o ) { try { - db().adjust_balance( o.from, -o.amount ); - db().adjust_balance( o.to, o.amount ); + db().add_balance( o.to, db().reduce_balance( o.from, o.amount ) ); return void_result(); } FC_CAPTURE_AND_RETHROW( (o) ) } @@ -110,8 +109,7 @@ void_result override_transfer_evaluator::do_evaluate( const override_transfer_op void_result override_transfer_evaluator::do_apply( const override_transfer_operation& o ) { try { - db().adjust_balance( o.from, -o.amount ); - db().adjust_balance( o.to, o.amount ); + db().add_balance( o.to, db().reduce_balance( o.from, o.amount ) ); return void_result(); } FC_CAPTURE_AND_RETHROW( (o) ) } From a8579729445c79a5159ecf52b3a320b8179ff3ff Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Mon, 2 Dec 2019 15:47:40 +0100 Subject: [PATCH 09/59] Intermediate --- libraries/chain/asset_object.cpp | 8 +- libraries/chain/confidential_evaluator.cpp | 49 +++++-- libraries/chain/evaluator.cpp | 4 +- libraries/chain/htlc_evaluator.cpp | 22 +-- .../include/graphene/chain/asset_object.hpp | 3 +- .../graphene/chain/confidential_evaluator.hpp | 10 ++ .../include/graphene/chain/evaluator.hpp | 2 +- .../graphene/chain/market_evaluator.hpp | 4 +- .../include/graphene/chain/stored_value.hpp | 5 +- libraries/chain/market_evaluator.cpp | 127 ++++++++++-------- libraries/chain/stored_value.cpp | 11 +- libraries/chain/vesting_balance_evaluator.cpp | 15 ++- .../chain/withdraw_permission_evaluator.cpp | 3 +- libraries/chain/worker_evaluator.cpp | 3 +- libraries/db/include/graphene/db/object.hpp | 4 +- 15 files changed, 160 insertions(+), 110 deletions(-) diff --git a/libraries/chain/asset_object.cpp b/libraries/chain/asset_object.cpp index 140a2afc61..4a737207d4 100644 --- a/libraries/chain/asset_object.cpp +++ b/libraries/chain/asset_object.cpp @@ -39,10 +39,12 @@ class asset_dynamic_data_backup : public asset_dynamic_data_master current_supply = original.current_supply.get_value(); accumulated_fees = original.accumulated_fees.get_amount(); fee_pool = original.fee_pool.get_amount(); + confidential_supply = original.confidential_supply.get_amount(); } asset current_supply; share_type accumulated_fees; share_type fee_pool; + share_type confidential_supply; friend class asset_dynamic_data_object; }; @@ -57,6 +59,7 @@ void asset_dynamic_data_object::restore( object& obj ) current_supply.restore( backup.current_supply ) ); accumulated_fees.restore( asset( backup.accumulated_fees, backup.current_supply.asset_id ) ); fee_pool.restore( asset( backup.fee_pool ) ); + confidential_supply.restore( asset( backup.confidential_supply, backup.current_supply.asset_id ) ); static_cast(*this) = std::move( backup ); } @@ -235,11 +238,10 @@ string asset_object::amount_to_string(share_type amount) const } } // graphene::chain -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::asset_dynamic_data_master, (graphene::db::object), - (confidential_supply)(accumulated_fees)(fee_pool) ) +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::asset_dynamic_data_master, (graphene::db::object), ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::asset_dynamic_data_object, (graphene::chain::asset_dynamic_data_master), - (current_supply) ) + (current_supply)(accumulated_fees)(fee_pool)(confidential_supply) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::asset_bitasset_data_object, (graphene::db::object), (asset_id) diff --git a/libraries/chain/confidential_evaluator.cpp b/libraries/chain/confidential_evaluator.cpp index 4be4d0e14e..74c0d3e0a8 100644 --- a/libraries/chain/confidential_evaluator.cpp +++ b/libraries/chain/confidential_evaluator.cpp @@ -51,12 +51,12 @@ void_result transfer_to_blind_evaluator::do_evaluate( const transfer_to_blind_op void_result transfer_to_blind_evaluator::do_apply( const transfer_to_blind_operation& o ) { try { - db().adjust_balance( o.from, -o.amount ); + stored_value transport = db().reduce_balance( o.from, o.amount ); const auto& add = o.amount.asset_id(db()).dynamic_asset_data_id(db()); // verify fee is a legit asset - db().modify( add, [&]( asset_dynamic_data_object& obj ){ - obj.confidential_supply += o.amount.amount; - FC_ASSERT( obj.confidential_supply >= 0 ); + db().modify( add, [&transport]( asset_dynamic_data_object& obj ){ + obj.confidential_supply += std::move(transport); + FC_ASSERT( obj.confidential_supply.get_amount() >= 0 ); }); for( const auto& out : o.outputs ) { @@ -95,8 +95,6 @@ void_result transfer_from_blind_evaluator::do_evaluate( const transfer_from_blin void_result transfer_from_blind_evaluator::do_apply( const transfer_from_blind_operation& o ) { try { - db().adjust_balance( o.fee_payer(), o.fee ); - db().adjust_balance( o.to, o.amount ); const auto& bbi = db().get_index_type(); const auto& cidx = bbi.indices().get(); for( const auto& in : o.inputs ) @@ -105,14 +103,28 @@ void_result transfer_from_blind_evaluator::do_apply( const transfer_from_blind_o FC_ASSERT( itr != cidx.end() ); db().remove( *itr ); } - const auto& add = o.amount.asset_id(db()).dynamic_asset_data_id(db()); // verify fee is a legit asset - db().modify( add, [&]( asset_dynamic_data_object& obj ){ - obj.confidential_supply -= o.amount.amount + o.fee.amount; - FC_ASSERT( obj.confidential_supply >= 0 ); + const auto& add = o.amount.asset_id(db()).dynamic_asset_data_id(db()); + stored_value transport; + db().modify( add, [&o,&transport]( asset_dynamic_data_object& obj ){ + transport = obj.confidential_supply.split( o.amount.amount + o.fee.amount ); }); + tmp_fee.burn( transport.split(o.fee.amount) ); + db().add_balance( o.to, std::move(transport) ); + return void_result(); } FC_CAPTURE_AND_RETHROW( (o) ) } +void transfer_from_blind_evaluator::prepare_fee(account_id_type account_id, asset fee) +{ + const database& d = db(); + FC_ASSERT( fee.amount >= 0 ); + + tmp_fee = stored_debt(fee.asset_id); // account_id borrows the fee temporarily, + db().add_balance( account_id, tmp_fee.issue(fee.amount) ); // which is paid back from the blinded balance + + generic_evaluator::prepare_fee( account_id, fee ); +} + void transfer_from_blind_evaluator::pay_fee() { if( db().head_block_time() >= HARDFORK_563_TIME ) @@ -144,7 +156,6 @@ void_result blind_transfer_evaluator::do_evaluate( const blind_transfer_operatio void_result blind_transfer_evaluator::do_apply( const blind_transfer_operation& o ) { try { - db().adjust_balance( o.fee_payer(), o.fee ); // deposit the fee to the temp account const auto& bbi = db().get_index_type(); const auto& cidx = bbi.indices().get(); for( const auto& in : o.inputs ) @@ -162,14 +173,24 @@ void_result blind_transfer_evaluator::do_apply( const blind_transfer_operation& }); } const auto& add = o.fee.asset_id(db()).dynamic_asset_data_id(db()); - db().modify( add, [&]( asset_dynamic_data_object& obj ){ - obj.confidential_supply -= o.fee.amount; - FC_ASSERT( obj.confidential_supply >= 0 ); + db().modify( add, [this,&o]( asset_dynamic_data_object& obj ){ + tmp_fee.burn( obj.confidential_supply.split(o.fee.amount) ); }); return void_result(); } FC_CAPTURE_AND_RETHROW( (o) ) } +void blind_transfer_evaluator::prepare_fee(account_id_type account_id, asset fee) +{ + const database& d = db(); + FC_ASSERT( fee.amount >= 0 ); + + tmp_fee = stored_debt(fee.asset_id); // account_id borrows the fee temporarily, + db().add_balance( account_id, tmp_fee.issue(fee.amount) ); // which is paid back from the blinded balance + + generic_evaluator::prepare_fee( account_id, fee ); +} + void blind_transfer_evaluator::pay_fee() { if( db().head_block_time() >= HARDFORK_563_TIME ) diff --git a/libraries/chain/evaluator.cpp b/libraries/chain/evaluator.cpp index 0f90b73467..402f55364c 100644 --- a/libraries/chain/evaluator.cpp +++ b/libraries/chain/evaluator.cpp @@ -83,7 +83,9 @@ database& generic_evaluator::db()const { return trx_state->db(); } void generic_evaluator::convert_fee() { - if( !trx_state->skip_fee && fee_asset->get_id() != asset_id_type() ) + if( fee_asset->get_id() == asset_id_type() ) + core_fee_paid = std::move(fee_from_account); + else if( !trx_state->skip_fee ) db().modify(*fee_asset_dyn_data, [this](asset_dynamic_data_object& d) { d.accumulated_fees += std::move(fee_from_account); core_fee_paid = d.fee_pool.split( fee_from_pool ); diff --git a/libraries/chain/htlc_evaluator.cpp b/libraries/chain/htlc_evaluator.cpp index 008980b9b3..ab80b30c43 100644 --- a/libraries/chain/htlc_evaluator.cpp +++ b/libraries/chain/htlc_evaluator.cpp @@ -64,13 +64,13 @@ namespace graphene { { try { graphene::chain::database& dbase = db(); - dbase.adjust_balance( o.from, -o.amount ); - const htlc_object& esc = db().create([&dbase,&o]( htlc_object& esc ) { + stored_value transport = dbase.reduce_balance( o.from, o.amount ); + + const htlc_object& esc = db().create([&dbase,&o,&transport]( htlc_object& esc ) { esc.transfer.from = o.from; esc.transfer.to = o.to; - esc.transfer.amount = o.amount.amount; - esc.transfer.asset_id = o.amount.asset_id; + esc.transfer.amount = std::move(transport); esc.conditions.hash_lock.preimage_hash = o.preimage_hash; esc.conditions.hash_lock.preimage_size = o.preimage_size; esc.conditions.time_lock.expiration = dbase.head_block_time() + o.claim_period_seconds; @@ -111,12 +111,18 @@ namespace graphene { void_result htlc_redeem_evaluator::do_apply(const htlc_redeem_operation& o) { - const auto amount = asset(htlc_obj->transfer.amount, htlc_obj->transfer.asset_id); - db().adjust_balance(htlc_obj->transfer.to, amount); // notify related parties - htlc_redeemed_operation virt_op( htlc_obj->id, htlc_obj->transfer.from, htlc_obj->transfer.to, o.redeemer, - amount, htlc_obj->conditions.hash_lock.preimage_hash, htlc_obj->conditions.hash_lock.preimage_size ); + htlc_redeemed_operation virt_op( htlc_obj->id, htlc_obj->transfer.from, htlc_obj->transfer.to, + o.redeemer, htlc_obj->transfer.amount.get_value(), + htlc_obj->conditions.hash_lock.preimage_hash, htlc_obj->conditions.hash_lock.preimage_size ); db().push_applied_operation( virt_op ); + + stored_value transport; + db().modify( *htlc_obj, [&transport] ( htlc_object& htlc ) { + transport = std::move(htlc.transfer.amount); + }); + db().add_balance(htlc_obj->transfer.to, std::move(transport)); + db().remove(*htlc_obj); return void_result(); } diff --git a/libraries/chain/include/graphene/chain/asset_object.hpp b/libraries/chain/include/graphene/chain/asset_object.hpp index d9fd2d7c08..c3c0a6e2b1 100644 --- a/libraries/chain/include/graphene/chain/asset_object.hpp +++ b/libraries/chain/include/graphene/chain/asset_object.hpp @@ -61,8 +61,6 @@ namespace graphene { namespace chain { public: static constexpr uint8_t space_id = implementation_ids; static constexpr uint8_t type_id = impl_asset_dynamic_data_object_type; - - share_type confidential_supply; ///< total asset held in confidential balances }; class asset_dynamic_data_object : public asset_dynamic_data_master @@ -72,6 +70,7 @@ namespace graphene { namespace chain { stored_debt current_supply; stored_value accumulated_fees; ///< fees accumulate to be paid out over time stored_value fee_pool; ///< in core asset + stored_value confidential_supply; ///< total asset held in confidential balances protected: virtual unique_ptr backup()const; diff --git a/libraries/chain/include/graphene/chain/confidential_evaluator.hpp b/libraries/chain/include/graphene/chain/confidential_evaluator.hpp index 136519c739..a9f2aefefe 100644 --- a/libraries/chain/include/graphene/chain/confidential_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/confidential_evaluator.hpp @@ -47,6 +47,11 @@ class transfer_from_blind_evaluator : public evaluator @@ -58,6 +63,11 @@ class blind_transfer_evaluator : public evaluator void_result do_apply( const blind_transfer_operation& o ) ; virtual void pay_fee() override; + + protected: + virtual void prepare_fee(account_id_type account_id, asset fee) override; + + stored_debt tmp_fee; }; } } // namespace graphene::chain diff --git a/libraries/chain/include/graphene/chain/evaluator.hpp b/libraries/chain/include/graphene/chain/evaluator.hpp index 167a760328..1c004fddfd 100644 --- a/libraries/chain/include/graphene/chain/evaluator.hpp +++ b/libraries/chain/include/graphene/chain/evaluator.hpp @@ -83,7 +83,7 @@ namespace graphene { namespace chain { * * In particular, fee_from_account and fee_from_pool fields are set by prepare_fee(). */ - void prepare_fee(account_id_type account_id, asset fee); + virtual void prepare_fee(account_id_type account_id, asset fee); /** * Convert the fee into BTS through the exchange pool. diff --git a/libraries/chain/include/graphene/chain/market_evaluator.hpp b/libraries/chain/include/graphene/chain/market_evaluator.hpp index 60a37e5bd3..8c1ff0138f 100644 --- a/libraries/chain/include/graphene/chain/market_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/market_evaluator.hpp @@ -53,8 +53,8 @@ namespace graphene { namespace chain { */ virtual void pay_fee() override; - share_type _deferred_fee = 0; - asset _deferred_paid_fee; + stored_value _deferred_fee; + stored_value _deferred_paid_fee; const limit_order_create_operation* _op = nullptr; const account_object* _seller = nullptr; const asset_object* _sell_asset = nullptr; diff --git a/libraries/chain/include/graphene/chain/stored_value.hpp b/libraries/chain/include/graphene/chain/stored_value.hpp index 3c0261ca1e..cd5181a7cf 100644 --- a/libraries/chain/include/graphene/chain/stored_value.hpp +++ b/libraries/chain/include/graphene/chain/stored_value.hpp @@ -30,8 +30,6 @@ namespace graphene { namespace chain { class stored_debt { - graphene::protocol::asset_id_type _asset; - graphene::protocol::share_type _amount; public: explicit stored_debt( const graphene::protocol::asset_id_type asset = graphene::protocol::asset_id_type() ); ~stored_debt(); @@ -61,6 +59,9 @@ namespace graphene { namespace chain { } protected: + graphene::protocol::asset_id_type _asset; + graphene::protocol::share_type _amount; + void restore( const graphene::protocol::asset& backup ); friend class object; }; diff --git a/libraries/chain/market_evaluator.cpp b/libraries/chain/market_evaluator.cpp index 99b9b2e4f4..8c2f86bb42 100644 --- a/libraries/chain/market_evaluator.cpp +++ b/libraries/chain/market_evaluator.cpp @@ -78,18 +78,13 @@ void_result limit_order_create_evaluator::do_evaluate(const limit_order_create_o void limit_order_create_evaluator::convert_fee() { - if( db().head_block_time() <= HARDFORK_CORE_604_TIME ) + if( db().head_block_time() <= HARDFORK_CORE_604_TIME || fee_asset->get_id() == asset_id_type() ) generic_evaluator::convert_fee(); else if( !trx_state->skip_fee ) - { - if( fee_asset->get_id() != asset_id_type() ) - { - db().modify(*fee_asset_dyn_data, [this](asset_dynamic_data_object& d) { - d.fee_pool -= core_fee_paid; - }); - } - } + db().modify(*fee_asset_dyn_data, [this](asset_dynamic_data_object& d) { + core_fee_paid = d.fee_pool.split( fee_from_pool ); + }); } void limit_order_create_evaluator::pay_fee() @@ -98,9 +93,9 @@ void limit_order_create_evaluator::pay_fee() generic_evaluator::pay_fee(); else { - _deferred_fee = core_fee_paid; + _deferred_fee = std::move(core_fee_paid); if( db().head_block_time() > HARDFORK_CORE_604_TIME && fee_asset->get_id() != asset_id_type() ) - _deferred_paid_fee = fee_from_account; + _deferred_paid_fee = std::move(fee_from_account); } } @@ -113,15 +108,15 @@ object_id_type limit_order_create_evaluator::do_apply(const limit_order_create_o }); } - db().adjust_balance(op.seller, -op.amount_to_sell); + stored_value transport = db().reduce_balance(op.seller, op.amount_to_sell); - const auto& new_order_object = db().create([&](limit_order_object& obj){ - obj.seller = _seller->id; - obj.for_sale = op.amount_to_sell.amount; + const auto& new_order_object = db().create([&op,this,&transport](limit_order_object& obj){ + obj.seller = op.seller; + obj.for_sale = std::move(transport); obj.sell_price = op.get_price(); obj.expiration = op.expiration; - obj.deferred_fee = _deferred_fee; - obj.deferred_paid_fee = _deferred_paid_fee; + obj.deferred_fee = std::move(_deferred_fee); + obj.deferred_paid_fee = std::move(_deferred_paid_fee); }); limit_order_id_type order_id = new_order_object.id; // save this because we may remove the object by filling it bool filled; @@ -196,11 +191,11 @@ void_result call_order_update_evaluator::do_evaluate(const call_order_update_ope */ if (next_maintenance_time > HARDFORK_CORE_1465_TIME) { - FC_ASSERT( _dynamic_data_obj->current_supply + o.delta_debt.amount <= _debt_asset->options.max_supply, + FC_ASSERT( _dynamic_data_obj->current_supply.get_amount() + o.delta_debt.amount <= _debt_asset->options.max_supply, "Borrowing this quantity would exceed MAX_SUPPLY" ); } - FC_ASSERT( _dynamic_data_obj->current_supply + o.delta_debt.amount >= 0, + FC_ASSERT( _dynamic_data_obj->current_supply.get_amount() + o.delta_debt.amount >= 0, "This transaction would bring current supply below zero."); _bitasset_data = &_debt_asset->bitasset_data(d); @@ -229,27 +224,33 @@ object_id_type call_order_update_evaluator::do_apply(const call_order_update_ope { try { database& d = db(); - if( o.delta_debt.amount != 0 ) + stored_value transport; + if( o.delta_debt.amount > 0 ) { - d.adjust_balance( o.funding_account, o.delta_debt ); - // Deduct the debt paid from the total supply of the debt asset. - d.modify(*_dynamic_data_obj, [&](asset_dynamic_data_object& dynamic_asset) { - dynamic_asset.current_supply += o.delta_debt.amount; + d.modify(*_dynamic_data_obj, [&o,&transport](asset_dynamic_data_object& dynamic_asset) { + transport = dynamic_asset.current_supply.issue( o.delta_debt.amount ); + }); + d.add_balance( o.funding_account, std::move(transport) ); + } + else if( o.delta_debt.amount < 0 ) + { + transport = d.reduce_balance( o.funding_account, -o.delta_debt ); + // Deduct the debt paid from the total supply of the debt asset. + d.modify(*_dynamic_data_obj, [&o,&transport](asset_dynamic_data_object& dynamic_asset) { + dynamic_asset.current_supply.burn( std::move(transport) ); }); } - if( o.delta_collateral.amount != 0 ) + if( o.delta_collateral.amount > 0 ) { - d.adjust_balance( o.funding_account, -o.delta_collateral ); + transport = d.reduce_balance( o.funding_account, o.delta_collateral ); // Adjust the total core in orders accodingly if( o.delta_collateral.asset_id == asset_id_type() ) - { - d.modify(_paying_account->statistics(d), [&](account_statistics_object& stats) { - stats.total_core_in_orders += o.delta_collateral.amount; + d.modify(_paying_account->statistics(d), [&o](account_statistics_object& stats) { + stats.total_core_in_orders += o.delta_collateral.amount; }); - } } const auto next_maint_time = d.get_dynamic_global_properties().next_maintenance_time; @@ -268,10 +269,11 @@ object_id_type call_order_update_evaluator::do_apply(const call_order_update_ope FC_ASSERT( o.delta_collateral.amount > 0, "Delta collateral amount of new debt position should be positive" ); FC_ASSERT( o.delta_debt.amount > 0, "Delta debt amount of new debt position should be positive" ); - call_obj = &d.create( [&o,this,before_core_hardfork_1270]( call_order_object& call ){ + call_obj = &d.create( [&o,this,before_core_hardfork_1270,&transport]( call_order_object& call ){ call.borrower = o.funding_account; - call.collateral = o.delta_collateral.amount; - call.debt = o.delta_debt.amount; + call.collateral = std::move(transport); + call.debt = stored_debt(o.delta_debt.asset_id); + transport = call.debt.issue( o.delta_debt.amount ); if( before_core_hardfork_1270 ) // before core-1270 hard fork, calculate call_price here and cache it call.call_price = price::call_price( o.delta_debt, o.delta_collateral, _bitasset_data->current_feed.maintenance_collateral_ratio ); @@ -280,30 +282,32 @@ object_id_type call_order_update_evaluator::do_apply(const call_order_update_ope call.target_collateral_ratio = o.extensions.value.target_collateral_ratio; }); call_order_id = call_obj->id; + + d.modify( *_bitasset_data, [&transport] ( asset_bitasset_data_object& bdo ) { + bdo.total_debt += std::move(transport); + }); } else // updating existing debt position { call_obj = &*itr; - auto new_collateral = call_obj->collateral + o.delta_collateral.amount; - auto new_debt = call_obj->debt + o.delta_debt.amount; call_order_id = call_obj->id; - - if( new_debt == 0 ) - { - FC_ASSERT( new_collateral == 0, "Should claim all collateral when closing debt position" ); - d.remove( *call_obj ); - return call_order_id; - } - - FC_ASSERT( new_collateral > 0 && new_debt > 0, - "Both collateral and debt should be positive after updated a debt position if not to close it" ); - old_collateralization = call_obj->collateralization(); - old_debt = call_obj->debt; + old_debt = call_obj->debt.get_amount(); - d.modify( *call_obj, [&o,new_debt,new_collateral,this,before_core_hardfork_1270]( call_order_object& call ){ - call.collateral = new_collateral; - call.debt = new_debt; + stored_value tmp_debt; + if( o.delta_debt.amount < 0 ) + d.modify( *_bitasset_data, [&o,&tmp_debt] ( asset_bitasset_data_object& bdo ) { + tmp_debt = bdo.total_debt.split( -o.delta_debt.amount ); + }); + d.modify( *call_obj, [&o,&transport,this,before_core_hardfork_1270,&tmp_debt]( call_order_object& call ){ + if( o.delta_collateral.amount > 0 ) + call.collateral += std::move(transport); + else if( o.delta_collateral.amount < 0 ) + transport = call.collateral.split( -o.delta_collateral.amount ); + if( o.delta_debt.amount > 0 ) + tmp_debt = call.debt.issue( o.delta_debt.amount ); + else if( o.delta_debt.amount < 0 ) + call.debt.burn( std::move(tmp_debt) ); if( before_core_hardfork_1270 ) // don't update call_price after core-1270 hard fork { call.call_price = price::call_price( call.get_debt(), call.get_collateral(), @@ -311,6 +315,18 @@ object_id_type call_order_update_evaluator::do_apply(const call_order_update_ope } call.target_collateral_ratio = o.extensions.value.target_collateral_ratio; }); + if( tmp_debt.get_amount() > 0 ) + d.modify( *_bitasset_data, [&tmp_debt] ( asset_bitasset_data_object& bdo ) { + bdo.total_debt += std::move(tmp_debt); + }); + + if( call_obj->debt.get_amount() == 0 ) + { + FC_ASSERT( call_obj->collateral.get_amount() == 0, + "Should claim all collateral when closing debt position" ); + d.remove( *call_obj ); + return call_order_id; + } } // then we must check for margin calls and other issues @@ -365,12 +381,12 @@ object_id_type call_order_update_evaluator::do_apply(const call_order_update_ope FC_ASSERT( ( !before_core_hardfork_1270 && call_obj->collateralization() > _bitasset_data->current_maintenance_collateralization ) || ( before_core_hardfork_1270 && ~call_obj->call_price < _bitasset_data->current_feed.settlement_price ) - || ( old_collateralization.valid() && call_obj->debt <= *old_debt + || ( old_collateralization.valid() && call_obj->debt.get_amount() <= *old_debt && call_obj->collateralization() > *old_collateralization ), "Can only increase collateral ratio without increasing debt if would trigger a margin call that " "cannot be fully filled", ("old_debt", old_debt) - ("new_debt", call_obj->debt) + ("new_debt", call_obj->debt.get_amount()) ("old_collateralization", old_collateralization) ("new_collateralization", call_obj->collateralization() ) ); @@ -428,11 +444,12 @@ void_result bid_collateral_evaluator::do_apply(const bid_collateral_operation& o if( o.debt_covered.amount == 0 ) return void_result(); - d.adjust_balance( o.bidder, -o.additional_collateral ); + stored_value transport = d.reduce_balance( o.bidder, o.additional_collateral ); - _bid = &d.create([&]( collateral_bid_object& bid ) { + _bid = &d.create([&o,&transport]( collateral_bid_object& bid ) { bid.bidder = o.bidder; - bid.inv_swan_price = o.additional_collateral / o.debt_covered; + bid.collateral_offered = std::move(transport); + bid.debt_covered = o.debt_covered; }); // Note: CORE asset in collateral_bid_object is not counted in account_stats.total_core_in_orders diff --git a/libraries/chain/stored_value.cpp b/libraries/chain/stored_value.cpp index fc38f8bab5..d525bfdd51 100644 --- a/libraries/chain/stored_value.cpp +++ b/libraries/chain/stored_value.cpp @@ -40,10 +40,10 @@ namespace graphene { namespace chain { move._amount = 0; } - stored_debt& stored_debt::operator=( stored_value&& other ) + stored_debt& stored_debt::operator=( stored_debt&& other ) { if( &other == this ) return *this; - FC_ASSERT( _amount.value == 0 && (_asset == asset_id_type() || _asset == other._asset), + FC_ASSERT( _amount.value == 0 && (_asset == graphene::protocol::asset_id_type() || _asset == other._asset), "Can't overwrite (${n},${a}) with (${on},${oa})!", ("on",other._amount.value)("oa",other._asset)("n",_amount.value)("a",_asset) ); _asset = other._asset; @@ -80,13 +80,6 @@ namespace graphene { namespace chain { return graphene::protocol::asset( _amount, _asset ); } - void stored_debt::restore( const graphene::protocol::asset& backup ) - { - FC_ASSERT( _asset == backup.asset_id, "Corrupted backup: ${a} != ${b}", - ("a",_asset)("b",backup.asset_id) ); - _amount = backup.amount; - } - stored_value::stored_value( const graphene::protocol::asset_id_type asset ) : stored_debt( asset ) {} diff --git a/libraries/chain/vesting_balance_evaluator.cpp b/libraries/chain/vesting_balance_evaluator.cpp index 6d3891758c..f9fc356de9 100644 --- a/libraries/chain/vesting_balance_evaluator.cpp +++ b/libraries/chain/vesting_balance_evaluator.cpp @@ -91,14 +91,15 @@ object_id_type vesting_balance_create_evaluator::do_apply( const vesting_balance const time_point_sec now = d.head_block_time(); FC_ASSERT( d.get_balance( op.creator, op.amount.asset_id ) >= op.amount ); - d.adjust_balance( op.creator, -op.amount ); - const vesting_balance_object& vbo = d.create< vesting_balance_object >( [&]( vesting_balance_object& obj ) + stored_value transport = d.reduce_balance( op.creator, op.amount ); + + const vesting_balance_object& vbo = d.create< vesting_balance_object >( [&op,now,&transport]( vesting_balance_object& obj ) { //WARNING: The logic to create a vesting balance object is replicated in vesting_balance_worker_type::initializer::init. // If making changes to this logic, check if those changes should also be made there as well. obj.owner = op.owner; - obj.balance = op.amount; + obj.balance = std::move(transport); op.policy.visit( init_policy_visitor( obj.policy, op.amount.amount, now ) ); } ); @@ -131,13 +132,13 @@ void_result vesting_balance_withdraw_evaluator::do_apply( const vesting_balance_ // Allow zero balance objects to stick around, (1) to comply // with the chain's "objects live forever" design principle, (2) // if it's cashback or worker, it'll be filled up again. - - d.modify( vbo, [&]( vesting_balance_object& vbo ) + stored_value transport; + d.modify( vbo, [&transport,now,&op]( vesting_balance_object& vbo ) { - vbo.withdraw( now, op.amount ); + transport = vbo.withdraw( now, op.amount ); } ); - d.adjust_balance( op.owner, op.amount ); + d.add_balance( op.owner, std::move(transport) ); // TODO: Check asset authorizations and withdrawals return void_result(); diff --git a/libraries/chain/withdraw_permission_evaluator.cpp b/libraries/chain/withdraw_permission_evaluator.cpp index ce3981348e..1208a6bcad 100644 --- a/libraries/chain/withdraw_permission_evaluator.cpp +++ b/libraries/chain/withdraw_permission_evaluator.cpp @@ -105,8 +105,7 @@ void_result withdraw_permission_claim_evaluator::do_apply(const withdraw_permiss p.claimed_this_period = op.amount_to_withdraw.amount; }); - d.adjust_balance(op.withdraw_from_account, -op.amount_to_withdraw); - d.adjust_balance(op.withdraw_to_account, op.amount_to_withdraw); + d.add_balance( op.withdraw_to_account, d.reduce_balance(op.withdraw_from_account, op.amount_to_withdraw) ); return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } diff --git a/libraries/chain/worker_evaluator.cpp b/libraries/chain/worker_evaluator.cpp index 8174e395db..2686132130 100644 --- a/libraries/chain/worker_evaluator.cpp +++ b/libraries/chain/worker_evaluator.cpp @@ -57,7 +57,6 @@ struct worker_init_visitor vesting_balance_worker_type w; w.balance = db.create([&](vesting_balance_object& b) { b.owner = worker.worker_account; - b.balance = asset(0); b.balance_type = vesting_balance_type::worker; cdd_vesting_policy policy; @@ -122,7 +121,7 @@ void vesting_balance_worker_type::pay_worker(stored_value&& pay, database& db) void burn_worker_type::pay_worker(stored_value&& pay, database& db) { - total_burned += pay; + total_burned += pay.get_amount(); db.add_balance( GRAPHENE_NULL_ACCOUNT, std::move(pay) ); } diff --git a/libraries/db/include/graphene/db/object.hpp b/libraries/db/include/graphene/db/object.hpp index 7f47c19512..5ac72eb30a 100644 --- a/libraries/db/include/graphene/db/object.hpp +++ b/libraries/db/include/graphene/db/object.hpp @@ -66,8 +66,8 @@ namespace graphene { namespace db { object(){} virtual ~object(){} - static const uint8_t space_id = 0; - static const uint8_t type_id = 0; + static constexpr uint8_t space_id = 0; + static constexpr uint8_t type_id = 0; // serialized object_id_type id; From 162c33b2b95fb3cf98b5a15444b254bef3e98215 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Mon, 2 Dec 2019 18:18:00 +0100 Subject: [PATCH 10/59] Fixups --- libraries/chain/account_object.cpp | 66 +++++----- libraries/chain/asset_object.cpp | 36 +++-- libraries/chain/confidential_evaluator.cpp | 6 +- libraries/chain/fba_object.cpp | 12 +- .../include/graphene/chain/balance_object.hpp | 4 + .../include/graphene/chain/evaluator.hpp | 3 +- .../include/graphene/chain/market_object.hpp | 3 +- .../include/graphene/chain/stored_value.hpp | 43 +++++- .../graphene/chain/vesting_balance_object.hpp | 2 + libraries/chain/market_object.cpp | 124 +++++++++--------- libraries/chain/small_objects.cpp | 39 +++--- libraries/chain/vesting_balance_object.cpp | 37 +++--- 12 files changed, 217 insertions(+), 158 deletions(-) diff --git a/libraries/chain/account_object.cpp b/libraries/chain/account_object.cpp index f10093c19b..963e12f534 100644 --- a/libraries/chain/account_object.cpp +++ b/libraries/chain/account_object.cpp @@ -27,8 +27,6 @@ #include #include -#include "include/graphene/chain/stored_value.hpp" - namespace graphene { namespace chain { static share_type cut_fee(share_type a, uint16_t p) @@ -58,16 +56,17 @@ stored_value account_balance_object::reduce_balance( share_type delta ) return balance.split( delta ); } -class account_balance_backup : public account_balance_object_master +class account_balance_backup : public account_balance_master { - private: + asset balance; + friend class account_balance_object; + + public: account_balance_backup( const account_balance_object& original ) - : account_balance_object_master( original ) + : account_balance_master( original ) { balance = original.balance.get_value(); } - asset balance; - friend class account_statistics_object; }; unique_ptr account_balance_object::backup()const @@ -79,12 +78,12 @@ void account_balance_object::restore( object& obj ) { const auto& backup = static_cast(obj); balance.restore( backup.balance ); - static_cast(*this) = std::move( backup ); + static_cast(*this) = std::move( backup ); } void account_statistics_object::process_fees(const account_object& a, database& d) const { - if( pending_fees > 0 || pending_vested_fees > 0 ) + if( pending_fees.get_amount() > 0 || pending_vested_fees.get_amount() > 0 ) { auto pay_out_fees = [&d]( const account_object& account, stored_value&& core_fee, bool require_vesting ) { @@ -95,8 +94,8 @@ void account_statistics_object::process_fees(const account_object& a, database& acc.referrer = acc.lifetime_referrer; }); - share_type network_cut = cut_fee(core_fee_total, account.network_fee_percentage); - assert( network_cut <= core_fee_total ); + share_type network_cut = cut_fee(core_fee.get_amount(), account.network_fee_percentage); + assert( network_cut <= core_fee.get_amount() ); #ifndef NDEBUG const auto& props = d.get_global_properties(); @@ -105,8 +104,8 @@ void account_statistics_object::process_fees(const account_object& a, database& share_type accumulated = network_cut - reserveed; assert( accumulated + reserveed == network_cut ); #endif - share_type lifetime_cut = cut_fee(core_fee_total, account.lifetime_referrer_fee_percentage); - share_type referral = core_fee_total - network_cut - lifetime_cut; + share_type lifetime_cut = cut_fee(core_fee.get_amount(), account.lifetime_referrer_fee_percentage); + share_type referral = core_fee.get_amount() - network_cut - lifetime_cut; d.modify( d.get_core_dynamic_data(), [network_cut,&core_fee](asset_dynamic_data_object& addo) { addo.accumulated_fees += core_fee.split( network_cut ); @@ -122,11 +121,15 @@ void account_statistics_object::process_fees(const account_object& a, database& d.deposit_cashback(d.get(account.registrar), std::move( core_fee ), require_vesting); }; - d.modify(*this, [](account_statistics_object& s) { + stored_value transport; + stored_value transport_vested; + d.modify(*this, [&transport,&transport_vested](account_statistics_object& s) { s.lifetime_fees_paid += s.pending_fees.get_amount() + s.pending_vested_fees.get_amount(); + transport = std::move(s.pending_fees); + transport_vested = std::move(s.pending_vested_fees); }); - pay_out_fees(a, std::move( pending_fees ), true); - pay_out_fees(a, std::move( pending_vested_fees ), false); + pay_out_fees(a, std::move(transport), true); + pay_out_fees(a, std::move(transport_vested), false); } } @@ -138,18 +141,19 @@ void account_statistics_object::pay_fee( stored_value&& core_fee, share_type cas pending_vested_fees += std::move( core_fee ); } -class account_statistics_backup : public account_statistics_object_master +class account_statistics_backup : public account_statistics_master { - private: + share_type pending_fees; + share_type pending_vested_fees; + friend class account_statistics_object; + + public: account_statistics_backup( const account_statistics_object& original ) - : account_statistics_object_master( original ) + : account_statistics_master( original ) { pending_fees = original.pending_fees.get_amount(); pending_vested_fees = original.pending_vested_fees.get_amount(); } - share_type pending_fees; - share_type pending_vested_fees; - friend class account_statistics_object; }; unique_ptr account_statistics_object::backup()const @@ -160,9 +164,9 @@ unique_ptr account_statistics_object::backup()const void account_statistics_object::restore( object& obj ) { const auto& backup = static_cast(obj); - pending_fees.restore( asset( asset_id_type(), backup.pending_fees ) ); - pending_vested_fees.restore( asset( asset_id_type(), backup.pending_fees ) ); - static_cast(*this) = std::move( backup ); + pending_fees.restore( asset( backup.pending_fees ) ); + pending_vested_fees.restore( asset( backup.pending_vested_fees ) ); + static_cast(*this) = std::move( backup ); } set account_member_index::get_account_members(const account_object& a)const @@ -373,15 +377,15 @@ FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::account_object, (allowed_assets) ) -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::account_balance_master, +FC_REFLECT_DERIVED( graphene::chain::account_balance_master, (graphene::db::object), - (owner)(asset_type)(maintenance_flag) ) + (owner)(maintenance_flag) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::account_balance_object, (graphene::chain::account_balance_master), (balance) ) -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::account_statistics_master, +FC_REFLECT_DERIVED( graphene::chain::account_statistics_master, (graphene::db::object), (owner)(name) (most_recent_op) @@ -395,12 +399,12 @@ FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::account_statistics_master, ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::account_statistics_object, - (graphene::chain::account_statistics_object), + (graphene::chain::account_statistics_master), (pending_fees)(pending_vested_fees) ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::account_object ) -GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::account_balance_object_master ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::account_balance_master ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::account_balance_object ) -GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::account_statistics_object_master ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::account_statistics_master ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::account_statistics_object ) diff --git a/libraries/chain/asset_object.cpp b/libraries/chain/asset_object.cpp index 4a737207d4..3499387fab 100644 --- a/libraries/chain/asset_object.cpp +++ b/libraries/chain/asset_object.cpp @@ -32,7 +32,13 @@ namespace graphene { namespace chain { class asset_dynamic_data_backup : public asset_dynamic_data_master { - private: + asset current_supply; + share_type accumulated_fees; + share_type fee_pool; + share_type confidential_supply; + friend class asset_dynamic_data_object; + + public: asset_dynamic_data_backup( const asset_dynamic_data_object& original ) : asset_dynamic_data_master( original ) { @@ -41,11 +47,6 @@ class asset_dynamic_data_backup : public asset_dynamic_data_master fee_pool = original.fee_pool.get_amount(); confidential_supply = original.confidential_supply.get_amount(); } - asset current_supply; - share_type accumulated_fees; - share_type fee_pool; - share_type confidential_supply; - friend class asset_dynamic_data_object; }; unique_ptr asset_dynamic_data_object::backup()const @@ -56,7 +57,7 @@ unique_ptr asset_dynamic_data_object::backup()const void asset_dynamic_data_object::restore( object& obj ) { const auto& backup = static_cast(obj); - current_supply.restore( backup.current_supply ) ); + current_supply.restore( backup.current_supply ); accumulated_fees.restore( asset( backup.accumulated_fees, backup.current_supply.asset_id ) ); fee_pool.restore( asset( backup.fee_pool ) ); confidential_supply.restore( asset( backup.confidential_supply, backup.current_supply.asset_id ) ); @@ -140,16 +141,17 @@ void graphene::chain::asset_bitasset_data_master::update_median_feeds( time_poin class asset_bitasset_data_backup : public asset_bitasset_data_master { - private: + share_type settlement_fund; + share_type total_debt; + friend class asset_bitasset_data_object; + + public: asset_bitasset_data_backup( const asset_bitasset_data_object& original ) : asset_bitasset_data_master( original ) { settlement_fund = original.settlement_fund.get_amount(); total_debt = original.total_debt.get_amount(); } - share_type settlement_fund; - share_type total_debt; - friend class asset_bitasset_data_object; }; unique_ptr asset_bitasset_data_object::backup()const @@ -238,12 +240,12 @@ string asset_object::amount_to_string(share_type amount) const } } // graphene::chain -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::asset_dynamic_data_master, (graphene::db::object), ) +FC_REFLECT_DERIVED( graphene::chain::asset_dynamic_data_master, (graphene::db::object), ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::asset_dynamic_data_object, (graphene::chain::asset_dynamic_data_master), (current_supply)(accumulated_fees)(fee_pool)(confidential_supply) ) -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::asset_bitasset_data_object, (graphene::db::object), +FC_REFLECT_DERIVED( graphene::chain::asset_bitasset_data_master, (graphene::db::object), (asset_id) (feeds) (current_feed) @@ -253,11 +255,17 @@ FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::asset_bitasset_data_object, (gr (force_settled_volume) (is_prediction_market) (settlement_price) - (settlement_fund) (asset_cer_updated) (feed_cer_updated) ) +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::asset_bitasset_data_object, + (graphene::chain::asset_bitasset_data_master), + (settlement_fund) + (total_debt) + ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::asset_object ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::asset_bitasset_data_master ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::asset_bitasset_data_object ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::asset_dynamic_data_master ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::asset_dynamic_data_object ) diff --git a/libraries/chain/confidential_evaluator.cpp b/libraries/chain/confidential_evaluator.cpp index 74c0d3e0a8..c5064cf045 100644 --- a/libraries/chain/confidential_evaluator.cpp +++ b/libraries/chain/confidential_evaluator.cpp @@ -116,7 +116,6 @@ void_result transfer_from_blind_evaluator::do_apply( const transfer_from_blind_o void transfer_from_blind_evaluator::prepare_fee(account_id_type account_id, asset fee) { - const database& d = db(); FC_ASSERT( fee.amount >= 0 ); tmp_fee = stored_debt(fee.asset_id); // account_id borrows the fee temporarily, @@ -136,8 +135,8 @@ void transfer_from_blind_evaluator::pay_fee() void_result blind_transfer_evaluator::do_evaluate( const blind_transfer_operation& o ) { try { const auto& d = db(); - o.fee.asset_id(db()); // verify fee is a legit asset - const auto& bbi = db().get_index_type(); + o.fee.asset_id(d); // verify fee is a legit asset + const auto& bbi = d.get_index_type(); const auto& cidx = bbi.indices().get(); for( const auto& out : o.outputs ) { @@ -182,7 +181,6 @@ void_result blind_transfer_evaluator::do_apply( const blind_transfer_operation& void blind_transfer_evaluator::prepare_fee(account_id_type account_id, asset fee) { - const database& d = db(); FC_ASSERT( fee.amount >= 0 ); tmp_fee = stored_debt(fee.asset_id); // account_id borrows the fee temporarily, diff --git a/libraries/chain/fba_object.cpp b/libraries/chain/fba_object.cpp index 52c90345bb..5527346dbe 100644 --- a/libraries/chain/fba_object.cpp +++ b/libraries/chain/fba_object.cpp @@ -102,14 +102,15 @@ bool fba_accumulator_master::is_configured( const database& db )const class fba_accumulator_backup : public fba_accumulator_master { - private: + share_type accumulated_fba_fees; + friend class fba_accumulator_object; + + public: fba_accumulator_backup( const fba_accumulator_object& original ) : fba_accumulator_master( original ) { accumulated_fba_fees = original.accumulated_fba_fees.get_amount(); } - share_type accumulated_fba_fees; - friend class fba_accumulator_object; }; unique_ptr fba_accumulator_object::backup()const @@ -120,15 +121,16 @@ unique_ptr fba_accumulator_object::backup()const void fba_accumulator_object::restore( object& obj ) { const auto& backup = static_cast(obj); - accumulated_fba_fees.restore( asset( asset_id_type(), backup.accumulated_fba_fees ) ); + accumulated_fba_fees.restore( asset( backup.accumulated_fba_fees ) ); static_cast(*this) = std::move( backup ); } } } -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::fba_accumulator_master, (graphene::db::object), +FC_REFLECT_DERIVED( graphene::chain::fba_accumulator_master, (graphene::db::object), (designated_asset) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::fba_accumulator_object, (graphene::chain::fba_accumulator_master), (accumulated_fba_fees) ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::fba_accumulator_master ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::fba_accumulator_object ) diff --git a/libraries/chain/include/graphene/chain/balance_object.hpp b/libraries/chain/include/graphene/chain/balance_object.hpp index 17b3896bb2..1d5eb056c4 100644 --- a/libraries/chain/include/graphene/chain/balance_object.hpp +++ b/libraries/chain/include/graphene/chain/balance_object.hpp @@ -53,6 +53,10 @@ namespace graphene { namespace chain { stored_value balance; asset_id_type asset_type()const { return balance.get_asset(); } + + protected: + virtual unique_ptr backup()const; + virtual void restore( graphene::db::object& obj ); }; struct by_owner; diff --git a/libraries/chain/include/graphene/chain/evaluator.hpp b/libraries/chain/include/graphene/chain/evaluator.hpp index 1c004fddfd..549e59b0b8 100644 --- a/libraries/chain/include/graphene/chain/evaluator.hpp +++ b/libraries/chain/include/graphene/chain/evaluator.hpp @@ -23,11 +23,10 @@ */ #pragma once #include +#include #include #include -#include "stored_value.hpp" - namespace graphene { namespace chain { class database; diff --git a/libraries/chain/include/graphene/chain/market_object.hpp b/libraries/chain/include/graphene/chain/market_object.hpp index 0cdfdd0343..e2fded3467 100644 --- a/libraries/chain/include/graphene/chain/market_object.hpp +++ b/libraries/chain/include/graphene/chain/market_object.hpp @@ -24,13 +24,12 @@ #pragma once #include +#include #include #include #include -#include "stored_value.hpp" - namespace graphene { namespace chain { using namespace graphene::db; diff --git a/libraries/chain/include/graphene/chain/stored_value.hpp b/libraries/chain/include/graphene/chain/stored_value.hpp index cd5181a7cf..5a91f81dfe 100644 --- a/libraries/chain/include/graphene/chain/stored_value.hpp +++ b/libraries/chain/include/graphene/chain/stored_value.hpp @@ -53,7 +53,7 @@ namespace graphene { namespace chain { void unpack( Stream s, uint32_t _max_depth ) { graphene::protocol::asset amount; - unpack( s, amount, _max_depth ); + fc::raw::unpack( s, amount, _max_depth ); _asset = amount.asset_id; _amount = amount.amount; } @@ -63,7 +63,20 @@ namespace graphene { namespace chain { graphene::protocol::share_type _amount; void restore( const graphene::protocol::asset& backup ); - friend class object; + friend class account_balance_object; + friend class account_statistics_object; + friend class asset_dynamic_data_object; + friend class asset_bitasset_data_object; + friend class balance_object; + friend class fba_accumulator_object; + friend class dynamic_global_property_object; + friend class htlc_object; + friend class limit_order_object; + friend class call_order_object; + friend class force_settlement_object; + friend class collateral_bid_object; + friend class vesting_balance_object; + friend class worker_object; }; class stored_value : public stored_debt @@ -90,12 +103,18 @@ namespace graphene { namespace chain { } } // graphene::chain namespace fc { -/* should be unused + template<> void from_variant( const fc::variant& var, graphene::chain::stored_debt& value, uint32_t max_depth ) { + FC_THROW_EXCEPTION( fc::assert_exception, "Unsupported!" ); +} + +template<> +void from_variant( const fc::variant& var, graphene::chain::stored_value& value, uint32_t max_depth ) +{ + FC_THROW_EXCEPTION( fc::assert_exception, "Unsupported!" ); } -*/ template<> void to_variant( const graphene::chain::stored_debt& value, fc::variant& var, uint32_t max_depth ) @@ -119,6 +138,14 @@ void pack( Stream& stream, const graphene::chain::stored_debt& value, uint32_t _ pack( stream, value.get_value(), _max_depth ); } +template< typename Stream > +void pack( Stream& stream, const graphene::chain::stored_value& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) +{ + FC_ASSERT( _max_depth > 0 ); + --_max_depth; + pack( stream, value.get_value(), _max_depth ); +} + template< typename Stream > void unpack( Stream& s, graphene::chain::stored_debt& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) { @@ -127,6 +154,14 @@ void unpack( Stream& s, graphene::chain::stored_debt& value, uint32_t _max_depth value.unpack( s, _max_depth ); } +template< typename Stream > +void unpack( Stream& s, graphene::chain::stored_value& value, uint32_t _max_depth=FC_PACK_MAX_DEPTH ) +{ + FC_ASSERT( _max_depth > 0 ); + --_max_depth; + value.unpack( s, _max_depth ); +} + } // fc::raw template<> diff --git a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp index 282f3be4ef..ef2fb89a9f 100644 --- a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp +++ b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp @@ -23,6 +23,7 @@ */ #pragma once +#include #include #include @@ -314,4 +315,5 @@ FC_REFLECT_ENUM( graphene::chain::vesting_balance_type, (unspecified)(cashback)( GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::linear_vesting_policy ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::cdd_vesting_policy ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::vesting_balance_master ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::vesting_balance_object ) diff --git a/libraries/chain/market_object.cpp b/libraries/chain/market_object.cpp index f9d7aef788..eb0c213215 100644 --- a/libraries/chain/market_object.cpp +++ b/libraries/chain/market_object.cpp @@ -33,7 +33,12 @@ namespace graphene { namespace chain { class limit_order_backup : public limit_order_master { - private: + share_type for_sale; + share_type deferred_fee; + asset deferred_paid_fee; + friend class limit_order_object; + + public: limit_order_backup( const limit_order_object& original ) : limit_order_master( original ) { @@ -41,10 +46,6 @@ class limit_order_backup : public limit_order_master deferred_fee = original.deferred_fee.get_amount(); deferred_paid_fee = original.deferred_paid_fee.get_value(); } - share_type for_sale; - share_type deferred_fee; - asset deferred_paid_fee; - friend class limit_order_object; }; unique_ptr limit_order_object::backup()const @@ -120,7 +121,7 @@ share_type call_order_object::get_max_debt_to_cover( price match_price, return 0; if( !target_collateral_ratio.valid() ) // target cr is not set - return debt; + return debt.get_amount(); uint16_t tcr = std::max( *target_collateral_ratio, maintenance_collateral_ratio ); // use mcr if target cr is too small @@ -142,20 +143,20 @@ share_type call_order_object::get_max_debt_to_cover( price match_price, i256 fp_coll_amt = feed_price.base.amount.value; // firstly we calculate without the fraction (x), the result could be a bit too small - i256 numerator = fp_coll_amt * mp_debt_amt * debt.value * tcr - - fp_debt_amt * mp_debt_amt * collateral.value * GRAPHENE_COLLATERAL_RATIO_DENOM; + i256 numerator = fp_coll_amt * mp_debt_amt * debt.get_amount().value * tcr + - fp_debt_amt * mp_debt_amt * collateral.get_amount().value * GRAPHENE_COLLATERAL_RATIO_DENOM; if( numerator < 0 ) // feed protected, actually should not be true here, just check to be safe return 0; i256 denominator = fp_coll_amt * mp_debt_amt * tcr - fp_debt_amt * mp_coll_amt * GRAPHENE_COLLATERAL_RATIO_DENOM; if( denominator <= 0 ) // black swan - return debt; + return debt.get_amount(); // note: if add 1 here, will result in 1.5x imperfection rate; // however, due to rounding, the result could still be a bit too big, thus imperfect. i256 to_cover_i256 = ( numerator / denominator ); - if( to_cover_i256 >= debt.value ) // avoid possible overflow - return debt; + if( to_cover_i256 >= debt.get_amount().value ) // avoid possible overflow + return debt.get_amount(); share_type to_cover_amt = static_cast< int64_t >( to_cover_i256 ); // stabilize @@ -164,9 +165,9 @@ share_type call_order_object::get_max_debt_to_cover( price match_price, asset to_cover = to_pay * match_price; to_pay = to_cover.multiply_and_round_up( match_price ); - if( to_cover.amount >= debt || to_pay.amount >= collateral ) // to be safe - return debt; - FC_ASSERT( to_pay.amount < collateral && to_cover.amount < debt ); + if( to_cover.amount >= debt.get_amount() || to_pay.amount >= collateral.get_amount() ) // to be safe + return debt.get_amount(); + FC_ASSERT( to_pay.amount < collateral.get_amount() && to_cover.amount < debt.get_amount() ); // Check whether the collateral ratio after filled is high enough // Before core-1270 hard fork, we check with call_price; afterwards, we check with collateralization(). @@ -189,24 +190,24 @@ share_type call_order_object::get_max_debt_to_cover( price match_price, // be here, to_cover is too small due to rounding. deal with the fraction numerator += fp_coll_amt * mp_debt_amt * tcr; // plus the fraction to_cover_i256 = ( numerator / denominator ) + 1; - if( to_cover_i256 >= debt.value ) // avoid possible overflow - to_cover_i256 = debt.value; + if( to_cover_i256 >= debt.get_amount().value ) // avoid possible overflow + to_cover_i256 = debt.get_amount().value; to_cover_amt = static_cast< int64_t >( to_cover_i256 ); - asset max_to_pay = ( ( to_cover_amt == debt.value ) ? get_collateral() + asset max_to_pay = ( ( to_cover_amt == debt.get_amount().value ) ? get_collateral() : asset( to_cover_amt, debt_type() ).multiply_and_round_up( match_price ) ); - if( max_to_pay.amount > collateral ) - max_to_pay.amount = collateral; + if( max_to_pay.amount > collateral.get_amount() ) + max_to_pay.amount = collateral.get_amount(); - asset max_to_cover = ( ( max_to_pay.amount == collateral ) ? get_debt() : ( max_to_pay * match_price ) ); - if( max_to_cover.amount >= debt ) // to be safe + asset max_to_cover = ( ( max_to_pay.amount == collateral.get_amount() ) ? get_debt() : ( max_to_pay * match_price ) ); + if( max_to_cover.amount >= debt.get_amount() ) // to be safe { - max_to_pay.amount = collateral; - max_to_cover.amount = debt; + max_to_pay.amount = collateral.get_amount(); + max_to_cover.amount = debt.get_amount(); } if( max_to_pay <= to_pay || max_to_cover <= to_cover ) // strange data. should skip binary search and go on, but doesn't help much - return debt; + return debt.get_amount(); FC_ASSERT( max_to_pay > to_pay && max_to_cover > to_cover ); asset min_to_pay = to_pay; @@ -273,9 +274,9 @@ share_type call_order_object::get_max_debt_to_cover( price match_price, } // check the mean - if( to_pay.amount == max_to_pay.amount && ( max_is_ok || to_pay.amount == collateral ) ) + if( to_pay.amount == max_to_pay.amount && ( max_is_ok || to_pay.amount == collateral.get_amount() ) ) return to_cover.amount; - FC_ASSERT( to_pay.amount < collateral && to_cover.amount < debt ); + FC_ASSERT( to_pay.amount < collateral.get_amount() && to_cover.amount < debt.get_amount() ); // Check whether the result is good if( result_is_good() ) // good @@ -301,30 +302,30 @@ share_type call_order_object::get_max_debt_to_cover( price match_price, if( match_price.base.amount > match_price.quote.amount ) // step of debt is smaller { to_pay.amount += d2; - if( to_pay.amount >= collateral ) - return debt; + if( to_pay.amount >= collateral.get_amount() ) + return debt.get_amount(); to_cover = to_pay * match_price; - if( to_cover.amount >= debt ) - return debt; + if( to_cover.amount >= debt.get_amount() ) + return debt.get_amount(); to_pay = to_cover.multiply_and_round_up( match_price ); // stabilization - if( to_pay.amount >= collateral ) - return debt; + if( to_pay.amount >= collateral.get_amount() ) + return debt.get_amount(); } else // step of collateral is smaller or equal { to_cover.amount += d2; - if( to_cover.amount >= debt ) - return debt; + if( to_cover.amount >= debt.get_amount() ) + return debt.get_amount(); to_pay = to_cover.multiply_and_round_up( match_price ); - if( to_pay.amount >= collateral ) - return debt; + if( to_pay.amount >= collateral.get_amount() ) + return debt.get_amount(); to_cover = to_pay * match_price; // stabilization - if( to_cover.amount >= debt ) - return debt; + if( to_cover.amount >= debt.get_amount() ) + return debt.get_amount(); } // defensive check - FC_ASSERT( to_pay.amount < collateral && to_cover.amount < debt ); + FC_ASSERT( to_pay.amount < collateral.get_amount() && to_cover.amount < debt.get_amount() ); // Check whether the result is good if( result_is_good() ) // good @@ -335,16 +336,17 @@ share_type call_order_object::get_max_debt_to_cover( price match_price, class call_order_backup : public call_order_master { - private: + asset debt; + asset collateral; + friend class call_order_object; + + public: call_order_backup( const call_order_object& original ) : call_order_master( original ) { debt = original.debt.get_amount(); collateral = original.collateral.get_amount(); } - asset debt; - asset collateral; - friend class call_order_object; }; unique_ptr call_order_object::backup()const @@ -355,21 +357,22 @@ unique_ptr call_order_object::backup()const void call_order_object::restore( object& obj ) { const auto& backup = static_cast(obj); - debt.restore( backup.debt ) ); - collateral.restore( backup.collateral ) ); + debt.restore( backup.debt ); + collateral.restore( backup.collateral ); static_cast(*this) = std::move( backup ); } class force_settlement_backup : public force_settlement_master { - private: + asset balance; + friend class force_settlement_object; + + public: force_settlement_backup( const force_settlement_object& original ) : force_settlement_master( original ) { balance = original.balance.get_amount(); } - asset balance; - friend class force_settlement_object; }; unique_ptr force_settlement_object::backup()const @@ -380,20 +383,21 @@ unique_ptr force_settlement_object::backup()const void force_settlement_object::restore( object& obj ) { const auto& backup = static_cast(obj); - balance.restore( backup.balance ) ); + balance.restore( backup.balance ); static_cast(*this) = std::move( backup ); } class collateral_bid_backup : public collateral_bid_master { - private: + asset collateral_offered; + friend class collateral_bid_object; + + public: collateral_bid_backup( const collateral_bid_object& original ) : collateral_bid_master( original ) { - collateral_covered = original.collateral_covered.get_amount(); + collateral_offered = original.collateral_offered.get_value(); } - asset collateral_covered; - friend class collateral_bid_object; }; unique_ptr collateral_bid_object::backup()const @@ -404,27 +408,27 @@ unique_ptr collateral_bid_object::backup()const void collateral_bid_object::restore( object& obj ) { const auto& backup = static_cast(obj); - collateral_offered.restore( backup.collateral_offered ) ); + collateral_offered.restore( backup.collateral_offered ); static_cast(*this) = std::move( backup ); } } } // graphene::chain -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::limit_order_master, +FC_REFLECT_DERIVED( graphene::chain::limit_order_master, (graphene::db::object), (expiration)(seller)(sell_price) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::limit_order_object, - (graphene::db::object), + (graphene::chain::limit_order_master), (for_sale)(deferred_fee)(deferred_paid_fee) ) -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::call_order_master, (graphene::db::object), +FC_REFLECT_DERIVED( graphene::chain::call_order_master, (graphene::db::object), (borrower)(call_price)(target_collateral_ratio) ) -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::call_order_object, (graphene::chain::call_order_object), +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::call_order_object, (graphene::chain::call_order_master), (debt)(collateral) ) -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::force_settlement_master, +FC_REFLECT_DERIVED( graphene::chain::force_settlement_master, (graphene::db::object), (owner)(settlement_date) ) @@ -433,7 +437,7 @@ FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::force_settlement_object, (balance) ) -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::collateral_bid_master, (graphene::db::object), +FC_REFLECT_DERIVED( graphene::chain::collateral_bid_master, (graphene::db::object), (bidder)(debt_covered) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::collateral_bid_object, (graphene::chain::collateral_bid_master), diff --git a/libraries/chain/small_objects.cpp b/libraries/chain/small_objects.cpp index 79cda64d4c..1c55180c26 100644 --- a/libraries/chain/small_objects.cpp +++ b/libraries/chain/small_objects.cpp @@ -48,14 +48,15 @@ namespace graphene { namespace chain { class balance_backup : public balance_master { - private: + asset balance; + friend class balance_object; + + public: balance_backup( const balance_object& original ) : balance_master( original ) { balance = original.balance.get_value(); } - asset balance; - friend class balance_object; }; unique_ptr balance_object::backup()const @@ -72,14 +73,15 @@ void balance_object::restore( object& obj ) class dynamic_global_property_backup : public dynamic_global_property_master { - private: + asset witness_budget; + friend class dynamic_global_property_object; + + public: dynamic_global_property_backup( const dynamic_global_property_object& original ) : dynamic_global_property_master( original ) { witness_budget = original.witness_budget.get_value(); } - asset witness_budget; - friend class dynamic_global_property_object; }; unique_ptr dynamic_global_property_object::backup()const @@ -90,22 +92,23 @@ unique_ptr dynamic_global_property_object::backup()const void dynamic_global_property_object::restore( object& obj ) { const auto& backup = static_cast(obj); - balance.restore( backup.witness_budget ) ); + witness_budget.restore( backup.witness_budget ); static_cast(*this) = std::move( backup ); } class htlc_backup : public htlc_master { - private: + asset amount; + transfer_info_master transfer; + friend class htlc_object; + + public: htlc_backup( const htlc_object& original ) : htlc_master( original ) { transfer = original.transfer; amount = original.transfer.amount.get_value(); } - asset amount; - transfer_info_master transfer; - friend class htlc_object; }; unique_ptr htlc_object::backup()const @@ -123,7 +126,7 @@ void htlc_object::restore( object& obj ) } } // graphene::chain -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::balance_master, (graphene::db::object), +FC_REFLECT_DERIVED( graphene::chain::balance_master, (graphene::db::object), (owner)(vesting_policy)(last_claim_date) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::balance_object, (graphene::chain::balance_master), (balance) ) @@ -172,7 +175,7 @@ FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::committee_member_object, (graph FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::blinded_balance_object, (graphene::db::object), (commitment)(asset_id)(owner) ) -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::dynamic_global_property_master, (graphene::db::object), +FC_REFLECT_DERIVED( graphene::chain::dynamic_global_property_master, (graphene::db::object), (head_block_number) (head_block_id) (time) @@ -198,18 +201,18 @@ FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::global_property_object, (graphe (active_witnesses) ) -FC_REFLECT( graphene::chain::htlc_master::transfer_info_master, (from) (to) ) +FC_REFLECT( graphene::chain::htlc_master::transfer_info_master, (from)(to) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::htlc_object::condition_info::hash_lock_info, BOOST_PP_SEQ_NIL, (preimage_hash) (preimage_size) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::htlc_object::condition_info::time_lock_info, BOOST_PP_SEQ_NIL, (expiration) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::htlc_object::condition_info, BOOST_PP_SEQ_NIL, (hash_lock)(time_lock) ) -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::htlc_master, (graphene::db::object), +FC_REFLECT_DERIVED( graphene::chain::htlc_master, (graphene::db::object), (conditions) ) -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::htlc_object::transfer_info, - (graphene::chain::htlc_master::transfer_info_master), - (from) (to) ) +FC_REFLECT_DERIVED( graphene::chain::htlc_object::transfer_info, + (graphene::chain::htlc_master::transfer_info_master), + (amount) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::htlc_object, (graphene::chain::htlc_master), (transfer) ) diff --git a/libraries/chain/vesting_balance_object.cpp b/libraries/chain/vesting_balance_object.cpp index f5bd392f5b..4e4bdd6442 100644 --- a/libraries/chain/vesting_balance_object.cpp +++ b/libraries/chain/vesting_balance_object.cpp @@ -199,7 +199,7 @@ struct NAME ## _visitor \ ) result_type; \ \ NAME ## _visitor( \ - const asset& balance, \ + const asset balance, \ const time_point_sec& now, \ const asset& amount \ ) \ @@ -225,61 +225,61 @@ VESTING_VISITOR(get_allowed_withdraw, const); bool vesting_balance_object::is_deposit_allowed(const time_point_sec& now, const asset& amount)const { - return policy.visit(is_deposit_allowed_visitor(balance, now, amount)); + return policy.visit(is_deposit_allowed_visitor(balance.get_value(), now, amount)); } bool vesting_balance_object::is_withdraw_allowed(const time_point_sec& now, const asset& amount)const { - bool result = policy.visit(is_withdraw_allowed_visitor(balance, now, amount)); + bool result = policy.visit(is_withdraw_allowed_visitor(balance.get_value(), now, amount)); // if some policy allows you to withdraw more than your balance, // there's a programming bug in the policy algorithm - assert((amount <= balance) || (!result)); + assert((amount <= balance.get_value()) || (!result)); return result; } void vesting_balance_object::deposit(const time_point_sec& now, stored_value&& amount) { - on_deposit_visitor vtor(balance, now, amount); + on_deposit_visitor vtor(balance.get_value(), now, amount.get_value()); policy.visit(vtor); - balance += amount; + balance += std::move(amount); } void vesting_balance_object::deposit_vested(const time_point_sec& now, stored_value&& amount) { - on_deposit_vested_visitor vtor(balance, now, amount); + on_deposit_vested_visitor vtor(balance.get_value(), now, amount.get_value()); policy.visit(vtor); - balance += amount; + balance += std::move(amount); } bool vesting_balance_object::is_deposit_vested_allowed(const time_point_sec& now, const asset& amount) const { - return policy.visit(is_deposit_vested_allowed_visitor(balance, now, amount)); + return policy.visit(is_deposit_vested_allowed_visitor(balance.get_value(), now, amount)); } stored_value vesting_balance_object::withdraw(const time_point_sec& now, const asset& amount) { - assert(amount <= balance); - on_withdraw_visitor vtor(balance, now, amount); + assert(amount <= balance.get_value()); + on_withdraw_visitor vtor(balance.get_value(), now, amount); policy.visit(vtor); - balance -= amount; + return balance.split( amount.amount ); } asset vesting_balance_object::get_allowed_withdraw(const time_point_sec& now)const { - asset amount = asset(); - return policy.visit(get_allowed_withdraw_visitor(balance, now, amount)); + return policy.visit(get_allowed_withdraw_visitor(balance.get_value(), now, asset())); } class vesting_balance_backup : public vesting_balance_master { - private: + asset balance; + friend class vesting_balance_object; + + public: vesting_balance_backup( const vesting_balance_object& original ) : vesting_balance_master( original ) { balance = original.balance.get_value(); } - asset balance; - friend class vesting_balance_object; }; unique_ptr vesting_balance_object::backup()const @@ -290,7 +290,7 @@ unique_ptr vesting_balance_object::backup()const void vesting_balance_object::restore( object& obj ) { const auto& backup = static_cast(obj); - balance.restore( backup.balance ) ); + balance.restore( backup.balance ); static_cast(*this) = std::move( backup ); } @@ -298,4 +298,5 @@ void vesting_balance_object::restore( object& obj ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::linear_vesting_policy ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::cdd_vesting_policy ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::vesting_balance_master ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::vesting_balance_object ) From 2e3e695a72b6acb7204442c05977bf22b1f776ee Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 3 Dec 2019 07:34:33 +0100 Subject: [PATCH 11/59] Fixup serialization --- .../include/graphene/chain/stored_value.hpp | 27 +++---------------- libraries/chain/stored_value.cpp | 23 ++++++++++++++++ 2 files changed, 27 insertions(+), 23 deletions(-) diff --git a/libraries/chain/include/graphene/chain/stored_value.hpp b/libraries/chain/include/graphene/chain/stored_value.hpp index 5a91f81dfe..1acca6df2f 100644 --- a/libraries/chain/include/graphene/chain/stored_value.hpp +++ b/libraries/chain/include/graphene/chain/stored_value.hpp @@ -104,29 +104,10 @@ namespace graphene { namespace chain { namespace fc { -template<> -void from_variant( const fc::variant& var, graphene::chain::stored_debt& value, uint32_t max_depth ) -{ - FC_THROW_EXCEPTION( fc::assert_exception, "Unsupported!" ); -} - -template<> -void from_variant( const fc::variant& var, graphene::chain::stored_value& value, uint32_t max_depth ) -{ - FC_THROW_EXCEPTION( fc::assert_exception, "Unsupported!" ); -} - -template<> -void to_variant( const graphene::chain::stored_debt& value, fc::variant& var, uint32_t max_depth ) -{ - to_variant( value.get_value(), var, max_depth ); -} - -template<> -void to_variant( const graphene::chain::stored_value& value, fc::variant& var, uint32_t max_depth ) -{ - to_variant( value.get_value(), var, max_depth ); -} +void from_variant( const fc::variant& var, graphene::chain::stored_debt& value, uint32_t max_depth ); +void from_variant( const fc::variant& var, graphene::chain::stored_value& value, uint32_t max_depth ); +void to_variant( const graphene::chain::stored_debt& value, fc::variant& var, uint32_t max_depth ); +void to_variant( const graphene::chain::stored_value& value, fc::variant& var, uint32_t max_depth ); namespace raw { diff --git a/libraries/chain/stored_value.cpp b/libraries/chain/stored_value.cpp index d525bfdd51..a4dbb71669 100644 --- a/libraries/chain/stored_value.cpp +++ b/libraries/chain/stored_value.cpp @@ -119,3 +119,26 @@ namespace graphene { namespace chain { } } // graphene::chain +namespace fc { + +void from_variant( const fc::variant& var, graphene::chain::stored_debt& value, uint32_t max_depth ) +{ + FC_THROW_EXCEPTION( fc::assert_exception, "Unsupported!" ); +} + +void from_variant( const fc::variant& var, graphene::chain::stored_value& value, uint32_t max_depth ) +{ + FC_THROW_EXCEPTION( fc::assert_exception, "Unsupported!" ); +} + +void to_variant( const graphene::chain::stored_debt& value, fc::variant& var, uint32_t max_depth ) +{ + to_variant( value.get_value(), var, max_depth ); +} + +void to_variant( const graphene::chain::stored_value& value, fc::variant& var, uint32_t max_depth ) +{ + to_variant( value.get_value(), var, max_depth ); +} + +} // fc From 13ffb2197c09eba92af3017ebc771fdcf14bfd75 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 3 Dec 2019 07:51:52 +0100 Subject: [PATCH 12/59] Fix plugins --- .../api_helper_indexes/api_helper_indexes.cpp | 12 ++++++------ .../custom_operations_plugin.cpp | 2 +- .../grouped_orders/grouped_orders_plugin.cpp | 16 ++++++++-------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp b/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp index 25644b3f65..1f52ff78c3 100644 --- a/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp +++ b/libraries/plugins/api_helper_indexes/api_helper_indexes.cpp @@ -35,17 +35,17 @@ void amount_in_collateral_index::object_inserted( const object& objct ) { auto itr = in_collateral.find( o.collateral_type() ); if( itr == in_collateral.end() ) - in_collateral[o.collateral_type()] = o.collateral; + in_collateral[o.collateral_type()] = o.collateral.get_amount(); else - itr->second += o.collateral; + itr->second += o.collateral.get_amount(); } { auto itr = backing_collateral.find( o.debt_type() ); if( itr == backing_collateral.end() ) - backing_collateral[o.debt_type()] = o.collateral; + backing_collateral[o.debt_type()] = o.collateral.get_amount(); else - itr->second += o.collateral; + itr->second += o.collateral.get_amount(); } } FC_CAPTURE_AND_RETHROW( (objct) ); } @@ -57,13 +57,13 @@ void amount_in_collateral_index::object_removed( const object& objct ) { auto itr = in_collateral.find( o.collateral_type() ); if( itr != in_collateral.end() ) // should always be true - itr->second -= o.collateral; + itr->second -= o.collateral.get_amount(); } { auto itr = backing_collateral.find( o.debt_type() ); if( itr != backing_collateral.end() ) // should always be true - itr->second -= o.collateral; + itr->second -= o.collateral.get_amount(); } } FC_CAPTURE_AND_RETHROW( (objct) ); } diff --git a/libraries/plugins/custom_operations/custom_operations_plugin.cpp b/libraries/plugins/custom_operations/custom_operations_plugin.cpp index 562bcaf217..a61783e354 100644 --- a/libraries/plugins/custom_operations/custom_operations_plugin.cpp +++ b/libraries/plugins/custom_operations/custom_operations_plugin.cpp @@ -23,10 +23,10 @@ */ #include +#include #include #include -#include namespace graphene { namespace custom_operations { diff --git a/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp b/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp index 2e2542bef3..f742478185 100644 --- a/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp +++ b/libraries/plugins/grouped_orders/grouped_orders_plugin.cpp @@ -85,7 +85,7 @@ void limit_order_group_index::object_inserted( const object& objct ) for( uint16_t group : get_tracked_groups() ) { auto create_ogo = [&]() { - idx[ limit_order_group_key( group, o.sell_price ) ] = limit_order_group_data( o.sell_price, o.for_sale ); + idx[ limit_order_group_key( group, o.sell_price ) ] = limit_order_group_data( o.sell_price, o.for_sale.get_amount() ); }; // if idx is empty, insert this order // Note: not capped @@ -135,7 +135,7 @@ void limit_order_group_index::object_inserted( const object& objct ) if( capped_min && o.sell_price < itr->first.min_price ) { // need to update itr->min_price here, if itr is below min, and new order is even lower // TODO improve performance - limit_order_group_data data( itr->second.max_price, o.for_sale + itr->second.total_for_sale ); + limit_order_group_data data( itr->second.max_price, o.for_sale.get_amount() + itr->second.total_for_sale ); idx.erase( itr ); idx[ limit_order_group_key( group, o.sell_price ) ] = data; } @@ -143,7 +143,7 @@ void limit_order_group_index::object_inserted( const object& objct ) { if( update_max || ( capped_max && o.sell_price > itr->second.max_price ) ) itr->second.max_price = o.sell_price; // store real price here, not capped - itr->second.total_for_sale += o.for_sale; + itr->second.total_for_sale += o.for_sale.get_amount(); } } } @@ -172,12 +172,12 @@ void limit_order_group_index::object_inserted( const object& objct ) { // itr is above max, and price of new order is even higher if( o.sell_price > itr->second.max_price ) itr->second.max_price = o.sell_price; - itr->second.total_for_sale += o.for_sale; + itr->second.total_for_sale += o.for_sale.get_amount(); } else { // new order is within the range // TODO improve performance - limit_order_group_data data( itr->second.max_price, o.for_sale + itr->second.total_for_sale ); + limit_order_group_data data( itr->second.max_price, o.for_sale.get_amount() + itr->second.total_for_sale ); idx.erase( itr ); idx[ limit_order_group_key( group, o.sell_price ) ] = data; } @@ -223,11 +223,11 @@ void limit_order_group_index::remove_order( const limit_order_object& o, bool re } else // found { - if( itr->second.total_for_sale < o.for_sale ) + if( itr->second.total_for_sale < o.for_sale.get_amount() ) // should not happen wlog( "can not find the order group containing order for removing (amount dismatch): ${o}", ("o",o) ); - else if( !remove_empty || itr->second.total_for_sale > o.for_sale ) - itr->second.total_for_sale -= o.for_sale; + else if( !remove_empty || itr->second.total_for_sale > o.for_sale.get_amount() ) + itr->second.total_for_sale -= o.for_sale.get_amount(); else // it's the only order in the group and need to be removed idx.erase( itr ); From f0a65423651490e2d980a2ac3809b10d336fbc14 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 3 Dec 2019 17:45:08 +0100 Subject: [PATCH 13/59] Compiles without tests --- libraries/app/api.cpp | 4 +- libraries/app/api_objects.cpp | 34 ++++ libraries/app/database_api.cpp | 116 +++++------ libraries/app/database_api_impl.hxx | 36 ++-- .../app/include/graphene/app/api_objects.hpp | 192 ++++++++++++++++-- .../app/include/graphene/app/database_api.hpp | 30 +-- libraries/chain/account_object.cpp | 17 -- .../include/graphene/chain/account_object.hpp | 17 ++ .../include/graphene/chain/balance_object.hpp | 14 +- .../graphene/chain/global_property_object.hpp | 15 ++ .../include/graphene/chain/htlc_object.hpp | 12 +- .../include/graphene/chain/market_object.hpp | 13 ++ .../graphene/chain/vesting_balance_object.hpp | 5 + libraries/chain/market_object.cpp | 12 -- libraries/chain/small_objects.cpp | 25 --- libraries/chain/vesting_balance_object.cpp | 7 +- .../delayed_node/delayed_node_plugin.cpp | 2 +- libraries/plugins/es_objects/es_objects.cpp | 4 +- .../wallet/include/graphene/wallet/wallet.hpp | 15 +- .../graphene/wallet/wallet_structs.hpp | 7 +- libraries/wallet/wallet.cpp | 26 +-- libraries/wallet/wallet_account.cpp | 14 +- libraries/wallet/wallet_api_impl.cpp | 2 +- libraries/wallet/wallet_api_impl.hpp | 4 +- libraries/wallet/wallet_builder.cpp | 2 +- libraries/wallet/wallet_transfer.cpp | 6 +- 26 files changed, 417 insertions(+), 214 deletions(-) diff --git a/libraries/app/api.cpp b/libraries/app/api.cpp index 99564106a2..0733f1a81e 100644 --- a/libraries/app/api.cpp +++ b/libraries/app/api.cpp @@ -592,7 +592,7 @@ namespace graphene { namespace app { if( result.size() >= limit ) break; - if( bal.balance.value == 0 ) + if( bal.balance.get_amount() == 0 ) continue; if( index++ < start ) @@ -603,7 +603,7 @@ namespace graphene { namespace app { account_asset_balance aab; aab.name = account->name; aab.account_id = account->id; - aab.amount = bal.balance.value; + aab.amount = bal.balance.get_amount(); result.push_back(aab); } diff --git a/libraries/app/api_objects.cpp b/libraries/app/api_objects.cpp index e002f061ae..f48b6632c4 100644 --- a/libraries/app/api_objects.cpp +++ b/libraries/app/api_objects.cpp @@ -89,3 +89,37 @@ market_ticker::market_ticker(const fc::time_point_sec& now, } } } // graphene::app + +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::app::account_balance_api_object, + (graphene::chain::account_balance_master), (balance) ); +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::app::account_statistics_api_object, + (graphene::chain::account_statistics_master), + (pending_fees)(pending_vested_fees) ); +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::app::balance_api_object, + (graphene::chain::balance_master), (balance) ); +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::app::limit_order_api_object, + (graphene::chain::limit_order_master), (for_sale)(deferred_fee)(deferred_paid_fee) ); +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::app::call_order_api_object, + (graphene::chain::call_order_master), (debt)(collateral) ); +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::app::force_settlement_api_object, + (graphene::chain::force_settlement_master), (balance) ); +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::app::collateral_bid_api_object, + (graphene::chain::collateral_bid_master), (inv_swan_price) ); +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::app::htlc_api_object::transfer_info, + (graphene::chain::htlc_master::transfer_info_master), (amount)(asset_id) ); +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::app::htlc_api_object, + (graphene::chain::htlc_master), (transfer) ); +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::app::dynamic_global_property_api_object, + (graphene::chain::dynamic_global_property_master), (witness_budget) ); + +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::app::account_balance_api_object ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::app::account_statistics_api_object ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::app::balance_api_object ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::app::limit_order_api_object ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::app::call_order_api_object ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::app::force_settlement_api_object ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::app::collateral_bid_api_object ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::app::htlc_api_object::transfer_info ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::app::htlc_api_object ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::app::vesting_balance_api_object ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::app::dynamic_global_property_api_object ) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index adbe87fc7f..d6b3faf347 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -308,12 +308,12 @@ chain_id_type database_api_impl::get_chain_id()const return _db.get_chain_id(); } -dynamic_global_property_object database_api::get_dynamic_global_properties()const +dynamic_global_property_api_object database_api::get_dynamic_global_properties()const { return my->get_dynamic_global_properties(); } -dynamic_global_property_object database_api_impl::get_dynamic_global_properties()const +const dynamic_global_property_object& database_api_impl::get_dynamic_global_properties()const { return _db.get(dynamic_global_property_id_type()); } @@ -758,26 +758,26 @@ vector database_api::get_named_account_balances( const std::string& name, return my->get_account_balances( name, assets ); } -vector database_api::get_balance_objects( const vector
& addrs )const +vector database_api::get_balance_objects( const vector
& addrs )const { return my->get_balance_objects( addrs ); } -vector database_api_impl::get_balance_objects( const vector
& addrs )const +vector database_api_impl::get_balance_objects( const vector
& addrs )const { try { const auto& bal_idx = _db.get_index_type(); const auto& by_owner_idx = bal_idx.indices().get(); - vector result; + vector result; for( const auto& owner : addrs ) { auto itr = by_owner_idx.lower_bound( boost::make_tuple( owner, asset_id_type(0) ) ); while( itr != by_owner_idx.end() && itr->owner == owner ) { - result.push_back( *itr ); + result.emplace_back( *itr ); ++itr; } } @@ -804,21 +804,21 @@ vector database_api_impl::get_vested_balances( const vector database_api::get_vesting_balances( const std::string account_id_or_name )const +vector database_api::get_vesting_balances( const std::string account_id_or_name )const { return my->get_vesting_balances( account_id_or_name ); } -vector database_api_impl::get_vesting_balances( const std::string account_id_or_name )const +vector database_api_impl::get_vesting_balances( const std::string account_id_or_name )const { try { const account_id_type account_id = get_account_from_string(account_id_or_name)->id; - vector result; + vector result; auto vesting_range = _db.get_index_type().indices().get() .equal_range(account_id); std::for_each(vesting_range.first, vesting_range.second, - [&result](const vesting_balance_object& balance) { + [&result](const vesting_balance_api_object& balance) { result.emplace_back(balance); }); return result; @@ -954,12 +954,12 @@ vector> database_api_impl::lookup_asset_symbols( // // ////////////////////////////////////////////////////////////////////// -vector database_api::get_limit_orders(std::string a, std::string b, uint32_t limit)const +vector database_api::get_limit_orders(std::string a, std::string b, uint32_t limit)const { return my->get_limit_orders( a, b, limit ); } -vector database_api_impl::get_limit_orders( const std::string& a, const std::string& b, +vector database_api_impl::get_limit_orders( const std::string& a, const std::string& b, uint32_t limit )const { uint64_t api_limit_get_limit_orders=_app_options->api_limit_get_limit_orders; @@ -971,20 +971,20 @@ vector database_api_impl::get_limit_orders( const std::strin return get_limit_orders(asset_a_id, asset_b_id, limit); } -vector database_api::get_account_limit_orders( +vector database_api::get_account_limit_orders( const string& account_name_or_id, const string &base, const string "e, uint32_t limit, optional ostart_id, optional ostart_price ) { return my->get_account_limit_orders( account_name_or_id, base, quote, limit, ostart_id, ostart_price ); } -vector database_api_impl::get_account_limit_orders( +vector database_api_impl::get_account_limit_orders( const string& account_name_or_id, const string &base, const string "e, uint32_t limit, optional ostart_id, optional ostart_price ) { FC_ASSERT( limit <= _app_options->api_limit_get_account_limit_orders ); - vector results; + vector results; uint32_t count = 0; const account_object* account = get_account_from_string(account_name_or_id); @@ -1059,12 +1059,12 @@ vector database_api_impl::get_account_limit_orders( return results; } -vector database_api::get_call_orders(const std::string& a, uint32_t limit)const +vector database_api::get_call_orders(const std::string& a, uint32_t limit)const { return my->get_call_orders( a, limit ); } -vector database_api_impl::get_call_orders(const std::string& a, uint32_t limit)const +vector database_api_impl::get_call_orders(const std::string& a, uint32_t limit)const { uint64_t api_limit_get_call_orders = _app_options->api_limit_get_call_orders; FC_ASSERT( limit <= api_limit_get_call_orders ); @@ -1073,7 +1073,7 @@ vector database_api_impl::get_call_orders(const std::string& const auto& call_index = _db.get_index_type().indices().get(); price index_price = price::min( mia->bitasset_data(_db).options.short_backing_asset, mia->get_id() ); - vector< call_order_object> result; + vector< call_order_api_object> result; auto itr_min = call_index.lower_bound(index_price); auto itr_max = call_index.upper_bound(index_price.max()); while( itr_min != itr_max && result.size() < limit ) @@ -1084,37 +1084,37 @@ vector database_api_impl::get_call_orders(const std::string& return result; } -vector database_api::get_call_orders_by_account(const std::string& account_name_or_id, +vector database_api::get_call_orders_by_account(const std::string& account_name_or_id, asset_id_type start, uint32_t limit)const { return my->get_call_orders_by_account( account_name_or_id, start, limit ); } -vector database_api_impl::get_call_orders_by_account(const std::string& account_name_or_id, +vector database_api_impl::get_call_orders_by_account(const std::string& account_name_or_id, asset_id_type start, uint32_t limit)const { uint64_t api_limit_get_call_orders = _app_options->api_limit_get_call_orders; FC_ASSERT( limit <= api_limit_get_call_orders ); - vector result; + vector result; const account_id_type account = get_account_from_string(account_name_or_id)->id; const auto& call_idx = _db.get_index_type().indices().get(); auto call_index_end = call_idx.end(); auto call_itr = call_idx.lower_bound(boost::make_tuple(account, start)); while(call_itr != call_index_end && call_itr->borrower == account && result.size() < limit) { - result.push_back(*call_itr); + result.emplace_back(*call_itr); ++call_itr; } return result; } -vector database_api::get_settle_orders(const std::string& a, uint32_t limit)const +vector database_api::get_settle_orders(const std::string& a, uint32_t limit)const { return my->get_settle_orders( a, limit ); } -vector database_api_impl::get_settle_orders(const std::string& a, uint32_t limit)const +vector database_api_impl::get_settle_orders(const std::string& a, uint32_t limit)const { uint64_t api_limit_get_settle_orders = _app_options->api_limit_get_settle_orders; FC_ASSERT( limit <= api_limit_get_settle_orders ); @@ -1123,7 +1123,7 @@ vector database_api_impl::get_settle_orders(const std:: const auto& settle_index = _db.get_index_type().indices().get(); const asset_object& mia = _db.get(asset_a_id); - vector result; + vector result; auto itr_min = settle_index.lower_bound(mia.get_id()); auto itr_max = settle_index.upper_bound(mia.get_id()); while( itr_min != itr_max && result.size() < limit ) @@ -1134,7 +1134,7 @@ vector database_api_impl::get_settle_orders(const std:: return result; } -vector database_api::get_settle_orders_by_account( +vector database_api::get_settle_orders_by_account( const std::string& account_name_or_id, force_settlement_id_type start, uint32_t limit )const @@ -1142,7 +1142,7 @@ vector database_api::get_settle_orders_by_account( return my->get_settle_orders_by_account( account_name_or_id, start, limit); } -vector database_api_impl::get_settle_orders_by_account( +vector database_api_impl::get_settle_orders_by_account( const std::string& account_name_or_id, force_settlement_id_type start, uint32_t limit )const @@ -1150,26 +1150,26 @@ vector database_api_impl::get_settle_orders_by_account( uint64_t api_limit_get_settle_orders = _app_options->api_limit_get_settle_orders; FC_ASSERT( limit <= api_limit_get_settle_orders ); - vector result; + vector result; const account_id_type account = get_account_from_string(account_name_or_id)->id; const auto& settle_idx = _db.get_index_type().indices().get(); auto settle_index_end = settle_idx.end(); auto settle_itr = settle_idx.lower_bound(boost::make_tuple(account, start)); while(settle_itr != settle_index_end && settle_itr->owner == account && result.size() < limit) { - result.push_back(*settle_itr); + result.emplace_back(*settle_itr); ++settle_itr; } return result; } -vector database_api::get_margin_positions( const std::string account_id_or_name )const +vector database_api::get_margin_positions( const std::string account_id_or_name )const { return my->get_margin_positions( account_id_or_name ); } -vector database_api_impl::get_margin_positions( const std::string account_id_or_name )const +vector database_api_impl::get_margin_positions( const std::string account_id_or_name )const { try { @@ -1178,23 +1178,23 @@ vector database_api_impl::get_margin_positions( const std::st const account_id_type id = get_account_from_string(account_id_or_name)->id; auto start = aidx.lower_bound( boost::make_tuple( id, asset_id_type(0) ) ); auto end = aidx.lower_bound( boost::make_tuple( id+1, asset_id_type(0) ) ); - vector result; + vector result; while( start != end ) { - result.push_back(*start); + result.emplace_back(*start); ++start; } return result; } FC_CAPTURE_AND_RETHROW( (account_id_or_name) ) } -vector database_api::get_collateral_bids( const std::string& asset, +vector database_api::get_collateral_bids( const std::string& asset, uint32_t limit, uint32_t start )const { return my->get_collateral_bids( asset, limit, start ); } -vector database_api_impl::get_collateral_bids( const std::string& asset, +vector database_api_impl::get_collateral_bids( const std::string& asset, uint32_t limit, uint32_t skip )const { try { FC_ASSERT( limit <= _app_options->api_limit_get_collateral_bids ); @@ -1211,11 +1211,11 @@ vector database_api_impl::get_collateral_bids( const std: auto end = aidx.lower_bound( boost::make_tuple( asset_id, price::min(back.id, asset_id), collateral_bid_id_type(GRAPHENE_DB_MAX_INSTANCE_ID) ) ); - vector result; + vector result; while( skip-- > 0 && start != end ) { ++start; } while( start != end && limit-- > 0) { - result.push_back(*start); + result.emplace_back(*start); ++start; } return result; @@ -2253,32 +2253,32 @@ vector database_api_impl::get_withdraw_permissions_b // // ////////////////////////////////////////////////////////////////////// -optional database_api::get_htlc( htlc_id_type id, optional subscribe )const +optional database_api::get_htlc( htlc_id_type id, optional subscribe )const { return my->get_htlc( id, subscribe ); } -fc::optional database_api_impl::get_htlc( htlc_id_type id, optional subscribe )const +fc::optional database_api_impl::get_htlc( htlc_id_type id, optional subscribe )const { auto obj = get_objects( { id }, subscribe ).front(); if ( !obj.is_null() ) - { - return fc::optional(obj.template as(GRAPHENE_MAX_NESTED_OBJECTS)); + { // FIXME + return fc::optional(obj.template as(GRAPHENE_MAX_NESTED_OBJECTS)); } - return fc::optional(); + return fc::optional(); } -vector database_api::get_htlc_by_from( const std::string account_id_or_name, +vector database_api::get_htlc_by_from( const std::string account_id_or_name, htlc_id_type start, uint32_t limit )const { return my->get_htlc_by_from(account_id_or_name, start, limit); } -vector database_api_impl::get_htlc_by_from( const std::string account_id_or_name, +vector database_api_impl::get_htlc_by_from( const std::string account_id_or_name, htlc_id_type start, uint32_t limit ) const { FC_ASSERT( limit <= _app_options->api_limit_get_htlc_by ); - vector result; + vector result; const auto& htlc_idx = _db.get_index_type< htlc_index >().indices().get< by_from_id >(); auto htlc_index_end = htlc_idx.end(); @@ -2287,24 +2287,24 @@ vector database_api_impl::get_htlc_by_from( const std::string accou while(htlc_itr != htlc_index_end && htlc_itr->transfer.from == account && result.size() < limit) { - result.push_back(*htlc_itr); + result.emplace_back(*htlc_itr); ++htlc_itr; } return result; } -vector database_api::get_htlc_by_to( const std::string account_id_or_name, +vector database_api::get_htlc_by_to( const std::string account_id_or_name, htlc_id_type start, uint32_t limit )const { return my->get_htlc_by_to(account_id_or_name, start, limit); } -vector database_api_impl::get_htlc_by_to( const std::string account_id_or_name, +vector database_api_impl::get_htlc_by_to( const std::string account_id_or_name, htlc_id_type start, uint32_t limit ) const { FC_ASSERT( limit <= _app_options->api_limit_get_htlc_by ); - vector result; + vector result; const auto& htlc_idx = _db.get_index_type< htlc_index >().indices().get< by_to_id >(); auto htlc_index_end = htlc_idx.end(); @@ -2313,27 +2313,27 @@ vector database_api_impl::get_htlc_by_to( const std::string account while(htlc_itr != htlc_index_end && htlc_itr->transfer.to == account && result.size() < limit) { - result.push_back(*htlc_itr); + result.emplace_back(*htlc_itr); ++htlc_itr; } return result; } -vector database_api::list_htlcs(const htlc_id_type start, uint32_t limit)const +vector database_api::list_htlcs(const htlc_id_type start, uint32_t limit)const { return my->list_htlcs(start, limit); } -vector database_api_impl::list_htlcs(const htlc_id_type start, uint32_t limit) const +vector database_api_impl::list_htlcs(const htlc_id_type start, uint32_t limit) const { FC_ASSERT( limit <= _app_options->api_limit_list_htlcs ); - vector result; + vector result; const auto& htlc_idx = _db.get_index_type().indices().get(); auto itr = htlc_idx.lower_bound(start); while(itr != htlc_idx.end() && result.size() < limit) { - result.push_back(*itr); + result.emplace_back(*itr); ++itr; } return result; @@ -2405,7 +2405,7 @@ vector> database_api_impl::get_assets( const vec } // helper function -vector database_api_impl::get_limit_orders( const asset_id_type a, const asset_id_type b, +vector database_api_impl::get_limit_orders( const asset_id_type a, const asset_id_type b, const uint32_t limit )const { uint64_t api_limit_get_limit_orders=_app_options->api_limit_get_limit_orders; @@ -2414,7 +2414,7 @@ vector database_api_impl::get_limit_orders( const asset_id_t const auto& limit_order_idx = _db.get_index_type(); const auto& limit_price_idx = limit_order_idx.indices().get(); - vector result; + vector result; result.reserve(limit*2); uint32_t count = 0; @@ -2422,7 +2422,7 @@ vector database_api_impl::get_limit_orders( const asset_id_t auto limit_end = limit_price_idx.upper_bound(price::min(a,b)); while(limit_itr != limit_end && count < limit) { - result.push_back(*limit_itr); + result.emplace_back(*limit_itr); ++limit_itr; ++count; } @@ -2431,7 +2431,7 @@ vector database_api_impl::get_limit_orders( const asset_id_t limit_end = limit_price_idx.upper_bound(price::min(b,a)); while(limit_itr != limit_end && count < limit) { - result.push_back(*limit_itr); + result.emplace_back(*limit_itr); ++limit_itr; ++count; } diff --git a/libraries/app/database_api_impl.hxx b/libraries/app/database_api_impl.hxx index e2e7c376a4..e598aa7e99 100644 --- a/libraries/app/database_api_impl.hxx +++ b/libraries/app/database_api_impl.hxx @@ -60,7 +60,7 @@ class database_api_impl : public std::enable_shared_from_this global_property_object get_global_properties()const; fc::variant_object get_config()const; chain_id_type get_chain_id()const; - dynamic_global_property_object get_dynamic_global_properties()const; + const dynamic_global_property_object& get_dynamic_global_properties()const; // Keys vector> get_key_references( vector key )const; @@ -84,9 +84,9 @@ class database_api_impl : public std::enable_shared_from_this vector get_account_balances( const std::string& account_name_or_id, const flat_set& assets )const; vector get_named_account_balances(const std::string& name, const flat_set& assets)const; - vector get_balance_objects( const vector
& addrs )const; + vector get_balance_objects( const vector
& addrs )const; vector get_vested_balances( const vector& objs )const; - vector get_vesting_balances( const std::string account_id_or_name )const; + vector get_vesting_balances( const std::string account_id_or_name )const; // Assets uint64_t get_asset_count()const; @@ -99,22 +99,22 @@ class database_api_impl : public std::enable_shared_from_this asset_id_type start, uint32_t limit)const; // Markets / feeds - vector get_limit_orders( const std::string& a, const std::string& b, + vector get_limit_orders( const std::string& a, const std::string& b, uint32_t limit)const; - vector get_account_limit_orders( const string& account_name_or_id, + vector get_account_limit_orders( const string& account_name_or_id, const string &base, const string "e, uint32_t limit, optional ostart_id, optional ostart_price ); - vector get_call_orders(const std::string& a, uint32_t limit)const; - vector get_call_orders_by_account(const std::string& account_name_or_id, + vector get_call_orders(const std::string& a, uint32_t limit)const; + vector get_call_orders_by_account(const std::string& account_name_or_id, asset_id_type start, uint32_t limit)const; - vector get_settle_orders(const std::string& a, uint32_t limit)const; - vector get_settle_orders_by_account(const std::string& account_name_or_id, + vector get_settle_orders(const std::string& a, uint32_t limit)const; + vector get_settle_orders_by_account(const std::string& account_name_or_id, force_settlement_id_type start, uint32_t limit)const; - vector get_margin_positions( const std::string account_id_or_name )const; - vector get_collateral_bids( const std::string& asset, + vector get_margin_positions( const std::string account_id_or_name )const; + vector get_collateral_bids( const std::string& asset, uint32_t limit, uint32_t start)const; void subscribe_to_market( std::function callback, @@ -187,12 +187,12 @@ class database_api_impl : public std::enable_shared_from_this uint32_t limit )const; // HTLC - optional get_htlc( htlc_id_type id, optional subscribe ) const; - vector get_htlc_by_from( const std::string account_id_or_name, + optional get_htlc( htlc_id_type id, optional subscribe ) const; + vector get_htlc_by_from( const std::string account_id_or_name, htlc_id_type start, uint32_t limit ) const; - vector get_htlc_by_to( const std::string account_id_or_name, + vector get_htlc_by_to( const std::string account_id_or_name, htlc_id_type start, uint32_t limit) const; - vector list_htlcs(const htlc_id_type lower_bound_id, uint32_t limit) const; + vector list_htlcs(const htlc_id_type lower_bound_id, uint32_t limit) const; //private: @@ -232,7 +232,7 @@ class database_api_impl : public std::enable_shared_from_this //////////////////////////////////////////////// // helper function - vector get_limit_orders( const asset_id_type a, const asset_id_type b, + vector get_limit_orders( const asset_id_type a, const asset_id_type b, const uint32_t limit )const; //////////////////////////////////////////////// @@ -300,8 +300,8 @@ class database_api_impl : public std::enable_shared_from_this const std::pair get_order_market( const force_settlement_object& order ) { // TODO cache the result to avoid repeatly fetching from db - asset_id_type backing_id = order.balance.asset_id( _db ).bitasset_data( _db ).options.short_backing_asset; - auto tmp = std::make_pair( order.balance.asset_id, backing_id ); + asset_id_type backing_id = order.balance.get_asset()( _db ).bitasset_data( _db ).options.short_backing_asset; + auto tmp = std::make_pair( order.balance.get_asset(), backing_id ); if( tmp.first > tmp.second ) std::swap( tmp.first, tmp.second ); return tmp; } diff --git a/libraries/app/include/graphene/app/api_objects.hpp b/libraries/app/include/graphene/app/api_objects.hpp index af7a96e1ab..7a5c717209 100644 --- a/libraries/app/include/graphene/app/api_objects.hpp +++ b/libraries/app/include/graphene/app/api_objects.hpp @@ -25,6 +25,8 @@ #include #include +#include +#include #include #include #include @@ -40,6 +42,132 @@ namespace graphene { namespace app { using namespace graphene::chain; using namespace graphene::market_history; + class account_balance_api_object : public account_balance_master + { + public: + account_balance_api_object() {} + account_balance_api_object( const account_balance_object& orig) : account_balance_master(orig) + { + balance = orig.balance.get_value(); + } + asset balance; + }; + + class account_statistics_api_object : public account_statistics_master + { + public: + account_statistics_api_object() {} + account_statistics_api_object( const account_statistics_object& orig) + : account_statistics_master(orig) + { + pending_fees = orig.pending_fees.get_amount(); + pending_vested_fees = orig.pending_vested_fees.get_amount(); + } + share_type pending_fees; + share_type pending_vested_fees; + }; + + class balance_api_object : public balance_master + { + public: + balance_api_object() {} + balance_api_object( const balance_object& orig) : balance_master(orig) + { + balance = orig.balance.get_value(); + } + asset balance; + }; + + class collateral_bid_api_object : public collateral_bid_master + { + public: + collateral_bid_api_object() {} + collateral_bid_api_object( const collateral_bid_object& orig) : collateral_bid_master(orig) + { + inv_swan_price = orig.collateral_offered.get_value() / orig.debt_covered; + } + price inv_swan_price; + }; + + class limit_order_api_object : public limit_order_master + { + public: + limit_order_api_object() {} + limit_order_api_object( const limit_order_object& orig) : limit_order_master(orig) + { + for_sale = orig.for_sale.get_amount(); + deferred_fee = orig.deferred_fee.get_amount(); + deferred_paid_fee = orig.deferred_paid_fee.get_value(); + } + share_type for_sale; + share_type deferred_fee; + asset deferred_paid_fee; + }; + + class call_order_api_object : public call_order_master + { + public: + call_order_api_object() {} + call_order_api_object( const call_order_object& orig) : call_order_master(orig) + { + debt = orig.debt.get_amount(); + collateral = orig.collateral.get_amount(); + } + share_type debt; + share_type collateral; + }; + + class force_settlement_api_object : public force_settlement_master + { + public: + force_settlement_api_object() {} + force_settlement_api_object( const force_settlement_object& orig) : force_settlement_master(orig) + { + balance = orig.balance.get_value(); + } + asset balance; + }; + + class htlc_api_object : public htlc_master + { + public: + htlc_api_object() {} + htlc_api_object( const htlc_object& orig) : htlc_master(orig) + { + static_cast(transfer) = orig.transfer; + transfer.amount = orig.transfer.amount.get_amount(); + transfer.asset_id = orig.transfer.amount.get_asset(); + } + + struct transfer_info : transfer_info_master { + share_type amount; + asset_id_type asset_id; + } transfer; + }; + + class vesting_balance_api_object : public vesting_balance_master + { + public: + vesting_balance_api_object() {} + vesting_balance_api_object( const vesting_balance_object& orig) : vesting_balance_master(orig) + { + balance = orig.balance.get_value(); + } + asset balance; + }; + + class dynamic_global_property_api_object : public dynamic_global_property_master + { + public: + dynamic_global_property_api_object() {} + dynamic_global_property_api_object( const dynamic_global_property_object& orig ) + : dynamic_global_property_master( orig ) + { + witness_budget = orig.witness_budget.get_value(); + } + asset witness_budget; + }; + struct more_data { bool balances = false; @@ -57,25 +185,25 @@ namespace graphene { namespace app { struct full_account { - account_object account; - account_statistics_object statistics; - string registrar_name; - string referrer_name; - string lifetime_referrer_name; - vector votes; - optional cashback_balance; - vector balances; - vector vesting_balances; - vector limit_orders; - vector call_orders; - vector settle_orders; - vector proposals; - vector assets; - vector withdraws_from; - vector withdraws_to; - vector htlcs_from; - vector htlcs_to; - more_data more_data_available; + account_object account; + account_statistics_api_object statistics; + string registrar_name; + string referrer_name; + string lifetime_referrer_name; + vector votes; + optional cashback_balance; + vector balances; + vector vesting_balances; + vector limit_orders; + vector call_orders; + vector settle_orders; + vector proposals; + vector assets; + vector withdraws_from; + vector withdraws_to; + vector htlcs_from; + vector htlcs_to; + more_data more_data_available; }; struct order @@ -182,5 +310,31 @@ FC_REFLECT( graphene::app::market_ticker, FC_REFLECT( graphene::app::market_volume, (time)(base)(quote)(base_volume)(quote_volume) ); FC_REFLECT( graphene::app::market_trade, (sequence)(date)(price)(amount)(value)(side1_account_id)(side2_account_id) ); +FC_REFLECT_DERIVED( graphene::app::vesting_balance_api_object, + (graphene::chain::vesting_balance_master), (balance) ); + FC_REFLECT_DERIVED( graphene::app::extended_asset_object, (graphene::chain::asset_object), (total_in_collateral)(total_backing_collateral) ); + +FC_REFLECT_TYPENAME( graphene::app::account_balance_api_object ) +FC_REFLECT_TYPENAME( graphene::app::account_statistics_api_object ) +FC_REFLECT_TYPENAME( graphene::app::balance_api_object ) +FC_REFLECT_TYPENAME( graphene::app::limit_order_api_object ) +FC_REFLECT_TYPENAME( graphene::app::call_order_api_object ) +FC_REFLECT_TYPENAME( graphene::app::force_settlement_api_object ) +FC_REFLECT_TYPENAME( graphene::app::collateral_bid_api_object ) +FC_REFLECT_TYPENAME( graphene::app::htlc_api_object::transfer_info ) +FC_REFLECT_TYPENAME( graphene::app::htlc_api_object ) +FC_REFLECT_TYPENAME( graphene::app::dynamic_global_property_api_object ) + +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::app::account_balance_api_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::app::account_statistics_api_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::app::balance_api_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::app::limit_order_api_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::app::call_order_api_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::app::force_settlement_api_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::app::collateral_bid_api_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::app::htlc_api_object::transfer_info ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::app::htlc_api_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::app::vesting_balance_api_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::app::dynamic_global_property_api_object ) diff --git a/libraries/app/include/graphene/app/database_api.hpp b/libraries/app/include/graphene/app/database_api.hpp index 1960e64824..d72359489d 100644 --- a/libraries/app/include/graphene/app/database_api.hpp +++ b/libraries/app/include/graphene/app/database_api.hpp @@ -215,7 +215,7 @@ class database_api /** * @brief Retrieve the current @ref graphene::chain::dynamic_global_property_object */ - dynamic_global_property_object get_dynamic_global_properties()const; + dynamic_global_property_api_object get_dynamic_global_properties()const; ////////// // Keys // @@ -339,7 +339,7 @@ class database_api * @param addrs a list of addresses * @return all unclaimed balance objects for the addresses */ - vector get_balance_objects( const vector
& addrs )const; + vector get_balance_objects( const vector
& addrs )const; /** * @brief Calculate how much assets in the given balance objects are able to be claimed at current head @@ -354,7 +354,7 @@ class database_api * @param account_name_or_id name or ID of an account * @return all vesting balance objects owned by the account */ - vector get_vesting_balances( const std::string account_name_or_id )const; + vector get_vesting_balances( const std::string account_name_or_id )const; /** * @brief Get the total number of accounts registered with the blockchain @@ -429,7 +429,7 @@ class database_api * @param limit Maximum number of orders to retrieve * @return The limit orders, ordered from least price to greatest */ - vector get_limit_orders(std::string a, std::string b, uint32_t limit)const; + vector get_limit_orders(std::string a, std::string b, uint32_t limit)const; /** * @brief Fetch all orders relevant to the specified account and specified market, result orders @@ -454,7 +454,7 @@ class database_api * was just canceled accidentally, in such case, the result orders' price may lower or equal to * @p ostart_price, but orders' id greater than @p ostart_id */ - vector get_account_limit_orders( const string& account_name_or_id, + vector get_account_limit_orders( const string& account_name_or_id, const string &base, const string "e, uint32_t limit = 101, @@ -467,7 +467,7 @@ class database_api * @param limit Maximum number of orders to retrieve * @return The call orders, ordered from earliest to be called to latest */ - vector get_call_orders(const std::string& a, uint32_t limit)const; + vector get_call_orders(const std::string& a, uint32_t limit)const; /** * @brief Get call orders (aka margin positions) of a given account @@ -476,7 +476,7 @@ class database_api * @param limit Maximum number of objects to retrieve * @return The call orders of the account */ - vector get_call_orders_by_account(const std::string& account_name_or_id, + vector get_call_orders_by_account(const std::string& account_name_or_id, asset_id_type start, uint32_t limit)const; /** @@ -485,7 +485,7 @@ class database_api * @param limit Maximum number of orders to retrieve * @return The settle orders, ordered from earliest settlement date to latest */ - vector get_settle_orders(const std::string& a, uint32_t limit)const; + vector get_settle_orders(const std::string& a, uint32_t limit)const; /** * @brief Get forced settlement orders of a given account @@ -494,7 +494,7 @@ class database_api * @param limit Maximum number of orders to retrieve * @return The settle orders of the account */ - vector get_settle_orders_by_account( const std::string& account_name_or_id, + vector get_settle_orders_by_account( const std::string& account_name_or_id, force_settlement_id_type start, uint32_t limit )const; @@ -505,7 +505,7 @@ class database_api * @param start skip that many results * @return The settle orders, ordered from earliest settlement date to latest */ - vector get_collateral_bids(const std::string& a, uint32_t limit, uint32_t start)const; + vector get_collateral_bids(const std::string& a, uint32_t limit, uint32_t start)const; /** * @brief Get all open margin positions of a given account @@ -514,7 +514,7 @@ class database_api * * Similar to @ref get_call_orders_by_account, but without pagination. */ - vector get_margin_positions( const std::string account_name_or_id )const; + vector get_margin_positions( const std::string account_name_or_id )const; /** * @brief Request notification when the active orders in the market between two assets changes @@ -854,7 +854,7 @@ class database_api * (see @ref set_auto_subscription) * @return HTLC object for the id */ - optional get_htlc( htlc_id_type id, optional subscribe = optional() ) const; + optional get_htlc( htlc_id_type id, optional subscribe = optional() ) const; /** * @brief Get non expired HTLC objects using the sender account @@ -863,7 +863,7 @@ class database_api * @param limit Maximum number of objects to retrieve * @return HTLC objects for the account */ - vector get_htlc_by_from( const std::string account_name_or_id, + vector get_htlc_by_from( const std::string account_name_or_id, htlc_id_type start, uint32_t limit ) const; @@ -874,7 +874,7 @@ class database_api * @param limit Maximum number of objects to retrieve * @return HTLC objects for the account */ - vector get_htlc_by_to( const std::string account_name_or_id, + vector get_htlc_by_to( const std::string account_name_or_id, htlc_id_type start, uint32_t limit ) const; @@ -884,7 +884,7 @@ class database_api * @param limit Maximum number of htlc objects to fetch * @return The htlc object list */ - vector list_htlcs(const htlc_id_type start, uint32_t limit) const; + vector list_htlcs(const htlc_id_type start, uint32_t limit) const; private: diff --git a/libraries/chain/account_object.cpp b/libraries/chain/account_object.cpp index 963e12f534..5a67e300dc 100644 --- a/libraries/chain/account_object.cpp +++ b/libraries/chain/account_object.cpp @@ -377,27 +377,10 @@ FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::account_object, (allowed_assets) ) -FC_REFLECT_DERIVED( graphene::chain::account_balance_master, - (graphene::db::object), - (owner)(maintenance_flag) ) - FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::account_balance_object, (graphene::chain::account_balance_master), (balance) ) -FC_REFLECT_DERIVED( graphene::chain::account_statistics_master, - (graphene::db::object), - (owner)(name) - (most_recent_op) - (total_ops)(removed_ops) - (total_core_in_orders) - (core_in_balance) - (has_cashback_vb) - (is_voting) - (last_vote_time) - (lifetime_fees_paid) - ) - FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::account_statistics_object, (graphene::chain::account_statistics_master), (pending_fees)(pending_vested_fees) diff --git a/libraries/chain/include/graphene/chain/account_object.hpp b/libraries/chain/include/graphene/chain/account_object.hpp index 87bb145f44..5661c3bc20 100644 --- a/libraries/chain/include/graphene/chain/account_object.hpp +++ b/libraries/chain/include/graphene/chain/account_object.hpp @@ -452,6 +452,23 @@ MAP_OBJECT_ID_TO_TYPE(graphene::chain::account_object) MAP_OBJECT_ID_TO_TYPE(graphene::chain::account_balance_object) MAP_OBJECT_ID_TO_TYPE(graphene::chain::account_statistics_object) +FC_REFLECT_DERIVED( graphene::chain::account_balance_master, + (graphene::db::object), + (owner)(maintenance_flag) ) + +FC_REFLECT_DERIVED( graphene::chain::account_statistics_master, + (graphene::db::object), + (owner)(name) + (most_recent_op) + (total_ops)(removed_ops) + (total_core_in_orders) + (core_in_balance) + (has_cashback_vb) + (is_voting) + (last_vote_time) + (lifetime_fees_paid) + ) + FC_REFLECT_TYPENAME( graphene::chain::account_object ) FC_REFLECT_TYPENAME( graphene::chain::account_balance_object ) FC_REFLECT_TYPENAME( graphene::chain::account_statistics_object ) diff --git a/libraries/chain/include/graphene/chain/balance_object.hpp b/libraries/chain/include/graphene/chain/balance_object.hpp index 1d5eb056c4..cc97f8a42c 100644 --- a/libraries/chain/include/graphene/chain/balance_object.hpp +++ b/libraries/chain/include/graphene/chain/balance_object.hpp @@ -36,6 +36,12 @@ namespace graphene { namespace chain { bool is_vesting_balance()const { return vesting_policy.valid(); } + asset available( const asset& balance, const fc::time_point_sec now )const + { + return is_vesting_balance()? vesting_policy->get_allowed_withdraw({balance, now, {}}) + : balance; + } + address owner; optional vesting_policy; time_point_sec last_claim_date; @@ -44,10 +50,9 @@ namespace graphene { namespace chain { class balance_object : public balance_master { public: - asset available(fc::time_point_sec now)const + asset available(const fc::time_point_sec now)const { - return is_vesting_balance()? vesting_policy->get_allowed_withdraw({balance.get_value(), now, {}}) - : balance.get_value(); + return balance_master::available( balance.get_value(), now ); } stored_value balance; @@ -84,6 +89,9 @@ namespace graphene { namespace chain { MAP_OBJECT_ID_TO_TYPE(graphene::chain::balance_object) +FC_REFLECT_DERIVED( graphene::chain::balance_master, (graphene::db::object), + (owner)(vesting_policy)(last_claim_date) ) + FC_REFLECT_TYPENAME( graphene::chain::balance_object ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::balance_master ) diff --git a/libraries/chain/include/graphene/chain/global_property_object.hpp b/libraries/chain/include/graphene/chain/global_property_object.hpp index ee9aee6c67..ff841991ba 100644 --- a/libraries/chain/include/graphene/chain/global_property_object.hpp +++ b/libraries/chain/include/graphene/chain/global_property_object.hpp @@ -133,6 +133,21 @@ namespace graphene { namespace chain { MAP_OBJECT_ID_TO_TYPE(graphene::chain::dynamic_global_property_object) MAP_OBJECT_ID_TO_TYPE(graphene::chain::global_property_object) +FC_REFLECT_DERIVED( graphene::chain::dynamic_global_property_master, (graphene::db::object), + (head_block_number) + (head_block_id) + (time) + (current_witness) + (next_maintenance_time) + (last_budget_time) + (accounts_registered_this_interval) + (recently_missed_count) + (current_aslot) + (recent_slots_filled) + (dynamic_flags) + (last_irreversible_block_num) + ) + FC_REFLECT_TYPENAME( graphene::chain::dynamic_global_property_object ) FC_REFLECT_TYPENAME( graphene::chain::global_property_object ) diff --git a/libraries/chain/include/graphene/chain/htlc_object.hpp b/libraries/chain/include/graphene/chain/htlc_object.hpp index cd31ab045b..424e976f5c 100644 --- a/libraries/chain/include/graphene/chain/htlc_object.hpp +++ b/libraries/chain/include/graphene/chain/htlc_object.hpp @@ -126,9 +126,15 @@ namespace graphene { namespace chain { MAP_OBJECT_ID_TO_TYPE(graphene::chain::htlc_object) -FC_REFLECT_TYPENAME( graphene::chain::htlc_object::condition_info::hash_lock_info ) -FC_REFLECT_TYPENAME( graphene::chain::htlc_object::condition_info::time_lock_info ) -FC_REFLECT_TYPENAME( graphene::chain::htlc_object::condition_info ) +FC_REFLECT( graphene::chain::htlc_master::transfer_info_master, (from)(to) ) +FC_REFLECT( graphene::chain::htlc_master::condition_info::hash_lock_info, + (preimage_hash) (preimage_size) ) +FC_REFLECT( graphene::chain::htlc_master::condition_info::time_lock_info, + (expiration) ) +FC_REFLECT( graphene::chain::htlc_master::condition_info, + (hash_lock)(time_lock) ) +FC_REFLECT_DERIVED( graphene::chain::htlc_master, (graphene::db::object), (conditions) ) + FC_REFLECT_TYPENAME( graphene::chain::htlc_object ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::htlc_master ) diff --git a/libraries/chain/include/graphene/chain/market_object.hpp b/libraries/chain/include/graphene/chain/market_object.hpp index e2fded3467..b6e2d63cf3 100644 --- a/libraries/chain/include/graphene/chain/market_object.hpp +++ b/libraries/chain/include/graphene/chain/market_object.hpp @@ -313,6 +313,19 @@ MAP_OBJECT_ID_TO_TYPE(graphene::chain::call_order_object) MAP_OBJECT_ID_TO_TYPE(graphene::chain::force_settlement_object) MAP_OBJECT_ID_TO_TYPE(graphene::chain::collateral_bid_object) +FC_REFLECT_DERIVED( graphene::chain::limit_order_master, + (graphene::db::object), + (expiration)(seller)(sell_price) + ) +FC_REFLECT_DERIVED( graphene::chain::call_order_master, (graphene::db::object), + (borrower)(call_price)(target_collateral_ratio) ) +FC_REFLECT_DERIVED( graphene::chain::force_settlement_master, + (graphene::db::object), + (owner)(settlement_date) + ) +FC_REFLECT_DERIVED( graphene::chain::collateral_bid_master, (graphene::db::object), + (bidder)(debt_covered) ) + FC_REFLECT_TYPENAME( graphene::chain::limit_order_object ) FC_REFLECT_TYPENAME( graphene::chain::call_order_object ) FC_REFLECT_TYPENAME( graphene::chain::force_settlement_object ) diff --git a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp index ef2fb89a9f..9ca9279035 100644 --- a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp +++ b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp @@ -161,6 +161,11 @@ namespace graphene { namespace chain { vesting_policy policy; /// type of the vesting balance vesting_balance_type balance_type = vesting_balance_type::unspecified; + + /** + * Get amount of allowed withdrawal. + */ + asset get_allowed_withdraw(const asset& balance, const time_point_sec& now )const; }; class vesting_balance_object : public vesting_balance_master diff --git a/libraries/chain/market_object.cpp b/libraries/chain/market_object.cpp index eb0c213215..a8d9abdd60 100644 --- a/libraries/chain/market_object.cpp +++ b/libraries/chain/market_object.cpp @@ -414,31 +414,19 @@ void collateral_bid_object::restore( object& obj ) } } // graphene::chain -FC_REFLECT_DERIVED( graphene::chain::limit_order_master, - (graphene::db::object), - (expiration)(seller)(sell_price) - ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::limit_order_object, (graphene::chain::limit_order_master), (for_sale)(deferred_fee)(deferred_paid_fee) ) -FC_REFLECT_DERIVED( graphene::chain::call_order_master, (graphene::db::object), - (borrower)(call_price)(target_collateral_ratio) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::call_order_object, (graphene::chain::call_order_master), (debt)(collateral) ) -FC_REFLECT_DERIVED( graphene::chain::force_settlement_master, - (graphene::db::object), - (owner)(settlement_date) - ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::force_settlement_object, (graphene::chain::force_settlement_master), (balance) ) -FC_REFLECT_DERIVED( graphene::chain::collateral_bid_master, (graphene::db::object), - (bidder)(debt_covered) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::collateral_bid_object, (graphene::chain::collateral_bid_master), (collateral_offered) ) diff --git a/libraries/chain/small_objects.cpp b/libraries/chain/small_objects.cpp index 1c55180c26..e0ef2363e8 100644 --- a/libraries/chain/small_objects.cpp +++ b/libraries/chain/small_objects.cpp @@ -126,8 +126,6 @@ void htlc_object::restore( object& obj ) } } // graphene::chain -FC_REFLECT_DERIVED( graphene::chain::balance_master, (graphene::db::object), - (owner)(vesting_policy)(last_claim_date) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::balance_object, (graphene::chain::balance_master), (balance) ) @@ -175,20 +173,6 @@ FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::committee_member_object, (graph FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::blinded_balance_object, (graphene::db::object), (commitment)(asset_id)(owner) ) -FC_REFLECT_DERIVED( graphene::chain::dynamic_global_property_master, (graphene::db::object), - (head_block_number) - (head_block_id) - (time) - (current_witness) - (next_maintenance_time) - (last_budget_time) - (accounts_registered_this_interval) - (recently_missed_count) - (current_aslot) - (recent_slots_filled) - (dynamic_flags) - (last_irreversible_block_num) - ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::dynamic_global_property_object, (graphene::chain::dynamic_global_property_master), (witness_budget) ) @@ -201,15 +185,6 @@ FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::global_property_object, (graphe (active_witnesses) ) -FC_REFLECT( graphene::chain::htlc_master::transfer_info_master, (from)(to) ) -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::htlc_object::condition_info::hash_lock_info, BOOST_PP_SEQ_NIL, - (preimage_hash) (preimage_size) ) -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::htlc_object::condition_info::time_lock_info, BOOST_PP_SEQ_NIL, - (expiration) ) -FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::htlc_object::condition_info, BOOST_PP_SEQ_NIL, - (hash_lock)(time_lock) ) -FC_REFLECT_DERIVED( graphene::chain::htlc_master, (graphene::db::object), - (conditions) ) FC_REFLECT_DERIVED( graphene::chain::htlc_object::transfer_info, (graphene::chain::htlc_master::transfer_info_master), (amount) ) diff --git a/libraries/chain/vesting_balance_object.cpp b/libraries/chain/vesting_balance_object.cpp index 4e4bdd6442..f0d366118f 100644 --- a/libraries/chain/vesting_balance_object.cpp +++ b/libraries/chain/vesting_balance_object.cpp @@ -264,9 +264,14 @@ stored_value vesting_balance_object::withdraw(const time_point_sec& now, const a return balance.split( amount.amount ); } +asset vesting_balance_master::get_allowed_withdraw( const asset& balance, const time_point_sec& now )const +{ + return policy.visit(get_allowed_withdraw_visitor(balance, now, asset())); +} + asset vesting_balance_object::get_allowed_withdraw(const time_point_sec& now)const { - return policy.visit(get_allowed_withdraw_visitor(balance.get_value(), now, asset())); + return vesting_balance_master::get_allowed_withdraw( balance.get_value(), now ); } class vesting_balance_backup : public vesting_balance_master diff --git a/libraries/plugins/delayed_node/delayed_node_plugin.cpp b/libraries/plugins/delayed_node/delayed_node_plugin.cpp index 01f4e48b31..0218120a13 100644 --- a/libraries/plugins/delayed_node/delayed_node_plugin.cpp +++ b/libraries/plugins/delayed_node/delayed_node_plugin.cpp @@ -86,7 +86,7 @@ void delayed_node_plugin::sync_with_trusted_node() uint32_t pass_count = 0; while( true ) { - graphene::chain::dynamic_global_property_object remote_dpo = my->database_api->get_dynamic_global_properties(); + auto remote_dpo = my->database_api->get_dynamic_global_properties(); if( remote_dpo.last_irreversible_block_num <= db.head_block_num() ) { if( remote_dpo.last_irreversible_block_num < db.head_block_num() ) diff --git a/libraries/plugins/es_objects/es_objects.cpp b/libraries/plugins/es_objects/es_objects.cpp index a2c332e9f1..1cb1e82ea4 100644 --- a/libraries/plugins/es_objects/es_objects.cpp +++ b/libraries/plugins/es_objects/es_objects.cpp @@ -74,7 +74,7 @@ class es_objects_plugin_impl private: template - void prepareTemplate(T blockchain_object, string index_name); + void prepareTemplate(const T& blockchain_object, string index_name); }; bool es_objects_plugin_impl::genesis() @@ -234,7 +234,7 @@ void es_objects_plugin_impl::remove_from_database( object_id_type id, std::strin } template -void es_objects_plugin_impl::prepareTemplate(T blockchain_object, string index_name) +void es_objects_plugin_impl::prepareTemplate(const T& blockchain_object, string index_name) { fc::mutable_variant_object bulk_header; bulk_header["_index"] = _es_objects_index_prefix + index_name; diff --git a/libraries/wallet/include/graphene/wallet/wallet.hpp b/libraries/wallet/include/graphene/wallet/wallet.hpp index 217b2ff862..d7bc6d2adc 100644 --- a/libraries/wallet/include/graphene/wallet/wallet.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet.hpp @@ -24,7 +24,6 @@ #pragma once #include -#include #include #include #include "wallet_structs.hpp" @@ -180,7 +179,7 @@ class wallet_api * if \c ostart_id is specified and valid, its price will be used to do page query preferentially, * otherwise the \c ostart_price will be used */ - vector get_account_limit_orders( const string& name_or_id, + vector get_account_limit_orders( const string& name_or_id, const string &base, const string "e, uint32_t limit = 101, @@ -194,7 +193,7 @@ class wallet_api * @param limit Maximum number of orders to retrieve * @return The limit orders, ordered from least price to greatest */ - vector get_limit_orders(string a, string b, uint32_t limit)const; + vector get_limit_orders(string a, string b, uint32_t limit)const; /** * @brief Get call orders (aka margin positions) for a given asset @@ -202,7 +201,7 @@ class wallet_api * @param limit Maximum number of orders to retrieve * @return The call orders, ordered from earliest to be called to latest */ - vector get_call_orders(string a, uint32_t limit)const; + vector get_call_orders(string a, uint32_t limit)const; /** * @brief Get forced settlement orders in a given asset @@ -210,7 +209,7 @@ class wallet_api * @param limit Maximum number of orders to retrieve * @return The settle orders, ordered from earliest settlement date to latest */ - vector get_settle_orders(string a, uint32_t limit)const; + vector get_settle_orders(string a, uint32_t limit)const; /** Returns the collateral_bid object for the given MPA * @@ -219,7 +218,7 @@ class wallet_api * @param start the sequence number where to start looping back throw the history * @returns a list of \c collateral_bid_objects */ - vector get_collateral_bids(string asset, uint32_t limit = 100, uint32_t start = 0)const; + vector get_collateral_bids(string asset, uint32_t limit = 100, uint32_t start = 0)const; /** Returns the block chain's slowly-changing settings. * This object contains all of the properties of the blockchain that are fixed @@ -250,7 +249,7 @@ class wallet_api * @see \c get_global_properties() for less-frequently changing properties * @returns the dynamic global properties */ - dynamic_global_property_object get_dynamic_global_properties() const; + graphene::app::dynamic_global_property_api_object get_dynamic_global_properties() const; /** Returns information about the given account. * @@ -271,7 +270,7 @@ class wallet_api * @param asset_name_or_id the symbol or id of the BitAsset in question * @returns the BitAsset-specific data for this asset */ - asset_bitasset_data_object get_bitasset_data(string asset_name_or_id)const; + variant get_bitasset_data(string asset_name_or_id)const; /** * Returns information about the given HTLC object. diff --git a/libraries/wallet/include/graphene/wallet/wallet_structs.hpp b/libraries/wallet/include/graphene/wallet/wallet_structs.hpp index 4c1a19fb7d..63e03efc3f 100644 --- a/libraries/wallet/include/graphene/wallet/wallet_structs.hpp +++ b/libraries/wallet/include/graphene/wallet/wallet_structs.hpp @@ -236,9 +236,9 @@ struct signed_block_with_info : public signed_block vector< transaction_id_type > transaction_ids; }; -struct vesting_balance_object_with_info : public vesting_balance_object +struct vesting_balance_object_with_info : public graphene::app::vesting_balance_api_object { - vesting_balance_object_with_info( const vesting_balance_object& vbo, fc::time_point_sec now ); + vesting_balance_object_with_info( const graphene::app::vesting_balance_api_object& vbo, fc::time_point_sec now ); vesting_balance_object_with_info( const vesting_balance_object_with_info& vbo ) = default; /** @@ -375,7 +375,8 @@ FC_REFLECT( graphene::wallet::worker_vote_delta, FC_REFLECT_DERIVED( graphene::wallet::signed_block_with_info, (graphene::chain::signed_block), (block_id)(signing_key)(transaction_ids) ) -FC_REFLECT_DERIVED( graphene::wallet::vesting_balance_object_with_info, (graphene::chain::vesting_balance_object), +FC_REFLECT_DERIVED( graphene::wallet::vesting_balance_object_with_info, + (graphene::app::vesting_balance_api_object), (allowed_withdraw)(allowed_withdraw_time) ) FC_REFLECT( graphene::wallet::operation_detail, diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 927e4a803d..d06f3f1cc6 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -210,10 +210,10 @@ signed_transaction wallet_api::htlc_create( string source, string destination, s fc::optional wallet_api::get_htlc(std::string htlc_id) const { - fc::optional optional_obj = my->get_htlc(htlc_id); + fc::optional optional_obj = my->get_htlc(htlc_id); if ( optional_obj.valid() ) { - const htlc_object& obj = *optional_obj; + const auto& obj = *optional_obj; // convert to formatted variant fc::mutable_variant_object transfer; const auto& from = my->get_account( obj.transfer.from ); @@ -426,7 +426,7 @@ vector wallet_api::get_market_history( return my->_remote_hist->get_market_history( symbol1, symbol2, bucket, start, end ); } -vector wallet_api::get_account_limit_orders( +vector wallet_api::get_account_limit_orders( const string& name_or_id, const string &base, const string "e, @@ -437,22 +437,22 @@ vector wallet_api::get_account_limit_orders( return my->_remote_db->get_account_limit_orders(name_or_id, base, quote, limit, ostart_id, ostart_price); } -vector wallet_api::get_limit_orders(std::string a, std::string b, uint32_t limit)const +vector wallet_api::get_limit_orders(std::string a, std::string b, uint32_t limit)const { return my->_remote_db->get_limit_orders(a, b, limit); } -vector wallet_api::get_call_orders(std::string a, uint32_t limit)const +vector wallet_api::get_call_orders(std::string a, uint32_t limit)const { return my->_remote_db->get_call_orders(a, limit); } -vector wallet_api::get_settle_orders(std::string a, uint32_t limit)const +vector wallet_api::get_settle_orders(std::string a, uint32_t limit)const { return my->_remote_db->get_settle_orders(a, limit); } -vector wallet_api::get_collateral_bids(std::string asset, uint32_t limit, uint32_t start)const +vector wallet_api::get_collateral_bids(std::string asset, uint32_t limit, uint32_t start)const { return my->_remote_db->get_collateral_bids(asset, limit, start); } @@ -567,11 +567,11 @@ extended_asset_object wallet_api::get_asset(string asset_name_or_id) const return *a; } -asset_bitasset_data_object wallet_api::get_bitasset_data(string asset_name_or_id) const +variant wallet_api::get_bitasset_data(string asset_name_or_id) const { auto asset = get_asset(asset_name_or_id); FC_ASSERT(asset.is_market_issued() && asset.bitasset_data_id); - return my->get_object(*asset.bitasset_data_id); + return my->_remote_db->get_objects({*asset.bitasset_data_id}, {}).front();; } account_id_type wallet_api::get_account_id(string account_name_or_id) const @@ -1097,7 +1097,7 @@ global_property_object wallet_api::get_global_properties() const return my->get_global_properties(); } -dynamic_global_property_object wallet_api::get_dynamic_global_properties() const +dynamic_global_property_api_object wallet_api::get_dynamic_global_properties() const { return my->get_dynamic_global_properties(); } @@ -1920,11 +1920,11 @@ signed_block_with_info::signed_block_with_info( const signed_block& block ) } vesting_balance_object_with_info::vesting_balance_object_with_info( - const vesting_balance_object& vbo, + const vesting_balance_api_object& vbo, fc::time_point_sec now ) - : vesting_balance_object( vbo ) + : vesting_balance_api_object( vbo ) { - allowed_withdraw = get_allowed_withdraw( now ); + allowed_withdraw = get_allowed_withdraw( balance, now ); allowed_withdraw_time = now; } diff --git a/libraries/wallet/wallet_account.cpp b/libraries/wallet/wallet_account.cpp index 477de41d4b..8e409fd7ad 100644 --- a/libraries/wallet/wallet_account.cpp +++ b/libraries/wallet/wallet_account.cpp @@ -300,11 +300,11 @@ namespace graphene { namespace wallet { namespace detail { return result; } - vector< vesting_balance_object > vbos = _remote_db->get_vesting_balances( account_name ); + vector< vesting_balance_api_object > vbos = _remote_db->get_vesting_balances( account_name ); if( vbos.size() == 0 ) return result; - for( const vesting_balance_object& vbo : vbos ) + for( const auto& vbo : vbos ) result.emplace_back( vbo, now ); return result; @@ -315,7 +315,7 @@ namespace graphene { namespace wallet { namespace detail { const vector& wif_keys, bool broadcast ) { try { FC_ASSERT(!is_locked()); - const dynamic_global_property_object& dpo = _remote_db->get_dynamic_global_properties(); + const auto dpo = _remote_db->get_dynamic_global_properties(); account_object claimer = get_account( name_or_id ); uint32_t max_ops_per_tx = 30; @@ -365,11 +365,11 @@ namespace graphene { namespace wallet { namespace detail { } } - vector< balance_object > balances = _remote_db->get_balance_objects( addrs ); + vector< balance_api_object > balances = _remote_db->get_balance_objects( addrs ); addrs.clear(); set bal_types; - for( auto b : balances ) bal_types.insert( b.balance.asset_id ); + for( const auto& b : balances ) bal_types.insert( b.balance.asset_id ); struct claim_tx { @@ -382,11 +382,11 @@ namespace graphene { namespace wallet { namespace detail { { balance_claim_operation op; op.deposit_to_account = claimer.id; - for( const balance_object& b : balances ) + for( const auto& b : balances ) { if( b.balance.asset_id == a ) { - op.total_claimed = b.available( dpo.time ); + op.total_claimed = b.available( b.balance, dpo.time ); if( op.total_claimed.amount == 0 ) continue; op.balance_to_claim = b.id; diff --git a/libraries/wallet/wallet_api_impl.cpp b/libraries/wallet/wallet_api_impl.cpp index 5d23c20be4..4abeedea68 100644 --- a/libraries/wallet/wallet_api_impl.cpp +++ b/libraries/wallet/wallet_api_impl.cpp @@ -172,7 +172,7 @@ namespace graphene { namespace wallet { namespace detail { { return _remote_db->get_global_properties(); } - dynamic_global_property_object wallet_api_impl::get_dynamic_global_properties() const + graphene::app::dynamic_global_property_api_object wallet_api_impl::get_dynamic_global_properties() const { return _remote_db->get_dynamic_global_properties(); } diff --git a/libraries/wallet/wallet_api_impl.hpp b/libraries/wallet/wallet_api_impl.hpp index 6bbb50acbc..8edf8cb580 100644 --- a/libraries/wallet/wallet_api_impl.hpp +++ b/libraries/wallet/wallet_api_impl.hpp @@ -151,7 +151,7 @@ class wallet_api_impl chain_property_object get_chain_properties() const; global_property_object get_global_properties() const; - dynamic_global_property_object get_dynamic_global_properties() const; + graphene::app::dynamic_global_property_api_object get_dynamic_global_properties() const; account_object get_account(account_id_type id) const; account_object get_account(string account_name_or_id) const; @@ -167,7 +167,7 @@ class wallet_api_impl extended_asset_object get_asset(string asset_symbol_or_id)const; - fc::optional get_htlc(string htlc_id) const; + fc::optional get_htlc(string htlc_id) const; asset_id_type get_asset_id(string asset_symbol_or_id) const; diff --git a/libraries/wallet/wallet_builder.cpp b/libraries/wallet/wallet_builder.cpp index dbcbe12c5d..ddbb96cd26 100644 --- a/libraries/wallet/wallet_builder.cpp +++ b/libraries/wallet/wallet_builder.cpp @@ -62,7 +62,7 @@ namespace graphene { namespace wallet { namespace detail { total_fee += gprops.get_current_fees().set_fee( op, fee_asset_obj.options.core_exchange_rate ); FC_ASSERT((total_fee * fee_asset_obj.options.core_exchange_rate).amount <= - get_object(fee_asset_obj.dynamic_asset_data_id).fee_pool, + get_object(fee_asset_obj.dynamic_asset_data_id).fee_pool.get_amount(), // FIXME "Cannot pay fees in ${asset}, as this asset's fee pool is insufficiently funded.", ("asset", fee_asset_obj.symbol)); } else { diff --git a/libraries/wallet/wallet_transfer.cpp b/libraries/wallet/wallet_transfer.cpp index 7228cec5dc..7a4dd0f6c9 100644 --- a/libraries/wallet/wallet_transfer.cpp +++ b/libraries/wallet/wallet_transfer.cpp @@ -115,7 +115,7 @@ namespace graphene { namespace wallet { namespace detail { try { FC_ASSERT( !self.is_locked() ); - fc::optional htlc_obj = get_htlc(htlc_id); + fc::optional htlc_obj = get_htlc(htlc_id); FC_ASSERT(htlc_obj, "Could not find HTLC matching ${htlc}", ("htlc", htlc_id)); account_object issuer_obj = get_account(issuer); @@ -140,7 +140,7 @@ namespace graphene { namespace wallet { namespace detail { try { FC_ASSERT( !self.is_locked() ); - fc::optional htlc_obj = get_htlc(htlc_id); + fc::optional htlc_obj = get_htlc(htlc_id); FC_ASSERT(htlc_obj, "Could not find HTLC matching ${htlc}", ("htlc", htlc_id)); account_object issuer_obj = get_account(issuer); @@ -159,7 +159,7 @@ namespace graphene { namespace wallet { namespace detail { } FC_CAPTURE_AND_RETHROW( (htlc_id)(issuer)(seconds_to_add)(broadcast) ) } - fc::optional wallet_api_impl::get_htlc(string htlc_id) const + fc::optional wallet_api_impl::get_htlc(string htlc_id) const { htlc_id_type id; fc::from_variant(htlc_id, id); From 6c32c85d081a3875def20b483fc0b993d0b14e67 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Wed, 4 Dec 2019 16:11:51 +0100 Subject: [PATCH 14/59] Tests compile but crash horribly --- .../include/graphene/chain/fba_object.hpp | 1 + tests/app/main.cpp | 2 +- tests/cli/main.cpp | 3 +- tests/common/database_fixture.cpp | 38 +- tests/tests/block_tests.cpp | 2 +- tests/tests/call_order_tests.cpp | 44 +- tests/tests/database_api_tests.cpp | 18 +- tests/tests/database_tests.cpp | 17 +- tests/tests/fee_tests.cpp | 432 +++++++-------- tests/tests/market_fee_sharing_tests.cpp | 12 +- tests/tests/market_rounding_tests.cpp | 188 +++---- tests/tests/market_tests.cpp | 364 ++++++------- tests/tests/operation_tests.cpp | 64 +-- tests/tests/operation_tests2.cpp | 54 +- tests/tests/settle_tests.cpp | 494 +++++++++--------- tests/tests/smartcoin_tests.cpp | 39 +- tests/tests/swan_tests.cpp | 22 +- tests/tests/uia_tests.cpp | 6 +- tests/tests/voting_tests.cpp | 12 +- 19 files changed, 905 insertions(+), 907 deletions(-) diff --git a/libraries/chain/include/graphene/chain/fba_object.hpp b/libraries/chain/include/graphene/chain/fba_object.hpp index 8961e9425a..23c4c5de81 100644 --- a/libraries/chain/include/graphene/chain/fba_object.hpp +++ b/libraries/chain/include/graphene/chain/fba_object.hpp @@ -24,6 +24,7 @@ #pragma once #include +#include #include namespace graphene { namespace chain { diff --git a/tests/app/main.cpp b/tests/app/main.cpp index bd7905870d..6f9c110db0 100644 --- a/tests/app/main.cpp +++ b/tests/app/main.cpp @@ -278,7 +278,7 @@ BOOST_AUTO_TEST_CASE( two_node_network ) claim_op.deposit_to_account = nathan_id; claim_op.balance_to_claim = bid; claim_op.balance_owner_key = nathan_key.get_public_key(); - claim_op.total_claimed = bid(*db1).balance; + claim_op.total_claimed = bid(*db1).balance.get_value(); trx.operations.push_back( claim_op ); db1->current_fee_schedule().set_fee( trx.operations.back() ); diff --git a/tests/cli/main.cpp b/tests/cli/main.cpp index baf3852ba7..90082b39c1 100644 --- a/tests/cli/main.cpp +++ b/tests/cli/main.cpp @@ -689,7 +689,7 @@ BOOST_FIXTURE_TEST_CASE( cli_confidential_tx_test, cli_fixture ) // ** Check head block: BOOST_TEST_MESSAGE("Check that all expected blocks have processed"); - dynamic_global_property_object dgp = W.get_dynamic_global_properties(); + graphene::app::dynamic_global_property_api_object dgp = W.get_dynamic_global_properties(); BOOST_CHECK(dgp.head_block_number == head_block); } catch( fc::exception& e ) { edump((e.to_detail_string())); @@ -809,7 +809,6 @@ BOOST_AUTO_TEST_CASE( cli_multisig_transaction ) // transfer bts from cifer.test to nathan BOOST_TEST_MESSAGE("Transferring bitshares from cifer.test to nathan"); - auto dyn_props = app1->chain_database()->get_dynamic_global_properties(); account_object cifer_test = con.wallet_api_ptr->get_account("cifer.test"); // construct a transfer transaction diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 211957ce2a..3d35b6f11a 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -475,7 +475,7 @@ void database_fixture::verify_asset_supplies( const database& db ) { //wlog("*** Begin asset supply verification ***"); const asset_dynamic_data_object& core_asset_data = db.get_core_asset().dynamic_asset_data_id(db); - BOOST_CHECK(core_asset_data.fee_pool == 0); + BOOST_CHECK(core_asset_data.fee_pool.get_amount() == 0); const auto& statistics_index = db.get_index_type().indices(); const auto& acct_balance_index = db.get_index_type().indices(); @@ -487,23 +487,23 @@ void database_fixture::verify_asset_supplies( const database& db ) share_type reported_core_in_orders; for( const account_balance_object& b : acct_balance_index ) - total_balances[b.asset_type] += b.balance; + total_balances[b.get_asset()] += b.balance.get_amount(); for( const force_settlement_object& s : settle_index ) - total_balances[s.balance.asset_id] += s.balance.amount; + total_balances[s.balance.get_asset()] += s.balance.get_amount(); for( const collateral_bid_object& b : bids ) - total_balances[b.inv_swan_price.base.asset_id] += b.inv_swan_price.base.amount; + total_balances[b.collateral_offered.get_asset()] += b.collateral_offered.get_amount(); for( const account_statistics_object& a : statistics_index ) { reported_core_in_orders += a.total_core_in_orders; - total_balances[asset_id_type()] += a.pending_fees + a.pending_vested_fees; + total_balances[asset_id_type()] += a.pending_fees.get_amount() + a.pending_vested_fees.get_amount(); } for( const limit_order_object& o : db.get_index_type().indices() ) { asset for_sale = o.amount_for_sale(); if( for_sale.asset_id == asset_id_type() ) core_in_orders += for_sale.amount; total_balances[for_sale.asset_id] += for_sale.amount; - total_balances[asset_id_type()] += o.deferred_fee; - total_balances[o.deferred_paid_fee.asset_id] += o.deferred_paid_fee.amount; + total_balances[asset_id_type()] += o.deferred_fee.get_amount(); + total_balances[o.deferred_paid_fee.get_asset()] += o.deferred_paid_fee.get_amount(); } for( const call_order_object& o : db.get_index_type().indices() ) { @@ -515,39 +515,39 @@ void database_fixture::verify_asset_supplies( const database& db ) for( const asset_object& asset_obj : db.get_index_type().indices() ) { const auto& dasset_obj = asset_obj.dynamic_asset_data_id(db); - total_balances[asset_obj.id] += dasset_obj.accumulated_fees; - total_balances[asset_id_type()] += dasset_obj.fee_pool; + total_balances[asset_obj.id] += dasset_obj.accumulated_fees.get_amount(); + total_balances[asset_id_type()] += dasset_obj.fee_pool.get_amount(); if( asset_obj.is_market_issued() ) { const auto& bad = asset_obj.bitasset_data(db); - total_balances[bad.options.short_backing_asset] += bad.settlement_fund; + total_balances[bad.options.short_backing_asset] += bad.settlement_fund.get_amount(); } - total_balances[asset_obj.id] += dasset_obj.confidential_supply.value; + total_balances[asset_obj.id] += dasset_obj.confidential_supply.get_amount(); } for( const vesting_balance_object& vbo : db.get_index_type< vesting_balance_index >().indices() ) - total_balances[ vbo.balance.asset_id ] += vbo.balance.amount; + total_balances[ vbo.balance.get_asset() ] += vbo.balance.get_amount(); for( const fba_accumulator_object& fba : db.get_index_type< simple_index< fba_accumulator_object > >() ) - total_balances[ asset_id_type() ] += fba.accumulated_fba_fees; + total_balances[ asset_id_type() ] += fba.accumulated_fba_fees.get_amount(); for( const balance_object& bo : db.get_index_type< balance_index >().indices() ) - total_balances[ bo.balance.asset_id ] += bo.balance.amount; + total_balances[ bo.balance.get_asset() ] += bo.balance.get_amount(); - total_balances[asset_id_type()] += db.get_dynamic_global_properties().witness_budget; + total_balances[asset_id_type()] += db.get_dynamic_global_properties().witness_budget.get_amount(); for( const auto& item : total_debts ) { - BOOST_CHECK_EQUAL(item.first(db).dynamic_asset_data_id(db).current_supply.value, item.second.value); + BOOST_CHECK_EQUAL(item.first(db).dynamic_asset_data_id(db).current_supply.get_amount().value, item.second.value); } // htlc const auto& htlc_idx = db.get_index_type< htlc_index >().indices().get< by_id >(); for( auto itr = htlc_idx.begin(); itr != htlc_idx.end(); ++itr ) { - total_balances[itr->transfer.asset_id] += itr->transfer.amount; + total_balances[itr->transfer.amount.get_asset()] += itr->transfer.amount.get_amount(); } for( const asset_object& asset_obj : db.get_index_type().indices() ) { - BOOST_CHECK_EQUAL(total_balances[asset_obj.id].value, asset_obj.dynamic_asset_data_id(db).current_supply.value); + BOOST_CHECK_EQUAL(total_balances[asset_obj.id].value, asset_obj.dynamic_asset_data_id(db).current_supply.get_amount().value); } BOOST_CHECK_EQUAL( core_in_orders.value , reported_core_in_orders.value ); @@ -1300,7 +1300,7 @@ void database_fixture::print_market( const string& syma, const string& symb )con while( cur != price_idx.end() ) { cerr << std::setw( 10 ) << std::left << cur->seller(db).name << " "; - cerr << std::setw( 10 ) << std::right << cur->for_sale.value << " "; + cerr << std::setw( 10 ) << std::right << cur->amount_for_sale().amount.value << " "; cerr << std::setw( 5 ) << std::left << cur->amount_for_sale().asset_id(db).symbol << " "; cerr << std::setw( 10 ) << std::right << cur->amount_to_receive().amount.value << " "; cerr << std::setw( 5 ) << std::left << cur->amount_to_receive().asset_id(db).symbol << " "; diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index c36455361f..31a2799823 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -928,7 +928,7 @@ BOOST_FIXTURE_TEST_CASE( limit_order_expiration, database_fixture ) BOOST_CHECK_EQUAL( get_balance(*nathan, *core), 49500 ); auto ptrx_id = ptrx.operation_results.back().get(); - auto limit_index = db.get_index_type().indices(); + auto& limit_index = db.get_index_type().indices(); auto limit_itr = limit_index.begin(); BOOST_REQUIRE( limit_itr != limit_index.end() ); BOOST_REQUIRE( limit_itr->id == ptrx_id ); diff --git a/tests/tests/call_order_tests.cpp b/tests/tests/call_order_tests.cpp index f78ad5e6ca..7ef8514c2a 100644 --- a/tests/tests/call_order_tests.cpp +++ b/tests/tests/call_order_tests.cpp @@ -40,15 +40,22 @@ BOOST_AUTO_TEST_CASE( call_order_object_test ) // assume GRAPHENE_COLLATERAL_RATIO_DENOM is 1000 in this test case BOOST_REQUIRE_EQUAL( 1000, GRAPHENE_COLLATERAL_RATIO_DENOM ); + stored_debt core_debt; + stored_value total_mia( asset_id_type(1) ); // function to create a new call_order_object - auto new_call_obj = []( const share_type c, const share_type d, int16_t mcr, optional tcr = {} ) { + auto new_call_obj = [&core_debt,&total_mia]( const share_type c, const share_type d, int16_t mcr, optional tcr = {} ) { call_order_object o; - o.collateral = c; - o.debt = d; - o.call_price = price::call_price( asset( d, asset_id_type(1)), asset(c) , mcr ); + o.collateral = core_debt.issue(c); + o.debt = stored_debt( asset_id_type(1) ); + total_mia += o.debt.issue(d); + o.call_price = price::call_price( o.debt.get_value(), o.collateral.get_value(), mcr ); o.target_collateral_ratio = tcr; return o; }; + auto clear_call_obj = [&core_debt,&total_mia]( call_order_object& obj ) { + core_debt.burn( std::move(obj.collateral) ); + obj.debt.burn( std::move(total_mia) ); + }; // function to validate result of call_order_object::get_max_debt_to_cover(...) auto validate_result = []( const call_order_object& o, const price& match_price, const price& feed_price, @@ -57,7 +64,7 @@ BOOST_AUTO_TEST_CASE( call_order_object_test ) return 1; BOOST_REQUIRE_GT( result.value, 0 ); - BOOST_REQUIRE_LE( result.value, o.debt.value ); + BOOST_REQUIRE_LE( result.value, o.debt.get_amount().value ); BOOST_REQUIRE( match_price.base.asset_id == o.collateral_type() ); BOOST_REQUIRE( match_price.quote.asset_id == o.debt_type() ); @@ -70,7 +77,7 @@ BOOST_AUTO_TEST_CASE( call_order_object_test ) if( !o.target_collateral_ratio.valid() ) { - BOOST_CHECK_EQUAL( result.value, o.debt.value ); + BOOST_CHECK_EQUAL( result.value, o.debt.get_amount().value ); return 2; } @@ -80,10 +87,10 @@ BOOST_AUTO_TEST_CASE( call_order_object_test ) asset to_cover( result, o.debt_type() ); asset to_pay = o.get_collateral(); - if( result < o.debt ) + if( result < o.debt.get_amount() ) { to_pay = to_cover.multiply_and_round_up( match_price ); - BOOST_CHECK_LT( to_pay.amount.value, o.collateral.value ); // should cover more on black swan event + BOOST_CHECK_LT( to_pay.amount.value, o.collateral.get_amount().value ); // should cover more on black swan event BOOST_CHECK_EQUAL( result.value, (to_pay * match_price).amount.value ); // should not change after rounded down debt to cover // should have target_cr set @@ -120,13 +127,13 @@ BOOST_AUTO_TEST_CASE( call_order_object_test ) sell_less = cover_less.multiply_and_round_up( match_price ); // round up to get collateral to sell if( sell_less.amount <= 0 || cover_less.amount <= 0 ) // unable to sell or cover less, we return { - if( to_pay.amount == o.collateral ) + if( to_pay.amount == o.collateral.get_amount() ) return j; return (j + 10); } } - BOOST_REQUIRE_LT( cover_less.amount.value, o.debt.value ); - BOOST_REQUIRE_LT( sell_less.amount.value, o.collateral.value ); + BOOST_REQUIRE_LT( cover_less.amount.value, o.debt.get_amount().value ); + BOOST_REQUIRE_LT( sell_less.amount.value, o.collateral.get_amount().value ); price tmp_tcr_call_price = price::call_price( o.get_debt() - cover_less, o.get_collateral() - sell_less, tcr ); price tmp_mcr_call_price = price::call_price( o.get_debt() - cover_less, o.get_collateral() - sell_less, mcr ); bool cover_less_is_enough = ( tmp_tcr_call_price > feed_price && tmp_mcr_call_price > feed_price ); @@ -134,7 +141,7 @@ BOOST_AUTO_TEST_CASE( call_order_object_test ) { if( !last_check ) continue; - if( to_pay.amount == o.collateral ) + if( to_pay.amount == o.collateral.get_amount() ) return j; return (j + 10); } @@ -147,7 +154,7 @@ BOOST_AUTO_TEST_CASE( call_order_object_test ) break; } } - if( to_pay.amount == o.collateral ) + if( to_pay.amount == o.collateral.get_amount() ) return j; return (j + 10); }; @@ -168,48 +175,56 @@ BOOST_AUTO_TEST_CASE( call_order_object_test ) result = obj.get_max_debt_to_cover( mp, fp, mcr ); BOOST_CHECK_EQUAL( result.value, expected ); validate_result( obj, mp, fp, mcr, result ); + clear_call_obj(obj); obj = new_call_obj( 1751, 1000, mcr, 10000 ); // order is not in margin call territory expected = 0; result = obj.get_max_debt_to_cover( mp, fp, mcr ); BOOST_CHECK_EQUAL( result.value, expected ); validate_result( obj, mp, fp, mcr, result ); + clear_call_obj(obj); obj = new_call_obj( 160, 100, mcr ); // target_cr is not set expected = 100; result = obj.get_max_debt_to_cover( mp, fp, mcr ); BOOST_CHECK_EQUAL( result.value, expected ); validate_result( obj, mp, fp, mcr, result ); + clear_call_obj(obj); obj = new_call_obj( 1009, 1000, mcr, 200 ); // target_cr set, but order is in black swan territory expected = 1000; result = obj.get_max_debt_to_cover( mp, fp, mcr ); BOOST_CHECK_EQUAL( result.value, expected ); validate_result( obj, mp, fp, mcr, result ); + clear_call_obj(obj); obj = new_call_obj( 1499, 999, mcr, 1600 ); // target_cr is 160%, less than 175%, so use 175% expected = 385; result = obj.get_max_debt_to_cover( mp, fp, mcr ); BOOST_CHECK_EQUAL( result.value, expected ); validate_result( obj, mp, fp, mcr, result ); + clear_call_obj(obj); obj = new_call_obj( 1500, 1000, mcr, 1800 ); // target_cr is 180% expected = 429; result = obj.get_max_debt_to_cover( mp, fp, mcr ); BOOST_CHECK_EQUAL( result.value, expected ); validate_result( obj, mp, fp, mcr, result ); + clear_call_obj(obj); obj = new_call_obj( 1501, 1001, mcr, 2000 ); // target_cr is 200% expected = 558; result = obj.get_max_debt_to_cover( mp, fp, mcr ); BOOST_CHECK_EQUAL( result.value, expected ); validate_result( obj, mp, fp, mcr, result ); + clear_call_obj(obj); obj = new_call_obj( 1502, 1002, mcr, 3000 ); // target_cr is 300% expected = 793; result = obj.get_max_debt_to_cover( mp, fp, mcr ); BOOST_CHECK_EQUAL( result.value, expected ); validate_result( obj, mp, fp, mcr, result ); + clear_call_obj(obj); mcr = 1750; mp = price( asset(40009), asset(79070, asset_id_type(1)) ); // match_price @@ -218,6 +233,7 @@ BOOST_AUTO_TEST_CASE( call_order_object_test ) obj = new_call_obj( 557197, 701502, mcr, 1700 ); // target_cr is less than mcr result = obj.get_max_debt_to_cover( mp, fp, mcr ); validate_result( obj, mp, fp, mcr, result ); + clear_call_obj(obj); mcr = 1455; mp = price( asset(1150171), asset(985450, asset_id_type(1)) ); // match_price @@ -226,6 +242,7 @@ BOOST_AUTO_TEST_CASE( call_order_object_test ) obj = new_call_obj( 423536, 302688, mcr, 200 ); // target_cr is less than mcr result = obj.get_max_debt_to_cover( mp, fp, mcr ); validate_result( obj, mp, fp, mcr, result ); + clear_call_obj(obj); // random tests std::mt19937_64 gen( time(NULL) ); @@ -337,6 +354,7 @@ BOOST_AUTO_TEST_CASE( call_order_object_test ) BOOST_CHECK( e.to_detail_string().find( "result <= GRAPHENE_MAX_SHARE_SUPPLY" ) != string::npos ); ++count[0]; } + clear_call_obj(obj); } ilog( "count: [bad_input,sell zero,not set," " sell full (perfect), sell full (<0.01%), sell full (<0.1%),sell full (<1%), sell full (other), ...," diff --git a/tests/tests/database_api_tests.cpp b/tests/tests/database_api_tests.cpp index 31f03e7781..2842dcceba 100644 --- a/tests/tests/database_api_tests.cpp +++ b/tests/tests/database_api_tests.cpp @@ -1134,8 +1134,8 @@ BOOST_AUTO_TEST_CASE(get_account_limit_orders) BOOST_CHECK(create_sell_order(seller, core.amount(100), bitcny.amount(250 - i))); } - std::vector results; - limit_order_object o; + std::vector results; + graphene::app::limit_order_api_object o; // query with no constraint, expected: // 1. up to 101 orders returned @@ -1186,7 +1186,7 @@ BOOST_AUTO_TEST_CASE(get_account_limit_orders) // id should greater than specified // 2. returned orders sorted by price desendingly // 3. the first order's sell price equal to specified - cancel_limit_order(o); // NOTE 1: this canceled order was in scope of the + cancel_limit_order( db.get(o.id) ); // NOTE 1: this canceled order was in scope of the // first created 50 orders, so with price 2.5 BTS/CNY results = db_api.get_account_limit_orders(seller.name, GRAPHENE_SYMBOL, "CNY", 50, limit_order_id_type(o.id), o.sell_price); @@ -1204,7 +1204,7 @@ BOOST_AUTO_TEST_CASE(get_account_limit_orders) o = results.back(); results.clear(); - cancel_limit_order(o); // NOTE 3: this time the canceled order was in scope + cancel_limit_order( db.get(o.id) ); // NOTE 3: this time the canceled order was in scope // of the lowest price 150 orders results = db_api.get_account_limit_orders(seller.name, GRAPHENE_SYMBOL, "CNY", 101, limit_order_id_type(o.id), o.sell_price); @@ -1568,7 +1568,7 @@ BOOST_AUTO_TEST_CASE( api_limit_get_limit_orders ){ fc::usleep(fc::milliseconds(100)); GRAPHENE_CHECK_THROW(db_api.get_limit_orders(std::string(static_cast(asset_id_type())), std::string(static_cast(bit_jmj_id)), 370), fc::exception); - vector limit_orders =db_api.get_limit_orders(std::string( + vector limit_orders =db_api.get_limit_orders(std::string( static_cast(asset_id_type())), std::string(static_cast(bit_jmj_id)), 340); BOOST_REQUIRE_EQUAL( limit_orders.size(), 0u); @@ -1592,7 +1592,7 @@ BOOST_AUTO_TEST_CASE( api_limit_get_call_orders ){ BOOST_CHECK( bitusd_id(db).is_market_issued() ); GRAPHENE_CHECK_THROW(db_api.get_call_orders(std::string(static_cast(bitusd_id)), 370), fc::exception); - vector< call_order_object> call_order =db_api.get_call_orders(std::string( + vector< graphene::app::call_order_api_object> call_order =db_api.get_call_orders(std::string( static_cast(bitusd_id)), 340); BOOST_REQUIRE_EQUAL( call_order.size(), 0u); }catch (fc::exception& e) { @@ -1613,7 +1613,7 @@ BOOST_AUTO_TEST_CASE( api_limit_get_settle_orders ){ fc::usleep(fc::milliseconds(100)); GRAPHENE_CHECK_THROW(db_api.get_settle_orders( std::string(static_cast(bitusd_id)), 370), fc::exception); - vector result =db_api.get_settle_orders( + vector result =db_api.get_settle_orders( std::string(static_cast(bitusd_id)), 340); BOOST_REQUIRE_EQUAL( result.size(), 0u); }catch (fc::exception& e) { @@ -1972,7 +1972,7 @@ BOOST_AUTO_TEST_CASE(api_limit_get_collateral_bids) { //validating normal case; total_bids =3 ; result_bids=3 - vector result_bids = db_api.get_collateral_bids(swan_symbol, 250, 0); + vector result_bids = db_api.get_collateral_bids(swan_symbol, 250, 0); BOOST_CHECK_EQUAL( 3u, result_bids.size() ); //verify skip /// inefficient code test @@ -2021,7 +2021,7 @@ BOOST_AUTO_TEST_CASE(api_limit_get_account_limit_orders) { } - std::vector results=db_api.get_account_limit_orders(seller.name, GRAPHENE_SYMBOL, "CNY",250); + std::vector results=db_api.get_account_limit_orders(seller.name, GRAPHENE_SYMBOL, "CNY",250); BOOST_REQUIRE_EQUAL( results.size(), 250u); GRAPHENE_CHECK_THROW( db_api.get_account_limit_orders(seller.name, GRAPHENE_SYMBOL, "CNY",251), fc::exception); diff --git a/tests/tests/database_tests.cpp b/tests/tests/database_tests.cpp index dd072fc1d5..ce2b3566b6 100644 --- a/tests/tests/database_tests.cpp +++ b/tests/tests/database_tests.cpp @@ -102,10 +102,13 @@ BOOST_AUTO_TEST_CASE( flat_index_test ) BOOST_CHECK( !(*bitusd.bitasset_data_id)(db).current_feed.settlement_price.is_null() ); try { auto ses = db._undo_db.start_undo_session(); - const auto& obj1 = db.create( [&]( asset_bitasset_data_object& obj ){ - obj.settlement_fund = 17; + stored_value dummy_value; + stored_debt dummy_debt(bitusd_id + 1); + dummy_value = dummy_debt.issue(17); + const auto& obj1 = db.create( [&dummy_value]( asset_bitasset_data_object& obj ){ + obj.settlement_fund = std::move(dummy_value); }); - BOOST_REQUIRE_EQUAL( obj1.settlement_fund.value, 17 ); + BOOST_REQUIRE_EQUAL( obj1.settlement_fund.get_amount().value, 17 ); throw std::string("Expected"); // With flat_index, obj1 will not really be removed from the index } catch ( const std::string& e ) @@ -124,8 +127,12 @@ BOOST_AUTO_TEST_CASE( merge_test ) try { database db; auto ses = db._undo_db.start_undo_session(); - db.create( [&]( account_balance_object& obj ){ - obj.balance = 42; + stored_value transport; + db.create( [&transport]( asset_dynamic_data_object& obj ){ + transport = obj.current_supply.issue(42); + }); + db.create( [&transport]( account_balance_object& obj ){ + obj.balance = std::move(transport); }); ses.merge(); diff --git a/tests/tests/fee_tests.cpp b/tests/tests/fee_tests.cpp index 83b7557425..3f1b0fb8ad 100644 --- a/tests/tests/fee_tests.cpp +++ b/tests/tests/fee_tests.cpp @@ -168,8 +168,8 @@ BOOST_AUTO_TEST_CASE(asset_claim_fees_test) //wdump( (jillcoin)(jillcoin.dynamic_asset_data_id(db))((*jillcoin.bitasset_data_id)(db)) ); // check the correct amount of fees has been awarded - BOOST_CHECK( izzycoin.dynamic_asset_data_id(db).accumulated_fees == _izzy(1).amount ); - BOOST_CHECK( jillcoin.dynamic_asset_data_id(db).accumulated_fees == _jill(6).amount ); + BOOST_CHECK( izzycoin.dynamic_asset_data_id(db).accumulated_fees.get_amount() == _izzy(1).amount ); + BOOST_CHECK( jillcoin.dynamic_asset_data_id(db).accumulated_fees.get_amount() == _jill(6).amount ); } @@ -188,14 +188,14 @@ BOOST_AUTO_TEST_CASE(asset_claim_fees_test) // can claim asset in one go claim_fees( izzy_id, _izzy(1) ); GRAPHENE_REQUIRE_THROW( claim_fees( izzy_id, izzy_satoshi ), fc::exception ); - BOOST_CHECK( izzycoin.dynamic_asset_data_id(db).accumulated_fees == _izzy(0).amount ); + BOOST_CHECK( izzycoin.dynamic_asset_data_id(db).accumulated_fees.get_amount() == _izzy(0).amount ); // can claim in multiple goes claim_fees( jill_id, _jill(4) ); - BOOST_CHECK( jillcoin.dynamic_asset_data_id(db).accumulated_fees == _jill(2).amount ); + BOOST_CHECK( jillcoin.dynamic_asset_data_id(db).accumulated_fees.get_amount() == _jill(2).amount ); GRAPHENE_REQUIRE_THROW( claim_fees( jill_id, _jill(2) + jill_satoshi ), fc::exception ); claim_fees( jill_id, _jill(2) ); - BOOST_CHECK( jillcoin.dynamic_asset_data_id(db).accumulated_fees == _jill(0).amount ); + BOOST_CHECK( jillcoin.dynamic_asset_data_id(db).accumulated_fees.get_amount() == _jill(0).amount ); } } FC_LOG_AND_RETHROW() @@ -287,8 +287,8 @@ BOOST_AUTO_TEST_CASE(asset_claim_pool_test) fund_fee_pool( alice_id(db), alicecoin_id(db), _core(300).amount ); // Test amount of CORE in fee pools - BOOST_CHECK( alicecoin_id(db).dynamic_asset_data_id(db).fee_pool == _core(300).amount ); - BOOST_CHECK( aliceusd_id(db).dynamic_asset_data_id(db).fee_pool == _core(100).amount ); + BOOST_CHECK( alicecoin_id(db).dynamic_asset_data_id(db).fee_pool.get_amount() == _core(300).amount ); + BOOST_CHECK( aliceusd_id(db).dynamic_asset_data_id(db).fee_pool.get_amount() == _core(100).amount ); // can't claim pool of an asset that doesn't belong to you GRAPHENE_REQUIRE_THROW( claim_pool( alice_id, bobcoin_id, _core(200), core_asset_hf), fc::exception ); @@ -301,12 +301,12 @@ BOOST_AUTO_TEST_CASE(asset_claim_pool_test) // can claim BTS back from the fee pool claim_pool( alice_id, alicecoin_id, _core(200), core_asset_hf ); - BOOST_CHECK( alicecoin_id(db).dynamic_asset_data_id(db).fee_pool == _core(100).amount ); + BOOST_CHECK( alicecoin_id(db).dynamic_asset_data_id(db).fee_pool.get_amount() == _core(100).amount ); // can pay fee in the asset other than the one whose pool is being drained share_type balance_before_claim = get_balance( alice_id, asset_id_type() ); claim_pool( alice_id, alicecoin_id, _core(100), aliceusd_id(db) ); - BOOST_CHECK( alicecoin_id(db).dynamic_asset_data_id(db).fee_pool == _core(0).amount ); + BOOST_CHECK( alicecoin_id(db).dynamic_asset_data_id(db).fee_pool.get_amount() == _core(0).amount ); //check balance after claiming pool share_type current_balance = get_balance( alice_id, asset_id_type() ); @@ -326,14 +326,14 @@ BOOST_AUTO_TEST_CASE(asset_claim_pool_test) BOOST_CHECK_EQUAL( get_balance( actor_name ## _id, asset_id_type() ), amount ) #define CHECK_VESTED_CASHBACK( actor_name, amount ) \ - BOOST_CHECK_EQUAL( actor_name ## _id(db).statistics(db).pending_vested_fees.value, amount ) + BOOST_CHECK_EQUAL( actor_name ## _id(db).statistics(db).pending_vested_fees.get_amount().value, amount ) #define CHECK_UNVESTED_CASHBACK( actor_name, amount ) \ - BOOST_CHECK_EQUAL( actor_name ## _id(db).statistics(db).pending_fees.value, amount ) + BOOST_CHECK_EQUAL( actor_name ## _id(db).statistics(db).pending_fees.get_amount().value, amount ) #define GET_CASHBACK_BALANCE( account ) \ ( (account.cashback_vb.valid()) \ - ? account.cashback_balance(db).balance.amount.value \ + ? account.cashback_balance(db).balance.get_amount().value \ : 0 ) #define CHECK_CASHBACK_VBO( actor_name, _amount ) \ @@ -965,8 +965,8 @@ BOOST_AUTO_TEST_CASE( non_core_fee_refund_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // Bob cancels order if( !expire_order ) @@ -1004,8 +1004,8 @@ BOOST_AUTO_TEST_CASE( non_core_fee_refund_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // Alice cancels order @@ -1020,8 +1020,8 @@ BOOST_AUTO_TEST_CASE( non_core_fee_refund_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // Check partial fill const limit_order_object* ao2 = create_sell_order( alice_id, asset(1000), asset(200, usd_id), exp, cer ); @@ -1047,8 +1047,8 @@ BOOST_AUTO_TEST_CASE( non_core_fee_refund_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // cancel Alice order, show that entire deferred_fee was consumed by partial match if( !expire_order ) @@ -1087,8 +1087,8 @@ BOOST_AUTO_TEST_CASE( non_core_fee_refund_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // Check multiple fill // Alice creating multiple orders @@ -1113,8 +1113,8 @@ BOOST_AUTO_TEST_CASE( non_core_fee_refund_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // Bob creating an order matching multiple Alice's orders const limit_order_object* bo31 = create_sell_order( bob_id, asset(500, usd_id), asset(2500), exp ); @@ -1138,8 +1138,8 @@ BOOST_AUTO_TEST_CASE( non_core_fee_refund_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // Bob creating an order matching multiple Alice's orders const limit_order_object* bo32 = create_sell_order( bob_id, asset(500, usd_id), asset(2500), exp ); @@ -1163,8 +1163,8 @@ BOOST_AUTO_TEST_CASE( non_core_fee_refund_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // cancel Bob order, show that entire deferred_fee was consumed by partial match if( !expire_order ) @@ -1202,8 +1202,8 @@ BOOST_AUTO_TEST_CASE( non_core_fee_refund_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // cancel Alice order, will refund after hard fork 445 cancel_limit_order( ao32id( db ) ); @@ -1217,8 +1217,8 @@ BOOST_AUTO_TEST_CASE( non_core_fee_refund_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // undo above tx's and reset generate_block( skip ); @@ -1337,8 +1337,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // ao3: won't expire, partially match before hard fork 445, fee in core BOOST_TEST_MESSAGE( "Creating order ao3 .." ); @@ -1358,8 +1358,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // ao4: will expire, will partially match before hard fork 445, fee in core BOOST_TEST_MESSAGE( "Creating order ao4 .." ); @@ -1379,8 +1379,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // bo3: won't expire, will partially match before hard fork 445, fee in usd BOOST_TEST_MESSAGE( "Creating order bo3 .." ); @@ -1402,8 +1402,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // bo4: will expire, will partially match before hard fork 445, fee in usd BOOST_TEST_MESSAGE( "Creating order bo4 .." ); @@ -1425,8 +1425,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // ao5: won't expire, partially match after hard fork 445, fee in core BOOST_TEST_MESSAGE( "Creating order ao5 .." ); @@ -1441,8 +1441,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // ao6: will expire, partially match after hard fork 445, fee in core BOOST_TEST_MESSAGE( "Creating order ao6 .." ); @@ -1457,8 +1457,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // bo5: won't expire, partially match after hard fork 445, fee in usd BOOST_TEST_MESSAGE( "Creating order bo5 .." ); @@ -1475,8 +1475,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // bo6: will expire, partially match after hard fork 445, fee in usd BOOST_TEST_MESSAGE( "Creating order bo6 .." ); @@ -1493,8 +1493,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // generate block so the orders will be in db before hard fork BOOST_TEST_MESSAGE( "Generating blocks ..." ); @@ -1509,8 +1509,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // generate more blocks, so some orders will expire generate_blocks( exp, true, skip ); @@ -1526,8 +1526,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // prepare for new transactions enable_fees(); @@ -1546,8 +1546,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // cancel ao3 BOOST_TEST_MESSAGE( "Cancel order ao3 .." ); @@ -1560,8 +1560,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // cancel bo1 BOOST_TEST_MESSAGE( "Cancel order bo1 .." ); @@ -1574,8 +1574,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // cancel bo3 BOOST_TEST_MESSAGE( "Cancel order bo3 .." ); @@ -1588,8 +1588,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // partially fill ao6 BOOST_TEST_MESSAGE( "Partially fill ao6 .." ); @@ -1605,8 +1605,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // partially fill bo6 BOOST_TEST_MESSAGE( "Partially fill bo6 .." ); @@ -1622,8 +1622,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // generate block to save the changes BOOST_TEST_MESSAGE( "Generating blocks ..." ); @@ -1633,8 +1633,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // generate blocks util exp2, so some orders will expire generate_blocks( exp2, true, skip ); @@ -1648,8 +1648,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // prepare for new transactions enable_fees(); @@ -1671,8 +1671,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // partially fill bo5 BOOST_TEST_MESSAGE( "Partially fill bo5 .." ); @@ -1688,8 +1688,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // cancel ao5 BOOST_TEST_MESSAGE( "Cancel order ao5 .." ); @@ -1702,8 +1702,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // cancel bo5 BOOST_TEST_MESSAGE( "Cancel order bo5 .." ); @@ -1716,8 +1716,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // generate block to save the changes BOOST_TEST_MESSAGE( "Generating blocks ..." ); @@ -1727,8 +1727,8 @@ BOOST_AUTO_TEST_CASE( hf445_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); } FC_LOG_AND_RETHROW() @@ -1913,8 +1913,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // Alice cancels order if( !expire_order ) @@ -1969,8 +1969,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); BOOST_TEST_MESSAGE( "Creating bo1" ); limit_order_id_type bo1_id = create_sell_order( bob_id, asset(500, usd_id), asset(1000), exp, cer )->id; @@ -1984,8 +1984,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // Bob cancels order if( !expire_order ) @@ -2054,8 +2054,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // Check partial fill @@ -2084,8 +2084,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // cancel Alice order, show that entire deferred_fee was consumed by partial match if( !expire_order ) @@ -2128,8 +2128,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // Check multiple fill // Alice creating multiple orders @@ -2155,8 +2155,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // Bob creating an order matching multiple Alice's orders BOOST_TEST_MESSAGE( "Creating bo31, completely fill ao31 and ao33, partially fill ao34" ); @@ -2182,8 +2182,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // Bob creating an order matching multiple Alice's orders BOOST_TEST_MESSAGE( "Creating bo32, completely fill partially filled ao34 and new ao35, leave on market" ); @@ -2209,8 +2209,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // cancel Bob order, show that entire deferred_fee was consumed by partial match if( !expire_order ) @@ -2252,8 +2252,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // cancel Alice order, will refund after hard fork 445 BOOST_TEST_MESSAGE( "Cancel order ao32" ); @@ -2269,8 +2269,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // undo above tx's and reset BOOST_TEST_MESSAGE( "Clean up" ); @@ -2401,8 +2401,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // ao3: won't expire, partially match before hard fork 445, fee in core BOOST_TEST_MESSAGE( "Creating order ao3 .." ); // 1:30 @@ -2422,8 +2422,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // ao4: will expire, will partially match before hard fork 445, fee in core BOOST_TEST_MESSAGE( "Creating order ao4 .." ); // 1:20 @@ -2443,8 +2443,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // bo3: won't expire, will partially match before hard fork 445, fee in usd BOOST_TEST_MESSAGE( "Creating order bo3 .." ); // 1:30 @@ -2466,8 +2466,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // bo4: will expire, will partially match before hard fork 445, fee in usd BOOST_TEST_MESSAGE( "Creating order bo4 .." ); // 1:20 @@ -2489,8 +2489,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // ao11: won't expire, partially match after hard fork core-604, fee in core @@ -2506,8 +2506,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // ao12: will expire, partially match after hard fork core-604, fee in core BOOST_TEST_MESSAGE( "Creating order ao12 .." ); // 1:16 @@ -2522,8 +2522,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // bo11: won't expire, partially match after hard fork core-604, fee in usd BOOST_TEST_MESSAGE( "Creating order bo11 .." ); // 1:18 @@ -2540,8 +2540,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // bo12: will expire, partially match after hard fork core-604, fee in usd BOOST_TEST_MESSAGE( "Creating order bo12 .." ); // 1:17 @@ -2558,8 +2558,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // ao5: won't expire, partially match after hard fork 445, fee in core BOOST_TEST_MESSAGE( "Creating order ao5 .." ); // 1:15 @@ -2574,8 +2574,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // ao6: will expire, partially match after hard fork 445, fee in core if( false ) { // only can have either ao5 or ao6, can't have both @@ -2591,8 +2591,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); } // bo5: won't expire, partially match after hard fork 445, fee in usd @@ -2611,8 +2611,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); } // bo6: will expire, partially match after hard fork 445, fee in usd @@ -2631,8 +2631,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // generate block so the orders will be in db before hard fork 445 BOOST_TEST_MESSAGE( "Generating blocks, passing hard fork 445 ..." ); @@ -2647,8 +2647,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // prepare for new transactions enable_fees(); @@ -2671,8 +2671,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); } // partially fill bo6 @@ -2689,8 +2689,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // partially fill ao5 BOOST_TEST_MESSAGE( "Partially fill ao5 .." ); // 1:15 @@ -2706,8 +2706,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // partially fill bo5 if( false ) { // only can have either bo5 or bo6, can't have both @@ -2724,8 +2724,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); } // prepare more orders @@ -2760,8 +2760,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // ao9: won't expire, partially match before hard fork core-604, fee in core BOOST_TEST_MESSAGE( "Creating order ao9 .." ); // 1:3 @@ -2781,8 +2781,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // ao10: will expire, will partially match before hard fork core-604, fee in core BOOST_TEST_MESSAGE( "Creating order ao10 .." ); // 1:2 @@ -2802,8 +2802,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // bo9: won't expire, will partially match before hard fork core-604, fee in usd BOOST_TEST_MESSAGE( "Creating order bo9 .." ); // 1:3 @@ -2825,8 +2825,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // bo10: will expire, will partially match before hard fork core-604, fee in usd BOOST_TEST_MESSAGE( "Creating order bo10 .." ); // 1:2 @@ -2848,8 +2848,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // ao13: won't expire, partially match after hard fork core-604, fee in core BOOST_TEST_MESSAGE( "Creating order ao13 .." ); // 1:1.5 @@ -2864,8 +2864,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // ao14: will expire, partially match after hard fork core-604, fee in core BOOST_TEST_MESSAGE( "Creating order ao14 .." ); // 1:1.2 @@ -2880,8 +2880,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // bo13: won't expire, partially match after hard fork core-604, fee in usd BOOST_TEST_MESSAGE( "Creating order bo13 .." ); // 1:1.5 @@ -2898,8 +2898,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // bo14: will expire, partially match after hard fork core-604, fee in usd BOOST_TEST_MESSAGE( "Creating order bo14 .." ); // 1:1.2 @@ -2916,8 +2916,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // generate block so the orders will be in db before hard fork core-604 BOOST_TEST_MESSAGE( "Generating blocks, passing hard fork core-604 ..." ); @@ -2932,8 +2932,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // prepare for new transactions enable_fees(); @@ -2955,8 +2955,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // partially fill bo14 BOOST_TEST_MESSAGE( "Partially fill bo14 .." ); // 1:1.2 @@ -2972,8 +2972,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // generate block to save the changes BOOST_TEST_MESSAGE( "Generating blocks ..." ); @@ -2983,8 +2983,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // generate more blocks, so some orders will expire generate_blocks( exp, true, skip ); @@ -3008,8 +3008,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // prepare for new transactions enable_fees(); @@ -3031,8 +3031,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // partially fill bo13 BOOST_TEST_MESSAGE( "Partially fill bo13 .." ); // 1:1.5 @@ -3048,8 +3048,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // don't refund fee, only refund remaining funds, for manually cancellations with an explicit fee: // * orders created before hard fork 445 : ao1, ao3, ao5, bo1, bo3, bo5 @@ -3066,8 +3066,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // cancel bo1 BOOST_TEST_MESSAGE( "Cancel order bo1 .." ); @@ -3080,8 +3080,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // cancel ao3 BOOST_TEST_MESSAGE( "Cancel order ao3 .." ); @@ -3094,8 +3094,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // cancel bo3 BOOST_TEST_MESSAGE( "Cancel order bo3 .." ); @@ -3108,8 +3108,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // cancel ao5 BOOST_TEST_MESSAGE( "Cancel order ao5 .." ); @@ -3122,8 +3122,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // cancel bo5 if( false ) { // can only have bo5 or bo6 but not both @@ -3137,8 +3137,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); } // cancel ao9 @@ -3152,8 +3152,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // cancel bo9 BOOST_TEST_MESSAGE( "Cancel order bo9 .." ); @@ -3166,8 +3166,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // cancel ao13 BOOST_TEST_MESSAGE( "Cancel order ao13 .." ); @@ -3180,8 +3180,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // cancel bo13 BOOST_TEST_MESSAGE( "Cancel order bo13 .." ); @@ -3194,8 +3194,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // generate block to save the changes @@ -3206,8 +3206,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // generate blocks util exp1, so some orders will expire BOOST_TEST_MESSAGE( "Generating blocks ..." ); @@ -3226,8 +3226,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // prepare for new transactions enable_fees(); @@ -3251,8 +3251,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // cancel bo7 BOOST_TEST_MESSAGE( "Cancel order bo7 .." ); @@ -3266,8 +3266,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // partially fill ao12 BOOST_TEST_MESSAGE( "Partially fill ao12 .." ); // 1:16 @@ -3283,8 +3283,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // partially fill bo12 BOOST_TEST_MESSAGE( "Partially fill bo12 .." ); // 1:17 @@ -3300,8 +3300,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // generate block to save the changes BOOST_TEST_MESSAGE( "Generating blocks ..." ); @@ -3311,8 +3311,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // generate blocks util exp2, so some orders will expire generate_blocks( exp2, true, skip ); @@ -3327,8 +3327,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // prepare for new transactions enable_fees(); @@ -3350,8 +3350,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // partially fill bo11 BOOST_TEST_MESSAGE( "Partially fill bo11 .." ); // 1:18 @@ -3367,8 +3367,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // no fee refund for orders created before hard fork 445, if manually cancelled with an explicit fee. // remaining funds will be refunded @@ -3384,8 +3384,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // cancel bo11 BOOST_TEST_MESSAGE( "Cancel order bo11 .." ); @@ -3398,8 +3398,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); // generate block to save the changes BOOST_TEST_MESSAGE( "Generating blocks ..." ); @@ -3409,8 +3409,8 @@ BOOST_AUTO_TEST_CASE( bsip26_fee_refund_cross_test ) BOOST_CHECK_EQUAL( get_balance( alice_id, usd_id ), alice_bu ); BOOST_CHECK_EQUAL( get_balance( bob_id, core_id ), bob_bc ); BOOST_CHECK_EQUAL( get_balance( bob_id, usd_id ), bob_bu ); - BOOST_CHECK_EQUAL( usd_stat->fee_pool.value, pool_b ); - BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.value, accum_b ); + BOOST_CHECK_EQUAL( usd_stat->fee_pool.get_amount().value, pool_b ); + BOOST_CHECK_EQUAL( usd_stat->accumulated_fees.get_amount().value, accum_b ); } FC_LOG_AND_RETHROW() diff --git a/tests/tests/market_fee_sharing_tests.cpp b/tests/tests/market_fee_sharing_tests.cpp index 7276d87e60..ac2591f343 100644 --- a/tests/tests/market_fee_sharing_tests.cpp +++ b/tests/tests/market_fee_sharing_tests.cpp @@ -650,8 +650,8 @@ BOOST_AUTO_TEST_CASE(accumulated_fees_before_hf_test) // 100 Izzys and 300 Jills are matched, so the fees should be // 10 Izzy (10%) and 60 Jill (20%). - BOOST_CHECK( izzycoin.dynamic_asset_data_id(db).accumulated_fees == izzycoin.amount(10).amount ); - BOOST_CHECK( jillcoin.dynamic_asset_data_id(db).accumulated_fees == jillcoin.amount(60).amount ); + BOOST_CHECK( izzycoin.dynamic_asset_data_id(db).accumulated_fees.get_amount() == izzycoin.amount(10).amount ); + BOOST_CHECK( jillcoin.dynamic_asset_data_id(db).accumulated_fees.get_amount() == jillcoin.amount(60).amount ); } FC_LOG_AND_RETHROW() } @@ -674,8 +674,8 @@ BOOST_AUTO_TEST_CASE(accumulated_fees_after_hf_test) // 100 Izzys and 300 Jills are matched, so the fees should be // 10 Izzy (10%) and 60 Jill (20%). - BOOST_CHECK( izzycoin.dynamic_asset_data_id(db).accumulated_fees == izzycoin.amount(10).amount ); - BOOST_CHECK( jillcoin.dynamic_asset_data_id(db).accumulated_fees == jillcoin.amount(60).amount ); + BOOST_CHECK( izzycoin.dynamic_asset_data_id(db).accumulated_fees.get_amount() == izzycoin.amount(10).amount ); + BOOST_CHECK( jillcoin.dynamic_asset_data_id(db).accumulated_fees.get_amount() == jillcoin.amount(60).amount ); } FC_LOG_AND_RETHROW() } @@ -705,8 +705,8 @@ BOOST_AUTO_TEST_CASE(accumulated_fees_with_additional_options_after_hf_test) // 100 Izzys and 300 Jills are matched, so the fees should be // 10 Izzy (10%) and 60 Jill (20%). - BOOST_CHECK( izzycoin.dynamic_asset_data_id(db).accumulated_fees == izzycoin.amount(10).amount ); - BOOST_CHECK( jillcoin.dynamic_asset_data_id(db).accumulated_fees == jillcoin.amount(60).amount ); + BOOST_CHECK( izzycoin.dynamic_asset_data_id(db).accumulated_fees.get_amount() == izzycoin.amount(10).amount ); + BOOST_CHECK( jillcoin.dynamic_asset_data_id(db).accumulated_fees.get_amount() == jillcoin.amount(60).amount ); } FC_LOG_AND_RETHROW() } diff --git a/tests/tests/market_rounding_tests.cpp b/tests/tests/market_rounding_tests.cpp index 66698bee45..d29b3905ef 100644 --- a/tests/tests/market_rounding_tests.cpp +++ b/tests/tests/market_rounding_tests.cpp @@ -178,7 +178,7 @@ BOOST_AUTO_TEST_CASE( limit_limit_rounding_test1 ) // the order is filled immediately BOOST_CHECK( !create_sell_order( buyer, test.amount(25), core.amount(2) ) ); - BOOST_CHECK_EQUAL( sell_id(db).for_sale.value, 1 ); // 2 core sold, 1 remaining + BOOST_CHECK_EQUAL( sell_id(db).for_sale.get_amount().value, 1 ); // 2 core sold, 1 remaining BOOST_CHECK_EQUAL(get_balance(seller, core), 99999997); BOOST_CHECK_EQUAL(get_balance(seller, test), 25); // seller got 25 test @@ -194,7 +194,7 @@ BOOST_AUTO_TEST_CASE( limit_limit_rounding_test1 ) generate_block(); BOOST_CHECK( !db.find_object( sell_id ) ); // sell order is filled - BOOST_CHECK_EQUAL( buy_id(db).for_sale.value, 15 ); // 10 test sold, 15 remaining + BOOST_CHECK_EQUAL( buy_id(db).for_sale.get_amount().value, 15 ); // 10 test sold, 15 remaining BOOST_CHECK_EQUAL(get_balance(seller_id, core_id), 99999997); BOOST_CHECK_EQUAL(get_balance(seller_id, test_id), 35); // seller got 10 more test @@ -244,7 +244,7 @@ BOOST_AUTO_TEST_CASE( limit_limit_rounding_test1_after_hf_342 ) // the order is filled immediately BOOST_CHECK( !create_sell_order( buyer, test.amount(25), core.amount(2) ) ); - BOOST_CHECK_EQUAL( sell_id(db).for_sale.value, 1 ); // 2 core sold, 1 remaining + BOOST_CHECK_EQUAL( sell_id(db).for_sale.get_amount().value, 1 ); // 2 core sold, 1 remaining BOOST_CHECK_EQUAL(get_balance(buyer, core), 2); // buyer got 2 core BOOST_CHECK_EQUAL(get_balance(buyer, test), 9999979); // buyer actually paid 21 test according to price 10.33 @@ -260,7 +260,7 @@ BOOST_AUTO_TEST_CASE( limit_limit_rounding_test1_after_hf_342 ) generate_block(); BOOST_CHECK( !db.find_object( sell_id ) ); // sell order is filled - BOOST_CHECK_EQUAL( buy_id(db).for_sale.value, 15 ); // 10 test sold according to price 10.33, and 15 remaining + BOOST_CHECK_EQUAL( buy_id(db).for_sale.get_amount().value, 15 ); // 10 test sold according to price 10.33, and 15 remaining BOOST_CHECK_EQUAL(get_balance(buyer_id, core_id), 3); // buyer got 1 more core BOOST_CHECK_EQUAL(get_balance(buyer_id, test_id), 9999954); @@ -306,7 +306,7 @@ BOOST_AUTO_TEST_CASE( limit_limit_rounding_test2 ) limit_order_id_type sell_id = create_sell_order( seller, core.amount(33), test.amount(5) )->id; BOOST_CHECK( !db.find_object( tmp_buy_id ) ); // buy order is filled - BOOST_CHECK_EQUAL( sell_id(db).for_sale.value, 16 ); // 17 core sold, 16 remaining + BOOST_CHECK_EQUAL( sell_id(db).for_sale.get_amount().value, 16 ); // 17 core sold, 16 remaining BOOST_CHECK_EQUAL(get_balance(seller, core), 99999967); BOOST_CHECK_EQUAL(get_balance(seller, test), 3); // seller got 3 test @@ -323,7 +323,7 @@ BOOST_AUTO_TEST_CASE( limit_limit_rounding_test2 ) generate_block(); BOOST_CHECK( !db.find_object( sell_id ) ); // sell order is filled - BOOST_CHECK_EQUAL( buy_id(db).for_sale.value, 1 ); // 2 test sold, 1 remaining + BOOST_CHECK_EQUAL( buy_id(db).for_sale.get_amount().value, 1 ); // 2 test sold, 1 remaining BOOST_CHECK_EQUAL(get_balance(seller_id, core_id), 99999967); // seller paid the 16 core which was remaining in the order BOOST_CHECK_EQUAL(get_balance(seller_id, test_id), 5); // seller got 2 more test @@ -373,7 +373,7 @@ BOOST_AUTO_TEST_CASE( limit_limit_rounding_test2_after_hf_342 ) limit_order_id_type sell_id = create_sell_order( seller, core.amount(33), test.amount(5) )->id; BOOST_CHECK( !db.find_object( tmp_buy_id ) ); // buy order is filled - BOOST_CHECK_EQUAL( sell_id(db).for_sale.value, 16 ); // 17 core sold, 16 remaining + BOOST_CHECK_EQUAL( sell_id(db).for_sale.get_amount().value, 16 ); // 17 core sold, 16 remaining BOOST_CHECK_EQUAL(get_balance(seller, core), 99999967); BOOST_CHECK_EQUAL(get_balance(seller, test), 3); // seller got 3 test @@ -390,7 +390,7 @@ BOOST_AUTO_TEST_CASE( limit_limit_rounding_test2_after_hf_342 ) generate_block(); BOOST_CHECK( !db.find_object( sell_id ) ); // sell order is filled - BOOST_CHECK_EQUAL( buy_id(db).for_sale.value, 1 ); // 2 test sold, 1 remaining + BOOST_CHECK_EQUAL( buy_id(db).for_sale.get_amount().value, 1 ); // 2 test sold, 1 remaining BOOST_CHECK_EQUAL(get_balance(buyer_id, core_id), 31); // buyer got 14 more core according to price 0.1515 BOOST_CHECK_EQUAL(get_balance(buyer_id, test_id), 9999994); @@ -444,12 +444,12 @@ BOOST_AUTO_TEST_CASE( issue_132_limit_and_call_test1 ) transfer(borrower2, seller, bitusd.amount(100000)); transfer(borrower3, seller, bitusd.amount(100000)); - BOOST_CHECK_EQUAL( 10, call.debt.value ); - BOOST_CHECK_EQUAL( 1, call.collateral.value ); - BOOST_CHECK_EQUAL( 100000, call2.debt.value ); - BOOST_CHECK_EQUAL( 15500, call2.collateral.value ); - BOOST_CHECK_EQUAL( 100000, call3.debt.value ); - BOOST_CHECK_EQUAL( 17500, call3.collateral.value ); + BOOST_CHECK_EQUAL( 10, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 1, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 100000, call2.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15500, call2.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 100000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 17500, call3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 200010, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -516,10 +516,10 @@ BOOST_AUTO_TEST_CASE( issue_132_limit_and_call_test2 ) transfer(borrower, seller, bitusd.amount(10)); transfer(borrower3, seller, bitusd.amount(100000)); - BOOST_CHECK_EQUAL( 10, call.debt.value ); - BOOST_CHECK_EQUAL( 1, call.collateral.value ); - BOOST_CHECK_EQUAL( 100000, call3.debt.value ); - BOOST_CHECK_EQUAL( 17500, call3.collateral.value ); + BOOST_CHECK_EQUAL( 10, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 1, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 100000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 17500, call3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 100010, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -538,7 +538,7 @@ BOOST_AUTO_TEST_CASE( issue_132_limit_and_call_test2 ) BOOST_CHECK( !db.find( call_id ) ); // the first call order get filled BOOST_CHECK_EQUAL( 100010-33, get_balance(seller, bitusd) ); // the seller paid 33 USD BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); // the seller got nothing - BOOST_CHECK_EQUAL( 33-10, sell_id(db).for_sale.value ); // the sell order has some USD left + BOOST_CHECK_EQUAL( 33-10, sell_id(db).for_sale.get_amount().value ); // the sell order has some USD left BOOST_CHECK_EQUAL( 0, get_balance(borrower, bitusd) ); BOOST_CHECK_EQUAL( init_balance, get_balance(borrower, core) ); @@ -589,10 +589,10 @@ BOOST_AUTO_TEST_CASE( issue_132_limit_and_call_test3 ) transfer(borrower, seller, bitusd.amount(10)); transfer(borrower3, seller, bitusd.amount(100000)); - BOOST_CHECK_EQUAL( 10, call.debt.value ); - BOOST_CHECK_EQUAL( 1, call.collateral.value ); - BOOST_CHECK_EQUAL( 100000, call3.debt.value ); - BOOST_CHECK_EQUAL( 17500, call3.collateral.value ); + BOOST_CHECK_EQUAL( 10, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 1, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 100000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 17500, call3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 100010, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -601,7 +601,7 @@ BOOST_AUTO_TEST_CASE( issue_132_limit_and_call_test3 ) // create a limit order which will be matched later limit_order_id_type sell_id = create_sell_order(seller, bitusd.amount(33), core.amount(3))->id; - BOOST_CHECK_EQUAL( 33, sell_id(db).for_sale.value ); + BOOST_CHECK_EQUAL( 33, sell_id(db).for_sale.get_amount().value ); BOOST_CHECK_EQUAL( 100010-33, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -618,7 +618,7 @@ BOOST_AUTO_TEST_CASE( issue_132_limit_and_call_test3 ) BOOST_CHECK( !db.find( call_id ) ); // the first call order get filled BOOST_CHECK_EQUAL( 100010-33, get_balance(seller_id, bitusd_id) ); // the seller paid 33 USD BOOST_CHECK_EQUAL( 0, get_balance(seller_id, core_id) ); // the seller got nothing - BOOST_CHECK_EQUAL( 33-10, sell_id(db).for_sale.value ); // the sell order has some USD left + BOOST_CHECK_EQUAL( 33-10, sell_id(db).for_sale.get_amount().value ); // the sell order has some USD left BOOST_CHECK_EQUAL( 0, get_balance(borrower_id, bitusd_id) ); BOOST_CHECK_EQUAL( init_balance, get_balance(borrower_id, core_id) ); @@ -667,12 +667,12 @@ BOOST_AUTO_TEST_CASE( issue_132_limit_and_call_test1_after_hardfork ) transfer(borrower2, seller, bitusd.amount(100000)); transfer(borrower3, seller, bitusd.amount(100000)); - BOOST_CHECK_EQUAL( 10, call.debt.value ); - BOOST_CHECK_EQUAL( 1, call.collateral.value ); - BOOST_CHECK_EQUAL( 100000, call2.debt.value ); - BOOST_CHECK_EQUAL( 15500, call2.collateral.value ); - BOOST_CHECK_EQUAL( 100000, call3.debt.value ); - BOOST_CHECK_EQUAL( 17500, call3.collateral.value ); + BOOST_CHECK_EQUAL( 10, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 1, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 100000, call2.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15500, call2.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 100000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 17500, call3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 200010, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -740,10 +740,10 @@ BOOST_AUTO_TEST_CASE( issue_132_limit_and_call_test2_after_hardfork ) transfer(borrower, seller, bitusd.amount(10)); transfer(borrower3, seller, bitusd.amount(100000)); - BOOST_CHECK_EQUAL( 10, call.debt.value ); - BOOST_CHECK_EQUAL( 1, call.collateral.value ); - BOOST_CHECK_EQUAL( 100000, call3.debt.value ); - BOOST_CHECK_EQUAL( 17500, call3.collateral.value ); + BOOST_CHECK_EQUAL( 10, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 1, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 100000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 17500, call3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 100010, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -763,7 +763,7 @@ BOOST_AUTO_TEST_CASE( issue_132_limit_and_call_test2_after_hardfork ) BOOST_CHECK( !db.find( call_id ) ); // the first call order get filled BOOST_CHECK_EQUAL( 100010-33, get_balance(seller, bitusd) ); // the seller paid 33 USD BOOST_CHECK_EQUAL( 1, get_balance(seller, core) ); // the seller got 1 CORE - BOOST_CHECK_EQUAL( 33-10, sell_id(db).for_sale.value ); // the sell order has some USD left + BOOST_CHECK_EQUAL( 33-10, sell_id(db).for_sale.get_amount().value ); // the sell order has some USD left BOOST_CHECK_EQUAL( 0, get_balance(borrower, bitusd) ); BOOST_CHECK_EQUAL( init_balance-1, get_balance(borrower, core) ); @@ -815,10 +815,10 @@ BOOST_AUTO_TEST_CASE( issue_132_limit_and_call_test3_after_hardfork ) transfer(borrower, seller, bitusd.amount(10)); transfer(borrower3, seller, bitusd.amount(100000)); - BOOST_CHECK_EQUAL( 10, call.debt.value ); - BOOST_CHECK_EQUAL( 1, call.collateral.value ); - BOOST_CHECK_EQUAL( 100000, call3.debt.value ); - BOOST_CHECK_EQUAL( 17500, call3.collateral.value ); + BOOST_CHECK_EQUAL( 10, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 1, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 100000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 17500, call3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 100010, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -827,7 +827,7 @@ BOOST_AUTO_TEST_CASE( issue_132_limit_and_call_test3_after_hardfork ) // create a limit order which will be matched later limit_order_id_type sell_id = create_sell_order(seller, bitusd.amount(33), core.amount(3))->id; - BOOST_CHECK_EQUAL( 33, sell_id(db).for_sale.value ); + BOOST_CHECK_EQUAL( 33, sell_id(db).for_sale.get_amount().value ); BOOST_CHECK_EQUAL( 100010-33, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -844,7 +844,7 @@ BOOST_AUTO_TEST_CASE( issue_132_limit_and_call_test3_after_hardfork ) BOOST_CHECK( !db.find( call_id ) ); // the first call order get filled BOOST_CHECK_EQUAL( 100010-33, get_balance(seller_id, bitusd_id) ); // the seller paid 33 USD BOOST_CHECK_EQUAL( 1, get_balance(seller_id, core_id) ); // the seller got 1 CORE - BOOST_CHECK_EQUAL( 33-10, sell_id(db).for_sale.value ); // the sell order has some USD left + BOOST_CHECK_EQUAL( 33-10, sell_id(db).for_sale.get_amount().value ); // the sell order has some USD left BOOST_CHECK_EQUAL( 0, get_balance(borrower_id, bitusd_id) ); BOOST_CHECK_EQUAL( init_balance-1, get_balance(borrower_id, core_id) ); @@ -891,10 +891,10 @@ BOOST_AUTO_TEST_CASE( limit_call_rounding_test1 ) transfer(borrower, seller, bitusd.amount(20)); transfer(borrower3, seller, bitusd.amount(100000)); - BOOST_CHECK_EQUAL( 20, call.debt.value ); - BOOST_CHECK_EQUAL( 2, call.collateral.value ); - BOOST_CHECK_EQUAL( 100000, call3.debt.value ); - BOOST_CHECK_EQUAL( 17500, call3.collateral.value ); + BOOST_CHECK_EQUAL( 20, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 2, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 100000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 17500, call3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 100020, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -914,7 +914,7 @@ BOOST_AUTO_TEST_CASE( limit_call_rounding_test1 ) BOOST_CHECK( !db.find( call_id ) ); // the first call order get filled BOOST_CHECK_EQUAL( 100020-33, get_balance(seller, bitusd) ); // the seller paid 33 USD BOOST_CHECK_EQUAL( 1, get_balance(seller, core) ); // the seller got 1 CORE - BOOST_CHECK_EQUAL( 33-20, sell_id(db).for_sale.value ); // the sell order has some USD left + BOOST_CHECK_EQUAL( 33-20, sell_id(db).for_sale.get_amount().value ); // the sell order has some USD left BOOST_CHECK_EQUAL( 0, get_balance(borrower, bitusd) ); BOOST_CHECK_EQUAL( init_balance-1, get_balance(borrower, core) ); @@ -962,10 +962,10 @@ BOOST_AUTO_TEST_CASE( limit_call_rounding_test1_after_hf_342 ) transfer(borrower, seller, bitusd.amount(20)); transfer(borrower3, seller, bitusd.amount(100000)); - BOOST_CHECK_EQUAL( 20, call.debt.value ); - BOOST_CHECK_EQUAL( 2, call.collateral.value ); - BOOST_CHECK_EQUAL( 100000, call3.debt.value ); - BOOST_CHECK_EQUAL( 17500, call3.collateral.value ); + BOOST_CHECK_EQUAL( 20, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 2, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 100000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 17500, call3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 100020, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -986,7 +986,7 @@ BOOST_AUTO_TEST_CASE( limit_call_rounding_test1_after_hf_342 ) BOOST_CHECK( !db.find( call_id ) ); // the first call order get filled BOOST_CHECK_EQUAL( 100020-33, get_balance(seller, bitusd) ); // the seller paid 33 USD BOOST_CHECK_EQUAL( 2, get_balance(seller, core) ); // the seller got 2 CORE - BOOST_CHECK_EQUAL( 33-20, sell_id(db).for_sale.value ); // the sell order has some USD left + BOOST_CHECK_EQUAL( 33-20, sell_id(db).for_sale.get_amount().value ); // the sell order has some USD left BOOST_CHECK_EQUAL( 0, get_balance(borrower, bitusd) ); BOOST_CHECK_EQUAL( init_balance-2, get_balance(borrower, core) ); @@ -1036,10 +1036,10 @@ BOOST_AUTO_TEST_CASE( limit_call_rounding_test2 ) transfer(borrower, seller, bitusd.amount(20)); transfer(borrower3, seller, bitusd.amount(100000)); - BOOST_CHECK_EQUAL( 20, call.debt.value ); - BOOST_CHECK_EQUAL( 2, call.collateral.value ); - BOOST_CHECK_EQUAL( 100000, call3.debt.value ); - BOOST_CHECK_EQUAL( 17500, call3.collateral.value ); + BOOST_CHECK_EQUAL( 20, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 2, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 100000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 17500, call3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 100020, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -1056,8 +1056,8 @@ BOOST_AUTO_TEST_CASE( limit_call_rounding_test2 ) // effective price is 15/1. BOOST_CHECK( !create_sell_order(seller, bitusd.amount(15), core.amount(1)) ); // the sell order is filled BOOST_CHECK( db.find( call_id ) != nullptr ); // the first call order did not get filled - BOOST_CHECK_EQUAL( 20-15, call.debt.value ); // call paid 15 USD - BOOST_CHECK_EQUAL( 2-1, call.collateral.value ); // call got 1 CORE + BOOST_CHECK_EQUAL( 20-15, call.debt.get_amount().value ); // call paid 15 USD + BOOST_CHECK_EQUAL( 2-1, call.collateral.get_amount().value ); // call got 1 CORE BOOST_CHECK_EQUAL( 100020-15, get_balance(seller, bitusd) ); // the seller paid 15 USD BOOST_CHECK_EQUAL( 1, get_balance(seller, core) ); // the seller got 1 CORE BOOST_CHECK_EQUAL( 0, get_balance(borrower, bitusd) ); @@ -1108,10 +1108,10 @@ BOOST_AUTO_TEST_CASE( limit_call_rounding_test2_after_hf_342 ) transfer(borrower, seller, bitusd.amount(20)); transfer(borrower3, seller, bitusd.amount(100000)); - BOOST_CHECK_EQUAL( 20, call.debt.value ); - BOOST_CHECK_EQUAL( 2, call.collateral.value ); - BOOST_CHECK_EQUAL( 100000, call3.debt.value ); - BOOST_CHECK_EQUAL( 17500, call3.collateral.value ); + BOOST_CHECK_EQUAL( 20, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 2, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 100000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 17500, call3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 100020, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -1129,8 +1129,8 @@ BOOST_AUTO_TEST_CASE( limit_call_rounding_test2_after_hf_342 ) // effective price is 11/1 which is close to 120/11. BOOST_CHECK( !create_sell_order(seller, bitusd.amount(15), core.amount(1)) ); // the sell order is filled BOOST_CHECK( db.find( call_id ) != nullptr ); // the first call order did not get filled - BOOST_CHECK_EQUAL( 20-11, call.debt.value ); // call paid 11 USD - BOOST_CHECK_EQUAL( 2-1, call.collateral.value ); // call got 1 CORE + BOOST_CHECK_EQUAL( 20-11, call.debt.get_amount().value ); // call paid 11 USD + BOOST_CHECK_EQUAL( 2-1, call.collateral.get_amount().value ); // call got 1 CORE BOOST_CHECK_EQUAL( 100020-11, get_balance(seller, bitusd) ); // the seller paid 11 USD BOOST_CHECK_EQUAL( 1, get_balance(seller, core) ); // the seller got 1 CORE BOOST_CHECK_EQUAL( 0, get_balance(borrower, bitusd) ); @@ -1181,10 +1181,10 @@ BOOST_AUTO_TEST_CASE( call_limit_rounding_test1 ) transfer(borrower, seller, bitusd.amount(20)); transfer(borrower3, seller, bitusd.amount(100000)); - BOOST_CHECK_EQUAL( 20, call.debt.value ); - BOOST_CHECK_EQUAL( 2, call.collateral.value ); - BOOST_CHECK_EQUAL( 100000, call3.debt.value ); - BOOST_CHECK_EQUAL( 17500, call3.collateral.value ); + BOOST_CHECK_EQUAL( 20, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 2, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 100000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 17500, call3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 100020, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -1193,7 +1193,7 @@ BOOST_AUTO_TEST_CASE( call_limit_rounding_test1 ) // create a limit order which will be matched later limit_order_id_type sell_id = create_sell_order(seller, bitusd.amount(33), core.amount(3))->id; - BOOST_CHECK_EQUAL( 33, sell_id(db).for_sale.value ); + BOOST_CHECK_EQUAL( 33, sell_id(db).for_sale.get_amount().value ); BOOST_CHECK_EQUAL( 100020-33, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -1211,7 +1211,7 @@ BOOST_AUTO_TEST_CASE( call_limit_rounding_test1 ) BOOST_CHECK( !db.find( call_id ) ); // the first call order get filled BOOST_CHECK_EQUAL( 100020-33, get_balance(seller_id, bitusd_id) ); // the seller paid 33 USD BOOST_CHECK_EQUAL( 1, get_balance(seller_id, core_id) ); // the seller got 1 CORE - BOOST_CHECK_EQUAL( 33-20, sell_id(db).for_sale.value ); // the sell order has some USD left + BOOST_CHECK_EQUAL( 33-20, sell_id(db).for_sale.get_amount().value ); // the sell order has some USD left BOOST_CHECK_EQUAL( 0, get_balance(borrower_id, bitusd_id) ); BOOST_CHECK_EQUAL( init_balance-1, get_balance(borrower_id, core_id) ); @@ -1261,10 +1261,10 @@ BOOST_AUTO_TEST_CASE( call_limit_rounding_test1_after_hf_342 ) transfer(borrower, seller, bitusd.amount(20)); transfer(borrower3, seller, bitusd.amount(100000)); - BOOST_CHECK_EQUAL( 20, call.debt.value ); - BOOST_CHECK_EQUAL( 2, call.collateral.value ); - BOOST_CHECK_EQUAL( 100000, call3.debt.value ); - BOOST_CHECK_EQUAL( 17500, call3.collateral.value ); + BOOST_CHECK_EQUAL( 20, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 2, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 100000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 17500, call3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 100020, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -1273,7 +1273,7 @@ BOOST_AUTO_TEST_CASE( call_limit_rounding_test1_after_hf_342 ) // create a limit order which will be matched later limit_order_id_type sell_id = create_sell_order(seller, bitusd.amount(33), core.amount(3))->id; - BOOST_CHECK_EQUAL( 33, sell_id(db).for_sale.value ); + BOOST_CHECK_EQUAL( 33, sell_id(db).for_sale.get_amount().value ); BOOST_CHECK_EQUAL( 100020-33, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -1291,7 +1291,7 @@ BOOST_AUTO_TEST_CASE( call_limit_rounding_test1_after_hf_342 ) BOOST_CHECK( !db.find( call_id ) ); // the first call order get filled BOOST_CHECK_EQUAL( 100020-33, get_balance(seller_id, bitusd_id) ); // the seller paid 33 USD BOOST_CHECK_EQUAL( 2, get_balance(seller_id, core_id) ); // the seller got 2 CORE - BOOST_CHECK_EQUAL( 33-20, sell_id(db).for_sale.value ); // the sell order has some USD left + BOOST_CHECK_EQUAL( 33-20, sell_id(db).for_sale.get_amount().value ); // the sell order has some USD left BOOST_CHECK_EQUAL( 0, get_balance(borrower_id, bitusd_id) ); BOOST_CHECK_EQUAL( init_balance-2, get_balance(borrower_id, core_id) ); @@ -1340,10 +1340,10 @@ BOOST_AUTO_TEST_CASE( call_limit_rounding_test2 ) transfer(borrower, seller, bitusd.amount(50)); transfer(borrower3, seller2, bitusd.amount(100000)); - BOOST_CHECK_EQUAL( 50, call.debt.value ); - BOOST_CHECK_EQUAL( 5, call.collateral.value ); - BOOST_CHECK_EQUAL( 100000, call3.debt.value ); - BOOST_CHECK_EQUAL( 17500, call3.collateral.value ); + BOOST_CHECK_EQUAL( 50, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 5, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 100000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 17500, call3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 50, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 100000, get_balance(seller2, bitusd) ); @@ -1353,7 +1353,7 @@ BOOST_AUTO_TEST_CASE( call_limit_rounding_test2 ) // create a buy order which will be matched limit_order_id_type buy_id = create_sell_order(buyer, core.amount(1), bitusd.amount(10))->id; - BOOST_CHECK_EQUAL( 1, buy_id(db).for_sale.value ); + BOOST_CHECK_EQUAL( 1, buy_id(db).for_sale.get_amount().value ); BOOST_CHECK_EQUAL( 1000000-1, get_balance(buyer, core) ); BOOST_CHECK_EQUAL( 0, get_balance(buyer, bitusd) ); @@ -1362,13 +1362,13 @@ BOOST_AUTO_TEST_CASE( call_limit_rounding_test2 ) BOOST_CHECK( !db.find( buy_id ) ); // the buy order is filled BOOST_CHECK_EQUAL( 1000000-1, get_balance(buyer, core) ); BOOST_CHECK_EQUAL( 10, get_balance(buyer, bitusd) ); // buyer got 10 usd - BOOST_CHECK_EQUAL( 21, sell_id(db).for_sale.value ); // remaining amount of sell order is 21 + BOOST_CHECK_EQUAL( 21, sell_id(db).for_sale.get_amount().value ); // remaining amount of sell order is 21 BOOST_CHECK_EQUAL( 50-31, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 1, get_balance(seller, core) ); // seller got 1 core // create another limit order which will be matched later limit_order_id_type sell_id2 = create_sell_order(seller2, bitusd.amount(14), core.amount(1))->id; - BOOST_CHECK_EQUAL( 14, sell_id2(db).for_sale.value ); + BOOST_CHECK_EQUAL( 14, sell_id2(db).for_sale.get_amount().value ); BOOST_CHECK_EQUAL( 100000-14, get_balance(seller2, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller2, core) ); @@ -1388,8 +1388,8 @@ BOOST_AUTO_TEST_CASE( call_limit_rounding_test2 ) BOOST_CHECK( !db.find( sell_id ) ); // the sell order is filled BOOST_CHECK( !db.find( sell_id2 ) ); // the other sell order is filled BOOST_CHECK( db.find( call_id ) != nullptr ); // the first call order did not get filled - BOOST_CHECK_EQUAL( 50-14-21, call_id(db).debt.value ); // call paid 14 USD and 21 USD - BOOST_CHECK_EQUAL( 5-1-1, call_id(db).collateral.value ); // call got 1 CORE and 1 CORE + BOOST_CHECK_EQUAL( 50-14-21, call_id(db).debt.get_amount().value ); // call paid 14 USD and 21 USD + BOOST_CHECK_EQUAL( 5-1-1, call_id(db).collateral.get_amount().value ); // call got 1 CORE and 1 CORE BOOST_CHECK_EQUAL( 50-31, get_balance(seller_id, bitusd_id) ); // seller paid 31 USD in total BOOST_CHECK_EQUAL( 1+1, get_balance(seller_id, core_id) ); // seller got 1 more CORE BOOST_CHECK_EQUAL( 100000-14, get_balance(seller2_id, bitusd_id) ); // seller2 paid 14 USD @@ -1443,10 +1443,10 @@ BOOST_AUTO_TEST_CASE( call_limit_rounding_test2_after_hf_342 ) transfer(borrower, seller, bitusd.amount(50)); transfer(borrower3, seller2, bitusd.amount(100000)); - BOOST_CHECK_EQUAL( 50, call.debt.value ); - BOOST_CHECK_EQUAL( 5, call.collateral.value ); - BOOST_CHECK_EQUAL( 100000, call3.debt.value ); - BOOST_CHECK_EQUAL( 17500, call3.collateral.value ); + BOOST_CHECK_EQUAL( 50, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 5, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 100000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 17500, call3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 50, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 100000, get_balance(seller2, bitusd) ); @@ -1456,7 +1456,7 @@ BOOST_AUTO_TEST_CASE( call_limit_rounding_test2_after_hf_342 ) // create a buy order which will be matched limit_order_id_type buy_id = create_sell_order(buyer, core.amount(1), bitusd.amount(10))->id; - BOOST_CHECK_EQUAL( 1, buy_id(db).for_sale.value ); + BOOST_CHECK_EQUAL( 1, buy_id(db).for_sale.get_amount().value ); BOOST_CHECK_EQUAL( 1000000-1, get_balance(buyer, core) ); BOOST_CHECK_EQUAL( 0, get_balance(buyer, bitusd) ); @@ -1465,13 +1465,13 @@ BOOST_AUTO_TEST_CASE( call_limit_rounding_test2_after_hf_342 ) BOOST_CHECK( !db.find( buy_id ) ); // the buy order is filled BOOST_CHECK_EQUAL( 1000000-1, get_balance(buyer, core) ); BOOST_CHECK_EQUAL( 10, get_balance(buyer, bitusd) ); // buyer got 10 usd - BOOST_CHECK_EQUAL( 21, sell_id(db).for_sale.value ); // remaining amount of sell order is 21 + BOOST_CHECK_EQUAL( 21, sell_id(db).for_sale.get_amount().value ); // remaining amount of sell order is 21 BOOST_CHECK_EQUAL( 50-31, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 1, get_balance(seller, core) ); // seller got 1 core // create another limit order which will be matched later limit_order_id_type sell_id2 = create_sell_order(seller2, bitusd.amount(14), core.amount(1))->id; - BOOST_CHECK_EQUAL( 14, sell_id2(db).for_sale.value ); + BOOST_CHECK_EQUAL( 14, sell_id2(db).for_sale.get_amount().value ); BOOST_CHECK_EQUAL( 100000-14, get_balance(seller2, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller2, core) ); @@ -1493,8 +1493,8 @@ BOOST_AUTO_TEST_CASE( call_limit_rounding_test2_after_hf_342 ) BOOST_CHECK( !db.find( sell_id ) ); // the sell order is filled BOOST_CHECK( !db.find( sell_id2 ) ); // the other sell order is filled BOOST_CHECK( db.find( call_id ) != nullptr ); // the first call order did not get filled - BOOST_CHECK_EQUAL( 50-14-16, call_id(db).debt.value ); // call paid 14 USD and 16 USD - BOOST_CHECK_EQUAL( 5-1-1, call_id(db).collateral.value ); // call got 1 CORE and 1 CORE + BOOST_CHECK_EQUAL( 50-14-16, call_id(db).debt.get_amount().value ); // call paid 14 USD and 16 USD + BOOST_CHECK_EQUAL( 5-1-1, call_id(db).collateral.get_amount().value ); // call got 1 CORE and 1 CORE BOOST_CHECK_EQUAL( 50-31+(21-16), get_balance(seller_id, bitusd_id) ); // seller paid 31 USD then get refunded 5 USD BOOST_CHECK_EQUAL( 1+1, get_balance(seller_id, core_id) ); // seller got 1 more CORE BOOST_CHECK_EQUAL( 100000-14, get_balance(seller2_id, bitusd_id) ); // seller2 paid 14 USD diff --git a/tests/tests/market_tests.cpp b/tests/tests/market_tests.cpp index f71c56a1fb..1dc6ff3850 100644 --- a/tests/tests/market_tests.cpp +++ b/tests/tests/market_tests.cpp @@ -77,8 +77,8 @@ BOOST_AUTO_TEST_CASE(issue_338_etc) call_order_id_type call3_id = call3.id; transfer(borrower, seller, bitusd.amount(1000)); - BOOST_CHECK_EQUAL( 1000, call.debt.value ); - BOOST_CHECK_EQUAL( 15000, call.collateral.value ); + BOOST_CHECK_EQUAL( 1000, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15000, call.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 1000, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -103,32 +103,32 @@ BOOST_AUTO_TEST_CASE(issue_338_etc) BOOST_CHECK( !create_sell_order(seller, bitusd.amount(7), core.amount(60)) ); BOOST_CHECK_EQUAL( 993, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 60, get_balance(seller, core) ); - BOOST_CHECK_EQUAL( 993, call.debt.value ); - BOOST_CHECK_EQUAL( 14940, call.collateral.value ); + BOOST_CHECK_EQUAL( 993, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 14940, call.collateral.get_amount().value ); limit_order_id_type buy_low = create_sell_order(buyer, asset(90), bitusd.amount(10))->id; // margin call takes precedence BOOST_CHECK( !create_sell_order(seller, bitusd.amount(7), core.amount(60)) ); BOOST_CHECK_EQUAL( 986, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 120, get_balance(seller, core) ); - BOOST_CHECK_EQUAL( 986, call.debt.value ); - BOOST_CHECK_EQUAL( 14880, call.collateral.value ); + BOOST_CHECK_EQUAL( 986, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 14880, call.collateral.get_amount().value ); limit_order_id_type buy_med = create_sell_order(buyer, asset(105), bitusd.amount(10))->id; // margin call takes precedence BOOST_CHECK( !create_sell_order(seller, bitusd.amount(7), core.amount(70)) ); BOOST_CHECK_EQUAL( 979, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 190, get_balance(seller, core) ); - BOOST_CHECK_EQUAL( 979, call.debt.value ); - BOOST_CHECK_EQUAL( 14810, call.collateral.value ); + BOOST_CHECK_EQUAL( 979, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 14810, call.collateral.get_amount().value ); limit_order_id_type buy_high = create_sell_order(buyer, asset(115), bitusd.amount(10))->id; // margin call still has precedence (!) #625 BOOST_CHECK( !create_sell_order(seller, bitusd.amount(7), core.amount(77)) ); BOOST_CHECK_EQUAL( 972, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 267, get_balance(seller, core) ); - BOOST_CHECK_EQUAL( 972, call.debt.value ); - BOOST_CHECK_EQUAL( 14733, call.collateral.value ); + BOOST_CHECK_EQUAL( 972, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 14733, call.collateral.get_amount().value ); cancel_limit_order( buy_high(db) ); cancel_limit_order( buy_med(db) ); @@ -138,8 +138,8 @@ BOOST_AUTO_TEST_CASE(issue_338_etc) BOOST_CHECK( !create_sell_order(seller, bitusd.amount(700), core.amount(7700)) ); BOOST_CHECK_EQUAL( 272, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 7967, get_balance(seller, core) ); - BOOST_CHECK_EQUAL( 272, call.debt.value ); - BOOST_CHECK_EQUAL( 7033, call.collateral.value ); + BOOST_CHECK_EQUAL( 272, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 7033, call.collateral.get_amount().value ); // at this moment, collateralization of call is 7033 / 272 = 25.8 // collateralization of call2 is 15500 / 1000 = 15.5 @@ -149,8 +149,8 @@ BOOST_AUTO_TEST_CASE(issue_338_etc) BOOST_CHECK( !create_sell_order(seller, bitusd.amount(10), core.amount(110)) ); BOOST_CHECK_EQUAL( 262, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 8077, get_balance(seller, core) ); - BOOST_CHECK_EQUAL( 262, call.debt.value ); - BOOST_CHECK_EQUAL( 6923, call.collateral.value ); + BOOST_CHECK_EQUAL( 262, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 6923, call.collateral.get_amount().value ); // at this moment, collateralization of call is 6923 / 262 = 26.4 // collateralization of call2 is 15500 / 1000 = 15.5 @@ -160,18 +160,18 @@ BOOST_AUTO_TEST_CASE(issue_338_etc) force_settle( seller, bitusd.amount(10) ); BOOST_CHECK_EQUAL( 252, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 8077, get_balance(seller, core) ); - BOOST_CHECK_EQUAL( 262, call.debt.value ); - BOOST_CHECK_EQUAL( 6923, call.collateral.value ); + BOOST_CHECK_EQUAL( 262, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 6923, call.collateral.get_amount().value ); // generate blocks to let the settle order execute (price feed will expire after it) generate_blocks( HARDFORK_615_TIME + fc::hours(25) ); // call2 get settled #343 BOOST_CHECK_EQUAL( 252, get_balance(seller_id, usd_id) ); BOOST_CHECK_EQUAL( 8177, get_balance(seller_id, core_id) ); - BOOST_CHECK_EQUAL( 262, call_id(db).debt.value ); - BOOST_CHECK_EQUAL( 6923, call_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 990, call2_id(db).debt.value ); - BOOST_CHECK_EQUAL( 15400, call2_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 262, call_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 6923, call_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 990, call2_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15400, call2_id(db).collateral.get_amount().value ); set_expiration( db, trx ); update_feed_producers( usd_id(db), {feedproducer_id} ); @@ -277,12 +277,12 @@ BOOST_AUTO_TEST_CASE(hardfork_core_338_test) transfer(borrower2, seller, bitusd.amount(1000)); transfer(borrower3, seller, bitusd.amount(1000)); - BOOST_CHECK_EQUAL( 1000, call.debt.value ); - BOOST_CHECK_EQUAL( 15000, call.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call2.debt.value ); - BOOST_CHECK_EQUAL( 15500, call2.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call3.debt.value ); - BOOST_CHECK_EQUAL( 16000, call3.collateral.value ); + BOOST_CHECK_EQUAL( 1000, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15000, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call2.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15500, call2.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 16000, call3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 3000, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -312,8 +312,8 @@ BOOST_AUTO_TEST_CASE(hardfork_core_338_test) // firstly it will match with buy_high, at buy_high's price: #625 fixed BOOST_CHECK( !db.find( buy_high ) ); - BOOST_CHECK_EQUAL( db.find( buy_med )->for_sale.value, 110 ); - BOOST_CHECK_EQUAL( db.find( buy_low )->for_sale.value, 90 ); + BOOST_CHECK_EQUAL( db.find( buy_med )->for_sale.get_amount().value, 110 ); + BOOST_CHECK_EQUAL( db.find( buy_low )->for_sale.get_amount().value, 90 ); // buy_high pays 111 CORE, receives 10 USD goes to buyer's balance BOOST_CHECK_EQUAL( 10, get_balance(buyer, bitusd) ); @@ -323,12 +323,12 @@ BOOST_AUTO_TEST_CASE(hardfork_core_338_test) // then it will match with call, at mssp: 1/11 = 690/7590 : #338 fixed BOOST_CHECK_EQUAL( 2293, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 7701, get_balance(seller, core) ); - BOOST_CHECK_EQUAL( 310, call.debt.value ); - BOOST_CHECK_EQUAL( 7410, call.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call2.debt.value ); - BOOST_CHECK_EQUAL( 15500, call2.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call3.debt.value ); - BOOST_CHECK_EQUAL( 16000, call3.collateral.value ); + BOOST_CHECK_EQUAL( 310, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 7410, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call2.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15500, call2.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 16000, call3.collateral.get_amount().value ); // call's call_price will be updated after the match, to 741/31/1.75 CORE/USD = 2964/217 // it's above settlement price (10/1) so won't be margin called again @@ -337,18 +337,18 @@ BOOST_AUTO_TEST_CASE(hardfork_core_338_test) // This would match with call before, but would match with call2 after #343 fixed BOOST_CHECK( !create_sell_order(seller, bitusd.amount(700), core.amount(6000) ) ); - BOOST_CHECK_EQUAL( db.find( buy_med )->for_sale.value, 110 ); - BOOST_CHECK_EQUAL( db.find( buy_low )->for_sale.value, 90 ); + BOOST_CHECK_EQUAL( db.find( buy_med )->for_sale.get_amount().value, 110 ); + BOOST_CHECK_EQUAL( db.find( buy_low )->for_sale.get_amount().value, 90 ); // fill price would be mssp: 1/11 = 700/7700 : #338 fixed BOOST_CHECK_EQUAL( 1593, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 15401, get_balance(seller, core) ); - BOOST_CHECK_EQUAL( 310, call.debt.value ); - BOOST_CHECK_EQUAL( 7410, call.collateral.value ); - BOOST_CHECK_EQUAL( 300, call2.debt.value ); - BOOST_CHECK_EQUAL( 7800, call2.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call3.debt.value ); - BOOST_CHECK_EQUAL( 16000, call3.collateral.value ); + BOOST_CHECK_EQUAL( 310, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 7410, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 300, call2.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 7800, call2.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 16000, call3.collateral.get_amount().value ); // call2's call_price will be updated after the match, to 78/3/1.75 CORE/USD = 312/21 if(!hf1270) // can use call price only if we are before hf1270 BOOST_CHECK( price(asset(312),asset(21,usd_id)) == call2.call_price ); @@ -363,12 +363,12 @@ BOOST_AUTO_TEST_CASE(hardfork_core_338_test) BOOST_CHECK_EQUAL( 1583, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 15401, get_balance(seller, core) ); - BOOST_CHECK_EQUAL( 310, call.debt.value ); - BOOST_CHECK_EQUAL( 7410, call.collateral.value ); - BOOST_CHECK_EQUAL( 300, call2.debt.value ); - BOOST_CHECK_EQUAL( 7800, call2.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call3.debt.value ); - BOOST_CHECK_EQUAL( 16000, call3.collateral.value ); + BOOST_CHECK_EQUAL( 310, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 7410, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 300, call2.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 7800, call2.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 16000, call3.collateral.get_amount().value ); // generate blocks to let the settle order execute (price feed will expire after it) generate_block(); @@ -377,12 +377,12 @@ BOOST_AUTO_TEST_CASE(hardfork_core_338_test) // call3 get settled, at settlement price 1/10: #343 fixed BOOST_CHECK_EQUAL( 1583, get_balance(seller_id, usd_id) ); BOOST_CHECK_EQUAL( 15501, get_balance(seller_id, core_id) ); - BOOST_CHECK_EQUAL( 310, call_id(db).debt.value ); - BOOST_CHECK_EQUAL( 7410, call_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 300, call2_id(db).debt.value ); - BOOST_CHECK_EQUAL( 7800, call2_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 990, call3_id(db).debt.value ); - BOOST_CHECK_EQUAL( 15900, call3_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 310, call_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 7410, call_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 300, call2_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 7800, call2_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 990, call3_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15900, call3_id(db).collateral.get_amount().value ); set_expiration( db, trx ); update_feed_producers( usd_id(db), {feedproducer_id} ); @@ -459,12 +459,12 @@ BOOST_AUTO_TEST_CASE(hardfork_core_453_test) transfer(borrower2, seller, bitusd.amount(1000)); transfer(borrower3, seller, bitusd.amount(1000)); - BOOST_CHECK_EQUAL( 1000, call.debt.value ); - BOOST_CHECK_EQUAL( 15000, call.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call2.debt.value ); - BOOST_CHECK_EQUAL( 15500, call2.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call3.debt.value ); - BOOST_CHECK_EQUAL( 16000, call3.collateral.value ); + BOOST_CHECK_EQUAL( 1000, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15000, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call2.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15500, call2.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 16000, call3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 3000, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -544,12 +544,12 @@ BOOST_AUTO_TEST_CASE(hardfork_core_625_big_limit_order_test) transfer(borrower2, seller, bitusd.amount(1000)); transfer(borrower3, seller, bitusd.amount(1000)); - BOOST_CHECK_EQUAL( 1000, call.debt.value ); - BOOST_CHECK_EQUAL( 15000, call.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call2.debt.value ); - BOOST_CHECK_EQUAL( 15500, call2.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call3.debt.value ); - BOOST_CHECK_EQUAL( 25000, call3.collateral.value ); + BOOST_CHECK_EQUAL( 1000, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15000, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call2.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15500, call2.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 25000, call3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 3000, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); BOOST_CHECK_EQUAL( 3000, get_balance(seller, bitusd) ); @@ -567,7 +567,7 @@ BOOST_AUTO_TEST_CASE(hardfork_core_625_big_limit_order_test) // This sell order above MSSP will not be matched with a call limit_order_id_type sell_high = create_sell_order(seller, bitusd.amount(7), core.amount(78))->id; - BOOST_CHECK_EQUAL( db.find( sell_high )->for_sale.value, 7 ); + BOOST_CHECK_EQUAL( db.find( sell_high )->for_sale.get_amount().value, 7 ); BOOST_CHECK_EQUAL( 2993, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -612,14 +612,14 @@ BOOST_AUTO_TEST_CASE(hardfork_core_625_big_limit_order_test) BOOST_CHECK_EQUAL( 783, get_balance(buyer2, bitusd) ); // 700*4-10-1000-1000=790, minus 1% market fee 790*100/10000=7 BOOST_CHECK_EQUAL( init_balance - 11000, get_balance(buyer2, core) ); // buy_med pays at 1/11 = 790/8690 - BOOST_CHECK_EQUAL( db.find( buy_med )->for_sale.value, 11000-8690 ); + BOOST_CHECK_EQUAL( db.find( buy_med )->for_sale.get_amount().value, 11000-8690 ); // call3 is not in margin call territory so won't be matched - BOOST_CHECK_EQUAL( 1000, call3.debt.value ); - BOOST_CHECK_EQUAL( 25000, call3.collateral.value ); + BOOST_CHECK_EQUAL( 1000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 25000, call3.collateral.get_amount().value ); // buy_low's price is too low that won't be matched - BOOST_CHECK_EQUAL( db.find( buy_low )->for_sale.value, 80 ); + BOOST_CHECK_EQUAL( db.find( buy_low )->for_sale.get_amount().value, 80 ); // check seller balance BOOST_CHECK_EQUAL( 193, get_balance(seller, bitusd) ); // 3000 - 7 - 700*4 @@ -633,17 +633,17 @@ BOOST_AUTO_TEST_CASE(hardfork_core_625_big_limit_order_test) // Create another sell order slightly below the call price, won't fill limit_order_id_type sell_med = create_sell_order( seller, bitusd.amount(7), core.amount(59) )->id; - BOOST_CHECK_EQUAL( db.find( sell_med )->for_sale.value, 7 ); + BOOST_CHECK_EQUAL( db.find( sell_med )->for_sale.get_amount().value, 7 ); // check seller balance BOOST_CHECK_EQUAL( 193-7, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 30801, get_balance(seller, core) ); // call3 is not in margin call territory so won't be matched - BOOST_CHECK_EQUAL( 1000, call3.debt.value ); - BOOST_CHECK_EQUAL( 25000, call3.collateral.value ); + BOOST_CHECK_EQUAL( 1000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 25000, call3.collateral.get_amount().value ); // buy_low's price is too low that won't be matched - BOOST_CHECK_EQUAL( db.find( buy_low )->for_sale.value, 80 ); + BOOST_CHECK_EQUAL( db.find( buy_low )->for_sale.get_amount().value, 80 ); // generate a block generate_block(); @@ -722,26 +722,26 @@ BOOST_AUTO_TEST_CASE(hard_fork_453_cross_test) transfer(borrower2, seller, bitcny.amount(1000)); transfer(borrower3, seller, bitcny.amount(1000)); - BOOST_CHECK_EQUAL( 1000, call_usd.debt.value ); - BOOST_CHECK_EQUAL( 15000, call_usd.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call_usd2.debt.value ); - BOOST_CHECK_EQUAL( 15500, call_usd2.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call_usd3.debt.value ); - BOOST_CHECK_EQUAL( 16000, call_usd3.collateral.value ); + BOOST_CHECK_EQUAL( 1000, call_usd.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15000, call_usd.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call_usd2.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15500, call_usd2.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call_usd3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 16000, call_usd3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 3000, get_balance(seller, bitusd) ); - BOOST_CHECK_EQUAL( 1000, call_eur.debt.value ); - BOOST_CHECK_EQUAL( 15000, call_eur.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call_eur2.debt.value ); - BOOST_CHECK_EQUAL( 15500, call_eur2.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call_eur3.debt.value ); - BOOST_CHECK_EQUAL( 16000, call_eur3.collateral.value ); + BOOST_CHECK_EQUAL( 1000, call_eur.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15000, call_eur.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call_eur2.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15500, call_eur2.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call_eur3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 16000, call_eur3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 3000, get_balance(seller, biteur) ); - BOOST_CHECK_EQUAL( 1000, call_cny.debt.value ); - BOOST_CHECK_EQUAL( 15000, call_cny.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call_cny2.debt.value ); - BOOST_CHECK_EQUAL( 15500, call_cny2.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call_cny3.debt.value ); - BOOST_CHECK_EQUAL( 16000, call_cny3.collateral.value ); + BOOST_CHECK_EQUAL( 1000, call_cny.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15000, call_cny.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call_cny2.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15500, call_cny2.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call_cny3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 16000, call_cny3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 3000, get_balance(seller, bitcny) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -807,9 +807,9 @@ BOOST_AUTO_TEST_CASE(hard_fork_453_cross_test) // sell_med and call3 should get matched BOOST_CHECK( !db.find( sell_usd_med ) ); // call3 now is not at margin call state, so sell_med2 won't get matched - BOOST_CHECK_EQUAL( db.find( sell_usd_med2 )->for_sale.value, 7 ); + BOOST_CHECK_EQUAL( db.find( sell_usd_med2 )->for_sale.get_amount().value, 7 ); // sell_high should still be there, didn't match anything - BOOST_CHECK_EQUAL( db.find( sell_usd_high )->for_sale.value, 7 ); + BOOST_CHECK_EQUAL( db.find( sell_usd_high )->for_sale.get_amount().value, 7 ); // sell_low and call should get matched first BOOST_CHECK( !db.find( sell_eur_low ) ); @@ -821,9 +821,9 @@ BOOST_AUTO_TEST_CASE(hard_fork_453_cross_test) // sell_med and call3 should get matched BOOST_CHECK( !db.find( sell_eur_med ) ); // call3 now is not at margin call state, so sell_med2 won't get matched - BOOST_CHECK_EQUAL( db.find( sell_eur_med2 )->for_sale.value, 7 ); + BOOST_CHECK_EQUAL( db.find( sell_eur_med2 )->for_sale.get_amount().value, 7 ); // sell_high should still be there, didn't match anything - BOOST_CHECK_EQUAL( db.find( sell_eur_high )->for_sale.value, 7 ); + BOOST_CHECK_EQUAL( db.find( sell_eur_high )->for_sale.get_amount().value, 7 ); // sell_low and call should get matched first BOOST_CHECK( !db.find( sell_cny_low ) ); @@ -835,21 +835,21 @@ BOOST_AUTO_TEST_CASE(hard_fork_453_cross_test) // sell_med and call3 should get matched BOOST_CHECK( !db.find( sell_cny_med ) ); // call3 now is not at margin call state, so sell_med2 won't get matched - BOOST_CHECK_EQUAL( db.find( sell_cny_med2 )->for_sale.value, 7 ); + BOOST_CHECK_EQUAL( db.find( sell_cny_med2 )->for_sale.get_amount().value, 7 ); // sell_high should still be there, didn't match anything - BOOST_CHECK_EQUAL( db.find( sell_cny_high )->for_sale.value, 7 ); + BOOST_CHECK_EQUAL( db.find( sell_cny_high )->for_sale.get_amount().value, 7 ); // all match price would be limit order price BOOST_CHECK_EQUAL( 3000-1000-1007-7-700-7, get_balance(seller_id, usd_id) ); BOOST_CHECK_EQUAL( 3000-1000-1007-7-700-7, get_balance(seller_id, eur_id) ); BOOST_CHECK_EQUAL( 3000-1000-1007-7-700-7, get_balance(seller_id, cny_id) ); BOOST_CHECK_EQUAL( (7000+8056+6400)*3, get_balance(seller_id, core_id) ); - BOOST_CHECK_EQUAL( 1000-7-700, call_usd3_id(db).debt.value ); - BOOST_CHECK_EQUAL( 16000-56-6400, call_usd3_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 1000-7-700, call_eur3_id(db).debt.value ); - BOOST_CHECK_EQUAL( 16000-56-6400, call_eur3_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 1000-7-700, call_cny3_id(db).debt.value ); - BOOST_CHECK_EQUAL( 16000-56-6400, call_cny3_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 1000-7-700, call_usd3_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 16000-56-6400, call_usd3_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000-7-700, call_eur3_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 16000-56-6400, call_eur3_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000-7-700, call_cny3_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 16000-56-6400, call_cny3_id(db).collateral.get_amount().value ); // call3's call_price should be updated: 9544/293/1.75 = 9544*4 / 293*7 = 38176/2051 CORE/USD BOOST_CHECK( price(asset(38176),asset(2051,usd_id)) == call_usd3_id(db).call_price ); BOOST_CHECK( price(asset(38176),asset(2051,eur_id)) == call_eur3_id(db).call_price ); @@ -907,12 +907,12 @@ BOOST_AUTO_TEST_CASE(hard_fork_338_cross_test) transfer(borrower2, seller, bitusd.amount(1000)); transfer(borrower3, seller, bitusd.amount(1000)); - BOOST_CHECK_EQUAL( 1000, call.debt.value ); - BOOST_CHECK_EQUAL( 15000, call.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call2.debt.value ); - BOOST_CHECK_EQUAL( 15500, call2.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call3.debt.value ); - BOOST_CHECK_EQUAL( 16000, call3.collateral.value ); + BOOST_CHECK_EQUAL( 1000, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15000, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call2.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15500, call2.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 16000, call3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 3000, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -964,7 +964,7 @@ BOOST_AUTO_TEST_CASE(hard_fork_338_cross_test) // since 16.1 > 16, global settlement should at feed price 16/1 // so settlement fund should be 986*16 + 1000*16 - BOOST_CHECK_EQUAL( 1986*16, usd_id(db).bitasset_data(db).settlement_fund.value ); + BOOST_CHECK_EQUAL( 1986*16, usd_id(db).bitasset_data(db).settlement_fund.get_amount().value ); // global settlement price should be 16/1, since no rounding here BOOST_CHECK( price(asset(1,usd_id),asset(16) ) == usd_id(db).bitasset_data(db).settlement_price ); @@ -1024,12 +1024,12 @@ BOOST_AUTO_TEST_CASE(hard_fork_649_cross_test) transfer(borrower2, seller, bitusd.amount(1000)); transfer(borrower3, seller, bitusd.amount(1000)); - BOOST_CHECK_EQUAL( 1000, call.debt.value ); - BOOST_CHECK_EQUAL( 15000, call.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call2.debt.value ); - BOOST_CHECK_EQUAL( 15500, call2.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call3.debt.value ); - BOOST_CHECK_EQUAL( 16000, call3.collateral.value ); + BOOST_CHECK_EQUAL( 1000, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15000, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call2.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15500, call2.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 16000, call3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 3000, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -1042,8 +1042,8 @@ BOOST_AUTO_TEST_CASE(hard_fork_649_cross_test) BOOST_CHECK( !create_sell_order(seller, bitusd.amount(707), core.amount(6464)) ); BOOST_CHECK_EQUAL( 3000-707, get_balance(seller_id, usd_id) ); BOOST_CHECK_EQUAL( 6464, get_balance(seller_id, core_id) ); - BOOST_CHECK_EQUAL( 293, call.debt.value ); - BOOST_CHECK_EQUAL( 8536, call.collateral.value ); + BOOST_CHECK_EQUAL( 293, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 8536, call.collateral.get_amount().value ); // at this moment, // collateralization of call is 8536 / 293 = 29.1 @@ -1076,7 +1076,7 @@ BOOST_AUTO_TEST_CASE(hard_fork_649_cross_test) // since least collateral ratio 15.5 < 20, global settlement should execute at price = least collateral ratio 15.5/1 // so settlement fund should be 15500 + 15500 + round_up(15.5 * 293) - BOOST_CHECK_EQUAL( 15500*2 + (293 * 155 + 9) / 10, usd_id(db).bitasset_data(db).settlement_fund.value ); + BOOST_CHECK_EQUAL( 15500*2 + (293 * 155 + 9) / 10, usd_id(db).bitasset_data(db).settlement_fund.get_amount().value ); // global settlement price should be settlement_fund/(2000+293), but not 15.5/1 due to rounding BOOST_CHECK( price(asset(2293,usd_id),asset(15500*2+(293*155+9)/10) ) == usd_id(db).bitasset_data(db).settlement_price ); @@ -1138,12 +1138,12 @@ BOOST_AUTO_TEST_CASE(hard_fork_343_cross_test) transfer(borrower2, seller, bitusd.amount(1000)); transfer(borrower3, seller, bitusd.amount(1000)); - BOOST_CHECK_EQUAL( 1000, call.debt.value ); - BOOST_CHECK_EQUAL( 15000, call.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call2.debt.value ); - BOOST_CHECK_EQUAL( 15500, call2.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call3.debt.value ); - BOOST_CHECK_EQUAL( 17500, call3.collateral.value ); + BOOST_CHECK_EQUAL( 1000, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15000, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call2.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15500, call2.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 17500, call3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 3000, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -1156,8 +1156,8 @@ BOOST_AUTO_TEST_CASE(hard_fork_343_cross_test) BOOST_CHECK( !create_sell_order(seller, bitusd.amount(700), core.amount(6400)) ); BOOST_CHECK_EQUAL( 3000-700, get_balance(seller_id, usd_id) ); BOOST_CHECK_EQUAL( 6400, get_balance(seller_id, core_id) ); - BOOST_CHECK_EQUAL( 300, call.debt.value ); - BOOST_CHECK_EQUAL( 8600, call.collateral.value ); + BOOST_CHECK_EQUAL( 300, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 8600, call.collateral.get_amount().value ); // at this moment, // collateralization of call is 8600 / 300 = 28.67 @@ -1175,12 +1175,12 @@ BOOST_AUTO_TEST_CASE(hard_fork_343_cross_test) BOOST_CHECK( !create_sell_order(seller_id(db), asset(7*50,usd_id), asset(65*50)) ); BOOST_CHECK_EQUAL( 3000-700-7*50, get_balance(seller_id, usd_id) ); BOOST_CHECK_EQUAL( 6400+77*50, get_balance(seller_id, core_id) ); - BOOST_CHECK_EQUAL( 300, call_id(db).debt.value ); - BOOST_CHECK_EQUAL( 8600, call_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 1000-7*50, call2_id(db).debt.value ); - BOOST_CHECK_EQUAL( 15500-77*50, call2_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 1000, call3_id(db).debt.value ); - BOOST_CHECK_EQUAL( 17500, call3_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 300, call_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 8600, call_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000-7*50, call2_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15500-77*50, call2_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call3_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 17500, call3_id(db).collateral.get_amount().value ); // at this moment, // collateralization of call is 8600 / 300 = 28.67 @@ -1191,12 +1191,12 @@ BOOST_AUTO_TEST_CASE(hard_fork_343_cross_test) BOOST_CHECK( !create_sell_order(seller_id(db), asset(7,usd_id), asset(65)) ); BOOST_CHECK_EQUAL( 3000-700-7*50-7, get_balance(seller_id, usd_id) ); BOOST_CHECK_EQUAL( 6400+77*50+77, get_balance(seller_id, core_id) ); - BOOST_CHECK_EQUAL( 300, call_id(db).debt.value ); - BOOST_CHECK_EQUAL( 8600, call_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 1000-7*50, call2_id(db).debt.value ); - BOOST_CHECK_EQUAL( 15500-77*50, call2_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 1000-7, call3_id(db).debt.value ); - BOOST_CHECK_EQUAL( 17500-77, call3_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 300, call_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 8600, call_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000-7*50, call2_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15500-77*50, call2_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000-7, call3_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 17500-77, call3_id(db).collateral.get_amount().value ); // at this moment, // collateralization of call is 8600 / 300 = 28.67 @@ -1259,12 +1259,12 @@ BOOST_AUTO_TEST_CASE(target_cr_test_limit_call) transfer(borrower2, seller, bitusd.amount(1000)); transfer(borrower3, seller, bitusd.amount(1000)); - BOOST_CHECK_EQUAL( 1000, call.debt.value ); - BOOST_CHECK_EQUAL( 15000, call.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call2.debt.value ); - BOOST_CHECK_EQUAL( 15500, call2.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call3.debt.value ); - BOOST_CHECK_EQUAL( 25000, call3.collateral.value ); + BOOST_CHECK_EQUAL( 1000, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15000, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call2.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15500, call2.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 25000, call3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 3000, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); BOOST_CHECK_EQUAL( 3000, get_balance(seller, bitusd) ); @@ -1282,7 +1282,7 @@ BOOST_AUTO_TEST_CASE(target_cr_test_limit_call) // This sell order above MSSP will not be matched with a call limit_order_id_type sell_high = create_sell_order(seller, bitusd.amount(7), core.amount(78))->id; - BOOST_CHECK_EQUAL( db.find( sell_high )->for_sale.value, 7 ); + BOOST_CHECK_EQUAL( db.find( sell_high )->for_sale.get_amount().value, 7 ); BOOST_CHECK_EQUAL( 2993, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -1305,8 +1305,8 @@ BOOST_AUTO_TEST_CASE(target_cr_test_limit_call) price match_price( bitusd.amount(1) / core.amount(11) ); share_type call_to_cover = call_id(db).get_max_debt_to_cover(match_price,current_feed.settlement_price,1750); share_type call2_to_cover = call2_id(db).get_max_debt_to_cover(match_price,current_feed.settlement_price,1750); - BOOST_CHECK_LT( call_to_cover.value, call_id(db).debt.value ); - BOOST_CHECK_LT( call2_to_cover.value, call2_id(db).debt.value ); + BOOST_CHECK_LT( call_to_cover.value, call_id(db).debt.get_amount().value ); + BOOST_CHECK_LT( call2_to_cover.value, call2_id(db).debt.get_amount().value ); // even though call2 has a higher CR, since call's TCR is less than call2's TCR, so we expect call will cover less when called BOOST_CHECK_LT( call_to_cover.value, call2_to_cover.value ); @@ -1325,10 +1325,10 @@ BOOST_AUTO_TEST_CASE(target_cr_test_limit_call) // call will receive call_to_cover, pay 11*call_to_cover share_type call_to_pay = call_to_cover * 11; - BOOST_CHECK_EQUAL( 1000 - call_to_cover.value, call.debt.value ); - BOOST_CHECK_EQUAL( 15000 - call_to_pay.value, call.collateral.value ); + BOOST_CHECK_EQUAL( 1000 - call_to_cover.value, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15000 - call_to_pay.value, call.collateral.get_amount().value ); // new collateral ratio should be higher than mcr as well as tcr - BOOST_CHECK( call.debt.value * 10 * 1750 < call.collateral.value * 1000 ); + BOOST_CHECK( call.debt.get_amount().value * 10 * 1750 < call.collateral.get_amount().value * 1000 ); idump( (call) ); // borrower's balance doesn't change BOOST_CHECK_EQUAL( init_balance - 15000, get_balance(borrower, core) ); @@ -1340,10 +1340,10 @@ BOOST_AUTO_TEST_CASE(target_cr_test_limit_call) // call2 will receive call2_to_cover, pay 11*call2_to_cover share_type call2_to_pay = call2_to_cover * 11; - BOOST_CHECK_EQUAL( 1000 - call2_to_cover.value, call2.debt.value ); - BOOST_CHECK_EQUAL( 15500 - call2_to_pay.value, call2.collateral.value ); + BOOST_CHECK_EQUAL( 1000 - call2_to_cover.value, call2.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15500 - call2_to_pay.value, call2.collateral.get_amount().value ); // new collateral ratio should be higher than mcr as well as tcr - BOOST_CHECK( call2.debt.value * 10 * 2000 < call2.collateral.value * 1000 ); + BOOST_CHECK( call2.debt.get_amount().value * 10 * 2000 < call2.collateral.get_amount().value * 1000 ); idump( (call2) ); // borrower2's balance doesn't change BOOST_CHECK_EQUAL( init_balance - 15500, get_balance(borrower2, core) ); @@ -1356,14 +1356,14 @@ BOOST_AUTO_TEST_CASE(target_cr_test_limit_call) buy_med_get -= (buy_med_get/100); // minus 1% market fee BOOST_CHECK_EQUAL( buy_med_get.value, get_balance(buyer2, bitusd) ); BOOST_CHECK_EQUAL( init_balance - 33000, get_balance(buyer2, core) ); - BOOST_CHECK_EQUAL( db.find( buy_med )->for_sale.value, 33000-buy_med_pay.value ); + BOOST_CHECK_EQUAL( db.find( buy_med )->for_sale.get_amount().value, 33000-buy_med_pay.value ); // call3 is not in margin call territory so won't be matched - BOOST_CHECK_EQUAL( 1000, call3.debt.value ); - BOOST_CHECK_EQUAL( 25000, call3.collateral.value ); + BOOST_CHECK_EQUAL( 1000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 25000, call3.collateral.get_amount().value ); // buy_low's price is too low that won't be matched - BOOST_CHECK_EQUAL( db.find( buy_low )->for_sale.value, 80 ); + BOOST_CHECK_EQUAL( db.find( buy_low )->for_sale.get_amount().value, 80 ); // check seller balance BOOST_CHECK_EQUAL( 193, get_balance(seller, bitusd) ); // 3000 - 7 - 700*4 @@ -1377,17 +1377,17 @@ BOOST_AUTO_TEST_CASE(target_cr_test_limit_call) // Create another sell order slightly below the call price, won't fill limit_order_id_type sell_med = create_sell_order( seller, bitusd.amount(7), core.amount(59) )->id; - BOOST_CHECK_EQUAL( db.find( sell_med )->for_sale.value, 7 ); + BOOST_CHECK_EQUAL( db.find( sell_med )->for_sale.get_amount().value, 7 ); // check seller balance BOOST_CHECK_EQUAL( 193-7, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 30801, get_balance(seller, core) ); // call3 is not in margin call territory so won't be matched - BOOST_CHECK_EQUAL( 1000, call3.debt.value ); - BOOST_CHECK_EQUAL( 25000, call3.collateral.value ); + BOOST_CHECK_EQUAL( 1000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 25000, call3.collateral.get_amount().value ); // buy_low's price is too low that won't be matched - BOOST_CHECK_EQUAL( db.find( buy_low )->for_sale.value, 80 ); + BOOST_CHECK_EQUAL( db.find( buy_low )->for_sale.get_amount().value, 80 ); // generate a block generate_block(); @@ -1441,12 +1441,12 @@ BOOST_AUTO_TEST_CASE(target_cr_test_call_limit) transfer(borrower2, seller, bitusd.amount(1000)); transfer(borrower3, seller, bitusd.amount(1000)); - BOOST_CHECK_EQUAL( 1000, call.debt.value ); - BOOST_CHECK_EQUAL( 15000, call.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call2.debt.value ); - BOOST_CHECK_EQUAL( 15500, call2.collateral.value ); - BOOST_CHECK_EQUAL( 1000, call3.debt.value ); - BOOST_CHECK_EQUAL( 25000, call3.collateral.value ); + BOOST_CHECK_EQUAL( 1000, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15000, call.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call2.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15500, call2.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 1000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 25000, call3.collateral.get_amount().value ); BOOST_CHECK_EQUAL( 3000, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); BOOST_CHECK_EQUAL( 3000, get_balance(seller, bitusd) ); @@ -1459,7 +1459,7 @@ BOOST_AUTO_TEST_CASE(target_cr_test_call_limit) // This sell order above MSSP will not be matched with a call limit_order_id_type sell_high = create_sell_order(seller, bitusd.amount(7), core.amount(78))->id; - BOOST_CHECK_EQUAL( db.find( sell_high )->for_sale.value, 7 ); + BOOST_CHECK_EQUAL( db.find( sell_high )->for_sale.get_amount().value, 7 ); BOOST_CHECK_EQUAL( 2993, get_balance(seller, bitusd) ); BOOST_CHECK_EQUAL( 0, get_balance(seller, core) ); @@ -1472,7 +1472,7 @@ BOOST_AUTO_TEST_CASE(target_cr_test_call_limit) // Create a sell order which will be matched with several call orders later, price 1/9 limit_order_id_type sell_id = create_sell_order(seller, bitusd.amount(500), core.amount(4500) )->id; - BOOST_CHECK_EQUAL( db.find( sell_id )->for_sale.value, 500 ); + BOOST_CHECK_EQUAL( db.find( sell_id )->for_sale.get_amount().value, 500 ); // prepare price feed to get call and call2 (but not call3) into margin call territory current_feed.settlement_price = bitusd.amount( 1 ) / core.amount(10); @@ -1481,8 +1481,8 @@ BOOST_AUTO_TEST_CASE(target_cr_test_call_limit) price match_price = sell_id(db).sell_price; share_type call_to_cover = call_id(db).get_max_debt_to_cover(match_price,current_feed.settlement_price,1750); share_type call2_to_cover = call2_id(db).get_max_debt_to_cover(match_price,current_feed.settlement_price,1750); - BOOST_CHECK_LT( call_to_cover.value, call_id(db).debt.value ); - BOOST_CHECK_LT( call2_to_cover.value, call2_id(db).debt.value ); + BOOST_CHECK_LT( call_to_cover.value, call_id(db).debt.get_amount().value ); + BOOST_CHECK_LT( call2_to_cover.value, call2_id(db).debt.get_amount().value ); // even though call2 has a higher CR, since call's TCR is less than call2's TCR, so we expect call will cover less when called BOOST_CHECK_LT( call_to_cover.value, call2_to_cover.value ); @@ -1496,10 +1496,10 @@ BOOST_AUTO_TEST_CASE(target_cr_test_call_limit) // call will receive call_to_cover, pay 9*call_to_cover share_type call_to_pay = call_to_cover * 9; - BOOST_CHECK_EQUAL( 1000 - call_to_cover.value, call.debt.value ); - BOOST_CHECK_EQUAL( 15000 - call_to_pay.value, call.collateral.value ); + BOOST_CHECK_EQUAL( 1000 - call_to_cover.value, call.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15000 - call_to_pay.value, call.collateral.get_amount().value ); // new collateral ratio should be higher than mcr as well as tcr - BOOST_CHECK( call.debt.value * 10 * 1750 < call.collateral.value * 1000 ); + BOOST_CHECK( call.debt.get_amount().value * 10 * 1750 < call.collateral.get_amount().value * 1000 ); idump( (call) ); // borrower's balance doesn't change BOOST_CHECK_EQUAL( init_balance - 15000, get_balance(borrower, core) ); @@ -1513,16 +1513,16 @@ BOOST_AUTO_TEST_CASE(target_cr_test_call_limit) // however it's not the case, so call2 will receive less call2_to_cover = 500 - call_to_cover; share_type call2_to_pay = call2_to_cover * 9; - BOOST_CHECK_EQUAL( 1000 - call2_to_cover.value, call2.debt.value ); - BOOST_CHECK_EQUAL( 15500 - call2_to_pay.value, call2.collateral.value ); + BOOST_CHECK_EQUAL( 1000 - call2_to_cover.value, call2.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 15500 - call2_to_pay.value, call2.collateral.get_amount().value ); idump( (call2) ); // borrower2's balance doesn't change BOOST_CHECK_EQUAL( init_balance - 15500, get_balance(borrower2, core) ); BOOST_CHECK_EQUAL( 0, get_balance(borrower2, bitusd) ); // call3 is not in margin call territory so won't be matched - BOOST_CHECK_EQUAL( 1000, call3.debt.value ); - BOOST_CHECK_EQUAL( 25000, call3.collateral.value ); + BOOST_CHECK_EQUAL( 1000, call3.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 25000, call3.collateral.get_amount().value ); // sell_id is completely filled BOOST_CHECK( !db.find( sell_id ) ); @@ -1532,7 +1532,7 @@ BOOST_AUTO_TEST_CASE(target_cr_test_call_limit) BOOST_CHECK_EQUAL( 4500, get_balance(seller, core) ); // 500*9 // buy_low's price is too low that won't be matched - BOOST_CHECK_EQUAL( db.find( buy_low )->for_sale.value, 80 ); + BOOST_CHECK_EQUAL( db.find( buy_low )->for_sale.get_amount().value, 80 ); // generate a block generate_block(); diff --git a/tests/tests/operation_tests.cpp b/tests/tests/operation_tests.cpp index 205adb8281..65e4e0fafb 100644 --- a/tests/tests/operation_tests.cpp +++ b/tests/tests/operation_tests.cpp @@ -787,7 +787,7 @@ BOOST_AUTO_TEST_CASE( prediction_market ) // force settle the rest force_settle( dan, pmark.amount(400) ); - BOOST_CHECK_EQUAL( 0, pmark_dd_id(db).current_supply.value ); + BOOST_CHECK_EQUAL( 0, pmark_dd_id(db).current_supply.get_amount().value ); generate_block(~database::skip_transaction_dupe_check); generate_blocks( db.get_dynamic_global_properties().next_maintenance_time ); @@ -825,7 +825,7 @@ BOOST_AUTO_TEST_CASE( prediction_market_resolves_to_0 ) // force settle the rest force_settle( dan, pmark.amount(900) ); - BOOST_CHECK_EQUAL( 0, pmark_dd_id(db).current_supply.value ); + BOOST_CHECK_EQUAL( 0, pmark_dd_id(db).current_supply.get_amount().value ); generate_block(~database::skip_transaction_dupe_check); generate_blocks( db.get_dynamic_global_properties().next_maintenance_time ); @@ -1035,7 +1035,7 @@ BOOST_AUTO_TEST_CASE( create_mia ) const asset_object& bitusd = create_bitasset( "USDBIT" ); BOOST_CHECK(bitusd.symbol == "USDBIT"); BOOST_CHECK(bitusd.bitasset_data(db).options.short_backing_asset == asset_id_type()); - BOOST_CHECK(bitusd.dynamic_asset_data_id(db).current_supply == 0); + BOOST_CHECK(bitusd.dynamic_asset_data_id(db).current_supply.get_amount() == 0); GRAPHENE_REQUIRE_THROW( create_bitasset("USDBIT"), fc::exception); } catch ( const fc::exception& e ) { elog( "${e}", ("e", e.to_detail_string() ) ); @@ -1126,9 +1126,9 @@ BOOST_AUTO_TEST_CASE( create_uia ) GRAPHENE_REQUIRE_THROW(PUSH_TX( db, trx, ~0 ), fc::exception); const asset_dynamic_data_object& test_asset_dynamic_data = test_asset.dynamic_asset_data_id(db); - BOOST_CHECK(test_asset_dynamic_data.current_supply == 0); - BOOST_CHECK(test_asset_dynamic_data.accumulated_fees == 0); - BOOST_CHECK(test_asset_dynamic_data.fee_pool == 0); + BOOST_CHECK(test_asset_dynamic_data.current_supply.get_amount()== 0); + BOOST_CHECK(test_asset_dynamic_data.accumulated_fees.get_amount() == 0); + BOOST_CHECK(test_asset_dynamic_data.fee_pool.get_amount() == 0); auto op = trx.operations.back().get(); op.symbol = "TESTFAIL"; @@ -1386,16 +1386,16 @@ BOOST_AUTO_TEST_CASE( issue_uia ) const asset_dynamic_data_object& test_dynamic_data = test_asset.dynamic_asset_data_id(db); BOOST_CHECK_EQUAL(get_balance(nathan_account, test_asset), 5000000); - BOOST_CHECK(test_dynamic_data.current_supply == 5000000); - BOOST_CHECK(test_dynamic_data.accumulated_fees == 0); - BOOST_CHECK(test_dynamic_data.fee_pool == 0); + BOOST_CHECK(test_dynamic_data.current_supply.get_amount() == 5000000); + BOOST_CHECK(test_dynamic_data.accumulated_fees.get_amount() == 0); + BOOST_CHECK(test_dynamic_data.fee_pool.get_amount() == 0); PUSH_TX( db, trx, ~0 ); BOOST_CHECK_EQUAL(get_balance(nathan_account, test_asset), 10000000); - BOOST_CHECK(test_dynamic_data.current_supply == 10000000); - BOOST_CHECK(test_dynamic_data.accumulated_fees == 0); - BOOST_CHECK(test_dynamic_data.fee_pool == 0); + BOOST_CHECK(test_dynamic_data.current_supply.get_amount() == 10000000); + BOOST_CHECK(test_dynamic_data.accumulated_fees.get_amount() == 0); + BOOST_CHECK(test_dynamic_data.fee_pool.get_amount() == 0); } catch(fc::exception& e) { edump((e.to_detail_string())); throw; @@ -1463,7 +1463,7 @@ BOOST_AUTO_TEST_CASE( create_buy_uia_multiple_match_new ) BOOST_CHECK_EQUAL( get_balance( seller_account, test_asset ), 200 ); BOOST_CHECK_EQUAL( get_balance( buyer_account, core_asset ), 297 ); - BOOST_CHECK_EQUAL( core_asset.dynamic_asset_data_id(db).accumulated_fees.value , 3 ); + BOOST_CHECK_EQUAL( core_asset.dynamic_asset_data_id(db).accumulated_fees.get_amount().value , 3 ); } catch ( const fc::exception& e ) { @@ -1503,7 +1503,7 @@ BOOST_AUTO_TEST_CASE( create_buy_exact_match_uia ) BOOST_CHECK_EQUAL( get_balance( seller_account, test_asset ), 99 ); BOOST_CHECK_EQUAL( get_balance( buyer_account, core_asset ), 100 ); - BOOST_CHECK_EQUAL( test_asset.dynamic_asset_data_id(db).accumulated_fees.value , 1 ); + BOOST_CHECK_EQUAL( test_asset.dynamic_asset_data_id(db).accumulated_fees.get_amount().value , 1 ); } catch ( const fc::exception& e ) { @@ -1544,7 +1544,7 @@ BOOST_AUTO_TEST_CASE( create_buy_uia_multiple_match_new_reverse ) BOOST_CHECK_EQUAL( get_balance( seller_account, test_asset ), 198 ); BOOST_CHECK_EQUAL( get_balance( buyer_account, core_asset ), 300 ); - BOOST_CHECK_EQUAL( test_asset.dynamic_asset_data_id(db).accumulated_fees.value , 2 ); + BOOST_CHECK_EQUAL( test_asset.dynamic_asset_data_id(db).accumulated_fees.get_amount().value , 2 ); } catch ( const fc::exception& e ) { @@ -1587,7 +1587,7 @@ BOOST_AUTO_TEST_CASE( create_buy_uia_multiple_match_new_reverse_fract ) BOOST_CHECK_EQUAL( get_balance( seller_account, test_asset ), 198 ); BOOST_CHECK_EQUAL( get_balance( buyer_account, core_asset ), 30 ); BOOST_CHECK_EQUAL( get_balance( seller_account, core_asset ), 0 ); - BOOST_CHECK_EQUAL( test_asset.dynamic_asset_data_id(db).accumulated_fees.value , 2 ); + BOOST_CHECK_EQUAL( test_asset.dynamic_asset_data_id(db).accumulated_fees.get_amount().value , 2 ); } catch ( const fc::exception& e ) { @@ -1611,7 +1611,7 @@ BOOST_AUTO_TEST_CASE( uia_fees ) const share_type prec = asset::scaled_precision( asset_id_type()(db).precision ); fund_fee_pool(committee_account, test_asset, 1000*prec); - BOOST_CHECK(asset_dynamic.fee_pool == 1000*prec); + BOOST_CHECK(asset_dynamic.fee_pool.get_amount() == 1000*prec); transfer_operation op; op.fee = test_asset.amount(0); @@ -1630,16 +1630,16 @@ BOOST_AUTO_TEST_CASE( uia_fees ) BOOST_CHECK_EQUAL(get_balance(nathan_account, test_asset), (old_balance - fee - test_asset.amount(100)).amount.value); BOOST_CHECK_EQUAL(get_balance(committee_account, test_asset), 100); - BOOST_CHECK(asset_dynamic.accumulated_fees == fee.amount); - BOOST_CHECK(asset_dynamic.fee_pool == 1000*prec - core_fee.amount); + BOOST_CHECK(asset_dynamic.accumulated_fees.get_amount() == fee.amount); + BOOST_CHECK(asset_dynamic.fee_pool.get_amount() == 1000*prec - core_fee.amount); //Do it again, for good measure. PUSH_TX( db, trx, ~0 ); BOOST_CHECK_EQUAL(get_balance(nathan_account, test_asset), (old_balance - fee - fee - test_asset.amount(200)).amount.value); BOOST_CHECK_EQUAL(get_balance(committee_account, test_asset), 200); - BOOST_CHECK(asset_dynamic.accumulated_fees == fee.amount + fee.amount); - BOOST_CHECK(asset_dynamic.fee_pool == 1000*prec - core_fee.amount - core_fee.amount); + BOOST_CHECK(asset_dynamic.accumulated_fees.get_amount() == fee.amount + fee.amount); + BOOST_CHECK(asset_dynamic.fee_pool.get_amount() == 1000*prec - core_fee.amount - core_fee.amount); op = std::move(trx.operations.back().get()); trx.operations.clear(); @@ -1656,8 +1656,8 @@ BOOST_AUTO_TEST_CASE( uia_fees ) BOOST_CHECK_EQUAL(get_balance(nathan_account, test_asset), (old_balance - fee - fee - fee - test_asset.amount(200)).amount.value); BOOST_CHECK_EQUAL(get_balance(committee_account, test_asset), 200); - BOOST_CHECK(asset_dynamic.accumulated_fees == fee.amount.value * 3); - BOOST_CHECK(asset_dynamic.fee_pool == 1000*prec - core_fee.amount.value * 3); + BOOST_CHECK(asset_dynamic.accumulated_fees.get_amount() == fee.amount.value * 3); + BOOST_CHECK(asset_dynamic.fee_pool.get_amount() == 1000*prec - core_fee.amount.value * 3); } catch (fc::exception& e) { edump((e.to_detail_string())); throw; @@ -1798,7 +1798,7 @@ BOOST_AUTO_TEST_CASE( witness_pay_test ) const witness_object& wit = db.fetch_block_by_number(db.head_block_num())->witness(db); if( !wit.pay_vb.valid() ) return 0; - return (*wit.pay_vb)(db).balance.amount; + return (*wit.pay_vb)(db).balance.get_amount(); }; const auto block_interval = db.get_global_properties().parameters.block_interval; @@ -1828,7 +1828,7 @@ BOOST_AUTO_TEST_CASE( witness_pay_test ) _gpo.parameters.witness_pay_per_block = witness_ppb; } ); - BOOST_CHECK_EQUAL(core->dynamic_asset_data_id(db).accumulated_fees.value, 0); + BOOST_CHECK_EQUAL(core->dynamic_asset_data_id(db).accumulated_fees.get_amount().value, 0); BOOST_TEST_MESSAGE( "Upgrading account" ); account_upgrade_operation uop; uop.account_to_upgrade = nathan->get_id(); @@ -1871,26 +1871,26 @@ BOOST_AUTO_TEST_CASE( witness_pay_test ) BOOST_CHECK( core->reserved(db).value == 8000*prec ); generate_block(); BOOST_CHECK_EQUAL( core->reserved(db).value, 999999406 ); - BOOST_CHECK_EQUAL( db.get_dynamic_global_properties().witness_budget.value, (int64_t)ref_budget ); + BOOST_CHECK_EQUAL( db.get_dynamic_global_properties().witness_budget.get_amount().value, (int64_t)ref_budget ); // first witness paid from old budget (so no pay) BOOST_CHECK_EQUAL( last_witness_vbo_balance().value, 0 ); // second witness finally gets paid! generate_block(); BOOST_CHECK_EQUAL( last_witness_vbo_balance().value, (int64_t)witness_ppb ); - BOOST_CHECK_EQUAL( db.get_dynamic_global_properties().witness_budget.value, (int64_t)(ref_budget - witness_ppb) ); + BOOST_CHECK_EQUAL( db.get_dynamic_global_properties().witness_budget.get_amount().value, (int64_t)(ref_budget - witness_ppb) ); generate_block(); BOOST_CHECK_EQUAL( last_witness_vbo_balance().value, (int64_t)witness_ppb ); - BOOST_CHECK_EQUAL( db.get_dynamic_global_properties().witness_budget.value, (int64_t)(ref_budget - 2 * witness_ppb) ); + BOOST_CHECK_EQUAL( db.get_dynamic_global_properties().witness_budget.get_amount().value, (int64_t)(ref_budget - 2 * witness_ppb) ); generate_block(); BOOST_CHECK_LT( last_witness_vbo_balance().value, (int64_t)witness_ppb ); BOOST_CHECK_EQUAL( last_witness_vbo_balance().value, (int64_t)(ref_budget - 2 * witness_ppb) ); - BOOST_CHECK_EQUAL( db.get_dynamic_global_properties().witness_budget.value, 0 ); + BOOST_CHECK_EQUAL( db.get_dynamic_global_properties().witness_budget.get_amount().value, 0 ); generate_block(); BOOST_CHECK_EQUAL( last_witness_vbo_balance().value, 0 ); - BOOST_CHECK_EQUAL( db.get_dynamic_global_properties().witness_budget.value, 0 ); + BOOST_CHECK_EQUAL( db.get_dynamic_global_properties().witness_budget.get_amount().value, 0 ); BOOST_CHECK_EQUAL(core->reserved(db).value, 999999406 ); } FC_LOG_AND_RETHROW() } @@ -2144,7 +2144,7 @@ BOOST_AUTO_TEST_CASE( cover_with_collateral_test ) const limit_order_object* order = create_sell_order( bob_id, bitusd.amount(99), asset(4950) ); BOOST_REQUIRE( order != nullptr ); limit_order_id_type order1_id = order->id; - BOOST_CHECK_EQUAL( order->for_sale.value, 99 ); + BOOST_CHECK_EQUAL( order->for_sale.get_amount().value, 99 ); // wdump( (*call_order) ); BOOST_TEST_MESSAGE( "Alice still cannot decrease her collateral to maint level" ); @@ -2155,7 +2155,7 @@ BOOST_AUTO_TEST_CASE( cover_with_collateral_test ) order = create_sell_order( bob_id, bitusd.amount(1), asset(50) ); BOOST_REQUIRE( order != nullptr ); limit_order_id_type order2_id = order->id; - BOOST_CHECK_EQUAL( order->for_sale.value, 1 ); + BOOST_CHECK_EQUAL( order->for_sale.get_amount().value, 1 ); // wdump( (*call_order) ); BOOST_TEST_MESSAGE( "Alice decreases her collateral to maint level and Bob's orders fill" ); diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index bb7d153a53..ef8fd660bb 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -1147,7 +1147,7 @@ BOOST_AUTO_TEST_CASE( worker_create_test ) const vesting_balance_object& balance = worker.worker.get().balance(db); BOOST_CHECK(balance.owner == nathan_id); - BOOST_CHECK(balance.balance == asset(0)); + BOOST_CHECK(balance.balance.get_value() == asset(0)); BOOST_CHECK(balance.policy.get().vesting_seconds == fc::days(1).to_seconds()); } FC_LOG_AND_RETHROW() } @@ -1176,9 +1176,9 @@ BOOST_AUTO_TEST_CASE( worker_pay_test ) trx.clear(); } - BOOST_CHECK_EQUAL(worker_id_type()(db).worker.get().balance(db).balance.amount.value, 0); + BOOST_CHECK_EQUAL(worker_id_type()(db).worker.get().balance(db).balance.get_amount().value, 0); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - BOOST_CHECK_EQUAL(worker_id_type()(db).worker.get().balance(db).balance.amount.value, 1000); + BOOST_CHECK_EQUAL(worker_id_type()(db).worker.get().balance(db).balance.get_amount().value, 1000); generate_blocks(db.head_block_time() + fc::hours(12)); { @@ -1196,7 +1196,7 @@ BOOST_AUTO_TEST_CASE( worker_pay_test ) } BOOST_CHECK_EQUAL(get_balance(nathan_id, asset_id_type()), 100500); - BOOST_CHECK_EQUAL(worker_id_type()(db).worker.get().balance(db).balance.amount.value, 500); + BOOST_CHECK_EQUAL(worker_id_type()(db).worker.get().balance(db).balance.get_amount().value, 500); { account_update_operation op; @@ -1209,7 +1209,7 @@ BOOST_AUTO_TEST_CASE( worker_pay_test ) } generate_blocks(db.head_block_time() + fc::hours(12)); - BOOST_CHECK_EQUAL(worker_id_type()(db).worker.get().balance(db).balance.amount.value, 500); + BOOST_CHECK_EQUAL(worker_id_type()(db).worker.get().balance(db).balance.get_amount().value, 500); { vesting_balance_withdraw_operation op; @@ -1230,7 +1230,7 @@ BOOST_AUTO_TEST_CASE( worker_pay_test ) } BOOST_CHECK_EQUAL(get_balance(nathan_id, asset_id_type()), 101000); - BOOST_CHECK_EQUAL(worker_id_type()(db).worker.get().balance(db).balance.amount.value, 0); + BOOST_CHECK_EQUAL(worker_id_type()(db).worker.get().balance(db).balance.get_amount().value, 0); } FC_LOG_AND_RETHROW() } BOOST_AUTO_TEST_CASE( refund_worker_test ) @@ -1507,7 +1507,7 @@ BOOST_AUTO_TEST_CASE( force_settle_test ) // settle3 should be least collateralized order according to index BOOST_CHECK( db.get_index_type().indices().get().begin()->id == call3_id ); - BOOST_CHECK_EQUAL( call3_id(db).debt.value, 3000 ); + BOOST_CHECK_EQUAL( call3_id(db).debt.get_amount().value, 3000 ); BOOST_TEST_MESSAGE( "Verify partial settlement of call" ); // Partially settle a call @@ -1515,9 +1515,9 @@ BOOST_AUTO_TEST_CASE( force_settle_test ) // Call does not take effect immediately BOOST_CHECK_EQUAL( get_balance(nathan_id, bitusd_id), 14950); - BOOST_CHECK_EQUAL( settle_id(db).balance.amount.value, 50); - BOOST_CHECK_EQUAL( call3_id(db).debt.value, 3000 ); - BOOST_CHECK_EQUAL( call3_id(db).collateral.value, 5780 ); + BOOST_CHECK_EQUAL( settle_id(db).balance.get_amount().value, 50); + BOOST_CHECK_EQUAL( call3_id(db).debt.get_amount().value, 3000 ); + BOOST_CHECK_EQUAL( call3_id(db).collateral.get_amount().value, 5780 ); BOOST_CHECK( settle_id(db).owner == nathan_id ); // Wait for settlement to take effect @@ -1528,8 +1528,8 @@ BOOST_AUTO_TEST_CASE( force_settle_test ) BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).force_settled_volume.value, 50 ); BOOST_CHECK_EQUAL( get_balance(nathan_id, bitusd_id), 14950); BOOST_CHECK_EQUAL( get_balance(nathan_id, core_id), 49 ); // 1% force_settlement_offset_percent (rounded unfavorably) - BOOST_CHECK_EQUAL( call3_id(db).debt.value, 2950 ); - BOOST_CHECK_EQUAL( call3_id(db).collateral.value, 5731 ); // 5731 == 5780-49 + BOOST_CHECK_EQUAL( call3_id(db).debt.get_amount().value, 2950 ); + BOOST_CHECK_EQUAL( call3_id(db).collateral.get_amount().value, 5731 ); // 5731 == 5780-49 BOOST_CHECK( db.get_index_type().indices().get().begin()->id == call3_id ); @@ -1585,11 +1585,11 @@ BOOST_AUTO_TEST_CASE( force_settle_test ) BOOST_REQUIRE( db.find(call1_id) != nullptr ); BOOST_REQUIRE( db.find(call2_id) != nullptr ); - BOOST_CHECK_EQUAL( call1_id(db).debt.value, 1000 ); - BOOST_CHECK_EQUAL( call1_id(db).collateral.value, 2000 ); + BOOST_CHECK_EQUAL( call1_id(db).debt.get_amount().value, 1000 ); + BOOST_CHECK_EQUAL( call1_id(db).collateral.get_amount().value, 2000 ); - BOOST_CHECK_EQUAL( call2_id(db).debt.value, 2000-550 ); - BOOST_CHECK_EQUAL( call2_id(db).collateral.value, 3998-call2_payout ); + BOOST_CHECK_EQUAL( call2_id(db).debt.get_amount().value, 2000-550 ); + BOOST_CHECK_EQUAL( call2_id(db).collateral.get_amount().value, 3998-call2_payout ); } catch(fc::exception& e) { @@ -1669,8 +1669,8 @@ BOOST_AUTO_TEST_CASE( balance_object_test ) db.open(td.path(), [this]{return genesis_state;}, "TEST"); const balance_object& balance = balance_id_type()(db); - BOOST_CHECK_EQUAL(balance.balance.amount.value, 1); - BOOST_CHECK_EQUAL(balance_id_type(1)(db).balance.amount.value, 1); + BOOST_CHECK_EQUAL(balance.balance.get_amount().value, 1); + BOOST_CHECK_EQUAL(balance_id_type(1)(db).balance.get_amount().value, 1); balance_claim_operation op; op.deposit_to_account = db.get_index_type().indices().get().find("n")->get_id(); @@ -1700,10 +1700,10 @@ BOOST_AUTO_TEST_CASE( balance_object_test ) const balance_object& vesting_balance_1 = balance_id_type(2)(db); const balance_object& vesting_balance_2 = balance_id_type(3)(db); BOOST_CHECK(vesting_balance_1.is_vesting_balance()); - BOOST_CHECK_EQUAL(vesting_balance_1.balance.amount.value, 500); + BOOST_CHECK_EQUAL(vesting_balance_1.balance.get_amount().value, 500); BOOST_CHECK_EQUAL(vesting_balance_1.available(db.head_block_time()).amount.value, 0); BOOST_CHECK(vesting_balance_2.is_vesting_balance()); - BOOST_CHECK_EQUAL(vesting_balance_2.balance.amount.value, 400); + BOOST_CHECK_EQUAL(vesting_balance_2.balance.get_amount().value, 400); BOOST_CHECK_EQUAL(vesting_balance_2.available(db.head_block_time()).amount.value, 150); op.balance_to_claim = vesting_balance_1.id; @@ -1735,7 +1735,7 @@ BOOST_AUTO_TEST_CASE( balance_object_test ) _sign( trx, v2_key ); PUSH_TX(db, trx); BOOST_CHECK_EQUAL(db.get_balance(op.deposit_to_account, asset_id_type()).amount.value, 101); - BOOST_CHECK_EQUAL(vesting_balance_2.balance.amount.value, 300); + BOOST_CHECK_EQUAL(vesting_balance_2.balance.get_amount().value, 300); op.total_claimed.amount = 10; trx.operations = {op}; @@ -1776,7 +1776,7 @@ BOOST_AUTO_TEST_CASE( balance_object_test ) db.generate_block(db.get_slot_time(slot), db.get_scheduled_witness(slot), init_account_priv_key, skip_flags); set_expiration( db, trx ); - op.total_claimed = vesting_balance_2.balance; + op.total_claimed = vesting_balance_2.balance.get_value(); trx.operations = {op}; trx.clear_signatures(); _sign( trx, n_key ); @@ -2232,17 +2232,17 @@ BOOST_AUTO_TEST_CASE( buyback ) generate_block(); // no success because buyback has none for sale - BOOST_CHECK( order_id_mid(db).for_sale == 100 ); + BOOST_CHECK( order_id_mid(db).for_sale.get_amount() == 100 ); // but we can send some to buyback fund( rex_id(db), asset( 100, asset_id_type() ) ); // no action until next maint - BOOST_CHECK( order_id_mid(db).for_sale == 100 ); + BOOST_CHECK( order_id_mid(db).for_sale.get_amount() == 100 ); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); generate_block(); // partial fill, Alice now sells 90 BUYME for 900 BTS. - BOOST_CHECK( order_id_mid(db).for_sale == 90 ); + BOOST_CHECK( order_id_mid(db).for_sale.get_amount() == 90 ); // TODO check burn amount @@ -2268,8 +2268,8 @@ BOOST_AUTO_TEST_CASE( buyback ) // 70 BUYME in mid order 0 BUYME in low order idump( (order_id_mid(db)) ); - BOOST_CHECK( order_id_mid(db).for_sale == 70 ); - BOOST_CHECK( order_id_high(db).for_sale == 10 ); + BOOST_CHECK( order_id_mid(db).for_sale.get_amount() == 70 ); + BOOST_CHECK( order_id_high(db).for_sale.get_amount() == 10 ); BOOST_CHECK( get_balance( rex_id, asset_id_type() ) == 0 ); diff --git a/tests/tests/settle_tests.cpp b/tests/tests/settle_tests.cpp index 6310493ae5..e22fa6afbf 100644 --- a/tests/tests/settle_tests.cpp +++ b/tests/tests/settle_tests.cpp @@ -90,7 +90,7 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) operation_result result = force_settle(rachel, bitusd.amount(4)); force_settlement_id_type settle_id = result.get(); - BOOST_CHECK_EQUAL( settle_id(db).balance.amount.value, 4 ); + BOOST_CHECK_EQUAL( settle_id(db).balance.get_amount().value, 4 ); BOOST_CHECK_EQUAL(get_balance(rachel, core), 0); BOOST_CHECK_EQUAL(get_balance(rachel, bitusd), 196); @@ -99,10 +99,10 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) BOOST_CHECK_EQUAL(get_balance(paul, core), 9999900); BOOST_CHECK_EQUAL(get_balance(paul, bitusd), 800); - BOOST_CHECK_EQUAL( 1000, call_paul.debt.value ); - BOOST_CHECK_EQUAL( 100, call_paul.collateral.value ); - BOOST_CHECK_EQUAL( 6, call_michael.debt.value ); - BOOST_CHECK_EQUAL( 8, call_michael.collateral.value ); + BOOST_CHECK_EQUAL( 1000, call_paul.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 100, call_paul.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 6, call_michael.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 8, call_michael.collateral.get_amount().value ); generate_blocks( db.head_block_time() + fc::hours(20) ); set_expiration( db, trx ); @@ -127,12 +127,12 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) BOOST_CHECK_EQUAL(get_balance(paul_id(db), core_id(db)), 9999900); BOOST_CHECK_EQUAL(get_balance(paul_id(db), bitusd_id(db)), 800); - BOOST_CHECK_EQUAL( 996, call_paul_id(db).debt.value ); - BOOST_CHECK_EQUAL( 100, call_paul_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 6, call_michael_id(db).debt.value ); - BOOST_CHECK_EQUAL( 8, call_michael_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 996, call_paul_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 100, call_paul_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 6, call_michael_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 8, call_michael_id(db).collateral.get_amount().value ); - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 1002 ); // 1000 + 6 - 4 + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 1002 ); // 1000 + 6 - 4 // settle more and check rounding issue // by default 20% of total supply can be settled per maintenance interval, here we test less than it @@ -140,7 +140,7 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) operation_result result2 = force_settle(rachel_id(db), bitusd_id(db).amount(34)); force_settlement_id_type settle_id2 = result2.get(); - BOOST_CHECK_EQUAL( settle_id2(db).balance.amount.value, 34 ); + BOOST_CHECK_EQUAL( settle_id2(db).balance.get_amount().value, 34 ); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), core_id(db)), 0); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), bitusd_id(db)), 162); // 196-34 @@ -149,10 +149,10 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) BOOST_CHECK_EQUAL(get_balance(paul_id(db), core_id(db)), 9999900); BOOST_CHECK_EQUAL(get_balance(paul_id(db), bitusd_id(db)), 800); - BOOST_CHECK_EQUAL( 996, call_paul_id(db).debt.value ); - BOOST_CHECK_EQUAL( 100, call_paul_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 6, call_michael_id(db).debt.value ); - BOOST_CHECK_EQUAL( 8, call_michael_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 996, call_paul_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 100, call_paul_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 6, call_michael_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 8, call_michael_id(db).collateral.get_amount().value ); generate_blocks( db.head_block_time() + fc::hours(10) ); set_expiration( db, trx ); @@ -177,12 +177,12 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) BOOST_CHECK_EQUAL(get_balance(paul_id(db), core_id(db)), 9999900); BOOST_CHECK_EQUAL(get_balance(paul_id(db), bitusd_id(db)), 800); - BOOST_CHECK_EQUAL( 962, call_paul_id(db).debt.value ); // 996 - 34 - BOOST_CHECK_EQUAL( 99, call_paul_id(db).collateral.value ); // 100 - 1 - BOOST_CHECK_EQUAL( 6, call_michael_id(db).debt.value ); - BOOST_CHECK_EQUAL( 8, call_michael_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 962, call_paul_id(db).debt.get_amount().value ); // 996 - 34 + BOOST_CHECK_EQUAL( 99, call_paul_id(db).collateral.get_amount().value ); // 100 - 1 + BOOST_CHECK_EQUAL( 6, call_michael_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 8, call_michael_id(db).collateral.get_amount().value ); - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 968 ); // 1002 - 34 + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 968 ); // 1002 - 34 // prepare for more tests transfer(paul_id, rachel_id, asset(300, bitusd_id)); @@ -195,13 +195,13 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) const operation_result result5 = force_settle(rachel_id(db), bitusd_id(db).amount(5)); force_settlement_id_type settle_id3 = result3.get(); - BOOST_CHECK_EQUAL( settle_id3(db).balance.amount.value, 3 ); + BOOST_CHECK_EQUAL( settle_id3(db).balance.get_amount().value, 3 ); force_settlement_id_type settle_id4 = result4.get(); - BOOST_CHECK_EQUAL( settle_id4(db).balance.amount.value, 434 ); + BOOST_CHECK_EQUAL( settle_id4(db).balance.get_amount().value, 434 ); force_settlement_id_type settle_id5 = result5.get(); - BOOST_CHECK_EQUAL( settle_id5(db).balance.amount.value, 5 ); + BOOST_CHECK_EQUAL( settle_id5(db).balance.get_amount().value, 5 ); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), core_id(db)), 1); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), bitusd_id(db)), 20); // 162 + 300 - 3 - 434 - 5 @@ -210,12 +210,12 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) BOOST_CHECK_EQUAL(get_balance(paul_id(db), core_id(db)), 9999900); BOOST_CHECK_EQUAL(get_balance(paul_id(db), bitusd_id(db)), 500); // 800 - 300 - BOOST_CHECK_EQUAL( 962, call_paul_id(db).debt.value ); - BOOST_CHECK_EQUAL( 99, call_paul_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 8, call_michael_id(db).debt.value ); // 6 + 2 - BOOST_CHECK_EQUAL( 11, call_michael_id(db).collateral.value ); // 8 + 3 + BOOST_CHECK_EQUAL( 962, call_paul_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 99, call_paul_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 8, call_michael_id(db).debt.get_amount().value ); // 6 + 2 + BOOST_CHECK_EQUAL( 11, call_michael_id(db).collateral.get_amount().value ); // 8 + 3 - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 970 ); // 968 + 2 + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 970 ); // 968 + 2 generate_blocks( db.head_block_time() + fc::hours(4) ); set_expiration( db, trx ); @@ -242,8 +242,8 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) // settle_id3 (amount was 3) will be filled and get nothing. // settle_id4 will pay 194 - 3 = 191 usd, will get round_down(191*5/101) = 9 core BOOST_CHECK( !db.find( settle_id3 ) ); - BOOST_CHECK_EQUAL( settle_id4(db).balance.amount.value, 243 ); // 434 - 191 - BOOST_CHECK_EQUAL( settle_id5(db).balance.amount.value, 5 ); // no change, since it's after settle_id4 + BOOST_CHECK_EQUAL( settle_id4(db).balance.get_amount().value, 243 ); // 434 - 191 + BOOST_CHECK_EQUAL( settle_id5(db).balance.get_amount().value, 5 ); // no change, since it's after settle_id4 BOOST_CHECK_EQUAL(get_balance(rachel_id(db), core_id(db)), 10); // 1 + 9 BOOST_CHECK_EQUAL(get_balance(rachel_id(db), bitusd_id(db)), 20); // no change @@ -252,12 +252,12 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) BOOST_CHECK_EQUAL(get_balance(paul_id(db), core_id(db)), 9999900); BOOST_CHECK_EQUAL(get_balance(paul_id(db), bitusd_id(db)), 500); - BOOST_CHECK_EQUAL( 768, call_paul_id(db).debt.value ); // 962 - 3 - 191 - BOOST_CHECK_EQUAL( 90, call_paul_id(db).collateral.value ); // 99 - 9 - BOOST_CHECK_EQUAL( 8, call_michael_id(db).debt.value ); - BOOST_CHECK_EQUAL( 11, call_michael_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 768, call_paul_id(db).debt.get_amount().value ); // 962 - 3 - 191 + BOOST_CHECK_EQUAL( 90, call_paul_id(db).collateral.get_amount().value ); // 99 - 9 + BOOST_CHECK_EQUAL( 8, call_michael_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 11, call_michael_id(db).collateral.get_amount().value ); - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 776 ); // 970 - 3 - 191 + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 776 ); // 970 - 3 - 191 BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).force_settled_volume.value, 194 ); // 3 + 191 generate_block(); @@ -266,8 +266,8 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) set_expiration( db, trx ); borrow(michael_id(db), bitusd_id(db).amount(18), core_id(db).amount(200)); - BOOST_CHECK_EQUAL( settle_id4(db).balance.amount.value, 243 ); - BOOST_CHECK_EQUAL( settle_id5(db).balance.amount.value, 5 ); + BOOST_CHECK_EQUAL( settle_id4(db).balance.get_amount().value, 243 ); + BOOST_CHECK_EQUAL( settle_id5(db).balance.get_amount().value, 5 ); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), core_id(db)), 10); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), bitusd_id(db)), 20); @@ -276,12 +276,12 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) BOOST_CHECK_EQUAL(get_balance(paul_id(db), core_id(db)), 9999900); BOOST_CHECK_EQUAL(get_balance(paul_id(db), bitusd_id(db)), 500); - BOOST_CHECK_EQUAL( 768, call_paul_id(db).debt.value ); - BOOST_CHECK_EQUAL( 90, call_paul_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 26, call_michael_id(db).debt.value ); // 8 + 18 - BOOST_CHECK_EQUAL( 211, call_michael_id(db).collateral.value ); // 11 + 200 + BOOST_CHECK_EQUAL( 768, call_paul_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 90, call_paul_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 26, call_michael_id(db).debt.get_amount().value ); // 8 + 18 + BOOST_CHECK_EQUAL( 211, call_michael_id(db).collateral.get_amount().value ); // 11 + 200 - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 794 ); // 776 + 18 + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 794 ); // 776 + 18 BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).force_settled_volume.value, 194 ); generate_block(); @@ -289,8 +289,8 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) // maximum amount that can be settled now is round_down((794+194) * 20%) = 197, // already settled 194, so 197 - 194 = 3 more usd can be settled, // so settle_id3 will pay 3 usd and get nothing - BOOST_CHECK_EQUAL( settle_id4(db).balance.amount.value, 240 ); // 243 - 3 - BOOST_CHECK_EQUAL( settle_id5(db).balance.amount.value, 5 ); + BOOST_CHECK_EQUAL( settle_id4(db).balance.get_amount().value, 240 ); // 243 - 3 + BOOST_CHECK_EQUAL( settle_id5(db).balance.get_amount().value, 5 ); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), core_id(db)), 10); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), bitusd_id(db)), 20); @@ -299,20 +299,20 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) BOOST_CHECK_EQUAL(get_balance(paul_id(db), core_id(db)), 9999900); BOOST_CHECK_EQUAL(get_balance(paul_id(db), bitusd_id(db)), 500); - BOOST_CHECK_EQUAL( 765, call_paul_id(db).debt.value ); // 768 - 3 - BOOST_CHECK_EQUAL( 90, call_paul_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 26, call_michael_id(db).debt.value ); - BOOST_CHECK_EQUAL( 211, call_michael_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 765, call_paul_id(db).debt.get_amount().value ); // 768 - 3 + BOOST_CHECK_EQUAL( 90, call_paul_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 26, call_michael_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 211, call_michael_id(db).collateral.get_amount().value ); - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 791 ); // 794 - 3 + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 791 ); // 794 - 3 BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).force_settled_volume.value, 197 ); // 194 + 3 // michael borrows a little more set_expiration( db, trx ); borrow(michael_id(db), bitusd_id(db).amount(20), core_id(db).amount(20)); - BOOST_CHECK_EQUAL( settle_id4(db).balance.amount.value, 240 ); - BOOST_CHECK_EQUAL( settle_id5(db).balance.amount.value, 5 ); + BOOST_CHECK_EQUAL( settle_id4(db).balance.get_amount().value, 240 ); + BOOST_CHECK_EQUAL( settle_id5(db).balance.get_amount().value, 5 ); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), core_id(db)), 10); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), bitusd_id(db)), 20); @@ -321,12 +321,12 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) BOOST_CHECK_EQUAL(get_balance(paul_id(db), core_id(db)), 9999900); BOOST_CHECK_EQUAL(get_balance(paul_id(db), bitusd_id(db)), 500); - BOOST_CHECK_EQUAL( 765, call_paul_id(db).debt.value ); - BOOST_CHECK_EQUAL( 90, call_paul_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 46, call_michael_id(db).debt.value ); // 26 + 20 - BOOST_CHECK_EQUAL( 231, call_michael_id(db).collateral.value ); // 211 + 20 + BOOST_CHECK_EQUAL( 765, call_paul_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 90, call_paul_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 46, call_michael_id(db).debt.get_amount().value ); // 26 + 20 + BOOST_CHECK_EQUAL( 231, call_michael_id(db).collateral.get_amount().value ); // 211 + 20 - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 811 ); // 791 + 20 + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 811 ); // 791 + 20 BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).force_settled_volume.value, 197 ); generate_block(); @@ -335,8 +335,8 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) // already settled 197, so 201 - 197 = 4 more usd can be settled, // so settle_id4 will pay 4 usd and get nothing - BOOST_CHECK_EQUAL( settle_id4(db).balance.amount.value, 236 ); // 240 - 4 - BOOST_CHECK_EQUAL( settle_id5(db).balance.amount.value, 5 ); // no change, since it's after settle_id4 + BOOST_CHECK_EQUAL( settle_id4(db).balance.get_amount().value, 236 ); // 240 - 4 + BOOST_CHECK_EQUAL( settle_id5(db).balance.get_amount().value, 5 ); // no change, since it's after settle_id4 BOOST_CHECK_EQUAL(get_balance(rachel_id(db), core_id(db)), 10); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), bitusd_id(db)), 20); @@ -345,12 +345,12 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) BOOST_CHECK_EQUAL(get_balance(paul_id(db), core_id(db)), 9999900); BOOST_CHECK_EQUAL(get_balance(paul_id(db), bitusd_id(db)), 500); - BOOST_CHECK_EQUAL( 761, call_paul_id(db).debt.value ); // 765 - 4 - BOOST_CHECK_EQUAL( 90, call_paul_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 46, call_michael_id(db).debt.value ); - BOOST_CHECK_EQUAL( 231, call_michael_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 761, call_paul_id(db).debt.get_amount().value ); // 765 - 4 + BOOST_CHECK_EQUAL( 90, call_paul_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 46, call_michael_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 231, call_michael_id(db).collateral.get_amount().value ); - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 807 ); // 811 - 4 + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 807 ); // 811 - 4 BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).force_settled_volume.value, 201 ); // 197 + 4 generate_block(); @@ -358,8 +358,8 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) // jim borrow some cny call_order_id_type call_jim_id = borrow(jim_id(db), bitcny_id(db).amount(2000), core_id(db).amount(2000))->id; - BOOST_CHECK_EQUAL( 2000, call_jim_id(db).debt.value ); - BOOST_CHECK_EQUAL( 2000, call_jim_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 2000, call_jim_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 2000, call_jim_id(db).collateral.get_amount().value ); BOOST_CHECK_EQUAL(get_balance(jim_id(db), core_id(db)), 9998000); BOOST_CHECK_EQUAL(get_balance(jim_id(db), bitcny_id(db)), 2000); @@ -387,13 +387,13 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) const operation_result result8 = force_settle(ted_id(db), bitusd_id(db).amount(22)); force_settlement_id_type settle_id6 = result6.get(); - BOOST_CHECK_EQUAL( settle_id6(db).balance.amount.value, 20 ); + BOOST_CHECK_EQUAL( settle_id6(db).balance.get_amount().value, 20 ); force_settlement_id_type settle_id7 = result7.get(); - BOOST_CHECK_EQUAL( settle_id7(db).balance.amount.value, 21 ); + BOOST_CHECK_EQUAL( settle_id7(db).balance.get_amount().value, 21 ); force_settlement_id_type settle_id8 = result8.get(); - BOOST_CHECK_EQUAL( settle_id8(db).balance.amount.value, 22 ); + BOOST_CHECK_EQUAL( settle_id8(db).balance.get_amount().value, 22 ); BOOST_CHECK_EQUAL(get_balance(ted_id(db), core_id(db)), 0); BOOST_CHECK_EQUAL(get_balance(ted_id(db), bitusd_id(db)), 37); // 100 - 20 - 21 - 22 @@ -404,13 +404,13 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) const operation_result result103 = force_settle(joe_id(db), bitcny_id(db).amount(300)); force_settlement_id_type settle_id101 = result101.get(); - BOOST_CHECK_EQUAL( settle_id101(db).balance.amount.value, 100 ); + BOOST_CHECK_EQUAL( settle_id101(db).balance.get_amount().value, 100 ); force_settlement_id_type settle_id102 = result102.get(); - BOOST_CHECK_EQUAL( settle_id102(db).balance.amount.value, 1000 ); + BOOST_CHECK_EQUAL( settle_id102(db).balance.get_amount().value, 1000 ); force_settlement_id_type settle_id103 = result103.get(); - BOOST_CHECK_EQUAL( settle_id103(db).balance.amount.value, 300 ); + BOOST_CHECK_EQUAL( settle_id103(db).balance.get_amount().value, 300 ); BOOST_CHECK_EQUAL(get_balance(joe_id(db), core_id(db)), 0); BOOST_CHECK_EQUAL(get_balance(joe_id(db), bitcny_id(db)), 100); // 1500 - 100 - 1000 - 300 @@ -436,11 +436,11 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) // maximum amount that can be settled now is round_down(807 * 20%) = 161, // settle_id4 will pay 161 usd, will get round_down(161*5/101) = 7 core - BOOST_CHECK_EQUAL( settle_id4(db).balance.amount.value, 75 ); // 236 - 161 - BOOST_CHECK_EQUAL( settle_id5(db).balance.amount.value, 5 ); // no change, since it's after settle_id4 - BOOST_CHECK_EQUAL( settle_id6(db).balance.amount.value, 20 ); // no change since not expired - BOOST_CHECK_EQUAL( settle_id7(db).balance.amount.value, 21 ); // no change since not expired - BOOST_CHECK_EQUAL( settle_id8(db).balance.amount.value, 22 ); // no change since not expired + BOOST_CHECK_EQUAL( settle_id4(db).balance.get_amount().value, 75 ); // 236 - 161 + BOOST_CHECK_EQUAL( settle_id5(db).balance.get_amount().value, 5 ); // no change, since it's after settle_id4 + BOOST_CHECK_EQUAL( settle_id6(db).balance.get_amount().value, 20 ); // no change since not expired + BOOST_CHECK_EQUAL( settle_id7(db).balance.get_amount().value, 21 ); // no change since not expired + BOOST_CHECK_EQUAL( settle_id8(db).balance.get_amount().value, 22 ); // no change since not expired BOOST_CHECK_EQUAL(get_balance(rachel_id(db), core_id(db)), 17); // 10 + 7 BOOST_CHECK_EQUAL(get_balance(rachel_id(db), bitusd_id(db)), 20); // no change @@ -451,28 +451,28 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) BOOST_CHECK_EQUAL(get_balance(ted_id(db), core_id(db)), 0); BOOST_CHECK_EQUAL(get_balance(ted_id(db), bitusd_id(db)), 37); - BOOST_CHECK_EQUAL( 600, call_paul_id(db).debt.value ); // 761 - 161 - BOOST_CHECK_EQUAL( 83, call_paul_id(db).collateral.value ); // 90 - 7 - BOOST_CHECK_EQUAL( 46, call_michael_id(db).debt.value ); - BOOST_CHECK_EQUAL( 231, call_michael_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 600, call_paul_id(db).debt.get_amount().value ); // 761 - 161 + BOOST_CHECK_EQUAL( 83, call_paul_id(db).collateral.get_amount().value ); // 90 - 7 + BOOST_CHECK_EQUAL( 46, call_michael_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 231, call_michael_id(db).collateral.get_amount().value ); - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 646 ); // 807 - 161 + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 646 ); // 807 - 161 BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).force_settled_volume.value, 161 ); // reset to 0, then 161 more // current cny data - BOOST_CHECK_EQUAL( settle_id101(db).balance.amount.value, 100 ); // no change since not expired - BOOST_CHECK_EQUAL( settle_id102(db).balance.amount.value, 1000 ); // no change since not expired - BOOST_CHECK_EQUAL( settle_id103(db).balance.amount.value, 300 ); // no change since not expired + BOOST_CHECK_EQUAL( settle_id101(db).balance.get_amount().value, 100 ); // no change since not expired + BOOST_CHECK_EQUAL( settle_id102(db).balance.get_amount().value, 1000 ); // no change since not expired + BOOST_CHECK_EQUAL( settle_id103(db).balance.get_amount().value, 300 ); // no change since not expired BOOST_CHECK_EQUAL(get_balance(jim_id(db), core_id(db)), 9998000); BOOST_CHECK_EQUAL(get_balance(jim_id(db), bitcny_id(db)), 500); BOOST_CHECK_EQUAL(get_balance(joe_id(db), core_id(db)), 0); BOOST_CHECK_EQUAL(get_balance(joe_id(db), bitcny_id(db)), 100); // 1500 - 100 - 1000 - 300 - BOOST_CHECK_EQUAL( 2000, call_jim_id(db).debt.value ); - BOOST_CHECK_EQUAL( 2000, call_jim_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 2000, call_jim_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 2000, call_jim_id(db).collateral.get_amount().value ); - BOOST_CHECK_EQUAL( bitcny_id(db).dynamic_data(db).current_supply.value, 2000 ); + BOOST_CHECK_EQUAL( bitcny_id(db).dynamic_data(db).current_supply.get_amount().value, 2000 ); BOOST_CHECK_EQUAL( bitcny_id(db).bitasset_data(db).force_settled_volume.value, 0 ); // bob borrow some @@ -482,10 +482,10 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) BOOST_CHECK_EQUAL(get_balance(bob_id(db), core_id(db)), 9999998); // 10000000 - 2 BOOST_CHECK_EQUAL(get_balance(bob_id(db), bitusd_id(db)), 19); // new - BOOST_CHECK_EQUAL( 19, call_bob_id(db).debt.value ); - BOOST_CHECK_EQUAL( 2, call_bob_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 19, call_bob_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 2, call_bob_id(db).collateral.get_amount().value ); - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 665 ); // 646 + 19 + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 665 ); // 646 + 19 BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).force_settled_volume.value, 161 ); generate_block(); @@ -493,11 +493,11 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) // maximum amount that can be settled now is round_down((665+161) * 20%) = 165, // settle_id4 will pay 165-161=4 usd, will get nothing // bob's call order will get partially settled since its collateral ratio is the lowest - BOOST_CHECK_EQUAL( settle_id4(db).balance.amount.value, 71 ); // 75 - 4 - BOOST_CHECK_EQUAL( settle_id5(db).balance.amount.value, 5 ); // no change, since it's after settle_id4 - BOOST_CHECK_EQUAL( settle_id6(db).balance.amount.value, 20 ); // no change since not expired - BOOST_CHECK_EQUAL( settle_id7(db).balance.amount.value, 21 ); // no change since not expired - BOOST_CHECK_EQUAL( settle_id8(db).balance.amount.value, 22 ); // no change since not expired + BOOST_CHECK_EQUAL( settle_id4(db).balance.get_amount().value, 71 ); // 75 - 4 + BOOST_CHECK_EQUAL( settle_id5(db).balance.get_amount().value, 5 ); // no change, since it's after settle_id4 + BOOST_CHECK_EQUAL( settle_id6(db).balance.get_amount().value, 20 ); // no change since not expired + BOOST_CHECK_EQUAL( settle_id7(db).balance.get_amount().value, 21 ); // no change since not expired + BOOST_CHECK_EQUAL( settle_id8(db).balance.get_amount().value, 22 ); // no change since not expired BOOST_CHECK_EQUAL(get_balance(bob_id(db), core_id(db)), 9999998); BOOST_CHECK_EQUAL(get_balance(bob_id(db), bitusd_id(db)), 19); @@ -510,14 +510,14 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) BOOST_CHECK_EQUAL(get_balance(ted_id(db), core_id(db)), 0); BOOST_CHECK_EQUAL(get_balance(ted_id(db), bitusd_id(db)), 37); - BOOST_CHECK_EQUAL( 15, call_bob_id(db).debt.value ); // 19 - 4 - BOOST_CHECK_EQUAL( 2, call_bob_id(db).collateral.value ); // no change - BOOST_CHECK_EQUAL( 600, call_paul_id(db).debt.value ); - BOOST_CHECK_EQUAL( 83, call_paul_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 46, call_michael_id(db).debt.value ); - BOOST_CHECK_EQUAL( 231, call_michael_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 15, call_bob_id(db).debt.get_amount().value ); // 19 - 4 + BOOST_CHECK_EQUAL( 2, call_bob_id(db).collateral.get_amount().value ); // no change + BOOST_CHECK_EQUAL( 600, call_paul_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 83, call_paul_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 46, call_michael_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 231, call_michael_id(db).collateral.get_amount().value ); - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 661 ); // 665 - 4 + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 661 ); // 665 - 4 BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).force_settled_volume.value, 165 ); // 161 + 4 // adding new feed so we have valid price to exit @@ -545,18 +545,18 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) // according to price 50 core / 101 cny, it will get 148 core and pay 300 cny; // settle_id103 won't be processed since it's after settle_id102 BOOST_CHECK( !db.find( settle_id101 ) ); - BOOST_CHECK_EQUAL( settle_id102(db).balance.amount.value, 700 ); // 1000 - 300 - BOOST_CHECK_EQUAL( settle_id103(db).balance.amount.value, 300 ); // no change since it's after settle_id102 + BOOST_CHECK_EQUAL( settle_id102(db).balance.get_amount().value, 700 ); // 1000 - 300 + BOOST_CHECK_EQUAL( settle_id103(db).balance.get_amount().value, 300 ); // no change since it's after settle_id102 BOOST_CHECK_EQUAL(get_balance(jim_id(db), core_id(db)), 9998000); BOOST_CHECK_EQUAL(get_balance(jim_id(db), bitcny_id(db)), 500); BOOST_CHECK_EQUAL(get_balance(joe_id(db), core_id(db)), 197); // 49 + 148 BOOST_CHECK_EQUAL(get_balance(joe_id(db), bitcny_id(db)), 100); - BOOST_CHECK_EQUAL( 1600, call_jim_id(db).debt.value ); // 2000 - 100 - 300 - BOOST_CHECK_EQUAL( 1803, call_jim_id(db).collateral.value ); // 2000 - 49 - 148 + BOOST_CHECK_EQUAL( 1600, call_jim_id(db).debt.get_amount().value ); // 2000 - 100 - 300 + BOOST_CHECK_EQUAL( 1803, call_jim_id(db).collateral.get_amount().value ); // 2000 - 49 - 148 - BOOST_CHECK_EQUAL( bitcny_id(db).dynamic_data(db).current_supply.value, 1600 ); + BOOST_CHECK_EQUAL( bitcny_id(db).dynamic_data(db).current_supply.get_amount().value, 1600 ); BOOST_CHECK_EQUAL( bitcny_id(db).bitasset_data(db).force_settled_volume.value, 400 ); // 100 + 300 // adding new feed so we have valid price to exit @@ -589,7 +589,7 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) BOOST_CHECK( !db.find( settle_id5 ) ); BOOST_CHECK( !db.find( settle_id6 ) ); BOOST_CHECK( !db.find( settle_id7 ) ); - BOOST_CHECK_EQUAL( settle_id8(db).balance.amount.value, 7 ); // 22 - 15 + BOOST_CHECK_EQUAL( settle_id8(db).balance.get_amount().value, 7 ); // 22 - 15 BOOST_CHECK_EQUAL(get_balance(bob_id(db), core_id(db)), 10000000); // 9999998 + 2 BOOST_CHECK_EQUAL(get_balance(bob_id(db), bitusd_id(db)), 19); @@ -603,12 +603,12 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) BOOST_CHECK_EQUAL(get_balance(ted_id(db), bitusd_id(db)), 37); BOOST_CHECK( !db.find( call_bob_id ) ); - BOOST_CHECK_EQUAL( 483, call_paul_id(db).debt.value ); // 600 - 56 - 5 - 20 - 21 - 15 - BOOST_CHECK_EQUAL( 80, call_paul_id(db).collateral.value ); // 83 - 2 - 1 - BOOST_CHECK_EQUAL( 46, call_michael_id(db).debt.value ); - BOOST_CHECK_EQUAL( 231, call_michael_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 483, call_paul_id(db).debt.get_amount().value ); // 600 - 56 - 5 - 20 - 21 - 15 + BOOST_CHECK_EQUAL( 80, call_paul_id(db).collateral.get_amount().value ); // 83 - 2 - 1 + BOOST_CHECK_EQUAL( 46, call_michael_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 231, call_michael_id(db).collateral.get_amount().value ); - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 529 ); // 661 - 132 + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 529 ); // 661 - 132 BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).force_settled_volume.value, 132 ); // reset to 0, then 132 more // check cny @@ -617,18 +617,18 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test ) // according to price 50 core / 101 cny, it will get 158 core and pay 320 cny; // settle_id103 won't be processed since it's after settle_id102 BOOST_CHECK( !db.find( settle_id101 ) ); - BOOST_CHECK_EQUAL( settle_id102(db).balance.amount.value, 380 ); // 700 - 320 - BOOST_CHECK_EQUAL( settle_id103(db).balance.amount.value, 300 ); // no change since it's after settle_id102 + BOOST_CHECK_EQUAL( settle_id102(db).balance.get_amount().value, 380 ); // 700 - 320 + BOOST_CHECK_EQUAL( settle_id103(db).balance.get_amount().value, 300 ); // no change since it's after settle_id102 BOOST_CHECK_EQUAL(get_balance(jim_id(db), core_id(db)), 9998000); BOOST_CHECK_EQUAL(get_balance(jim_id(db), bitcny_id(db)), 500); BOOST_CHECK_EQUAL(get_balance(joe_id(db), core_id(db)), 355); // 197 + 158 BOOST_CHECK_EQUAL(get_balance(joe_id(db), bitcny_id(db)), 100); - BOOST_CHECK_EQUAL( 1280, call_jim_id(db).debt.value ); // 1600 - 320 - BOOST_CHECK_EQUAL( 1645, call_jim_id(db).collateral.value ); // 1803 - 158 + BOOST_CHECK_EQUAL( 1280, call_jim_id(db).debt.get_amount().value ); // 1600 - 320 + BOOST_CHECK_EQUAL( 1645, call_jim_id(db).collateral.get_amount().value ); // 1803 - 158 - BOOST_CHECK_EQUAL( bitcny_id(db).dynamic_data(db).current_supply.value, 1280 ); + BOOST_CHECK_EQUAL( bitcny_id(db).dynamic_data(db).current_supply.get_amount().value, 1280 ); BOOST_CHECK_EQUAL( bitcny_id(db).bitasset_data(db).force_settled_volume.value, 320 ); // reset to 0, then 320 generate_block(); @@ -694,7 +694,7 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) const operation_result result = force_settle(rachel, bitusd.amount(4)); force_settlement_id_type settle_id = result.get(); - BOOST_CHECK_EQUAL( settle_id(db).balance.amount.value, 4 ); + BOOST_CHECK_EQUAL( settle_id(db).balance.get_amount().value, 4 ); BOOST_CHECK_EQUAL(get_balance(rachel, core), 0); BOOST_CHECK_EQUAL(get_balance(rachel, bitusd), 196); @@ -703,10 +703,10 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) BOOST_CHECK_EQUAL(get_balance(paul, core), 9999900); BOOST_CHECK_EQUAL(get_balance(paul, bitusd), 800); - BOOST_CHECK_EQUAL( 1000, call_paul.debt.value ); - BOOST_CHECK_EQUAL( 100, call_paul.collateral.value ); - BOOST_CHECK_EQUAL( 6, call_michael.debt.value ); - BOOST_CHECK_EQUAL( 8, call_michael.collateral.value ); + BOOST_CHECK_EQUAL( 1000, call_paul.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 100, call_paul.collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 6, call_michael.debt.get_amount().value ); + BOOST_CHECK_EQUAL( 8, call_michael.collateral.get_amount().value ); generate_blocks( db.head_block_time() + fc::hours(20) ); set_expiration( db, trx ); @@ -731,12 +731,12 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) BOOST_CHECK_EQUAL(get_balance(paul_id(db), core_id(db)), 9999900); BOOST_CHECK_EQUAL(get_balance(paul_id(db), bitusd_id(db)), 800); - BOOST_CHECK_EQUAL( 1000, call_paul_id(db).debt.value ); - BOOST_CHECK_EQUAL( 100, call_paul_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 6, call_michael_id(db).debt.value ); - BOOST_CHECK_EQUAL( 8, call_michael_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 1000, call_paul_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 100, call_paul_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 6, call_michael_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 8, call_michael_id(db).collateral.get_amount().value ); - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 1006 ); // 1000 + 6 + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 1006 ); // 1000 + 6 // settle more and check rounding issue // by default 20% of total supply can be settled per maintenance interval, here we test less than it @@ -744,7 +744,7 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) const operation_result result2 = force_settle(rachel_id(db), bitusd_id(db).amount(34)); force_settlement_id_type settle_id2 = result2.get(); - BOOST_CHECK_EQUAL( settle_id2(db).balance.amount.value, 34 ); + BOOST_CHECK_EQUAL( settle_id2(db).balance.get_amount().value, 34 ); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), core_id(db)), 0); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), bitusd_id(db)), 166); // 200-34 @@ -753,10 +753,10 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) BOOST_CHECK_EQUAL(get_balance(paul_id(db), core_id(db)), 9999900); BOOST_CHECK_EQUAL(get_balance(paul_id(db), bitusd_id(db)), 800); - BOOST_CHECK_EQUAL( 1000, call_paul_id(db).debt.value ); - BOOST_CHECK_EQUAL( 100, call_paul_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 6, call_michael_id(db).debt.value ); - BOOST_CHECK_EQUAL( 8, call_michael_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 1000, call_paul_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 100, call_paul_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 6, call_michael_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 8, call_michael_id(db).collateral.get_amount().value ); generate_blocks( db.head_block_time() + fc::hours(10) ); set_expiration( db, trx ); @@ -781,12 +781,12 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) BOOST_CHECK_EQUAL(get_balance(paul_id(db), core_id(db)), 9999900); BOOST_CHECK_EQUAL(get_balance(paul_id(db), bitusd_id(db)), 800); - BOOST_CHECK_EQUAL( 979, call_paul_id(db).debt.value ); // 1000 - 21 - BOOST_CHECK_EQUAL( 99, call_paul_id(db).collateral.value ); // 100 - 1 - BOOST_CHECK_EQUAL( 6, call_michael_id(db).debt.value ); - BOOST_CHECK_EQUAL( 8, call_michael_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 979, call_paul_id(db).debt.get_amount().value ); // 1000 - 21 + BOOST_CHECK_EQUAL( 99, call_paul_id(db).collateral.get_amount().value ); // 100 - 1 + BOOST_CHECK_EQUAL( 6, call_michael_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 8, call_michael_id(db).collateral.get_amount().value ); - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 985 ); // 1006 - 21 + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 985 ); // 1006 - 21 // prepare for more tests transfer(paul_id, rachel_id, asset(300, bitusd_id)); @@ -799,13 +799,13 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) const operation_result result5 = force_settle(rachel_id(db), bitusd_id(db).amount(5)); force_settlement_id_type settle_id3 = result3.get(); - BOOST_CHECK_EQUAL( settle_id3(db).balance.amount.value, 3 ); + BOOST_CHECK_EQUAL( settle_id3(db).balance.get_amount().value, 3 ); force_settlement_id_type settle_id4 = result4.get(); - BOOST_CHECK_EQUAL( settle_id4(db).balance.amount.value, 434 ); + BOOST_CHECK_EQUAL( settle_id4(db).balance.get_amount().value, 434 ); force_settlement_id_type settle_id5 = result5.get(); - BOOST_CHECK_EQUAL( settle_id5(db).balance.amount.value, 5 ); + BOOST_CHECK_EQUAL( settle_id5(db).balance.get_amount().value, 5 ); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), core_id(db)), 1); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), bitusd_id(db)), 37); // 179 + 300 - 3 - 434 - 5 @@ -814,12 +814,12 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) BOOST_CHECK_EQUAL(get_balance(paul_id(db), core_id(db)), 9999900); BOOST_CHECK_EQUAL(get_balance(paul_id(db), bitusd_id(db)), 500); // 800 - 300 - BOOST_CHECK_EQUAL( 979, call_paul_id(db).debt.value ); - BOOST_CHECK_EQUAL( 99, call_paul_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 8, call_michael_id(db).debt.value ); // 6 + 2 - BOOST_CHECK_EQUAL( 11, call_michael_id(db).collateral.value ); // 8 + 3 + BOOST_CHECK_EQUAL( 979, call_paul_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 99, call_paul_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 8, call_michael_id(db).debt.get_amount().value ); // 6 + 2 + BOOST_CHECK_EQUAL( 11, call_michael_id(db).collateral.get_amount().value ); // 8 + 3 - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 987 ); // 985 + 2 + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 987 ); // 985 + 2 generate_blocks( db.head_block_time() + fc::hours(4) ); set_expiration( db, trx ); @@ -847,8 +847,8 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) // according to price (101/5), the amount worths more than 9 core but less than 10 core, so 9 core will be settled, // and 9 core worths 181.5 usd, so rachel will pay 182 usd and get 9 core BOOST_CHECK( !db.find( settle_id3 ) ); - BOOST_CHECK_EQUAL( settle_id4(db).balance.amount.value, 252 ); // 434 - 182 - BOOST_CHECK_EQUAL( settle_id5(db).balance.amount.value, 5 ); // no change, since it's after settle_id4 + BOOST_CHECK_EQUAL( settle_id4(db).balance.get_amount().value, 252 ); // 434 - 182 + BOOST_CHECK_EQUAL( settle_id5(db).balance.get_amount().value, 5 ); // no change, since it's after settle_id4 BOOST_CHECK_EQUAL(get_balance(rachel_id(db), core_id(db)), 10); // 1 + 9 BOOST_CHECK_EQUAL(get_balance(rachel_id(db), bitusd_id(db)), 40); // 37 + 3 @@ -857,12 +857,12 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) BOOST_CHECK_EQUAL(get_balance(paul_id(db), core_id(db)), 9999900); BOOST_CHECK_EQUAL(get_balance(paul_id(db), bitusd_id(db)), 500); - BOOST_CHECK_EQUAL( 797, call_paul_id(db).debt.value ); // 979 - 182 - BOOST_CHECK_EQUAL( 90, call_paul_id(db).collateral.value ); // 99 - 9 - BOOST_CHECK_EQUAL( 8, call_michael_id(db).debt.value ); - BOOST_CHECK_EQUAL( 11, call_michael_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 797, call_paul_id(db).debt.get_amount().value ); // 979 - 182 + BOOST_CHECK_EQUAL( 90, call_paul_id(db).collateral.get_amount().value ); // 99 - 9 + BOOST_CHECK_EQUAL( 8, call_michael_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 11, call_michael_id(db).collateral.get_amount().value ); - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 805 ); // 987 - 182 + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 805 ); // 987 - 182 BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).force_settled_volume.value, 182 ); generate_block(); @@ -871,8 +871,8 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) set_expiration( db, trx ); borrow(michael_id(db), bitusd_id(db).amount(18), core_id(db).amount(200)); - BOOST_CHECK_EQUAL( settle_id4(db).balance.amount.value, 252 ); - BOOST_CHECK_EQUAL( settle_id5(db).balance.amount.value, 5 ); + BOOST_CHECK_EQUAL( settle_id4(db).balance.get_amount().value, 252 ); + BOOST_CHECK_EQUAL( settle_id5(db).balance.get_amount().value, 5 ); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), core_id(db)), 10); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), bitusd_id(db)), 40); @@ -881,12 +881,12 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) BOOST_CHECK_EQUAL(get_balance(paul_id(db), core_id(db)), 9999900); BOOST_CHECK_EQUAL(get_balance(paul_id(db), bitusd_id(db)), 500); - BOOST_CHECK_EQUAL( 797, call_paul_id(db).debt.value ); - BOOST_CHECK_EQUAL( 90, call_paul_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 26, call_michael_id(db).debt.value ); // 8 + 18 - BOOST_CHECK_EQUAL( 211, call_michael_id(db).collateral.value ); // 11 + 200 + BOOST_CHECK_EQUAL( 797, call_paul_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 90, call_paul_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 26, call_michael_id(db).debt.get_amount().value ); // 8 + 18 + BOOST_CHECK_EQUAL( 211, call_michael_id(db).collateral.get_amount().value ); // 11 + 200 - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 823 ); // 805 + 18 + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 823 ); // 805 + 18 BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).force_settled_volume.value, 182 ); generate_block(); @@ -895,8 +895,8 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) // already settled 182, so 201 - 182 = 19 more usd can be settled, // according to price (101/5), the amount worths less than 1 core, // so nothing will happen. - BOOST_CHECK_EQUAL( settle_id4(db).balance.amount.value, 252 ); - BOOST_CHECK_EQUAL( settle_id5(db).balance.amount.value, 5 ); + BOOST_CHECK_EQUAL( settle_id4(db).balance.get_amount().value, 252 ); + BOOST_CHECK_EQUAL( settle_id5(db).balance.get_amount().value, 5 ); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), core_id(db)), 10); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), bitusd_id(db)), 40); @@ -905,20 +905,20 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) BOOST_CHECK_EQUAL(get_balance(paul_id(db), core_id(db)), 9999900); BOOST_CHECK_EQUAL(get_balance(paul_id(db), bitusd_id(db)), 500); - BOOST_CHECK_EQUAL( 797, call_paul_id(db).debt.value ); - BOOST_CHECK_EQUAL( 90, call_paul_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 26, call_michael_id(db).debt.value ); - BOOST_CHECK_EQUAL( 211, call_michael_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 797, call_paul_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 90, call_paul_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 26, call_michael_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 211, call_michael_id(db).collateral.get_amount().value ); - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 823 ); + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 823 ); BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).force_settled_volume.value, 182 ); // michael borrows a little more set_expiration( db, trx ); borrow(michael_id(db), bitusd_id(db).amount(20), core_id(db).amount(20)); - BOOST_CHECK_EQUAL( settle_id4(db).balance.amount.value, 252 ); - BOOST_CHECK_EQUAL( settle_id5(db).balance.amount.value, 5 ); + BOOST_CHECK_EQUAL( settle_id4(db).balance.get_amount().value, 252 ); + BOOST_CHECK_EQUAL( settle_id5(db).balance.get_amount().value, 5 ); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), core_id(db)), 10); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), bitusd_id(db)), 40); @@ -927,12 +927,12 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) BOOST_CHECK_EQUAL(get_balance(paul_id(db), core_id(db)), 9999900); BOOST_CHECK_EQUAL(get_balance(paul_id(db), bitusd_id(db)), 500); - BOOST_CHECK_EQUAL( 797, call_paul_id(db).debt.value ); - BOOST_CHECK_EQUAL( 90, call_paul_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 46, call_michael_id(db).debt.value ); // 26 + 20 - BOOST_CHECK_EQUAL( 231, call_michael_id(db).collateral.value ); // 211 + 20 + BOOST_CHECK_EQUAL( 797, call_paul_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 90, call_paul_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 46, call_michael_id(db).debt.get_amount().value ); // 26 + 20 + BOOST_CHECK_EQUAL( 231, call_michael_id(db).collateral.get_amount().value ); // 211 + 20 - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 843 ); // 823 + 20 + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 843 ); // 823 + 20 BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).force_settled_volume.value, 182 ); generate_block(); @@ -943,8 +943,8 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) // so settle order will fill 1 more core, since 1 core worth more than 20 usd but less than 21 usd, // so rachel will pay 21 usd and get 1 core - BOOST_CHECK_EQUAL( settle_id4(db).balance.amount.value, 231 ); // 252 - 21 - BOOST_CHECK_EQUAL( settle_id5(db).balance.amount.value, 5 ); // no change, since it's after settle_id4 + BOOST_CHECK_EQUAL( settle_id4(db).balance.get_amount().value, 231 ); // 252 - 21 + BOOST_CHECK_EQUAL( settle_id5(db).balance.get_amount().value, 5 ); // no change, since it's after settle_id4 BOOST_CHECK_EQUAL(get_balance(rachel_id(db), core_id(db)), 11); // 10 + 1 BOOST_CHECK_EQUAL(get_balance(rachel_id(db), bitusd_id(db)), 40); // no change @@ -953,19 +953,19 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) BOOST_CHECK_EQUAL(get_balance(paul_id(db), core_id(db)), 9999900); BOOST_CHECK_EQUAL(get_balance(paul_id(db), bitusd_id(db)), 500); - BOOST_CHECK_EQUAL( 776, call_paul_id(db).debt.value ); // 797 - 21 - BOOST_CHECK_EQUAL( 89, call_paul_id(db).collateral.value ); // 90 - 1 - BOOST_CHECK_EQUAL( 46, call_michael_id(db).debt.value ); - BOOST_CHECK_EQUAL( 231, call_michael_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 776, call_paul_id(db).debt.get_amount().value ); // 797 - 21 + BOOST_CHECK_EQUAL( 89, call_paul_id(db).collateral.get_amount().value ); // 90 - 1 + BOOST_CHECK_EQUAL( 46, call_michael_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 231, call_michael_id(db).collateral.get_amount().value ); - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 822 ); // 843 - 21 + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 822 ); // 843 - 21 BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).force_settled_volume.value, 203 ); // 182 + 21 // jim borrow some cny call_order_id_type call_jim_id = borrow(jim_id(db), bitcny_id(db).amount(2000), core_id(db).amount(2000))->id; - BOOST_CHECK_EQUAL( 2000, call_jim_id(db).debt.value ); - BOOST_CHECK_EQUAL( 2000, call_jim_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 2000, call_jim_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 2000, call_jim_id(db).collateral.get_amount().value ); BOOST_CHECK_EQUAL(get_balance(jim_id(db), core_id(db)), 9998000); BOOST_CHECK_EQUAL(get_balance(jim_id(db), bitcny_id(db)), 2000); @@ -993,13 +993,13 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) const operation_result result8 = force_settle(ted_id(db), bitusd_id(db).amount(22)); force_settlement_id_type settle_id6 = result6.get(); - BOOST_CHECK_EQUAL( settle_id6(db).balance.amount.value, 20 ); + BOOST_CHECK_EQUAL( settle_id6(db).balance.get_amount().value, 20 ); force_settlement_id_type settle_id7 = result7.get(); - BOOST_CHECK_EQUAL( settle_id7(db).balance.amount.value, 21 ); + BOOST_CHECK_EQUAL( settle_id7(db).balance.get_amount().value, 21 ); force_settlement_id_type settle_id8 = result8.get(); - BOOST_CHECK_EQUAL( settle_id8(db).balance.amount.value, 22 ); + BOOST_CHECK_EQUAL( settle_id8(db).balance.get_amount().value, 22 ); BOOST_CHECK_EQUAL(get_balance(ted_id(db), core_id(db)), 0); BOOST_CHECK_EQUAL(get_balance(ted_id(db), bitusd_id(db)), 37); // 100 - 20 - 21 - 22 @@ -1010,13 +1010,13 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) const operation_result result103 = force_settle(joe_id(db), bitcny_id(db).amount(300)); force_settlement_id_type settle_id101 = result101.get(); - BOOST_CHECK_EQUAL( settle_id101(db).balance.amount.value, 100 ); + BOOST_CHECK_EQUAL( settle_id101(db).balance.get_amount().value, 100 ); force_settlement_id_type settle_id102 = result102.get(); - BOOST_CHECK_EQUAL( settle_id102(db).balance.amount.value, 1000 ); + BOOST_CHECK_EQUAL( settle_id102(db).balance.get_amount().value, 1000 ); force_settlement_id_type settle_id103 = result103.get(); - BOOST_CHECK_EQUAL( settle_id103(db).balance.amount.value, 300 ); + BOOST_CHECK_EQUAL( settle_id103(db).balance.get_amount().value, 300 ); BOOST_CHECK_EQUAL(get_balance(joe_id(db), core_id(db)), 0); BOOST_CHECK_EQUAL(get_balance(joe_id(db), bitcny_id(db)), 100); // 1500 - 100 - 1000 - 300 @@ -1044,11 +1044,11 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) // according to price (101/5), the amount worths more than 8 core but less than 9 core, // so settle order will fill 8 more core, since 8 core worth more than 161 usd but less than 162 usd, // so rachel will pay 162 usd and get 8 core - BOOST_CHECK_EQUAL( settle_id4(db).balance.amount.value, 69 ); // 231 - 162 - BOOST_CHECK_EQUAL( settle_id5(db).balance.amount.value, 5 ); // no change, since it's after settle_id4 - BOOST_CHECK_EQUAL( settle_id6(db).balance.amount.value, 20 ); // no change since not expired - BOOST_CHECK_EQUAL( settle_id7(db).balance.amount.value, 21 ); // no change since not expired - BOOST_CHECK_EQUAL( settle_id8(db).balance.amount.value, 22 ); // no change since not expired + BOOST_CHECK_EQUAL( settle_id4(db).balance.get_amount().value, 69 ); // 231 - 162 + BOOST_CHECK_EQUAL( settle_id5(db).balance.get_amount().value, 5 ); // no change, since it's after settle_id4 + BOOST_CHECK_EQUAL( settle_id6(db).balance.get_amount().value, 20 ); // no change since not expired + BOOST_CHECK_EQUAL( settle_id7(db).balance.get_amount().value, 21 ); // no change since not expired + BOOST_CHECK_EQUAL( settle_id8(db).balance.get_amount().value, 22 ); // no change since not expired BOOST_CHECK_EQUAL(get_balance(rachel_id(db), core_id(db)), 19); // 11 + 8 BOOST_CHECK_EQUAL(get_balance(rachel_id(db), bitusd_id(db)), 40); // no change @@ -1059,28 +1059,28 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) BOOST_CHECK_EQUAL(get_balance(ted_id(db), core_id(db)), 0); BOOST_CHECK_EQUAL(get_balance(ted_id(db), bitusd_id(db)), 37); - BOOST_CHECK_EQUAL( 614, call_paul_id(db).debt.value ); // 776 - 162 - BOOST_CHECK_EQUAL( 81, call_paul_id(db).collateral.value ); // 89 - 8 - BOOST_CHECK_EQUAL( 46, call_michael_id(db).debt.value ); - BOOST_CHECK_EQUAL( 231, call_michael_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 614, call_paul_id(db).debt.get_amount().value ); // 776 - 162 + BOOST_CHECK_EQUAL( 81, call_paul_id(db).collateral.get_amount().value ); // 89 - 8 + BOOST_CHECK_EQUAL( 46, call_michael_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 231, call_michael_id(db).collateral.get_amount().value ); - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 660 ); // 822 - 162 + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 660 ); // 822 - 162 BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).force_settled_volume.value, 162 ); // reset to 0, then 162 more // current cny data - BOOST_CHECK_EQUAL( settle_id101(db).balance.amount.value, 100 ); // no change since not expired - BOOST_CHECK_EQUAL( settle_id102(db).balance.amount.value, 1000 ); // no change since not expired - BOOST_CHECK_EQUAL( settle_id103(db).balance.amount.value, 300 ); // no change since not expired + BOOST_CHECK_EQUAL( settle_id101(db).balance.get_amount().value, 100 ); // no change since not expired + BOOST_CHECK_EQUAL( settle_id102(db).balance.get_amount().value, 1000 ); // no change since not expired + BOOST_CHECK_EQUAL( settle_id103(db).balance.get_amount().value, 300 ); // no change since not expired BOOST_CHECK_EQUAL(get_balance(jim_id(db), core_id(db)), 9998000); BOOST_CHECK_EQUAL(get_balance(jim_id(db), bitcny_id(db)), 500); BOOST_CHECK_EQUAL(get_balance(joe_id(db), core_id(db)), 0); BOOST_CHECK_EQUAL(get_balance(joe_id(db), bitcny_id(db)), 100); // 1500 - 100 - 1000 - 300 - BOOST_CHECK_EQUAL( 2000, call_jim_id(db).debt.value ); - BOOST_CHECK_EQUAL( 2000, call_jim_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 2000, call_jim_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 2000, call_jim_id(db).collateral.get_amount().value ); - BOOST_CHECK_EQUAL( bitcny_id(db).dynamic_data(db).current_supply.value, 2000 ); + BOOST_CHECK_EQUAL( bitcny_id(db).dynamic_data(db).current_supply.get_amount().value, 2000 ); BOOST_CHECK_EQUAL( bitcny_id(db).bitasset_data(db).force_settled_volume.value, 0 ); // bob borrow some @@ -1090,10 +1090,10 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) BOOST_CHECK_EQUAL(get_balance(bob_id(db), core_id(db)), 9999998); // 10000000 - 2 BOOST_CHECK_EQUAL(get_balance(bob_id(db), bitusd_id(db)), 19); // new - BOOST_CHECK_EQUAL( 19, call_bob_id(db).debt.value ); - BOOST_CHECK_EQUAL( 2, call_bob_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 19, call_bob_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 2, call_bob_id(db).collateral.get_amount().value ); - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 679 ); // 660 + 19 + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 679 ); // 660 + 19 BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).force_settled_volume.value, 162 ); generate_block(); @@ -1102,11 +1102,11 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) // already settled 162, so 168 - 162 = 6 more usd can be settled, // according to price (101/5), the amount worths less than 1 core, // so nothing will happen. - BOOST_CHECK_EQUAL( settle_id4(db).balance.amount.value, 69 ); - BOOST_CHECK_EQUAL( settle_id5(db).balance.amount.value, 5 ); - BOOST_CHECK_EQUAL( settle_id6(db).balance.amount.value, 20 ); - BOOST_CHECK_EQUAL( settle_id7(db).balance.amount.value, 21 ); - BOOST_CHECK_EQUAL( settle_id8(db).balance.amount.value, 22 ); + BOOST_CHECK_EQUAL( settle_id4(db).balance.get_amount().value, 69 ); + BOOST_CHECK_EQUAL( settle_id5(db).balance.get_amount().value, 5 ); + BOOST_CHECK_EQUAL( settle_id6(db).balance.get_amount().value, 20 ); + BOOST_CHECK_EQUAL( settle_id7(db).balance.get_amount().value, 21 ); + BOOST_CHECK_EQUAL( settle_id8(db).balance.get_amount().value, 22 ); BOOST_CHECK_EQUAL(get_balance(bob_id(db), core_id(db)), 9999998); BOOST_CHECK_EQUAL(get_balance(bob_id(db), bitusd_id(db)), 19); @@ -1119,14 +1119,14 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) BOOST_CHECK_EQUAL(get_balance(ted_id(db), core_id(db)), 0); BOOST_CHECK_EQUAL(get_balance(ted_id(db), bitusd_id(db)), 37); - BOOST_CHECK_EQUAL( 19, call_bob_id(db).debt.value ); - BOOST_CHECK_EQUAL( 2, call_bob_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 614, call_paul_id(db).debt.value ); - BOOST_CHECK_EQUAL( 81, call_paul_id(db).collateral.value ); - BOOST_CHECK_EQUAL( 46, call_michael_id(db).debt.value ); - BOOST_CHECK_EQUAL( 231, call_michael_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 19, call_bob_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 2, call_bob_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 614, call_paul_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 81, call_paul_id(db).collateral.get_amount().value ); + BOOST_CHECK_EQUAL( 46, call_michael_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 231, call_michael_id(db).collateral.get_amount().value ); - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 679 ); + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 679 ); BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).force_settled_volume.value, 162 ); // adding new feed so we have valid price to exit @@ -1154,18 +1154,18 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) // according to price 50 core / 101 cny, it will get 149 core and pay 301 cny; // settle_id103 won't be processed since it's after settle_id102 BOOST_CHECK( !db.find( settle_id101 ) ); - BOOST_CHECK_EQUAL( settle_id102(db).balance.amount.value, 699 ); // 1000 - 301 - BOOST_CHECK_EQUAL( settle_id103(db).balance.amount.value, 300 ); // no change since it's after settle_id102 + BOOST_CHECK_EQUAL( settle_id102(db).balance.get_amount().value, 699 ); // 1000 - 301 + BOOST_CHECK_EQUAL( settle_id103(db).balance.get_amount().value, 300 ); // no change since it's after settle_id102 BOOST_CHECK_EQUAL(get_balance(jim_id(db), core_id(db)), 9998000); BOOST_CHECK_EQUAL(get_balance(jim_id(db), bitcny_id(db)), 500); BOOST_CHECK_EQUAL(get_balance(joe_id(db), core_id(db)), 198); // 49 + 149 BOOST_CHECK_EQUAL(get_balance(joe_id(db), bitcny_id(db)), 101); // 100 + 1 - BOOST_CHECK_EQUAL( 1600, call_jim_id(db).debt.value ); // 2000 - 99 - 301 - BOOST_CHECK_EQUAL( 1802, call_jim_id(db).collateral.value ); // 2000 - 49 - 149 + BOOST_CHECK_EQUAL( 1600, call_jim_id(db).debt.get_amount().value ); // 2000 - 99 - 301 + BOOST_CHECK_EQUAL( 1802, call_jim_id(db).collateral.get_amount().value ); // 2000 - 49 - 149 - BOOST_CHECK_EQUAL( bitcny_id(db).dynamic_data(db).current_supply.value, 1600 ); + BOOST_CHECK_EQUAL( bitcny_id(db).dynamic_data(db).current_supply.get_amount().value, 1600 ); BOOST_CHECK_EQUAL( bitcny_id(db).bitasset_data(db).force_settled_volume.value, 400 ); // 99 + 301 // adding new feed so we have valid price to exit @@ -1215,12 +1215,12 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) BOOST_CHECK_EQUAL(get_balance(ted_id(db), bitusd_id(db)), 58); // 37 + 20 + 1 BOOST_CHECK( !db.find( call_bob_id ) ); - BOOST_CHECK_EQUAL( 531, call_paul_id(db).debt.value ); // 614 - 41 - 21 - 21 - BOOST_CHECK_EQUAL( 77, call_paul_id(db).collateral.value ); // 81 - 2 - 1 - 1 - BOOST_CHECK_EQUAL( 46, call_michael_id(db).debt.value ); - BOOST_CHECK_EQUAL( 231, call_michael_id(db).collateral.value ); + BOOST_CHECK_EQUAL( 531, call_paul_id(db).debt.get_amount().value ); // 614 - 41 - 21 - 21 + BOOST_CHECK_EQUAL( 77, call_paul_id(db).collateral.get_amount().value ); // 81 - 2 - 1 - 1 + BOOST_CHECK_EQUAL( 46, call_michael_id(db).debt.get_amount().value ); + BOOST_CHECK_EQUAL( 231, call_michael_id(db).collateral.get_amount().value ); - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 577 ); // 679 - 19 - 41 - 21 - 21 + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 577 ); // 679 - 19 - 41 - 21 - 21 BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).force_settled_volume.value, 102 ); // reset to 0, then 19 + 41 + 21 + 21 // check cny @@ -1229,18 +1229,18 @@ BOOST_AUTO_TEST_CASE( settle_rounding_test_after_hf_184 ) // according to price 50 core / 101 cny, it will get 158 core and pay 320 cny; // settle_id103 won't be processed since it's after settle_id102 BOOST_CHECK( !db.find( settle_id101 ) ); - BOOST_CHECK_EQUAL( settle_id102(db).balance.amount.value, 379 ); // 699 - 320 - BOOST_CHECK_EQUAL( settle_id103(db).balance.amount.value, 300 ); // no change since it's after settle_id102 + BOOST_CHECK_EQUAL( settle_id102(db).balance.get_amount().value, 379 ); // 699 - 320 + BOOST_CHECK_EQUAL( settle_id103(db).balance.get_amount().value, 300 ); // no change since it's after settle_id102 BOOST_CHECK_EQUAL(get_balance(jim_id(db), core_id(db)), 9998000); BOOST_CHECK_EQUAL(get_balance(jim_id(db), bitcny_id(db)), 500); BOOST_CHECK_EQUAL(get_balance(joe_id(db), core_id(db)), 356); // 198 + 158 BOOST_CHECK_EQUAL(get_balance(joe_id(db), bitcny_id(db)), 101); - BOOST_CHECK_EQUAL( 1280, call_jim_id(db).debt.value ); // 1600 - 320 - BOOST_CHECK_EQUAL( 1644, call_jim_id(db).collateral.value ); // 1802 - 158 + BOOST_CHECK_EQUAL( 1280, call_jim_id(db).debt.get_amount().value ); // 1600 - 320 + BOOST_CHECK_EQUAL( 1644, call_jim_id(db).collateral.get_amount().value ); // 1802 - 158 - BOOST_CHECK_EQUAL( bitcny_id(db).dynamic_data(db).current_supply.value, 1280 ); + BOOST_CHECK_EQUAL( bitcny_id(db).dynamic_data(db).current_supply.get_amount().value, 1280 ); BOOST_CHECK_EQUAL( bitcny_id(db).bitasset_data(db).force_settled_volume.value, 320 ); // reset to 0, then 320 generate_block(); @@ -1326,8 +1326,8 @@ BOOST_AUTO_TEST_CASE( global_settle_rounding_test ) BOOST_CHECK( bitusd_id(db).bitasset_data(db).settlement_price == price( bitusd_id(db).amount(1007), core_id(db).amount(100) ) ); - BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).settlement_fund.value, 100 ); // 100 from paul, and 0 from michael - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 1007 ); + BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).settlement_fund.get_amount().value, 100 ); // 100 from paul, and 0 from michael + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 1007 ); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), core_id(db)), 0); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), bitusd_id(db)), 200); @@ -1346,8 +1346,8 @@ BOOST_AUTO_TEST_CASE( global_settle_rounding_test ) BOOST_CHECK( bitusd_id(db).bitasset_data(db).settlement_price == price( bitusd_id(db).amount(1007), core_id(db).amount(100) ) ); - BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).settlement_fund.value, 100 ); // paid nothing - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 1003 ); // settled 4 usd + BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).settlement_fund.get_amount().value, 100 ); // paid nothing + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 1003 ); // settled 4 usd BOOST_CHECK_EQUAL(get_balance(rachel_id(db), core_id(db)), 0); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), bitusd_id(db)), 196); // rachel paid 4 usd and got nothing @@ -1362,8 +1362,8 @@ BOOST_AUTO_TEST_CASE( global_settle_rounding_test ) BOOST_CHECK( bitusd_id(db).bitasset_data(db).settlement_price == price( bitusd_id(db).amount(1007), core_id(db).amount(100) ) ); - BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).settlement_fund.value, 99 ); // paid 1 core - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 990 ); // settled 13 usd + BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).settlement_fund.get_amount().value, 99 ); // paid 1 core + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 990 ); // settled 13 usd BOOST_CHECK_EQUAL(get_balance(rachel_id(db), core_id(db)), 1); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), bitusd_id(db)), 183); // rachel paid 13 usd and got 1 core @@ -1449,8 +1449,8 @@ BOOST_AUTO_TEST_CASE( global_settle_rounding_test_after_hf_184 ) BOOST_CHECK( bitusd_id(db).bitasset_data(db).settlement_price == price( bitusd_id(db).amount(1007), core_id(db).amount(102) ) ); - BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).settlement_fund.value, 102 ); // 101 from paul, and 1 from michael - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 1007 ); + BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).settlement_fund.get_amount().value, 102 ); // 101 from paul, and 1 from michael + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 1007 ); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), core_id(db)), 0); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), bitusd_id(db)), 200); @@ -1471,8 +1471,8 @@ BOOST_AUTO_TEST_CASE( global_settle_rounding_test_after_hf_184 ) // balances unchanged BOOST_CHECK( bitusd_id(db).bitasset_data(db).settlement_price == price( bitusd_id(db).amount(1007), core_id(db).amount(102) ) ); - BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).settlement_fund.value, 102 ); - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 1007 ); + BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).settlement_fund.get_amount().value, 102 ); + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 1007 ); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), core_id(db)), 0); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), bitusd_id(db)), 200); @@ -1487,8 +1487,8 @@ BOOST_AUTO_TEST_CASE( global_settle_rounding_test_after_hf_184 ) BOOST_CHECK( bitusd_id(db).bitasset_data(db).settlement_price == price( bitusd_id(db).amount(1007), core_id(db).amount(102) ) ); - BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).settlement_fund.value, 101 ); // paid 1 core - BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.value, 997 ); // settled 10 usd + BOOST_CHECK_EQUAL( bitusd_id(db).bitasset_data(db).settlement_fund.get_amount().value, 101 ); // paid 1 core + BOOST_CHECK_EQUAL( bitusd_id(db).dynamic_data(db).current_supply.get_amount().value, 997 ); // settled 10 usd BOOST_CHECK_EQUAL(get_balance(rachel_id(db), core_id(db)), 1); BOOST_CHECK_EQUAL(get_balance(rachel_id(db), bitusd_id(db)), 190); // rachel paid 10 usd and got 1 core, 3 usd returned diff --git a/tests/tests/smartcoin_tests.cpp b/tests/tests/smartcoin_tests.cpp index 7d69caaa05..45a932d30b 100644 --- a/tests/tests/smartcoin_tests.cpp +++ b/tests/tests/smartcoin_tests.cpp @@ -130,6 +130,8 @@ BOOST_AUTO_TEST_CASE(bsip36) generate_block(); trx.clear(); + const asset_bitasset_data_object& bitasset_data = bit_usd_id(db).bitasset_data(db); + // Check current default witnesses, default chain is configured with 10 witnesses auto witnesses = db.get_global_properties().active_witnesses; BOOST_CHECK_EQUAL(witnesses.size(), INITIAL_WITNESS_COUNT); @@ -196,7 +198,6 @@ BOOST_AUTO_TEST_CASE(bsip36) feed.settlement_price = bit_usd_id(db).amount(1) / core.amount(5); publish_feed(bit_usd_id(db), witness0_id(db), feed); - asset_bitasset_data_object bitasset_data = bit_usd_id(db).bitasset_data(db); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 1u); auto itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 16u); @@ -204,7 +205,6 @@ BOOST_AUTO_TEST_CASE(bsip36) feed.settlement_price = bit_usd_id(db).amount(2) / core.amount(5); publish_feed(bit_usd_id(db), witness1_id(db), feed); - bitasset_data = bit_usd_id(db).bitasset_data(db); itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 2u); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 16u); @@ -247,15 +247,13 @@ BOOST_AUTO_TEST_CASE(bsip36) // witness0 has been removed but it was a feeder before // Feed persist in the blockchain, this reproduces the issue - bitasset_data = bit_usd_id(db).bitasset_data(db); itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 2u); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 16u); // Feed persist after expiration - const auto feed_lifetime = bit_usd_id(db).bitasset_data(db).options.feed_lifetime_sec; + const auto feed_lifetime = bitasset_data.options.feed_lifetime_sec; generate_blocks(db.head_block_time() + feed_lifetime + 1); - bitasset_data = bit_usd_id(db).bitasset_data(db); itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 2u); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 16u); @@ -267,14 +265,13 @@ BOOST_AUTO_TEST_CASE(bsip36) publish_feed(bit_usd_id(db), witness3_id(db), feed); // But the one from witness0 is never removed - bitasset_data = bit_usd_id(db).bitasset_data(db); itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 4u); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 16u); // Feed from witness1 is also expired but never deleted // All feeds should be deleted at this point - const auto minimum_feeds = bit_usd_id(db).bitasset_data(db).options.minimum_feeds; + const auto minimum_feeds = bitasset_data.options.minimum_feeds; BOOST_CHECK_EQUAL(minimum_feeds, 1u); BOOST_CHECK_EQUAL(itr[1].first.instance.value, 17u); @@ -285,13 +282,11 @@ BOOST_AUTO_TEST_CASE(bsip36) generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); // All expired feeds are deleted - bitasset_data = bit_usd_id(db).bitasset_data(db); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 0u); // witness1 start feed producing again feed.settlement_price = bit_usd_id(db).amount(1) / core.amount(5); publish_feed(bit_usd_id(db), witness1_id(db), feed); - bitasset_data = bit_usd_id(db).bitasset_data(db); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 1u); itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 17u); @@ -302,7 +297,6 @@ BOOST_AUTO_TEST_CASE(bsip36) // add another feed with witness2 feed.settlement_price = bit_usd_id(db).amount(1) / core.amount(5); publish_feed(bit_usd_id(db), witness2_id(db), feed); - bitasset_data = bit_usd_id(db).bitasset_data(db); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 2u); itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 17u); @@ -313,7 +307,6 @@ BOOST_AUTO_TEST_CASE(bsip36) generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); // feed from witness0 expires and gets deleted, feed from witness is on time so persist - bitasset_data = bit_usd_id(db).bitasset_data(db); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 1u); itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 18u); @@ -321,13 +314,11 @@ BOOST_AUTO_TEST_CASE(bsip36) // expire everything generate_blocks(itr[0].second.first + feed_lifetime + 1); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - bitasset_data = bit_usd_id(db).bitasset_data(db); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 0u); // add new feed with witness1 feed.settlement_price = bit_usd_id(db).amount(1) / core.amount(5); publish_feed(bit_usd_id(db), witness1_id(db), feed); - bitasset_data = bit_usd_id(db).bitasset_data(db); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 1u); itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 17u); @@ -376,7 +367,6 @@ BOOST_AUTO_TEST_CASE(bsip36) generate_blocks(itr[0].second.first + feed_lifetime + 1); generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); - bitasset_data = bit_usd_id(db).bitasset_data(db); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 0u); } FC_LOG_AND_RETHROW() @@ -393,8 +383,8 @@ BOOST_AUTO_TEST_CASE(bsip36_update_feed_producers) const asset_id_type bit_usd_id = create_bitasset("USDBIT").id; // Update asset issuer - const asset_object &asset_obj = bit_usd_id(db); { + const asset_object &asset_obj = bit_usd_id(db); asset_update_operation op; op.asset_to_update = bit_usd_id; op.issuer = asset_obj.issuer; @@ -421,7 +411,7 @@ BOOST_AUTO_TEST_CASE(bsip36_update_feed_producers) } // Bitshares will create entries in the field feed after feed producers are added - auto bitasset_data = bit_usd_id(db).bitasset_data(db); + const auto& bitasset_data = bit_usd_id(db).bitasset_data(db); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 3u); auto itr = bitasset_data.feeds.begin(); @@ -443,16 +433,14 @@ BOOST_AUTO_TEST_CASE(bsip36_update_feed_producers) } // Feed for removed producer is removed - bitasset_data = bit_usd_id(db).bitasset_data(db); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 2u); itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 17u); BOOST_CHECK_EQUAL(itr[1].first.instance.value, 18u); // Feed persist after expiration - const auto feed_lifetime = bit_usd_id(db).bitasset_data(db).options.feed_lifetime_sec; + const auto feed_lifetime = bitasset_data.options.feed_lifetime_sec; generate_blocks(db.head_block_time() + feed_lifetime + 1); - bitasset_data = bit_usd_id(db).bitasset_data(db); itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 2u); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 17u); @@ -465,7 +453,6 @@ BOOST_AUTO_TEST_CASE(bsip36_update_feed_producers) generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); // Expired feeds persist, no changes - bitasset_data = bit_usd_id(db).bitasset_data(db); itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 2u); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 17u); @@ -511,7 +498,7 @@ BOOST_AUTO_TEST_CASE(bsip36_additional) price_feed feed; feed.settlement_price = bit_usd_id(db).amount(1) / core_id(db).amount(5); publish_feed(bit_usd_id(db), witness5_id(db), feed); - auto bitasset_data = bit_usd_id(db).bitasset_data(db); + const auto& bitasset_data = bit_usd_id(db).bitasset_data(db); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 1u); auto itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 21u); @@ -521,7 +508,6 @@ BOOST_AUTO_TEST_CASE(bsip36_additional) feed.settlement_price = bit_usd_id(db).amount(1) / core_id(db).amount(5); publish_feed(bit_usd_id(db), witness6_id(db), feed); - bitasset_data = bit_usd_id(db).bitasset_data(db); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 2u); itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 21u); @@ -532,7 +518,6 @@ BOOST_AUTO_TEST_CASE(bsip36_additional) feed.settlement_price = bit_usd_id(db).amount(1) / core_id(db).amount(5); publish_feed(bit_usd_id(db), witness7_id(db), feed); - bitasset_data = bit_usd_id(db).bitasset_data(db); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 3u); itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 21u); @@ -544,7 +529,6 @@ BOOST_AUTO_TEST_CASE(bsip36_additional) feed.settlement_price = bit_usd_id(db).amount(1) / core_id(db).amount(5); publish_feed(bit_usd_id(db), witness8_id(db), feed); - bitasset_data = bit_usd_id(db).bitasset_data(db); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 4u); itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 21u); @@ -557,7 +541,6 @@ BOOST_AUTO_TEST_CASE(bsip36_additional) feed.settlement_price = bit_usd_id(db).amount(1) / core_id(db).amount(5); publish_feed(bit_usd_id(db), witness9_id(db), feed); - bitasset_data = bit_usd_id(db).bitasset_data(db); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 5u); itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 21u); @@ -571,7 +554,6 @@ BOOST_AUTO_TEST_CASE(bsip36_additional) feed.settlement_price = bit_usd_id(db).amount(1) / core_id(db).amount(5); publish_feed(bit_usd_id(db), witness10_id(db), feed); - bitasset_data = bit_usd_id(db).bitasset_data(db); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 6u); itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 21u); @@ -585,7 +567,6 @@ BOOST_AUTO_TEST_CASE(bsip36_additional) generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); generate_block(); - bitasset_data = bit_usd_id(db).bitasset_data(db); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 5u); itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 22u); @@ -600,7 +581,6 @@ BOOST_AUTO_TEST_CASE(bsip36_additional) generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); generate_block(); - bitasset_data = bit_usd_id(db).bitasset_data(db); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 3u); itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 24u); @@ -610,7 +590,6 @@ BOOST_AUTO_TEST_CASE(bsip36_additional) // witness5 add new feed, feeds are sorted by witness_id not by feed_time feed.settlement_price = bit_usd_id(db).amount(1) / core_id(db).amount(5); publish_feed(bit_usd_id(db), witness5_id(db), feed); - bitasset_data = bit_usd_id(db).bitasset_data(db); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 4u); itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 21u); @@ -621,7 +600,6 @@ BOOST_AUTO_TEST_CASE(bsip36_additional) // another feed expires generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); generate_block(); - bitasset_data = bit_usd_id(db).bitasset_data(db); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 3u); itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 21u); @@ -631,7 +609,6 @@ BOOST_AUTO_TEST_CASE(bsip36_additional) // another feed expires generate_blocks(db.get_dynamic_global_properties().next_maintenance_time); generate_block(); - bitasset_data = bit_usd_id(db).bitasset_data(db); BOOST_CHECK_EQUAL(bitasset_data.feeds.size(), 2u); itr = bitasset_data.feeds.begin(); BOOST_CHECK_EQUAL(itr[0].first.instance.value, 21u); diff --git a/tests/tests/swan_tests.cpp b/tests/tests/swan_tests.cpp index d5aff8b996..0eacae0daf 100644 --- a/tests/tests/swan_tests.cpp +++ b/tests/tests/swan_tests.cpp @@ -351,8 +351,8 @@ BOOST_AUTO_TEST_CASE( recollateralize ) // can't bid wrong collateral type GRAPHENE_REQUIRE_THROW( bid_collateral( borrower2(), bitcny.amount(100), swan().amount(100) ), fc::exception ); - BOOST_CHECK( swan().dynamic_data(db).current_supply == 1400 ); - BOOST_CHECK( swan().bitasset_data(db).settlement_fund == 2800 ); + BOOST_CHECK( swan().dynamic_data(db).current_supply.get_amount() == 1400 ); + BOOST_CHECK( swan().bitasset_data(db).settlement_fund.get_amount() == 2800 ); BOOST_CHECK( swan().bitasset_data(db).has_settlement() ); BOOST_CHECK( swan().bitasset_data(db).current_feed.settlement_price.is_null() ); @@ -383,7 +383,7 @@ BOOST_AUTO_TEST_CASE( recollateralize ) graphene::app::database_api db_api( db, &( app.get_options() )); GRAPHENE_REQUIRE_THROW( db_api.get_collateral_bids(back().symbol, 100, 0), fc::assert_exception ); auto swan_symbol = _swan(db).symbol; - vector bids = db_api.get_collateral_bids(swan_symbol, 100, 1); + vector bids = db_api.get_collateral_bids(swan_symbol, 100, 1); BOOST_CHECK_EQUAL( 1u, bids.size() ); FC_ASSERT( _borrower2 == bids[0].bidder ); bids = db_api.get_collateral_bids(swan_symbol, 1, 0); @@ -421,8 +421,8 @@ BOOST_AUTO_TEST_CASE( revive_empty_recovered ) cancel_limit_order( oid(db) ); force_settle( borrower(), swan().amount(1000) ); force_settle( borrower2(), swan().amount(1000) ); - BOOST_CHECK_EQUAL( 0, swan().dynamic_data(db).current_supply.value ); - BOOST_CHECK_EQUAL( 0, swan().bitasset_data(db).settlement_fund.value ); + BOOST_CHECK_EQUAL( 0, swan().dynamic_data(db).current_supply.get_amount().value ); + BOOST_CHECK_EQUAL( 0, swan().bitasset_data(db).settlement_fund.get_amount().value ); BOOST_CHECK( swan().bitasset_data(db).has_settlement() ); // revive after price recovers @@ -452,7 +452,7 @@ BOOST_AUTO_TEST_CASE( revive_empty ) cancel_limit_order( oid(db) ); force_settle( borrower(), swan().amount(1000) ); force_settle( borrower2(), swan().amount(1000) ); - BOOST_CHECK_EQUAL( 0, swan().dynamic_data(db).current_supply.value ); + BOOST_CHECK_EQUAL( 0, swan().dynamic_data(db).current_supply.get_amount().value ); BOOST_CHECK( swan().bitasset_data(db).has_settlement() ); @@ -491,8 +491,8 @@ BOOST_AUTO_TEST_CASE( revive_empty_with_bid ) force_settle( borrower(), swan().amount(500) ); force_settle( borrower2(), swan().amount(667) ); force_settle( borrower2(), swan().amount(333) ); - BOOST_CHECK_EQUAL( 0, swan().dynamic_data(db).current_supply.value ); - BOOST_CHECK_EQUAL( 0, swan().bitasset_data(db).settlement_fund.value ); + BOOST_CHECK_EQUAL( 0, swan().dynamic_data(db).current_supply.get_amount().value ); + BOOST_CHECK_EQUAL( 0, swan().bitasset_data(db).settlement_fund.get_amount().value ); bid_collateral( borrower(), back().amount(3000), swan().amount(700) ); @@ -503,7 +503,7 @@ BOOST_AUTO_TEST_CASE( revive_empty_with_bid ) BOOST_CHECK( !swan().bitasset_data(db).has_settlement() ); graphene::app::database_api db_api( db, &( app.get_options() )); auto swan_symbol = _swan(db).symbol; - vector bids = db_api.get_collateral_bids(swan_symbol, 100, 0); + vector bids = db_api.get_collateral_bids(swan_symbol, 100, 0); BOOST_CHECK( bids.empty() ); auto& call_idx = db.get_index_type().indices().get(); @@ -577,10 +577,10 @@ BOOST_AUTO_TEST_CASE( overflow ) auto& call_idx = db.get_index_type().indices().get(); auto itr = call_idx.find( boost::make_tuple(_borrower, _swan) ); BOOST_REQUIRE( itr != call_idx.end() ); - BOOST_CHECK_EQUAL( 1, itr->debt.value ); + BOOST_CHECK_EQUAL( 1, itr->debt.get_amount().value ); itr = call_idx.find( boost::make_tuple(_borrower2, _swan) ); BOOST_REQUIRE( itr != call_idx.end() ); - BOOST_CHECK_EQUAL( 1399, itr->debt.value ); + BOOST_CHECK_EQUAL( 1399, itr->debt.get_amount().value ); BOOST_CHECK( !swan().bitasset_data(db).has_settlement() ); } FC_LOG_AND_RETHROW() } diff --git a/tests/tests/uia_tests.cpp b/tests/tests/uia_tests.cpp index e68b55d5dd..811bd139fc 100644 --- a/tests/tests/uia_tests.cpp +++ b/tests/tests/uia_tests.cpp @@ -71,9 +71,9 @@ BOOST_AUTO_TEST_CASE( create_advanced_uia ) BOOST_CHECK(test_asset.options.market_fee_percent == GRAPHENE_MAX_MARKET_FEE_PERCENT/100); const asset_dynamic_data_object& test_asset_dynamic_data = test_asset.dynamic_asset_data_id(db); - BOOST_CHECK(test_asset_dynamic_data.current_supply == 0); - BOOST_CHECK(test_asset_dynamic_data.accumulated_fees == 0); - BOOST_CHECK(test_asset_dynamic_data.fee_pool == 0); + BOOST_CHECK(test_asset_dynamic_data.current_supply.get_amount() == 0); + BOOST_CHECK(test_asset_dynamic_data.accumulated_fees.get_amount() == 0); + BOOST_CHECK(test_asset_dynamic_data.fee_pool.get_amount() == 0); } catch(fc::exception& e) { edump((e.to_detail_string())); diff --git a/tests/tests/voting_tests.cpp b/tests/tests/voting_tests.cpp index 1d61c65bc9..936e7e3380 100644 --- a/tests/tests/voting_tests.cpp +++ b/tests/tests/voting_tests.cpp @@ -464,7 +464,7 @@ BOOST_AUTO_TEST_CASE(last_voting_date) // we are going to vote for this witness auto witness1 = witness_id_type(1)(db); - auto stats_obj = db.get_account_stats_by_owner(alice_id); + const auto& stats_obj = db.get_account_stats_by_owner(alice_id); BOOST_CHECK_EQUAL(stats_obj.last_vote_time.sec_since_epoch(), 0u); // alice votes @@ -479,7 +479,6 @@ BOOST_AUTO_TEST_CASE(last_voting_date) auto now = db.head_block_time().sec_since_epoch(); // last_vote_time is updated for alice - stats_obj = db.get_account_stats_by_owner(alice_id); BOOST_CHECK_EQUAL(stats_obj.last_vote_time.sec_since_epoch(), now); } FC_LOG_AND_RETHROW() @@ -510,7 +509,7 @@ BOOST_AUTO_TEST_CASE(last_voting_date_proxy) PUSH_TX( db, trx, ~0 ); } // alice last_vote_time is updated - auto alice_stats_obj = db.get_account_stats_by_owner(alice_id); + const auto& alice_stats_obj = db.get_account_stats_by_owner(alice_id); auto round1 = db.head_block_time().sec_since_epoch(); BOOST_CHECK_EQUAL(alice_stats_obj.last_vote_time.sec_since_epoch(), round1); @@ -527,7 +526,6 @@ BOOST_AUTO_TEST_CASE(last_voting_date_proxy) PUSH_TX( db, trx, ~0 ); } // last_vote_time is not updated - alice_stats_obj = db.get_account_stats_by_owner(alice_id); BOOST_CHECK_EQUAL(alice_stats_obj.last_vote_time.sec_since_epoch(), round1); generate_block(); @@ -546,7 +544,7 @@ BOOST_AUTO_TEST_CASE(last_voting_date_proxy) // last_vote_time for bob is updated as he voted auto round3 = db.head_block_time().sec_since_epoch(); - auto bob_stats_obj = db.get_account_stats_by_owner(bob_id); + const auto& bob_stats_obj = db.get_account_stats_by_owner(bob_id); BOOST_CHECK_EQUAL(bob_stats_obj.last_vote_time.sec_since_epoch(), round3); generate_block(); @@ -564,15 +562,13 @@ BOOST_AUTO_TEST_CASE(last_voting_date_proxy) // proxy just voted so the last_vote_time is updated auto round4 = db.head_block_time().sec_since_epoch(); - auto proxy_stats_obj = db.get_account_stats_by_owner(proxy_id); + const auto& proxy_stats_obj = db.get_account_stats_by_owner(proxy_id); BOOST_CHECK_EQUAL(proxy_stats_obj.last_vote_time.sec_since_epoch(), round4); // alice haves proxy, proxy votes but last_vote_time is not updated for alice - alice_stats_obj = db.get_account_stats_by_owner(alice_id); BOOST_CHECK_EQUAL(alice_stats_obj.last_vote_time.sec_since_epoch(), round1); // bob haves nothing to do with proxy so last_vote_time is not updated - bob_stats_obj = db.get_account_stats_by_owner(bob_id); BOOST_CHECK_EQUAL(bob_stats_obj.last_vote_time.sec_since_epoch(), round3); } FC_LOG_AND_RETHROW() From 25f3f676b534e1d2b392c12bdf3de8760a0ab3b4 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 5 Dec 2019 08:25:55 +0100 Subject: [PATCH 15/59] Fixup modify --- libraries/db/include/graphene/db/index.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/db/include/graphene/db/index.hpp b/libraries/db/include/graphene/db/index.hpp index bdcc67b509..baf237bb3c 100644 --- a/libraries/db/include/graphene/db/index.hpp +++ b/libraries/db/include/graphene/db/index.hpp @@ -125,7 +125,7 @@ namespace graphene { namespace db { * @note Lambda should have the signature: void(Object&) */ template - void modify( const Object& obj, Lambda&& l ) { + void modify( const Object& obj, const Lambda& l ) { modify( static_cast(obj), std::function( [&l]( object& o ){ l( static_cast(o) ); } ) ); } From c6556846dfa87984902a78b6b9bcf5b80261a2c5 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 5 Dec 2019 17:24:18 +0100 Subject: [PATCH 16/59] Implement clear(), fix backup/restore --- libraries/chain/account_object.cpp | 11 +++++++++ libraries/chain/asset_object.cpp | 14 +++++++++++ libraries/chain/db_management.cpp | 1 + libraries/chain/fba_object.cpp | 5 ++++ .../include/graphene/chain/account_object.hpp | 2 ++ .../include/graphene/chain/asset_object.hpp | 2 ++ .../include/graphene/chain/balance_object.hpp | 1 + .../include/graphene/chain/fba_object.hpp | 1 + .../graphene/chain/global_property_object.hpp | 1 + .../include/graphene/chain/htlc_object.hpp | 1 + .../include/graphene/chain/market_object.hpp | 4 ++++ .../include/graphene/chain/stored_value.hpp | 4 ++-- .../graphene/chain/vesting_balance_object.hpp | 1 + libraries/chain/market_object.cpp | 23 ++++++++++++++++++ libraries/chain/small_objects.cpp | 15 ++++++++++++ libraries/chain/stored_value.cpp | 3 +-- libraries/chain/vesting_balance_object.cpp | 5 ++++ libraries/db/include/graphene/db/object.hpp | 1 + .../include/graphene/db/object_database.hpp | 1 + libraries/db/object_database.cpp | 24 ++++++++++++++++++- libraries/db/undo_database.cpp | 7 ++---- 21 files changed, 117 insertions(+), 10 deletions(-) diff --git a/libraries/chain/account_object.cpp b/libraries/chain/account_object.cpp index 5a67e300dc..75c2745d4c 100644 --- a/libraries/chain/account_object.cpp +++ b/libraries/chain/account_object.cpp @@ -81,6 +81,11 @@ void account_balance_object::restore( object& obj ) static_cast(*this) = std::move( backup ); } +void account_balance_object::clear() +{ + balance.clear(); +} + void account_statistics_object::process_fees(const account_object& a, database& d) const { if( pending_fees.get_amount() > 0 || pending_vested_fees.get_amount() > 0 ) @@ -169,6 +174,12 @@ void account_statistics_object::restore( object& obj ) static_cast(*this) = std::move( backup ); } +void account_statistics_object::clear() +{ + pending_fees.clear(); + pending_vested_fees.clear(); +} + set account_member_index::get_account_members(const account_object& a)const { set result; diff --git a/libraries/chain/asset_object.cpp b/libraries/chain/asset_object.cpp index 3499387fab..cc0240de2e 100644 --- a/libraries/chain/asset_object.cpp +++ b/libraries/chain/asset_object.cpp @@ -64,6 +64,14 @@ void asset_dynamic_data_object::restore( object& obj ) static_cast(*this) = std::move( backup ); } +void asset_dynamic_data_object::clear() +{ + current_supply.clear(); + accumulated_fees.clear(); + fee_pool.clear(); + confidential_supply.clear(); +} + share_type asset_bitasset_data_master::max_force_settlement_volume(share_type current_supply) const { if( options.maximum_force_settlement_volume == 0 ) @@ -167,6 +175,12 @@ void asset_bitasset_data_object::restore( object& obj ) static_cast(*this) = std::move( backup ); } +void asset_bitasset_data_object::clear() +{ + settlement_fund.clear(); + total_debt.clear(); +} + asset asset_object::amount_from_string(string amount_string) const { try { diff --git a/libraries/chain/db_management.cpp b/libraries/chain/db_management.cpp index 9ca657ef6f..977e288a8f 100644 --- a/libraries/chain/db_management.cpp +++ b/libraries/chain/db_management.cpp @@ -32,6 +32,7 @@ #include #include +#include #include #include diff --git a/libraries/chain/fba_object.cpp b/libraries/chain/fba_object.cpp index 5527346dbe..d41b85f9ed 100644 --- a/libraries/chain/fba_object.cpp +++ b/libraries/chain/fba_object.cpp @@ -125,6 +125,11 @@ void fba_accumulator_object::restore( object& obj ) static_cast(*this) = std::move( backup ); } +void fba_accumulator_object::clear() +{ + accumulated_fba_fees.clear(); +} + } } FC_REFLECT_DERIVED( graphene::chain::fba_accumulator_master, (graphene::db::object), diff --git a/libraries/chain/include/graphene/chain/account_object.hpp b/libraries/chain/include/graphene/chain/account_object.hpp index 5661c3bc20..d2dd2ae6c6 100644 --- a/libraries/chain/include/graphene/chain/account_object.hpp +++ b/libraries/chain/include/graphene/chain/account_object.hpp @@ -127,6 +127,7 @@ namespace graphene { namespace chain { protected: virtual unique_ptr backup()const; virtual void restore( graphene::db::object& obj ); + virtual void clear(); }; /** @@ -160,6 +161,7 @@ namespace graphene { namespace chain { protected: virtual unique_ptr backup()const; virtual void restore( graphene::db::object& obj ); + virtual void clear(); }; /** diff --git a/libraries/chain/include/graphene/chain/asset_object.hpp b/libraries/chain/include/graphene/chain/asset_object.hpp index c3c0a6e2b1..b1593271f8 100644 --- a/libraries/chain/include/graphene/chain/asset_object.hpp +++ b/libraries/chain/include/graphene/chain/asset_object.hpp @@ -75,6 +75,7 @@ namespace graphene { namespace chain { protected: virtual unique_ptr backup()const; virtual void restore( graphene::db::object& obj ); + virtual void clear(); }; /** @@ -281,6 +282,7 @@ namespace graphene { namespace chain { protected: virtual unique_ptr backup()const; virtual void restore( graphene::db::object& obj ); + virtual void clear(); }; // key extractor for short backing asset diff --git a/libraries/chain/include/graphene/chain/balance_object.hpp b/libraries/chain/include/graphene/chain/balance_object.hpp index cc97f8a42c..c7cbc3fd4e 100644 --- a/libraries/chain/include/graphene/chain/balance_object.hpp +++ b/libraries/chain/include/graphene/chain/balance_object.hpp @@ -62,6 +62,7 @@ namespace graphene { namespace chain { protected: virtual unique_ptr backup()const; virtual void restore( graphene::db::object& obj ); + virtual void clear(); }; struct by_owner; diff --git a/libraries/chain/include/graphene/chain/fba_object.hpp b/libraries/chain/include/graphene/chain/fba_object.hpp index 23c4c5de81..da289f67f0 100644 --- a/libraries/chain/include/graphene/chain/fba_object.hpp +++ b/libraries/chain/include/graphene/chain/fba_object.hpp @@ -57,6 +57,7 @@ class fba_accumulator_object : public fba_accumulator_master protected: virtual unique_ptr backup()const; virtual void restore( graphene::db::object& obj ); + virtual void clear(); }; } } // graphene::chain diff --git a/libraries/chain/include/graphene/chain/global_property_object.hpp b/libraries/chain/include/graphene/chain/global_property_object.hpp index ff841991ba..700fdfbbf4 100644 --- a/libraries/chain/include/graphene/chain/global_property_object.hpp +++ b/libraries/chain/include/graphene/chain/global_property_object.hpp @@ -127,6 +127,7 @@ namespace graphene { namespace chain { protected: virtual unique_ptr backup()const; virtual void restore( graphene::db::object& obj ); + virtual void clear(); }; }} diff --git a/libraries/chain/include/graphene/chain/htlc_object.hpp b/libraries/chain/include/graphene/chain/htlc_object.hpp index 424e976f5c..d25ef0b710 100644 --- a/libraries/chain/include/graphene/chain/htlc_object.hpp +++ b/libraries/chain/include/graphene/chain/htlc_object.hpp @@ -92,6 +92,7 @@ namespace graphene { namespace chain { protected: virtual unique_ptr backup()const; virtual void restore( graphene::db::object& obj ); + virtual void clear(); }; struct by_from_id; diff --git a/libraries/chain/include/graphene/chain/market_object.hpp b/libraries/chain/include/graphene/chain/market_object.hpp index b6e2d63cf3..e105c3c3c6 100644 --- a/libraries/chain/include/graphene/chain/market_object.hpp +++ b/libraries/chain/include/graphene/chain/market_object.hpp @@ -76,6 +76,7 @@ class limit_order_object : public limit_order_master protected: virtual unique_ptr backup()const; virtual void restore( graphene::db::object& obj ); + virtual void clear(); }; struct by_price; @@ -168,6 +169,7 @@ class call_order_object : public call_order_master protected: virtual unique_ptr backup()const; virtual void restore( graphene::db::object& obj ); + virtual void clear(); }; /** @@ -196,6 +198,7 @@ class force_settlement_object : public force_settlement_master protected: virtual unique_ptr backup()const; virtual void restore( graphene::db::object& obj ); + virtual void clear(); }; /** @@ -227,6 +230,7 @@ class collateral_bid_object : public collateral_bid_master protected: virtual unique_ptr backup()const; virtual void restore( graphene::db::object& obj ); + virtual void clear(); }; struct by_collateral; diff --git a/libraries/chain/include/graphene/chain/stored_value.hpp b/libraries/chain/include/graphene/chain/stored_value.hpp index 1acca6df2f..c57b414fc7 100644 --- a/libraries/chain/include/graphene/chain/stored_value.hpp +++ b/libraries/chain/include/graphene/chain/stored_value.hpp @@ -62,7 +62,8 @@ namespace graphene { namespace chain { graphene::protocol::asset_id_type _asset; graphene::protocol::share_type _amount; - void restore( const graphene::protocol::asset& backup ); + virtual void restore( const graphene::protocol::asset& backup ); + virtual void clear() { _amount = 0; } friend class account_balance_object; friend class account_statistics_object; friend class asset_dynamic_data_object; @@ -76,7 +77,6 @@ namespace graphene { namespace chain { friend class force_settlement_object; friend class collateral_bid_object; friend class vesting_balance_object; - friend class worker_object; }; class stored_value : public stored_debt diff --git a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp index 9ca9279035..3c6330e2fe 100644 --- a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp +++ b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp @@ -202,6 +202,7 @@ namespace graphene { namespace chain { protected: virtual unique_ptr backup()const; virtual void restore( graphene::db::object& obj ); + virtual void clear(); }; /** diff --git a/libraries/chain/market_object.cpp b/libraries/chain/market_object.cpp index a8d9abdd60..823e6bdba1 100644 --- a/libraries/chain/market_object.cpp +++ b/libraries/chain/market_object.cpp @@ -62,6 +62,13 @@ void limit_order_object::restore( object& obj ) static_cast(*this) = std::move( backup ); } +void limit_order_object::clear() +{ + for_sale.clear(); + deferred_fee.clear(); + deferred_paid_fee.clear(); +} + /* target_CR = max( target_CR, MCR ) @@ -362,6 +369,12 @@ void call_order_object::restore( object& obj ) static_cast(*this) = std::move( backup ); } +void call_order_object::clear() +{ + debt.clear(); + collateral.clear(); +} + class force_settlement_backup : public force_settlement_master { asset balance; @@ -387,6 +400,11 @@ void force_settlement_object::restore( object& obj ) static_cast(*this) = std::move( backup ); } +void force_settlement_object::clear() +{ + balance.clear(); +} + class collateral_bid_backup : public collateral_bid_master { asset collateral_offered; @@ -412,6 +430,11 @@ void collateral_bid_object::restore( object& obj ) static_cast(*this) = std::move( backup ); } +void collateral_bid_object::clear() +{ + collateral_offered.clear(); +} + } } // graphene::chain FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::limit_order_object, diff --git a/libraries/chain/small_objects.cpp b/libraries/chain/small_objects.cpp index e0ef2363e8..45d9b754b2 100644 --- a/libraries/chain/small_objects.cpp +++ b/libraries/chain/small_objects.cpp @@ -71,6 +71,11 @@ void balance_object::restore( object& obj ) static_cast(*this) = std::move( backup ); } +void balance_object::clear() +{ + balance.clear(); +} + class dynamic_global_property_backup : public dynamic_global_property_master { asset witness_budget; @@ -96,6 +101,11 @@ void dynamic_global_property_object::restore( object& obj ) static_cast(*this) = std::move( backup ); } +void dynamic_global_property_object::clear() +{ + witness_budget.clear(); +} + class htlc_backup : public htlc_master { asset amount; @@ -124,6 +134,11 @@ void htlc_object::restore( object& obj ) static_cast(*this) = std::move( backup ); } +void htlc_object::clear() +{ + transfer.amount.clear(); +} + } } // graphene::chain FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::balance_object, (graphene::chain::balance_master), diff --git a/libraries/chain/stored_value.cpp b/libraries/chain/stored_value.cpp index a4dbb71669..7c808e46bc 100644 --- a/libraries/chain/stored_value.cpp +++ b/libraries/chain/stored_value.cpp @@ -70,8 +70,7 @@ namespace graphene { namespace chain { void stored_debt::restore( const graphene::protocol::asset& backup ) { - FC_ASSERT( _asset == backup.asset_id, "Corrupted backup: ${a} != ${b}", - ("a",_asset)("b",backup.asset_id) ); + _asset = backup.asset_id; _amount = backup.amount; } diff --git a/libraries/chain/vesting_balance_object.cpp b/libraries/chain/vesting_balance_object.cpp index f0d366118f..21ff49be04 100644 --- a/libraries/chain/vesting_balance_object.cpp +++ b/libraries/chain/vesting_balance_object.cpp @@ -299,6 +299,11 @@ void vesting_balance_object::restore( object& obj ) static_cast(*this) = std::move( backup ); } +void vesting_balance_object::clear() +{ + balance.clear(); +} + } } // graphene::chain GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::chain::linear_vesting_policy ) diff --git a/libraries/db/include/graphene/db/object.hpp b/libraries/db/include/graphene/db/object.hpp index 5ac72eb30a..b94977394d 100644 --- a/libraries/db/include/graphene/db/object.hpp +++ b/libraries/db/include/graphene/db/object.hpp @@ -80,6 +80,7 @@ namespace graphene { namespace db { virtual unique_ptr backup()const = 0; virtual void clear() {} virtual void restore( object& obj ) = 0; + friend class object_database; friend class undo_database; }; diff --git a/libraries/db/include/graphene/db/object_database.hpp b/libraries/db/include/graphene/db/object_database.hpp index 9718b70716..61bc707f5a 100644 --- a/libraries/db/include/graphene/db/object_database.hpp +++ b/libraries/db/include/graphene/db/object_database.hpp @@ -43,6 +43,7 @@ namespace graphene { namespace db { ~object_database(); void reset_indexes() { _index.clear(); _index.resize(255); } + void clear_objects(); void open(const fc::path& data_dir ); diff --git a/libraries/db/object_database.cpp b/libraries/db/object_database.cpp index 75b7090be4..889e980959 100644 --- a/libraries/db/object_database.cpp +++ b/libraries/db/object_database.cpp @@ -36,7 +36,10 @@ object_database::object_database() _undo_db.enable(); } -object_database::~object_database(){} +object_database::~object_database() +{ + clear_objects(); +} void object_database::close() { @@ -124,6 +127,25 @@ void object_database::open(const fc::path& data_dir) } FC_CAPTURE_AND_RETHROW( (data_dir) ) } +void object_database::clear_objects() +{ + bool undo_was_enabled = _undo_db.enabled(); + _undo_db.disable(); + std::vector> tasks; + tasks.reserve(200); + for( uint32_t space = 0; space < _index.size(); ++space ) + for( uint32_t type = 0; type < _index[space].size(); ++type ) + if( _index[space][type] ) + tasks.push_back( fc::do_parallel( [this,space,type] () { + auto& index = _index[space][type]; + index->inspect_all_objects( [&index] ( const graphene::db::object& object ) { + index->modify( object, [] (graphene::db::object& o) { o.clear(); } ); + }); + } ) ); + for( auto& task : tasks ) + task.wait(); + if( undo_was_enabled ) _undo_db.enable(); +} void object_database::pop_undo() { try { diff --git a/libraries/db/undo_database.cpp b/libraries/db/undo_database.cpp index 64c5886e4f..970dd85158 100644 --- a/libraries/db/undo_database.cpp +++ b/libraries/db/undo_database.cpp @@ -126,7 +126,7 @@ void undo_database::undo() _db.get_mutable_index( item.first.space(), item.first.type() ).set_next_id( item.second ); for( auto& item : state.removed ) - _db.insert( std::move(*item.second) ); + _db.insert( std::move(*item.second) ); // FIXME _stack.pop_back(); enable(); @@ -194,13 +194,11 @@ void undo_database::merge() if( prev_state.new_ids.find(obj.second->id) != prev_state.new_ids.end() ) { // new+upd -> new, type A - obj.second->clear(); continue; } if( prev_state.old_values.find(obj.second->id) != prev_state.old_values.end() ) { // upd(was=X) + upd(was=Y) -> upd(was=X), type A - obj.second->clear(); continue; } // del+upd -> N/A @@ -236,7 +234,6 @@ void undo_database::merge() if( prev_state.new_ids.find(obj.second->id) != prev_state.new_ids.end() ) { // new + del -> nop (type C) - obj.second->clear(); prev_state.new_ids.erase(obj.second->id); continue; } @@ -289,7 +286,7 @@ void undo_database::pop_commit() } for( auto& item : state.removed ) - _db.insert( std::move(*item.second) ); + _db.insert( std::move(*item.second) ); // FIXME _stack.pop_back(); } From 2a0a918e8f5420a3fb32bc131d057ab3b9511cbe Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 6 Dec 2019 11:40:37 +0100 Subject: [PATCH 17/59] Refactored duplicate code into common method --- .../db/include/graphene/db/undo_database.hpp | 1 + libraries/db/undo_database.cpp | 34 +++++-------------- 2 files changed, 9 insertions(+), 26 deletions(-) diff --git a/libraries/db/include/graphene/db/undo_database.hpp b/libraries/db/include/graphene/db/undo_database.hpp index 5234ac65aa..1a3bdfb91d 100644 --- a/libraries/db/include/graphene/db/undo_database.hpp +++ b/libraries/db/include/graphene/db/undo_database.hpp @@ -127,6 +127,7 @@ namespace graphene { namespace db { void undo(); void merge(); void commit(); + void _undo_last(); uint32_t _active_sessions = 0; bool _disabled = true; diff --git a/libraries/db/undo_database.cpp b/libraries/db/undo_database.cpp index 970dd85158..d878e4a1dd 100644 --- a/libraries/db/undo_database.cpp +++ b/libraries/db/undo_database.cpp @@ -110,7 +110,13 @@ void undo_database::undo() FC_ASSERT( !_disabled ); FC_ASSERT( _active_sessions > 0 ); disable(); + _undo_last(); + enable(); + --_active_sessions; +} FC_CAPTURE_AND_RETHROW() } +void undo_database::_undo_last() +{ auto& state = _stack.back(); for( auto& item : state.old_values ) _db.modify( _db.get_object( item.second->id ), [&item]( object& obj ){ obj.restore( *item.second ); } ); @@ -129,9 +135,7 @@ void undo_database::undo() _db.insert( std::move(*item.second) ); // FIXME _stack.pop_back(); - enable(); - --_active_sessions; -} FC_CAPTURE_AND_RETHROW() } +} void undo_database::merge() { @@ -266,29 +270,7 @@ void undo_database::pop_commit() disable(); try { - auto& state = _stack.back(); - - for( auto& item : state.old_values ) - { - _db.modify( _db.get_object( item.second->id ), [&item]( object& obj ){ obj.restore( *item.second ); } ); - } - - for( auto ritr = state.new_ids.begin(); ritr != state.new_ids.end(); ++ritr ) - { - const auto& obj = _db.get_object(*ritr); - _db.modify( obj, [] ( object& o ) { o.clear(); } ); - _db.remove( obj ); - } - - for( auto& item : state.old_index_next_ids ) - { - _db.get_mutable_index( item.first.space(), item.first.type() ).set_next_id( item.second ); - } - - for( auto& item : state.removed ) - _db.insert( std::move(*item.second) ); // FIXME - - _stack.pop_back(); + _undo_last(); } catch ( const fc::exception& e ) { From 88b3371f3b48ba46fdcb58f3f02107f42099bccb Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 6 Dec 2019 11:56:08 +0100 Subject: [PATCH 18/59] Removed unused annotated_object --- libraries/db/include/graphene/db/object.hpp | 28 --------------------- 1 file changed, 28 deletions(-) diff --git a/libraries/db/include/graphene/db/object.hpp b/libraries/db/include/graphene/db/object.hpp index b94977394d..c224fb2b69 100644 --- a/libraries/db/include/graphene/db/object.hpp +++ b/libraries/db/include/graphene/db/object.hpp @@ -111,33 +111,6 @@ namespace graphene { namespace db { typedef flat_map annotation_map; - /** - * @class annotated_object - * @brief An object that is easily extended by providing pointers to other objects, one for each space. - */ - template - class annotated_object : public abstract_object - { - public: - /** return object_id_type() if no anotation is found for id_space */ - object_id_type get_annotation( uint8_t annotation_id_space )const - { - auto itr = annotations.find(annotation_id_space); - if( itr != annotations.end() ) return itr->second; - return object_id_type(); - } - void set_annotation( object_id_type id ) - { - annotations[id.space()] = id; - } - - /** - * Annotations should be accessed via get_annotation and set_annotation so - * that they can be maintained in sorted order. - */ - annotation_map annotations; - }; - } } // graphene::db // Without this, pack(object_id) tries to match the template for @@ -149,4 +122,3 @@ struct is_restricted_conversion : public mpl::true_ {}; FC_REFLECT_TYPENAME( graphene::db::annotation_map ) FC_REFLECT( graphene::db::object, (id) ) -FC_REFLECT_DERIVED_TEMPLATE( (typename Derived), graphene::db::annotated_object, (graphene::db::object), (annotations) ) From b988d16eaa0a6ea46a8ab5cbd3931946633d9bf3 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 6 Dec 2019 16:18:57 +0100 Subject: [PATCH 19/59] Fixed undo --- libraries/chain/account_object.cpp | 9 +++++++-- libraries/chain/asset_object.cpp | 6 ++++-- libraries/chain/fba_object.cpp | 2 +- libraries/chain/market_object.cpp | 11 +++++++---- libraries/chain/small_objects.cpp | 8 +++++--- libraries/chain/vesting_balance_object.cpp | 4 +++- libraries/db/include/graphene/db/object.hpp | 3 +++ libraries/db/include/graphene/db/undo_database.hpp | 13 +++++++++++++ libraries/db/undo_database.cpp | 6 +++++- 9 files changed, 48 insertions(+), 14 deletions(-) diff --git a/libraries/chain/account_object.cpp b/libraries/chain/account_object.cpp index 75c2745d4c..13685144f1 100644 --- a/libraries/chain/account_object.cpp +++ b/libraries/chain/account_object.cpp @@ -56,11 +56,15 @@ stored_value account_balance_object::reduce_balance( share_type delta ) return balance.split( delta ); } -class account_balance_backup : public account_balance_master +class account_balance_backup + : public account_balance_master, public backup_object { asset balance; friend class account_balance_object; + protected: + using backup_object::recreate; + public: account_balance_backup( const account_balance_object& original ) : account_balance_master( original ) @@ -146,7 +150,8 @@ void account_statistics_object::pay_fee( stored_value&& core_fee, share_type cas pending_vested_fees += std::move( core_fee ); } -class account_statistics_backup : public account_statistics_master +class account_statistics_backup + : public account_statistics_master, public backup_object { share_type pending_fees; share_type pending_vested_fees; diff --git a/libraries/chain/asset_object.cpp b/libraries/chain/asset_object.cpp index cc0240de2e..27d09355da 100644 --- a/libraries/chain/asset_object.cpp +++ b/libraries/chain/asset_object.cpp @@ -30,7 +30,8 @@ namespace graphene { namespace chain { -class asset_dynamic_data_backup : public asset_dynamic_data_master +class asset_dynamic_data_backup + : public asset_dynamic_data_master, public backup_object { asset current_supply; share_type accumulated_fees; @@ -147,7 +148,8 @@ void graphene::chain::asset_bitasset_data_master::update_median_feeds( time_poin current_maintenance_collateralization = current_feed.maintenance_collateralization(); } -class asset_bitasset_data_backup : public asset_bitasset_data_master +class asset_bitasset_data_backup + : public asset_bitasset_data_master, public graphene::db::backup_object { share_type settlement_fund; share_type total_debt; diff --git a/libraries/chain/fba_object.cpp b/libraries/chain/fba_object.cpp index d41b85f9ed..7824d33f3c 100644 --- a/libraries/chain/fba_object.cpp +++ b/libraries/chain/fba_object.cpp @@ -100,7 +100,7 @@ bool fba_accumulator_master::is_configured( const database& db )const return true; } -class fba_accumulator_backup : public fba_accumulator_master +class fba_accumulator_backup : public fba_accumulator_master, public backup_object { share_type accumulated_fba_fees; friend class fba_accumulator_object; diff --git a/libraries/chain/market_object.cpp b/libraries/chain/market_object.cpp index 823e6bdba1..fc0a0f3d25 100644 --- a/libraries/chain/market_object.cpp +++ b/libraries/chain/market_object.cpp @@ -22,6 +22,7 @@ * THE SOFTWARE. */ #include +#include #include @@ -31,7 +32,7 @@ namespace graphene { namespace chain { -class limit_order_backup : public limit_order_master +class limit_order_backup : public limit_order_master, public graphene::db::backup_object { share_type for_sale; share_type deferred_fee; @@ -341,7 +342,7 @@ share_type call_order_object::get_max_debt_to_cover( price match_price, } FC_CAPTURE_AND_RETHROW( (*this)(feed_price)(match_price)(maintenance_collateral_ratio) ) } -class call_order_backup : public call_order_master +class call_order_backup : public call_order_master, public graphene::db::backup_object { asset debt; asset collateral; @@ -375,7 +376,8 @@ void call_order_object::clear() collateral.clear(); } -class force_settlement_backup : public force_settlement_master +class force_settlement_backup + : public force_settlement_master, public graphene::db::backup_object { asset balance; friend class force_settlement_object; @@ -405,7 +407,8 @@ void force_settlement_object::clear() balance.clear(); } -class collateral_bid_backup : public collateral_bid_master +class collateral_bid_backup + : public collateral_bid_master, public graphene::db::backup_object { asset collateral_offered; friend class collateral_bid_object; diff --git a/libraries/chain/small_objects.cpp b/libraries/chain/small_objects.cpp index 45d9b754b2..b8d231dca0 100644 --- a/libraries/chain/small_objects.cpp +++ b/libraries/chain/small_objects.cpp @@ -41,12 +41,13 @@ #include #include #include +#include #include namespace graphene { namespace chain { -class balance_backup : public balance_master +class balance_backup : public balance_master, public graphene::db::backup_object { asset balance; friend class balance_object; @@ -76,7 +77,8 @@ void balance_object::clear() balance.clear(); } -class dynamic_global_property_backup : public dynamic_global_property_master +class dynamic_global_property_backup + : public dynamic_global_property_master, public graphene::db::backup_object { asset witness_budget; friend class dynamic_global_property_object; @@ -106,7 +108,7 @@ void dynamic_global_property_object::clear() witness_budget.clear(); } -class htlc_backup : public htlc_master +class htlc_backup : public htlc_master, public graphene::db::backup_object { asset amount; transfer_info_master transfer; diff --git a/libraries/chain/vesting_balance_object.cpp b/libraries/chain/vesting_balance_object.cpp index 21ff49be04..52d4253145 100644 --- a/libraries/chain/vesting_balance_object.cpp +++ b/libraries/chain/vesting_balance_object.cpp @@ -23,6 +23,7 @@ */ #include +#include #include @@ -274,7 +275,8 @@ asset vesting_balance_object::get_allowed_withdraw(const time_point_sec& now)con return vesting_balance_master::get_allowed_withdraw( balance.get_value(), now ); } -class vesting_balance_backup : public vesting_balance_master +class vesting_balance_backup + : public vesting_balance_master, public graphene::db::backup_object { asset balance; friend class vesting_balance_object; diff --git a/libraries/db/include/graphene/db/object.hpp b/libraries/db/include/graphene/db/object.hpp index c224fb2b69..3297edf103 100644 --- a/libraries/db/include/graphene/db/object.hpp +++ b/libraries/db/include/graphene/db/object.hpp @@ -80,6 +80,7 @@ namespace graphene { namespace db { virtual unique_ptr backup()const = 0; virtual void clear() {} virtual void restore( object& obj ) = 0; + virtual object* recreate() = 0; friend class object_database; friend class undo_database; }; @@ -104,6 +105,8 @@ namespace graphene { namespace db { { static_cast(*this) = std::move( static_cast(obj) ); } + + virtual object* recreate() { return this; } public: virtual variant to_variant()const { return variant( static_cast(*this), MAX_NESTING ); } virtual vector pack()const { return fc::raw::pack( static_cast(*this) ); } diff --git a/libraries/db/include/graphene/db/undo_database.hpp b/libraries/db/include/graphene/db/undo_database.hpp index 1a3bdfb91d..70f6683497 100644 --- a/libraries/db/include/graphene/db/undo_database.hpp +++ b/libraries/db/include/graphene/db/undo_database.hpp @@ -136,4 +136,17 @@ namespace graphene { namespace db { size_t _max_size = 256; }; + template + class backup_object + { + std::unique_ptr tmp; + protected: + virtual object* recreate() + { + if( !tmp ) + tmp = std::make_unique(); + return tmp.get(); + } + friend class undo_database; + }; } } // graphene::db diff --git a/libraries/db/undo_database.cpp b/libraries/db/undo_database.cpp index d878e4a1dd..0feca7eb99 100644 --- a/libraries/db/undo_database.cpp +++ b/libraries/db/undo_database.cpp @@ -132,7 +132,11 @@ void undo_database::_undo_last() _db.get_mutable_index( item.first.space(), item.first.type() ).set_next_id( item.second ); for( auto& item : state.removed ) - _db.insert( std::move(*item.second) ); // FIXME + { + object* tmp = item.second->recreate(); + tmp->restore( *item.second ); + _db.insert( std::move(*tmp) ); + } _stack.pop_back(); } From 53171e32b9ce313daaaf460d2f4aaed43aee4c1c Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 6 Dec 2019 16:20:59 +0100 Subject: [PATCH 20/59] Allow non-zero balance during exception handling (assume stack is being rolled back) --- libraries/chain/stored_value.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/chain/stored_value.cpp b/libraries/chain/stored_value.cpp index 7c808e46bc..bc21087d29 100644 --- a/libraries/chain/stored_value.cpp +++ b/libraries/chain/stored_value.cpp @@ -31,7 +31,8 @@ namespace graphene { namespace chain { stored_debt::~stored_debt() { - FC_ASSERT( _amount == 0, "Value leak detected: (${n],${a])!", ("n",_amount.value)("a",_asset) ); + FC_ASSERT( _amount == 0 || std::current_exception() // should check for enabled undo_db in case of exception + , "Value leak detected: (${n],${a])!", ("n",_amount.value)("a",_asset) ); } stored_debt::stored_debt( stored_debt&& move ) From c728899828472ef746bd20753f2bab05204eaf55 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 10 Dec 2019 17:56:07 +0100 Subject: [PATCH 21/59] Fixups --- libraries/chain/db_maint.cpp | 2 +- libraries/chain/db_market.cpp | 2 +- libraries/chain/include/graphene/chain/stored_value.hpp | 2 +- libraries/chain/vesting_balance_evaluator.cpp | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 810d93af60..6e11825764 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -577,7 +577,7 @@ void update_top_n_authorities( database& db ) const auto range = bal_idx.equal_range( boost::make_tuple( tha.asset ) ); for( const account_balance_object& bal : boost::make_iterator_range( range.first, range.second ) ) { - assert( bal.asset_type == tha.asset ); + assert( bal.get_asset() == tha.asset ); if( bal.owner == acct.id ) continue; vc.add( bal.owner, bal.get_amount().value ); diff --git a/libraries/chain/db_market.cpp b/libraries/chain/db_market.cpp index 03df5f1618..2378a6290a 100644 --- a/libraries/chain/db_market.cpp +++ b/libraries/chain/db_market.cpp @@ -949,7 +949,7 @@ void database::fill_settle_order( const force_settlement_object& settle, const a add_balance( settle.owner, std::move(receives) ); - assert( paid.asset_id != receives.asset_id ); + assert( paid.asset_id != receives.get_asset() ); push_applied_operation( fill_order_operation( settle.id, settle.owner, paid, received, issuer_fees, fill_price, false ) ); if( settle.balance.get_amount() == 0 ) diff --git a/libraries/chain/include/graphene/chain/stored_value.hpp b/libraries/chain/include/graphene/chain/stored_value.hpp index c57b414fc7..ec3810aee9 100644 --- a/libraries/chain/include/graphene/chain/stored_value.hpp +++ b/libraries/chain/include/graphene/chain/stored_value.hpp @@ -50,7 +50,7 @@ namespace graphene { namespace chain { void burn( stored_value&& amount ); template< typename Stream > - void unpack( Stream s, uint32_t _max_depth ) + void unpack( Stream& s, uint32_t _max_depth ) { graphene::protocol::asset amount; fc::raw::unpack( s, amount, _max_depth ); diff --git a/libraries/chain/vesting_balance_evaluator.cpp b/libraries/chain/vesting_balance_evaluator.cpp index f9fc356de9..47766525f9 100644 --- a/libraries/chain/vesting_balance_evaluator.cpp +++ b/libraries/chain/vesting_balance_evaluator.cpp @@ -115,7 +115,7 @@ void_result vesting_balance_withdraw_evaluator::do_evaluate( const vesting_balan const vesting_balance_object& vbo = op.vesting_balance( d ); FC_ASSERT( op.owner == vbo.owner, "", ("op.owner", op.owner)("vbo.owner", vbo.owner) ); FC_ASSERT( vbo.is_withdraw_allowed( now, op.amount ), "", ("now", now)("op", op)("vbo", vbo) ); - assert( op.amount <= vbo.balance ); // is_withdraw_allowed should fail before this check is reached + assert( op.amount <= vbo.balance.get_value() ); // is_withdraw_allowed should fail before this check is reached /* const account_object& owner_account = */ op.owner( d ); // TODO: Check asset authorizations and withdrawals From 6a7ce5f37bc5dcae0bbecc52f2431a1657ba7762 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 10 Dec 2019 19:00:36 +0100 Subject: [PATCH 22/59] fixup object::restore --- libraries/db/include/graphene/db/object.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/db/include/graphene/db/object.hpp b/libraries/db/include/graphene/db/object.hpp index 3297edf103..2ac1e8e8a9 100644 --- a/libraries/db/include/graphene/db/object.hpp +++ b/libraries/db/include/graphene/db/object.hpp @@ -103,7 +103,8 @@ namespace graphene { namespace db { virtual void restore( object& obj ) { - static_cast(*this) = std::move( static_cast(obj) ); + if( this != &obj ) + static_cast(*this) = std::move( static_cast(obj) ); } virtual object* recreate() { return this; } From c07fb096c88dd6d71c630db1960acb8cc8d9e365 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 10 Dec 2019 19:00:54 +0100 Subject: [PATCH 23/59] Fixup balance claim --- libraries/chain/balance_evaluator.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libraries/chain/balance_evaluator.cpp b/libraries/chain/balance_evaluator.cpp index 030c4065c2..fd5d71ffe7 100644 --- a/libraries/chain/balance_evaluator.cpp +++ b/libraries/chain/balance_evaluator.cpp @@ -78,7 +78,8 @@ void_result balance_claim_evaluator::do_apply(const balance_claim_operation& op) stored_value claim; d.modify(*balance, [&claim,&d,&op](balance_object& b) { - b.vesting_policy->on_withdraw({b.balance.get_value(), d.head_block_time(), op.total_claimed}); + if( b.is_vesting_balance() ) + b.vesting_policy->on_withdraw({b.balance.get_value(), d.head_block_time(), op.total_claimed}); claim = b.balance.split( op.total_claimed.amount ); b.last_claim_date = d.head_block_time(); }); From e5127feedf635c2fffb175c6a9b21f00ac861763 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 10 Dec 2019 19:01:09 +0100 Subject: [PATCH 24/59] fixup recreate --- libraries/chain/account_object.cpp | 4 ++++ libraries/chain/asset_object.cpp | 4 ++++ libraries/chain/fba_object.cpp | 2 ++ libraries/chain/market_object.cpp | 8 ++++++++ libraries/chain/small_objects.cpp | 8 ++++++++ libraries/chain/vesting_balance_object.cpp | 2 ++ 6 files changed, 28 insertions(+) diff --git a/libraries/chain/account_object.cpp b/libraries/chain/account_object.cpp index 13685144f1..eaf907be0a 100644 --- a/libraries/chain/account_object.cpp +++ b/libraries/chain/account_object.cpp @@ -71,6 +71,8 @@ class account_balance_backup { balance = original.balance.get_value(); } + + virtual object* recreate() { return graphene::db::backup_object::recreate(); } }; unique_ptr account_balance_object::backup()const @@ -164,6 +166,8 @@ class account_statistics_backup pending_fees = original.pending_fees.get_amount(); pending_vested_fees = original.pending_vested_fees.get_amount(); } + + virtual object* recreate() { return graphene::db::backup_object::recreate(); } }; unique_ptr account_statistics_object::backup()const diff --git a/libraries/chain/asset_object.cpp b/libraries/chain/asset_object.cpp index 27d09355da..f937e260f8 100644 --- a/libraries/chain/asset_object.cpp +++ b/libraries/chain/asset_object.cpp @@ -48,6 +48,8 @@ class asset_dynamic_data_backup fee_pool = original.fee_pool.get_amount(); confidential_supply = original.confidential_supply.get_amount(); } + + virtual object* recreate() { return graphene::db::backup_object::recreate(); } }; unique_ptr asset_dynamic_data_object::backup()const @@ -162,6 +164,8 @@ class asset_bitasset_data_backup settlement_fund = original.settlement_fund.get_amount(); total_debt = original.total_debt.get_amount(); } + + virtual object* recreate() { return graphene::db::backup_object::recreate(); } }; unique_ptr asset_bitasset_data_object::backup()const diff --git a/libraries/chain/fba_object.cpp b/libraries/chain/fba_object.cpp index 7824d33f3c..f6137a79e6 100644 --- a/libraries/chain/fba_object.cpp +++ b/libraries/chain/fba_object.cpp @@ -111,6 +111,8 @@ class fba_accumulator_backup : public fba_accumulator_master, public backup_obje { accumulated_fba_fees = original.accumulated_fba_fees.get_amount(); } + + virtual object* recreate() { return graphene::db::backup_object::recreate(); } }; unique_ptr fba_accumulator_object::backup()const diff --git a/libraries/chain/market_object.cpp b/libraries/chain/market_object.cpp index fc0a0f3d25..43a0a1c768 100644 --- a/libraries/chain/market_object.cpp +++ b/libraries/chain/market_object.cpp @@ -47,6 +47,8 @@ class limit_order_backup : public limit_order_master, public graphene::db::backu deferred_fee = original.deferred_fee.get_amount(); deferred_paid_fee = original.deferred_paid_fee.get_value(); } + + virtual object* recreate() { return graphene::db::backup_object::recreate(); } }; unique_ptr limit_order_object::backup()const @@ -355,6 +357,8 @@ class call_order_backup : public call_order_master, public graphene::db::backup_ debt = original.debt.get_amount(); collateral = original.collateral.get_amount(); } + + virtual object* recreate() { return graphene::db::backup_object::recreate(); } }; unique_ptr call_order_object::backup()const @@ -388,6 +392,8 @@ class force_settlement_backup { balance = original.balance.get_amount(); } + + virtual object* recreate() { return graphene::db::backup_object::recreate(); } }; unique_ptr force_settlement_object::backup()const @@ -419,6 +425,8 @@ class collateral_bid_backup { collateral_offered = original.collateral_offered.get_value(); } + + virtual object* recreate() { return graphene::db::backup_object::recreate(); } }; unique_ptr collateral_bid_object::backup()const diff --git a/libraries/chain/small_objects.cpp b/libraries/chain/small_objects.cpp index b8d231dca0..bc9ab9aaad 100644 --- a/libraries/chain/small_objects.cpp +++ b/libraries/chain/small_objects.cpp @@ -58,6 +58,8 @@ class balance_backup : public balance_master, public graphene::db::backup_object { balance = original.balance.get_value(); } + + virtual object* recreate() { return graphene::db::backup_object::recreate(); } }; unique_ptr balance_object::backup()const @@ -89,6 +91,10 @@ class dynamic_global_property_backup { witness_budget = original.witness_budget.get_value(); } + + virtual object* recreate() { + return graphene::db::backup_object::recreate(); + } }; unique_ptr dynamic_global_property_object::backup()const @@ -121,6 +127,8 @@ class htlc_backup : public htlc_master, public graphene::db::backup_object::recreate(); } }; unique_ptr htlc_object::backup()const diff --git a/libraries/chain/vesting_balance_object.cpp b/libraries/chain/vesting_balance_object.cpp index 52d4253145..72e4eadd9e 100644 --- a/libraries/chain/vesting_balance_object.cpp +++ b/libraries/chain/vesting_balance_object.cpp @@ -287,6 +287,8 @@ class vesting_balance_backup { balance = original.balance.get_value(); } + + virtual object* recreate() { return graphene::db::backup_object::recreate(); } }; unique_ptr vesting_balance_object::backup()const From 25737fff734cafca3bc35bfa47b54ec4768aa17d Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 10 Dec 2019 19:01:51 +0100 Subject: [PATCH 25/59] Fixed initial testing balance --- tests/common/database_fixture.cpp | 20 ++++++++++++++++--- tests/tests/block_tests.cpp | 32 ++++++++++++++++++++++--------- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 3d35b6f11a..068cfb2499 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -113,10 +113,14 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) init_account_priv_key.get_public_key(), true); genesis_state.initial_committee_candidates.push_back({name}); - genesis_state.initial_witness_candidates.push_back({name, init_account_priv_key.get_public_key()}); + genesis_state.initial_witness_candidates.push_back({name, init_account_pub_key}); } genesis_state.initial_parameters.get_mutable_fees().zero_all_fees(); + genesis_state_type::initial_balance_type initial_core{ address(init_account_pub_key), GRAPHENE_SYMBOL, + GRAPHENE_MAX_SHARE_SUPPLY }; + genesis_state.initial_balances.push_back(initial_core); + genesis_state_type::initial_asset_type init_mpa1; init_mpa1.symbol = "INITMPA"; init_mpa1.issuer_name = "committee-account"; @@ -359,11 +363,22 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) generate_block(); + set_expiration( db, trx ); + + { + balance_claim_operation bop; + bop.balance_owner_key = init_account_pub_key; + bop.total_claimed = asset( GRAPHENE_MAX_SHARE_SUPPLY ); + trx.clear(); + trx.operations.emplace_back(bop); + PUSH_TX(db, trx, ~0); + trx.operations.clear(); + } + asset_id_type mpa1_id(1); BOOST_REQUIRE( mpa1_id(db).is_market_issued() ); BOOST_CHECK( mpa1_id(db).bitasset_data(db).asset_id == mpa1_id ); - set_expiration( db, trx ); } catch ( const fc::exception& e ) { edump( (e.to_detail_string()) ); @@ -383,7 +398,6 @@ database_fixture::~database_fixture() verify_asset_supplies(db); BOOST_CHECK( db.get_node_properties().skip_flags == database::skip_nothing ); } - return; } catch (fc::exception& ex) { BOOST_FAIL( std::string("fc::exception in ~database_fixture: ") + ex.to_detail_string() ); } catch (std::exception& e) { diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 31a2799823..c4c3ac2941 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -51,6 +51,7 @@ genesis_state_type make_genesis() { genesis_state.initial_timestamp = time_point_sec( GRAPHENE_TESTING_GENESIS_TIMESTAMP ); auto init_account_priv_key = fc::ecc::private_key::regenerate(fc::sha256::hash(string("null_key"))); + const public_key_type init_account_pub_key = init_account_priv_key.get_public_key(); genesis_state.initial_active_witnesses = 10; genesis_state.immutable_parameters.min_committee_member_count = INITIAL_COMMITTEE_MEMBER_COUNT; genesis_state.immutable_parameters.min_witness_count = INITIAL_WITNESS_COUNT; @@ -58,14 +59,14 @@ genesis_state_type make_genesis() { for( unsigned int i = 0; i < genesis_state.initial_active_witnesses; ++i ) { auto name = "init"+fc::to_string(i); - genesis_state.initial_accounts.emplace_back(name, - init_account_priv_key.get_public_key(), - init_account_priv_key.get_public_key(), - true); + genesis_state.initial_accounts.emplace_back(name, init_account_pub_key, init_account_pub_key, true); genesis_state.initial_committee_candidates.push_back({name}); - genesis_state.initial_witness_candidates.push_back({name, init_account_priv_key.get_public_key()}); + genesis_state.initial_witness_candidates.push_back({name, init_account_pub_key}); } genesis_state.initial_parameters.get_mutable_fees().zero_all_fees(); + genesis_state_type::initial_balance_type initial_core{ address(init_account_pub_key), GRAPHENE_SYMBOL, + GRAPHENE_MAX_SHARE_SUPPLY }; + genesis_state.initial_balances.push_back(initial_core); return genesis_state; } @@ -583,6 +584,11 @@ BOOST_AUTO_TEST_CASE( undo_pending ) signed_transaction trx; set_expiration( db, trx ); + balance_claim_operation bop; + bop.balance_owner_key = init_account_pub_key; + bop.total_claimed = asset( GRAPHENE_MAX_SHARE_SUPPLY ); + trx.operations.push_back(bop); + trx.operations.push_back(t); PUSH_TX( db, trx, ~0 ); @@ -706,6 +712,12 @@ BOOST_AUTO_TEST_CASE( duplicate_transactions ) signed_transaction trx; set_expiration( db1, trx ); + + balance_claim_operation bop; + bop.balance_owner_key = init_account_pub_key; + bop.total_claimed = asset( GRAPHENE_MAX_SHARE_SUPPLY ); + trx.operations.push_back(bop); + account_id_type nathan_id = account_idx.get_next_id(); account_create_operation cop; cop.name = "nathan"; @@ -771,10 +783,12 @@ BOOST_AUTO_TEST_CASE( tapos ) b = db1.generate_block(db1.get_slot_time(1), db1.get_scheduled_witness(1), init_account_priv_key, database::skip_nothing); trx.clear(); - transfer_operation t; - t.to = nathan_id; - t.amount = asset(50); - trx.operations.push_back(t); + + balance_claim_operation bop; + bop.deposit_to_account = nathan_id; + bop.balance_owner_key = init_account_pub_key; + bop.total_claimed = asset( GRAPHENE_MAX_SHARE_SUPPLY ); + trx.operations.push_back(bop); trx.sign( init_account_priv_key, db1.get_chain_id() ); //relative_expiration is 1, but ref block is 2 blocks old, so this should fail. GRAPHENE_REQUIRE_THROW(PUSH_TX( db1, trx, database::skip_transaction_signatures ), fc::exception); From 1ecb7442a284b51269925d218d4067cf33b25abc Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 12 Dec 2019 16:35:49 +0100 Subject: [PATCH 26/59] Fixup call_order backup --- libraries/chain/market_object.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/chain/market_object.cpp b/libraries/chain/market_object.cpp index 43a0a1c768..7ad7334062 100644 --- a/libraries/chain/market_object.cpp +++ b/libraries/chain/market_object.cpp @@ -354,8 +354,8 @@ class call_order_backup : public call_order_master, public graphene::db::backup_ call_order_backup( const call_order_object& original ) : call_order_master( original ) { - debt = original.debt.get_amount(); - collateral = original.collateral.get_amount(); + debt = original.debt.get_value(); + collateral = original.collateral.get_value(); } virtual object* recreate() { return graphene::db::backup_object::recreate(); } From b956066fb31df3fbd4a2b73505ecb8157c00944d Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 12 Dec 2019 16:36:07 +0100 Subject: [PATCH 27/59] Fixup asset object initialization --- libraries/chain/asset_evaluator.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index 01e2984f21..991bf2982f 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -106,25 +106,30 @@ object_id_type asset_create_evaluator::do_apply( const asset_create_operation& o { try { database& d = db(); + const auto next_asset_id = d.get_index_type().get_next_id(); + if( (core_fee_paid.get_amount().value & 1) && d.head_block_time() <= HARDFORK_CORE_429_TIME ) d.modify( d.get_core_dynamic_data(), [this]( asset_dynamic_data_object& dd ) { for_pool += dd.current_supply.issue(1); }); const asset_dynamic_data_object& dyn_asset = - d.create( [this]( asset_dynamic_data_object& a ) { + d.create( [this,next_asset_id]( asset_dynamic_data_object& a ) { + a.current_supply = stored_debt(next_asset_id); + a.accumulated_fees = stored_value(next_asset_id); a.fee_pool = std::move(for_pool); + a.confidential_supply = stored_value(next_asset_id); }); asset_bitasset_data_id_type bit_asset_id; - auto next_asset_id = d.get_index_type().get_next_id(); - if( op.bitasset_opts.valid() ) bit_asset_id = d.create( [&op,next_asset_id]( asset_bitasset_data_object& a ) { a.options = *op.bitasset_opts; a.is_prediction_market = op.is_prediction_market; a.asset_id = next_asset_id; + a.total_debt = stored_value(next_asset_id); + a.settlement_fund = stored_value(a.options.short_backing_asset); }).id; const asset_object& new_asset = From 2b294861b1c32b3e4c3c2f0b4c5366050f029737 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 12 Dec 2019 16:36:52 +0100 Subject: [PATCH 28/59] Fixup call_order_update evaluator --- libraries/chain/market_evaluator.cpp | 52 +++++++++++++++------------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/libraries/chain/market_evaluator.cpp b/libraries/chain/market_evaluator.cpp index 8c2f86bb42..ce771595a9 100644 --- a/libraries/chain/market_evaluator.cpp +++ b/libraries/chain/market_evaluator.cpp @@ -224,27 +224,28 @@ object_id_type call_order_update_evaluator::do_apply(const call_order_update_ope { try { database& d = db(); - stored_value transport; + stored_value transport_debt; if( o.delta_debt.amount > 0 ) { // Deduct the debt paid from the total supply of the debt asset. - d.modify(*_dynamic_data_obj, [&o,&transport](asset_dynamic_data_object& dynamic_asset) { - transport = dynamic_asset.current_supply.issue( o.delta_debt.amount ); + d.modify(*_dynamic_data_obj, [&o,&transport_debt](asset_dynamic_data_object& dynamic_asset) { + transport_debt = dynamic_asset.current_supply.issue( o.delta_debt.amount ); }); - d.add_balance( o.funding_account, std::move(transport) ); + d.add_balance( o.funding_account, std::move(transport_debt) ); } else if( o.delta_debt.amount < 0 ) { - transport = d.reduce_balance( o.funding_account, -o.delta_debt ); + transport_debt = d.reduce_balance( o.funding_account, -o.delta_debt ); // Deduct the debt paid from the total supply of the debt asset. - d.modify(*_dynamic_data_obj, [&o,&transport](asset_dynamic_data_object& dynamic_asset) { - dynamic_asset.current_supply.burn( std::move(transport) ); + d.modify(*_dynamic_data_obj, [&o,&transport_debt](asset_dynamic_data_object& dynamic_asset) { + dynamic_asset.current_supply.burn( std::move(transport_debt) ); }); } + stored_value transport_collateral; if( o.delta_collateral.amount > 0 ) { - transport = d.reduce_balance( o.funding_account, o.delta_collateral ); + transport_collateral = d.reduce_balance( o.funding_account, o.delta_collateral ); // Adjust the total core in orders accodingly if( o.delta_collateral.asset_id == asset_id_type() ) @@ -269,11 +270,12 @@ object_id_type call_order_update_evaluator::do_apply(const call_order_update_ope FC_ASSERT( o.delta_collateral.amount > 0, "Delta collateral amount of new debt position should be positive" ); FC_ASSERT( o.delta_debt.amount > 0, "Delta debt amount of new debt position should be positive" ); - call_obj = &d.create( [&o,this,before_core_hardfork_1270,&transport]( call_order_object& call ){ + call_obj = &d.create( + [&o,this,before_core_hardfork_1270,&transport_debt,&transport_collateral]( call_order_object& call ){ call.borrower = o.funding_account; - call.collateral = std::move(transport); + call.collateral = std::move(transport_collateral); call.debt = stored_debt(o.delta_debt.asset_id); - transport = call.debt.issue( o.delta_debt.amount ); + transport_debt = call.debt.issue( o.delta_debt.amount ); if( before_core_hardfork_1270 ) // before core-1270 hard fork, calculate call_price here and cache it call.call_price = price::call_price( o.delta_debt, o.delta_collateral, _bitasset_data->current_feed.maintenance_collateral_ratio ); @@ -283,8 +285,8 @@ object_id_type call_order_update_evaluator::do_apply(const call_order_update_ope }); call_order_id = call_obj->id; - d.modify( *_bitasset_data, [&transport] ( asset_bitasset_data_object& bdo ) { - bdo.total_debt += std::move(transport); + d.modify( *_bitasset_data, [&transport_debt] ( asset_bitasset_data_object& bdo ) { + bdo.total_debt += std::move(transport_debt); }); } else // updating existing debt position @@ -294,20 +296,20 @@ object_id_type call_order_update_evaluator::do_apply(const call_order_update_ope old_collateralization = call_obj->collateralization(); old_debt = call_obj->debt.get_amount(); - stored_value tmp_debt; if( o.delta_debt.amount < 0 ) - d.modify( *_bitasset_data, [&o,&tmp_debt] ( asset_bitasset_data_object& bdo ) { - tmp_debt = bdo.total_debt.split( -o.delta_debt.amount ); + d.modify( *_bitasset_data, [&o,&transport_debt] ( asset_bitasset_data_object& bdo ) { + transport_debt = bdo.total_debt.split( -o.delta_debt.amount ); }); - d.modify( *call_obj, [&o,&transport,this,before_core_hardfork_1270,&tmp_debt]( call_order_object& call ){ + d.modify( *call_obj, + [&o,&transport_debt,&transport_collateral,this,before_core_hardfork_1270]( call_order_object& call ){ if( o.delta_collateral.amount > 0 ) - call.collateral += std::move(transport); + call.collateral += std::move(transport_collateral); else if( o.delta_collateral.amount < 0 ) - transport = call.collateral.split( -o.delta_collateral.amount ); + transport_collateral = call.collateral.split( -o.delta_collateral.amount ); if( o.delta_debt.amount > 0 ) - tmp_debt = call.debt.issue( o.delta_debt.amount ); + transport_debt = call.debt.issue( o.delta_debt.amount ); else if( o.delta_debt.amount < 0 ) - call.debt.burn( std::move(tmp_debt) ); + call.debt.burn( std::move(transport_debt) ); if( before_core_hardfork_1270 ) // don't update call_price after core-1270 hard fork { call.call_price = price::call_price( call.get_debt(), call.get_collateral(), @@ -315,10 +317,12 @@ object_id_type call_order_update_evaluator::do_apply(const call_order_update_ope } call.target_collateral_ratio = o.extensions.value.target_collateral_ratio; }); - if( tmp_debt.get_amount() > 0 ) - d.modify( *_bitasset_data, [&tmp_debt] ( asset_bitasset_data_object& bdo ) { - bdo.total_debt += std::move(tmp_debt); + if( transport_debt.get_amount() > 0 ) + d.modify( *_bitasset_data, [&transport_debt] ( asset_bitasset_data_object& bdo ) { + bdo.total_debt += std::move(transport_debt); }); + if( transport_collateral.get_amount() > 0 ) // negative delta_collateral + d.add_balance( o.funding_account, std::move(transport_collateral) ); if( call_obj->debt.get_amount() == 0 ) { From 6cc08235380106ecae2d61ada8a63c0b6511e1b2 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 12 Dec 2019 16:37:01 +0100 Subject: [PATCH 29/59] Fixup order matching --- libraries/chain/db_market.cpp | 101 +++++++++--------- .../chain/include/graphene/chain/database.hpp | 10 +- 2 files changed, 57 insertions(+), 54 deletions(-) diff --git a/libraries/chain/db_market.cpp b/libraries/chain/db_market.cpp index 2378a6290a..ad1fa360e4 100644 --- a/libraries/chain/db_market.cpp +++ b/libraries/chain/db_market.cpp @@ -648,12 +648,14 @@ int database::match( const limit_order_object& usd, const limit_order_object& co core_pays == core.amount_for_sale() ); int result = 0; - stored_value transport; - modify( core, [&transport,&core_pays] ( limit_order_object& loo ) { - transport = loo.for_sale.split( core_pays.amount ); + stored_value transport_core; + modify( core, [&transport_core,&core_pays] ( limit_order_object& loo ) { + transport_core = loo.for_sale.split( core_pays.amount ); }); - result |= fill_limit_order( usd, usd_pays, std::move(transport), cull_taker, match_price, false, false ); // the first param is taker - result |= fill_limit_order( core, core_pays, std::move(transport), true, match_price, true, true ) << 1; // the second param is maker + fc::optional transport_usd = stored_value(usd_pays.asset_id); + result |= fill_limit_order( usd, usd_pays, std::move(transport_core), cull_taker, match_price, transport_usd, false ); // the first param is taker + fc::optional ignore; + result |= fill_limit_order( core, core_pays, std::move(*transport_usd), true, match_price, ignore, true ) << 1; // the second param is maker FC_ASSERT( result != 0 ); return result; } @@ -699,12 +701,14 @@ int database::match( const limit_order_object& bid, const call_order_object& ask order_pays = call_receives; int result = 0; - stored_value transport; - modify( ask, [&transport,&call_pays] ( call_order_object& coo ) { - transport = coo.collateral.split( call_pays.amount ); + stored_value transport_debt; + modify( ask, [&transport_debt,&call_pays] ( call_order_object& coo ) { + transport_debt = coo.collateral.split( call_pays.amount ); }); - result |= fill_limit_order( bid, order_pays, std::move(transport), cull_taker, match_price, false, false ); // the limit order is taker - result |= fill_call_order( ask, call_pays, std::move(transport), match_price, true, true ) << 1; // the call order is maker + fc::optional transport_collateral = stored_value(order_pays.asset_id); + result |= fill_limit_order( bid, order_pays, std::move(transport_debt), cull_taker, match_price, transport_collateral, false ); // the limit order is taker + fc::optional ignore; + result |= fill_call_order( ask, call_pays, std::move(*transport_collateral), match_price, ignore, true ) << 1; // the call order is maker // result can be 0 when call order has target_collateral_ratio option set. return result; @@ -806,8 +810,9 @@ asset database::match( const call_order_object& call, modify( settle, [&transport,&settle_pays] ( force_settlement_object& fso ) { transport = fso.balance.split( settle_pays.amount ); }); - fill_call_order( call, call_pays, std::move(transport), fill_price, false, true ); // call order is maker - fill_settle_order( settle, settle_pays, std::move(transport), fill_price ); // force settlement order is always taker + fc::optional transport_debt = stored_value(); + fill_call_order( call, call_pays, std::move(transport), fill_price, transport_debt, true ); // call order is maker + fill_settle_order( settle, settle_pays, std::move(*transport_debt), fill_price ); // force settlement order is always taker if( cull_settle_order ) cancel_settle_order( settle ); @@ -815,32 +820,37 @@ asset database::match( const call_order_object& call, return call_receives; } FC_CAPTURE_AND_RETHROW( (call)(settle)(match_price)(max_settlement) ) } -bool database::fill_limit_order( const limit_order_object& order, const asset& pays, stored_value&& transport, - bool cull_if_small, const price& fill_price, bool already_paid, const bool is_maker ) +bool database::fill_limit_order( const limit_order_object& order, const asset& pays, stored_value&& receives, + bool cull_if_small, const price& fill_price, + fc::optional& transport, const bool is_maker ) { try { - const auto receives = transport.get_value(); + const auto received = receives.get_value(); cull_if_small |= (head_block_time() < HARDFORK_555_TIME); FC_ASSERT( order.amount_for_sale().asset_id == pays.asset_id ); - FC_ASSERT( pays.asset_id != receives.asset_id ); + FC_ASSERT( pays.asset_id != received.asset_id ); const account_object& seller = order.seller(*this); - const asset_object& recv_asset = receives.asset_id(*this); + const asset_object& recv_asset = received.asset_id(*this); - auto issuer_fees = pay_market_fees( &seller, recv_asset, std::move(transport) ); + auto issuer_fees = pay_market_fees( &seller, recv_asset, std::move(receives) ); + add_balance( seller.get_id(), std::move(receives) ); - push_applied_operation( fill_order_operation( order.id, order.seller, pays, receives, issuer_fees, fill_price, is_maker ) ); + push_applied_operation( fill_order_operation( order.id, order.seller, pays, received, issuer_fees, fill_price, is_maker ) ); - pay_order( seller, std::move(transport), pays ); + if( pays.asset_id == asset_id_type() ) + modify( seller.statistics(*this), [&pays]( account_statistics_object& b ){ + b.total_core_in_orders -= pays.amount; + }); stored_value deferred_fee; stored_value deferred_paid_fee; - modify( order, [&pays,&transport,&deferred_fee,&deferred_paid_fee,already_paid] ( limit_order_object& loo ) { + modify( order, [&pays,&transport,&deferred_fee,&deferred_paid_fee] ( limit_order_object& loo ) { deferred_fee = std::move(loo.deferred_fee); deferred_paid_fee = std::move(loo.deferred_paid_fee); - if( !already_paid ) - transport = loo.for_sale.split( pays.amount ); + if( transport.valid() ) + *transport = loo.for_sale.split( pays.amount ); }); // conditional because cheap integer comparison may allow us to avoid two expensive modify() and object lookups if( deferred_fee.get_amount() > 0 ) @@ -869,39 +879,39 @@ bool database::fill_limit_order( const limit_order_object& order, const asset& p return maybe_cull_small_order( *this, order ); return false; -} FC_CAPTURE_AND_RETHROW( (order)(pays)(transport) ) } +} FC_CAPTURE_AND_RETHROW( (order)(pays)(receives.get_value()) ) } -bool database::fill_call_order( const call_order_object& order, const asset& pays, stored_value&& transport, - const price& fill_price, bool already_paid, const bool is_maker ) +bool database::fill_call_order( const call_order_object& order, const asset& pays, stored_value&& receives, + const price& fill_price, fc::optional& transport, + const bool is_maker ) { try { - const auto receives = transport.get_value(); + const asset received = receives.get_value(); - FC_ASSERT( order.debt_type() == receives.asset_id ); + FC_ASSERT( order.debt_type() == receives.get_asset() ); FC_ASSERT( order.collateral_type() == pays.asset_id ); FC_ASSERT( order.collateral.get_amount() >= pays.amount ); // TODO pass in mia and bitasset_data for better performance - const asset_object& mia = receives.asset_id(*this); + const asset_object& mia = receives.get_asset()(*this); FC_ASSERT( mia.is_market_issued() ); - stored_value supply_to_burn = std::move(transport); // update current supply const asset_dynamic_data_object& mia_ddo = mia.dynamic_asset_data_id(*this); - modify( mia_ddo, [&supply_to_burn]( asset_dynamic_data_object& ao ){ - ao.current_supply.burn( std::move(supply_to_burn) ); + modify( mia_ddo, [&receives]( asset_dynamic_data_object& ao ){ + ao.current_supply.burn( std::move(receives) ); }); stored_value debt_to_burn; const auto& bdo = (*mia.bitasset_data_id)(*this); - modify( bdo, [&receives,&debt_to_burn] ( asset_bitasset_data_object& _bdo ) { - debt_to_burn = _bdo.total_debt.split( receives.amount ); + modify( bdo, [&received,&debt_to_burn] ( asset_bitasset_data_object& _bdo ) { + debt_to_burn = _bdo.total_debt.split( received.amount ); }); stored_value collateral_freed( order.collateral_type() ); - modify( order, [&bdo,&pays,&debt_to_burn,&transport,&collateral_freed,already_paid,this]( call_order_object& o ){ + modify( order, [&bdo,&pays,&debt_to_burn,&transport,&collateral_freed,this]( call_order_object& o ){ o.debt.burn( std::move(debt_to_burn) ); - if( !already_paid ) + if( transport.valid() ) transport = o.collateral.split( pays.amount ); if( o.debt.get_amount() == 0 ) collateral_freed = std::move( o.collateral ); @@ -930,7 +940,7 @@ bool database::fill_call_order( const call_order_object& order, const asset& pay // Adjust balance add_balance( order.borrower, std::move(collateral_freed) ); - push_applied_operation( fill_order_operation( order.id, order.borrower, pays, receives, + push_applied_operation( fill_order_operation( order.id, order.borrower, pays, received, asset(0, pays.asset_id), fill_price, is_maker ) ); bool filled = order.collateral.get_amount() == 0; @@ -1151,7 +1161,9 @@ bool database::check_call_orders( const asset_object& mia, bool enable_black_swa transport = loo.for_sale.split(order_pays.amount); }); // when for_new_limit_order is true, the call order is maker, otherwise the call order is taker - fill_call_order( call_order, call_pays, std::move(transport), match_price, false, for_new_limit_order ); + fc::optional transport_debt = stored_value(); + fill_call_order( call_order, call_pays, std::move(transport), match_price, transport_debt, + for_new_limit_order ); if( !before_core_hardfork_1270 ) call_collateral_itr = call_collateral_index.lower_bound( call_min ); else if( !before_core_hardfork_343 ) @@ -1159,7 +1171,9 @@ bool database::check_call_orders( const asset_object& mia, bool enable_black_swa auto next_limit_itr = std::next( limit_itr ); // when for_new_limit_order is true, the limit order is taker, otherwise the limit order is maker - bool really_filled = fill_limit_order( limit_order, order_pays, std::move(transport), true, match_price, true, !for_new_limit_order ); + fc::optional ignore; + bool really_filled = fill_limit_order( limit_order, order_pays, std::move(*transport_debt), true, + match_price, ignore, !for_new_limit_order ); if( really_filled || ( filled_limit && before_core_hardfork_453 ) ) limit_itr = next_limit_itr; @@ -1168,15 +1182,6 @@ bool database::check_call_orders( const asset_object& mia, bool enable_black_swa return margin_called; } FC_CAPTURE_AND_RETHROW() } -void database::pay_order( const account_object& receiver, stored_value&& receives, const asset& pays ) -{ - if( receives.get_asset() == asset_id_type() ) - modify( receiver.statistics(*this), [&pays]( account_statistics_object& b ){ - b.total_core_in_orders -= pays.amount; - }); - add_balance( receiver.get_id(), std::move(receives) ); -} - share_type database::calculate_market_fee( const asset_object& trade_asset, const share_type trade_amount ) { if( !trade_asset.charges_market_fees() ) diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index 7c828cf4b3..18a221c258 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -408,10 +408,10 @@ namespace graphene { namespace chain { /** * @return true if the order was completely filled and thus freed. */ - bool fill_limit_order( const limit_order_object& order, const asset& pays, stored_value&& transport, - bool cull_if_small, const price& fill_price, bool already_paid, const bool is_maker ); - bool fill_call_order( const call_order_object& order, const asset& pays, stored_value&& transport, - const price& fill_price, bool already_paid, const bool is_maker ); + bool fill_limit_order( const limit_order_object& order, const asset& pays, stored_value&& receives, + bool cull_if_small, const price& fill_price, fc::optional& transport, const bool is_maker ); + bool fill_call_order( const call_order_object& order, const asset& pays, stored_value&& receives, + const price& fill_price, fc::optional& transport_debt, const bool is_maker ); void fill_settle_order( const force_settlement_object& settle, const asset& pays, stored_value&& receives, const price& fill_price ); @@ -419,8 +419,6 @@ namespace graphene { namespace chain { const asset_bitasset_data_object* bitasset_ptr = nullptr ); // helpers to fill_order - void pay_order( const account_object& receiver, stored_value&& receives, const asset& pays ); - share_type calculate_market_fee(const asset_object& recv_asset, const share_type trade_amount); asset pay_market_fees(const account_object* seller, const asset_object& recv_asset, stored_value&& receives ); ///@} From 9cb376f418e5e521b3ce84fb8622cf5a0fbc924d Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 13 Dec 2019 18:00:02 +0100 Subject: [PATCH 30/59] Fixup stored_value --- libraries/chain/stored_value.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/stored_value.cpp b/libraries/chain/stored_value.cpp index bc21087d29..7cf9b4cbb2 100644 --- a/libraries/chain/stored_value.cpp +++ b/libraries/chain/stored_value.cpp @@ -31,7 +31,7 @@ namespace graphene { namespace chain { stored_debt::~stored_debt() { - FC_ASSERT( _amount == 0 || std::current_exception() // should check for enabled undo_db in case of exception + FC_ASSERT( _amount == 0 || std::uncaught_exception() // should check for enabled undo_db in case of exception , "Value leak detected: (${n],${a])!", ("n",_amount.value)("a",_asset) ); } From f5b10f51f009403034e36459f79adc933158f6e8 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 13 Dec 2019 18:00:29 +0100 Subject: [PATCH 31/59] Fix confidential fee handling --- libraries/chain/confidential_evaluator.cpp | 38 ++++++++++++------- .../graphene/chain/confidential_evaluator.hpp | 4 +- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/libraries/chain/confidential_evaluator.cpp b/libraries/chain/confidential_evaluator.cpp index c5064cf045..062ac92b51 100644 --- a/libraries/chain/confidential_evaluator.cpp +++ b/libraries/chain/confidential_evaluator.cpp @@ -80,7 +80,6 @@ void transfer_to_blind_evaluator::pay_fee() void_result transfer_from_blind_evaluator::do_evaluate( const transfer_from_blind_operation& o ) { try { const auto& d = db(); - o.fee.asset_id(d); // verify fee is a legit asset const auto& bbi = d.get_index_type(); const auto& cidx = bbi.indices().get(); for( const auto& in : o.inputs ) @@ -103,12 +102,10 @@ void_result transfer_from_blind_evaluator::do_apply( const transfer_from_blind_o FC_ASSERT( itr != cidx.end() ); db().remove( *itr ); } - const auto& add = o.amount.asset_id(db()).dynamic_asset_data_id(db()); stored_value transport; - db().modify( add, [&o,&transport]( asset_dynamic_data_object& obj ){ - transport = obj.confidential_supply.split( o.amount.amount + o.fee.amount ); + db().modify( *fee_asset_dd, [&o,&transport]( asset_dynamic_data_object& obj ){ + transport = obj.confidential_supply.split( o.amount.amount ); }); - tmp_fee.burn( transport.split(o.fee.amount) ); db().add_balance( o.to, std::move(transport) ); return void_result(); @@ -118,8 +115,18 @@ void transfer_from_blind_evaluator::prepare_fee(account_id_type account_id, asse { FC_ASSERT( fee.amount >= 0 ); - tmp_fee = stored_debt(fee.asset_id); // account_id borrows the fee temporarily, - db().add_balance( account_id, tmp_fee.issue(fee.amount) ); // which is paid back from the blinded balance + const auto& fee_asset = fee.asset_id(db()); // verify fee is a legit asset + fee_asset_dd = &fee_asset.dynamic_asset_data_id(db()); + + // This breaks the order we normally do things - do read-only evaluate() first, + // only when that's ok we do read-write apply(). Problem here is that the fee is + // logically paid from the blinded balance, but in fact paid by account_id before + // the blinded balance is un-blinded. + stored_value transport; + db().modify( *fee_asset_dd, [&transport,&fee] ( asset_dynamic_data_object& add ) { + transport = add.confidential_supply.split( fee.amount ); + }); + db().add_balance( account_id, std::move(transport) ); generic_evaluator::prepare_fee( account_id, fee ); } @@ -135,7 +142,6 @@ void transfer_from_blind_evaluator::pay_fee() void_result blind_transfer_evaluator::do_evaluate( const blind_transfer_operation& o ) { try { const auto& d = db(); - o.fee.asset_id(d); // verify fee is a legit asset const auto& bbi = d.get_index_type(); const auto& cidx = bbi.indices().get(); for( const auto& out : o.outputs ) @@ -171,10 +177,6 @@ void_result blind_transfer_evaluator::do_apply( const blind_transfer_operation& obj.commitment = out.commitment; }); } - const auto& add = o.fee.asset_id(db()).dynamic_asset_data_id(db()); - db().modify( add, [this,&o]( asset_dynamic_data_object& obj ){ - tmp_fee.burn( obj.confidential_supply.split(o.fee.amount) ); - }); return void_result(); } FC_CAPTURE_AND_RETHROW( (o) ) } @@ -183,8 +185,16 @@ void blind_transfer_evaluator::prepare_fee(account_id_type account_id, asset fee { FC_ASSERT( fee.amount >= 0 ); - tmp_fee = stored_debt(fee.asset_id); // account_id borrows the fee temporarily, - db().add_balance( account_id, tmp_fee.issue(fee.amount) ); // which is paid back from the blinded balance + const auto& fee_asset = fee.asset_id(db()); // also verifies fee is a legit asset + + // This breaks the order we normally do things - do read-only evaluate() first, + // only when that's ok we do read-write apply(). Problem here is that the fee is + // logically paid from the blinded balance, but in fact paid by account_id. + stored_value transport; + db().modify( fee_asset.dynamic_asset_data_id(db()), [&transport,&fee] ( asset_dynamic_data_object& add ) { + transport = add.confidential_supply.split( fee.amount ); + }); + db().add_balance( account_id, std::move(transport) ); generic_evaluator::prepare_fee( account_id, fee ); } diff --git a/libraries/chain/include/graphene/chain/confidential_evaluator.hpp b/libraries/chain/include/graphene/chain/confidential_evaluator.hpp index a9f2aefefe..577f84423c 100644 --- a/libraries/chain/include/graphene/chain/confidential_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/confidential_evaluator.hpp @@ -51,7 +51,7 @@ class transfer_from_blind_evaluator : public evaluator @@ -66,8 +66,6 @@ class blind_transfer_evaluator : public evaluator protected: virtual void prepare_fee(account_id_type account_id, asset fee) override; - - stored_debt tmp_fee; }; } } // namespace graphene::chain From 1ecffe2f7d95ff8f4604d42594f08e6a8a9e7d50 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 13 Dec 2019 18:29:02 +0100 Subject: [PATCH 32/59] Fix fee height check --- libraries/chain/include/graphene/chain/evaluator.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/chain/include/graphene/chain/evaluator.hpp b/libraries/chain/include/graphene/chain/evaluator.hpp index 549e59b0b8..5e7660dfe0 100644 --- a/libraries/chain/include/graphene/chain/evaluator.hpp +++ b/libraries/chain/include/graphene/chain/evaluator.hpp @@ -149,10 +149,11 @@ namespace graphene { namespace chain { if( !trx_state->skip_fee_schedule_check ) { share_type required_fee = calculate_fee_for_operation(op); - GRAPHENE_ASSERT( core_fee_paid.get_amount() >= required_fee, + share_type fee_to_pay = op.fee.asset_id == asset_id_type() ? fee_from_account.get_amount() : fee_from_pool; + GRAPHENE_ASSERT( fee_to_pay >= required_fee, insufficient_fee, "Insufficient Fee Paid", - ("core_fee_paid",core_fee_paid.get_amount())("required", required_fee) ); + ("core_fee_to_pay",fee_to_pay)("required", required_fee) ); } return eval->do_evaluate(op); From 4ce6cb6e1eeb1927ef8d507af9086a4fa387538f Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sat, 14 Dec 2019 14:04:12 +0100 Subject: [PATCH 33/59] Fixed object notification --- libraries/chain/db_notify.cpp | 24 +++++++++---------- .../include/graphene/chain/htlc_object.hpp | 5 ++++ libraries/chain/small_objects.cpp | 1 + 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/libraries/chain/db_notify.cpp b/libraries/chain/db_notify.cpp index 6213badc1c..8cac0164c4 100644 --- a/libraries/chain/db_notify.cpp +++ b/libraries/chain/db_notify.cpp @@ -315,7 +315,7 @@ void get_relevant_accounts( const object* obj, flat_set& accoun accounts.insert( aobj->issuer ); break; } case force_settlement_object_type:{ - const auto& aobj = dynamic_cast(obj); + const auto& aobj = dynamic_cast(obj); FC_ASSERT( aobj != nullptr ); accounts.insert( aobj->owner ); break; @@ -330,12 +330,12 @@ void get_relevant_accounts( const object* obj, flat_set& accoun accounts.insert( aobj->witness_account ); break; } case limit_order_object_type:{ - const auto& aobj = dynamic_cast(obj); + const auto& aobj = dynamic_cast(obj); FC_ASSERT( aobj != nullptr ); accounts.insert( aobj->seller ); break; } case call_order_object_type:{ - const auto& aobj = dynamic_cast(obj); + const auto& aobj = dynamic_cast(obj); FC_ASSERT( aobj != nullptr ); accounts.insert( aobj->borrower ); break; @@ -358,7 +358,7 @@ void get_relevant_accounts( const object* obj, flat_set& accoun accounts.insert( aobj->authorized_account ); break; } case vesting_balance_object_type:{ - const auto& aobj = dynamic_cast(obj); + const auto& aobj = dynamic_cast(obj); FC_ASSERT( aobj != nullptr ); accounts.insert( aobj->owner ); break; @@ -371,11 +371,11 @@ void get_relevant_accounts( const object* obj, flat_set& accoun /** these are free from any accounts */ break; } case htlc_object_type:{ - const auto& htlc_obj = dynamic_cast(obj); - FC_ASSERT( htlc_obj != nullptr ); - accounts.insert( htlc_obj->transfer.from ); - accounts.insert( htlc_obj->transfer.to ); - break; + const auto htlc_obj = dynamic_cast(obj); + FC_ASSERT( htlc_obj != nullptr ); + accounts.insert( htlc_obj->get_transfer_info().from ); + accounts.insert( htlc_obj->get_transfer_info().to ); + break; } } } @@ -394,12 +394,12 @@ void get_relevant_accounts( const object* obj, flat_set& accoun case impl_asset_bitasset_data_object_type: break; case impl_account_balance_object_type:{ - const auto& aobj = dynamic_cast(obj); + const auto& aobj = dynamic_cast(obj); FC_ASSERT( aobj != nullptr ); accounts.insert( aobj->owner ); break; } case impl_account_statistics_object_type:{ - const auto& aobj = dynamic_cast(obj); + const auto& aobj = dynamic_cast(obj); FC_ASSERT( aobj != nullptr ); accounts.insert( aobj->owner ); break; @@ -434,7 +434,7 @@ void get_relevant_accounts( const object* obj, flat_set& accoun case impl_fba_accumulator_object_type: break; case impl_collateral_bid_object_type:{ - const auto& aobj = dynamic_cast(obj); + const auto& aobj = dynamic_cast(obj); FC_ASSERT( aobj != nullptr ); accounts.insert( aobj->bidder ); break; diff --git a/libraries/chain/include/graphene/chain/htlc_object.hpp b/libraries/chain/include/graphene/chain/htlc_object.hpp index d25ef0b710..be359d085d 100644 --- a/libraries/chain/include/graphene/chain/htlc_object.hpp +++ b/libraries/chain/include/graphene/chain/htlc_object.hpp @@ -25,6 +25,7 @@ #include #include +#include #include @@ -64,6 +65,8 @@ namespace graphene { namespace chain { typedef fc::time_point_sec result_type; const result_type& operator()(const htlc_master& o)const { return o.conditions.time_lock.expiration; } }; + + virtual const transfer_info_master& get_transfer_info()const { FC_ASSERT( !"Override in subclass!" ); } }; class htlc_object : public htlc_master @@ -89,6 +92,8 @@ namespace graphene { namespace chain { const result_type& operator()(const htlc_object& o)const { return o.transfer.to; } }; + virtual const transfer_info_master& get_transfer_info()const { return transfer; } + protected: virtual unique_ptr backup()const; virtual void restore( graphene::db::object& obj ); diff --git a/libraries/chain/small_objects.cpp b/libraries/chain/small_objects.cpp index bc9ab9aaad..c8d550f327 100644 --- a/libraries/chain/small_objects.cpp +++ b/libraries/chain/small_objects.cpp @@ -129,6 +129,7 @@ class htlc_backup : public htlc_master, public graphene::db::backup_object::recreate(); } + virtual const transfer_info_master& get_transfer_info()const { return transfer; } }; unique_ptr htlc_object::backup()const From 3ad63f5c79aefe1722609ec62d4cc1bbdf0dfc81 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sun, 15 Dec 2019 12:26:24 +0100 Subject: [PATCH 34/59] Avoid _undo_db operating on unregistered indexes --- tests/tests/database_tests.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/tests/database_tests.cpp b/tests/tests/database_tests.cpp index ce2b3566b6..84787b4855 100644 --- a/tests/tests/database_tests.cpp +++ b/tests/tests/database_tests.cpp @@ -147,6 +147,8 @@ BOOST_AUTO_TEST_CASE( merge_test ) BOOST_AUTO_TEST_CASE( direct_index_test ) { try { + db._undo_db.disable(); + try { const graphene::db::primary_index< account_index, 6 > small_chunkbits( db ); BOOST_FAIL( "Expected assertion failure!" ); @@ -228,6 +230,8 @@ BOOST_AUTO_TEST_CASE( direct_index_test ) }), fc::assert_exception ); // This is actually undefined behaviour. The object has been modified, but // but the secondary has not updated its representation + + db._undo_db.enable(); } FC_LOG_AND_RETHROW() } BOOST_AUTO_TEST_CASE( required_approval_index_test ) // see https://github.com/bitshares/bitshares-core/issues/1719 From eb33f537c17f2ce9ae4fa0030b918a2d93771dae Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Sun, 15 Dec 2019 12:45:40 +0100 Subject: [PATCH 35/59] Fixup fixture --- tests/common/database_fixture.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/common/database_fixture.cpp b/tests/common/database_fixture.cpp index 068cfb2499..36483ae56a 100644 --- a/tests/common/database_fixture.cpp +++ b/tests/common/database_fixture.cpp @@ -373,6 +373,7 @@ database_fixture::database_fixture(const fc::time_point_sec &initial_timestamp) trx.operations.emplace_back(bop); PUSH_TX(db, trx, ~0); trx.operations.clear(); + generate_block(); } asset_id_type mpa1_id(1); From 6baa6ad2902421e3a1a2d64e37a5283e07827bb5 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Mon, 16 Dec 2019 18:11:47 +0100 Subject: [PATCH 36/59] Fixed deferred_paid_fee handling --- libraries/chain/db_market.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/libraries/chain/db_market.cpp b/libraries/chain/db_market.cpp index ad1fa360e4..af5c14001a 100644 --- a/libraries/chain/db_market.cpp +++ b/libraries/chain/db_market.cpp @@ -257,6 +257,7 @@ void database::cancel_limit_order( const limit_order_object& order, bool create_ deferred_fee = std::move( loo.deferred_fee ); deferred_paid_fee = std::move( loo.deferred_paid_fee ); }); + const bool have_deferred_fee = deferred_paid_fee.get_amount() != 0; if( create_virtual_op ) { vop.order = order.id; @@ -273,7 +274,7 @@ void database::cancel_limit_order( const limit_order_object& order, bool create_ { // handle originally paid fee if any: // to_deduct = round_up( paid_fee * core_cancel_fee / deferred_core_fee_before_deduct ) - if( deferred_paid_fee.get_amount() == 0 ) + if( !have_deferred_fee ) { vop.fee = asset( core_cancel_fee_amount ); } @@ -317,7 +318,7 @@ void database::cancel_limit_order( const limit_order_object& order, bool create_ // refund fee // could be virtual op or real op here - if( deferred_paid_fee.get_amount() == 0 ) + if( !have_deferred_fee ) { // be here, order.create_time <= HARDFORK_CORE_604_TIME, or fee paid in CORE, or no fee to refund. // if order was created before hard fork 604 then cancelled no matter before or after hard fork 604, @@ -328,11 +329,14 @@ void database::cancel_limit_order( const limit_order_object& order, bool create_ { add_balance( order.seller, std::move(deferred_paid_fee) ); // be here, must have: fee_asset != CORE - if( fee_asset_dyn_data == nullptr ) - fee_asset_dyn_data = &deferred_paid_fee.get_asset()(*this).dynamic_asset_data_id(*this); - modify( *fee_asset_dyn_data, [&deferred_fee](asset_dynamic_data_object& addo) { - addo.fee_pool += std::move(deferred_fee); - }); + if( deferred_fee.get_amount() > 0 ) + { + if( fee_asset_dyn_data == nullptr ) + fee_asset_dyn_data = &deferred_paid_fee.get_asset()(*this).dynamic_asset_data_id(*this); + modify( *fee_asset_dyn_data, [&deferred_fee](asset_dynamic_data_object& addo) { + addo.fee_pool += std::move(deferred_fee); + }); + } } if( create_virtual_op ) From 6a284be992bab340f526d79435d52992ae1c6a9d Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Mon, 16 Dec 2019 18:20:41 +0100 Subject: [PATCH 37/59] Fix budget calculation --- libraries/chain/db_maint.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index 6e11825764..eaf2bbe10d 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -486,8 +486,8 @@ void database::process_budget() available_funds = std::move(_core.accumulated_fees); share_type required = rec.total_budget - available_funds.get_amount() - - rec.witness_budget - + dpo.witness_budget.get_amount(); + + rec.witness_budget + - dpo.witness_budget.get_amount(); if( required > 0 ) available_funds += _core.current_supply.issue( required ); }); From f53f8cdc38434e909dd048e17daaf96386b54015 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Mon, 16 Dec 2019 18:22:47 +0100 Subject: [PATCH 38/59] Fixed expected block number due to change in fixture --- tests/tests/block_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index c4c3ac2941..e4e8c50645 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -871,7 +871,7 @@ BOOST_FIXTURE_TEST_CASE( maintenance_interval, database_fixture ) { try { generate_block(); - BOOST_CHECK_EQUAL(db.head_block_num(), 2u); + BOOST_CHECK_EQUAL(db.head_block_num(), 3u); fc::time_point_sec maintenence_time = db.get_dynamic_global_properties().next_maintenance_time; BOOST_CHECK_GT(maintenence_time.sec_since_epoch(), db.head_block_time().sec_since_epoch()); From 620a02f89f5c825c2a5e577bcacdbe1256684ca0 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Mon, 16 Dec 2019 18:26:21 +0100 Subject: [PATCH 39/59] Revert "Avoid _undo_db operating on unregistered indexes" This reverts commit 3ad63f5c79aefe1722609ec62d4cc1bbdf0dfc81. --- tests/tests/database_tests.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/tests/database_tests.cpp b/tests/tests/database_tests.cpp index 84787b4855..ce2b3566b6 100644 --- a/tests/tests/database_tests.cpp +++ b/tests/tests/database_tests.cpp @@ -147,8 +147,6 @@ BOOST_AUTO_TEST_CASE( merge_test ) BOOST_AUTO_TEST_CASE( direct_index_test ) { try { - db._undo_db.disable(); - try { const graphene::db::primary_index< account_index, 6 > small_chunkbits( db ); BOOST_FAIL( "Expected assertion failure!" ); @@ -230,8 +228,6 @@ BOOST_AUTO_TEST_CASE( direct_index_test ) }), fc::assert_exception ); // This is actually undefined behaviour. The object has been modified, but // but the secondary has not updated its representation - - db._undo_db.enable(); } FC_LOG_AND_RETHROW() } BOOST_AUTO_TEST_CASE( required_approval_index_test ) // see https://github.com/bitshares/bitshares-core/issues/1719 From 8f182a48e98e2cb964b37c3449adf336a8712ae0 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Mon, 16 Dec 2019 18:47:05 +0100 Subject: [PATCH 40/59] Fix op history test expectations wrt balance_claim in fixture --- tests/tests/history_api_tests.cpp | 61 ++++++++++++++----------------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/tests/tests/history_api_tests.cpp b/tests/tests/history_api_tests.cpp index e8856fda28..22a1b73dae 100644 --- a/tests/tests/history_api_tests.cpp +++ b/tests/tests/history_api_tests.cpp @@ -52,16 +52,16 @@ BOOST_AUTO_TEST_CASE(get_account_history) { int asset_create_op_id = operation::tag::value; int account_create_op_id = operation::tag::value; - //account_id_type() did 3 ops and includes id0 + //account_id_type() did 4 ops and includes id0 vector histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 100, operation_history_id_type()); - BOOST_CHECK_EQUAL(histories.size(), 3u); - BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u); + BOOST_CHECK_EQUAL(histories.size(), 4u); + BOOST_CHECK_EQUAL(histories[3].id.instance(), 0u); BOOST_CHECK_EQUAL(histories[2].op.which(), asset_create_op_id); // 1 account_create op larger than id1 histories = hist_api.get_account_history("1.2.0", operation_history_id_type(1), 100, operation_history_id_type()); - BOOST_CHECK_EQUAL(histories.size(), 1u); + BOOST_CHECK_EQUAL(histories.size(), 2u); BOOST_CHECK(histories[0].id.instance() != 0); BOOST_CHECK_EQUAL(histories[0].op.which(), account_create_op_id); @@ -89,10 +89,9 @@ BOOST_AUTO_TEST_CASE(get_account_history_additional) { // account_id_type() and dan share operation id 1(account create) - share can be also in id 0 // no history at all in the chain - vector histories = hist_api.get_account_history("1.2.0", operation_history_id_type(0), 4, operation_history_id_type(0)); + vector histories = hist_api.get_account_history("1.2.1", operation_history_id_type(0), 4, operation_history_id_type(0)); BOOST_CHECK_EQUAL(histories.size(), 0u); - create_bitasset("USD", account_id_type()); // create op 0 generate_block(); // what if the account only has one history entry and it is 0? histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 4, operation_history_id_type()); @@ -409,7 +408,6 @@ BOOST_AUTO_TEST_CASE(track_account) { //account_id_type() creates some ops create_bitasset("CNY", account_id_type()); - create_bitasset("USD", account_id_type()); // account_id_type() creates dan(account tracked) const account_object& dan = create_account("dan"); @@ -483,7 +481,6 @@ BOOST_AUTO_TEST_CASE(track_account2) { auto alice_id = alice.id; //account_id_type() creates some ops - create_bitasset("CNY", account_id_type()); create_bitasset("USD", account_id_type()); // alice makes 1 op @@ -502,16 +499,16 @@ BOOST_AUTO_TEST_CASE(track_account2) { BOOST_CHECK_EQUAL(histories[2].id.instance(), 1u); BOOST_CHECK_EQUAL(histories[3].id.instance(), 0u); - // all alice account should have 2 ops {3, 0} + // all alice account should have 2 ops {3, 1} histories = hist_api.get_account_history("alice", operation_history_id_type(0), 10, operation_history_id_type(0)); BOOST_CHECK_EQUAL(histories.size(), 2u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 3u); - BOOST_CHECK_EQUAL(histories[1].id.instance(), 0u); + BOOST_CHECK_EQUAL(histories[1].id.instance(), 1u); - // alice first op should be {0} + // alice first op should be {1} histories = hist_api.get_account_history("alice", operation_history_id_type(0), 1, operation_history_id_type(1)); BOOST_CHECK_EQUAL(histories.size(), 1u); - BOOST_CHECK_EQUAL(histories[0].id.instance(), 0u); + BOOST_CHECK_EQUAL(histories[0].id.instance(), 1u); // alice second op should be {3} histories = hist_api.get_account_history("alice", operation_history_id_type(1), 1, operation_history_id_type(0)); @@ -536,23 +533,23 @@ BOOST_AUTO_TEST_CASE(get_account_history_operations) { try { graphene::app::history_api hist_api(app); - //account_id_type() do 3 ops - create_bitasset("CNY", account_id_type()); + //account_id_type() do 2 ops create_account("sam"); create_account("alice"); generate_block(); fc::usleep(fc::milliseconds(2000)); - int asset_create_op_id = operation::tag::value; - int account_create_op_id = operation::tag::value; + constexpr int asset_create_op_id = operation::tag::value; + constexpr int account_create_op_id = operation::tag::value; + constexpr int balance_claim_op_id = operation::tag::value; - //account_id_type() did 1 asset_create op + //account_id_type() did 1 balance_claim op vector histories = hist_api.get_account_history_operations( - "committee-account", asset_create_op_id, operation_history_id_type(), operation_history_id_type(), 100); + "committee-account", balance_claim_op_id, operation_history_id_type(), operation_history_id_type(), 100); BOOST_CHECK_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 0u); - BOOST_CHECK_EQUAL(histories[0].op.which(), asset_create_op_id); + BOOST_CHECK_EQUAL(histories[0].op.which(), balance_claim_op_id); //account_id_type() did 2 account_create ops histories = hist_api.get_account_history_operations( @@ -604,23 +601,23 @@ BOOST_AUTO_TEST_CASE(get_account_history_operations) { BOOST_AUTO_TEST_CASE(api_limit_get_account_history_operations) { try { graphene::app::history_api hist_api(app); - //account_id_type() do 3 ops - create_bitasset("CNY", account_id_type()); + //account_id_type() do 2 ops create_account("sam"); create_account("alice"); generate_block(); fc::usleep(fc::milliseconds(100)); - int asset_create_op_id = operation::tag::value; - int account_create_op_id = operation::tag::value; + constexpr int asset_create_op_id = operation::tag::value; + constexpr int account_create_op_id = operation::tag::value; + constexpr int balance_claim_op_id = operation::tag::value; //account_id_type() did 1 asset_create op vector histories = hist_api.get_account_history_operations( - "committee-account", asset_create_op_id, operation_history_id_type(), operation_history_id_type(), 200); + "committee-account", balance_claim_op_id, operation_history_id_type(), operation_history_id_type(), 200); BOOST_CHECK_EQUAL(histories.size(), 1u); BOOST_CHECK_EQUAL(histories[0].id.instance(), 0u); - BOOST_CHECK_EQUAL(histories[0].op.which(), asset_create_op_id); + BOOST_CHECK_EQUAL(histories[0].op.which(), balance_claim_op_id); //account_id_type() did 2 account_create ops histories = hist_api.get_account_history_operations( @@ -670,22 +667,21 @@ BOOST_AUTO_TEST_CASE(api_limit_get_account_history_operations) { BOOST_AUTO_TEST_CASE(api_limit_get_account_history) { try{ graphene::app::history_api hist_api(app); - //account_id_type() do 3 ops - create_bitasset("USD", account_id_type()); + //account_id_type() do 2 ops create_account("dan"); create_account("bob"); generate_block(); fc::usleep(fc::milliseconds(100)); - int asset_create_op_id = operation::tag::value; - int account_create_op_id = operation::tag::value; - //account_id_type() did 3 ops and includes id0 + constexpr int account_create_op_id = operation::tag::value; + constexpr int balance_claim_op_id = operation::tag::value; + //account_id_type() did 2 ops and includes id0 vector histories = hist_api.get_account_history("1.2.0", operation_history_id_type(), 210, operation_history_id_type()); BOOST_CHECK_EQUAL(histories.size(), 3u); BOOST_CHECK_EQUAL(histories[2].id.instance(), 0u); - BOOST_CHECK_EQUAL(histories[2].op.which(), asset_create_op_id); + BOOST_CHECK_EQUAL(histories[2].op.which(), balance_claim_op_id); // 1 account_create op larger than id1 histories = hist_api.get_account_history("1.2.0", operation_history_id_type(1), 210, operation_history_id_type()); @@ -745,8 +741,7 @@ BOOST_AUTO_TEST_CASE(api_limit_get_account_history_by_operations) { try { graphene::app::history_api hist_api(app); vector operation_types; - //account_id_type() do 3 ops - create_bitasset("USD", account_id_type()); + //account_id_type() do 2 ops create_account("dan"); create_account("bob"); generate_block(); From 18006c3fb3b0c77670f54bd09cc9df8ea5941f95 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Mon, 16 Dec 2019 22:23:20 +0100 Subject: [PATCH 41/59] Fixup total core in orders --- libraries/chain/db_market.cpp | 2 +- libraries/chain/market_evaluator.cpp | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/libraries/chain/db_market.cpp b/libraries/chain/db_market.cpp index af5c14001a..08a81c48c5 100644 --- a/libraries/chain/db_market.cpp +++ b/libraries/chain/db_market.cpp @@ -894,7 +894,7 @@ bool database::fill_call_order( const call_order_object& order, const asset& pay FC_ASSERT( order.debt_type() == receives.get_asset() ); FC_ASSERT( order.collateral_type() == pays.asset_id ); - FC_ASSERT( order.collateral.get_amount() >= pays.amount ); + FC_ASSERT( !transport.valid() || order.collateral.get_amount() >= pays.amount ); // TODO pass in mia and bitasset_data for better performance const asset_object& mia = receives.get_asset()(*this); diff --git a/libraries/chain/market_evaluator.cpp b/libraries/chain/market_evaluator.cpp index ce771595a9..c112a4a73f 100644 --- a/libraries/chain/market_evaluator.cpp +++ b/libraries/chain/market_evaluator.cpp @@ -244,15 +244,13 @@ object_id_type call_order_update_evaluator::do_apply(const call_order_update_ope stored_value transport_collateral; if( o.delta_collateral.amount > 0 ) - { transport_collateral = d.reduce_balance( o.funding_account, o.delta_collateral ); - // Adjust the total core in orders accodingly - if( o.delta_collateral.asset_id == asset_id_type() ) - d.modify(_paying_account->statistics(d), [&o](account_statistics_object& stats) { - stats.total_core_in_orders += o.delta_collateral.amount; - }); - } + // Adjust the total core in orders accodingly + if( o.delta_collateral.amount != 0 && o.delta_collateral.asset_id == asset_id_type() ) + d.modify(_paying_account->statistics(d), [&o](account_statistics_object& stats) { + stats.total_core_in_orders += o.delta_collateral.amount; + }); const auto next_maint_time = d.get_dynamic_global_properties().next_maintenance_time; bool before_core_hardfork_1270 = ( next_maint_time <= HARDFORK_CORE_1270_TIME ); // call price caching issue From bd5ffa1fbd7c9bab5c9d36727ce0fd30a0dc0ceb Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 17 Dec 2019 15:03:22 +0100 Subject: [PATCH 42/59] Dont update call_price if no collateral is left --- libraries/chain/market_evaluator.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/market_evaluator.cpp b/libraries/chain/market_evaluator.cpp index c112a4a73f..32f5afa713 100644 --- a/libraries/chain/market_evaluator.cpp +++ b/libraries/chain/market_evaluator.cpp @@ -308,7 +308,7 @@ object_id_type call_order_update_evaluator::do_apply(const call_order_update_ope transport_debt = call.debt.issue( o.delta_debt.amount ); else if( o.delta_debt.amount < 0 ) call.debt.burn( std::move(transport_debt) ); - if( before_core_hardfork_1270 ) // don't update call_price after core-1270 hard fork + if( before_core_hardfork_1270 && call.collateral.get_amount() > 0 ) // don't update call_price after core-1270 hard fork { call.call_price = price::call_price( call.get_debt(), call.get_collateral(), _bitasset_data->current_feed.maintenance_collateral_ratio ); From 845249801da4c88ba0a73b3e1a198eb0145c3caa Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 17 Dec 2019 15:12:29 +0100 Subject: [PATCH 43/59] Fixup force settlement evaluator --- libraries/chain/asset_evaluator.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index 991bf2982f..e1c2aee2c4 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -732,18 +732,19 @@ operation_result asset_settle_evaluator::do_apply(const asset_settle_evaluator:: pays = settled_amount.multiply_and_round_up( bitasset.settlement_price ); } - stored_value transport = d.reduce_balance( op.account, pays ); - d.modify( mia_dyn, [&transport]( asset_dynamic_data_object& obj ){ - obj.current_supply.burn( std::move(transport) ); + stored_value transport_debt = d.reduce_balance( op.account, pays ); + d.modify( mia_dyn, [&transport_debt]( asset_dynamic_data_object& obj ){ + obj.current_supply.burn( std::move(transport_debt) ); }); if( settled_amount.amount > 0 ) { - d.modify( bitasset, [&transport,&settled_amount]( asset_bitasset_data_object& obj ){ - transport = obj.settlement_fund.split( settled_amount.amount ); + stored_value transport_collateral; + d.modify( bitasset, [&transport_collateral,&settled_amount]( asset_bitasset_data_object& obj ){ + transport_collateral = obj.settlement_fund.split( settled_amount.amount ); }); - d.add_balance( op.account, std::move(transport) ); + d.add_balance( op.account, std::move(transport_collateral) ); } return settled_amount; From ed988f43529f434004e0978e884265bae0de4732 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 17 Dec 2019 16:46:30 +0100 Subject: [PATCH 44/59] Fixup worker payout --- libraries/chain/db_maint.cpp | 9 ++++----- libraries/chain/include/graphene/chain/database.hpp | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/libraries/chain/db_maint.cpp b/libraries/chain/db_maint.cpp index eaf2bbe10d..61b3717e98 100644 --- a/libraries/chain/db_maint.cpp +++ b/libraries/chain/db_maint.cpp @@ -148,7 +148,7 @@ void database::update_worker_votes() } } -void database::pay_workers( stored_value&& budget ) +void database::pay_workers( const fc::microseconds passed_time_ms, stored_value& budget ) { const auto head_time = head_block_time(); // ilog("Processing payroll! Available budget is ${b}", ("b", budget)); @@ -170,8 +170,6 @@ void database::pay_workers( stored_value&& budget ) return wa.id < wb.id; }); - const auto last_budget_time = get_dynamic_global_properties().last_budget_time; - const auto passed_time_ms = head_time - last_budget_time; const auto passed_time_count = passed_time_ms.count(); const auto day_count = fc::days(1).count(); for( uint32_t i = 0; i < active_workers.size() && budget.get_amount() > 0; ++i ) @@ -492,7 +490,8 @@ void database::process_budget() available_funds += _core.current_supply.issue( required ); }); - modify(dpo, [now,&available_funds,&rec]( dynamic_global_property_object& _dpo ) + const auto passed_time_ms = now - get_dynamic_global_properties().last_budget_time; + modify(dpo, [now,&available_funds,&rec]( dynamic_global_property_object& _dpo ) { _dpo.last_budget_time = now; if( _dpo.witness_budget.get_amount() > rec.witness_budget ) @@ -511,7 +510,7 @@ void database::process_budget() rec.worker_budget = static_cast(worker_budget_u128); stored_value worker_budget = available_funds.split( rec.worker_budget ); - pay_workers( std::move(worker_budget) ); + pay_workers( passed_time_ms, worker_budget ); rec.leftover_worker_funds = worker_budget.get_amount(); available_funds += std::move( worker_budget ); diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index 18a221c258..5e4c08da8b 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -528,7 +528,7 @@ namespace graphene { namespace chain { void initialize_budget_record( fc::time_point_sec now, budget_record& rec )const; void process_budget(); - void pay_workers( stored_value&& budget ); + void pay_workers( const fc::microseconds passed_time_ms, stored_value& budget ); void perform_chain_maintenance(const signed_block& next_block, const global_property_object& global_props); void update_active_witnesses(); void update_active_committee_members(); From 254bde921b30efd2b2e66d7fe378d41d729ab63e Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 17 Dec 2019 17:35:03 +0100 Subject: [PATCH 45/59] Fixup force_settle_backup --- libraries/chain/market_object.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/chain/market_object.cpp b/libraries/chain/market_object.cpp index 7ad7334062..a00d4f7196 100644 --- a/libraries/chain/market_object.cpp +++ b/libraries/chain/market_object.cpp @@ -390,7 +390,7 @@ class force_settlement_backup force_settlement_backup( const force_settlement_object& original ) : force_settlement_master( original ) { - balance = original.balance.get_amount(); + balance = original.balance.get_value(); } virtual object* recreate() { return graphene::db::backup_object::recreate(); } From 130086e1c5ef5895330b4aef14cf4a07a63d9bd8 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 17 Dec 2019 17:39:48 +0100 Subject: [PATCH 46/59] Fix tests --- tests/tests/operation_tests.cpp | 4 ---- tests/tests/operation_tests2.cpp | 1 + 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/tests/operation_tests.cpp b/tests/tests/operation_tests.cpp index 65e4e0fafb..7c57e6f8e2 100644 --- a/tests/tests/operation_tests.cpp +++ b/tests/tests/operation_tests.cpp @@ -1783,10 +1783,6 @@ BOOST_AUTO_TEST_CASE( witness_pay_test ) const share_type prec = asset::scaled_precision( asset_id_type()(db).precision ); - // there is an immediate maintenance interval in the first block - // which will initialize last_budget_time - generate_block(); - // Make an account and upgrade it to prime, so that witnesses get some pay create_account("nathan", init_account_pub_key); transfer(account_id_type()(db), get_account("nathan"), asset(20000*prec)); diff --git a/tests/tests/operation_tests2.cpp b/tests/tests/operation_tests2.cpp index ef8fd660bb..4affd43d9b 100644 --- a/tests/tests/operation_tests2.cpp +++ b/tests/tests/operation_tests2.cpp @@ -1640,6 +1640,7 @@ BOOST_AUTO_TEST_CASE( balance_object_test ) database db; const uint32_t skip_flags = database::skip_undo_history_check; fc::temp_directory td( graphene::utilities::temp_directory_path() ); + genesis_state.initial_balances.clear(); genesis_state.initial_balances.push_back({generate_private_key("n").get_public_key(), GRAPHENE_SYMBOL, 1}); genesis_state.initial_balances.push_back({generate_private_key("x").get_public_key(), GRAPHENE_SYMBOL, 1}); fc::time_point_sec starting_time = genesis_state.initial_timestamp + 3000; From da29b6efdbcda1ae317ad9d56da7ddf041c5bde9 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 19 Dec 2019 21:38:32 +0100 Subject: [PATCH 47/59] Object serialization fixes --- libraries/chain/asset_object.cpp | 14 ------------ libraries/chain/fba_object.cpp | 2 -- .../include/graphene/chain/account_object.hpp | 7 ++++-- .../include/graphene/chain/asset_object.hpp | 22 +++++++++++++++++-- .../include/graphene/chain/balance_object.hpp | 3 ++- .../include/graphene/chain/fba_object.hpp | 6 +++-- .../graphene/chain/global_property_object.hpp | 4 +++- .../include/graphene/chain/htlc_object.hpp | 3 ++- .../include/graphene/chain/market_object.hpp | 12 ++++++---- .../graphene/chain/vesting_balance_object.hpp | 3 ++- libraries/db/include/graphene/db/object.hpp | 6 ++--- 11 files changed, 49 insertions(+), 33 deletions(-) diff --git a/libraries/chain/asset_object.cpp b/libraries/chain/asset_object.cpp index f937e260f8..aafa5fdb39 100644 --- a/libraries/chain/asset_object.cpp +++ b/libraries/chain/asset_object.cpp @@ -260,24 +260,10 @@ string asset_object::amount_to_string(share_type amount) const } } // graphene::chain -FC_REFLECT_DERIVED( graphene::chain::asset_dynamic_data_master, (graphene::db::object), ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::asset_dynamic_data_object, (graphene::chain::asset_dynamic_data_master), (current_supply)(accumulated_fees)(fee_pool)(confidential_supply) ) -FC_REFLECT_DERIVED( graphene::chain::asset_bitasset_data_master, (graphene::db::object), - (asset_id) - (feeds) - (current_feed) - (current_feed_publication_time) - (current_maintenance_collateralization) - (options) - (force_settled_volume) - (is_prediction_market) - (settlement_price) - (asset_cer_updated) - (feed_cer_updated) - ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::asset_bitasset_data_object, (graphene::chain::asset_bitasset_data_master), (settlement_fund) diff --git a/libraries/chain/fba_object.cpp b/libraries/chain/fba_object.cpp index f6137a79e6..4d8122bcb9 100644 --- a/libraries/chain/fba_object.cpp +++ b/libraries/chain/fba_object.cpp @@ -134,8 +134,6 @@ void fba_accumulator_object::clear() } } -FC_REFLECT_DERIVED( graphene::chain::fba_accumulator_master, (graphene::db::object), - (designated_asset) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::fba_accumulator_object, (graphene::chain::fba_accumulator_master), (accumulated_fba_fees) ) diff --git a/libraries/chain/include/graphene/chain/account_object.hpp b/libraries/chain/include/graphene/chain/account_object.hpp index d2dd2ae6c6..8587f8dd54 100644 --- a/libraries/chain/include/graphene/chain/account_object.hpp +++ b/libraries/chain/include/graphene/chain/account_object.hpp @@ -44,7 +44,9 @@ namespace graphene { namespace chain { * separating the account data that changes frequently from the account data that is mostly static, which will * minimize the amount of data that must be backed up as part of the undo history everytime a transfer is made. */ - class account_statistics_master : public graphene::db::abstract_object + class account_statistics_object; + class account_statistics_master + : public graphene::db::abstract_object< account_statistics_master, account_statistics_object > { public: static constexpr uint8_t space_id = implementation_ids; @@ -137,7 +139,8 @@ namespace graphene { namespace chain { * This object is indexed on owner and asset_type so that black swan * events in asset_type can be processed quickly. */ - class account_balance_master : public abstract_object + class account_balance_object; + class account_balance_master : public abstract_object< account_balance_master, account_balance_object > { public: static constexpr uint8_t space_id = implementation_ids; diff --git a/libraries/chain/include/graphene/chain/asset_object.hpp b/libraries/chain/include/graphene/chain/asset_object.hpp index b1593271f8..ecb1857ef7 100644 --- a/libraries/chain/include/graphene/chain/asset_object.hpp +++ b/libraries/chain/include/graphene/chain/asset_object.hpp @@ -56,7 +56,9 @@ namespace graphene { namespace chain { * This object exists as an implementation detail and its ID should never be referenced by * a blockchain operation. */ - class asset_dynamic_data_master : public abstract_object + class asset_dynamic_data_object; + class asset_dynamic_data_master + : public abstract_object< asset_dynamic_data_master, asset_dynamic_data_object > { public: static constexpr uint8_t space_id = implementation_ids; @@ -182,7 +184,8 @@ namespace graphene { namespace chain { * @ingroup object * @ingroup implementation */ - class asset_bitasset_data_master : public abstract_object + class asset_bitasset_data_master + : public abstract_object< asset_bitasset_data_master, asset_bitasset_data_object > { public: static constexpr uint8_t space_id = implementation_ids; @@ -357,6 +360,21 @@ FC_REFLECT_DERIVED( graphene::chain::asset_object, (graphene::db::object), (buyback_account) ) +FC_REFLECT_DERIVED( graphene::chain::asset_bitasset_data_master, (graphene::db::object), + (asset_id) + (feeds) + (current_feed) + (current_feed_publication_time) + (current_maintenance_collateralization) + (options) + (force_settled_volume) + (is_prediction_market) + (settlement_price) + (asset_cer_updated) + (feed_cer_updated) + ) +FC_REFLECT_DERIVED( graphene::chain::asset_dynamic_data_master, (graphene::db::object), ) + FC_REFLECT_TYPENAME( graphene::chain::asset_bitasset_data_object ) FC_REFLECT_TYPENAME( graphene::chain::asset_dynamic_data_object ) diff --git a/libraries/chain/include/graphene/chain/balance_object.hpp b/libraries/chain/include/graphene/chain/balance_object.hpp index c7cbc3fd4e..926d9c8c72 100644 --- a/libraries/chain/include/graphene/chain/balance_object.hpp +++ b/libraries/chain/include/graphene/chain/balance_object.hpp @@ -27,7 +27,8 @@ namespace graphene { namespace chain { - class balance_master : public abstract_object + class balance_object; + class balance_master : public abstract_object< balance_master, balance_object > { public: static constexpr uint8_t space_id = protocol_ids; diff --git a/libraries/chain/include/graphene/chain/fba_object.hpp b/libraries/chain/include/graphene/chain/fba_object.hpp index da289f67f0..afafb56f96 100644 --- a/libraries/chain/include/graphene/chain/fba_object.hpp +++ b/libraries/chain/include/graphene/chain/fba_object.hpp @@ -34,8 +34,9 @@ class database; /** * fba_accumulator_object accumulates fees to be paid out via buyback or other FBA mechanism. */ - -class fba_accumulator_master : public graphene::db::abstract_object< fba_accumulator_master > +class fba_accumulator_object; +class fba_accumulator_master + : public graphene::db::abstract_object< fba_accumulator_master, fba_accumulator_object > { public: static constexpr uint8_t space_id = implementation_ids; @@ -64,6 +65,7 @@ class fba_accumulator_object : public fba_accumulator_master MAP_OBJECT_ID_TO_TYPE(graphene::chain::fba_accumulator_object) +FC_REFLECT_DERIVED( graphene::chain::fba_accumulator_master, (graphene::db::object), (designated_asset) ) FC_REFLECT_TYPENAME( graphene::chain::fba_accumulator_object ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::chain::fba_accumulator_master ) diff --git a/libraries/chain/include/graphene/chain/global_property_object.hpp b/libraries/chain/include/graphene/chain/global_property_object.hpp index 700fdfbbf4..678b7f1faa 100644 --- a/libraries/chain/include/graphene/chain/global_property_object.hpp +++ b/libraries/chain/include/graphene/chain/global_property_object.hpp @@ -62,7 +62,9 @@ namespace graphene { namespace chain { * This is an implementation detail. The values here are calculated during normal chain operations and reflect the * current values of global blockchain properties. */ - class dynamic_global_property_master : public abstract_object + class dynamic_global_property_object; + class dynamic_global_property_master + : public abstract_object< dynamic_global_property_master, dynamic_global_property_object > { public: static constexpr uint8_t space_id = implementation_ids; diff --git a/libraries/chain/include/graphene/chain/htlc_object.hpp b/libraries/chain/include/graphene/chain/htlc_object.hpp index be359d085d..4ca57f6b9c 100644 --- a/libraries/chain/include/graphene/chain/htlc_object.hpp +++ b/libraries/chain/include/graphene/chain/htlc_object.hpp @@ -38,7 +38,8 @@ namespace graphene { namespace chain { * This object is stored in the database while an HTLC is active. The HTLC will * become inactive at expiration or when unlocked via the preimage. */ - class htlc_master : public graphene::db::abstract_object { + class htlc_object; + class htlc_master : public graphene::db::abstract_object< htlc_master, htlc_object > { public: // uniquely identify this object in the database static constexpr uint8_t space_id = protocol_ids; diff --git a/libraries/chain/include/graphene/chain/market_object.hpp b/libraries/chain/include/graphene/chain/market_object.hpp index e105c3c3c6..cf4eab93d8 100644 --- a/libraries/chain/include/graphene/chain/market_object.hpp +++ b/libraries/chain/include/graphene/chain/market_object.hpp @@ -42,7 +42,8 @@ using namespace graphene::db; * * This limit_order_objects are indexed by @ref expiration and is automatically deleted on the first block after expiration. */ -class limit_order_master : public abstract_object +class limit_order_object; +class limit_order_master : public abstract_object< limit_order_master, limit_order_object > { public: static constexpr uint8_t space_id = protocol_ids; @@ -119,7 +120,8 @@ typedef generic_index limit_or * 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_master : public abstract_object +class call_order_object; +class call_order_master : public abstract_object< call_order_master, call_order_object > { public: static constexpr uint8_t space_id = protocol_ids; @@ -178,7 +180,8 @@ class call_order_object : public call_order_master * 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_master : public abstract_object +class force_settlement_object; +class force_settlement_master : public abstract_object< force_settlement_master, force_settlement_object > { public: static constexpr uint8_t space_id = protocol_ids; @@ -208,7 +211,8 @@ class force_settlement_object : public force_settlement_master * There should only be one collateral_bid_object per asset per account, and * only for smartcoin assets that have a global settlement_price. */ -class collateral_bid_master : public abstract_object +class collateral_bid_object; +class collateral_bid_master : public abstract_object< collateral_bid_master, collateral_bid_object > { public: static constexpr uint8_t space_id = implementation_ids; diff --git a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp index 3c6330e2fe..c375889125 100644 --- a/libraries/chain/include/graphene/chain/vesting_balance_object.hpp +++ b/libraries/chain/include/graphene/chain/vesting_balance_object.hpp @@ -149,7 +149,8 @@ namespace graphene { namespace chain { /** * Vesting balance object is a balance that is locked by the blockchain for a period of time. */ - class vesting_balance_master : public abstract_object + class vesting_balance_object; + class vesting_balance_master : public abstract_object< vesting_balance_master, vesting_balance_object > { public: static constexpr uint8_t space_id = protocol_ids; diff --git a/libraries/db/include/graphene/db/object.hpp b/libraries/db/include/graphene/db/object.hpp index 2ac1e8e8a9..c913d545d0 100644 --- a/libraries/db/include/graphene/db/object.hpp +++ b/libraries/db/include/graphene/db/object.hpp @@ -92,7 +92,7 @@ namespace graphene { namespace db { * * http://en.wikipedia.org/wiki/Curiously_recurring_template_pattern */ - template + template class abstract_object : public object { protected: @@ -109,8 +109,8 @@ namespace graphene { namespace db { virtual object* recreate() { return this; } public: - virtual variant to_variant()const { return variant( static_cast(*this), MAX_NESTING ); } - virtual vector pack()const { return fc::raw::pack( static_cast(*this) ); } + virtual variant to_variant()const { return variant( static_cast(*this), MAX_NESTING ); } + virtual vector pack()const { return fc::raw::pack( static_cast(*this) ); } }; typedef flat_map annotation_map; From 09bfbfc7e767798fa66cd6c49ce77bf5e6ec14fc Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 19 Dec 2019 21:39:04 +0100 Subject: [PATCH 48/59] Resolve API incompatibilities --- libraries/app/api_objects.cpp | 10 ++ libraries/app/database_api.cpp | 49 +++++++- .../app/include/graphene/app/api_objects.hpp | 108 ++++++++++++++---- .../include/graphene/protocol/object_id.hpp | 2 + 4 files changed, 146 insertions(+), 23 deletions(-) diff --git a/libraries/app/api_objects.cpp b/libraries/app/api_objects.cpp index f48b6632c4..9e0d25f0f8 100644 --- a/libraries/app/api_objects.cpp +++ b/libraries/app/api_objects.cpp @@ -95,8 +95,15 @@ FC_REFLECT_DERIVED_NO_TYPENAME( graphene::app::account_balance_api_object, FC_REFLECT_DERIVED_NO_TYPENAME( graphene::app::account_statistics_api_object, (graphene::chain::account_statistics_master), (pending_fees)(pending_vested_fees) ); +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::app::asset_bitasset_data_api_object, + (graphene::chain::asset_bitasset_data_master), (settlement_fund) ); +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::app::asset_dynamic_data_api_object, + (graphene::chain::asset_dynamic_data_master), + (current_supply)(confidential_supply)(accumulated_fees)(fee_pool) ); FC_REFLECT_DERIVED_NO_TYPENAME( graphene::app::balance_api_object, (graphene::chain::balance_master), (balance) ); +FC_REFLECT_DERIVED_NO_TYPENAME( graphene::app::fba_accumulator_api_object, + (graphene::chain::fba_accumulator_master), (accumulated_fba_fees) ); FC_REFLECT_DERIVED_NO_TYPENAME( graphene::app::limit_order_api_object, (graphene::chain::limit_order_master), (for_sale)(deferred_fee)(deferred_paid_fee) ); FC_REFLECT_DERIVED_NO_TYPENAME( graphene::app::call_order_api_object, @@ -114,7 +121,10 @@ FC_REFLECT_DERIVED_NO_TYPENAME( graphene::app::dynamic_global_property_api_objec GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::app::account_balance_api_object ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::app::account_statistics_api_object ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::app::asset_bitasset_data_api_object ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::app::asset_dynamic_data_api_object ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::app::balance_api_object ) +GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::app::fba_accumulator_api_object ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::app::limit_order_api_object ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::app::call_order_api_object ) GRAPHENE_IMPLEMENT_EXTERNAL_SERIALIZATION( graphene::app::force_settlement_api_object ) diff --git a/libraries/app/database_api.cpp b/libraries/app/database_api.cpp index d6b3faf347..898dfde18c 100644 --- a/libraries/app/database_api.cpp +++ b/libraries/app/database_api.cpp @@ -110,11 +110,56 @@ fc::variants database_api_impl::get_objects( const vector& ids, std::transform(ids.begin(), ids.end(), std::back_inserter(result), [this,to_subscribe](object_id_type id) -> fc::variant { - if(auto obj = _db.find_object(id)) + if(const auto* obj = _db.find_object(id)) { if( to_subscribe && !id.is() && !id.is() ) this->subscribe_to_item( id ); - return obj->to_variant(); + variant tmp; + switch( id.space_type() ) + { + case account_balance_id_type::space_type(): + to_variant( account_balance_api_object( *dynamic_cast(obj) ), tmp, MAX_NESTING ); + break; + case account_statistics_id_type::space_type(): + to_variant( account_statistics_api_object( *dynamic_cast(obj) ), tmp, MAX_NESTING ); + break; + case asset_dynamic_data_id_type::space_type(): + to_variant( asset_dynamic_data_api_object( *dynamic_cast(obj) ), tmp, MAX_NESTING ); + break; + case asset_bitasset_data_id_type::space_type(): + to_variant( asset_bitasset_data_api_object( *dynamic_cast(obj) ), tmp, MAX_NESTING ); + break; + case balance_id_type::space_type(): + to_variant( balance_api_object( *dynamic_cast(obj) ), tmp, MAX_NESTING ); + break; + case fba_accumulator_id_type::space_type(): + to_variant( fba_accumulator_api_object( *dynamic_cast(obj) ), tmp, MAX_NESTING ); + break; + case dynamic_global_property_id_type::space_type(): + to_variant( dynamic_global_property_api_object( *dynamic_cast(obj) ), tmp, MAX_NESTING ); + break; + case htlc_id_type::space_type(): + to_variant( htlc_api_object( *dynamic_cast(obj) ), tmp, MAX_NESTING ); + break; + case limit_order_id_type::space_type(): + to_variant( limit_order_api_object( *dynamic_cast(obj) ), tmp, MAX_NESTING ); + break; + case call_order_id_type::space_type(): + to_variant( call_order_api_object( *dynamic_cast(obj) ), tmp, MAX_NESTING ); + break; + case force_settlement_id_type::space_type(): + to_variant( force_settlement_api_object( *dynamic_cast(obj) ), tmp, MAX_NESTING ); + break; + case collateral_bid_id_type::space_type(): + to_variant( collateral_bid_api_object( *dynamic_cast(obj) ), tmp, MAX_NESTING ); + break; + case vesting_balance_id_type::space_type(): + to_variant( vesting_balance_api_object( *dynamic_cast(obj) ), tmp, MAX_NESTING ); + break; + default: + tmp = obj->to_variant(); + } + return tmp; } return {}; }); diff --git a/libraries/app/include/graphene/app/api_objects.hpp b/libraries/app/include/graphene/app/api_objects.hpp index 7a5c717209..20d22c6ca9 100644 --- a/libraries/app/include/graphene/app/api_objects.hpp +++ b/libraries/app/include/graphene/app/api_objects.hpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include #include @@ -42,23 +43,36 @@ namespace graphene { namespace app { using namespace graphene::chain; using namespace graphene::market_history; - class account_balance_api_object : public account_balance_master + template + class api_object : public Master + { + public: + api_object() {} + api_object( const Master& orig ) : Master(orig) {} + + virtual variant to_variant()const { return variant( static_cast(*this), MAX_NESTING ); } + virtual vector pack()const { return fc::raw::pack( static_cast(*this) ); } + }; + + class account_balance_api_object : public api_object< account_balance_master, account_balance_api_object > { public: account_balance_api_object() {} - account_balance_api_object( const account_balance_object& orig) : account_balance_master(orig) + account_balance_api_object( const account_balance_object& orig) + : api_object(orig) { balance = orig.balance.get_value(); } asset balance; }; - class account_statistics_api_object : public account_statistics_master + class account_statistics_api_object + : public api_object< account_statistics_master, account_statistics_api_object > { public: account_statistics_api_object() {} account_statistics_api_object( const account_statistics_object& orig) - : account_statistics_master(orig) + : api_object(orig) { pending_fees = orig.pending_fees.get_amount(); pending_vested_fees = orig.pending_vested_fees.get_amount(); @@ -67,33 +81,80 @@ namespace graphene { namespace app { share_type pending_vested_fees; }; - class balance_api_object : public balance_master + class asset_dynamic_data_api_object : public api_object< asset_dynamic_data_master, asset_dynamic_data_api_object > + { + public: + asset_dynamic_data_api_object() {} + asset_dynamic_data_api_object( const asset_dynamic_data_object& orig ) + : api_object(orig) + { + current_supply = orig.current_supply.get_amount(); + confidential_supply = orig.confidential_supply.get_amount(); + accumulated_fees = orig.accumulated_fees.get_amount(); + fee_pool = orig.fee_pool.get_amount(); + } + + share_type current_supply; + share_type confidential_supply; + share_type accumulated_fees; + share_type fee_pool; + }; + + class asset_bitasset_data_api_object : public api_object< asset_bitasset_data_master, asset_bitasset_data_api_object > + { + public: + asset_bitasset_data_api_object() {} + asset_bitasset_data_api_object( const asset_bitasset_data_object& orig ) + : api_object(orig) + { + settlement_fund = orig.settlement_fund.get_amount(); + } + + share_type settlement_fund; + }; + + class balance_api_object : public api_object< balance_master, balance_api_object > { public: balance_api_object() {} - balance_api_object( const balance_object& orig) : balance_master(orig) + balance_api_object( const balance_object& orig) + : api_object(orig) { balance = orig.balance.get_value(); } asset balance; }; - class collateral_bid_api_object : public collateral_bid_master + class fba_accumulator_api_object : public api_object< fba_accumulator_master, fba_accumulator_api_object > + { + public: + fba_accumulator_api_object() {} + fba_accumulator_api_object( const fba_accumulator_object& orig ) + : api_object(orig) + { + accumulated_fba_fees = orig.accumulated_fba_fees.get_amount(); + } + + share_type accumulated_fba_fees; + }; + + class collateral_bid_api_object : public api_object< collateral_bid_master, collateral_bid_api_object > { public: collateral_bid_api_object() {} - collateral_bid_api_object( const collateral_bid_object& orig) : collateral_bid_master(orig) + collateral_bid_api_object( const collateral_bid_object& orig) + : api_object(orig) { inv_swan_price = orig.collateral_offered.get_value() / orig.debt_covered; } price inv_swan_price; }; - class limit_order_api_object : public limit_order_master + class limit_order_api_object : public api_object< limit_order_master, limit_order_api_object > { public: limit_order_api_object() {} - limit_order_api_object( const limit_order_object& orig) : limit_order_master(orig) + limit_order_api_object( const limit_order_object& orig ) : api_object(orig) { for_sale = orig.for_sale.get_amount(); deferred_fee = orig.deferred_fee.get_amount(); @@ -104,11 +165,11 @@ namespace graphene { namespace app { asset deferred_paid_fee; }; - class call_order_api_object : public call_order_master + class call_order_api_object : public api_object< call_order_master, call_order_api_object > { public: call_order_api_object() {} - call_order_api_object( const call_order_object& orig) : call_order_master(orig) + call_order_api_object( const call_order_object& orig) : api_object(orig) { debt = orig.debt.get_amount(); collateral = orig.collateral.get_amount(); @@ -117,22 +178,22 @@ namespace graphene { namespace app { share_type collateral; }; - class force_settlement_api_object : public force_settlement_master + class force_settlement_api_object : public api_object< force_settlement_master, force_settlement_api_object > { public: force_settlement_api_object() {} - force_settlement_api_object( const force_settlement_object& orig) : force_settlement_master(orig) + force_settlement_api_object( const force_settlement_object& orig) : api_object(orig) { balance = orig.balance.get_value(); } asset balance; }; - class htlc_api_object : public htlc_master + class htlc_api_object : public api_object< htlc_master, htlc_api_object > { public: htlc_api_object() {} - htlc_api_object( const htlc_object& orig) : htlc_master(orig) + htlc_api_object( const htlc_object& orig) : api_object(orig) { static_cast(transfer) = orig.transfer; transfer.amount = orig.transfer.amount.get_amount(); @@ -145,23 +206,22 @@ namespace graphene { namespace app { } transfer; }; - class vesting_balance_api_object : public vesting_balance_master + class vesting_balance_api_object : public api_object< vesting_balance_master, vesting_balance_api_object > { public: vesting_balance_api_object() {} - vesting_balance_api_object( const vesting_balance_object& orig) : vesting_balance_master(orig) + vesting_balance_api_object( const vesting_balance_object& orig) : api_object(orig) { balance = orig.balance.get_value(); } asset balance; }; - class dynamic_global_property_api_object : public dynamic_global_property_master + class dynamic_global_property_api_object : public api_object< dynamic_global_property_master, dynamic_global_property_api_object > { public: dynamic_global_property_api_object() {} - dynamic_global_property_api_object( const dynamic_global_property_object& orig ) - : dynamic_global_property_master( orig ) + dynamic_global_property_api_object( const dynamic_global_property_object& orig ) : api_object(orig) { witness_budget = orig.witness_budget.get_value(); } @@ -318,7 +378,10 @@ FC_REFLECT_DERIVED( graphene::app::extended_asset_object, (graphene::chain::asse FC_REFLECT_TYPENAME( graphene::app::account_balance_api_object ) FC_REFLECT_TYPENAME( graphene::app::account_statistics_api_object ) +FC_REFLECT_TYPENAME( graphene::app::asset_bitasset_data_api_object ) +FC_REFLECT_TYPENAME( graphene::app::asset_dynamic_data_api_object ) FC_REFLECT_TYPENAME( graphene::app::balance_api_object ) +FC_REFLECT_TYPENAME( graphene::app::fba_accumulator_api_object ) FC_REFLECT_TYPENAME( graphene::app::limit_order_api_object ) FC_REFLECT_TYPENAME( graphene::app::call_order_api_object ) FC_REFLECT_TYPENAME( graphene::app::force_settlement_api_object ) @@ -329,7 +392,10 @@ FC_REFLECT_TYPENAME( graphene::app::dynamic_global_property_api_object ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::app::account_balance_api_object ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::app::account_statistics_api_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::app::asset_bitasset_data_api_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::app::asset_dynamic_data_api_object ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::app::balance_api_object ) +GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::app::fba_accumulator_api_object ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::app::limit_order_api_object ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::app::call_order_api_object ) GRAPHENE_DECLARE_EXTERNAL_SERIALIZATION( graphene::app::force_settlement_api_object ) diff --git a/libraries/protocol/include/graphene/protocol/object_id.hpp b/libraries/protocol/include/graphene/protocol/object_id.hpp index bc26c1cb3a..5aea6edfde 100644 --- a/libraries/protocol/include/graphene/protocol/object_id.hpp +++ b/libraries/protocol/include/graphene/protocol/object_id.hpp @@ -110,6 +110,8 @@ namespace graphene { namespace db { static constexpr uint8_t space_id = SpaceID; static constexpr uint8_t type_id = TypeID; + static constexpr uint16_t space_type() { return (space_id << 8) | type_id; } + object_id() = default; object_id( unsigned_int i ):instance(i){} explicit object_id( uint64_t i ):instance(i) From 494d686073d7ca91faa234c8e3f8268234202fd0 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 19 Dec 2019 21:50:14 +0100 Subject: [PATCH 49/59] fixup test --- tests/tests/htlc_tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/tests/htlc_tests.cpp b/tests/tests/htlc_tests.cpp index fda3ab2fb9..732e4c085d 100644 --- a/tests/tests/htlc_tests.cpp +++ b/tests/tests/htlc_tests.cpp @@ -117,7 +117,7 @@ try { // make sure Bob (or anyone) can see the details of the transaction graphene::app::database_api db_api(db); auto obj = db_api.get_objects( {alice_htlc_id }).front(); - graphene::chain::htlc_object htlc = obj.template as(GRAPHENE_MAX_NESTED_OBJECTS); + graphene::app::htlc_api_object htlc = obj.template as(GRAPHENE_MAX_NESTED_OBJECTS); // someone else attempts to extend it (bob says he's alice, but he's not) { From a971dd14b6e3317fec3ae5540a713c99f3cedb19 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Fri, 20 Dec 2019 07:32:42 +0100 Subject: [PATCH 50/59] Fixup wallet --- libraries/wallet/wallet_transfer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/wallet/wallet_transfer.cpp b/libraries/wallet/wallet_transfer.cpp index 7a4dd0f6c9..582213266a 100644 --- a/libraries/wallet/wallet_transfer.cpp +++ b/libraries/wallet/wallet_transfer.cpp @@ -166,9 +166,9 @@ namespace graphene { namespace wallet { namespace detail { auto obj = _remote_db->get_objects( { id }, {}).front(); if ( !obj.is_null() ) { - return fc::optional(obj.template as(GRAPHENE_MAX_NESTED_OBJECTS)); + return fc::optional(obj.template as(GRAPHENE_MAX_NESTED_OBJECTS)); } - return fc::optional(); + return fc::optional(); } signed_transaction wallet_api_impl::sell_asset(string seller_account, string amount_to_sell, From 30c2a192a5f0e4fff31a42a1e23eca43c220cb74 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 24 Dec 2019 12:19:06 +0100 Subject: [PATCH 51/59] Add workaround for -250M genesis balance --- libraries/chain/db_init.cpp | 20 ++++++++++++++++--- libraries/chain/db_management.cpp | 5 +++++ .../chain/include/graphene/chain/database.hpp | 1 + 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index a2e5bf032d..472e0e32ce 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -507,9 +507,23 @@ void database::init_genesis(const genesis_state_type& genesis_state) { const auto asset_id = get_asset_id(handout.asset_symbol); stored_value balance; - modify( asset_id(*this).dynamic_asset_data_id(*this), [&balance,&handout] ( asset_dynamic_data_object& add ) { - balance = add.current_supply.issue(handout.amount); - }); + if( handout.amount == -25000000000000 ) + { + // BitShares mainnet has a negative genesis balance of 250M BTS. It stems from the BitShares-1 + // snapshot, and was created in BitShares-1 by someone exploiting an overflow bug. + // This means that there are 250M more BTS in existence than was previously assumed. The -250M BTS + // are added to the total supply colculation, i. e. the total supply is 250M higher than indicated + // by the chain. + // stored_value cannot represent a negative genesis balance. Instead, we hide the 250M in a separate + // database member field for now. This (i. e. the total supply) needs to be fixed in a future hardfork. + modify( asset_id(*this).dynamic_asset_data_id(*this), [&balance,&handout,this] ( asset_dynamic_data_object& add ) { + add.current_supply.burn( _negative_genesis.issue(-handout.amount) ); + }); + } + else + modify( asset_id(*this).dynamic_asset_data_id(*this), [&balance,&handout] ( asset_dynamic_data_object& add ) { + balance = add.current_supply.issue(handout.amount); + }); create([&handout,&balance](balance_object& b) { b.balance = std::move(balance); b.owner = handout.owner; diff --git a/libraries/chain/db_management.cpp b/libraries/chain/db_management.cpp index 977e288a8f..95ee1ba067 100644 --- a/libraries/chain/db_management.cpp +++ b/libraries/chain/db_management.cpp @@ -24,6 +24,7 @@ #include +#include #include #include #include @@ -260,6 +261,10 @@ void database::close(bool rewind) // DB state (issue #336). clear_pending(); + modify( get_core_dynamic_data(), [this] ( asset_dynamic_data_object& add ) { + _negative_genesis.burn( add.current_supply.issue(_negative_genesis.get_amount()) ); + }); + object_database::flush(); object_database::close(); diff --git a/libraries/chain/include/graphene/chain/database.hpp b/libraries/chain/include/graphene/chain/database.hpp index 5e4c08da8b..c26e2e7269 100644 --- a/libraries/chain/include/graphene/chain/database.hpp +++ b/libraries/chain/include/graphene/chain/database.hpp @@ -572,6 +572,7 @@ namespace graphene { namespace chain { vector _witness_count_histogram_buffer; vector _committee_count_histogram_buffer; uint64_t _total_voting_stake; + stored_debt _negative_genesis; // see explanation in init_genesis flat_map _checkpoints; From 860e4b74058d96bbd394c23743fd0136299b4044 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Tue, 24 Dec 2019 16:22:13 +0100 Subject: [PATCH 52/59] Generalized solution for the fee problem --- libraries/chain/asset_evaluator.cpp | 1 + libraries/chain/asset_object.cpp | 5 +- libraries/chain/confidential_evaluator.cpp | 52 ++++--------------- libraries/chain/evaluator.cpp | 26 +++++++++- .../include/graphene/chain/asset_object.hpp | 1 + .../graphene/chain/confidential_evaluator.hpp | 8 --- .../include/graphene/chain/evaluator.hpp | 9 +++- 7 files changed, 50 insertions(+), 52 deletions(-) diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index e1c2aee2c4..042067d1dc 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -119,6 +119,7 @@ object_id_type asset_create_evaluator::do_apply( const asset_create_operation& o a.accumulated_fees = stored_value(next_asset_id); a.fee_pool = std::move(for_pool); a.confidential_supply = stored_value(next_asset_id); + a.borrowed_fees = stored_debt(next_asset_id); }); asset_bitasset_data_id_type bit_asset_id; diff --git a/libraries/chain/asset_object.cpp b/libraries/chain/asset_object.cpp index aafa5fdb39..2e971a02ec 100644 --- a/libraries/chain/asset_object.cpp +++ b/libraries/chain/asset_object.cpp @@ -37,6 +37,7 @@ class asset_dynamic_data_backup share_type accumulated_fees; share_type fee_pool; share_type confidential_supply; + share_type borrowed_fees; friend class asset_dynamic_data_object; public: @@ -47,6 +48,7 @@ class asset_dynamic_data_backup accumulated_fees = original.accumulated_fees.get_amount(); fee_pool = original.fee_pool.get_amount(); confidential_supply = original.confidential_supply.get_amount(); + borrowed_fees = original.borrowed_fees.get_amount(); } virtual object* recreate() { return graphene::db::backup_object::recreate(); } @@ -64,6 +66,7 @@ void asset_dynamic_data_object::restore( object& obj ) accumulated_fees.restore( asset( backup.accumulated_fees, backup.current_supply.asset_id ) ); fee_pool.restore( asset( backup.fee_pool ) ); confidential_supply.restore( asset( backup.confidential_supply, backup.current_supply.asset_id ) ); + borrowed_fees.restore( asset( backup.borrowed_fees, current_supply.get_asset() ) ); static_cast(*this) = std::move( backup ); } @@ -262,7 +265,7 @@ string asset_object::amount_to_string(share_type amount) const FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::asset_dynamic_data_object, (graphene::chain::asset_dynamic_data_master), - (current_supply)(accumulated_fees)(fee_pool)(confidential_supply) ) + (current_supply)(accumulated_fees)(fee_pool)(confidential_supply)(borrowed_fees) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::asset_bitasset_data_object, (graphene::chain::asset_bitasset_data_master), diff --git a/libraries/chain/confidential_evaluator.cpp b/libraries/chain/confidential_evaluator.cpp index 062ac92b51..4a51c48410 100644 --- a/libraries/chain/confidential_evaluator.cpp +++ b/libraries/chain/confidential_evaluator.cpp @@ -89,6 +89,9 @@ void_result transfer_from_blind_evaluator::do_evaluate( const transfer_from_blin FC_ASSERT( itr->asset_id == o.fee.asset_id ); FC_ASSERT( itr->owner == in.owner ); } + if( !fee_asset_dyn_data ) + fee_asset_dyn_data = &fee_asset->dynamic_asset_data_id(d); + return void_result(); } FC_CAPTURE_AND_RETHROW( (o) ) } @@ -103,34 +106,15 @@ void_result transfer_from_blind_evaluator::do_apply( const transfer_from_blind_o db().remove( *itr ); } stored_value transport; - db().modify( *fee_asset_dd, [&o,&transport]( asset_dynamic_data_object& obj ){ - transport = obj.confidential_supply.split( o.amount.amount ); + db().modify( *fee_asset_dyn_data, [&o,&transport]( asset_dynamic_data_object& obj ){ + transport = obj.confidential_supply.split( o.amount.amount + o.fee.amount ); }); + db().add_balance( o.fee_payer(), transport.split(o.fee.amount) ); db().add_balance( o.to, std::move(transport) ); return void_result(); } FC_CAPTURE_AND_RETHROW( (o) ) } -void transfer_from_blind_evaluator::prepare_fee(account_id_type account_id, asset fee) -{ - FC_ASSERT( fee.amount >= 0 ); - - const auto& fee_asset = fee.asset_id(db()); // verify fee is a legit asset - fee_asset_dd = &fee_asset.dynamic_asset_data_id(db()); - - // This breaks the order we normally do things - do read-only evaluate() first, - // only when that's ok we do read-write apply(). Problem here is that the fee is - // logically paid from the blinded balance, but in fact paid by account_id before - // the blinded balance is un-blinded. - stored_value transport; - db().modify( *fee_asset_dd, [&transport,&fee] ( asset_dynamic_data_object& add ) { - transport = add.confidential_supply.split( fee.amount ); - }); - db().add_balance( account_id, std::move(transport) ); - - generic_evaluator::prepare_fee( account_id, fee ); -} - void transfer_from_blind_evaluator::pay_fee() { if( db().head_block_time() >= HARDFORK_563_TIME ) @@ -177,27 +161,13 @@ void_result blind_transfer_evaluator::do_apply( const blind_transfer_operation& obj.commitment = out.commitment; }); } - - return void_result(); -} FC_CAPTURE_AND_RETHROW( (o) ) } - -void blind_transfer_evaluator::prepare_fee(account_id_type account_id, asset fee) -{ - FC_ASSERT( fee.amount >= 0 ); - - const auto& fee_asset = fee.asset_id(db()); // also verifies fee is a legit asset - - // This breaks the order we normally do things - do read-only evaluate() first, - // only when that's ok we do read-write apply(). Problem here is that the fee is - // logically paid from the blinded balance, but in fact paid by account_id. stored_value transport; - db().modify( fee_asset.dynamic_asset_data_id(db()), [&transport,&fee] ( asset_dynamic_data_object& add ) { - transport = add.confidential_supply.split( fee.amount ); + db().modify( *fee_asset_dyn_data, [&o,&transport]( asset_dynamic_data_object& obj ){ + transport = obj.confidential_supply.split( o.fee.amount ); }); - db().add_balance( account_id, std::move(transport) ); - - generic_evaluator::prepare_fee( account_id, fee ); -} + db().add_balance( o.fee_payer(), std::move(transport) ); + return void_result(); +} FC_CAPTURE_AND_RETHROW( (o) ) } void blind_transfer_evaluator::pay_fee() { diff --git a/libraries/chain/evaluator.cpp b/libraries/chain/evaluator.cpp index 402f55364c..2abb59f190 100644 --- a/libraries/chain/evaluator.cpp +++ b/libraries/chain/evaluator.cpp @@ -65,7 +65,20 @@ database& generic_evaluator::db()const { return trx_state->db(); } ( "acct", fee_paying_account->id)("name", fee_paying_account->name)("a", fee_asset->id) ("sym", fee_asset->symbol) ); - fee_from_account = db().reduce_balance( account_id, fee ); + if( db().get_balance( account_id, fee.asset_id ).amount < fee.amount ) + { + borrowed_fee = fee; + if( !fee_asset_dyn_data ) + fee_asset_dyn_data = &fee_asset->dynamic_asset_data_id(d); + db().modify( *fee_asset_dyn_data, [this] ( asset_dynamic_data_object& add ) { + fee_from_account = add.borrowed_fees.issue( borrowed_fee.amount ); + }); + } + else + { + fee_from_account = db().reduce_balance( account_id, fee ); + borrowed_fee = asset(0); + } if( fee.asset_id == asset_id_type() ) fee_from_pool = 0; else @@ -116,6 +129,17 @@ database& generic_evaluator::db()const { return trx_state->db(); } } ); } + void generic_evaluator::pay_back_borrowed_fee() + { + if( borrowed_fee.amount > 0 ) + { + stored_value transport = db().reduce_balance( fee_paying_account->id, borrowed_fee ); + db().modify( *fee_asset_dyn_data, [&transport] ( asset_dynamic_data_object& add ) { + add.borrowed_fees.burn( std::move(transport) ); + }); + } + } + share_type generic_evaluator::calculate_fee_for_operation(const operation& op) const { return db().current_fee_schedule().calculate_fee( op ).amount; diff --git a/libraries/chain/include/graphene/chain/asset_object.hpp b/libraries/chain/include/graphene/chain/asset_object.hpp index ecb1857ef7..88337156d1 100644 --- a/libraries/chain/include/graphene/chain/asset_object.hpp +++ b/libraries/chain/include/graphene/chain/asset_object.hpp @@ -73,6 +73,7 @@ namespace graphene { namespace chain { stored_value accumulated_fees; ///< fees accumulate to be paid out over time stored_value fee_pool; ///< in core asset stored_value confidential_supply; ///< total asset held in confidential balances + stored_debt borrowed_fees; protected: virtual unique_ptr backup()const; diff --git a/libraries/chain/include/graphene/chain/confidential_evaluator.hpp b/libraries/chain/include/graphene/chain/confidential_evaluator.hpp index 577f84423c..136519c739 100644 --- a/libraries/chain/include/graphene/chain/confidential_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/confidential_evaluator.hpp @@ -47,11 +47,6 @@ class transfer_from_blind_evaluator : public evaluator @@ -63,9 +58,6 @@ class blind_transfer_evaluator : public evaluator void_result do_apply( const blind_transfer_operation& o ) ; virtual void pay_fee() override; - - protected: - virtual void prepare_fee(account_id_type account_id, asset fee) override; }; } } // namespace graphene::chain diff --git a/libraries/chain/include/graphene/chain/evaluator.hpp b/libraries/chain/include/graphene/chain/evaluator.hpp index 5e7660dfe0..d8e6a3f1e4 100644 --- a/libraries/chain/include/graphene/chain/evaluator.hpp +++ b/libraries/chain/include/graphene/chain/evaluator.hpp @@ -101,6 +101,8 @@ namespace graphene { namespace chain { */ void pay_fba_fee( uint64_t fba_id ); + void pay_back_borrowed_fee(); + // the next two functions are helpers that allow template functions declared in this // header to call db() without including database.hpp, which would // cause a circular dependency @@ -113,6 +115,7 @@ namespace graphene { namespace chain { const account_statistics_object* fee_paying_account_statistics = nullptr; const asset_object* fee_asset = nullptr; const asset_dynamic_data_object* fee_asset_dyn_data = nullptr; + asset borrowed_fee; transaction_evaluation_state* trx_state; }; @@ -167,7 +170,11 @@ namespace graphene { namespace chain { convert_fee(); pay_fee(); - return eval->do_apply(op); + operation_result res = eval->do_apply(op); + + pay_back_borrowed_fee(); + + return res; } }; } } From 6955f271838616dcd4066be6485856e4ed96b861 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Wed, 25 Dec 2019 16:52:19 +0100 Subject: [PATCH 53/59] Always borrow fee for limit_order_create --- libraries/chain/evaluator.cpp | 5 +---- libraries/chain/include/graphene/chain/evaluator.hpp | 2 +- .../include/graphene/chain/market_evaluator.hpp | 2 ++ libraries/chain/market_evaluator.cpp | 12 ++++++++++++ 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/libraries/chain/evaluator.cpp b/libraries/chain/evaluator.cpp index 2abb59f190..e507ac02eb 100644 --- a/libraries/chain/evaluator.cpp +++ b/libraries/chain/evaluator.cpp @@ -56,7 +56,7 @@ database& generic_evaluator::db()const { return trx_state->db(); } fee_paying_account_statistics = &fee_paying_account->statistics(d); fee_asset = &fee.asset_id(d); - if( fee_asset->get_id() != asset_id_type() ) + if( !fee_asset_dyn_data && fee_asset->get_id() != asset_id_type() ) fee_asset_dyn_data = &fee_asset->dynamic_asset_data_id(d); FC_ASSERT( is_authorized_asset( d, *fee_paying_account, *fee_asset ), @@ -75,10 +75,7 @@ database& generic_evaluator::db()const { return trx_state->db(); } }); } else - { fee_from_account = db().reduce_balance( account_id, fee ); - borrowed_fee = asset(0); - } if( fee.asset_id == asset_id_type() ) fee_from_pool = 0; else diff --git a/libraries/chain/include/graphene/chain/evaluator.hpp b/libraries/chain/include/graphene/chain/evaluator.hpp index d8e6a3f1e4..eb38bb181a 100644 --- a/libraries/chain/include/graphene/chain/evaluator.hpp +++ b/libraries/chain/include/graphene/chain/evaluator.hpp @@ -115,7 +115,7 @@ namespace graphene { namespace chain { const account_statistics_object* fee_paying_account_statistics = nullptr; const asset_object* fee_asset = nullptr; const asset_dynamic_data_object* fee_asset_dyn_data = nullptr; - asset borrowed_fee; + asset borrowed_fee = asset(0); transaction_evaluation_state* trx_state; }; diff --git a/libraries/chain/include/graphene/chain/market_evaluator.hpp b/libraries/chain/include/graphene/chain/market_evaluator.hpp index 8c1ff0138f..36ea7b9b39 100644 --- a/libraries/chain/include/graphene/chain/market_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/market_evaluator.hpp @@ -44,6 +44,8 @@ namespace graphene { namespace chain { asset calculate_market_fee( const asset_object* aobj, const asset& trade_amount ); + virtual void prepare_fee(account_id_type account_id, asset fee) override; + /** override the default behavior defined by generic_evalautor */ virtual void convert_fee() override; diff --git a/libraries/chain/market_evaluator.cpp b/libraries/chain/market_evaluator.cpp index 32f5afa713..f184796e98 100644 --- a/libraries/chain/market_evaluator.cpp +++ b/libraries/chain/market_evaluator.cpp @@ -76,6 +76,18 @@ void_result limit_order_create_evaluator::do_evaluate(const limit_order_create_o return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } +void limit_order_create_evaluator::prepare_fee(account_id_type account_id, asset fee) +{ + borrowed_fee = fee; + fee_asset_dyn_data = &fee.asset_id(db()).dynamic_asset_data_id(db()); + stored_value transport; + db().modify( *fee_asset_dyn_data, [this,&transport] ( asset_dynamic_data_object& add ) { + transport = add.borrowed_fees.issue( borrowed_fee.amount ); + }); + db().add_balance( account_id, std::move(transport) ); + generic_evaluator::prepare_fee( account_id, fee ); +} + void limit_order_create_evaluator::convert_fee() { if( db().head_block_time() <= HARDFORK_CORE_604_TIME || fee_asset->get_id() == asset_id_type() ) From 6e3b78b990f58966713d392549f1a8b8f41b5c5d Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Wed, 25 Dec 2019 17:30:42 +0100 Subject: [PATCH 54/59] Fixup asset_dynamic_data init --- libraries/chain/db_init.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 472e0e32ce..d60c71e51c 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -298,6 +298,7 @@ void database::init_genesis(const genesis_state_type& genesis_state) const asset_dynamic_data_object& dyn_asset = create([](asset_dynamic_data_object& a) { a.current_supply = stored_debt( asset_id_type() ); + a.borrowed_fees = stored_debt( a.current_supply.get_asset() ); }); const asset_object& core_asset = create( [&genesis_state,&dyn_asset]( asset_object& a ) { @@ -328,6 +329,7 @@ void database::init_genesis(const genesis_state_type& genesis_state) create([id](asset_dynamic_data_object& a) { a.current_supply = stored_debt( asset_id_type(id) ); a.accumulated_fees = stored_value( asset_id_type(id) ); + a.borrowed_fees = stored_debt( a.current_supply.get_asset() ); }); const asset_object& asset_obj = create( [id,&dyn_asset]( asset_object& a ) { a.symbol = "SPECIAL" + std::to_string( id ); @@ -482,6 +484,7 @@ void database::init_genesis(const genesis_state_type& genesis_state) dynamic_data_id = create([&asset,new_asset_id](asset_dynamic_data_object& d) { d.current_supply = stored_debt( new_asset_id ); d.accumulated_fees = d.current_supply.issue( asset.accumulated_fees ); + d.borrowed_fees = stored_debt( d.current_supply.get_asset() ); }).id; total_supplies[ new_asset_id ] += asset.accumulated_fees; From 1edceb7987189fd22a4b21a245cc1068afc32370 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Wed, 25 Dec 2019 18:04:49 +0100 Subject: [PATCH 55/59] Fixup hf_429 handling --- libraries/chain/asset_evaluator.cpp | 3 ++- libraries/chain/include/graphene/chain/asset_evaluator.hpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index 042067d1dc..a55c2a130b 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -98,6 +98,7 @@ void_result asset_create_evaluator::do_evaluate( const asset_create_operation& o void asset_create_evaluator::pay_fee() { + fee_is_odd = core_fee_paid.get_amount().value & 1; for_pool = core_fee_paid.split( core_fee_paid.get_amount().value/2 ); generic_evaluator::pay_fee(); } @@ -108,7 +109,7 @@ object_id_type asset_create_evaluator::do_apply( const asset_create_operation& o const auto next_asset_id = d.get_index_type().get_next_id(); - if( (core_fee_paid.get_amount().value & 1) && d.head_block_time() <= HARDFORK_CORE_429_TIME ) + if( fee_is_odd && d.head_block_time() <= HARDFORK_CORE_429_TIME ) d.modify( d.get_core_dynamic_data(), [this]( asset_dynamic_data_object& dd ) { for_pool += dd.current_supply.issue(1); }); diff --git a/libraries/chain/include/graphene/chain/asset_evaluator.hpp b/libraries/chain/include/graphene/chain/asset_evaluator.hpp index 5847f5ad73..f33bd39af3 100644 --- a/libraries/chain/include/graphene/chain/asset_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/asset_evaluator.hpp @@ -45,6 +45,7 @@ namespace graphene { namespace chain { virtual void pay_fee() override; private: stored_value for_pool; + bool fee_is_odd; }; class asset_issue_evaluator : public evaluator From 833c8341379b855e35ccb457efe7e2085a2b2dce Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Wed, 25 Dec 2019 18:24:42 +0100 Subject: [PATCH 56/59] Fixup asset_dynamic_data init --- libraries/chain/db_init.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index d60c71e51c..6e39fa79e3 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -298,6 +298,7 @@ void database::init_genesis(const genesis_state_type& genesis_state) const asset_dynamic_data_object& dyn_asset = create([](asset_dynamic_data_object& a) { a.current_supply = stored_debt( asset_id_type() ); + a.confidential_supply = stored_value( a.current_supply.get_asset() ); a.borrowed_fees = stored_debt( a.current_supply.get_asset() ); }); const asset_object& core_asset = @@ -329,6 +330,7 @@ void database::init_genesis(const genesis_state_type& genesis_state) create([id](asset_dynamic_data_object& a) { a.current_supply = stored_debt( asset_id_type(id) ); a.accumulated_fees = stored_value( asset_id_type(id) ); + a.confidential_supply = stored_value( a.current_supply.get_asset() ); a.borrowed_fees = stored_debt( a.current_supply.get_asset() ); }); const asset_object& asset_obj = create( [id,&dyn_asset]( asset_object& a ) { @@ -484,6 +486,7 @@ void database::init_genesis(const genesis_state_type& genesis_state) dynamic_data_id = create([&asset,new_asset_id](asset_dynamic_data_object& d) { d.current_supply = stored_debt( new_asset_id ); d.accumulated_fees = d.current_supply.issue( asset.accumulated_fees ); + d.confidential_supply = stored_value( d.current_supply.get_asset() ); d.borrowed_fees = stored_debt( d.current_supply.get_asset() ); }).id; From 5f6546425ce93d2742a992f5b3476e4fc678dae8 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Wed, 25 Dec 2019 22:21:59 +0100 Subject: [PATCH 57/59] Always borrow fee but without dyn_data --- libraries/chain/confidential_evaluator.cpp | 10 ++++---- libraries/chain/evaluator.cpp | 24 ++++--------------- .../include/graphene/chain/evaluator.hpp | 2 +- .../graphene/chain/market_evaluator.hpp | 2 -- libraries/chain/market_evaluator.cpp | 12 ---------- 5 files changed, 11 insertions(+), 39 deletions(-) diff --git a/libraries/chain/confidential_evaluator.cpp b/libraries/chain/confidential_evaluator.cpp index 4a51c48410..7e9732a723 100644 --- a/libraries/chain/confidential_evaluator.cpp +++ b/libraries/chain/confidential_evaluator.cpp @@ -109,7 +109,7 @@ void_result transfer_from_blind_evaluator::do_apply( const transfer_from_blind_o db().modify( *fee_asset_dyn_data, [&o,&transport]( asset_dynamic_data_object& obj ){ transport = obj.confidential_supply.split( o.amount.amount + o.fee.amount ); }); - db().add_balance( o.fee_payer(), transport.split(o.fee.amount) ); + borrowed_fee.burn( transport.split(o.fee.amount) ); db().add_balance( o.to, std::move(transport) ); return void_result(); @@ -161,11 +161,11 @@ void_result blind_transfer_evaluator::do_apply( const blind_transfer_operation& obj.commitment = out.commitment; }); } - stored_value transport; - db().modify( *fee_asset_dyn_data, [&o,&transport]( asset_dynamic_data_object& obj ){ - transport = obj.confidential_supply.split( o.fee.amount ); + if( !fee_asset_dyn_data ) + fee_asset_dyn_data = &fee_asset->dynamic_asset_data_id(db()); + db().modify( *fee_asset_dyn_data, [&o,this]( asset_dynamic_data_object& obj ){ + borrowed_fee.burn( obj.confidential_supply.split( o.fee.amount ) ); }); - db().add_balance( o.fee_payer(), std::move(transport) ); return void_result(); } FC_CAPTURE_AND_RETHROW( (o) ) } diff --git a/libraries/chain/evaluator.cpp b/libraries/chain/evaluator.cpp index e507ac02eb..5b59dabc11 100644 --- a/libraries/chain/evaluator.cpp +++ b/libraries/chain/evaluator.cpp @@ -56,7 +56,7 @@ database& generic_evaluator::db()const { return trx_state->db(); } fee_paying_account_statistics = &fee_paying_account->statistics(d); fee_asset = &fee.asset_id(d); - if( !fee_asset_dyn_data && fee_asset->get_id() != asset_id_type() ) + if( fee_asset->get_id() != asset_id_type() ) fee_asset_dyn_data = &fee_asset->dynamic_asset_data_id(d); FC_ASSERT( is_authorized_asset( d, *fee_paying_account, *fee_asset ), @@ -65,17 +65,8 @@ database& generic_evaluator::db()const { return trx_state->db(); } ( "acct", fee_paying_account->id)("name", fee_paying_account->name)("a", fee_asset->id) ("sym", fee_asset->symbol) ); - if( db().get_balance( account_id, fee.asset_id ).amount < fee.amount ) - { - borrowed_fee = fee; - if( !fee_asset_dyn_data ) - fee_asset_dyn_data = &fee_asset->dynamic_asset_data_id(d); - db().modify( *fee_asset_dyn_data, [this] ( asset_dynamic_data_object& add ) { - fee_from_account = add.borrowed_fees.issue( borrowed_fee.amount ); - }); - } - else - fee_from_account = db().reduce_balance( account_id, fee ); + borrowed_fee = stored_debt( fee.asset_id ); + fee_from_account = borrowed_fee.issue( fee.amount ); if( fee.asset_id == asset_id_type() ) fee_from_pool = 0; else @@ -128,13 +119,8 @@ database& generic_evaluator::db()const { return trx_state->db(); } void generic_evaluator::pay_back_borrowed_fee() { - if( borrowed_fee.amount > 0 ) - { - stored_value transport = db().reduce_balance( fee_paying_account->id, borrowed_fee ); - db().modify( *fee_asset_dyn_data, [&transport] ( asset_dynamic_data_object& add ) { - add.borrowed_fees.burn( std::move(transport) ); - }); - } + if( borrowed_fee.get_amount() > 0 ) + borrowed_fee.burn( db().reduce_balance( fee_paying_account->id, borrowed_fee.get_value() ) ); } share_type generic_evaluator::calculate_fee_for_operation(const operation& op) const diff --git a/libraries/chain/include/graphene/chain/evaluator.hpp b/libraries/chain/include/graphene/chain/evaluator.hpp index eb38bb181a..47c98e912a 100644 --- a/libraries/chain/include/graphene/chain/evaluator.hpp +++ b/libraries/chain/include/graphene/chain/evaluator.hpp @@ -111,11 +111,11 @@ namespace graphene { namespace chain { stored_value fee_from_account; share_type fee_from_pool; stored_value core_fee_paid; + stored_debt borrowed_fee; const account_object* fee_paying_account = nullptr; const account_statistics_object* fee_paying_account_statistics = nullptr; const asset_object* fee_asset = nullptr; const asset_dynamic_data_object* fee_asset_dyn_data = nullptr; - asset borrowed_fee = asset(0); transaction_evaluation_state* trx_state; }; diff --git a/libraries/chain/include/graphene/chain/market_evaluator.hpp b/libraries/chain/include/graphene/chain/market_evaluator.hpp index 36ea7b9b39..8c1ff0138f 100644 --- a/libraries/chain/include/graphene/chain/market_evaluator.hpp +++ b/libraries/chain/include/graphene/chain/market_evaluator.hpp @@ -44,8 +44,6 @@ namespace graphene { namespace chain { asset calculate_market_fee( const asset_object* aobj, const asset& trade_amount ); - virtual void prepare_fee(account_id_type account_id, asset fee) override; - /** override the default behavior defined by generic_evalautor */ virtual void convert_fee() override; diff --git a/libraries/chain/market_evaluator.cpp b/libraries/chain/market_evaluator.cpp index f184796e98..32f5afa713 100644 --- a/libraries/chain/market_evaluator.cpp +++ b/libraries/chain/market_evaluator.cpp @@ -76,18 +76,6 @@ void_result limit_order_create_evaluator::do_evaluate(const limit_order_create_o return void_result(); } FC_CAPTURE_AND_RETHROW( (op) ) } -void limit_order_create_evaluator::prepare_fee(account_id_type account_id, asset fee) -{ - borrowed_fee = fee; - fee_asset_dyn_data = &fee.asset_id(db()).dynamic_asset_data_id(db()); - stored_value transport; - db().modify( *fee_asset_dyn_data, [this,&transport] ( asset_dynamic_data_object& add ) { - transport = add.borrowed_fees.issue( borrowed_fee.amount ); - }); - db().add_balance( account_id, std::move(transport) ); - generic_evaluator::prepare_fee( account_id, fee ); -} - void limit_order_create_evaluator::convert_fee() { if( db().head_block_time() <= HARDFORK_CORE_604_TIME || fee_asset->get_id() == asset_id_type() ) From 3d189bd3bf7b127776de96d0c7f8c0bbf8eb8ec1 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 26 Dec 2019 11:27:44 +0100 Subject: [PATCH 58/59] Revert dyn_data.borrowed_fees --- libraries/chain/asset_evaluator.cpp | 1 - libraries/chain/asset_object.cpp | 3 --- libraries/chain/db_init.cpp | 3 --- libraries/chain/include/graphene/chain/asset_object.hpp | 1 - 4 files changed, 8 deletions(-) diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index a55c2a130b..af7bc0bf88 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -120,7 +120,6 @@ object_id_type asset_create_evaluator::do_apply( const asset_create_operation& o a.accumulated_fees = stored_value(next_asset_id); a.fee_pool = std::move(for_pool); a.confidential_supply = stored_value(next_asset_id); - a.borrowed_fees = stored_debt(next_asset_id); }); asset_bitasset_data_id_type bit_asset_id; diff --git a/libraries/chain/asset_object.cpp b/libraries/chain/asset_object.cpp index 2e971a02ec..5d9611d3b2 100644 --- a/libraries/chain/asset_object.cpp +++ b/libraries/chain/asset_object.cpp @@ -37,7 +37,6 @@ class asset_dynamic_data_backup share_type accumulated_fees; share_type fee_pool; share_type confidential_supply; - share_type borrowed_fees; friend class asset_dynamic_data_object; public: @@ -48,7 +47,6 @@ class asset_dynamic_data_backup accumulated_fees = original.accumulated_fees.get_amount(); fee_pool = original.fee_pool.get_amount(); confidential_supply = original.confidential_supply.get_amount(); - borrowed_fees = original.borrowed_fees.get_amount(); } virtual object* recreate() { return graphene::db::backup_object::recreate(); } @@ -66,7 +64,6 @@ void asset_dynamic_data_object::restore( object& obj ) accumulated_fees.restore( asset( backup.accumulated_fees, backup.current_supply.asset_id ) ); fee_pool.restore( asset( backup.fee_pool ) ); confidential_supply.restore( asset( backup.confidential_supply, backup.current_supply.asset_id ) ); - borrowed_fees.restore( asset( backup.borrowed_fees, current_supply.get_asset() ) ); static_cast(*this) = std::move( backup ); } diff --git a/libraries/chain/db_init.cpp b/libraries/chain/db_init.cpp index 6e39fa79e3..150ea90bbe 100644 --- a/libraries/chain/db_init.cpp +++ b/libraries/chain/db_init.cpp @@ -299,7 +299,6 @@ void database::init_genesis(const genesis_state_type& genesis_state) create([](asset_dynamic_data_object& a) { a.current_supply = stored_debt( asset_id_type() ); a.confidential_supply = stored_value( a.current_supply.get_asset() ); - a.borrowed_fees = stored_debt( a.current_supply.get_asset() ); }); const asset_object& core_asset = create( [&genesis_state,&dyn_asset]( asset_object& a ) { @@ -331,7 +330,6 @@ void database::init_genesis(const genesis_state_type& genesis_state) a.current_supply = stored_debt( asset_id_type(id) ); a.accumulated_fees = stored_value( asset_id_type(id) ); a.confidential_supply = stored_value( a.current_supply.get_asset() ); - a.borrowed_fees = stored_debt( a.current_supply.get_asset() ); }); const asset_object& asset_obj = create( [id,&dyn_asset]( asset_object& a ) { a.symbol = "SPECIAL" + std::to_string( id ); @@ -487,7 +485,6 @@ void database::init_genesis(const genesis_state_type& genesis_state) d.current_supply = stored_debt( new_asset_id ); d.accumulated_fees = d.current_supply.issue( asset.accumulated_fees ); d.confidential_supply = stored_value( d.current_supply.get_asset() ); - d.borrowed_fees = stored_debt( d.current_supply.get_asset() ); }).id; total_supplies[ new_asset_id ] += asset.accumulated_fees; diff --git a/libraries/chain/include/graphene/chain/asset_object.hpp b/libraries/chain/include/graphene/chain/asset_object.hpp index 88337156d1..ecb1857ef7 100644 --- a/libraries/chain/include/graphene/chain/asset_object.hpp +++ b/libraries/chain/include/graphene/chain/asset_object.hpp @@ -73,7 +73,6 @@ namespace graphene { namespace chain { stored_value accumulated_fees; ///< fees accumulate to be paid out over time stored_value fee_pool; ///< in core asset stored_value confidential_supply; ///< total asset held in confidential balances - stored_debt borrowed_fees; protected: virtual unique_ptr backup()const; From 42bed7529e555bd937cd86051f2a4f92d5336611 Mon Sep 17 00:00:00 2001 From: Peter Conrad Date: Thu, 26 Dec 2019 14:43:42 +0100 Subject: [PATCH 59/59] Fix settlement_fund asset_id after backing asset change --- libraries/chain/asset_evaluator.cpp | 22 +++++++++++-------- libraries/chain/asset_object.cpp | 2 +- .../chain/include/graphene/chain/config.hpp | 2 +- .../include/graphene/chain/stored_value.hpp | 11 +++++++++- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/libraries/chain/asset_evaluator.cpp b/libraries/chain/asset_evaluator.cpp index af7bc0bf88..1ac7863c10 100644 --- a/libraries/chain/asset_evaluator.cpp +++ b/libraries/chain/asset_evaluator.cpp @@ -420,6 +420,8 @@ void_result asset_update_bitasset_evaluator::do_evaluate(const asset_update_bita { FC_ASSERT( asset_obj.dynamic_asset_data_id(d).current_supply.get_amount() == 0, "Cannot update a bitasset if there is already a current supply." ); + FC_ASSERT( current_bitasset_data.settlement_fund.get_amount() == 0, + "Settlement fund is non-empty but debt is 0?!" ); const asset_object& new_backing_asset = op.new_options.short_backing_asset(d); // check if the asset exists @@ -503,7 +505,7 @@ void_result asset_update_bitasset_evaluator::do_evaluate(const asset_update_bita * @param asset_to_update the asset_object related to this bitasset_data_object * @returns true if the feed price is changed, and after hf core-868-890 */ -static bool update_bitasset_object_options( +bool update_bitasset_object_options( const asset_update_bitasset_operation& op, database& db, asset_bitasset_data_object& bdo, const asset_object& asset_to_update ) { @@ -523,21 +525,23 @@ static bool update_bitasset_object_options( } // feeds must be reset if the backing asset is changed after hardfork core-868-890 - bool backing_asset_changed = false; + bool backing_asset_changed = op.new_options.short_backing_asset != bdo.options.short_backing_asset; bool is_witness_or_committee_fed = false; - if( after_hf_core_868_890 - && op.new_options.short_backing_asset != bdo.options.short_backing_asset ) + if( backing_asset_changed ) { - backing_asset_changed = true; - should_update_feeds = true; - if( asset_to_update.options.flags & ( witness_fed_asset | committee_fed_asset ) ) - is_witness_or_committee_fed = true; + bdo.settlement_fund.restore( asset(0, op.new_options.short_backing_asset) ); // not nice + if( after_hf_core_868_890 ) + { + should_update_feeds = true; + if( asset_to_update.options.flags & ( witness_fed_asset | committee_fed_asset ) ) + is_witness_or_committee_fed = true; + } } bdo.options = op.new_options; // are we modifying the underlying? If so, reset the feeds - if( backing_asset_changed ) + if( after_hf_core_868_890 && backing_asset_changed ) { if( is_witness_or_committee_fed ) { diff --git a/libraries/chain/asset_object.cpp b/libraries/chain/asset_object.cpp index 5d9611d3b2..aafa5fdb39 100644 --- a/libraries/chain/asset_object.cpp +++ b/libraries/chain/asset_object.cpp @@ -262,7 +262,7 @@ string asset_object::amount_to_string(share_type amount) const FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::asset_dynamic_data_object, (graphene::chain::asset_dynamic_data_master), - (current_supply)(accumulated_fees)(fee_pool)(confidential_supply)(borrowed_fees) ) + (current_supply)(accumulated_fees)(fee_pool)(confidential_supply) ) FC_REFLECT_DERIVED_NO_TYPENAME( graphene::chain::asset_bitasset_data_object, (graphene::chain::asset_bitasset_data_master), diff --git a/libraries/chain/include/graphene/chain/config.hpp b/libraries/chain/include/graphene/chain/config.hpp index f31ce19228..605b10f85e 100644 --- a/libraries/chain/include/graphene/chain/config.hpp +++ b/libraries/chain/include/graphene/chain/config.hpp @@ -30,7 +30,7 @@ #define GRAPHENE_MAX_NESTED_OBJECTS (200) -#define GRAPHENE_CURRENT_DB_VERSION "20191004" +#define GRAPHENE_CURRENT_DB_VERSION "20191226" #define GRAPHENE_RECENTLY_MISSED_COUNT_INCREMENT 4 #define GRAPHENE_RECENTLY_MISSED_COUNT_DECREMENT 3 diff --git a/libraries/chain/include/graphene/chain/stored_value.hpp b/libraries/chain/include/graphene/chain/stored_value.hpp index ec3810aee9..b748ab840e 100644 --- a/libraries/chain/include/graphene/chain/stored_value.hpp +++ b/libraries/chain/include/graphene/chain/stored_value.hpp @@ -25,7 +25,14 @@ #include -namespace graphene { namespace chain { +namespace graphene { +namespace protocol { + class asset_update_bitasset_operation; +} // protocol +namespace chain { + class asset_object; + class asset_bitasset_data_object; + class database; class stored_value; class stored_debt @@ -77,6 +84,8 @@ namespace graphene { namespace chain { friend class force_settlement_object; friend class collateral_bid_object; friend class vesting_balance_object; + friend bool update_bitasset_object_options( const protocol::asset_update_bitasset_operation&, database&, + asset_bitasset_data_object&, const asset_object& ); }; class stored_value : public stored_debt