Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion cmd/soroban-cli/src/commands/contract/deploy/asset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ use std::{array::TryFromSliceError, fmt::Debug, num::ParseIntError};
use crate::commands::tx::fetch;
use crate::{
commands::{
contract::{self, extend},
global,
txn_result::{TxnEnvelopeResult, TxnResult},
HEADING_TRANSACTION,
},
config::{self, data, network, token::UnresolvedToken},
config::{self, alias, data, network, token::UnresolvedToken},
key,
rpc::Error as SorobanRpcError,
tx::builder,
};
Expand Down Expand Up @@ -64,6 +66,9 @@ pub enum Error {

#[error(transparent)]
Fetch(#[from] fetch::Error),

#[error(transparent)]
Extend(#[from] extend::Error),
}

impl From<Infallible> for Error {
Expand Down Expand Up @@ -94,6 +99,10 @@ pub struct Cmd {
/// Build the transaction and only write the base64 xdr to stdout
#[arg(long, help_heading = HEADING_TRANSACTION)]
pub build_only: bool,

/// Number of ledgers to extend the contract instance TTL after deploying
#[arg(long, visible_alias = "ledgers-to-expire")]
pub ledgers_to_extend: Option<u32>,
}

impl Cmd {
Expand Down Expand Up @@ -199,6 +208,26 @@ impl Cmd {
)
.await?;

if let Some(ledgers_to_extend) = self.ledgers_to_extend {
extend::Cmd {
ledgers_to_extend,
ttl_ledger_only: false,
key: key::Args {
contract_id: Some(alias::UnresolvedContract::Resolved(contract_id)),
key: None,
key_xdr: None,
wasm: None,
wasm_hash: None,
durability: contract::Durability::Persistent,
},
config: config.clone(),
resources: self.resources.clone(),
build_only: self.build_only,
}
.execute(config, quiet, no_cache)
.await?;
}

if let Some(url) = utils::lab_url_for_contract(&network, &contract_id) {
print.linkln(url);
}
Expand Down
55 changes: 53 additions & 2 deletions cmd/soroban-cli/src/commands/contract/deploy/wasm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ use crate::commands::tx::fetch;
use crate::utils::XDR_DEPTH_LIMIT;
use crate::{
commands::{
contract::{self, arg_parsing, build, id::wasm::get_contract_id, upload},
contract::{self, arg_parsing, build, extend, id::wasm::get_contract_id, upload},
global,
txn_result::{TxnEnvelopeResult, TxnResult},
HEADING_TRANSACTION,
},
config::{self, data, locator, network},
config::{self, alias, data, locator, network},
key,
print::Print,
rpc,
utils::{self, rpc::get_remote_wasm_from_hash},
Expand Down Expand Up @@ -72,6 +73,9 @@ pub struct Cmd {
/// Build the transaction and only write the base64 xdr to stdout
#[arg(long, help_heading = HEADING_TRANSACTION)]
pub build_only: bool,
/// Number of ledgers to extend the contract instance TTL after deploying
#[arg(long, visible_alias = "ledgers-to-expire")]
pub ledgers_to_extend: Option<u32>,
/// If provided, will be passed to the contract's `__constructor` function with provided arguments for that function as `--arg-name value`
#[arg(last = true, id = "CONTRACT_CONSTRUCTOR_ARGS")]
pub slop: Vec<OsString>,
Expand All @@ -87,6 +91,9 @@ pub enum Error {
#[error(transparent)]
Install(#[from] upload::Error),

#[error(transparent)]
Extend(#[from] extend::Error),

#[error("error parsing int: {0}")]
ParseIntError(#[from] ParseIntError),

Expand Down Expand Up @@ -346,6 +353,7 @@ impl Cmd {
auth_mode: self.auth_mode.clone(),
ignore_checks: self.ignore_checks,
build_only: is_build,
ledgers_to_extend: self.ledgers_to_extend,
package: None,
build_args: build::BuildArgs::default(),
}
Expand Down Expand Up @@ -457,6 +465,26 @@ impl Cmd {
)
.await?;

if let Some(ledgers_to_extend) = self.ledgers_to_extend {
extend::Cmd {
ledgers_to_extend,
ttl_ledger_only: false,
key: key::Args {
contract_id: Some(alias::UnresolvedContract::Resolved(contract_id)),
key: None,
key_xdr: None,
wasm: None,
wasm_hash: None,
durability: contract::Durability::Persistent,
},
config: config.clone(),
resources: self.resources.clone(),
build_only: self.build_only,
}
.execute(config, quiet, no_cache)
.await?;
}

if let Some(url) = utils::lab_url_for_contract(&network, &contract_id) {
print.linkln(url);
}
Expand Down Expand Up @@ -597,4 +625,27 @@ mod tests {

assert_eq!(reserved_package_alias(Some(&alias), &contracts), None);
}

#[test]
fn parse_ledgers_to_extend_and_expire_alias() {
let cmd = Cmd::try_parse_from([
"deploy",
"--wasm",
"test.wasm",
"--ledgers-to-extend",
"5000",
])
.unwrap();
assert_eq!(cmd.ledgers_to_extend, Some(5000));

let cmd_alias = Cmd::try_parse_from([
"deploy",
"--wasm",
"test.wasm",
"--ledgers-to-expire",
"6000",
])
.unwrap();
assert_eq!(cmd_alias.ledgers_to_extend, Some(6000));
}
}
2 changes: 1 addition & 1 deletion cmd/soroban-cli/src/commands/contract/extend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use crate::{
#[group(skip)]
pub struct Cmd {
/// Number of ledgers to extend the entries
#[arg(long, required = true)]
#[arg(long, visible_alias = "ledgers-to-expire", required = true)]
pub ledgers_to_extend: u32,

/// Only print the new Time To Live ledger
Expand Down
15 changes: 14 additions & 1 deletion cmd/soroban-cli/src/commands/contract/restore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub struct Cmd {
pub key: key::Args,

/// Number of ledgers to extend the entry
#[arg(long)]
#[arg(long, visible_alias = "ledgers-to-expire")]
pub ledgers_to_extend: Option<u32>,

/// Only print the new Time To Live ledger
Expand Down Expand Up @@ -547,4 +547,17 @@ mod tests {
let result = parse_changes(&changes);
assert_eq!(result, None);
}

#[test]
fn test_parse_ledgers_to_expire_alias() {
let cmd = Cmd::try_parse_from([
"restore",
"--id",
"CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM",
"--ledgers-to-expire",
"4000",
])
.unwrap();
assert_eq!(cmd.ledgers_to_extend, Some(4000));
}
}
71 changes: 70 additions & 1 deletion cmd/soroban-cli/src/commands/contract/upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::xdr::{
};
use clap::Parser;

use super::{build, restore};
use super::{build, extend, restore};
use crate::commands::tx::fetch;
use crate::{
commands::{
Expand Down Expand Up @@ -58,6 +58,10 @@ pub struct Cmd {
#[arg(long, help_heading = HEADING_TRANSACTION)]
pub build_only: bool,

/// Number of ledgers to extend the contract code TTL after uploading
#[arg(long, visible_alias = "ledgers-to-expire")]
pub ledgers_to_extend: Option<u32>,

/// Package to build when --wasm is not provided
#[arg(long, help_heading = "Build Options", conflicts_with = "wasm")]
pub package: Option<String>,
Expand Down Expand Up @@ -91,6 +95,9 @@ pub enum Error {
#[error(transparent)]
Restore(#[from] restore::Error),

#[error(transparent)]
Extend(#[from] extend::Error),

#[error("cannot parse WASM file {wasm}: {error}")]
CannotParseWasm {
wasm: std::path::PathBuf,
Expand Down Expand Up @@ -291,6 +298,25 @@ impl Cmd {
// exists.
if code.ext.ne(&ContractCodeEntryExt::V0) {
print.infoln("Skipping install because wasm already installed");
if let Some(ledgers_to_extend) = self.ledgers_to_extend {
extend::Cmd {
ledgers_to_extend,
ttl_ledger_only: false,
key: key::Args {
contract_id: None,
key: None,
key_xdr: None,
wasm: Some(wasm_path.clone()),
wasm_hash: None,
durability: super::Durability::Persistent,
},
config: config.clone(),
resources: self.resources.clone(),
build_only: self.build_only,
}
.execute(config, quiet, no_cache)
.await?;
}
return Ok(TxnResult::Res(hash));
}
}
Expand Down Expand Up @@ -344,6 +370,26 @@ impl Cmd {
data::write_spec(&hash.to_string(), &wasm_spec.spec)?;
}

if let Some(ledgers_to_extend) = self.ledgers_to_extend {
extend::Cmd {
ledgers_to_extend,
ttl_ledger_only: false,
key: key::Args {
contract_id: None,
key: None,
key_xdr: None,
wasm: Some(wasm_path.clone()),
wasm_hash: None,
durability: super::Durability::Persistent,
},
config: config.clone(),
resources: self.resources.clone(),
build_only: self.build_only,
}
.execute(config, quiet, no_cache)
.await?;
}

Ok(TxnResult::Res(hash))
}
}
Expand Down Expand Up @@ -441,4 +487,27 @@ mod tests {
// "rc" detection (used to gate the release-candidate check) still works.
assert!(version.contains("rc"));
}

#[test]
fn parse_ledgers_to_extend_and_expire_alias() {
let cmd = Cmd::try_parse_from([
"upload",
"--wasm",
"test.wasm",
"--ledgers-to-extend",
"1000",
])
.unwrap();
assert_eq!(cmd.ledgers_to_extend, Some(1000));

let cmd_alias = Cmd::try_parse_from([
"upload",
"--wasm",
"test.wasm",
"--ledgers-to-expire",
"2000",
])
.unwrap();
assert_eq!(cmd_alias.ledgers_to_extend, Some(2000));
}
}