From 312f95f78d457df2ee943400fd784c79ccaa7c56 Mon Sep 17 00:00:00 2001 From: Amit Dave Date: Wed, 1 May 2024 19:30:14 -0700 Subject: [PATCH 1/4] Added --bech-32 flag to forc contract-id command --- forc/Cargo.toml | 1 + forc/src/cli/commands/contract_id.rs | 2 ++ forc/src/ops/forc_contract_id.rs | 10 +++++++++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/forc/Cargo.toml b/forc/Cargo.toml index 2e526f3afa2..1029678623c 100644 --- a/forc/Cargo.toml +++ b/forc/Cargo.toml @@ -29,6 +29,7 @@ forc-tracing = { version = "0.56.0", path = "../forc-tracing" } forc-util = { version = "0.56.0", path = "../forc-util" } fs_extra = "1.2" fuel-asm = { workspace = true } +fuels-core = { workspace = true } hex = "0.4.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.73" diff --git a/forc/src/cli/commands/contract_id.rs b/forc/src/cli/commands/contract_id.rs index 55848428aa8..fc697455c0d 100644 --- a/forc/src/cli/commands/contract_id.rs +++ b/forc/src/cli/commands/contract_id.rs @@ -32,6 +32,8 @@ pub struct Command { /// Disable the "new encoding" feature #[clap(long)] pub no_encoding_v1: bool, + #[clap(long)] + pub bech32: bool, } pub(crate) fn exec(cmd: Command) -> ForcResult<()> { diff --git a/forc/src/ops/forc_contract_id.rs b/forc/src/ops/forc_contract_id.rs index c6a3a966505..3ed736587d0 100644 --- a/forc/src/ops/forc_contract_id.rs +++ b/forc/src/ops/forc_contract_id.rs @@ -5,6 +5,7 @@ use forc_tracing::println_green; use pkg::manifest::build_profile::ExperimentalFlags; use sway_core::{fuel_prelude::fuel_tx, BuildTarget}; use tracing::info; +use fuels_core::types::bech32::Bech32ContractId; pub fn contract_id(command: ContractIdCommand) -> Result<()> { let build_options = build_opts_from_cmd(&command); @@ -40,7 +41,14 @@ pub fn contract_id(command: ContractIdCommand) -> Result<()> { let contract_id = pkg::contract_id(built_contract.bytecode.bytes.clone(), storage_slots, &salt); println_green(&format!(" {name}")); - info!(" Contract id: 0x{contract_id}"); + if command.bech32 + { + let contract_id_bech32 = Bech32ContractId::from(contract_id); + info!(" Contract id: {contract_id_bech32}"); + } + else { + info!(" Contract id: 0x{contract_id}"); + } } Ok(()) } From ab6c531fb40b1022a92774515faf81e9d8839b1d Mon Sep 17 00:00:00 2001 From: Amit Dave Date: Wed, 1 May 2024 19:37:39 -0700 Subject: [PATCH 2/4] Added comments --- forc/src/cli/commands/contract_id.rs | 1 + forc/src/ops/forc_contract_id.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/forc/src/cli/commands/contract_id.rs b/forc/src/cli/commands/contract_id.rs index fc697455c0d..99b5cdfb43b 100644 --- a/forc/src/cli/commands/contract_id.rs +++ b/forc/src/cli/commands/contract_id.rs @@ -32,6 +32,7 @@ pub struct Command { /// Disable the "new encoding" feature #[clap(long)] pub no_encoding_v1: bool, + // flag to display contract-id in bech32 format #[clap(long)] pub bech32: bool, } diff --git a/forc/src/ops/forc_contract_id.rs b/forc/src/ops/forc_contract_id.rs index 3ed736587d0..c09f5be7428 100644 --- a/forc/src/ops/forc_contract_id.rs +++ b/forc/src/ops/forc_contract_id.rs @@ -41,6 +41,7 @@ pub fn contract_id(command: ContractIdCommand) -> Result<()> { let contract_id = pkg::contract_id(built_contract.bytecode.bytes.clone(), storage_slots, &salt); println_green(&format!(" {name}")); + //check if --bech32 flag is present in command if command.bech32 { let contract_id_bech32 = Bech32ContractId::from(contract_id); From e7ac66a96716a767c7c18e88bb0ae7959b95aae8 Mon Sep 17 00:00:00 2001 From: Amit Dave Date: Thu, 2 May 2024 13:19:51 -0700 Subject: [PATCH 3/4] Added requested changes --- Cargo.lock | 1 + forc/src/cli/commands/contract_id.rs | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 3c26d7307a5..73fbaa4472d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2044,6 +2044,7 @@ dependencies = [ "forc-util", "fs_extra", "fuel-asm", + "fuels-core", "hex", "serde", "serde_json", diff --git a/forc/src/cli/commands/contract_id.rs b/forc/src/cli/commands/contract_id.rs index 99b5cdfb43b..127789edc7b 100644 --- a/forc/src/cli/commands/contract_id.rs +++ b/forc/src/cli/commands/contract_id.rs @@ -32,7 +32,7 @@ pub struct Command { /// Disable the "new encoding" feature #[clap(long)] pub no_encoding_v1: bool, - // flag to display contract-id in bech32 format + // Flag to display contract-id in bech32 format #[clap(long)] pub bech32: bool, } From 24d503f4b969657c4acfac1b9b92b644fcc4a9ee Mon Sep 17 00:00:00 2001 From: Amit Dave Date: Fri, 3 May 2024 19:24:36 -0700 Subject: [PATCH 4/4] Run cargo fmt --- forc/src/ops/forc_contract_id.rs | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/forc/src/ops/forc_contract_id.rs b/forc/src/ops/forc_contract_id.rs index c09f5be7428..1ab8219c239 100644 --- a/forc/src/ops/forc_contract_id.rs +++ b/forc/src/ops/forc_contract_id.rs @@ -2,10 +2,10 @@ use crate::cli::ContractIdCommand; use anyhow::{bail, Result}; use forc_pkg::{self as pkg, build_with_options}; use forc_tracing::println_green; +use fuels_core::types::bech32::Bech32ContractId; use pkg::manifest::build_profile::ExperimentalFlags; use sway_core::{fuel_prelude::fuel_tx, BuildTarget}; use tracing::info; -use fuels_core::types::bech32::Bech32ContractId; pub fn contract_id(command: ContractIdCommand) -> Result<()> { let build_options = build_opts_from_cmd(&command); @@ -42,12 +42,10 @@ pub fn contract_id(command: ContractIdCommand) -> Result<()> { pkg::contract_id(built_contract.bytecode.bytes.clone(), storage_slots, &salt); println_green(&format!(" {name}")); //check if --bech32 flag is present in command - if command.bech32 - { + if command.bech32 { let contract_id_bech32 = Bech32ContractId::from(contract_id); info!(" Contract id: {contract_id_bech32}"); - } - else { + } else { info!(" Contract id: 0x{contract_id}"); } }