Skip to content

Commit 9a25f90

Browse files
author
ABW
committed
change assertions in balance objects to conform with extended assertions scheme
1 parent 0c5fd3d commit 9a25f90

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

libraries/chain/include/hive/chain/util/balance.hpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,15 +195,17 @@ inline void balance_base::transfer_from( balance_base& source, const asset& delt
195195
{
196196
funds += delta;
197197
source.funds -= delta;
198-
FC_ASSERT( is_valid() && source.is_valid() && "transfer asset to balance", "balance underflow" );
198+
HIVE_CHAIN_BALANCE_ASSERT( is_valid() && source.is_valid() && "transfer asset to balance",
199+
delta, "balance underflow", ( "destination", funds )( "source", source.funds ) );
199200
}
200201

201202
template< uint32_t _SYMBOL >
202203
inline void balance_base::transfer_from( tiny_balance_base< _SYMBOL >& source, const tiny_asset< _SYMBOL >& delta )
203204
{
204205
this->funds += delta.to_asset();
205206
source.funds -= delta;
206-
FC_ASSERT( this->is_valid() && source.is_valid() && "transfer tiny_asset to balance", "balance underflow" );
207+
HIVE_CHAIN_BALANCE_ASSERT( this->is_valid() && source.is_valid() && "transfer tiny_asset to balance",
208+
delta, "balance underflow", ( "destination", this->funds )( "source", source.funds ) );
207209
}
208210

209211
inline void balance_base::transfer_from( balance_base& source )
@@ -244,15 +246,17 @@ inline void tiny_balance_base< _SYMBOL >::transfer_from( balance_base& source, c
244246
{
245247
this->funds += matching_asset( delta );
246248
source.funds -= delta;
247-
FC_ASSERT( this->is_valid() && source.is_valid() && "transfer asset to tiny_balance", "balance underflow" );
249+
HIVE_CHAIN_BALANCE_ASSERT( this->is_valid() && source.is_valid() && "transfer asset to tiny_balance",
250+
delta, "balance underflow", ( "destination", this->funds )( "source", source.funds ) );
248251
}
249252

250253
template< uint32_t _SYMBOL >
251254
inline void tiny_balance_base< _SYMBOL >::transfer_from( tiny_balance_base& source, const matching_asset& delta )
252255
{
253256
this->funds += delta;
254257
source.funds -= delta;
255-
FC_ASSERT( this->is_valid() && source.is_valid() && "transfer tiny_asset to tiny_balance", "balance underflow" );
258+
HIVE_CHAIN_BALANCE_ASSERT( this->is_valid() && source.is_valid() && "transfer tiny_asset to tiny_balance",
259+
delta, "balance underflow", ( "destination", this->funds )( "source", source.funds ) );
256260
}
257261

258262
/**
@@ -318,15 +322,15 @@ class temp_balance final : public balance_base
318322
temp_balance( temp_balance&& b ) = default;
319323
temp_balance& operator=( temp_balance&& b )
320324
{
321-
FC_ASSERT( is_empty() && "temp_balance move assign", "Destruction of funds" );
325+
HIVE_CHAIN_BALANCE_ASSERT( is_empty() && "temp_balance move assign", funds, "Destruction of funds" );
322326
balance_base::operator=( std::move( b ) );
323327
return *this;
324328
}
325329

326330
~temp_balance() noexcept( false )
327331
{
328332
if( std::uncaught_exceptions() == 0 )
329-
FC_ASSERT( is_empty() && "temp_balance", "Destruction of funds" );
333+
HIVE_CHAIN_BALANCE_ASSERT( is_empty() && "temp_balance", funds, "Destruction of funds" );
330334
}
331335

332336
// can set or clear balance with arbitrary value; temporary - to be removed once balance_object.md task is fully done
@@ -347,15 +351,15 @@ class temp_tiny_balance final : public tiny_balance_base< _SYMBOL >
347351
// creates asset out of thin air (remember to update total counters in dgpo after call)
348352
void issue_asset( const matching_asset& a )
349353
{
350-
FC_ASSERT( a.amount >= 0 && "issue", "Can't issue negative funds" );
354+
HIVE_CHAIN_ASSET_ASSERT( a.amount >= 0 && "issue", a, "Can't issue negative funds" );
351355
this->funds += a;
352356
}
353357
// burns asset into void (remember to update total counters in dgpo after call)
354358
void burn_asset( const matching_asset& a )
355359
{
356-
FC_ASSERT( a.amount >= 0 && "burn", "Can't burn negative funds" );
360+
HIVE_CHAIN_ASSET_ASSERT( a.amount >= 0 && "burn", a, "Can't burn negative funds" );
357361
this->funds -= a;
358-
FC_ASSERT( this->is_valid(), "Balance underflow" );
362+
HIVE_CHAIN_BALANCE_ASSERT( this->is_valid(), a, "Balance underflow", ( "balance", this->funds ) );
359363
}
360364

361365
temp_tiny_balance( const temp_tiny_balance& ) = delete;
@@ -367,15 +371,15 @@ class temp_tiny_balance final : public tiny_balance_base< _SYMBOL >
367371
temp_tiny_balance( temp_tiny_balance&& b ) = default;
368372
temp_tiny_balance& operator=( temp_tiny_balance&& b )
369373
{
370-
FC_ASSERT( this->is_empty() && "temp_tiny_balance move assign", "Destruction of funds" );
374+
HIVE_CHAIN_BALANCE_ASSERT( this->is_empty() && "temp_tiny_balance move assign", this->funds, "Destruction of funds" );
371375
tiny_balance_base< _SYMBOL >::operator=( std::move( b ) );
372376
return *this;
373377
}
374378

375379
~temp_tiny_balance() noexcept( false )
376380
{
377381
if( std::uncaught_exceptions() == 0 )
378-
FC_ASSERT( this->is_empty() && "temp_tiny_balance", "Destruction of funds" );
382+
HIVE_CHAIN_BALANCE_ASSERT( this->is_empty() && "temp_tiny_balance", this->funds, "Destruction of funds" );
379383
}
380384

381385
// can set or clear balance with arbitrary value; temporary - to be removed once balance_object.md task is fully done

0 commit comments

Comments
 (0)