feat: cli init (#141)
This commit is contained in:
parent
a18ae28c48
commit
84ccbb201d
9 changed files with 1188 additions and 94 deletions
1200
Cargo.lock
generated
1200
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
|
@ -26,6 +26,7 @@ authors = ["Informal Systems <hello@informal.systems>"]
|
||||||
anyhow = { version = "1.0.86", default-features = false }
|
anyhow = { version = "1.0.86", default-features = false }
|
||||||
async-trait = { version = "0.1.79", default-features = false }
|
async-trait = { version = "0.1.79", default-features = false }
|
||||||
bip32 = { version = "0.5.1", default-features = false, features = ["alloc", "secp256k1", "bip39"] }
|
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"] }
|
clap = { version = "4.1.8", default-features = false, features = ["derive", "std"] }
|
||||||
color-eyre = { version = "0.6.2", default-features = false }
|
color-eyre = { version = "0.6.2", default-features = false }
|
||||||
der = { version = "0.7.9", 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 = { version = "0.1.39", default-features = false }
|
||||||
tracing-subscriber = { version = "0.3.17", default-features = false, features = ["fmt"] }
|
tracing-subscriber = { version = "0.3.17", default-features = false, features = ["fmt"] }
|
||||||
uuid = { version = "1.4.1", default-features = false, features = ["serde"] }
|
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-cert = { version = "0.2.5", default-features = false }
|
||||||
x509-parser = { version = "0.16.0", features = ["default", "verify"] }
|
x509-parser = { version = "0.16.0", features = ["default", "verify"] }
|
||||||
zeroize = { version = "1.7.0", default-features = false }
|
zeroize = { version = "1.7.0", default-features = false }
|
||||||
|
|
||||||
# cosmos
|
# cosmos
|
||||||
cosmos-sdk-proto = { version = "0.22.0" }
|
cosmos-sdk-proto = { version = "0.22.0" }
|
||||||
cosmrs = { version = "=0.17.0", default-features = false }
|
cosmrs = { version = "=0.17.0", default-features = false }
|
||||||
|
|
13
apps/transfers/cargo-generate.toml
Normal file
13
apps/transfers/cargo-generate.toml
Normal 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"
|
||||||
|
]
|
|
@ -11,6 +11,7 @@ readme = "README.md"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
async-trait.workspace = true
|
async-trait.workspace = true
|
||||||
|
cargo-generate.workspace = true
|
||||||
clap = { workspace = true, features=["env"] }
|
clap = { workspace = true, features=["env"] }
|
||||||
color-eyre.workspace = true
|
color-eyre.workspace = true
|
||||||
displaydoc.workspace = true
|
displaydoc.workspace = true
|
||||||
|
|
|
@ -44,12 +44,12 @@ pub struct Cli {
|
||||||
pub enum Command {
|
pub enum Command {
|
||||||
/// Create an empty Quartz app from a template
|
/// Create an empty Quartz app from a template
|
||||||
Init {
|
Init {
|
||||||
/// path to create & init a Quartz app, defaults to current path if unspecified
|
/// the name of your Quartz app directory, defaults to quartz_app
|
||||||
#[clap(long)]
|
#[clap(long, default_value = "quartz_app")]
|
||||||
path: Option<PathBuf>,
|
name: String,
|
||||||
},
|
},
|
||||||
Handshake {
|
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)]
|
#[arg(short, long, value_parser = wasmaddr_to_id)]
|
||||||
contract: AccountId,
|
contract: AccountId,
|
||||||
/// Port enclave is listening on
|
/// Port enclave is listening on
|
||||||
|
@ -64,10 +64,10 @@ pub enum Command {
|
||||||
/// <host>:<port> to tendermint rpc interface for this chain
|
/// <host>:<port> to tendermint rpc interface for this chain
|
||||||
#[clap(long, default_value_t = default_node_url())]
|
#[clap(long, default_value_t = default_node_url())]
|
||||||
node_url: String,
|
node_url: String,
|
||||||
/// RPC interface for the quartz enclave
|
/// RPC interface for the Quartz enclave
|
||||||
#[clap(long, default_value_t = default_rpc_addr())]
|
#[clap(long, default_value_t = default_rpc_addr())]
|
||||||
enclave_rpc_addr: String,
|
enclave_rpc_addr: String,
|
||||||
/// Path to quartz app directory
|
/// Path to Quartz app directory
|
||||||
/// Defaults to current working dir
|
/// Defaults to current working dir
|
||||||
#[clap(long)]
|
#[clap(long)]
|
||||||
app_dir: Option<PathBuf>,
|
app_dir: Option<PathBuf>,
|
||||||
|
|
|
@ -1,4 +1,7 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
|
use cargo_generate::{generate, GenerateArgs, TemplatePath, Vcs};
|
||||||
use tracing::trace;
|
use tracing::trace;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -17,6 +20,24 @@ impl Handler for InitRequest {
|
||||||
async fn handle(self, _config: Config) -> Result<Self::Response, Self::Error> {
|
async fn handle(self, _config: Config) -> Result<Self::Response, Self::Error> {
|
||||||
trace!("initializing directory structure...");
|
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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ impl TryFrom<Command> for Request {
|
||||||
|
|
||||||
fn try_from(cmd: Command) -> Result<Self, Self::Error> {
|
fn try_from(cmd: Command) -> Result<Self, Self::Error> {
|
||||||
match cmd {
|
match cmd {
|
||||||
Command::Init { path } => InitRequest::try_from(path).map(Into::into),
|
Command::Init { name } => Ok(InitRequest { name }.try_into()?),
|
||||||
Command::Handshake {
|
Command::Handshake {
|
||||||
contract,
|
contract,
|
||||||
port,
|
port,
|
||||||
|
|
|
@ -1,30 +1,20 @@
|
||||||
use std::path::PathBuf;
|
use std::path::Path;
|
||||||
|
|
||||||
use crate::{error::Error, request::Request};
|
use crate::{error::Error, request::Request};
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct InitRequest {
|
pub struct InitRequest {
|
||||||
// TODO(hu55a1n1): remove `allow(unused)` here once init handler is implemented
|
pub name: String,
|
||||||
#[allow(unused)]
|
|
||||||
directory: PathBuf,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TryFrom<Option<PathBuf>> for InitRequest {
|
impl TryFrom<InitRequest> for Request {
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
fn try_from(path: Option<PathBuf>) -> Result<Self, Self::Error> {
|
fn try_from(request: InitRequest) -> Result<Request, Error> {
|
||||||
if let Some(path) = path {
|
if Path::new(&request.name).iter().count() != 1 {
|
||||||
if !path.is_dir() {
|
return Err(Error::GenericErr("App name contains path".to_string()));
|
||||||
return Err(Error::PathNotDir(format!("{}", path.display())));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
todo!()
|
Ok(Request::Init(request))
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<InitRequest> for Request {
|
|
||||||
fn from(request: InitRequest) -> Self {
|
|
||||||
Self::Init(request)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,9 @@ use serde::Serialize;
|
||||||
use crate::response::Response;
|
use crate::response::Response;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Serialize)]
|
#[derive(Clone, Debug, Serialize)]
|
||||||
pub struct InitResponse;
|
pub struct InitResponse {
|
||||||
|
pub result_dir: String,
|
||||||
|
}
|
||||||
|
|
||||||
impl From<InitResponse> for Response {
|
impl From<InitResponse> for Response {
|
||||||
fn from(response: InitResponse) -> Self {
|
fn from(response: InitResponse) -> Self {
|
||||||
|
|
Loading…
Reference in a new issue