Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
YottaChain
YTBP
提交
c20a6627
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,发现更多精彩内容 >>
提交
c20a6627
编写于
5月 06, 2018
作者:
A
Anton Perkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
cleos support different token precision #2807
上级
8d817242
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
46 addition
and
10 deletion
+46
-10
programs/cleos/main.cpp
programs/cleos/main.cpp
+46
-10
未找到文件。
programs/cleos/main.cpp
浏览文件 @
c20a6627
...
...
@@ -554,6 +554,42 @@ authority parse_json_authority_or_key(const std::string& authorityJsonOrFile) {
}
}
asset
to_asset
(
const
string
&
code
,
const
string
&
s
)
{
static
map
<
eosio
::
chain
::
symbol_code
,
eosio
::
chain
::
symbol
>
cache
;
auto
a
=
asset
::
from_string
(
s
);
eosio
::
chain
::
symbol_code
sym
=
a
.
sym
.
to_symbol_code
();
auto
it
=
cache
.
find
(
sym
);
auto
sym_str
=
a
.
symbol_name
();
if
(
it
==
cache
.
end
()
)
{
auto
json
=
call
(
get_currency_stats_func
,
fc
::
mutable_variant_object
(
"json"
,
false
)
(
"code"
,
code
)
(
"symbol"
,
sym_str
)
);
auto
obj
=
json
.
get_object
();
auto
obj_it
=
obj
.
find
(
sym_str
);
if
(
obj_it
!=
obj
.
end
())
{
auto
result
=
obj_it
->
value
().
as
<
eosio
::
chain_apis
::
read_only
::
get_currency_stats_result
>
();
auto
p
=
cache
.
insert
(
make_pair
(
sym
,
result
.
max_supply
.
sym
));
it
=
p
.
first
;
}
else
{
FC_THROW
(
"Symbol ${s} is not supported by token contract ${c}"
,
(
"s"
,
sym_str
)(
"c"
,
code
));
}
}
auto
expected_symbol
=
it
->
second
;
if
(
a
.
decimals
()
<
expected_symbol
.
decimals
()
)
{
auto
factor
=
expected_symbol
.
precision
()
/
a
.
precision
();
auto
a_old
=
a
;
a
=
asset
(
a
.
amount
*
factor
,
expected_symbol
);
}
else
if
(
a
.
decimals
()
>
expected_symbol
.
decimals
()
)
{
FC_THROW
(
"Too many decimal digits in ${a}, only ${d} supported"
,
(
"a"
,
a
)(
"d"
,
expected_symbol
.
decimals
()));
}
// else precision matches
return
a
;
}
inline
asset
to_asset
(
const
string
&
s
)
{
return
to_asset
(
"eosio.token"
,
s
);
}
struct
set_account_permission_subcommand
{
string
accountStr
;
string
permissionStr
;
...
...
@@ -752,9 +788,9 @@ struct create_account_subcommand {
}
EOS_RETHROW_EXCEPTIONS
(
public_key_type_exception
,
"Invalid active public key: ${public_key}"
,
(
"public_key"
,
active_key_str
));
auto
create
=
create_newaccount
(
creator
,
account_name
,
owner_key
,
active_key
);
if
(
!
simple
)
{
action
buyram
=
!
buy_ram_eos
.
empty
()
?
create_buyram
(
creator
,
account_name
,
asset
::
from_string
(
buy_ram_eos
))
action
buyram
=
!
buy_ram_eos
.
empty
()
?
create_buyram
(
creator
,
account_name
,
to_asset
(
buy_ram_eos
))
:
create_buyrambytes
(
creator
,
account_name
,
buy_ram_bytes_in_kbytes
*
1024
);
action
delegate
=
create_delegate
(
creator
,
account_name
,
asset
::
from_string
(
stake_net
),
asset
::
from_string
(
stake_cpu
)
);
action
delegate
=
create_delegate
(
creator
,
account_name
,
to_asset
(
stake_net
),
to_asset
(
stake_cpu
)
);
send_actions
(
{
create
,
buyram
,
delegate
}
);
}
else
{
send_actions
(
{
create
}
);
...
...
@@ -842,8 +878,8 @@ struct delegate_bandwidth_subcommand {
fc
::
variant
act_payload
=
fc
::
mutable_variant_object
()
(
"from"
,
from_str
)
(
"receiver"
,
receiver_str
)
(
"stake_net_quantity"
,
stake_net_amount
+
" EOS"
)
(
"stake_cpu_quantity"
,
stake_cpu_amount
+
" EOS"
);
(
"stake_net_quantity"
,
to_asset
(
stake_net_amount
)
)
(
"stake_cpu_quantity"
,
to_asset
(
stake_cpu_amount
)
);
wdump
((
act_payload
));
send_actions
({
create_action
({
permission_level
{
from_str
,
config
::
active_name
}},
config
::
system_account_name
,
N
(
delegatebw
),
act_payload
)});
});
...
...
@@ -869,8 +905,8 @@ struct undelegate_bandwidth_subcommand {
fc
::
variant
act_payload
=
fc
::
mutable_variant_object
()
(
"from"
,
from_str
)
(
"receiver"
,
receiver_str
)
(
"unstake_net_quantity"
,
unstake_net_amount
+
" EOS"
)
(
"unstake_cpu_quantity"
,
unstake_cpu_amount
+
" EOS"
);
(
"unstake_net_quantity"
,
to_asset
(
unstake_net_amount
)
)
(
"unstake_cpu_quantity"
,
to_asset
(
unstake_cpu_amount
)
);
send_actions
({
create_action
({
permission_level
{
from_str
,
config
::
active_name
}},
config
::
system_account_name
,
N
(
undelegatebw
),
act_payload
)});
});
}
...
...
@@ -891,7 +927,7 @@ struct buyram_subcommand {
fc
::
variant
act_payload
=
fc
::
mutable_variant_object
()
(
"payer"
,
from_str
)
(
"receiver"
,
receiver_str
)
(
"quant"
,
asset
::
from_string
(
amount
));
(
"quant"
,
to_asset
(
amount
));
send_actions
({
create_action
({
permission_level
{
from_str
,
config
::
active_name
}},
config
::
system_account_name
,
N
(
buyram
),
act_payload
)});
});
}
...
...
@@ -1084,7 +1120,7 @@ void get_account( const string& accountName, bool json_format ) {
std
::
cout
<<
"net bandwidth:"
<<
std
::
endl
;
if
(
res
.
total_resources
.
is_object
()
&&
res
.
delegated_bandwidth
.
is_object
()
)
{
asset
net_own
(
stoll
(
res
.
delegated_bandwidth
.
get_object
()[
"net_weight"
].
as_string
()
)
);
auto
net_others
=
asset
::
from_string
(
res
.
total_resources
.
get_object
()[
"net_weight"
].
as_string
())
-
net_own
;
auto
net_others
=
to_asset
(
res
.
total_resources
.
get_object
()[
"net_weight"
].
as_string
())
-
net_own
;
std
::
cout
<<
indent
<<
"staked:"
<<
std
::
setw
(
20
)
<<
net_own
<<
std
::
string
(
11
,
' '
)
<<
"(total stake delegated from account to self)"
<<
std
::
endl
<<
indent
<<
"delegated:"
<<
std
::
setw
(
17
)
<<
net_others
...
...
@@ -1102,7 +1138,7 @@ void get_account( const string& accountName, bool json_format ) {
std
::
cout
<<
"cpu bandwidth:"
<<
std
::
endl
;
if
(
res
.
total_resources
.
is_object
()
&&
res
.
delegated_bandwidth
.
is_object
()
)
{
asset
cpu_own
(
stoll
(
res
.
delegated_bandwidth
.
get_object
()[
"cpu_weight"
].
as_string
()
)
);
auto
cpu_others
=
asset
::
from_string
(
res
.
total_resources
.
get_object
()[
"cpu_weight"
].
as_string
())
-
cpu_own
;
auto
cpu_others
=
to_asset
(
res
.
total_resources
.
get_object
()[
"cpu_weight"
].
as_string
())
-
cpu_own
;
std
::
cout
<<
indent
<<
"staked:"
<<
std
::
setw
(
20
)
<<
cpu_own
<<
std
::
string
(
11
,
' '
)
<<
"(total stake delegated from account to self)"
<<
std
::
endl
<<
indent
<<
"delegated:"
<<
std
::
setw
(
17
)
<<
cpu_others
...
...
@@ -1610,7 +1646,7 @@ int main( int argc, char** argv ) {
tx_force_unique
=
false
;
}
send_actions
({
create_transfer
(
con
,
sender
,
recipient
,
asset
::
from_string
(
amount
),
memo
)});
send_actions
({
create_transfer
(
con
,
sender
,
recipient
,
to_asset
(
amount
),
memo
)});
});
// Net subcommand
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录