Skip to content

Commit

Permalink
feat(CLI): add Deploy subcommand that allows calling custom init func…
Browse files Browse the repository at this point in the history
…tion (#28)

* feat: add deploy subcommand with custom init call

* fix: fee issue and update CLI
  • Loading branch information
willemneal authored Nov 8, 2023
1 parent 4cc668b commit 63bc7f1
Show file tree
Hide file tree
Showing 20 changed files with 576 additions and 58 deletions.
2 changes: 1 addition & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[alias] # command aliases
bwl = "build --profile release-with-logs"
install_soroban = "binstall -y --install-path ./target/bin soroban-cli --version 20.0.0-rc.4.1"
install_soroban_dev = "install --git https://github.com/stellar/soroban-tools --tag v20.0.0-rc.4.1 --debug --root ./target soroban-cli"
install_soroban_dev = "install --git https://github.com/stellar/soroban-tools --rev d3f0dc53aee5b5f2791ad9a9d615312f6560aad4 --debug --root ./target soroban-cli"
install_loam = "install --version 0.6.5 --debug --root ./target loam-cli"
# c = "check"
# t = "test"
Expand Down
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SOROBAN_NETWORK=standalone
SOROBAN_NETWORK=testnet
SOROBAN_ACCOUNT=default
CONFIG_DIR=.
SOROBAN_FEE=1000000
SOROBAN_FEE=10000000
37 changes: 31 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ members = [
"examples/increment",
"examples/errors",
"examples/cross_contract/*",
"examples/increment-init"
]

exclude = [
Expand Down
2 changes: 1 addition & 1 deletion contract_id.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CDNOMEB3ZQHS5WPCUPQ7IS4OKGTOTBRDCZUITBRNSQAB63JJ52JFO4KX
CABJP36BKN2MOLGD7UCVZPJN42XTWEV7SKXCRXACHQOTAMYO26LQET5O
1 change: 1 addition & 0 deletions contracts/smartdeploy/src/registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub trait IsDeployable {
deployed_name: soroban_sdk::String,
owner: soroban_sdk::Address,
salt: Option<soroban_sdk::BytesN<32>>,
init: Option<(soroban_sdk::Symbol, soroban_sdk::Vec<soroban_sdk::Val>)>,
) -> Result<soroban_sdk::Address, Error>;

/// Fetch contract id
Expand Down
23 changes: 16 additions & 7 deletions contracts/smartdeploy/src/registry/contract.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
#![allow(non_upper_case_globals)]
use loam_sdk::soroban_sdk::{self, contracttype, env, vec, Address, BytesN, Map, String, Lazy, Symbol, symbol_short};

use crate::{error::Error, registry::Publishable, util::{hash_string, MAX_BUMP}, version::Version, Contract};
use loam_sdk::soroban_sdk::{
self, contracttype, env, symbol_short, vec, Address, BytesN, Lazy, Map, String, Symbol, Val,
};

use crate::{
error::Error,
registry::Publishable,
util::{hash_string, MAX_BUMP},
version::Version,
Contract,
};

use super::{IsDeployable, IsDevDeployable};


loam_sdk::import_contract!(core_riff);

// Is the same as
// Is the same as

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


#[contracttype(export = false)]
pub struct ContractRegistry(pub Map<String, Address>);

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


impl Lazy for ContractRegistry {
fn get_lazy() -> Option<Self> {
env().storage().persistent().get(&key())
Expand Down Expand Up @@ -57,6 +62,7 @@ impl IsDeployable for ContractRegistry {
deployed_name: String,
owner: Address,
salt: Option<BytesN<32>>,
init: Option<(Symbol, soroban_sdk::Vec<soroban_sdk::Val>)>,
) -> Result<Address, Error> {
if self.0.contains_key(deployed_name.clone()) {
return Err(Error::NoSuchContractDeployed);
Expand All @@ -66,6 +72,9 @@ impl IsDeployable for ContractRegistry {
let hash = Contract::fetch_hash(contract_name, version)?;
let salt = salt.unwrap_or_else(|| hash_string(&deployed_name));
let address = deploy_and_init(&owner, salt, hash)?;
if let Some((init_fn, args)) = init {
let _ = env().invoke_contract::<Val>(&address, &init_fn, args);
}
self.0.set(deployed_name, address.clone());
Ok(address)
}
Expand Down
6 changes: 6 additions & 0 deletions crates/smartdeploy-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ thiserror = "1.0.31"
tokio = { version = "1", features = ["full"] }
shlex = "1.1.0"
smartdeploy-build = { path = "../smartdeploy-build", version = "0.2.1" }
loam-sdk = { workspace = true }
soroban-spec = "20.0.0-rc2"
soroban-spec-tools = "20.0.0-rc3"
heck = "0.4.1"
ed25519-dalek = "2.0.0"
stellar-strkey = "0.0.8"

[dev-dependencies]
assert_cmd = "2.0.4"
Expand Down
3 changes: 1 addition & 2 deletions crates/smartdeploy-cli/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use clap::{CommandFactory, Parser};

use smartdeploy_cli::{Root, testnet};

use smartdeploy_cli::{testnet, Root};

#[tokio::main]
async fn main() {
Expand Down
Loading

0 comments on commit 63bc7f1

Please sign in to comment.