diff --git a/libraries/chain/transfer_evaluator.cpp b/libraries/chain/transfer_evaluator.cpp index 66e5724b..5ec4977b 100644 --- a/libraries/chain/transfer_evaluator.cpp +++ b/libraries/chain/transfer_evaluator.cpp @@ -22,6 +22,7 @@ namespace graphene { namespace chain { void_result transfer_evaluator::do_evaluate( const transfer_operation& op ) { try { + database& d = db(); const account_object& from_account = op.from(d); @@ -29,35 +30,41 @@ void_result transfer_evaluator::do_evaluate( const transfer_operation& op ) const asset_object& asset_type = op.amount.asset_id(d); const asset_object& fee_asset_type = op.fee.asset_id(d); - if( asset_type.options.flags & white_list ) - { - GRAPHENE_ASSERT( - from_account.is_authorized_asset( asset_type ), - transfer_from_account_not_whitelisted, - "'from' account ${from} is not whitelisted for asset ${asset}", - ("from",op.from) - ("asset",op.amount.asset_id) - ); - GRAPHENE_ASSERT( - to_account.is_authorized_asset( asset_type ), - transfer_to_account_not_whitelisted, - "'to' account ${to} is not whitelisted for asset ${asset}", - ("to",op.to) - ("asset",op.amount.asset_id) - ); - } + try { - if( fee_asset_type.options.flags & white_list ) - FC_ASSERT( from_account.is_authorized_asset( asset_type ) ); + if( asset_type.options.flags & white_list ) + { + GRAPHENE_ASSERT( + from_account.is_authorized_asset( asset_type ), + transfer_from_account_not_whitelisted, + "'from' account ${from} is not whitelisted for asset ${asset}", + ("from",op.from) + ("asset",op.amount.asset_id) + ); + GRAPHENE_ASSERT( + to_account.is_authorized_asset( asset_type ), + transfer_to_account_not_whitelisted, + "'to' account ${to} is not whitelisted for asset ${asset}", + ("to",op.to) + ("asset",op.amount.asset_id) + ); + } - if( asset_type.is_transfer_restricted() ) - FC_ASSERT( from_account.id == asset_type.issuer || to_account.id == asset_type.issuer ); + if( fee_asset_type.options.flags & white_list ) + FC_ASSERT( from_account.is_authorized_asset( asset_type ) ); - FC_ASSERT( d.get_balance( from_account, asset_type ).amount >= op.amount.amount, - "", ("total_transfer",op.amount)("balance",d.get_balance(from_account, asset_type).amount) ); + if( asset_type.is_transfer_restricted() ) + FC_ASSERT( from_account.id == asset_type.issuer || to_account.id == asset_type.issuer ); - return void_result(); -} FC_CAPTURE_AND_RETHROW( (op) ) } + bool insufficient_balance = d.get_balance( from_account, asset_type ).amount >= op.amount.amount; + FC_ASSERT( insufficient_balance, + "Insufficient Balance: ${balance}, unable to transfer '${total_transfer}' from account '${a}' to '${t}'", + ("a",from_account.name)("t",to_account.name)("total_transfer",d.to_pretty_string(op.amount))("balance",d.to_pretty_string(d.get_balance(from_account, asset_type))) ); + + return void_result(); + } FC_RETHROW_EXCEPTIONS( error, "Unable to transfer ${a} from ${f} to ${t}", ("a",d.to_pretty_string(op.amount))("f",op.from(d).name)("t",op.to(d).name) ); + +} FC_CAPTURE_AND_RETHROW( (op) ) } void_result transfer_evaluator::do_apply( const transfer_operation& o ) { try { diff --git a/tests/tests/operation_tests.cpp b/tests/tests/operation_tests.cpp index 6804e77b..a20ab56e 100644 --- a/tests/tests/operation_tests.cpp +++ b/tests/tests/operation_tests.cpp @@ -704,10 +704,11 @@ BOOST_AUTO_TEST_CASE( transfer_uia ) BOOST_CHECK_EQUAL(get_balance(nathan, uia), 10000000); transfer_operation top; - top.to = nathan.id; - top.from = genesis.id; + top.from = nathan.id; + top.to = genesis.id; top.amount = uia.amount(5000); trx.operations.push_back(top); + BOOST_TEST_MESSAGE( "Transfering 5000 TEST from nathan to genesis" ); PUSH_TX( db, trx, ~0 ); BOOST_CHECK_EQUAL(get_balance(nathan, uia), 10000000 - 5000); BOOST_CHECK_EQUAL(get_balance(genesis, uia), 5000);