专栏首页区块链技术专栏EOS 投票合约,终于等到你。

EOS 投票合约,终于等到你。

作者:OuterST

1. 相关信息重要说明

1.1 文件配置与存储目录

nodes目录下有两个文件夹,一个是config,一个是data。

config里面有一个config.ini配置文件,只有在运行一次nodes后才会出现,主要配置一些插件和节点,需要第一次运行修改。

data文件是运行nodes后生成的区块信息,比如创建的钱包和账户等信息,都会保存在此处,删除data文件夹,相当于把已有的数据全部删除,为稳定测试提供很大帮助

~/.local/share/eosio/nodeos/

1.2 get table 命令

这是一条非常重要的命令,只能通过get table,获取到数据库中数据表的内容,不可以通过mondodb等查看。

参数如下:

Usage: cleos get table [OPTIONS] contract scope table



Positionals:

contract TEXT The contract who owns the table

scope TEXT The scope within the contract in which the table is found

table TEXT The name of the table as specified by the contract abi

参数说明:

contract:要获取的表的合约名;

table:要获取的表名;

scope:这个理解有点难,表示查找的范围。

举个栗子:

看一下eosio.system.abi文件中的tables,voters 是笔者添加的,后续会有说明。

"tables": [{

"name": "producerinfo",

"type": "producer\_info",

"index\_type": "i64",

"key\_names" : ["owner"],

"key\_types" : ["uint64"]

},{

"name": "totalband",

"type": "total\_resources",

"index\_type": "i64",

"key\_names" : ["owner"],

"key\_types" : ["uint64"]

},{

"name": "delband",

"type": "delegated\_bandwidth",

"index\_type": "i64",

"key\_names" : ["to"],

"key\_types" : ["uint64"]

},{

"name": "refunds",

"type": "refund\_request",

"index\_type": "i64",

"key\_names" : ["owner"],

"key\_types" : ["uint64"]

},{

"name": "voters",

"type": "voter\_info",

"index\_type": "i64",

"key\_names" : ["owner"],

"key\_types" : ["uint64"]

}

]

这里拿delband 中的key_names 来说明一下,它表示表的索引。 首先来看一下 delegated_bandwidth 的结构

{

"name": "delegated\_bandwidth",

"base": "",

"fields": [

{"name":"from", "type":"account\_name"},

{"name":"to", "type":"account\_name"},

{"name":"net\_weight", "type":"uint64"},

{"name":"cpu\_weight", "type":"uint64"},

{"name":"storage\_stake", "type":"uint64"},

{"name":"storage\_bytes", "type":"uint64"}

]

}

如果索引是owner,scope一般都是部署合约的账户名。

如果是表里的某一参数,scope一般都是执行合约的账户名。

这里具体的联系还没找出,有错误或者知道的,可以指出。

2. eosio.system 投票智能合约

2.1 测试前准备

为了测试投票后,查看投票信息,首先需要手动在eos/contracts/eosio.system/eosio.system.abi中的tables加上voters,如前文提到的。

首先启动nodes

nodeos -e -p eosio --plugin eosio::wallet\_api\_plugin --plugin eosio::chain\_api\_plugin --plugin eosio::account\_history\_api\_plugin 

后续命令都是在 eos 根目录执行的,为了减少文章篇幅,命令执行后的输出,尽量不在写在文章内。

下面创建钱包,导入私钥,创建账号,部署合约,发币,转账要一气呵成,为后面测试用,多创建几个账号

钱包私钥:PW5JtvZQES9UqCJ83z29Kxs2anz7v41tdoNgH7Sgy2Lus44MxaJhV

 cleos wallet create



cleos wallet import 5Jmsawgsp1tQ3GD6JyGCwy1dcvqKZgX6ugMVMdjirx85iv5VyPR



cleos set contract eosio build/contracts/eosio.bios -p eosio



cleos create account eosio eosio.token EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4 EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4



cleos create account eosio ost EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4 EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4



cleos create account eosio imtube EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4 EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4



cleos create account eosio alice EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4 EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4



cleos create account eosio bob EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4 EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4



cleos set contract eosio build/contracts/eosio.system/ -p eosio



cleos set contract eosio.token build/contracts/eosio.token -p eosio.token



 cleos push action eosio.token create '[ "eosio", "1000000000.0000 EOS", 0, 0, 0]' -p eosio.token



cleos push action eosio.token issue '["ost","1000.0000 EOS",""]' -p eosio



cleos push action eosio.token issue '["imtube","1000.0000 EOS",""]' -p eosio



cleos push action eosio.token issue '["alice","2000.0000 EOS",""]' -p eosio



cleos push action eosio.token issue '["bob","1000.0000 EOS",""]' -p eosio

2.2 投票流程

为了保证可以一次流程尽可能多的测试各种情况,可能会涉及多次重复同一操作。

2.2.1 节点的注册、取消与更改

注册节点:

cleos push action eosio regproducer '{"producer":"alice","producer\_key":"000374efa00b0f3bdf5cbbd4cff249af0faf1fcec74e085f21b455e4a5e85cd26a90","prefs":{"base\_per\_transaction\_net\_usage":100,"base\_per\_transaction\_cpu\_usage":500,"base\_per\_action\_cpu\_usage":1000,"base\_setcode\_cpu\_usage":2097152,"per\_signature\_cpu\_usage":100000,"per\_lock\_net\_usage":32,"context\_free\_discount\_cpu\_usage\_num":20,"context\_free\_discount\_cpu\_usage\_den":100,"max\_transaction\_cpu\_usage":10485760,"max\_transaction\_net\_usage":104857,"max\_block\_cpu\_usage":104857600,"target\_block\_cpu\_usage\_pct":1000,"max\_block\_net\_usage":1048576,"target\_block\_net\_usage\_pct":1000,"max\_transaction\_lifetime":3600,"max\_transaction\_exec\_time":10000,"max\_authority\_depth":6,"max\_inline\_depth":4,"max\_inline\_action\_size":4096,"max\_generated\_transaction\_count":16,"max\_storage\_size":10485760,"percent\_of\_max\_inflation\_rate":0,"storage\_reserve\_ratio":1000,"max\_transaction\_delay":864000}}' -p alice

这里的producer_key是由 EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4 公钥转成的,公钥可以用于接收节点奖励,私钥可以用于签名。

具体这个“000374efa00b0f3bdf5cbbd4cff249af0faf1fcec74e085f21b455e4a5e85cd26a90” 是怎么来的:代码中是 fc::raw::pack( public_key),而在cloes没有找到对应的接口。

这里取了个巧:运行 cleos system (后续会提到)下面的代码,虽然报错,缺少了max_transaction_delay字段,你会发现他不紧把public_key转成了需要的格式,还把其他字段显示出来了,只要复制一下,然后把max_transaction_delay加上就可以了。

cleos system regproducer alice EOS7ijWCBmoXBi3CgtK7DJxentZZeTkeUnaSDvyro9dq7Sd1C3dC4



Error 3040002: Invalid Action Arguments

Ensure that your arguments follow the contract abi!

You can check the contract's abi by using 'cleos get code' command.

Error Details:

'{"producer":"alice","producer\_key":"000374efa00b0f3bdf5cbbd4cff249af0faf1fcec74e085f21b455e4a5e85cd26a90","prefs":{"base\_per\_transaction\_net\_usage":100,"base\_per\_transaction\_cpu\_usage":500,"base\_per\_action\_cpu\_usage":1000,"base\_setcode\_cpu\_usage":2097152,"per\_signature\_cpu\_usage":100000,"per\_lock\_net\_usage":32,"context\_free\_discount\_cpu\_usage\_num":20,"context\_free\_discount\_cpu\_usage\_den":100,"max\_transaction\_cpu\_usage":10485760,"max\_transaction\_net\_usage":104857,"max\_block\_cpu\_usage":104857600,"target\_block\_cpu\_usage\_pct":1000,"max\_block\_net\_usage":1048576,"target\_block\_net\_usage\_pct":1000,"max\_transaction\_lifetime":3600,"max\_transaction\_exec\_time":10000,"max\_authority\_depth":6,"max\_inline\_depth":4,"max\_inline\_action\_size":4096,"max\_generated\_transaction\_count":16,"max\_storage\_size":10485760,"percent\_of\_max\_inflation\_rate":0,"storage\_reserve\_ratio":1000}}' is invalid args for action 'regproducer' code 'eosio'

Missing 'max\_transaction\_delay' in variant object

更改节点:

更改可以改两项,producer_key 和 prefs,而 producer 是不可以更改的。

下面的只是另一种加密方式的秘钥对。

要换成的秘钥对:

私钥:PVT_R1_iyQmnyPEGvFd8uffnk152WC2WryBjgTrg22fXQryuGL9mU6qW

公钥:PUB_R1_6EPHFSKVYHBjQgxVGQPrwCxTg7BbZ69H9i4gztN9deKTEXYne4

下面只是更改了producer_key,获取方式也是用 cleos system。

cleos push action eosio regproducer '{"producer":"alice","producer\_key":"0102b0deed150ac513f4e0b62d2f7669cb3b36e79e3e7f0a9e021dd013a33eee9c66","prefs":{"base\_per\_transaction\_net\_usage":100,"base\_per\_transaction\_cpu\_usage":500,"base\_per\_action\_cpu\_usage":1000,"base\_setcode\_cpu\_usage":2097152,"per\_signature\_cpu\_usage":100000,"per\_lock\_net\_usage":32,"context\_free\_discount\_cpu\_usage\_num":20,"context\_free\_discount\_cpu\_usage\_den":100,"max\_transaction\_cpu\_usage":10485760,"max\_transaction\_net\_usage":104857,"max\_block\_cpu\_usage":104857600,"target\_block\_cpu\_usage\_pct":1000,"max\_block\_net\_usage":1048576,"target\_block\_net\_usage\_pct":1000,"max\_transaction\_lifetime":3600,"max\_transaction\_exec\_time":10000,"max\_authority\_depth":6,"max\_inline\_depth":4,"max\_inline\_action\_size":4096,"max\_generated\_transaction\_count":16,"max\_storage\_size":10485760,"percent\_of\_max\_inflation\_rate":0,"storage\_reserve\_ratio":1000,"max\_transaction\_delay":864000}}' -p alice

取消节点:

这个就比较简单,值得注意的是,取消节点后,其他账号不能在为其投票,但是之前投的票会被保留,下次创建节点还有出现。

cleos push action eosio unregprod '{"producer":"alice"}' -p alice

2.2.2 抵押与取消抵押

抵押:

抵押给自己:

cleos push action eosio delegatebw '{"from":"ost","receiver":"ost","stake\_net\_quantity":"10.0000 EOS","stake\_cpu\_quantity":"10.0000 EOS","stake\_storage\_quantity":"10.0000 EOS"}' -p ost

抵押前转给了ost 1000.0000 EOS token,查看抵押后的账户

cleos get table eosio.token ost accounts

{

"rows": [{

"balance": "970.0000 EOS",

"frozen": 0,

"whitelist": 1

}

],

"more": false

}

查看抵押信息:

cleos get table eosio ost delband

{

"rows": [{

"from": "ost",

"to": "ost",

"net\_weight": 100000,

"cpu\_weight": 1397703940,

"storage\_stake": 100000,

"storage\_bytes": 1397703940

}

],

"more": false

}

抵押给别人:

cleos push action eosio delegatebw '{"from":"ost","receiver":"imtube","stake\_net\_quantity":"5.0000 EOS","stake\_cpu\_quantity":"5.0000 EOS","stake\_storage\_quantity":"5.0000 EOS"}' -p ost

查看抵押信息:

cleos get table eosio ost delband{

"rows": [{

"from": "ost",

"to": "imtube",

"net\_weight": 50000,

"cpu\_weight": 1397703940,

"storage\_stake": 50000,

"storage\_bytes": 1397703940

},{

"from": "ost",

"to": "ost",

"net\_weight": 100000,

"cpu\_weight": 1397703940,

"storage\_stake": 100000,

"storage\_bytes": 1397703940

}

],

"more": false

}

查询ost的balance为:955.0000 EOS

取消抵押:

cleos push action eosio undelegatebw '{"from":"ost","receiver":"ost","unstake\_net\_quantity":"5.0000 EOS","unstake\_cpu\_quantity":"5.0000 EOS","unstake\_storage\_bytes":0}' -p ost

查看抵押信息,取消抵押的部分,已经撤回了

cleos get table eosio ost delband{

"rows": [{

"from": "ost",

"to": "imtube",

"net\_weight": 50000,

"cpu\_weight": 1397703940,

"storage\_stake": 50000,

"storage\_bytes": 1397703940

},{

"from": "ost",

"to": "ost",

"net\_weight": 50000,

"cpu\_weight": 1397703940,

"storage\_stake": 50000,

"storage\_bytes": 1397703940

}

],

"more": false

}

然后再次查看 ost 的 balance,发现还是955.0000 EOS,没有将取消抵押的返回回来,原因是取消抵押有3天延迟,认真的同学可以去试试三天后会不会返还。

cleos get table eosio.token ost accounts

{

"rows": [{

"balance": "955.0000 EOS",

"frozen": 0,

"whitelist": 1

}

],

"more": false

}

2.2.3 投票与取消投票

2.2.3.1 投票前准备

投票的先有节点,创建节点:

cleos push action eosio regproducer '{"producer":"ost","producer\_key":"000374efa00b0f3bdf5cbbd4cff249af0faf1fcec74e085f21b455e4a5e85cd26a90","prefs":{"base\_per\_transaction\_net\_usage":100,"base\_per\_transaction\_cpu\_usage":500,"base\_per\_action\_cpu\_usage":1000,"base\_setcode\_cpu\_usage":2097152,"per\_signature\_cpu\_usage":100000,"per\_lock\_net\_usage":32,"context\_free\_discount\_cpu\_usage\_num":20,"context\_free\_discount\_cpu\_usage\_den":100,"max\_transaction\_cpu\_usage":10485760,"max\_transaction\_net\_usage":104857,"max\_block\_cpu\_usage":104857600,"target\_block\_cpu\_usage\_pct":1000,"max\_block\_net\_usage":1048576,"target\_block\_net\_usage\_pct":1000,"max\_transaction\_lifetime":3600,"max\_transaction\_exec\_time":10000,"max\_authority\_depth":6,"max\_inline\_depth":4,"max\_inline\_action\_size":4096,"max\_generated\_transaction\_count":16,"max\_storage\_size":10485760,"percent\_of\_max\_inflation\_rate":0,"storage\_reserve\_ratio":1000,"max\_transaction\_delay":864000}}' -p ost
cleos push action eosio regproducer '{"producer":"imtube","producer\_key":"000374efa00b0f3bdf5cbbd4cff249af0faf1fcec74e085f21b455e4a5e85cd26a90","prefs":{"base\_per\_transaction\_net\_usage":100,"base\_per\_transaction\_cpu\_usage":500,"base\_per\_action\_cpu\_usage":1000,"base\_setcode\_cpu\_usage":2097152,"per\_signature\_cpu\_usage":100000,"per\_lock\_net\_usage":32,"context\_free\_discount\_cpu\_usage\_num":20,"context\_free\_discount\_cpu\_usage\_den":100,"max\_transaction\_cpu\_usage":10485760,"max\_transaction\_net\_usage":104857,"max\_block\_cpu\_usage":104857600,"target\_block\_cpu\_usage\_pct":1000,"max\_block\_net\_usage":1048576,"target\_block\_net\_usage\_pct":1000,"max\_transaction\_lifetime":3600,"max\_transaction\_exec\_time":10000,"max\_authority\_depth":6,"max\_inline\_depth":4,"max\_inline\_action\_size":4096,"max\_generated\_transaction\_count":16,"max\_storage\_size":10485760,"percent\_of\_max\_inflation\_rate":0,"storage\_reserve\_ratio":1000,"max\_transaction\_delay":864000}}' -p imtube

抵押:

前文已经抵押过了:ost → ost 5.0000 EOS, ost → imtube 5.0000 EOS

cleos get table eosio ost delband

{

"rows": [{

"from": "ost",

"to": "imtube",

"net\_weight": 50000,

"cpu\_weight": 1397703940,

"storage\_stake": 50000,

"storage\_bytes": 1397703940

},{

"from": "ost",

"to": "ost",

"net\_weight": 50000,

"cpu\_weight": 1397703940,

"storage\_stake": 50000,

"storage\_bytes": 1397703940

}

],

"more": false

}

imtube → imtube

cleos push action eosio delegatebw '{"from":"imtube","receiver":"imtube","stake\_net\_quantity":"2.0000 EOS","stake\_cpu\_quantity":"2.0000 EOS","stake\_storage\_quantity":"2.0000 EOS"}' -p imtube

查看 imtube 抵押信息:

cleos get table eosio imtube delband{

"rows": [{

"from": "imtube",

"to": "imtube",

"net\_weight": 20000,

"cpu\_weight": 1397703940,

"storage\_stake": 20000,

"storage\_bytes": 1397703940

}

],

"more": false

}

imtube → bob

cleos push action eosio delegatebw '{"from":"imtube","receiver":"bob","stake\_net\_quantity":"3.0000 EOS","stake\_cpu\_quantity":"3.0000 EOS","stake\_storage\_quantity":"3.0000 EOS"}' -p imtube

2.3.3.2 节点给其他节点投票

cleos push action eosio voteproducer '{"voter":"imtube","proxy":"","producers":["ost"]}' -p imtube

获取投票者信息:

cleos get table eosio eosio voters

{

"rows": [{

"owner": "imtube",

"proxy": "",

"last\_update": 1526029573,

"is\_proxy": 0,

"staked": "10.0000 EOS",

"unstaking": "0.0000 EOS",

"unstake\_per\_week": "0.0000 EOS",

"proxied\_votes": "0",

"producers": [

"ost"

],

"deferred\_trx\_id": 0,

"last\_unstake": 0

},{

"owner": "ost",

"proxy": "",

"last\_update": 1526027699,

"is\_proxy": 0,

"staked": "20.0000 EOS",

"unstaking": "0.0000 EOS",

"unstake\_per\_week": "0.0000 EOS",

"proxied\_votes": "0",

"producers": [],

"deferred\_trx\_id": 0,

"last\_unstake": 0

}

],

"more": false

}

默认是没有voters表的,前文已经提到在eosio.system.abi修改tables了,这里就不在提及了。

可以看到上面 imtube 的 staked(抵押)剩余为10.0000 EOS,其值为delband 中 net_weight 与 storage_stake 的和(可存在多组)。

举个栗子:

staked = 3 + 3 + 2 + 2;

cleos get table eosio imtube delband

{

"rows": [{

"from": "imtube",

"to": "bob",

"net\_weight": 30000,

"cpu\_weight": 1397703940,

"storage\_stake": 30000,

"storage\_bytes": 1397703940

},{

"from": "imtube",

"to": "imtube",

"net\_weight": 20000,

"cpu\_weight": 1397703940,

"storage\_stake": 20000,

"storage\_bytes": 1397703940

}

],

"more": false

}

2.3.3.3 节点给自己投票

cleos push action eosio voteproducer '{"voter":"imtube","proxy":"","producers":["imtube"]}' -p imtube

2.3.3.4 账号给节点投票

bob抵押:

cleos push action eosio delegatebw '{"from":"bob","receiver":"bob","stake\_net\_quantity":"11.0000 EOS","stake\_cpu\_quantity":"11.0000 EOS","stake\_storage\_quantity":"11.0000 EOS"}' -p bob

bob给ost投票:

cleos push action eosio voteproducer '{"voter":"bob","proxy":"","producers":["ost"]}' -p bob

查看节点信息:

首先可以看到ost的投票数量是220000 , votingNum = (stake_net_quantity + stake_cpu_quantity) * 10000;

也可以看到imtube投票数量为10000,是之前imtube投给自己的。

cleos get table eosio eosio producerinfo{

"rows": [{

"owner": "alice",

"total\_votes": "0",

"prefs": {

"base\_per\_transaction\_net\_usage": 100,

"base\_per\_transaction\_cpu\_usage": 500,

"base\_per\_action\_cpu\_usage": 1000,

"base\_setcode\_cpu\_usage": 2097152,

"per\_signature\_cpu\_usage": 100000,

"per\_lock\_net\_usage": 32,

"context\_free\_discount\_cpu\_usage\_num": 20,

"context\_free\_discount\_cpu\_usage\_den": 100,

"max\_transaction\_cpu\_usage": 10485760,

"max\_transaction\_net\_usage": 104857,

"max\_block\_cpu\_usage": 104857600,

"target\_block\_cpu\_usage\_pct": 1000,

"max\_block\_net\_usage": 1048576,

"target\_block\_net\_usage\_pct": 1000,

"max\_transaction\_lifetime": 3600,

"max\_transaction\_exec\_time": 10000,

"max\_authority\_depth": 6,

"max\_inline\_depth": 4,

"max\_inline\_action\_size": 4096,

"max\_generated\_transaction\_count": 16,

"max\_transaction\_delay": 864000,

"max\_storage\_size": 10485760,

"percent\_of\_max\_inflation\_rate": 0,

"storage\_reserve\_ratio": 1000

},

"packed\_key": [],

"per\_block\_payments": 0,

"last\_claim\_time": 1397703940

},{

"owner": "imtube",

"total\_votes": "100000",

"prefs": {

"base\_per\_transaction\_net\_usage": 100,

"base\_per\_transaction\_cpu\_usage": 500,

"base\_per\_action\_cpu\_usage": 1000,

"base\_setcode\_cpu\_usage": 2097152,

"per\_signature\_cpu\_usage": 100000,

"per\_lock\_net\_usage": 32,

"context\_free\_discount\_cpu\_usage\_num": 20,

"context\_free\_discount\_cpu\_usage\_den": 100,

"max\_transaction\_cpu\_usage": 10485760,

"max\_transaction\_net\_usage": 104857,

"max\_block\_cpu\_usage": 104857600,

"target\_block\_cpu\_usage\_pct": 1000,

"max\_block\_net\_usage": 1048576,

"target\_block\_net\_usage\_pct": 1000,

"max\_transaction\_lifetime": 3600,

"max\_transaction\_exec\_time": 10000,

"max\_authority\_depth": 6,

"max\_inline\_depth": 4,

"max\_inline\_action\_size": 4096,

"max\_generated\_transaction\_count": 16,

"max\_transaction\_delay": 864000,

"max\_storage\_size": 10485760,

"percent\_of\_max\_inflation\_rate": 0,

"storage\_reserve\_ratio": 1000

},

"packed\_key": [

0,

3,

116,

239,

160,

11,

15,

59,

223,

92,

187,

212,

207,

242,

73,

175,

15,

175,

31,

206,

199,

78,

8,

95,

33,

180,

85,

228,

165,

232,

92,

210,

106,

144

],

"per\_block\_payments": 0,

"last\_claim\_time": 1397703940

},{

"owner": "ost",

"total\_votes": "220000",

"prefs": {

"base\_per\_transaction\_net\_usage": 100,

"base\_per\_transaction\_cpu\_usage": 500,

"base\_per\_action\_cpu\_usage": 1000,

"base\_setcode\_cpu\_usage": 2097152,

"per\_signature\_cpu\_usage": 100000,

"per\_lock\_net\_usage": 32,

"context\_free\_discount\_cpu\_usage\_num": 20,

"context\_free\_discount\_cpu\_usage\_den": 100,

"max\_transaction\_cpu\_usage": 10485760,

"max\_transaction\_net\_usage": 104857,

"max\_block\_cpu\_usage": 104857600,

"target\_block\_cpu\_usage\_pct": 1000,

"max\_block\_net\_usage": 1048576,

"target\_block\_net\_usage\_pct": 1000,

"max\_transaction\_lifetime": 3600,

"max\_transaction\_exec\_time": 10000,

"max\_authority\_depth": 6,

"max\_inline\_depth": 4,

"max\_inline\_action\_size": 4096,

"max\_generated\_transaction\_count": 16,

"max\_transaction\_delay": 864000,

"max\_storage\_size": 10485760,

"percent\_of\_max\_inflation\_rate": 0,

"storage\_reserve\_ratio": 1000

},

"packed\_key": [

0,

3,

116,

239,

160,

11,

15,

59,

223,

92,

187,

212,

207,

242,

73,

175,

15,

175,

31,

206,

199,

78,

8,

95,

33,

180,

85,

228,

165,

232,

92,

210,

106,

144

],

"per\_block\_payments": 0,

"last\_claim\_time": 1397703940

}

],

"more": false

}

2.3.3.5 投票给多个节点

将alice设置为节点

cleos push action eosio regproducer '{"producer":"alice","producer\_key":"000374efa00b0f3bdf5cbbd4cff249af0faf1fcec74e085f21b455e4a5e85cd26a90","prefs":{"base\_per\_transaction\_net\_usage":100,"base\_per\_transaction\_cpu\_usage":500,"base\_per\_action\_cpu\_usage":1000,"base\_setcode\_cpu\_usage":2097152,"per\_signature\_cpu\_usage":100000,"per\_lock\_net\_usage":32,"context\_free\_discount\_cpu\_usage\_num":20,"context\_free\_discount\_cpu\_usage\_den":100,"max\_transaction\_cpu\_usage":10485760,"max\_transaction\_net\_usage":104857,"max\_block\_cpu\_usage":104857600,"target\_block\_cpu\_usage\_pct":1000,"max\_block\_net\_usage":1048576,"target\_block\_net\_usage\_pct":1000,"max\_transaction\_lifetime":3600,"max\_transaction\_exec\_time":10000,"max\_authority\_depth":6,"max\_inline\_depth":4,"max\_inline\_action\_size":4096,"max\_generated\_transaction\_count":16,"max\_storage\_size":10485760,"percent\_of\_max\_inflation\_rate":0,"storage\_reserve\_ratio":1000,"max\_transaction\_delay":864000}}' -p alice

通过 cleos get table eosio eosio producerinfo ,可以看到 alice,imtube,ost是有一个先后顺序的。

在为多节点投票的时候,要保证顺序是和前面一样的。

举个栗子:上面的顺序为 alice → imtube → ost,所以下面的顺序应该是imtube在ost前面,而不能到过来。

cleos push action eosio voteproducer '{"voter":"bob","proxy":"","producers":["imtube","ost"]}' -p bob

2.2.4 投票失败

未创建的节点;

创建后又取消的节点;

一次投30个以上的节点,只有前30可以成功;

多个节点投票,没有按顺序;

2.2.5 节点奖励

cleos push action eosio claimrewards '{"owner":"imtube"}' -p imtube

要想发放节点奖励,必须保证per_block_payments 大于0;

在eos/contracts/eosio.system/producer_pay.cpp 中, 发现奖励相关的代码是注释掉的。

const system\_token\_type block\_payment = parameters.payment\_per\_block;

system\_token\_type rewards = prod->per\_block\_payments;

2.2.5 投票小总结

在账号准备好的情况下,就是已经创建,并且拥有token。

流程: 创建节点 - 抵押 - 投票

抵押取消时,会有三天的延迟到账。

保留投票:节点取消前,已经拥有投票,下次在创建的时候,数量将被保留。

投票比较自由,账号和节点都可以投票,节点也可以投给自己。

一次可以给30个以下投票(包含30),每个节点的投票数量均为抵押数量,

多个节点投票,要有顺序。

在投票结束后,在nodes端出报异常,但是不影响,不知道为什么,有人知道可以指教一下吗?

2134510ms thread-0 producer\_plugin.cpp:239 block\_production\_loo ] eosio generated block 18d334e2... #56764 @ 2018-05-11T11:35:34.500 with 0 trxs, lib: 56763

2135008ms thread-0 wasm\_interface.cpp:812 eosio\_assert ] message: must issue positive quantity 

2135009ms thread-0 chain\_controller.cpp:2142 operator() ] 10 assert\_exception: Assert Exception

condition: assertion failed: must issue positive quantity

{"s":"must issue positive quantity"}

thread-0 wasm\_interface.cpp:813 eosio\_assert



{"\_pending\_console\_output.str()":"issue"}

thread-0 apply\_context.cpp:30 exec\_one



{}

thread-0 chain\_controller.cpp:2129 \_\_apply\_transaction

2135009ms thread-0 chain\_controller.cpp:2142 operator() ] meta.id: dff86816ef58f2270d7d0f6b4d1af3053dd33fef6fee6402b9c610281aa25d0e

2.3 代理投票流程

删除nodes下面的data文件夹,重新来过,走一遍准备流程,这里不在重复写出。

2.3.1 节点注册与取消

和之前是一样的:

leos push action eosio regproducer '{"producer":"ost","producer\_key":"000374efa00b0f3bdf5cbbd4cff249af0faf1fcec74e085f21b455e4a5e85cd26a90","prefs":{"base\_per\_transaction\_net\_usage":100,"base\_per\_transaction\_cpu\_usage":500,"base\_per\_action\_cpu\_usage":1000,"base\_setcode\_cpu\_usage":2097152,"per\_signature\_cpu\_usage":100000,"per\_lock\_net\_usage":32,"context\_free\_discount\_cpu\_usage\_num":20,"context\_free\_discount\_cpu\_usage\_den":100,"max\_transaction\_cpu\_usage":10485760,"max\_transaction\_net\_usage":104857,"max\_block\_cpu\_usage":104857600,"target\_block\_cpu\_usage\_pct":1000,"max\_block\_net\_usage":1048576,"target\_block\_net\_usage\_pct":1000,"max\_transaction\_lifetime":3600,"max\_transaction\_exec\_time":10000,"max\_authority\_depth":6,"max\_inline\_depth":4,"max\_inline\_action\_size":4096,"max\_generated\_transaction\_count":16,"max\_storage\_size":10485760,"percent\_of\_max\_inflation\_rate":0,"storage\_reserve\_ratio":1000,"max\_transaction\_delay":864000}}' -p ost

2.3.2 建立代理与取消代理

建立代理:

cleos push action eosio regproxy '{"proxy":"imtube"}' -p imtube

取消代理:

cleos push action eosio unregproxy '{"proxy":"imtube"}' -p imtube

2.3.3 代理投票

建立代理:

cleos push action eosio regproxy '{"proxy":"alice"}' -p alice

抵押:

cleos push action eosio delegatebw '{"from":"imtube","receiver":"imtube","stake\_net\_quantity":"11.0000 EOS","stake\_cpu\_quantity":"11.0000 EOS","stake\_storage\_quantity":"11.0000 EOS"}' -p imtube

委托代理:

cleos push action eosio voteproducer '{"voter":"imtube","proxy":"alice","producers":[]}' -p imtube

代理投票:

cleos push action eosio voteproducer '{"voter":"alice","proxy":"","producers":[]}' -p alice

2.3.4 代理小结

代理的作用就是替别人做出选择投票,本身不需要抵押。

在投票的时候,要先抵押,而投票的选择有两种,只能选择一种,两种不能同时存在。

如果选择投票,就直接投票了。

如果选择代理,就是自己抵押相当于是替代理抵押了,然后代理去选择要投票的节点。

已经作为代理的账号,不能在设置代理投票。

3 cleos system

Send eosio.system contract action to the blockchain.

Usage: cleos system SUBCOMMAND



Subcommands:

regproducer Register a new produce

unregprod Unregister an existing produce

voteproducer Vote for a produce

delegatebw Delegate bandwidth

undelegatebw Undelegate bandwidth

claimrewards Claim producer rewards

regproxy Register an account as a proxy (for voting)

unregproxy Unregister an account as a proxy (for voting)

postrecovery Post recovery request

vetorecovery Veto a posted recovery

canceldelay Cancel a delayed transaction

这里就是官方把eosio.system合约放到了cleos中,并且为写合约简化了书写格式。

这里笔者还没有测试的有:postrecovery,vetorecovery,canceldelay,这三个后续会更新。

regproducer :注册节点的时候,有点小问题,提示没有 max_transaction_delay 字段的,可以使用push action的方法。

4 投票总结

笔者认为比较重要的几个点:

投票的流程:要执行投票,得有两个前置条件,存在节点,已经抵押过token;

取消抵押的时候,有三天的延迟;

get table 中 scope 的含义;

投票失败的几个原因;

选择代理的时候不能同时选择投票。

原文转自EOS中文社区: https://eosfans.io/topics/443

原文链接:https://eosfans.io/topics/443

我来说两句

0 条评论
登录 后参与评论

相关文章

  • EOSIO 4.0测试网络启动教程

    与EOS3.0相比,EOS4.0无疑是具有重要意义的预发布版。其中对eosio.system合约的更改相当大。下面就来说一下搭建网络的具体步骤。

    lome
  • EOS 权限管理之-权限的使用 (你绝对找不到的干货)

    相信看这篇教程的人,对我之前的一些账户操作已经进行了了解,如果不了解的,可以移步 https://eosfans.io/topics/372.

    lome
  • EOSIO Dawn 4.0 发布

    上周我们介绍了EOSIO Dawn 4.0,今天我们很自豪地为您带来EOSIO的下一个主要预发布。过去一周发生了很多事情!

    lome
  • 网页开发之目前流行的五大浏览器内核介绍

    浏览器的内核是分为两个部分的,一是渲染引擎,另一个是JS引擎。现在JS引擎比较独立,内核更加倾向于说渲染引擎。

    用户1289394
  • Webpack优化——将你的构建效率提速翻倍

    随着构建体系不断完善、构建体验不断优化,webpack 已经逐渐成为了前端构建体系的一大霸主,对于工作中的真正意义上的前端工程项目,webpack 已经成为了我...

    桃翁
  • Webpack优化——将你的构建效率提速翻倍

    随着构建体系不断完善、构建体验不断优化,webpack 已经逐渐成为了前端构建体系的一大霸主,对于工作中的真正意义上的前端工程项目,webpack 已经成为了我...

    ConardLi
  • 【Webpack】418- 深度优化 Webpack 性能,翻倍构建性能

    随着构建体系不断完善、构建体验不断优化,webpack 已经逐渐成为了前端构建体系的一大霸主,对于工作中的真正意义上的前端工程项目,webpack 已经成为了我...

    pingan8787
  • 这四种特性让以太币与众不同

    程序你好
  • [C#]UDP实现广播

    原文链接:http://blog.csdn.net/humanking7/article/details/51125620

    祥知道
  • tick数据研究(一)

          经常听见tick数据,回测的时候也用过,但是还真的没有自己去处理过tick数据,据说tick数据有很多坑,所以打算自己研究一下。首先的第一步就是先拿...

    钱塘小甲子

扫码关注云+社区

领取腾讯云代金券