Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fix call and install #21

Merged
merged 6 commits into from
Oct 27, 2023
Merged
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
6 changes: 3 additions & 3 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# paths = ["/path/to/override"] # path dependency overrides

[alias] # command aliases
xtask = "run --package xtask --"
bwl = "build --profile release-with-logs"
install_soroban_dev = "install --git https://github.com/stellar/soroban-tools --rev 7d3b4175b1970f76455b4789797c2edc5f79e432 --debug --root ./target soroban-cli"
install_soroban = "binstall -y --install-path ./target/bin soroban-cli --version 20.0.0-rc3"
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 = "binstall -y --install-path ./target/bin soroban-cli --version 20.0.0-rc.4.1"
install_loam = "install --version 0.6.5 --debug --root ./target loam-cli"
# c = "check"
# t = "test"
Expand All @@ -28,6 +27,7 @@ rustflags = [
"-Aclippy::missing_panics_doc",
"-Aclippy::missing_errors_doc",
"-Aclippy::module-name-repetitions",
"-Aclippy::ignored_unit_patterns"
# "-Aclippy::missing_safety_doc",
# "-Aclippy::inline_always",
# "-Aclippy::default_trait_access",
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/standalone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ jobs:
runs-on: ubuntu-20.04
services:
rpc:
image: stellar/quickstart:soroban-dev@sha256:2cd55fb75bb0777f0355b14a5426ffc870bb87ff1f9d1ea96d2bdcc58663c5f9
image: stellar/quickstart:soroban-dev@sha256:c1030a6ee75c31ba6807b8feddded2af23789b5f2c9be3ac55a550630a35ef42
ports:
- 8000:8000
env:
ENABLE_LOGS: true
NETWORK: standalone
NETWORK: local
ENABLE_SOROBAN_RPC: true
options: >-
--health-cmd "curl -X POST \"http://localhost:8000/soroban/rpc\""
Expand All @@ -32,6 +32,7 @@ jobs:
target/
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
- uses: taiki-e/install-action@just
- uses: taiki-e/install-action@cargo-binstall
- run: rustup update
- run: rustup target add wasm32-unknown-unknown
- run: just setup
Expand Down
87 changes: 87 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# Setup

First clone this repo:

```
git clone https://github.com/TENK-DAO/smartdeploy
cd smartdeploy
```

### install `just`

[just](https://github.com/casey/just) is a task running for helping executing graphs of dependent tasks.

```bash
cargo install just
```

though it's prefered to use

```bash
cargo binstall just
```

```bash
cargo install cargo-binstall
```

As this the relesaed binary, skipping having to build it.

At the moment only Unix OSes are supported (sorry!) in the follow steps.

### Setup local soroban binary

This will install the correct binaries to `./target/bin`.

```bash
just setup
```

### Setting up smartdeploy itself

Currently standalone is the default network. (see [.env](./.env))

You'll need docker installed. Then you can open a separate terminal and run:

```bash
just start_docker
```

To deploy your own Smartdeploy first run:

```bash
just clean
```

Then

```bash
just publish_all
```

This command creates a new smartdeploy contract and publishes all the examples to it. Then deploys a contract with the same name. Lastly a local script is created for each one and this path is visible to the just script.

```bash
just soroban --list
```

should print something like:

```
Installed Plugins:
smartdeploy
increment
errors
```

And now that soroban has a plugin system you can invoke it like

```
just soroban increment --help
```

or for short

```bash
just s increment --help
```
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,6 @@ serde-aux = "4.1.2"
hex = "0.4.3"
num-bigint = "0.4"
tokio = { version = "1", features = ["full"] }
soroban-cli = "0.9.4"
soroban-cli = "20.0.0-rc4.1"
tracing = "0.1.37"
tracing-subscriber = "0.3.17"
107 changes: 6 additions & 101 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ The key idea behind smartdeploy is that contract should be redeployable and main

First you need to add smartdeploy-sdk to your contract's `Cargo.toml`

```toml
smartdeploy-sdk = "0.1.0"
```bash
cargo add smartdeploy-sdk
```

### `soroban-cli`

Currently smartdeploy relies on yet unreleased features in `soroban-cli`, so you must install it with the following
Currently smartdeploy relies on yet unstable version of the CLI

```bash
cargo install --git https://github.com/ahalabs/soroban-tools --branch smartdeploy --debug --force soroban-cli
cargo install soroban-cli --version 20.0.0-rc4
```

Next you need to add the following line to your contract:
Expand Down Expand Up @@ -66,111 +66,16 @@ SOROBAN_FEE=1000000

Uses [Loam-SDK](https://github.com/loambuild/loam-sdk)

## Publishing

Currently smart contracts are `installed` to the network allowing them to be deployed using the hash of the installed contract. However, unless you are the author of the smart contract you won't know much about which hashes correspond to which contracts. Furthermore, there is no notion of a version of each hash so you would find many contracts with almost identical implementations.



## Trying it out

First clone this repo:

```
git clone https://github.com/TENK-DAO/smartdeploy
cd smartdeploy
```

## Setup

### install `just`

[just](https://github.com/casey/just) is a task running for helping executing graphs of dependent tasks.

```bash
cargo install just
```

though it's prefered to use

```bash
cargo binstall just
```

```bash
cargo install cargo-binstall
```

As this the relesaed binary, skipping having to build it.

At the moment only Unix OSes are supported (sorry!) in the follow steps.

### Setup local soroban binary

This will install the correct binaries to `./target/bin`.

```bash
just setup
```

### Setting up smartdeploy itself

Currently standalone is the default network. (see [.env](./.env))

You'll need docker installed. Then you can open a separate terminal and run:

```bash
just start_docker
```

To deploy your own Smartdeploy first run:

```bash
just clean
```

Then

```bash
just publish_all
```

This command creates a new smartdeploy contract and publishes all the examples to it. Then deploys a contract with the same name. Lastly a local script is created for each one and this path is visible to the just script.

```bash
just soroban --list
```

should print something like:

```
Installed Plugins:
smartdeploy
increment
errors
```

And now that soroban has a plugin system you can invoke it like

```
just soroban increment --help
```

or for short

```bash
just s increment --help
```


# Smartdeploy CLI

## Install
```
cargo install
cargo install smartdeploy-cli
```

Currently the smartdeploy CLI has a `call` subcommand which lets you use a deployed contract's name when invoking it.
Currently the smartdeploy CLI has a `install` and `call` subcommand which lets you use a deployed contract's name when invoking it.

```bash
cargo run -- call smartdeploy -- --help
Expand Down
2 changes: 1 addition & 1 deletion contract_id.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CBG572OEPI6LNOUHCOCEUOCDII72UNUWNHCCGB4CHCHB52VQ3RI6NEOW
CCZIZYOHMPFO4WR526WLT4VAFVLLKW3RABOJ6IB6JULTDQZMBXEBXYLJ
9 changes: 9 additions & 0 deletions crates/smartdeploy-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use loam_build::get_target_dir;
pub enum Error {
#[error(transparent)]
LoamBuild(#[from] loam_build::Error),
#[error("Missing contract_id for {0}")]
MissingContractId(String),
}


Expand All @@ -22,6 +24,13 @@ pub fn wasm_location(name: &str, out_dir: Option<&Path>) -> Result<PathBuf, Erro
Ok(out_file)
}

pub fn contract_id(name: &str, out_dir: Option<&Path>) -> Result<String, Error> {
let wasm = wasm_location(name, out_dir)?;
let parent = wasm.parent().ok_or_else(|| Error::MissingContractId(name.to_owned()))?;
let id_file = parent.join("contract_id.txt");
std::fs::read_to_string(id_file).map_err(|_| Error::MissingContractId(name.to_owned()))
}

fn manifest() -> PathBuf {
std::path::PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap()).join("Cargo.toml")
}
Expand Down
8 changes: 5 additions & 3 deletions crates/smartdeploy-cli/src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
use clap::{CommandFactory, Parser};

use smartdeploy_cli::{Root, futurenet};
use smartdeploy_cli::{Root, testnet};


#[tokio::main]
async fn main() {
std::env::set_var("SOROBAN_CONTRACT_ID", futurenet::contract_id());
std::env::set_var("SOROBAN_NETWORK", "futurenet");
std::env::set_var("SOROBAN_CONTRACT_ID", testnet::contract_id());
std::env::set_var("SOROBAN_RPC_URL", testnet::rpc_url());
std::env::set_var("SOROBAN_NETWORK_PASSPHRASE", testnet::network_passphrase());
std::env::remove_var("SOROBAN_NETWORK");
let mut root = Root::try_parse().unwrap_or_else(|e| {
let mut cmd = Root::command();
e.format(&mut cmd).exit();
Expand Down
32 changes: 24 additions & 8 deletions crates/smartdeploy-cli/src/commands/call.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clap::Parser;

use smartdeploy_build::contract_id;
use soroban_cli::commands::{contract::invoke, global};

#[derive(Parser, Debug, Clone)]
Expand All @@ -13,20 +14,35 @@ pub struct Cmd {
pub enum Error {
#[error(transparent)]
Invoke(#[from] invoke::Error),
#[error(transparent)]
SmartdeployBuild(#[from] smartdeploy_build::Error),
#[error(transparent)]
Install(#[from] super::install::Error),
}

impl Cmd {
pub async fn run(&self) -> Result<(), Error> {
let mut contract_invoke = self.call.clone();
contract_invoke.slop = vec!["fetch_contract_id", "--deployed_name", &self.deployed_name]
.into_iter()
.map(Into::into)
.collect::<Vec<_>>();
let global_args = &global::Args::default();
let id = contract_invoke.invoke(global_args).await?;
let id = self.contract_id().await?;
let mut contract = self.call.clone();
contract.contract_id = id.trim_matches('"').to_string();
contract.run(global_args).await?;
contract.run(&global::Args::default()).await?;
Ok(())
}

pub async fn contract_id(&self) -> Result<String, Error> {
let res = contract_id(&self.deployed_name, None);
Ok(
if let Err(smartdeploy_build::Error::MissingContractId(_)) = &res {
super::install::Cmd {
deployed_name: self.deployed_name.clone(),
out_dir: None,
}
.run()
.await?;
contract_id(&self.deployed_name, None)
} else {
res
}?,
)
}
}
Loading
Loading