From 6f13838c65e4604e26db9288e105b4d503daa629 Mon Sep 17 00:00:00 2001 From: Sagar Patil Date: Fri, 10 Jan 2025 10:47:11 -0800 Subject: [PATCH 1/2] update config so it stalebot wait 90 days before closing (#1823) --- .github/workflows/stale.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/stale.yml b/.github/workflows/stale.yml index 54c57da0e..582ca41ec 100644 --- a/.github/workflows/stale.yml +++ b/.github/workflows/stale.yml @@ -13,9 +13,9 @@ jobs: with: debug-only: false days-before-stale: 30 - days-before-close: 30 - stale-issue-message: 'This issue is stale because it has been assigned for 30 days with no activity. It will be closed in 30 days unless the stale label is removed, and the assignee is removed or updated.' - stale-pr-message: 'This pull request is stale because it has been open for 30 days with no activity. It will be closed in 30 days unless the stale label is removed.' + days-before-close: 90 + stale-issue-message: 'This issue is stale because it has been assigned for 30 days with no activity. It will be closed in 90 days unless the stale label is removed, and the assignee is removed or updated.' + stale-pr-message: 'This pull request is stale because it has been open for 30 days with no activity. It will be closed in 90 days unless the stale label is removed.' stale-issue-label: stale stale-pr-label: stale remove-stale-when-updated: true From 6425231a0356d7aac14e92f98e71e24289ed8cf4 Mon Sep 17 00:00:00 2001 From: Nando Vieira Date: Mon, 13 Jan 2025 12:30:08 -0800 Subject: [PATCH 2/2] Add alias support to `contract asset deploy` (#1829) --- FULL_HELP_DOCS.md | 1 + .../src/commands/contract/deploy.rs | 1 + .../src/commands/contract/deploy/asset.rs | 22 ++++++++ .../src/commands/contract/deploy/utils.rs | 56 +++++++++++++++++++ .../src/commands/contract/deploy/wasm.rs | 44 +-------------- 5 files changed, 81 insertions(+), 43 deletions(-) create mode 100644 cmd/soroban-cli/src/commands/contract/deploy/utils.rs diff --git a/FULL_HELP_DOCS.md b/FULL_HELP_DOCS.md index 9347f4a68..01edf1e15 100644 --- a/FULL_HELP_DOCS.md +++ b/FULL_HELP_DOCS.md @@ -151,6 +151,7 @@ Deploy builtin Soroban Asset Contract * `--instructions ` — Number of instructions to simulate * `--build-only` — Build the transaction and only write the base64 xdr to stdout * `--sim-only` — (Deprecated) simulate the transaction and only write the base64 xdr to stdout +* `--alias ` — The alias that will be used to save the assets's id. Whenever used, `--alias` will always overwrite the existing contract id configuration without asking for confirmation diff --git a/cmd/soroban-cli/src/commands/contract/deploy.rs b/cmd/soroban-cli/src/commands/contract/deploy.rs index 812fb4c77..3e6dcf3ea 100644 --- a/cmd/soroban-cli/src/commands/contract/deploy.rs +++ b/cmd/soroban-cli/src/commands/contract/deploy.rs @@ -1,6 +1,7 @@ use crate::commands::global; pub mod asset; +pub mod utils; pub mod wasm; #[derive(Debug, clap::Subcommand)] diff --git a/cmd/soroban-cli/src/commands/contract/deploy/asset.rs b/cmd/soroban-cli/src/commands/contract/deploy/asset.rs index 04a0380ed..8c4419277 100644 --- a/cmd/soroban-cli/src/commands/contract/deploy/asset.rs +++ b/cmd/soroban-cli/src/commands/contract/deploy/asset.rs @@ -1,3 +1,4 @@ +use crate::config::locator; use crate::xdr::{ Asset, ContractDataDurability, ContractExecutable, ContractIdPreimage, CreateContractArgs, Error as XdrError, Hash, HostFunction, InvokeHostFunctionOp, LedgerKey::ContractData, @@ -21,6 +22,8 @@ use crate::{ utils::contract_id_hash_from_asset, }; +use crate::commands::contract::deploy::utils::alias_validator; + #[derive(thiserror::Error, Debug)] pub enum Error { #[error("error parsing int: {0}")] @@ -39,6 +42,8 @@ pub enum Error { Network(#[from] network::Error), #[error(transparent)] Builder(#[from] builder::Error), + #[error(transparent)] + Locator(#[from] locator::Error), } impl From for Error { @@ -56,8 +61,15 @@ pub struct Cmd { #[command(flatten)] pub config: config::Args, + #[command(flatten)] pub fee: crate::fee::Args, + + /// The alias that will be used to save the assets's id. + /// Whenever used, `--alias` will always overwrite the existing contract id + /// configuration without asking for confirmation. + #[arg(long, value_parser = clap::builder::ValueParser::new(alias_validator))] + pub alias: Option, } impl Cmd { @@ -66,6 +78,16 @@ impl Cmd { match res { TxnEnvelopeResult::TxnEnvelope(tx) => println!("{}", tx.to_xdr_base64(Limits::none())?), TxnEnvelopeResult::Res(contract) => { + let network = self.config.get_network()?; + + if let Some(alias) = self.alias.clone() { + self.config.locator.save_contract_id( + &network.network_passphrase, + &contract, + &alias, + )?; + } + println!("{contract}"); } } diff --git a/cmd/soroban-cli/src/commands/contract/deploy/utils.rs b/cmd/soroban-cli/src/commands/contract/deploy/utils.rs new file mode 100644 index 000000000..2a698e2a8 --- /dev/null +++ b/cmd/soroban-cli/src/commands/contract/deploy/utils.rs @@ -0,0 +1,56 @@ +use regex::Regex; + +#[derive(thiserror::Error, Debug)] +pub enum Error { + #[error( + "alias must be 1-30 chars long, and have only letters, numbers, underscores and dashes" + )] + InvalidAliasFormat { alias: String }, +} + +pub fn alias_validator(alias: &str) -> Result { + let regex = Regex::new(r"^[a-zA-Z0-9_-]{1,30}$").unwrap(); + + if regex.is_match(alias) { + Ok(alias.into()) + } else { + Err(Error::InvalidAliasFormat { + alias: alias.into(), + }) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_alias_validator_with_valid_inputs() { + let valid_inputs = [ + "hello", + "123", + "hello123", + "hello_123", + "123_hello", + "123-hello", + "hello-123", + "HeLlo-123", + ]; + + for input in valid_inputs { + let result = alias_validator(input); + assert!(result.is_ok()); + assert!(result.unwrap() == input); + } + } + + #[test] + fn test_alias_validator_with_invalid_inputs() { + let invalid_inputs = ["", "invalid!", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]; + + for input in invalid_inputs { + let result = alias_validator(input); + assert!(result.is_err()); + } + } +} diff --git a/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs b/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs index 1d85832b0..9bd8fed68 100644 --- a/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs +++ b/cmd/soroban-cli/src/commands/contract/deploy/wasm.rs @@ -1,3 +1,4 @@ +use crate::commands::contract::deploy::utils::alias_validator; use std::array::TryFromSliceError; use std::ffi::OsString; use std::fmt::Debug; @@ -12,7 +13,6 @@ use crate::xdr::{ }; use clap::{arg, command, Parser}; use rand::Rng; -use regex::Regex; use soroban_spec_tools::contract as contract_spec; @@ -152,18 +152,6 @@ impl Cmd { } } -fn alias_validator(alias: &str) -> Result { - let regex = Regex::new(r"^[a-zA-Z0-9_-]{1,30}$").unwrap(); - - if regex.is_match(alias) { - Ok(alias.into()) - } else { - Err(Error::InvalidAliasFormat { - alias: alias.into(), - }) - } -} - #[async_trait::async_trait] impl NetworkRunnable for Cmd { type Error = Error; @@ -390,34 +378,4 @@ mod tests { assert!(result.is_ok()); } - - #[test] - fn test_alias_validator_with_valid_inputs() { - let valid_inputs = [ - "hello", - "123", - "hello123", - "hello_123", - "123_hello", - "123-hello", - "hello-123", - "HeLlo-123", - ]; - - for input in valid_inputs { - let result = alias_validator(input); - assert!(result.is_ok()); - assert!(result.unwrap() == input); - } - } - - #[test] - fn test_alias_validator_with_invalid_inputs() { - let invalid_inputs = ["", "invalid!", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"]; - - for input in invalid_inputs { - let result = alias_validator(input); - assert!(result.is_err()); - } - } }