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

Add Publish & Custom Genesis REST documentation. #1176

Merged
merged 13 commits into from
Apr 7, 2022
Prev Previous commit
Next Next commit
merge main
  • Loading branch information
arun-koshy committed Apr 5, 2022
commit d13f59ae0264c5522bef1f487db5369a98e1d236
6 changes: 2 additions & 4 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@ jobs:
toolchain: beta
components: clippy
override: true
# See '.cargo/config' for list of enabled/disappled clippy lints
- name: cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets -- -D clippy::all -D warnings -D clippy::disallowed_methods
run: cargo xclippy -D warnings
- name: cargo test
uses: actions-rs/cargo@v1
with:
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,9 @@ jobs:
- uses: bmwill/rust-cache@v1 # Fork of 'Swatinem/rust-cache' which allows caching additional paths
with:
path: ~/.cargo/registry/src/**/librocksdb-sys-*
# See '.cargo/config' for list of enabled/disappled clippy lints
- name: cargo clippy
uses: actions-rs/cargo@v1
with:
command: clippy
args: --all-targets -- -D clippy::all -D warnings -D clippy::disallowed_methods
run: cargo xclippy -D warnings

rustfmt:
needs: diff
Expand Down
17 changes: 9 additions & 8 deletions doc/src/build/rest-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,9 @@ You should replace `{{owner_address}}` and `{{to_address}}` in the
command above with an actual address values, for example one obtained
from `wallet.conf`. You should also replace
`{{coin_object_id}}` and `{{gas_object_id}}` in the command above with
an actual object ID, for example one obtained from `objType` in the output
an actual object ID, for example one obtained from `objId` in the output
of [`GET /objects`](#get-apiobjects). You can see that all gas objects generated
during genesis are of `Coin/SUI` type. For this call to work, objects
during genesis are of `Coin/SUI` type). For this call to work, objects
represented by both `{{coin_object_id}}` and `{{gas_object_id}}` must
be owned by the address represented by `{{owner_address}}`.

Expand Down Expand Up @@ -254,12 +254,13 @@ the process of publishing a Move package). Gas budget is required because of the
need to execute module initializers.

You should replace `{{owner_address}}` in the
command above with an actual address value, for example one obtained
from [`GET /addresses`](#get-addresses). You should also replace `{{gas_object_id}}` in the command above with an actual object ID, for example one obtained from [`GET
/objects`](#get-objects) (from `objType` in the output of [`GET
/objects`](#get-objects). You can see that all gas objects generated
during genesis are of `Coin/SUI` type). For this call to work, `{{gas_object_id}}` must
be owned by the address represented by `{{owner_address}}`.
command above with an actual address values, for example one obtained
from `wallet.conf`. You should also replace `{{gas_object_id}}` in the command above with
an actual object ID, for example one obtained from `objId` in the output
of [`GET /objects`](#get-apiobjects). You can see that all gas objects generated
during genesis are of `Coin/SUI` type). For this call to work, the object
represented by `{{gas_object_id}}` must be owned by the address represented by
`{{owner_address}}`.

To publish a Move module, you also need `{{vector_of_compiled_modules}}`. To generate the value of this field, you can use the `sui-move` command. The `sui-move` command supports printing the bytecodes as hex with the following option

Expand Down
53 changes: 32 additions & 21 deletions doc/src/build/wallet.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,14 @@ $ wallet --config /path/to/wallet/config/file
```

The Sui interactive wallet supports the following shell functionality:
* Command History

* *Command history* -
The `history` command can be used to print the interactive shell's command history;
you can also use Up, Down or Ctrl-P, Ctrl-N to navigate previous or next matches from history.
History search is also supported using Ctrl-R.
* *Tab completion* -
Tab completion is supported for all commands using Tab and Ctrl-I keys.
* Environment variable substitution
* *Environment variable substitution* -
The wallet shell will substitute inputs prefixed with `$` with environment variables,
you can use the `env` command to print out the entire list of variables and
use `echo` to preview the substitution without invoking any commands.
Expand Down Expand Up @@ -335,26 +336,26 @@ To see how much gas is in an account, use the `gas` command. Note that this comm

```
wallet --no-shell gas
Object ID | Version | Gas Value
Object ID | Version | Gas Value
----------------------------------------------------------------------
0B8A4620426E526FA42995CF26EB610BFE6BF063 | 0 | 100000
3C0763CCDEA4FF5A4557505A62AB5E1DAF91F4A2 | 0 | 100000
45A589A9E760D7F75D399327AC0FCBA21495C22E | 0 | 100000
4C377A3A9D4B1B9C92189DD12BB1DCD0302A954B | 0 | 100000
F2961464AC6860A05D21B48C020B7E121399965C | 0 | 100000
0B8A4620426E526FA42995CF26EB610BFE6BF063 | 0 | 100000
3C0763CCDEA4FF5A4557505A62AB5E1DAF91F4A2 | 0 | 100000
45A589A9E760D7F75D399327AC0FCBA21495C22E | 0 | 100000
4C377A3A9D4B1B9C92189DD12BB1DCD0302A954B | 0 | 100000
F2961464AC6860A05D21B48C020B7E121399965C | 0 | 100000
```

If one does not want to use the active address, the addresses can be specified:

```
/wallet --no-shell gas --address 562F07CF6369E8D22DBF226A5BFEDC6300014837
Object ID | Version | Gas Value
Object ID | Version | Gas Value
----------------------------------------------------------------------
A8DDC2661A19010E5F85CBF6D905DDFBE4DD0320 | 0 | 100000
B2683D0B592E5B002D110989A52943BC9DA19158 | 0 | 100000
B41BF45B01C9BEFCE3A0A371E2B98E062691438D | 0 | 100000
BA9E10F319182F3BD584EDB92C7899CC6D018723 | 0 | 100000
F8BFE77A5B21E7ABFA3BC285991F9DA4E5CC2D7B | 0 | 100000
A8DDC2661A19010E5F85CBF6D905DDFBE4DD0320 | 0 | 100000
B2683D0B592E5B002D110989A52943BC9DA19158 | 0 | 100000
B41BF45B01C9BEFCE3A0A371E2B98E062691438D | 0 | 100000
BA9E10F319182F3BD584EDB92C7899CC6D018723 | 0 | 100000
F8BFE77A5B21E7ABFA3BC285991F9DA4E5CC2D7B | 0 | 100000

```

Expand Down Expand Up @@ -483,27 +484,37 @@ We will explore how to transfer objects using the wallet in this section.

```shell
USAGE:
transfer [FLAGS] --gas <gas> --gas-budget <gas-budget> --object-id <object-id> --to <to>
transfer [FLAGS] [OPTIONS] --gas-budget <gas-budget> --object-id <object-id> --to <to>

FLAGS:
-h, --help Prints help information
--json Returns command outputs in JSON format
-V, --version Prints version information

OPTIONS:
--gas <gas> ID of the gas object for gas payment, in 20 bytes Hex string
--gas <gas> ID of the gas object for gas payment, in 20 bytes Hex string If not provided, a gas
object with at least gas_budget value will be selected
--gas-budget <gas-budget> Gas budget for this transfer
--object-id <object-id> Object to transfer, in 20 bytes Hex string
--to <to> Recipient address
--object-id <object-id> Object to transfer, in 20 bytes Hex string
--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,
and the gas object ID for the transaction fee payment. Gas budget sets a cap for how much gas you want to spend.
We are still finalizing our gas metering mechanisms. For now, just set something large enough.
and optionally the gas object ID for the transaction fee payment. If a gas
object is not specified, one that meets the budget is picked. Gas budget sets a
cap for how much gas you want to spend. We are still finalizing our gas metering
mechanisms. For now, just set something large enough.

Here is an example transfer of an object to account `F456EBEF195E4A231488DF56B762AC90695BE2DD`:

```shell
$ wallet --no-shell transfer --to C72CF3ADCC4D11C03079CEF2C8992AEA5268677A --object-id DA2237A9890BCCEBEEEAE0D23EC739F00D2CE2B1 --gas 00A0A5211F6EDCF4BA09D23B8A7250072BE1EDB6 --gas-budget 100
$ wallet --no-shell transfer --to C72CF3ADCC4D11C03079CEF2C8992AEA5268677A --object-id DA2237A9890BCCEBEEEAE0D23EC739F00D2CE2B1 --gas-budget 100
```

With output like:

```
Transfer confirmed after 4412 us
----- Certificate ----
Signed Authorities : [k#21d89c3a12409b7aeadf36a9753417ead5fa9ea607ccb666e83b739b8a73c5e8, k#8d86bef2f8ae835d4763c9a697ad5c458130907996d59adc4ea5be37f2e0fab2, k#f9664056f3cc46b03e86beeb3febf99af1c9ec3f6aa709a1dbd101c9e9a79c3a]
Expand Down
4 changes: 4 additions & 0 deletions sui/src/sui_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ impl SuiCommand {
keystore.save(&keystore_path)?;
info!("Wallet keystore is stored in {:?}.", keystore_path);

// Use the first address if any
let active_address = accounts.get(0).copied();

let gateway_config = GatewayConfig {
db_folder_path,
authorities: network_config.get_authority_infos(),
Expand All @@ -152,6 +155,7 @@ impl SuiCommand {
accounts,
keystore: KeystoreType::File(keystore_path),
gateway: GatewayType::Embedded(PersistedConfig::read(&gateway_path)?),
active_address,
};

let wallet_config = wallet_config.persisted(&wallet_path);
Expand Down
11 changes: 5 additions & 6 deletions sui/src/unit_tests/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ use std::time::Duration;
use crate::cli_tests::sui_network::start_test_network;
use move_core_types::identifier::Identifier;
use serde_json::{json, Value};
use tracing_test::traced_test;

use crate::cli_tests::sui_network::start_test_network;
use std::fmt::Write;
use sui::config::{
AccountConfig, Config, GenesisConfig, NetworkConfig, ObjectConfig, PersistedConfig,
Expand All @@ -25,11 +22,13 @@ use sui::sui_commands::SuiCommand;
use sui::sui_json::SuiJsonValue;
use sui::wallet_commands::{WalletCommandResult, WalletCommands, WalletContext};
use sui::{SUI_GATEWAY_CONFIG, SUI_NETWORK_CONFIG, SUI_WALLET_CONFIG};
use sui_core::gateway_state::gateway_responses::SwitchResponse;
use sui_types::base_types::{ObjectID, SequenceNumber, SuiAddress};
use sui_types::crypto::get_key_pair;
use sui_types::gas_coin::GasCoin;
use sui_types::messages::TransactionEffects;
use sui_types::object::{Object, ObjectRead, GAS_VALUE_FOR_TESTING};
use tracing_test::traced_test;

const TEST_DATA_DIR: &str = "src/unit_tests/data/";
const AIRDROP_SOURCE_CONTRACT_ADDRESS: &str = "bc4ca0eda7647a8ab7c2061c2e118a18a936f13d";
Expand Down Expand Up @@ -501,7 +500,7 @@ async fn test_gas_command() -> Result<(), anyhow::Error> {
WalletCommands::Transfer {
to: recipient,
object_id: object_to_send,
gas: object_id,
gas: Some(object_id),
gas_budget: 50000,
}
.execute(&mut context)
Expand Down Expand Up @@ -1087,7 +1086,7 @@ async fn test_switch_command() -> Result<(), anyhow::Error> {
.execute(&mut context)
.await?;

// Run a command with address ommited
// Run a command with address omitted
let os = WalletCommands::Objects { address: None }
.execute(&mut context)
.await?;
Expand Down Expand Up @@ -1170,7 +1169,7 @@ async fn test_active_address_command() -> Result<(), anyhow::Error> {
.execute(&mut context)
.await?;

// Run a command with address ommited
// Run a command with address omitted
let os = WalletCommands::ActiveAddress {}
.execute(&mut context)
.await?;
Expand Down
3 changes: 2 additions & 1 deletion sui/src/unit_tests/sui_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub async fn start_test_network(
info
})
.collect();

let active_address = accounts.get(0).copied();
// Create wallet config with stated authorities port
WalletConfig {
accounts,
Expand All @@ -60,6 +60,7 @@ pub async fn start_test_network(
authorities,
..Default::default()
}),
active_address,
}
.persisted(&wallet_path)
.save()?;
Expand Down
65 changes: 43 additions & 22 deletions sui/src/wallet_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub enum WalletCommands {
/// ID of the gas object for gas payment, in 20 bytes Hex string
/// If not provided, a gas object with at least gas_budget value will be selected
#[structopt(long)]
gas: ObjectID,
gas: Option<ObjectID>,

/// Gas budget for this transfer
#[structopt(long)]
Expand Down Expand Up @@ -343,15 +343,38 @@ impl WalletCommands {
gas,
gas_budget,
} => {
let gas_object_info = context.gateway.get_object_info(*gas).await?;
let gas_object = gas_object_info.object()?;
let obj = context
.gateway
.get_object_info(*object_id)
.await?
.object()?
.clone();
let forbidden_gas_objects = BTreeSet::from([*object_id]);

// If this isnt the active account, and no gas is specified, derive sender and gas from object to be sent
let gas_object = if context.active_address()? != obj.owner.get_owner_address()?
&& gas.is_none()
{
context
.gas_for_owner_budget(
obj.owner.get_owner_address()?,
*gas_budget,
forbidden_gas_objects,
)
.await?
.1
} else {
context
.choose_gas_for_wallet(*gas, *gas_budget, forbidden_gas_objects)
.await?
};
let from = gas_object.owner.get_owner_address()?;

let time_start = Instant::now();

let data = context
.gateway
.transfer_coin(from, *object_id, *gas, *gas_budget, *to)
.transfer_coin(from, *object_id, gas_object.id(), *gas_budget, *to)
.await?;
let signature = context
.keystore
Expand All @@ -377,7 +400,11 @@ impl WalletCommands {
}

WalletCommands::Objects { address } => {
WalletCommandResult::Objects(context.gateway.get_owned_objects(*address)?)
let address = match address {
Some(a) => *a,
None => context.active_address()?,
};
WalletCommandResult::Objects(context.gateway.get_owned_objects(address)?)
}

WalletCommands::SyncClientState { address } => {
Expand All @@ -395,23 +422,17 @@ impl WalletCommands {
WalletCommandResult::NewAddress(address)
}
WalletCommands::Gas { address } => {
context.gateway.sync_account_state(*address).await?;
let object_refs = context.gateway.get_owned_objects(*address)?;

// TODO: We should ideally fetch the objects from local cache
let mut coins = Vec::new();
for (id, _, _) in object_refs {
match context.gateway.get_object_info(id).await? {
Exists(_, o, _) => {
if matches!( o.type_(), Some(v) if *v == GasCoin::type_()) {
// Okay to unwrap() since we already checked type
let gas_coin = GasCoin::try_from(o.data.try_as_move().unwrap())?;
coins.push(gas_coin);
}
}
_ => continue,
}
}
let address = match address {
Some(a) => *a,
None => context.active_address()?,
};
let coins = context
.gas_objects(address)
.await?
.iter()
// Ok to unwrap() since `get_gas_objects` guarantees gas
.map(|q| GasCoin::try_from(&q.1).unwrap())
.collect();
WalletCommandResult::Gas(coins)
}
WalletCommands::SplitCoin {
Expand Down
Loading
You are viewing a condensed version of this merge commit. You can view the full changes here.