EOS一直宣传自己的账号权限机制,下面将演示针对账号bcskill三个权限组的增删改查
- owner 账号拥有者,拥有账号全部的权限,等于超级管理员 (新建账号预设)
- active 拥有账号大部分账户的权限,等于管理员 (新建账号预设)
- custom 自定义添加,用于下面演示针对权限组的增删改查
拥有哪些组的私钥,就拥有当前账号哪些权限。每个组可以有多个授权key,也可以多个授权账户。
1. 生成多组公钥私钥 (在线生成)
- 用于添加到三个权限组演示
权限名 | 公钥 | 私钥 |
---|---|---|
owner | EOS6fQzsc9Bn5buFbNxHgGMNh9zr2gcbHz2YaaBCfMApw3E8vADu3 | 5Hvpv1qkoBymEb8DA1MfrgHdcPbxGkE7Ux9DPzhRnb8kHBoAuBn |
active | EOS5G45ChvRSTjQJGvHX8gBEV2ZrUvbxnh6WEd1qfXKox7KqnZb7j | 5Jqq6ztSk41Y6duygrFwCKKVBTaat8zLExG3owwnJSHZMKRcZC4 |
custom | EOS5QxpwkWLAAWQqcT8teKrUceYr5Nj6PsBmCVoLaQQVqcoP2ZjF5 | 5JewRAyyYoNoTfwmy32CLBiyqS2DfQ8njY4ENuzqJ5Rrp7Zft2o |
- 用于演示一个权限组多个账号
账户名 | 公钥 | 私钥 |
---|---|---|
temporary | EOS7Yfs4kL6j9G8nmCTFt5ycLUpV4NmPaZKfuVfYC8XJbuDYPPdnA | 5JnHkERVzDec7j31gAscy39mDbZvTr2XvGS7SZgwQCgNca3McL1 |
- 用于演示一个权限组多个授权key
公钥 | 私钥 |
---|---|
EOS7UKzLPHVUTYpex48pRZokvBNEEp5KKXFGwcb5Qv6dZTWUYHGeP | 5JUhVJetKVxZ1vKPBwxKe458g7Zz3LnAz9kLhmirVs7tiSF2bGk |
2.导入私钥
cleos wallet import 5Hvpv1qkoBymEb8DA1MfrgHdcPbxGkE7Ux9DPzhRnb8kHBoAuBn
cleos wallet import 5Jqq6ztSk41Y6duygrFwCKKVBTaat8zLExG3owwnJSHZMKRcZC4
cleos wallet import 5JewRAyyYoNoTfwmy32CLBiyqS2DfQ8njY4ENuzqJ5Rrp7Zft2o
3.创建账号
cleos system newaccount eosio bcskill EOS6fQzsc9Bn5buFbNxHgGMNh9zr2gcbHz2YaaBCfMApw3E8vADu3 EOS5G45ChvRSTjQJGvHX8gBEV2ZrUvbxnh6WEd1qfXKox7KqnZb7j --stake-net '50.00 SYS' --stake-cpu '50.00 SYS' --buy-ram-kbytes 10000
创建账户时,会一同加入owner,active两个组,(两个组的公钥可以用同一个,但不建议)
4.查看账户信息
cleos get account bcskill -j
也就是只要有EOS6fQzsc9Bn5buFbNxHgGMNh9zr2gcbHz2YaaBCfMApw3E8vADu3的私钥,就拥有对账户bcskill的owner权限组的权限
拥有EOS5G45ChvRSTjQJGvHX8gBEV2ZrUvbxnh6WEd1qfXKox7KqnZb7j的私钥,就拥有对账户bcskill的active权限组的权限
5.为bcskill账号增加自定义权限组custom,基于active
cleos set account permission bcskill custom '{"threshold":1,"keys":[{"key":"EOS5QxpwkWLAAWQqcT8teKrUceYr5Nj6PsBmCVoLaQQVqcoP2ZjF5","weight":1}],"accounts":[]}' active
6.查看账户信息
cleos get account bcskill -j
7.为权限组custom更换权限key
cleos set account permission bcskill custom '{"threshold": 1, "keys": [{"key": "EOS7UKzLPHVUTYpex48pRZokvBNEEp5KKXFGwcb5Qv6dZTWUYHGeP", "weight": 1}], "accounts": []}' active
8.查看账户信息
cleos get account bcskill -j
custom授权key已更新
9.为custom添加多个授权key
cleos set account permission bcskill custom '{"threshold":1,"keys":[{"key":"EOS5QxpwkWLAAWQqcT8teKrUceYr5Nj6PsBmCVoLaQQVqcoP2ZjF5","weight":1},{"key":"EOS7UKzLPHVUTYpex48pRZokvBNEEp5KKXFGwcb5Qv6dZTWUYHGeP","weight":1}],"accounts":[]}' active
10.查看账户信息
cleos get account bcskill -j
custom已有两个授权key
11.创建账号temporary
cleos system newaccount eosio temporary EOS7Yfs4kL6j9G8nmCTFt5ycLUpV4NmPaZKfuVfYC8XJbuDYPPdnA EOS7Yfs4kL6j9G8nmCTFt5ycLUpV4NmPaZKfuVfYC8XJbuDYPPdnA --stake-net '50.00 SYS' --stake-cpu '50.00 SYS' --buy-ram-kbytes 10000
12.为custom添加其他授权账号temporary
cleos set account permission bcskill custom '{"threshold":2,"keys":[{"key":"EOS5QxpwkWLAAWQqcT8teKrUceYr5Nj6PsBmCVoLaQQVqcoP2ZjF5","weight":1}],"accounts":[{"permission":{"actor":"temporary","permission":"active"},"weight":1}]}' active
13.查看账户信息
cleos get account bcskill -j
custom已有授权账号temporary
14.删除custom权限组
cleos set account permission bcskill custom 'NULL' active
15.查看账户信息
cleos get account bcskill -j
custom权限组已被删除
下一篇将讲解EOS账户权限的使用
版权属于:区块链中文技术社区 / 转载原创者
本文链接:https://bcskill.com/index.php/archives/51.html
相关技术文章仅限于相关区块链底层技术研究,禁止用于非法用途,后果自负!本站严格遵守一切相关法律政策!