feat: cli init (#141)

This commit is contained in:
Daniel Gushchyan 2024-08-08 16:47:02 -07:00 committed by GitHub
parent a18ae28c48
commit 84ccbb201d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 1188 additions and 94 deletions

1200
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -26,6 +26,7 @@ authors = ["Informal Systems <hello@informal.systems>"]
anyhow = { version = "1.0.86", default-features = false }
async-trait = { version = "0.1.79", default-features = false }
bip32 = { version = "0.5.1", default-features = false, features = ["alloc", "secp256k1", "bip39"] }
cargo-generate = "0.21.3"
clap = { version = "4.1.8", default-features = false, features = ["derive", "std"] }
color-eyre = { version = "0.6.2", default-features = false }
der = { version = "0.7.9", default-features = false }
@ -53,10 +54,10 @@ tonic-build = { version = "=0.12.1", default-features = false, features = ["pros
tracing = { version = "0.1.39", default-features = false }
tracing-subscriber = { version = "0.3.17", default-features = false, features = ["fmt"] }
uuid = { version = "1.4.1", default-features = false, features = ["serde"] }
walkdir = { version = "2.5.0", default-features = false }
x509-cert = { version = "0.2.5", default-features = false }
x509-parser = { version = "0.16.0", features = ["default", "verify"] }
zeroize = { version = "1.7.0", default-features = false }
# cosmos
cosmos-sdk-proto = { version = "0.22.0" }
cosmrs = { version = "=0.17.0", default-features = false }

View file

@ -0,0 +1,13 @@
[template]
name = "quartz-app-template"
description = "An functioning example of a quartz app"
ignore = [
"contracts/Cargo.lock",
"contracts/target",
"contracts/target/*",
"enclave/target",
"enclave/target/*",
"frontend/package-lock.json",
"frontend/public/images"
]

View file

@ -11,6 +11,7 @@ readme = "README.md"
[dependencies]
async-trait.workspace = true
cargo-generate.workspace = true
clap = { workspace = true, features=["env"] }
color-eyre.workspace = true
displaydoc.workspace = true

View file

@ -44,12 +44,12 @@ pub struct Cli {
pub enum Command {
/// Create an empty Quartz app from a template
Init {
/// path to create & init a Quartz app, defaults to current path if unspecified
#[clap(long)]
path: Option<PathBuf>,
/// the name of your Quartz app directory, defaults to quartz_app
#[clap(long, default_value = "quartz_app")]
name: String,
},
Handshake {
/// path to create & init a quartz app, defaults to current path if unspecified
/// path to create & init a Quartz app, defaults to current path if unspecified
#[arg(short, long, value_parser = wasmaddr_to_id)]
contract: AccountId,
/// Port enclave is listening on
@ -64,10 +64,10 @@ pub enum Command {
/// <host>:<port> to tendermint rpc interface for this chain
#[clap(long, default_value_t = default_node_url())]
node_url: String,
/// RPC interface for the quartz enclave
/// RPC interface for the Quartz enclave
#[clap(long, default_value_t = default_rpc_addr())]
enclave_rpc_addr: String,
/// Path to quartz app directory
/// Path to Quartz app directory
/// Defaults to current working dir
#[clap(long)]
app_dir: Option<PathBuf>,

View file

@ -1,4 +1,7 @@
use std::path::PathBuf;
use async_trait::async_trait;
use cargo_generate::{generate, GenerateArgs, TemplatePath, Vcs};
use tracing::trace;
use crate::{
@ -17,6 +20,24 @@ impl Handler for InitRequest {
async fn handle(self, _config: Config) -> Result<Self::Response, Self::Error> {
trace!("initializing directory structure...");
Ok(InitResponse.into())
let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("..");
let wasm_pack_args = GenerateArgs {
name: Some(self.name),
vcs: Some(Vcs::Git),
template_path: TemplatePath {
// git: Some("git@github.com:informalsystems/cycles-quartz.git".to_string()), // TODO: replace with public http address when open-sourced
path: Some(root_dir.join("apps/transfers").display().to_string()),
..TemplatePath::default()
},
..GenerateArgs::default()
};
let result_dir = generate(wasm_pack_args)
.expect("something went wrong!")
.display()
.to_string();
Ok(InitResponse { result_dir }.into())
}
}

View file

@ -27,7 +27,7 @@ impl TryFrom<Command> for Request {
fn try_from(cmd: Command) -> Result<Self, Self::Error> {
match cmd {
Command::Init { path } => InitRequest::try_from(path).map(Into::into),
Command::Init { name } => Ok(InitRequest { name }.try_into()?),
Command::Handshake {
contract,
port,

View file

@ -1,30 +1,20 @@
use std::path::PathBuf;
use std::path::Path;
use crate::{error::Error, request::Request};
#[derive(Clone, Debug)]
pub struct InitRequest {
// TODO(hu55a1n1): remove `allow(unused)` here once init handler is implemented
#[allow(unused)]
directory: PathBuf,
pub name: String,
}
impl TryFrom<Option<PathBuf>> for InitRequest {
impl TryFrom<InitRequest> for Request {
type Error = Error;
fn try_from(path: Option<PathBuf>) -> Result<Self, Self::Error> {
if let Some(path) = path {
if !path.is_dir() {
return Err(Error::PathNotDir(format!("{}", path.display())));
}
fn try_from(request: InitRequest) -> Result<Request, Error> {
if Path::new(&request.name).iter().count() != 1 {
return Err(Error::GenericErr("App name contains path".to_string()));
}
todo!()
}
}
impl From<InitRequest> for Request {
fn from(request: InitRequest) -> Self {
Self::Init(request)
Ok(Request::Init(request))
}
}

View file

@ -3,7 +3,9 @@ use serde::Serialize;
use crate::response::Response;
#[derive(Clone, Debug, Serialize)]
pub struct InitResponse;
pub struct InitResponse {
pub result_dir: String,
}
impl From<InitResponse> for Response {
fn from(response: InitResponse) -> Self {