feat: cli contract build (#138)
This commit is contained in:
parent
84ccbb201d
commit
048f8e7d0f
8 changed files with 92 additions and 8 deletions
|
@ -48,6 +48,7 @@ pub enum Command {
|
|||
#[clap(long, default_value = "quartz_app")]
|
||||
name: String,
|
||||
},
|
||||
/// Perform handshake
|
||||
Handshake {
|
||||
/// path to create & init a Quartz app, defaults to current path if unspecified
|
||||
#[arg(short, long, value_parser = wasmaddr_to_id)]
|
||||
|
@ -72,7 +73,7 @@ pub enum Command {
|
|||
#[clap(long)]
|
||||
app_dir: Option<PathBuf>,
|
||||
},
|
||||
/// Create an empty Quartz app from a template
|
||||
/// Subcommands for handling the Quartz app contract
|
||||
Contract {
|
||||
#[command(subcommand)]
|
||||
contract_command: ContractCommand,
|
||||
|
@ -88,7 +89,7 @@ pub enum Command {
|
|||
pub enum ContractCommand {
|
||||
Build {
|
||||
#[clap(long)]
|
||||
path: Option<PathBuf>,
|
||||
manifest_path: PathBuf,
|
||||
},
|
||||
Deploy {
|
||||
/// Json-formatted cosmwasm contract initialization message
|
||||
|
|
|
@ -7,6 +7,6 @@ pub enum Error {
|
|||
PathNotDir(String),
|
||||
/// Specified file `{0}` does not exist
|
||||
PathNotFile(String),
|
||||
/// {0}
|
||||
/// unspecified error: {0}
|
||||
GenericErr(String),
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ use crate::{error::Error, request::Request, response::Response, Config};
|
|||
|
||||
pub mod utils;
|
||||
// commands
|
||||
pub mod contract_build;
|
||||
pub mod contract_deploy;
|
||||
pub mod enclave_build;
|
||||
pub mod handshake;
|
||||
|
@ -26,6 +27,7 @@ impl Handler for Request {
|
|||
match self {
|
||||
Request::Init(request) => request.handle(config).await,
|
||||
Request::Handshake(request) => request.handle(config).await,
|
||||
Request::ContractBuild(request) => request.handle(config).await,
|
||||
Request::ContractDeploy(request) => request.handle(config).await,
|
||||
Request::EnclaveBuild(request) => request.handle(config).await,
|
||||
}
|
||||
|
|
45
cli/src/handler/contract_build.rs
Normal file
45
cli/src/handler/contract_build.rs
Normal file
|
@ -0,0 +1,45 @@
|
|||
use std::process::Command;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use tracing::{debug, trace};
|
||||
|
||||
use crate::{
|
||||
error::Error,
|
||||
handler::Handler,
|
||||
request::contract_build::ContractBuildRequest,
|
||||
response::{contract_build::ContractBuildResponse, Response},
|
||||
Config,
|
||||
};
|
||||
|
||||
#[async_trait]
|
||||
impl Handler for ContractBuildRequest {
|
||||
type Error = Error;
|
||||
type Response = Response;
|
||||
|
||||
async fn handle(self, config: Config) -> Result<Self::Response, Self::Error> {
|
||||
let mut cargo = Command::new("cargo");
|
||||
let command = cargo
|
||||
.arg("wasm")
|
||||
.args(["--manifest-path", &self.manifest_path.display().to_string()])
|
||||
.env("RUSTFLAGS", "-C link-arg=-s");
|
||||
|
||||
if config.mock_sgx {
|
||||
debug!("Building with mock-sgx enabled");
|
||||
command.arg("--features=mock-sgx");
|
||||
}
|
||||
|
||||
trace!("🚧 Building contract binary ...");
|
||||
let status = command
|
||||
.status()
|
||||
.map_err(|e| Error::GenericErr(e.to_string()))?;
|
||||
|
||||
if !status.success() {
|
||||
return Err(Error::GenericErr(format!(
|
||||
"Couldn't build contract. \n{:?}",
|
||||
status
|
||||
)));
|
||||
}
|
||||
|
||||
Ok(ContractBuildResponse.into())
|
||||
}
|
||||
}
|
|
@ -4,11 +4,12 @@ use crate::{
|
|||
cli::{Command, ContractCommand, EnclaveCommand},
|
||||
error::Error,
|
||||
request::{
|
||||
contract_deploy::ContractDeployRequest, enclave_build::EnclaveBuildRequest,
|
||||
handshake::HandshakeRequest, init::InitRequest,
|
||||
contract_build::ContractBuildRequest, contract_deploy::ContractDeployRequest,
|
||||
enclave_build::EnclaveBuildRequest, handshake::HandshakeRequest, init::InitRequest,
|
||||
},
|
||||
};
|
||||
|
||||
pub mod contract_build;
|
||||
pub mod contract_deploy;
|
||||
pub mod enclave_build;
|
||||
pub mod handshake;
|
||||
|
@ -18,6 +19,7 @@ pub mod init;
|
|||
pub enum Request {
|
||||
Init(InitRequest),
|
||||
Handshake(HandshakeRequest),
|
||||
ContractBuild(ContractBuildRequest),
|
||||
ContractDeploy(ContractDeployRequest),
|
||||
EnclaveBuild(EnclaveBuildRequest),
|
||||
}
|
||||
|
@ -94,7 +96,13 @@ impl TryFrom<ContractCommand> for Request {
|
|||
}
|
||||
.into())
|
||||
}
|
||||
ContractCommand::Build { path: _ } => todo!(),
|
||||
ContractCommand::Build { manifest_path } => {
|
||||
if !manifest_path.exists() {
|
||||
return Err(Error::PathNotFile(manifest_path.display().to_string()));
|
||||
}
|
||||
|
||||
Ok(ContractBuildRequest { manifest_path }.into())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
14
cli/src/request/contract_build.rs
Normal file
14
cli/src/request/contract_build.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
use std::path::PathBuf;
|
||||
|
||||
use crate::request::Request;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ContractBuildRequest {
|
||||
pub manifest_path: PathBuf,
|
||||
}
|
||||
|
||||
impl From<ContractBuildRequest> for Request {
|
||||
fn from(request: ContractBuildRequest) -> Self {
|
||||
Self::ContractBuild(request)
|
||||
}
|
||||
}
|
|
@ -1,10 +1,11 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::response::{
|
||||
contract_deploy::ContractDeployResponse, enclave_build::EnclaveBuildResponse,
|
||||
handshake::HandshakeResponse, init::InitResponse,
|
||||
contract_build::ContractBuildResponse, contract_deploy::ContractDeployResponse,
|
||||
enclave_build::EnclaveBuildResponse, handshake::HandshakeResponse, init::InitResponse,
|
||||
};
|
||||
|
||||
pub mod contract_build;
|
||||
pub mod contract_deploy;
|
||||
pub mod enclave_build;
|
||||
pub mod handshake;
|
||||
|
@ -14,6 +15,7 @@ pub mod init;
|
|||
pub enum Response {
|
||||
Init(InitResponse),
|
||||
Handshake(HandshakeResponse),
|
||||
ContractBuild(ContractBuildResponse),
|
||||
ContractDeploy(ContractDeployResponse),
|
||||
EnclaveBuild(EnclaveBuildResponse),
|
||||
}
|
||||
|
|
12
cli/src/response/contract_build.rs
Normal file
12
cli/src/response/contract_build.rs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use serde::Serialize;
|
||||
|
||||
use crate::response::Response;
|
||||
|
||||
#[derive(Clone, Debug, Serialize)]
|
||||
pub struct ContractBuildResponse;
|
||||
|
||||
impl From<ContractBuildResponse> for Response {
|
||||
fn from(response: ContractBuildResponse) -> Self {
|
||||
Self::ContractBuild(response)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue