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

New ram_actions to transfer ram between accounts #112

Merged
merged 2 commits into from
Feb 7, 2024
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
102 changes: 99 additions & 3 deletions contracts/eosio.system/include/eosio.system/eosio.system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,29 @@ namespace eosiosystem {
asset stake_change;
};

struct action_return_sellram {
name account;
asset quantity;
int64_t bytes_sold;
int64_t ram_bytes;
};

struct action_return_buyram {
name payer;
name receiver;
asset quantity;
int64_t bytes_purchased;
int64_t ram_bytes;
};

struct action_return_ramtransfer {
name from;
name to;
int64_t bytes;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bytes could be renamed to transferred_bytes in the Reference Contracts. Since this PR is a merge. Don't change it now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ramburn also returns the action_return_ramtransfer, and for that reason we left the field name as bytes.

int64_t from_ram_bytes;
int64_t to_ram_bytes;
};

struct powerup_config_resource {
std::optional<int64_t> current_weight_ratio; // Immediately set weight_ratio to this amount. 1x = 10^15. 0.01x = 10^13.
// Do not specify to preserve the existing setting or use the default;
Expand Down Expand Up @@ -1097,7 +1120,7 @@ namespace eosiosystem {
* @param quant - the quantity of tokens to buy ram with.
*/
[[eosio::action]]
void buyram( const name& payer, const name& receiver, const asset& quant );
action_return_buyram buyram( const name& payer, const name& receiver, const asset& quant );

/**
* Buy a specific amount of ram bytes action. Increases receiver's ram in quantity of bytes provided.
Expand All @@ -1108,7 +1131,30 @@ namespace eosiosystem {
* @param bytes - the quantity of ram to buy specified in bytes.
*/
[[eosio::action]]
void buyrambytes( const name& payer, const name& receiver, uint32_t bytes );
action_return_buyram buyrambytes( const name& payer, const name& receiver, uint32_t bytes );

/**
* The buyramself action is designed to enhance the permission security by allowing an account to purchase RAM exclusively for itself.
* This action prevents the potential risk associated with standard actions like buyram and buyrambytes,
* which can transfer EOS tokens out of the account, acting as a proxy for eosio.token::transfer.
*
* @param account - the ram buyer and receiver,
* @param quant - the quantity of tokens to buy ram with.
*/
[[eosio::action]]
action_return_buyram buyramself( const name& account, const asset& quant );

/**
* 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
Expand All @@ -1118,7 +1164,49 @@ namespace eosiosystem {
* @param bytes - the amount of ram to sell in bytes.
*/
[[eosio::action]]
void sellram( const name& account, int64_t bytes );
action_return_sellram 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.
*
* @param from - the ram sender account,
* @param to - the ram receiver account,
* @param bytes - the amount of ram to transfer in bytes,
* @param memo - the memo string to accompany the transaction.
*/
[[eosio::action]]
action_return_ramtransfer ramtransfer( const name& from, const name& to, int64_t bytes, const std::string& memo );

/**
* Burn ram action, reduces owner's quota by bytes.
*
* @param owner - the ram owner account,
* @param bytes - the amount of ram to be burned in bytes,
* @param memo - the memo string to accompany the transaction.
*/
[[eosio::action]]
action_return_ramtransfer ramburn( const name& owner, int64_t bytes, const std::string& memo );

/**
* Logging for ram changes
*
* @param owner - the ram owner account,
* @param bytes - the bytes balance change,
* @param ram_bytes - the ram bytes held by owner after the action.
*/
[[eosio::action]]
void logramchange( const name& owner, int64_t bytes, int64_t ram_bytes );

/**
* Refund action, this action is called after the delegation-period to claim all pending
Expand Down Expand Up @@ -1417,7 +1505,12 @@ 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 ramburn_action = eosio::action_wrapper<"ramburn"_n, &system_contract::ramburn>;
using logramchange_action = eosio::action_wrapper<"logramchange"_n, &system_contract::logramchange>;
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>;
Expand Down Expand Up @@ -1496,6 +1589,9 @@ namespace eosiosystem {
void changebw( name from, const name& receiver,
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 );
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
41 changes: 41 additions & 0 deletions contracts/eosio.system/ricardian/eosio.system.contracts.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ icon: @ICON_BASE_URL@/@RESOURCE_ICON_URI@

{{payer}} buys RAM on behalf of {{receiver}} by paying {{quant}}. This transaction will incur a 0.5% fee out of {{quant}} and the amount of RAM delivered will depend on market rates.

<h1 class="contract">buyramself</h1>

---
spec_version: "0.2.0"
title: Buy RAM self
summary: '{{nowrap account}} buys RAM to self by paying {{nowrap quant}}'
icon: @ICON_BASE_URL@/@RESOURCE_ICON_URI@
---

{{account}} buys RAM to self by paying {{quant}}. This transaction will incur a 0.5% fee out of {{quant}} and the amount of RAM delivered will depend on market rates.

<h1 class="contract">buyrambytes</h1>

---
Expand Down Expand Up @@ -413,6 +424,36 @@ icon: @ICON_BASE_URL@/@RESOURCE_ICON_URI@

Sell {{bytes}} bytes of unused RAM from account {{account}} at market price. This transaction will incur a 0.5% fee on the proceeds which depend on market rates.

<h1 class="contract">ramtransfer</h1>

---
spec_version: "0.2.0"
title: Transfer RAM from Account
summary: 'Transfer unused RAM from {{nowrap from}} to {{nowrap to}}'
icon: @ICON_BASE_URL@/@RESOURCE_ICON_URI@
---

Transfer {{bytes}} bytes of unused RAM from account {{from}} to account {{to}}.

{{#if memo}}There is a memo attached to the transfer stating:
{{memo}}
{{/if}}

<h1 class="contract">ramburn</h1>

---
spec_version: "0.2.0"
title: Burn RAM from Account
summary: 'Burn unused RAM from {{nowrap owner}}'
icon: @ICON_BASE_URL@/@RESOURCE_ICON_URI@
---

Burn {{bytes}} bytes of unused RAM from account {{owner}}.

{{#if memo}}There is a memo attached to the burn stating:
{{memo}}
{{/if}}

<h1 class="contract">sellrex</h1>

---
Expand Down
Loading
Loading