Skip to content
Permalink
Browse files

eosio.ram payment problem

  • Loading branch information...
moskvanaft committed Jul 6, 2018
1 parent 8390189 commit 6db6e867a7a6722bdec69de132a7c6fd0c3d4fd0
@@ -28,6 +28,13 @@
{"name":"quantity", "type":"asset"},
{"name":"memo", "type":"string"}
]
},{
"name": "close",
"base": "",
"fields": [
{"name":"owner", "type":"account_name"},
{"name":"symbol", "type":"symbol"},
]
},{
"name": "account",
"base": "",
@@ -30,8 +30,9 @@ namespace eosio {
account_name to,
asset quantity,
string memo );



void close( account_name owner, symbol_name symbol );

inline asset get_supply( symbol_name sym )const;

inline asset get_balance( account_name owner, symbol_name sym )const;
@@ -79,9 +79,10 @@ void token::transfer( account_name from,
eosio_assert( quantity.symbol == st.supply.symbol, "symbol precision mismatch" );
eosio_assert( memo.size() <= 256, "memo has more than 256 bytes" );

auto payer = has_auth( to ) ? to : from;

sub_balance( from, quantity );
add_balance( to, quantity, from );
add_balance( to, quantity, payer );
}

void token::sub_balance( account_name owner, asset value ) {
@@ -90,14 +91,9 @@ void token::sub_balance( account_name owner, asset value ) {
const auto& from = from_acnts.get( value.symbol.name(), "no balance object found" );
eosio_assert( from.balance.amount >= value.amount, "overdrawn balance" );


if( from.balance.amount == value.amount ) {
from_acnts.erase( from );
} else {
from_acnts.modify( from, owner, [&]( auto& a ) {
a.balance -= value;
from_acnts.modify( from, owner, [&]( auto& a ) {
a.balance -= value;
});
}
}

void token::add_balance( account_name owner, asset value, account_name ram_payer )
@@ -115,6 +111,14 @@ void token::add_balance( account_name owner, asset value, account_name ram_payer
}
}

void token::close( account_name owner, symbol_name symbol ) {
accounts acnts( _self, owner );
auto it = acnts.find( symbol );
eosio_assert( it != acnts.end(), "Balance row already deleted or never existed. Action won't have any effect." );
eosio_assert( it->balance.amount == 0, "Cannot close because the balance is not zero." );
acnts.erase( it );
}

} /// namespace eosio

EOSIO_ABI( eosio::token, (create)(issue)(transfer) )
EOSIO_ABI( eosio::token, (create)(issue)(transfer)(close) )
@@ -92,6 +92,16 @@ class eosio_token_tester : public tester {
);
}

action_result close( account_name owner,
const string& symbolname ) {
auto symb = eosio::chain::symbol::from_string(symbolname);
auto symbol_code = symb.to_symbol_code().value;
return push_action( owner, N(close), mvo()
( "owner", owner )
( "symbol", symbol_code.to_string() )
);
}

abi_serializer abi_ser;
};

@@ -263,4 +273,32 @@ BOOST_FIXTURE_TEST_CASE( transfer_tests, eosio_token_tester ) try {

} FC_LOG_AND_RETHROW()


BOOST_FIXTURE_TEST_CASE( close_tests, eosio_token_tester ) try {

auto token = create( N(alice), asset::from_string("1000 CERO"));

auto alice_balance = get_account(N(alice), "0,CERO");
BOOST_REQUIRE_EQUAL(true, alice_balance.is_null() );

BOOST_REQUIRE_EQUAL( success(), issue( N(alice), N(alice), asset::from_string("1000 CERO"), "hola" ) );

alice_balance = get_account(N(alice), "0,CERO");
REQUIRE_MATCHING_OBJECT( alice_balance, mvo()
("balance", "1000 CERO")
);

BOOST_REQUIRE_EQUAL( success(), transfer( N(alice), N(bob), asset::from_string("1000 CERO"), "hola" ) );

alice_balance = get_account(N(alice), "0,CERO");
REQUIRE_MATCHING_OBJECT( alice_balance, mvo()
("balance", "0 CERO")
);

BOOST_REQUIRE_EQUAL( success(), close( N(alice), "0,CERO" ) );
alice_balance = get_account(N(alice), "0,CERO");
BOOST_REQUIRE_EQUAL(true, alice_balance.is_null() );

} FC_LOG_AND_RETHROW()

BOOST_AUTO_TEST_SUITE_END()

0 comments on commit 6db6e86

Please sign in to comment.
You can’t perform that action at this time.