diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 740eb49f2..e6525e8a3 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -18,6 +18,7 @@ clockwork-cron = { path = "../cron", version = "1.2.12" } clockwork-utils = { path = "../utils", version = "1.3.11" } chrono = { version = "0.4.19", default-features = false, features = ["alloc"] } dirs-next = "2.0.0" +regex = "1.6.0" serde = { version = "1.0.136", features = ["derive"] } serde_json = "1.0.79" serde_yaml = "0.9.4" diff --git a/cli/build.rs b/cli/build.rs index 90b06fa9f..7324ffae3 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -1,33 +1,14 @@ use cargo_toml::{Dependency, Manifest}; use regex::Regex; -use std::process::Command; fn main() { - let validator_version = get_validator_version(); let geyser_interface_version = get_geyser_interface_version(); - - println!("cargo:rustc-env=VALIDATOR_VERSION={}", validator_version); println!( "cargo:rustc-env=GEYSER_INTERFACE_VERSION={}", geyser_interface_version ); } -fn get_validator_version() -> String { - let output = Command::new("solana-test-validator") - .arg("--version") - .output() - .unwrap(); - let version = String::from_utf8_lossy(&output.stdout); - let re = Regex::new(r"(\d{1}\.\d{2}\.\d{1})").unwrap(); - let caps = re.captures(&version).unwrap(); - caps.get(1) - .map_or("unknown (error parsing solana-validator version)", |m| { - m.as_str() - }) - .into() -} - fn get_geyser_interface_version() -> String { let plugin_manifest = Manifest::from_path("../plugin/Cargo.toml").unwrap(); let plugin_interface = plugin_manifest @@ -35,9 +16,18 @@ fn get_geyser_interface_version() -> String { .get("solana-geyser-plugin-interface") .unwrap(); - match plugin_interface { + let semver = match plugin_interface { Dependency::Simple(version) => version.into(), Dependency::Detailed(detail) => detail.version.as_ref().unwrap().into(), - _ => "unknown (error parsing Cargo.toml)".to_string(), - } + _ => "unknown (error parsing Plugin's Cargo.toml)".to_string(), + }; + + let re = Regex::new(r"(\d\.\d{2}\.\d)").unwrap(); + re.captures(&semver) + .unwrap() + .get(1) + .map_or("unknown (error parsing solana-geyser-plugin-interface version)", |m| { + m.as_str() + }) + .into() } diff --git a/cli/src/processor/localnet.rs b/cli/src/processor/localnet.rs index 8bd2b45a9..15a37bca4 100644 --- a/cli/src/processor/localnet.rs +++ b/cli/src/processor/localnet.rs @@ -10,6 +10,7 @@ use { thread::state::{Thread, Trigger}, Client, }, + regex::Regex, solana_sdk::{ native_token::LAMPORTS_PER_SOL, program_pack::Pack, @@ -46,8 +47,7 @@ pub fn start(client: &Client, program_infos: Vec) -> Result<(), Cli } fn check_test_validator_version() { - // add link to the FAQ about solana version instead - let validator_version = env!("VALIDATOR_VERSION"); + let validator_version = get_validator_version(); let clockwork_version = env!("GEYSER_INTERFACE_VERSION"); if validator_version != clockwork_version { @@ -56,8 +56,9 @@ fn check_test_validator_version() { let err = format!( "Your Solana version and the Clockwork Engine's Solana version differs. \ This behavior is undefined. \ - You have {} installed, but the Clockwork Engine requires {} \ - We recommend you to run `solana-install init {}`\nDo you want to continue anyway?", + You have '{}' installed, but the Clockwork Engine requires {} \ + We recommend you to run `solana-install init {}`\nDo you want to continue anyway? \ + More info: https://github.com/clockwork-xyz/docs/blob/main/FAQ.md#clockwork-engine", validator_version, clockwork_version, clockwork_version ); println!("⚠️ \x1b[93m{}️\x1b[0m", err); @@ -67,6 +68,23 @@ fn check_test_validator_version() { } } +fn get_validator_version() -> String { + Command::new("solana-test-validator") + .arg("--version") + .output() + .map_or("unknown".into(), |output| { + let version = String::from_utf8_lossy(&output.stdout); + let re = Regex::new(r"(\d\.\d{2}\.\d)").unwrap(); + let caps = re.captures(&version).unwrap(); + caps + .get(1) + .map_or("unknown (error parsing solana-validator version)", |m| { + m.as_str() + }) + .into() + }) +} + fn mint_clockwork_token(client: &Client) -> Result { // Calculate rent and pubkeys let mint_keypair = Keypair::new();