operation fee在创世区块就定义了,那就不得不从genesis.json开始说起!
genesis.json
为了防止影响本地节点的数据,我在节点目录下创建一个test目录,然后再调用命令,建立缺省genesis.json文件,方式如下:
Chaim:test Chaim$ ../programs/witness_node/witness_node --create-genesis-json ./genesis.json
Creating example genesis state in file ./genesis.json
查看genesis.json文件内容:
{
"initial_timestamp": "2018-04-21T17:29:30",
"max_core_supply": "1000000000000000",
"initial_parameters": {
"current_fees": {
"parameters": [[
0,{
"fee": 2000000,
"price_per_kbyte": 1000000
}
],[
1,{
"fee": 500000
}
],[
2,{
"fee": 0
}
],[
3,{
"fee": 2000000
}
],[
4,{}
],[
5,{
"basic_fee": 500000,
"premium_fee": 200000000,
"price_per_kbyte": 100000
}
],[
6,{
"fee": 2000000,
"price_per_kbyte": 100000
}
],[
7,{
"fee": 300000
}
],[
8,{
"membership_annual_fee": 200000000,
"membership_lifetime_fee": 1000000000
}
],[
9,{
"fee": 50000000
}
],[
10,{
"symbol3": "50000000000",
"symbol4": "30000000000",
"long_symbol": 500000000,
"price_per_kbyte": 10
}
],[
11,{
"fee": 50000000,
"price_per_kbyte": 10
}
],[
12,{
"fee": 50000000
}
],[
13,{
"fee": 50000000
}
],[
14,{
"fee": 2000000,
"price_per_kbyte": 100000
}
],[
15,{
"fee": 2000000
}
],[
16,{
"fee": 100000
}
],[
17,{
"fee": 10000000
}
],[
18,{
"fee": 50000000
}
],[
19,{
"fee": 100000
}
],[
20,{
"fee": 500000000
}
],[
21,{
"fee": 2000000
}
],[
22,{
"fee": 2000000,
"price_per_kbyte": 10
}
],[
23,{
"fee": 2000000,
"price_per_kbyte": 10
}
],[
24,{
"fee": 100000
}
],[
25,{
"fee": 100000
}
],[
26,{
"fee": 100000
}
],[
27,{
"fee": 2000000,
"price_per_kbyte": 10
}
],[
28,{
"fee": 0
}
],[
29,{
"fee": 500000000
}
],[
30,{
"fee": 2000000
}
],[
31,{
"fee": 100000
}
],[
32,{
"fee": 100000
}
],[
33,{
"fee": 2000000
}
],[
34,{
"fee": 500000000
}
],[
35,{
"fee": 100000,
"price_per_kbyte": 10
}
],[
36,{
"fee": 100000
}
],[
37,{}
],[
38,{
"fee": 2000000,
"price_per_kbyte": 10
}
],[
39,{
"fee": 500000,
"price_per_output": 500000
}
],[
40,{
"fee": 500000,
"price_per_output": 500000
}
],[
41,{
"fee": 500000
}
],[
42,{}
],[
43,{
"fee": 2000000
}
],[
44,{}
],[
45,{
"fee": 2000000
}
],[
46,{}
]
],
"scale": 10000
}
}
...
}
这里只保留了与operation相关的费用(genesis.json的其它内容碰到了再分析),每个操作类型基本都有"fee"这一项,不同操作可能还有其它费用,如transfer的operation id为0,除了"fee"这个费用外还有"price_per_kbyte",用来指定每Kbytes的价格。
genesis.json指定的是创世区块时的operation的费用,实际上费用可以通过取全局属性获得。
get_object("2.0.0")
通过get_object("2.0.0")取到的数据结构与genesis.json中基本相同,如下:
get_object 2.0.0
[{
"id": "2.0.0",
"parameters": {
"current_fees": {
"parameters": [[
0,{
"fee": 10420,
"price_per_kbyte": 5789
}
],[
1,{
"fee": 578
}
]]
...
}
}
}
]
在config.hpp中可以找到fee的基数,如下:
#define GRAPHENE_BLOCKCHAIN_PRECISION uint64_t( 100000 )
#define GRAPHENE_BLOCKCHAIN_PRECISION_DIGITS 5
#define GRAPHENE_DEFAULT_TRANSFER_FEE (1*GRAPHENE_BLOCKCHAIN_PRECISION)
也就是说transfer费用为0.1042bts,而每K字节为0.05789bts。当然费用可以是其它资产,数量会资产的核心兑换比率进行转换。
transfer费用这块bitshares-ui在trHelper.js中处理。
在转帐界面看一下,与我们取到的数据是一样的:
注意这个字节数是真正编码后的数据长度
evaluate
链上肯定也会对费用进行检验处理的,bitshares-core中在evaluate中对费用进行了处理,如下:
virtual operation_result evaluate(const operation& o) final override
{
auto* eval = static_cast(this);
const auto& op = o.get();
prepare_fee(op.fee_payer(), op.fee);
if( !trx_state->skip_fee_schedule_check )
{
share_type required_fee = calculate_fee_for_operation(op);
GRAPHENE_ASSERT( core_fee_paid >= required_fee,
insufficient_fee,
"Insufficient Fee Paid",
("core_fee_paid",core_fee_paid)("required", required_fee) );
}
return eval->do_evaluate(op);
}
燃料费用这块似乎不是很复杂,但却很重要,谁能说收钱不重要呢!
感谢您阅读 @chaimyu 的帖子,期待您能留言交流!
https://steemit.com/bitshares/@chaimyu/bitshares-operation-fee
网友评论