Skip to content

Commit

Permalink
charms server
Browse files Browse the repository at this point in the history
  • Loading branch information
imikushin committed Dec 23, 2024
1 parent 8c20ae8 commit 7f4da5b
Show file tree
Hide file tree
Showing 10 changed files with 284 additions and 62 deletions.
117 changes: 114 additions & 3 deletions Cargo.lock

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

7 changes: 6 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ license = "MIT"

[dependencies]
anyhow = { workspace = true }
axum = { version = "0.8.0-rc.1" }
bitcoin = { workspace = true, features = ["rand", "rand-std"] }
bitcoincore-rpc = { version = "0.19.0" }
charms-data = { path = "./charms-data", version = "0.1.2" }
charms-spell-checker = { path = "charms-spell-checker", version = "0.1.2" }
ciborium = { workspace = true }
clap = { version = "4.5.0", features = ["derive"] }
hex = { workspace = true }
Expand All @@ -27,7 +30,9 @@ serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
serde_yaml = { workspace = true }
sp1-sdk = { workspace = true, features = ["native-gnark"] }
charms-spell-checker = { path = "charms-spell-checker", version = "0.1.2" }
tokio = { version = "1.0", features = ["full"] }
tracing = { version = "0.1" }
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

[dev-dependencies]
proptest = { workspace = true }
Expand Down
29 changes: 18 additions & 11 deletions src/commands/app.rs → src/cli/app.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1,49 @@
use crate::app;
use anyhow::{ensure, Result};
use charms::app;
use std::fs;
use std::{
env, fs, io,
process::{Command, Stdio},
};

pub fn new(name: &str) -> Result<()> {
if !std::process::Command::new("which")
if !Command::new("which")
.args(&["cargo-generate"])
.stdout(Stdio::null())
.status()?
.success()
{
std::process::Command::new("cargo")
Command::new("cargo")
.args(&["install", "cargo-generate"])
.status()?;
}
let status = std::process::Command::new("cargo")
let status = Command::new("cargo")
.args(&["generate", "sigma0-dev/charms-app", "--name", name])
.status()?;
ensure!(status.success());
Ok(())
}

pub fn build() -> Result<()> {
if !std::process::Command::new("which")
if !Command::new("which")
.args(&["cargo-prove"])
.stdout(Stdio::null())
.status()?
.success()
{
std::process::Command::new("bash")
Command::new("bash")
.args(&["-c", "curl -L https://sp1.succinct.xyz | bash"])
.stdout(Stdio::null())
.status()?;
std::process::Command::new(format!("{}/.sp1/bin/sp1up", std::env::var("HOME")?))
Command::new(format!("{}/.sp1/bin/sp1up", env::var("HOME")?))
.stdout(Stdio::null())
.status()?;
}
let mut child = std::process::Command::new("cargo")
let mut child = Command::new("cargo")
.args(&["prove", "build"])
.stdout(std::process::Stdio::piped())
.stdout(Stdio::piped())
.spawn()?;
let stdout = child.stdout.take().expect("Failed to open stdout");
std::io::copy(&mut std::io::BufReader::new(stdout), &mut std::io::stderr())?;
io::copy(&mut io::BufReader::new(stdout), &mut io::stderr())?;
let status = child.wait()?;
ensure!(status.success());
Ok(())
Expand Down
49 changes: 46 additions & 3 deletions src/commands/mod.rs → src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
pub mod app;
pub mod server;
pub mod spell;
pub mod tx;

use clap::{Parser, Subcommand};
use std::path::PathBuf;
use std::{net::IpAddr, path::PathBuf};

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
Expand All @@ -14,18 +15,28 @@ pub struct Cli {

#[derive(Subcommand)]
pub enum Commands {
/// Charms API Server
Server {
#[arg(long, default_value = "127.0.0.1")]
ip_addr: IpAddr,

#[arg(long, default_value = "3000")]
port: u16,
},

/// Work with spells
Spell {
#[command(subcommand)]
command: SpellCommands,
},

/// Low level transaction-related commands
/// Low level transaction-related cli
Tx {
#[command(subcommand)]
command: TxCommands,
},

/// App contract commands
/// Manage apps
App {
#[command(subcommand)]
command: AppCommands,
Expand Down Expand Up @@ -100,3 +111,35 @@ pub enum AppCommands {
/// Generate the app proof for a spell.
Prove,
}

pub async fn run() {
let cli = Cli::parse();

match cli.command {
Commands::Server { ip_addr, port } => server::server(ip_addr, port).await,
Commands::Spell { command } => match command {
SpellCommands::Parse => spell::spell_parse(),
SpellCommands::Print => spell::spell_print(),
SpellCommands::Prove { .. } => spell::spell_prove(command),
},
Commands::Tx { command } => match command {
TxCommands::AddSpell { .. } => tx::tx_add_spell(command),
TxCommands::ShowSpell { tx } => tx::tx_show_spell(tx),
},
Commands::App { command } => match command {
AppCommands::New { name } => app::new(&name),
AppCommands::Vk { path } => app::vk(path),
AppCommands::Build => app::build(),
AppCommands::Prove => {
todo!()
}
},
}
.expect("Error");
}

#[cfg(test)]
mod test {
#[test]
fn dummy() {}
}
Loading

0 comments on commit 7f4da5b

Please sign in to comment.