From 8bfc7d06b3348fb55a7dc49f9c69265782b00e67 Mon Sep 17 00:00:00 2001 From: Denis Carriere Date: Sat, 6 Jan 2024 17:19:18 -0500 Subject: [PATCH 1/3] add logbuyram action --- .../include/eosio.system/eosio.system.hpp | 12 ++++++++++++ contracts/eosio.system/src/delegate_bandwidth.cpp | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/contracts/eosio.system/include/eosio.system/eosio.system.hpp b/contracts/eosio.system/include/eosio.system/eosio.system.hpp index 4c2574fa..c6dd81dc 100644 --- a/contracts/eosio.system/include/eosio.system/eosio.system.hpp +++ b/contracts/eosio.system/include/eosio.system/eosio.system.hpp @@ -1110,6 +1110,17 @@ 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 quant - the quantity of tokens to buy ram with. + * @param bytes - the quantity of ram to buy specified in bytes. + */ + [[eosio::action]] + void logbuyram( const name& payer, const name& receiver, const asset& quant, uint32_t 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. @@ -1417,6 +1428,7 @@ 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 refund_action = eosio::action_wrapper<"refund"_n, &system_contract::refund>; using regproducer_action = eosio::action_wrapper<"regproducer"_n, &system_contract::regproducer>; diff --git a/contracts/eosio.system/src/delegate_bandwidth.cpp b/contracts/eosio.system/src/delegate_bandwidth.cpp index f8fc6f67..db620f48 100644 --- a/contracts/eosio.system/src/delegate_bandwidth.cpp +++ b/contracts/eosio.system/src/delegate_bandwidth.cpp @@ -44,6 +44,7 @@ namespace eosiosystem { { require_auth( payer ); update_ram_supply(); + require_recipient(receiver); check( quant.symbol == core_symbol(), "must buy ram with core token" ); check( quant.amount > 0, "must purchase a positive amount" ); @@ -100,6 +101,16 @@ namespace eosiosystem { get_resource_limits( res_itr->owner, ram_bytes, net, cpu ); set_resource_limits( res_itr->owner, res_itr->ram_bytes + ram_gift_bytes, net, cpu ); } + + // logging + system_contract::logbuyram_action logbuyram_act{ get_self(), { {get_self(), active_permission} } }; + logbuyram_act.send( payer, receiver, quant, bytes_out ); + } + + void system_contract::logbuyram( const name& payer, const name& receiver, const asset& quant, uint32_t bytes ) { + require_auth( get_self() ); + require_recipient(payer); + require_recipient(receiver); } /** From 0703ea2ff416e22e5f2ea8bcdaedaf5eee791800 Mon Sep 17 00:00:00 2001 From: Denis Carriere Date: Tue, 9 Jan 2024 16:48:53 -0500 Subject: [PATCH 2/3] add logsellram --- .../include/eosio.system/eosio.system.hpp | 17 +++++++++++++++-- .../eosio.system/src/delegate_bandwidth.cpp | 15 +++++++++++++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/contracts/eosio.system/include/eosio.system/eosio.system.hpp b/contracts/eosio.system/include/eosio.system/eosio.system.hpp index c6dd81dc..384de4c2 100644 --- a/contracts/eosio.system/include/eosio.system/eosio.system.hpp +++ b/contracts/eosio.system/include/eosio.system/eosio.system.hpp @@ -1115,11 +1115,12 @@ namespace eosiosystem { * * @param payer - the ram buyer, * @param receiver - the ram receiver, - * @param quant - the quantity of tokens to buy ram with. + * @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& quant, uint32_t bytes ); + 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 @@ -1131,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 ); + /** * Refund action, this action is called after the delegation-period to claim all pending * unstaked tokens belonging to owner. @@ -1430,6 +1442,7 @@ namespace eosiosystem { 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 refund_action = eosio::action_wrapper<"refund"_n, &system_contract::refund>; using regproducer_action = eosio::action_wrapper<"regproducer"_n, &system_contract::regproducer>; using regproducer2_action = eosio::action_wrapper<"regproducer2"_n, &system_contract::regproducer2>; diff --git a/contracts/eosio.system/src/delegate_bandwidth.cpp b/contracts/eosio.system/src/delegate_bandwidth.cpp index db620f48..4088b97a 100644 --- a/contracts/eosio.system/src/delegate_bandwidth.cpp +++ b/contracts/eosio.system/src/delegate_bandwidth.cpp @@ -44,6 +44,7 @@ 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" ); @@ -104,10 +105,10 @@ namespace eosiosystem { // logging system_contract::logbuyram_action logbuyram_act{ get_self(), { {get_self(), active_permission} } }; - logbuyram_act.send( payer, receiver, quant, bytes_out ); + logbuyram_act.send( payer, receiver, quant, bytes_out, res_itr->ram_bytes ); } - void system_contract::logbuyram( const name& payer, const name& receiver, const asset& quant, uint32_t 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); @@ -122,6 +123,7 @@ namespace eosiosystem { void system_contract::sellram( const name& account, int64_t bytes ) { require_auth( account ); update_ram_supply(); + require_recipient(account); check( bytes > 0, "cannot sell negative byte" ); @@ -167,6 +169,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, res_itr->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); } void validate_b1_vesting( int64_t stake ) { From b21165791801f2d2a8b5ef82d86bae16e0ca3e2e Mon Sep 17 00:00:00 2001 From: Denis Carriere Date: Tue, 16 Jan 2024 14:39:28 -0500 Subject: [PATCH 3/3] return ram_bytes --- .../include/eosio.system/eosio.system.hpp | 4 ++-- contracts/eosio.system/src/delegate_bandwidth.cpp | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/contracts/eosio.system/include/eosio.system/eosio.system.hpp b/contracts/eosio.system/include/eosio.system/eosio.system.hpp index d280c7c9..5f7176f8 100644 --- a/contracts/eosio.system/include/eosio.system/eosio.system.hpp +++ b/contracts/eosio.system/include/eosio.system/eosio.system.hpp @@ -1544,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 ); diff --git a/contracts/eosio.system/src/delegate_bandwidth.cpp b/contracts/eosio.system/src/delegate_bandwidth.cpp index 61cc335b..3cf04021 100644 --- a/contracts/eosio.system/src/delegate_bandwidth.cpp +++ b/contracts/eosio.system/src/delegate_bandwidth.cpp @@ -81,11 +81,11 @@ 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, res_itr->ram_bytes ); + 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 ) { @@ -104,7 +104,7 @@ namespace eosiosystem { require_auth( account ); update_ram_supply(); require_recipient(account); - reduce_ram(account, bytes); + const int64_t ram_bytes = reduce_ram(account, bytes); asset tokens_out; auto itr = _rammarket.find(ramcore_symbol.raw()); @@ -135,7 +135,7 @@ namespace eosiosystem { // logging system_contract::logsellram_action logsellram_act{ get_self(), { {get_self(), active_permission} } }; - logsellram_act.send( account, tokens_out, bytes, res_itr->ram_bytes ); + 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 ) { @@ -162,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 ); @@ -177,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 ); @@ -201,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 ) {