本文详细介绍了eosio.system智能合约中的选举、投票、系统设置,适用于EOS智能合约的初级开发者,了解如何进行选举、投票以及系统设置。
01
概述
“eosio.system”智能合约是eos的系统命令合约。这个合约几乎实现了eos全部的系统命令,包括创建账户、资源质押、超级节点投票、域名竞拍等功能,它定义了区块链核心功能所需的结构和操作。
下文将介绍eosio.system是如何实现选举、投票以及系统设置的。
02
环境准备
(一)一条正在运行且可访问的区块链
中移链(基于EOS)测试环境搭建:
https://mp.weixin.qq.com/s/NBNFk9Xk9FCukMVgl0tfHA
(二)确保本地钱包已打开并解锁
如何创建钱包:
https://developers.eos.io/manuals/eos/latest/cleos/how-to-guides/how-to-create-a-wallet
(三)已完成eosio.contracts的构建和部署
如何构建eosio.contracts:
https://developers.eos.io/manuals/eosio.contracts/latest/build-and-deploy
(四)已完成token的创建、发行和转移
如何创建、发行和转移token:
https://developers.eos.io/manuals/eosio.contracts/latest/guides/how-to-create-issue-and-transfer-a-token
03
选举
(一)节点的注册、取消
eos的超级节点选举是围绕账户进行的。账户注册为超级节点候选账户,其他账户才可以为其投票。
注册为超级节点候选账户,需要提供公钥,此公钥用于当选超级节点后,产块时验证签名。
命令基础结构:
cleos system regproducer [OPTIONS] account producer_key [url] [location]
注册节点示例:
cleos system regproducer alice EOS6u3S5RbCxVrCE2sW7yBQLZ7fftaupqB85BLDeuV9j4eTBGCKX1
取消节点:
cleos system unregprod alice EOS6u3S5RbCxVrCE2sW7yBQLZ7fftaupqB85BLDeuV9j4eTBGCKX1
取消节点后,其他账号不能再为其投票,但是之前投的票会被保留,下次创建节点仍会出现。
04
投票
(一)投票流程
1、注册节点
运行以下指令注册节点(详见前文):
cleos system regproducer alice EOS6u3S5RbCxVrCE2sW7yBQLZ7fftaupqB85BLDeuV9j4eTBGCKX1
2、抵押与取消抵押
抵押:
抵押给自己:
cleos system delegatebw ost ost "5 SYS" "5 SYS"
抵押成功返回值
executed transaction: 403f264c483947d3a5b2cd3508632d2993789467674ff458fac1b413d2f2b4ea 144 bytes 318 us
# eosio <= eosio::delegatebw {"from":"ost","receiver":"ost","stake_net_quantity":"51.0000 SYS","stake_cpu_quantity":"49.0000 SYS"...
# eosio.token <= eosio.token::transfer {"from":"ost","to":"eosio.stake","quantity":"100.0000 SYS","memo":"stake bandwidth"}
# ost <= eosio.token::transfer {"from":"ost","to":"eosio.stake","quantity":"100.0000 SYS","memo":"stake bandwidth"}
# eosio.stake <= eosio.token::transfer {"from":"ost","to":"eosio.stake","quantity":"100.0000 SYS","memo":"stake bandwidth"}
warning: transaction executed locally, but may not be confirmed by the network yet ]
抵押前转给ost 1000.0000 SYS token,查看抵押后的账户:
cleos get table eosio.token ost accounts
{
"rows": [{
"balance": "900.0000 SYS"
}
],
"more": false,
"next_key": "",
"next_key_bytes": ""
}
查看抵押信息:
cleos get table eosio ost delband
{
"rows": [{
"from": "ost",
"to": "ost",
"net_weight": "153.0000 SYS",
"cpu_weight": "147.0000 SYS"
}
],
"more": false,
"next_key": "",
"next_key_bytes": ""
}
抵押给别人:
cleos system delegatebw ost imtube "5.0000 SYS" "5.0000 SYS"
查看抵押信息:
cleos get table eosio ost delband{
{
"rows": [{
"from": "ost",
"to": "imtube",
"net_weight": "5.0000 SYS",
"cpu_weight": "5.0000 SYS"
},{
"from": "ost",
"to": "ost",
"net_weight": "153.0000 SYS",
"cpu_weight": "147.0000 SYS"
}
],
"more": false,
"next_key": "",
"next_key_bytes": ""
}
查询ost的balance为:890.0000 SYS
取消抵押:
取消抵押命令基础结构如下:
cleos system undelegatebw [OPTIONS] from receiver unstake_net_quantity unstake_cpu_quantity
此时再次查看ost的balance,显示仍为890.0000 SYS,没有将取消抵押的返回,原因是取消抵押有3天延迟,3天后再查看即可得到正常反馈。
cleos get table eosio.token ost accounts
{
"rows": [{
"balance": "890.0000 SYS"
}
],
"more": false,
"next_key": "",
"next_key_bytes": ""
}
3、投票与取消投票
投票前准备:
创建节点