@hitchhacker
2018-07-23T13:29:40.000000Z
字数 2338
阅读 1973
输入以下命令:
cleos get account [账户名]
查看该账户的信息。
返回如下结果:
{
"account_name": "gakki",
"permissions": [{
"perm_name": "active",
"parent": "owner",
"required_auth": {
"threshold": 1,
"keys": [{
"key": "EOS6mzzYJfUq2V55PRLrfu4UqoSt1wKMs6XvbxCFfw4trsnqECC97",
"weight": 1
}
],
"accounts": []
}
},{
"perm_name": "owner",
"parent": "",
"required_auth": {
"threshold": 1,
"keys": [{
"key": "EOS6mzzYJfUq2V55PRLrfu4UqoSt1wKMs6XvbxCFfw4trsnqECC97",
"weight": 1
}
],
"accounts": []
}
}
]
}
在第二讲的时候,我们创建账户的时候输入的是如下命令:
cleos create account eosio [新账户名] [ 生成的公钥 ] [ 生成的公钥 ]
有人会产生这个疑问:为什么公钥要输入两次呢?这一串命令的实际形式是这样的:
cleos create account [授权账户] [新账户名] [所有者(owner)公钥] [活跃(active)公钥]
原文:
owner authority symbolizes ownership of an account. There are only a few transactions that require this authority, but most notably, are actions that make any kind of change to the owner authority. Generally, it is suggested that owner is kept in cold storage and not shared with anyone. owner can be used to recover another permission that may have been compromised.
active authority is used for transferring funds, voting for producers and making other high-level account changes.
输入以下命令:
cleos get accounts [公钥]
查看该公钥下的所有账户。
返回如下结果:
{
"account_names": [
"gakki",
"gakkifans"
]
}
输入以下命令:
cleos get servants [主人账户名]
返回主人账户下的所有仆人账户。
例如我们输入:
cleos get servants eosio
返回如下结果:
{
"controlled_accounts": [
"gakki",
"gakkifans"
]
}
输入以下命令:
cleos set account permission [「仆人」账户名] [权限名(例如active或者owner)] [一个JSON] [ [授权的权限名,一般是 owner]
例如:
「仆人」账户名: sb2
权限名: active
一个 JSON:
'{"threshold":2,"keys":[{"key":"EOS6mzzYJfUq2V55PRLrfu4UqoSt1wKMs6XvbxCFfw4trsnqECC97","weight":1}],"accounts":[{"permission":{"actor":"gakki","permission":"active"},"weight":1}]}'
授权的权限名: owner
然后这行代码是这样的:
cleos set account permission sb2 active '{"threshold":2,"keys":[{"key":"EOS6mzzYJfUq2V55PRLrfu4UqoSt1wKMs6XvbxCFfw4trsnqECC97","weight":1}],"accounts":[{"permission":{"actor":"gakki","permission":"active"},"weight":1}]}' owner
那么这行鬼画符一样的JSON又是什么呢?别急,让我们继续拆解:
Threshold:一个整数——授权所需的签名权重的和
keys:一个数组——由EOSIO样式的公钥代表的每个权限所组成。
account:一个数组——由EOSIO样式的账户代表的每个权限所组成。
所以,别憷,构建这个JSON很容易,我们只要把这篇文章里的JSON复制过去,然后修改key为「主人」账户的公钥,修改actor为「主人」账户的名字即可。然后还要注意的,就是所有的weight加起来要等于Threshold了。
我们运行这一串命令,返回如下结果即表示操作成功。
再用cleos get account sb2
这个命令查看账户具体信息,发现gakki具有本账户的active权限。
再用cleos get servants gakki
查看一下gakki的仆人,嗯,sb2赫然在列!