Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
5e73b664
Y
YTBP
项目概览
YottaChain
/
YTBP
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
YTBP
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
5e73b664
编写于
5月 03, 2018
作者:
D
Daniel Larimer
提交者:
GitHub
5月 03, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'slim' into currency-test-fixes
上级
6805904a
b619b0f3
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
61 addition
and
3 deletion
+61
-3
contracts/eosio.system/delegate_bandwidth.cpp
contracts/eosio.system/delegate_bandwidth.cpp
+21
-1
contracts/eosio.system/eosio.system.abi
contracts/eosio.system/eosio.system.abi
+23
-0
contracts/eosio.system/eosio.system.cpp
contracts/eosio.system/eosio.system.cpp
+1
-1
contracts/eosio.system/eosio.system.hpp
contracts/eosio.system/eosio.system.hpp
+2
-1
unittests/eosio.system_tests.cpp
unittests/eosio.system_tests.cpp
+14
-0
未找到文件。
contracts/eosio.system/delegate_bandwidth.cpp
浏览文件 @
5e73b664
...
...
@@ -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
,
uint
64
_t
bytes
)
{
void
system_contract
::
sellram
(
account_name
account
,
uint
32
_t
bytes
)
{
user_resources_table
userres
(
_self
,
account
);
auto
res_itr
=
userres
.
find
(
account
);
eosio_assert
(
res_itr
!=
userres
.
end
(),
"no resource row"
);
...
...
contracts/eosio.system/eosio.system.abi
浏览文件 @
5e73b664
...
...
@@ -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",
...
...
contracts/eosio.system/eosio.system.cpp
浏览文件 @
5e73b664
...
...
@@ -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
...
...
contracts/eosio.system/eosio.system.hpp
浏览文件 @
5e73b664
...
...
@@ -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
,
uint
64
_t
bytes
);
void
sellram
(
account_name
receiver
,
uint
32
_t
bytes
);
/**
* This action is called after the delegation-period to claim all pending
...
...
unittests/eosio.system_tests.cpp
浏览文件 @
5e73b664
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录