Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove chainhook subcommands #1328

Merged
103 changes: 9 additions & 94 deletions components/clarinet-cli/src/frontend/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use clarinet_deployments::types::{DeploymentGenerationArtifacts, DeploymentSpeci
use clarinet_deployments::{
get_default_deployment_path, load_deployment, setup_session_with_deployment,
};
use clarinet_files::chainhook_types::Chain;
use clarinet_files::chainhook_types::StacksNetwork;
use clarinet_files::{
get_manifest_location, FileLocation, NetworkManifest, ProjectManifest, ProjectManifestFile,
Expand All @@ -37,7 +36,7 @@ use clarity_repl::frontend::terminal::print_clarity_wasm_warning;
use clarity_repl::repl::diagnostic::output_diagnostic;
use clarity_repl::repl::{ClarityCodeSource, ClarityContract, ContractDeployer, DEFAULT_EPOCH};
use clarity_repl::{analysis, repl, Terminal};
use stacks_network::{self, check_chainhooks, DevnetOrchestrator};
use stacks_network::{self, DevnetOrchestrator};
use std::collections::HashMap;
use std::fs::{self, File};
use std::io::prelude::*;
Expand Down Expand Up @@ -74,9 +73,9 @@ enum Command {
/// Interact with contracts deployed on Mainnet
#[clap(subcommand, name = "requirements", aliases = &["requirement"])]
Requirements(Requirements),
/// Subcommands for working with chainhooks
#[clap(subcommand, name = "chainhooks", aliases = &["chainhook"])]
Chainhooks(Chainhooks),
/// Subcommands for working with chainhooks (deprecated)
#[clap(name = "chainhooks", aliases = &["chainhook"])]
Chainhooks,
/// Manage contracts deployments on Simnet/Devnet/Testnet/Mainnet
#[clap(subcommand, name = "deployments", aliases = &["deployment"])]
Deployments(Deployments),
Expand Down Expand Up @@ -142,20 +141,6 @@ enum Deployments {
ApplyDeployment(ApplyDeployment),
}

#[allow(clippy::enum_variant_names)]
#[derive(Subcommand, PartialEq, Clone, Debug)]
enum Chainhooks {
/// Generate files and settings for a new hook
#[clap(name = "new", bin_name = "new")]
NewChainhook(NewChainhook),
/// Check hooks format
#[clap(name = "check", bin_name = "check")]
CheckChainhooks(CheckChainhooks),
/// Publish contracts on chain
#[clap(name = "deploy", bin_name = "deploy")]
DeployChainhook(DeployChainhook),
}

#[derive(Parser, PartialEq, Clone, Debug)]
struct DevnetPackage {
/// Output json file name
Expand Down Expand Up @@ -287,38 +272,6 @@ struct GenerateDeployment {
pub manual_cost: bool,
}

#[derive(Parser, PartialEq, Clone, Debug)]
struct NewChainhook {
/// Hook's name
pub name: String,
/// Path to Clarinet.toml
#[clap(long = "manifest-path")]
pub manifest_path: Option<String>,
/// Generate a Bitcoin chainhook
#[clap(long = "bitcoin", conflicts_with = "stacks")]
pub bitcoin: bool,
/// Generate a Stacks chainhook
#[clap(long = "stacks", conflicts_with = "bitcoin")]
pub stacks: bool,
}

#[derive(Parser, PartialEq, Clone, Debug)]
struct CheckChainhooks {
/// Path to Clarinet.toml
#[clap(long = "manifest-path")]
pub manifest_path: Option<String>,
/// Display chainhooks JSON representation
#[clap(long = "output-json")]
pub output_json: bool,
}

#[derive(Parser, PartialEq, Clone, Debug)]
struct DeployChainhook {
/// Path to Clarinet.toml
#[clap(long = "manifest-path")]
pub manifest_path: Option<String>,
}

#[derive(Parser, PartialEq, Clone, Debug)]
struct ApplyDeployment {
/// Apply default deployment settings/default.devnet-plan.toml
Expand Down Expand Up @@ -872,49 +825,11 @@ pub fn main() {
}
}
},
Command::Chainhooks(subcommand) => match subcommand {
Chainhooks::NewChainhook(cmd) => {
let manifest = load_manifest_or_exit(cmd.manifest_path);

let chain = match (cmd.bitcoin, cmd.stacks) {
(true, false) => Chain::Bitcoin,
(false, true) => Chain::Stacks,
(_, _) => {
println!(
"{}",
format_err!("either --bitcoin or --stacks must be passed")
);
process::exit(1);
}
};

let changes =
match generate::get_changes_for_new_chainhook(&manifest, cmd.name, chain) {
Ok(changes) => changes,
Err(message) => {
println!("{}", format_err!(message));
std::process::exit(1);
}
};

if !execute_changes(changes) {
std::process::exit(1);
}
if global_settings.enable_hints.unwrap_or(true) {
display_post_check_hint();
}
}
Chainhooks::CheckChainhooks(cmd) => {
let manifest_location = get_manifest_location_or_exit(cmd.manifest_path);
// Ensure that all the hooks can correctly be deserialized.
println!("Checking chainhooks");
let _ = check_chainhooks(&manifest_location, cmd.output_json);
}
Chainhooks::DeployChainhook(_cmd) => {
// TODO(lgalabru): follow-up on this implementation
unimplemented!()
}
},
Command::Chainhooks => {
let message = "This command is deprecated. Use the chainhooks library instead (https://github.com/hirosystems/chainhook)";
println!("{}", format_err!(message));
std::process::exit(1);
}
Command::Contracts(subcommand) => match subcommand {
Contracts::NewContract(cmd) => {
let manifest = load_manifest_or_exit(cmd.manifest_path);
Expand Down
154 changes: 0 additions & 154 deletions components/clarinet-cli/src/generate/chainhook.rs

This file was deleted.

14 changes: 0 additions & 14 deletions components/clarinet-cli/src/generate/mod.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
mod chainhook;
pub mod changes;
mod contract;
mod project;

use chainhook::GetChangesForNewChainhook;
pub use changes::Changes;
use clarinet_files::chainhook_types::Chain;
use clarinet_files::FileLocation;
use contract::GetChangesForNewContract;
use project::GetChangesForNewProject;

use clarinet_files::ProjectManifest;

use self::contract::GetChangesForRmContract;

pub fn get_changes_for_new_project(
Expand Down Expand Up @@ -41,12 +36,3 @@ pub fn get_changes_for_rm_contract(
let mut command = GetChangesForRmContract::new(manifest_location.clone(), contract_name);
command.run()
}

pub fn get_changes_for_new_chainhook(
manifest: &ProjectManifest,
chainhook_name: String,
chain: Chain,
) -> Result<Vec<Changes>, String> {
let mut command = GetChangesForNewChainhook::new(manifest, chainhook_name, chain);
command.run()
}
20 changes: 0 additions & 20 deletions components/stacks-network/src/chainhooks.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use chainhook_sdk::chainhooks::types::{ChainhookConfig, ChainhookFullSpecification};
use chainhook_sdk::types::{BitcoinNetwork, StacksNetwork};
use clarinet_files::FileLocation;
use hiro_system_kit::{green, red};
use std::fs::File;
use std::io::BufReader;
use std::path::PathBuf;
Expand Down Expand Up @@ -56,25 +55,6 @@ pub fn load_chainhooks(
})
}

pub fn check_chainhooks(manifest_location: &FileLocation, output_json: bool) -> Result<(), String> {
let hook_files = get_chainhooks_files(manifest_location)?;
for (path, relative_path) in hook_files.into_iter() {
let _hook = match parse_chainhook_full_specification(&path) {
Ok(hook) => hook,
Err(msg) => {
println!("{} {} syntax incorrect\n{}", red!("x"), relative_path, msg);
continue;
}
};
println!("{} {} succesfully checked", green!("✔"), relative_path);
if output_json {
let body = serde_json::to_string_pretty(&_hook).unwrap();
println!("{}", body);
}
}
Ok(())
}

fn get_chainhooks_files(
manifest_location: &FileLocation,
) -> Result<Vec<(PathBuf, String)>, String> {
Expand Down
2 changes: 1 addition & 1 deletion components/stacks-network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod ui;

pub use chainhook_sdk::observer::MempoolAdmissionData;
pub use chainhook_sdk::{self, utils::Context};
pub use chainhooks::{check_chainhooks, load_chainhooks, parse_chainhook_full_specification};
pub use chainhooks::{load_chainhooks, parse_chainhook_full_specification};
use chains_coordinator::BitcoinMiningCommand;
use clarinet_files::NetworkManifest;
pub use event::DevnetEvent;
Expand Down
Loading