diff --git a/crates/iota-move/src/build.rs b/crates/iota-move/src/build.rs index 0eb2829a2ef..06d3c910b25 100644 --- a/crates/iota-move/src/build.rs +++ b/crates/iota-move/src/build.rs @@ -26,11 +26,16 @@ pub struct Build { /// Whether we are printing in base64. #[clap(long, global = true)] pub dump_bytecode_as_base64: 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., - /// the TypeScript SDK) to enable serialization/deserialization of - /// transaction arguments and events. + /// 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. + #[arg(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., the TypeScript SDK) to enable + /// serialization/deserialization of transaction arguments and events. #[clap(long, global = true)] pub generate_struct_layouts: bool, /// The chain ID, if resolved. Required when the dump_bytecode_as_base64 is diff --git a/crates/iota/src/iota_commands.rs b/crates/iota/src/iota_commands.rs index 9f34f7f0755..ab0c9387a74 100644 --- a/crates/iota/src/iota_commands.rs +++ b/crates/iota/src/iota_commands.rs @@ -505,18 +505,21 @@ impl IotaCommand { } => { match &mut cmd { iota_move::Command::Build(build) if build.dump_bytecode_as_base64 => { - // `iota 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(iota_config_dir()?.join(IOTA_CLIENT_CONFIG)); - prompt_if_no_config(&config, false, true).await?; - let context = WalletContext::new(&config, None, None)?; - let client = context.get_client().await?; - let chain_id = client.read_api().get_chain_identifier().await.ok(); - build.chain_id = chain_id.clone(); + if build.ignore_chain { + build.chain_id = None; + } else { + // `iota 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(iota_config_dir()?.join(IOTA_CLIENT_CONFIG)); + prompt_if_no_config(&config, false, true).await?; + let context = WalletContext::new(&config, None, None)?; + let client = context.get_client().await?; + build.chain_id = client.read_api().get_chain_identifier().await.ok(); + } } _ => (), }; diff --git a/crates/iota/src/keytool.rs b/crates/iota/src/keytool.rs index 73dda76e6bd..716548db44d 100644 --- a/crates/iota/src/keytool.rs +++ b/crates/iota/src/keytool.rs @@ -589,8 +589,11 @@ impl KeyToolCommand { } => match IotaKeyPair::decode(&input_string) { Ok(ikp) => { info!("Importing Bech32 encoded private key to keystore"); - let key = Key::from(&ikp); + let mut key = Key::from(&ikp); + keystore.add_key(alias, ikp)?; + key.alias = Some(keystore.get_alias_by_address(&key.iota_address)?); + CommandOutput::Import(key) } Err(_) => { @@ -617,7 +620,10 @@ impl KeyToolCommand { }; let ikp = keystore.get_key(&iota_address)?; - let key = Key::from(ikp); + let mut key = Key::from(ikp); + + key.alias = Some(keystore.get_alias_by_address(&key.iota_address)?); + CommandOutput::Import(key) } }, diff --git a/crates/iota/tests/cli_tests.rs b/crates/iota/tests/cli_tests.rs index 6a4ac04eeec..12523268fad 100644 --- a/crates/iota/tests/cli_tests.rs +++ b/crates/iota/tests/cli_tests.rs @@ -4383,6 +4383,7 @@ async fn test_move_new() -> Result<(), anyhow::Error> { build_config: move_package::BuildConfig::default(), cmd: iota_move::Command::Build(iota_move::build::Build { chain_id: None, + ignore_chain: false, dump_bytecode_as_base64: false, generate_struct_layouts: false, with_unpublished_dependencies: false,