Skip to content

Commit

Permalink
[document] Update account manager document. (#2545)
Browse files Browse the repository at this point in the history
  • Loading branch information
jolestar authored May 28, 2021
1 parent 4e4fde6 commit 17efec2
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 73 deletions.
81 changes: 44 additions & 37 deletions developer.starcoin.org/content/cli/account_manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ The Starcoin node has a built-in decentralized wallet that allows users to manag
When the node starts, a default account is automatically created with an empty password. The default can be changed via account commands. The following commands require a connection to the console, see [Using the starcoin console](./console). 1.



1. The account create command allows you to create an account
1. Create account

```bash
starcoin% account create -p my-pass
Expand All @@ -25,75 +24,83 @@ starcoin% account create -p my-pass

```

2. The account show command allows you to view the account status
2. Show account

```bash
starcoin% account show 0x8d885d806c14654832aa371c3c980153
+--------------------+--------------------------------------------------------------------+
| account.address | 0x8d885d806c14654832aa371c3c980153 |
+--------------------+--------------------------------------------------------------------+
| account.is_default | false |
+--------------------+--------------------------------------------------------------------+
| account.public_key | 0xf0a2cee9d7c85a40f3f217782b449fab9ba73fa11ab210f11d12305fdf57b908 |
+--------------------+--------------------------------------------------------------------+
| auth_key | 0xbc0b37f099741399c30dcd09cfd8a6118d885d806c14654832aa371c3c980153 |
+--------------------+--------------------------------------------------------------------+
| sequence_number | |
+--------------------+--------------------------------------------------------------------+
starcoin% account create -p my-pass
+--------------------+------------------------------------------------------------------------------------------+
| address | 0x812a1a9c8f03a008f96ae412baa69be8 |
+--------------------+------------------------------------------------------------------------------------------+
| is_default | false |
+--------------------+------------------------------------------------------------------------------------------+
| is_readonly | false |
+--------------------+------------------------------------------------------------------------------------------+
| public_key | 0x36012395c6ddf99cc4e6d60f35ac24b59c3a930d5e2611ac39d8bdfac2bfecf4 |
+--------------------+------------------------------------------------------------------------------------------+
| receipt_identifier | stc1psy4p48y0qwsq37t2usft4f5mapaeav0uh6uzu37raz2c7nz692tcz2s6nj8s8gqgl94wgy4656d7szgl0sw |
+--------------------+------------------------------------------------------------------------------------------+
```

- address is the address of the account.
- is_default Indicates whether the account is the default account. Many commands that require an account address parameter, if user not passed it, the command will use the default account address. If the node has enable the miner client, the default account will also be used for miner client.
- public_key is the public key corresponding to the address of the account.
- auth_key is the authentication key.

> Note that creating an account only creates a pair of keys in the starcoin node, and does not update the state of the chain. So balance and sequence_number are still empty at this point. All the above information is public information.

3. You can see the list of accounts through the account list
3. List accounts

```bash
starcoin% account list
+------------------------------------+------------+--------------------------------------------------------------------------------------------------------------------------------------+
| address | is_default | public_key |
+------------------------------------+------------+--------------------------------------------------------------------------------------------------------------------------------------+
| 0xddf5d370b6aae8251dacc99d1ff6fe94 | true | 0xaaf0b46c8a6bb88322e047aebdc90b0be7415583230d2dccff7b3fbe1fcfbfec |
+------------------------------------+------------+--------------------------------------------------------------------------------------------------------------------------------------+
| address | is_default | public_key |
+------------------------------------+------------+--------------------------------------------------------------------------------------------------------------------------------------+
| 0x8d885d806c14654832aa371c3c980153 | false | 0xf0a2cee9d7c85a40f3f217782b449fab9ba73fa11ab210f11d12305fdf57b908 |
+------------------------------------+------------+--------------------------------------------------------------------------------------------------------------------------------------+
```

- is_default: Indicates whether the account is the default account. Many commands that require an account address parameter, if user not passed it, the command will use the default account address. If the node has enable the miner client, the default account will also be used for miner client.

4. View or change the default account via the account default command
4. View or change the default account

To view the default account address.

```bash
account default
starcoin% account default
```
Set 0x8d885d806c14654832aa371c3c980153 to the default address.
Set 0x812a1a9c8f03a008f96ae412baa69be8 to the default address.
```bash
account default 0x8d885d806c14654832aa371c3c980153
starcoin% account default 0x812a1a9c8f03a008f96ae412baa69be8
```

> Note: After changing the default account, some services will not automatically use the new default account, it is better to restart the node.
5. Export and import accounts via the account export/import command
5. Export and import accounts

In order to avoid losing your assets due to disk corruption and other reasons, it is important to backup your private key.

Execute the following command:
```bash
account export 0x8d885d806c14654832aa371c3c980153 -p my-pass
starcoin% account export 0x812a1a9c8f03a008f96ae412baa69be8 -p my-pass
```
to export the private key of 0x8d885d806c14654832aa371c3c980153.

Execute the following command:

```bash
account import -i <private-key> -p my-pass 0x8d885d806c14654832aa371c3c980153
starcoin% account import -i <private-key> -p my-pass 0x812a1a9c8f03a008f96ae412baa69be8
```

This will import the 0x812a1a9c8f03a008f96ae412baa69be8 account. This command can also be used to import the account to a different node and used to do node migration.

6. Import readonly accounts


If you do not want to host the private key in the node wallet, but just want to view the account, or use the account as a mining account, you can import the read-only account with the public key:

```bash
starcoin% account import-readonly -i <public-key>
```

Then set the account as the default account.


7. Remove account

```bash
starcoin% account remove 0x812a1a9c8f03a008f96ae412baa69be8 -p my-pass
```

This will import the 0x8d885d806c14654832aa371c3c980153 account. This command can also be used to import the account to a different node and used to do node migration.
If it is a read-only account, you do not need to pass the -p parameter. Deleting an account only deletes the account from the node wallet and does not affect the account on the chain.
81 changes: 45 additions & 36 deletions developer.starcoin.org/content/cli/account_manager.zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,97 +9,106 @@ Starcoin 节点内置了一个去中心化的钱包,用户可以通过账号

节点启动的时候,会自动创建一个默认账号,默认密码是空。默认可以通过账号相关的命令进行变更。以下命令需要连接到控制台进行操作,连接方式请参看[使用 starcoin 控制台](./console)



1. 通过 account create 命令可以创建账号
1. 创建账号

```bash
starcoin% account create -p my-pass
+--------------------+------------------------------------------------------------------------------------------+
| address | 0xf95ba08e9015e99cf318cdf2d5b97bd7 |
| address | 0x812a1a9c8f03a008f96ae412baa69be8 |
+--------------------+------------------------------------------------------------------------------------------+
| is_default | false |
+--------------------+------------------------------------------------------------------------------------------+
| public_key | 0xdd28fce93aa5c28d4264ff9e0418063e53d3236e520f33dc1d48119da26860c2 |
| is_readonly | false |
+--------------------+------------------------------------------------------------------------------------------+
| public_key | 0x36012395c6ddf99cc4e6d60f35ac24b59c3a930d5e2611ac39d8bdfac2bfecf4 |
+--------------------+------------------------------------------------------------------------------------------+
| receipt_identifier | stc1pl9d6pr5szh5eeuccehedtwtm6ulk4f678xu5agr7ryntl9dt89c0jkaq36gpt6vu7vvvmuk4h9aawjyh2cd |
| receipt_identifier | stc1psy4p48y0qwsq37t2usft4f5mapaeav0uh6uzu37raz2c7nz692tcz2s6nj8s8gqgl94wgy4656d7szgl0sw |
+--------------------+------------------------------------------------------------------------------------------+

```

2. 通过 account show 命令可以查看账号状态
2. 查看账号

```bash
starcoin% account show 0xf95ba08e9015e99cf318cdf2d5b97bd7
starcoin% account show 0x812a1a9c8f03a008f96ae412baa69be8
+----------------------------+------------------------------------------------------------------------------------------+
| account.address | 0xf95ba08e9015e99cf318cdf2d5b97bd7 |
| account.address | 0x812a1a9c8f03a008f96ae412baa69be8 |
+----------------------------+------------------------------------------------------------------------------------------+
| account.is_default | false |
+----------------------------+------------------------------------------------------------------------------------------+
| account.public_key | 0xdd28fce93aa5c28d4264ff9e0418063e53d3236e520f33dc1d48119da26860c2 |
| account.is_readonly | false |
+----------------------------+------------------------------------------------------------------------------------------+
| account.receipt_identifier | stc1pl9d6pr5szh5eeuccehedtwtm6ulk4f678xu5agr7ryntl9dt89c0jkaq36gpt6vu7vvvmuk4h9aawjyh2cd |
| account.public_key | 0x36012395c6ddf99cc4e6d60f35ac24b59c3a930d5e2611ac39d8bdfac2bfecf4 |
+----------------------------+------------------------------------------------------------------------------------------+
| auth_key | 0x3f6aa75e39b94ea07e1926bf95ab3970f95ba08e9015e99cf318cdf2d5b97bd7 |
| account.receipt_identifier | stc1psy4p48y0qwsq37t2usft4f5mapaeav0uh6uzu37raz2c7nz692tcz2s6nj8s8gqgl94wgy4656d7szgl0sw |
+----------------------------+------------------------------------------------------------------------------------------+
| auth_key | 0x7b9eb1fcbeb82e47c3e8958f4c5a2a97812a1a9c8f03a008f96ae412baa69be8 |
+----------------------------+------------------------------------------------------------------------------------------+
| sequence_number | |
+----------------------------+------------------------------------------------------------------------------------------+

```

- address 是账户地址
- is_default 表示是否为默认账号。很多命令如果需要账号参数,但用户没有传递,则会使用默认账号。如果节点开启了挖矿客户端,也会使用默认账号进行挖矿。
- is_readonly 表示是否为只读账号,只读账号的私钥并不托管在节点钱包中。
- public_key 是账户地址对应的公钥
- receipt_identifier 是收款人识别码
- auth_key 是认证秘钥,最后是需要写到链上去的
- auth_key 是认证秘钥,最后是需要写到链上去的

> 注意,创建账户只是在 starcoin node 里创建一对密钥,并不会更新链的状态。所以 balance 和 sequence_number 此时还是空的。以上信息都属于公开信息,只有私钥是需要用户保密的。

3. 通过 account list 可以查看账号列表
3. 查看账号列表

```bash
starcoin% account list
+------------------------------------+------------+--------------------------------------------------------------------------------------------------------------------------------------+
| address | is_default | public_key |
+------------------------------------+------------+--------------------------------------------------------------------------------------------------------------------------------------+
| 0xddf5d370b6aae8251dacc99d1ff6fe94 | true | 0xaaf0b46c8a6bb88322e047aebdc90b0be7415583230d2dccff7b3fbe1fcfbfec |
+------------------------------------+------------+--------------------------------------------------------------------------------------------------------------------------------------+
| address | is_default | public_key |
+------------------------------------+------------+--------------------------------------------------------------------------------------------------------------------------------------+
| 0x8d885d806c14654832aa371c3c980153 | false | 0xf0a2cee9d7c85a40f3f217782b449fab9ba73fa11ab210f11d12305fdf57b908 |
+------------------------------------+------------+--------------------------------------------------------------------------------------------------------------------------------------+
```

- is_default: 表示是否为默认账号。很多命令如果需要账号参数,但用户没有传递,则会使用默认账号。如果节点开启了挖矿客户端,也会使用默认账号进行挖矿。

4. 通过 account default 命令查看或者变更默认账号
4. 查看或者变更默认账号

查看默认账号地址:

```bash
account default
starcoin% account default
```
0x8d885d806c14654832aa371c3c980153 设置位默认地址。
0x812a1a9c8f03a008f96ae412baa69be8 设置位默认地址。
```bash
account default 0x8d885d806c14654832aa371c3c980153
starcoin% account default 0x812a1a9c8f03a008f96ae412baa69be8
```

> 注意:改变默认账号后,有的服务不会自动使用新的默认账号,最好重启一下节点。
5. 通过 account export/import 命令导出导入账号
5. 导出导入账号

为了避免磁盘损坏等原因导致自己的资产损失,备份自己的私钥非常重要。

执行以下命令:
```bash
account export 0x8d885d806c14654832aa371c3c980153 -p my-pass
starcoin% account export 0x812a1a9c8f03a008f96ae412baa69be8 -p my-pass
```
即可导出 0x8d885d806c14654832aa371c3c980153 的私钥。
即可导出 0x812a1a9c8f03a008f96ae412baa69be8 的私钥。

执行以下命令:

```bash
account import -i <private-key> -p my-pass 0x8d885d806c14654832aa371c3c980153
starcoin% account import -i <private-key> -p my-pass 0x812a1a9c8f03a008f96ae412baa69be8
```

即可导入 0x812a1a9c8f03a008f96ae412baa69be8 账号。这个命令也可以用于将账号导入到不同的节点上,用来做节点迁移。

6. 导入只读账号

如果不想把私钥托管在节点钱包中,只是想查看该账号,或者将该账号作为挖矿账号,可以通过公钥导入只读账号:

```bash
starcoin% account import-readonly -i <public-key>
```

然后将该账号设置为默认账号。

7. 删除账号

```bash
starcoin% account remove 0x812a1a9c8f03a008f96ae412baa69be8 -p my-pass
```

即可导入 0x8d885d806c14654832aa371c3c980153 账号。这个命令也可以用于将账号导入到不同的节点上,用来做节点迁移
如果是只读账号,无需传递 -p 参数。删除账号只是将账号从节点钱包中删除,并不影响该账号在链上的状态
3 changes: 3 additions & 0 deletions testsuite/features/cmd.feature
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ Feature: cmd integration test
Then cmd: "account unlock -p test @$.address@"
Then cmd: "account change-password @$.address@ -p hello"
Then cmd: "account remove @$.address@ -p hello"
Then cmd: "account generate-keypair"
Then cmd: "account import-readonly -i @$[0].public_key@"
Then cmd: "account remove @$.address@"
Then cmd: "account list"
Then cmd: "account show"
# Then cmd: "account execute-builtin --blocking --script empty_script -s @$.account.address@"
Expand Down

0 comments on commit 17efec2

Please sign in to comment.