Skip to content

Commit

Permalink
feat: update to loam
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Apr 28, 2023
1 parent 1cbb1a0 commit e864db0
Show file tree
Hide file tree
Showing 13 changed files with 280 additions and 322 deletions.
1 change: 1 addition & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ rustflags = [
"-Aclippy::must_use_candidate",
"-Aclippy::missing_panics_doc",
"-Aclippy::missing_errors_doc",
"-Aclippy::module-name-repetitions",
# "-Aclippy::missing_safety_doc",
# "-Aclippy::inline_always",
# "-Aclippy::default_trait_access",
Expand Down
16 changes: 4 additions & 12 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ lto = true
[workspace.dependencies]
# loam-sdk = { path = "../../loam/crates/loam" }
# loam-sdk-core-riffs = { path = "../../loam/crates/loam-core" }
loam-sdk = { git = "https://github.com/loambuild/loam-sdk", rev = "fb45acf5cb508f5ffc85c335221b56aa10842897" }
loam-sdk-core-riffs = { git = "https://github.com/loambuild/loam-sdk", rev = "fb45acf5cb508f5ffc85c335221b56aa10842897" }
loam-sdk = { git = "https://github.com/loambuild/loam-sdk", tag = "v0.1.0" }
loam-sdk-core-riffs = { git = "https://github.com/loambuild/loam-sdk", tag = "v0.1.0" }
2 changes: 1 addition & 1 deletion contract_id.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8f20288b65636659d758493805f798bb623d1a8fc83eb7dfcfefb3b39e3f0f7d
f0979039df1471f9f7ecc0b55bbc49f57f26e7035fd42fba97d23ad024df4df4
2 changes: 2 additions & 0 deletions crates/smartdeploy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[package]
name = "smartdeploy"
description = "A crate for managing and deploying smart contracts on the Soroban blockchain."
documentation = "https://docs.rs/smartdeploy"
version = "0.0.0"
authors = ["Stellar Development Foundation <[email protected]>"]
license = "Apache-2.0"
Expand Down
20 changes: 20 additions & 0 deletions crates/smartdeploy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# SmartDeploy

`smartdeploy` is a Rust crate for managing and deploying smart contracts on the Soroban blockchain. It provides an easy-to-use interface for developers to interact with the blockchain and deploy their smart contracts without dealing with low-level implementation details.

## Features

- Register contract names for publishing
- Publish contract binaries with version management
- Fetch contract binaries and metadata
- Deploy published contracts to the blockchain
- Retrieve deployment statistics for contracts
- Manage contract ownership and redeployment

## Usage

Add `smartdeploy` as a dependency in your project's `Cargo.toml` file:

```toml
[dependencies]
smartdeploy = "0.0.0"
66 changes: 21 additions & 45 deletions crates/smartdeploy/src/gen.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,34 @@
#![allow(clippy::let_unit_value)]
use loam_sdk::soroban_sdk::{self, contractimpl, set_env, Address, BytesN, Env, Lazy, String};
use loam_sdk::soroban_sdk::{self, contractimpl, set_env, Address, BytesN, Env, String};
use loam_sdk_core_riffs::{Ownable, Redeployable};

use crate::{error::Error, version::Version, ContractMetadata, SmartDeploy};
use crate::{
error::Error,
metadata::PublishedWasm,
registry::{Binary, Deployable},
version::Version,
Contract,
};

pub struct SorobanContract;

#[contractimpl]
impl SorobanContract {
/// Register a contract name to allow publishing.
pub fn register_name(env: Env, author: Address, contract_name: String) -> Result<(), Error> {
set_env(env);
let mut this = SmartDeploy::get_lazy().unwrap_or_default();
let res = this.register_name(author, contract_name)?;
SmartDeploy::set_lazy(this);
Ok(res)
}

/// Publish a contract.
/// Currently a contract's version is a `u32` and publishing will increment it.
/// If no repo is provided, then the previously published binary's repo will be used. If it's the first
/// time then it will be empty.
/// `kind` is Patch by default,
pub fn publish_binary(
pub fn publish(
env: Env,
contract_name: String,
author: Address,
hash: BytesN<32>,
repo: Option<String>,
kind: Option<crate::version::Kind>,
) -> Result<(), Error> {
set_env(env);
let mut this = SmartDeploy::get_lazy().unwrap_or_default();
let res = this.publish_binary(contract_name, hash, repo, kind)?;
SmartDeploy::set_lazy(this);
Ok(res)
Contract::publish(contract_name, author, hash, repo, kind)
}

/// Fetch the hash for a given `contract_name`.
Expand All @@ -43,26 +37,23 @@ impl SorobanContract {
env: Env,
contract_name: String,
version: Option<Version>,
) -> Result<BytesN<32>, Error> {
) -> Result<PublishedWasm, Error> {
set_env(env);
SmartDeploy::get_lazy()
.unwrap_or_default()
.fetch(contract_name, version)
Contract::fetch(contract_name, version)
}

/// Fetch metadata for a given `contract_name`.
/// If version is not provided, it is the most recent version.
pub fn fetch_metadata(
pub fn fetch_hash(
env: Env,
contract_name: String,
version: Option<Version>,
) -> Result<ContractMetadata, Error> {
) -> Result<BytesN<32>, Error> {
set_env(env);
SmartDeploy::get_lazy()
.unwrap_or_default()
.fetch_metadata(contract_name, version)
Contract::fetch_hash(contract_name, version)
}

/// Deploy a contract and register a deployed contract
pub fn deploy(
env: Env,
contract_name: String,
Expand All @@ -71,38 +62,23 @@ impl SorobanContract {
salt: Option<BytesN<32>>,
) -> Result<BytesN<32>, Error> {
set_env(env);
let mut this = SmartDeploy::get_lazy().unwrap_or_default();
let res = this.deploy(contract_name, version, deployed_name, salt)?;
SmartDeploy::set_lazy(this);
Ok(res)
}

/// How many deploys have been made for the given contract.
pub fn get_num_deploys(
env: Env,
contract_name: String,
version: Option<Version>,
) -> Result<u64, Error> {
set_env(env);
SmartDeploy::get_lazy()
.unwrap_or_default()
.get_num_deploys(contract_name, version)
Contract::deploy(contract_name, version, deployed_name, salt)
}

/// Initial method called when contract is deployed. After that only the owner can set the owner, e.i. transfer ownership
pub fn owner_set(env: Env, owner: Address) {
set_env(env);
SmartDeploy::owner_set(owner);
Contract::owner_set(owner);
}
/// Current owner of the contract
pub fn owner_get(env: Env) -> Option<Address> {
set_env(env);
SmartDeploy::owner_get()
Contract::owner_get()
}

/// Redeploy contract to given hash
pub fn redeploy(env: Env, hash: BytesN<32>) {
set_env(env);
SmartDeploy::redeploy(hash);
Contract::redeploy(hash);
}
}
Loading

0 comments on commit e864db0

Please sign in to comment.