Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wallet] Add merge/split coins command to the wallet #657

Merged
merged 3 commits into from
Mar 5, 2022

Conversation

patrickkuo
Copy link
Contributor

@patrickkuo patrickkuo commented Mar 4, 2022

  • added merge-coin and split-coin commends to the wallet
  • added doc for merge and split coins
  • changed Client api's merge and split coin function to receive ObjectID instead of ObjectRef
  • Implemented display for Merge and Split coin response

@patrickkuo patrickkuo self-assigned this Mar 4, 2022
@patrickkuo patrickkuo requested review from lxfind, awelc and oxade March 4, 2022 15:11
@patrickkuo patrickkuo force-pushed the pat/wallet_merge_split_coin branch from ce19bef to dc83746 Compare March 4, 2022 19:09
@patrickkuo patrickkuo marked this pull request as ready for review March 4, 2022 19:11
@patrickkuo
Copy link
Contributor Author

@Clay-Mysten can you please help review the docs?


/// Split a coin object into multiple coins.
SplitCoin {
/// Coin to Split, in 20 bytes Hex string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optionally, lowercase hex throughout:
https://en.wikipedia.org/wiki/Hexadecimal

Totally not a big deal though.

Sui wallet. The config file contains information of the accounts and
the Sui network. Sui wallet uses the network information to communicate
the Sui network. The keystore file contains all the public private key pair of the created accounts.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public-private key pairs

Copy link
Contributor

@lxfind lxfind left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Like the Displays

The `accounts` variable contains all of the account's address and key pairs.
This will be used by the wallet to sign transactions. The `authorities`
variable contains Sui network authorities' name, host and port information.
The `accounts` variable contains account's address the wallet manages.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contains the

and object data belonging to the account.

#### Key management
As you might have noticed, the key pairs are stored as plain text in `wallet.conf`,
which is not secure and shouldn't be used in a production environment. We have plans to
The key pairs are stored in `wallet.key`, however, it is not secure
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

. However, this is

@@ -203,17 +205,242 @@ Created new keypair for address : 3F8962C87474F8FB8BFB99151D5F83E677062078

#### Add existing accounts to `wallet.conf` manually.

If you have existing key pair from an old wallet config, you can copy the account data manually to the new `wallet.conf`'s accounts section.
If you have existing key pair from an old wallet config, you can copy the account
address manually to the new `wallet.conf`'s accounts section, and add the keypair to the keystore file,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key pair (for consistency with previous references)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throughout (three references are joined)

@@ -203,17 +205,242 @@ Created new keypair for address : 3F8962C87474F8FB8BFB99151D5F83E677062078

#### Add existing accounts to `wallet.conf` manually.

If you have existing key pair from an old wallet config, you can copy the account data manually to the new `wallet.conf`'s accounts section.
If you have existing key pair from an old wallet config, you can copy the account
address manually to the new `wallet.conf`'s accounts section, and add the keypair to the keystore file,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would replace the comma at the end of this line with a semicolon (;) since the previous and next sentence are complete.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also:

If you have an existing key pair


FLAGS:
-h, --help Prints help information
--json Return command outputs in json format
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON (in description/output)


FLAGS:
-h, --help Prints help information
--json Return command outputs in json format
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returns (to agree with the previous and following Prints)

-V, --version Prints version information

OPTIONS:
--address <address> Address owning the objects
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the

argument takes or does. What is the active verb that should proceed "Address owning the objects" here?

OPTIONS:
--address <address> Address owning the objects
```
To view the objects owned by the accounts created in genesis, run the following command in the Sui interactive console (substitute the address with one of the genesis address in your wallet):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

of the genesis addresses (plural)

(9C7626A4CBFFCE894518B8A317F06D051597A378, SequenceNumber(0), o#10dd0b5cabf227952a6e731001d3b57039595225eb188ca6e7ac65bf55ac7c6f)
(AFA6A58082E961E8706FFF48A0D531C2BED8A94D, SequenceNumber(0), o#2c4b5c7c8be3055287deb4d445c87cf02603d84155d761bcd71f0457d76254ad)
```
If you want to view more information about the objects, you can use the `object` command.
Copy link
Contributor

@Clay-Mysten Clay-Mysten Mar 4, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we repeating this here when we have it at the beginning of this section ## View objects owned by the account?

Ah, we should centralize the generic flags (-h, --json, -V) at the beginning, before address and then focus upon only the new argument (address, object, etc.).

```shell
sui>-$ objects --address 0DC70EA8CA82FE6966900C697B73A235B8E2346F
```
The result should look similar to the following, which shows the object in the format of (`object_id`, `sequence_number`, `object_hash`).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace "look similar to" with "resemble" throughout

Type: 0x2::Coin::Coin<0x2::GAS::GAS>
```
The result shows some basic information about the object, the owner,
version, id, if the object is immutable and the type of the object.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ID

The result shows some basic information about the object, the owner,
version, id, if the object is immutable and the type of the object.
If you need a deeper look into the object, you can use the `--json`
flag to view the raw json representation of the object.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON

sui>-$ objects --address 830F66EA8EA867DDCA479535BC12CE2852E571F2
Showing 0 results.
```
To add objects to the account, you can invoke a move function (see [Calling Move code](#calling-move-code) for more information),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optionally, simply make "invoke a move function" the link, like so:

you can invoke a move function, or you can transfer...

Showing 0 results.
```
To add objects to the account, you can invoke a move function (see [Calling Move code](#calling-move-code) for more information),
or you can transfer one of the existing object from the genesis account to the new account.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one of the existing objects

--to <to> Recipient address
```
To transfer an object to a recipient, you will need the recipient's address,
the object id of the object that you want to transfer,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

object ID

```
To transfer an object to a recipient, you will need the recipient's address,
the object id of the object that you want to transfer,
and the gas object' id for the transaction fee payment.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gas object's ID

@lxfind
Copy link
Contributor

lxfind commented Mar 4, 2022

Hi @Clay-Mysten , I think you could use the "Start a review" button to batch review them, instead of adding single comment on each review :)

the object id of the object that you want to transfer,
and the gas object' id for the transaction fee payment.

Here is an example of a transfer of object to account `830F66EA8EA867DDCA479535BC12CE2852E571F2`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is an example transfer of an object to account...

```

## Merging and splitting coin objects
Overtime, the account might receive coins from other account and will become unmanageable when
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from other accounts (plural)


## Merging and splitting coin objects
Overtime, the account might receive coins from other account and will become unmanageable when
the number of coins grows; contrarily the account might need to split the coin for payment or
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contrarily,


## Merging and splitting coin objects
Overtime, the account might receive coins from other account and will become unmanageable when
the number of coins grows; contrarily the account might need to split the coin for payment or
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split the coins (plural?)

## Merging and splitting coin objects
Overtime, the account might receive coins from other account and will become unmanageable when
the number of coins grows; contrarily the account might need to split the coin for payment or
for transfer to other account.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to another account.

the number of coins grows; contrarily the account might need to split the coin for payment or
for transfer to other account.

We can use the `merge-coin` command and `split-coin` command to consolidate or split coins.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or split coins, respectively.

--gas-budget <gas-budget> Gas budget for this call
--primary-coin <primary-coin> Coin to merge into, in 20 bytes Hex string
```
Here is an example of how to merge coins, to merge coins, you will need at lease three coin objects -
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would replace this first comma with a period, like so:

coins. To

-V, --version Prints version information

OPTIONS:
--amounts <amounts>... Amount to split out from the coin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have ellipsis here:

...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is generated by the code, it means the --amounts options can take multiple values

Updated Gas : Coin { id: B7FD91A802DAF5523CAAB69FF4652FAFA6FF4ADF, value: 99996 }
```

### Split coin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optionally, make plural:

Split coins

For splitting coins, you will need at lease two coins to execute the `split-coin` command,
one coin to split, one for the gas payment.

Here is an example of splitting coin, we are splitting out three new coins from the original coin,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

example of splitting coins (assuming we decided on plural; if not, not worries)

one coin to split, one for the gas payment.

Here is an example of splitting coin, we are splitting out three new coins from the original coin,
with values of 1000, 5000 and 3000 respectively, note that the `--amounts` accepts list of values.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

with values of 1000, 5000 and 3000, respectively; note that the --amounts argument accepts a list of values.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an excellent point, by the way. I would have been confused seeing the command next without this. Thanks!

(B7FD91A802DAF5523CAAB69FF4652FAFA6FF4ADF, SequenceNumber(3), o#839e98b33b3de62bc84c36c35b9fd6cdf3383f9d7c4f760c398cbbc7bef8c932)
(BFA8BAB64ED8F74BA3731C9220FD7462456BC601, SequenceNumber(1), o#6748854128a8b4746fb5bd124eddafc4f9129bae36a8a34af85a8f29b07ee124)
```
From the result we can see three new coins got created in the transaction.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coins were created

Copy link
Contributor

@Clay-Mysten Clay-Mysten left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fantastic work, Patrick! An absolutely wonderful addition to our docs.

If you simply want to merge, I will gladly make these non-semantic changes myself. Thanks!

@patrickkuo patrickkuo force-pushed the pat/wallet_merge_split_coin branch from dc83746 to f75efb6 Compare March 5, 2022 00:24
@patrickkuo patrickkuo merged commit 2b5e4f7 into main Mar 5, 2022
@patrickkuo patrickkuo deleted the pat/wallet_merge_split_coin branch March 5, 2022 00:49
@patrickkuo patrickkuo linked an issue Mar 7, 2022 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[wallet] Add merge/split coins command to the wallet
3 participants