Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buy/Sell RAM Notifications and Logging #103

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions contracts/eosio.system/include/eosio.system/eosio.system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1110,6 +1110,18 @@ namespace eosiosystem {
[[eosio::action]]
void buyrambytes( const name& payer, const name& receiver, uint32_t bytes );

/**
* Logging for buyram & buyrambytes action
*
* @param payer - the ram buyer,
* @param receiver - the ram receiver,
* @param quantity - the quantity of tokens to buy ram with.
* @param bytes - the quantity of ram to buy specified in bytes.
* @param ram_bytes - the ram bytes held by receiver after the action.
*/
[[eosio::action]]
void logbuyram( const name& payer, const name& receiver, const asset& quantity, int64_t bytes, int64_t ram_bytes );

/**
* Sell ram action, reduces quota by bytes and then performs an inline transfer of tokens
* to receiver based upon the average purchase price of the original quota.
Expand All @@ -1120,6 +1132,17 @@ namespace eosiosystem {
[[eosio::action]]
void sellram( const name& account, int64_t bytes );

/**
* Logging for sellram action
*
* @param account - the ram seller,
* @param quantity - the quantity of tokens to sell ram with.
* @param bytes - the quantity of ram to sell specified in bytes.
* @param ram_bytes - the ram bytes held by account after the action.
*/
[[eosio::action]]
void logsellram( const name& account, const asset& quantity, int64_t bytes, int64_t ram_bytes );

/**
* Transfer ram action, reduces sender's quota by bytes and increase receiver's quota by bytes.
*
Expand Down Expand Up @@ -1437,7 +1460,9 @@ namespace eosiosystem {
using undelegatebw_action = eosio::action_wrapper<"undelegatebw"_n, &system_contract::undelegatebw>;
using buyram_action = eosio::action_wrapper<"buyram"_n, &system_contract::buyram>;
using buyrambytes_action = eosio::action_wrapper<"buyrambytes"_n, &system_contract::buyrambytes>;
using logbuyram_action = eosio::action_wrapper<"logbuyram"_n, &system_contract::logbuyram>;
using sellram_action = eosio::action_wrapper<"sellram"_n, &system_contract::sellram>;
using logsellram_action = eosio::action_wrapper<"logsellram"_n, &system_contract::logsellram>;
using ramtransfer_action = eosio::action_wrapper<"ramtransfer"_n, &system_contract::ramtransfer>;
using logramchange_action = eosio::action_wrapper<"logramchange"_n, &system_contract::logramchange>;
using refund_action = eosio::action_wrapper<"refund"_n, &system_contract::refund>;
Expand Down Expand Up @@ -1519,8 +1544,8 @@ namespace eosiosystem {
const asset& stake_net_quantity, const asset& stake_cpu_quantity, bool transfer );
void update_voting_power( const name& voter, const asset& total_update );
void set_resource_ram_bytes_limits( const name& owner );
void reduce_ram( const name& owner, int64_t bytes );
void add_ram( const name& owner, int64_t bytes );
int64_t reduce_ram( const name& owner, int64_t bytes );
int64_t add_ram( const name& owner, int64_t bytes );

// defined in voting.cpp
void register_producer( const name& producer, const eosio::block_signing_authority& producer_authority, const std::string& url, uint16_t location );
Expand Down
32 changes: 28 additions & 4 deletions contracts/eosio.system/src/delegate_bandwidth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ namespace eosiosystem {
{
require_auth( payer );
update_ram_supply();
require_recipient(payer);
require_recipient(receiver);

check( quant.symbol == core_symbol(), "must buy ram with core token" );
check( quant.amount > 0, "must purchase a positive amount" );
Expand Down Expand Up @@ -79,7 +81,17 @@ namespace eosiosystem {
_gstate.total_ram_bytes_reserved += uint64_t(bytes_out);
_gstate.total_ram_stake += quant_after_fee.amount;

add_ram( receiver, bytes_out );
const int64_t ram_bytes = add_ram( receiver, bytes_out );

// logging
system_contract::logbuyram_action logbuyram_act{ get_self(), { {get_self(), active_permission} } };
logbuyram_act.send( payer, receiver, quant, bytes_out, ram_bytes );
}

void system_contract::logbuyram( const name& payer, const name& receiver, const asset& quantity, int64_t bytes, int64_t ram_bytes ) {
require_auth( get_self() );
require_recipient(payer);
require_recipient(receiver);
}

/**
Expand All @@ -91,7 +103,8 @@ namespace eosiosystem {
void system_contract::sellram( const name& account, int64_t bytes ) {
require_auth( account );
update_ram_supply();
reduce_ram(account, bytes);
require_recipient(account);
const int64_t ram_bytes = reduce_ram(account, bytes);

asset tokens_out;
auto itr = _rammarket.find(ramcore_symbol.raw());
Expand Down Expand Up @@ -119,6 +132,15 @@ namespace eosiosystem {
transfer_act.send( account, ramfee_account, asset(fee, core_symbol()), "sell ram fee" );
channel_to_rex( ramfee_account, asset(fee, core_symbol() ));
}

// logging
system_contract::logsellram_action logsellram_act{ get_self(), { {get_self(), active_permission} } };
logsellram_act.send( account, tokens_out, bytes, ram_bytes );
}

void system_contract::logsellram( const name& account, const asset& quantity, int64_t bytes, int64_t ram_bytes ) {
require_auth( get_self() );
require_recipient(account);
}

/**
Expand All @@ -140,7 +162,7 @@ namespace eosiosystem {
require_recipient( owner );
}

void system_contract::reduce_ram( const name& owner, int64_t bytes ) {
int64_t system_contract::reduce_ram( const name& owner, int64_t bytes ) {
check( bytes > 0, "cannot reduce negative byte" );
user_resources_table userres( get_self(), owner.value );
auto res_itr = userres.find( owner.value );
Expand All @@ -155,9 +177,10 @@ namespace eosiosystem {
// logging
system_contract::logramchange_action logramchange_act{ get_self(), { {get_self(), active_permission} }};
logramchange_act.send( owner, -bytes, res_itr->ram_bytes );
return res_itr->ram_bytes;
}

void system_contract::add_ram( const name& owner, int64_t bytes ) {
int64_t system_contract::add_ram( const name& owner, int64_t bytes ) {
check( bytes > 0, "cannot add negative byte" );
check( is_account(owner), "owner=" + owner.to_string() + " account does not exist");
user_resources_table userres( get_self(), owner.value );
Expand All @@ -179,6 +202,7 @@ namespace eosiosystem {
// logging
system_contract::logramchange_action logramchange_act{ get_self(), { {get_self(), active_permission} } };
logramchange_act.send( owner, bytes, res_itr->ram_bytes );
return res_itr->ram_bytes;
}

void system_contract::set_resource_ram_bytes_limits( const name& owner ) {
Expand Down