未验证 提交 5e73b664 编写于 作者: D Daniel Larimer 提交者: GitHub

Merge branch 'slim' into currency-test-fixes

......@@ -113,6 +113,26 @@ namespace eosiosystem {
// r->cpu_weight.amount );
}
/**
* This action will buy an exact amount of ram and bill the payer the current market price.
*/
void system_contract::buyrambytes( account_name payer, account_name receiver, uint32_t bytes ) {
const double system_token_supply = eosio::token(N(eosio.token)).get_supply(eosio::symbol_type(system_token_symbol).name()).amount;
const double unstaked_token_supply = system_token_supply - _gstate.total_storage_stake.amount;
const double R = unstaked_token_supply;
const double C = _gstate.free_ram() + bytes;
const double F = _gstate.storage_reserve_ratio / 10000.0;
const double T = bytes;
const double ONE(1.0);
double E = -R * (ONE - std::pow( ONE + T/C, F ) );
int64_t tokens_out = int64_t(E*1.0105);
print( "desired ram: ", bytes, "\n" );
buyram( payer, receiver, asset(tokens_out) );
}
/**
......@@ -176,7 +196,7 @@ namespace eosiosystem {
* refunds the purchase price to the account. In this way there is no profit to be made through buying
* and selling ram.
*/
void system_contract::sellram( account_name account, uint64_t bytes ) {
void system_contract::sellram( account_name account, uint32_t bytes ) {
user_resources_table userres( _self, account );
auto res_itr = userres.find( account );
eosio_assert( res_itr != userres.end(), "no resource row" );
......
......@@ -6,6 +6,21 @@
"fields": [
{"name":"value", "type":"string"}
]
},{
"name": "buyrambytes",
"base": "",
"fields": [
{"name":"payer", "type":"account_name"},
{"name":"receiver", "type":"account_name"},
{"name":"bytes", "type":"uint32"}
]
},{
"name": "sellram",
"base": "",
"fields": [
{"name":"account", "type":"account_name"},
{"name":"bytes", "type":"uint32"}
]
},{
"name": "buyram",
"base": "",
......@@ -179,9 +194,17 @@
],
"actions": [
{
"name": "buyrambytes",
"type": "buyrambytes",
"ricardian_contract": ""
},{
"name": "buyram",
"type": "buyram",
"ricardian_contract": ""
},{
"name": "sellram",
"type": "sellram",
"ricardian_contract": ""
},{
"name": "delegatebw",
"type": "delegatebw",
......
......@@ -38,7 +38,7 @@ EOSIO_ABI( eosiosystem::system_contract,
(setparams)
// delegate_bandwith.cpp
(delegatebw)(undelegatebw)(refund)
(buyram)(sellram)
(buyram)(buyrambytes)(sellram)
// voting.cpp
(regproxy)(regproducer)(unregprod)(voteproducer)
// producer_pay.cpp
......
......@@ -156,12 +156,13 @@ namespace eosiosystem {
* tokens will be executed.
*/
void buyram( account_name buyer, account_name receiver, asset tokens );
void buyrambytes( account_name buyer, account_name receiver, uint32_t bytes );
/**
* Reduces quota my bytes and then performs an inline transfer of tokens
* to receiver based upon the average purchase price of the original quota.
*/
void sellram( account_name receiver, uint64_t bytes );
void sellram( account_name receiver, uint32_t bytes );
/**
* This action is called after the delegation-period to claim all pending
......
......@@ -102,6 +102,17 @@ public:
return push_transaction( trx );
}
action_result buyram( const account_name& payer, account_name receiver, string eosin ) {
return push_action( payer, N(buyram), mvo()( "payer",payer)("receiver",receiver)("quant",eosin) );
}
action_result buyrambytes( const account_name& payer, account_name receiver, uint32_t numbytes ) {
return push_action( payer, N(buyrambytes), mvo()( "payer",payer)("receiver",receiver)("bytes",numbytes) );
}
action_result sellram( const account_name& account, uint32_t numbytes ) {
return push_action( account, N(sellram), mvo()( "account", account)("bytes",numbytes) );
}
action_result push_action( const account_name& signer, const action_name &name, const variant_object &data, bool auth = true ) {
string action_type_name = abi_ser.get_action_type(name);
......@@ -297,6 +308,9 @@ BOOST_FIXTURE_TEST_CASE( stake_unstake, eosio_system_tester ) try {
BOOST_REQUIRE_EQUAL( asset::from_string("1000.0000 EOS"), get_balance( "alice" ) );
BOOST_REQUIRE_EQUAL( success(), stake( "alice", "bob", "200.0000 EOS", "100.0000 EOS" ) );
BOOST_REQUIRE_EQUAL( asset::from_string("700.0000 EOS"), get_balance( "alice" ) );
BOOST_REQUIRE_EQUAL( success(), buyram( "alice", "bob", "200.0000 EOS" ) );
BOOST_REQUIRE_EQUAL( success(), buyrambytes( "alice", "bob", 100 ) );
BOOST_REQUIRE_EQUAL( success(), sellram( "bob", 100 ) );
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册