Skip to content

Commit 63bc7f1

Browse files
authored
feat(CLI): add Deploy subcommand that allows calling custom init function (#28)
* feat: add deploy subcommand with custom init call * fix: fee issue and update CLI
1 parent 4cc668b commit 63bc7f1

File tree

20 files changed

+576
-58
lines changed

20 files changed

+576
-58
lines changed

.cargo/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[alias] # command aliases
44
bwl = "build --profile release-with-logs"
55
install_soroban = "binstall -y --install-path ./target/bin soroban-cli --version 20.0.0-rc.4.1"
6-
install_soroban_dev = "install --git https://github.com/stellar/soroban-tools --tag v20.0.0-rc.4.1 --debug --root ./target soroban-cli"
6+
install_soroban_dev = "install --git https://github.com/stellar/soroban-tools --rev d3f0dc53aee5b5f2791ad9a9d615312f6560aad4 --debug --root ./target soroban-cli"
77
install_loam = "install --version 0.6.5 --debug --root ./target loam-cli"
88
# c = "check"
99
# t = "test"

.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
SOROBAN_NETWORK=standalone
1+
SOROBAN_NETWORK=testnet
22
SOROBAN_ACCOUNT=default
33
CONFIG_DIR=.
4-
SOROBAN_FEE=1000000
4+
SOROBAN_FEE=10000000

Cargo.lock

Lines changed: 31 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ members = [
77
"examples/increment",
88
"examples/errors",
99
"examples/cross_contract/*",
10+
"examples/increment-init"
1011
]
1112

1213
exclude = [

contract_id.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
CDNOMEB3ZQHS5WPCUPQ7IS4OKGTOTBRDCZUITBRNSQAB63JJ52JFO4KX
1+
CABJP36BKN2MOLGD7UCVZPJN42XTWEV7SKXCRXACHQOTAMYO26LQET5O

contracts/smartdeploy/src/registry.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ pub trait IsDeployable {
6464
deployed_name: soroban_sdk::String,
6565
owner: soroban_sdk::Address,
6666
salt: Option<soroban_sdk::BytesN<32>>,
67+
init: Option<(soroban_sdk::Symbol, soroban_sdk::Vec<soroban_sdk::Val>)>,
6768
) -> Result<soroban_sdk::Address, Error>;
6869

6970
/// Fetch contract id

contracts/smartdeploy/src/registry/contract.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
#![allow(non_upper_case_globals)]
2-
use loam_sdk::soroban_sdk::{self, contracttype, env, vec, Address, BytesN, Map, String, Lazy, Symbol, symbol_short};
3-
4-
use crate::{error::Error, registry::Publishable, util::{hash_string, MAX_BUMP}, version::Version, Contract};
2+
use loam_sdk::soroban_sdk::{
3+
self, contracttype, env, symbol_short, vec, Address, BytesN, Lazy, Map, String, Symbol, Val,
4+
};
5+
6+
use crate::{
7+
error::Error,
8+
registry::Publishable,
9+
util::{hash_string, MAX_BUMP},
10+
version::Version,
11+
Contract,
12+
};
513

614
use super::{IsDeployable, IsDevDeployable};
715

8-
916
loam_sdk::import_contract!(core_riff);
1017

11-
// Is the same as
18+
// Is the same as
1219

1320
// mod core_riff {
1421
// use loam_sdk::soroban_sdk;
1522
// loam_sdk::soroban_sdk::contractimport!(file = "../../target/loam/core_riff.wasm",);
1623
// }
1724

18-
1925
#[contracttype(export = false)]
2026
pub struct ContractRegistry(pub Map<String, Address>);
2127

@@ -29,7 +35,6 @@ fn key() -> Symbol {
2935
symbol_short!("contractR")
3036
}
3137

32-
3338
impl Lazy for ContractRegistry {
3439
fn get_lazy() -> Option<Self> {
3540
env().storage().persistent().get(&key())
@@ -57,6 +62,7 @@ impl IsDeployable for ContractRegistry {
5762
deployed_name: String,
5863
owner: Address,
5964
salt: Option<BytesN<32>>,
65+
init: Option<(Symbol, soroban_sdk::Vec<soroban_sdk::Val>)>,
6066
) -> Result<Address, Error> {
6167
if self.0.contains_key(deployed_name.clone()) {
6268
return Err(Error::NoSuchContractDeployed);
@@ -66,6 +72,9 @@ impl IsDeployable for ContractRegistry {
6672
let hash = Contract::fetch_hash(contract_name, version)?;
6773
let salt = salt.unwrap_or_else(|| hash_string(&deployed_name));
6874
let address = deploy_and_init(&owner, salt, hash)?;
75+
if let Some((init_fn, args)) = init {
76+
let _ = env().invoke_contract::<Val>(&address, &init_fn, args);
77+
}
6978
self.0.set(deployed_name, address.clone());
7079
Ok(address)
7180
}

crates/smartdeploy-cli/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ thiserror = "1.0.31"
3939
tokio = { version = "1", features = ["full"] }
4040
shlex = "1.1.0"
4141
smartdeploy-build = { path = "../smartdeploy-build", version = "0.2.1" }
42+
loam-sdk = { workspace = true }
43+
soroban-spec = "20.0.0-rc2"
44+
soroban-spec-tools = "20.0.0-rc3"
45+
heck = "0.4.1"
46+
ed25519-dalek = "2.0.0"
47+
stellar-strkey = "0.0.8"
4248

4349
[dev-dependencies]
4450
assert_cmd = "2.0.4"

crates/smartdeploy-cli/src/bin/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use clap::{CommandFactory, Parser};
22

3-
use smartdeploy_cli::{Root, testnet};
4-
3+
use smartdeploy_cli::{testnet, Root};
54

65
#[tokio::main]
76
async fn main() {

0 commit comments

Comments
 (0)