Skip to content

Commit

Permalink
Ignore chain id when using --dump-bytecode-as-base64 in `sui move b…
Browse files Browse the repository at this point in the history
…uild` (#20475)

## Description 

Allow `sui move build --dump-bytecode-as-base64` to not need to read the
chain from `client.yaml` by adding a flag `--ignore-chain`. This allows
building to proceed without a network connection or active environment,
but it will not be able to automatically determine the addresses of its
dependencies.
NB: `--ignore-chain` depends on `dump-bytecode-as-base64`, so it cannot
be used on its own.

Should close #20458.

## Test plan 

Local test.
```
➜  first_package git:(main) ✗ sui move build --dump-bytecode-as-base64 --ignore-chain
INCLUDING DEPENDENCY Sui
INCLUDING DEPENDENCY MoveStdlib
BUILDING my_first_package
JSON_OUTPUT_HERE - replaced for brevity.
➜  first_package git:(main) ✗ sui move build --dump-bytecode-as-base64
Config file ["/Users/user/.sui/sui_config/client.yaml"] doesn't exist, do you want to connect to a Sui Full node server [y/N]?
```
---
## Release notes

Check each box that your changes affect. If none of the boxes relate to
your changes, release notes aren't required.

For each box you select, include information after the relevant heading
that describes the impact of your changes that a user might notice and
any actions they must take to implement updates.

- [ ] Protocol: 
- [ ] Nodes (Validators and Full nodes): 
- [ ] Indexer: 
- [ ] JSON-RPC: 
- [ ] GraphQL: 
- [x] CLI: Added the flag `--ignore-chain` that works together with `sui
move build --dump-bytecode-as-base64` to bypass the need for a
`client.yaml` file. This allows building to proceed without a network
connection or active environment, but it will not be able to
automatically determine the addresses of its dependencies. NB:
`--ignore-chain` depends on `--dump-bytecode-as-base64`, so it cannot be
used on its own.
- [ ] Rust SDK:
- [ ] REST API:

---------

Co-authored-by: Ashok Menon <[email protected]>
  • Loading branch information
stefan-mysten and amnn authored Dec 2, 2024
1 parent 84498cb commit bb714c5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
5 changes: 5 additions & 0 deletions crates/sui-move/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ pub struct Build {
/// Whether we are printing in base64.
#[clap(long, global = true)]
pub dump_bytecode_as_base64: bool,
/// Don't specialize the package to the active chain when dumping bytecode as Base64. This
/// allows building to proceed without a network connection or active environment, but it
/// will not be able to automatically determine the addresses of its dependencies.
#[clap(long, global = true, requires = "dump_bytecode_as_base64")]
pub ignore_chain: bool,
/// If true, generate struct layout schemas for
/// all struct types passed into `entry` functions declared by modules in this package
/// These layout schemas can be consumed by clients (e.g.,
Expand Down
30 changes: 17 additions & 13 deletions crates/sui/src/sui_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,20 +486,24 @@ impl SuiCommand {
} => {
match &mut cmd {
sui_move::Command::Build(build) if build.dump_bytecode_as_base64 => {
// `sui move build` does not ordinarily require a network connection.
// The exception is when --dump-bytecode-as-base64 is specified: In this
// case, we should resolve the correct addresses for the respective chain
// (e.g., testnet, mainnet) from the Move.lock under automated address management.
let config =
client_config.unwrap_or(sui_config_dir()?.join(SUI_CLIENT_CONFIG));
prompt_if_no_config(&config, false).await?;
let context = WalletContext::new(&config, None, None)?;
if let Err(e) = context.get_client().await?.check_api_version() {
eprintln!("{}", format!("[warning] {e}").yellow().bold());
if build.ignore_chain {
build.chain_id = None;
} else {
// `sui move build` does not ordinarily require a network connection.
// The exception is when --dump-bytecode-as-base64 is specified: In this
// case, we should resolve the correct addresses for the respective chain
// (e.g., testnet, mainnet) from the Move.lock under automated address management.
let config =
client_config.unwrap_or(sui_config_dir()?.join(SUI_CLIENT_CONFIG));
prompt_if_no_config(&config, false).await?;
let context = WalletContext::new(&config, None, None)?;
if let Err(e) = context.get_client().await?.check_api_version() {
eprintln!("{}", format!("[warning] {e}").yellow().bold());
}
let client = context.get_client().await?;
let chain_id = client.read_api().get_chain_identifier().await.ok();
build.chain_id = chain_id.clone();
}
let client = context.get_client().await?;
let chain_id = client.read_api().get_chain_identifier().await.ok();
build.chain_id = chain_id.clone();
}
_ => (),
};
Expand Down

0 comments on commit bb714c5

Please sign in to comment.