diff --git a/Cargo.lock b/Cargo.lock index 6a52d14..eaf0fd2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1172,17 +1172,6 @@ dependencies = [ "url", ] -[[package]] -name = "atty" -version = "0.2.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" -dependencies = [ - "hermit-abi 0.1.19", - "libc", - "winapi", -] - [[package]] name = "auto_impl" version = "1.2.0" @@ -1546,16 +1535,6 @@ dependencies = [ "serde", ] -[[package]] -name = "bincode2" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f49f6183038e081170ebbbadee6678966c7d54728938a3e7de7f4e780770318f" -dependencies = [ - "byteorder", - "serde", -] - [[package]] name = "bindgen" version = "0.69.5" @@ -1729,7 +1708,7 @@ checksum = "4f8754ff7a709cf0643f82093fff582192a36afe3b075cde8e752ad9e39d35ed" dependencies = [ "cargo_metadata", "fs2", - "gadget-blueprint-proc-macro-core", + "gadget-blueprint-proc-macro-core 0.1.5", "rustdoc-types", "serde", "serde_json", @@ -2041,21 +2020,6 @@ dependencies = [ "libloading", ] -[[package]] -name = "clap" -version = "2.34.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" -dependencies = [ - "ansi_term", - "atty", - "bitflags 1.3.2", - "strsim 0.8.0", - "textwrap", - "unicode-width", - "vec_map", -] - [[package]] name = "clap" version = "4.5.20" @@ -4200,11 +4164,10 @@ dependencies = [ [[package]] name = "gadget-blueprint-proc-macro" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9279fa5ac3579da5e1c5467c395aae4c910cc63a702fcae097d529687398a4b7" +version = "0.4.0" +source = "git+https://github.com/tangle-network/gadget.git#6b0064168d12d0610bff7edb3198171f8884bd75" dependencies = [ - "gadget-blueprint-proc-macro-core", + "gadget-blueprint-proc-macro-core 0.2.0", "indexmap 2.6.0", "itertools 0.13.0", "proc-macro2", @@ -4225,10 +4188,30 @@ dependencies = [ ] [[package]] -name = "gadget-context-derive" +name = "gadget-blueprint-proc-macro-core" version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2f15fa82798ae66fec9bea17791a5f37f200ed9803158b08180fd6ba85737c1" +source = "git+https://github.com/tangle-network/gadget.git#6b0064168d12d0610bff7edb3198171f8884bd75" +dependencies = [ + "cid", + "ethereum-types", + "serde", +] + +[[package]] +name = "gadget-blueprint-serde" +version = "0.2.0" +source = "git+https://github.com/tangle-network/gadget.git#6b0064168d12d0610bff7edb3198171f8884bd75" +dependencies = [ + "paste", + "serde", + "serde_bytes", + "tangle-subxt", +] + +[[package]] +name = "gadget-context-derive" +version = "0.2.2" +source = "git+https://github.com/tangle-network/gadget.git#6b0064168d12d0610bff7edb3198171f8884bd75" dependencies = [ "proc-macro2", "quote", @@ -4238,11 +4221,10 @@ dependencies = [ [[package]] name = "gadget-io" version = "0.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ff8d951c0776ee79a2594634f49f9f6b6006eff55ed7c61b033c84b33f4f839" +source = "git+https://github.com/tangle-network/gadget.git#6b0064168d12d0610bff7edb3198171f8884bd75" dependencies = [ "cfg-if", - "clap 4.5.20", + "clap", "hex", "multiaddr", "parity-scale-codec", @@ -4260,11 +4242,11 @@ dependencies = [ [[package]] name = "gadget-sdk" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "155e6e50f8d4651766c2d597132b421cc19f23fddcde752f8014363b98140de0" +version = "0.5.1" +source = "git+https://github.com/tangle-network/gadget.git#6b0064168d12d0610bff7edb3198171f8884bd75" dependencies = [ "alloy-contract", + "alloy-json-abi", "alloy-network", "alloy-primitives 0.7.7", "alloy-provider", @@ -4282,9 +4264,9 @@ dependencies = [ "auto_impl", "backon", "bincode", - "bincode2", "bollard", - "clap 4.5.20", + "clap", + "color-eyre", "dashmap 6.1.0", "ed25519-zebra 4.0.3", "eigensdk", @@ -4292,7 +4274,8 @@ dependencies = [ "failure", "futures", "gadget-blueprint-proc-macro", - "gadget-blueprint-proc-macro-core", + "gadget-blueprint-proc-macro-core 0.2.0", + "gadget-blueprint-serde", "gadget-context-derive", "gadget-io", "getrandom", @@ -4536,15 +4519,6 @@ dependencies = [ "hashbrown 0.14.5", ] -[[package]] -name = "heck" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] - [[package]] name = "heck" version = "0.4.1" @@ -4560,15 +4534,6 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - [[package]] name = "hermit-abi" version = "0.3.9" @@ -4948,14 +4913,10 @@ dependencies = [ name = "hyperlane-relayer-blueprint" version = "0.1.0" dependencies = [ - "async-trait", "blueprint-metadata", "color-eyre", "gadget-sdk", - "structopt", - "tokio", "tracing", - "tracing-subscriber 0.3.18", ] [[package]] @@ -10138,12 +10099,6 @@ dependencies = [ "unicode-properties", ] -[[package]] -name = "strsim" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" - [[package]] name = "strsim" version = "0.10.0" @@ -10179,30 +10134,6 @@ dependencies = [ "syn 2.0.85", ] -[[package]] -name = "structopt" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" -dependencies = [ - "clap 2.34.0", - "lazy_static", - "structopt-derive", -] - -[[package]] -name = "structopt-derive" -version = "0.4.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" -dependencies = [ - "heck 0.3.3", - "proc-macro-error", - "proc-macro2", - "quote", - "syn 1.0.109", -] - [[package]] name = "strum" version = "0.26.3" @@ -10558,9 +10489,9 @@ dependencies = [ [[package]] name = "tangle-subxt" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fd92b3c29823ab4db09ed7030222dbcdf94d5edbb384b5fca4eb76f646ead9c" +checksum = "f66ffe3bf80b02cebae9b5d8b0932becf5638179e4cf7b9c12d0c753b51c5e64" dependencies = [ "parity-scale-codec", "scale-info", @@ -10654,15 +10585,6 @@ dependencies = [ "url", ] -[[package]] -name = "textwrap" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - [[package]] name = "thiserror" version = "1.0.65" @@ -11073,7 +10995,6 @@ dependencies = [ "matchers 0.1.0", "nu-ansi-term", "once_cell", - "parking_lot", "regex", "serde", "serde_json", @@ -11249,12 +11170,6 @@ version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6ccf251212114b54433ec949fd6a7841275f9ada20dddd2f29e9ceea4501493" -[[package]] -name = "unicode-width" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" - [[package]] name = "unicode-xid" version = "0.2.6" @@ -11362,12 +11277,6 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - [[package]] name = "version_check" version = "0.9.5" diff --git a/Cargo.toml b/Cargo.toml index d739604..4e82e43 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,14 +14,11 @@ rust-version = "1.81" [dependencies] tracing = "0.1" -async-trait = "0.1" color-eyre = "0.6" -structopt = "0.3.26" -tokio = { version = "^1", default-features = false, features = ["full"] } -tracing-subscriber = { version = "0.3", features = ["parking_lot", "env-filter"] } [dependencies.gadget-sdk] -version = "0.4.0" +#version = "0.5.1" +git = "https://github.com/tangle-network/gadget.git" default-features = false features = ["getrandom"] diff --git a/src/lib.rs b/src/lib.rs index d196788..add8cfc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,47 +1,55 @@ use api::services::events::JobCalled; +use color_eyre::Result; use gadget_sdk as sdk; +use sdk::config::StdGadgetConfiguration; +use sdk::contexts::{ServicesContext, TangleClientContext}; +use sdk::docker::bollard::Docker; +use sdk::docker::connect_to_docker; use sdk::event_listener::tangle::{ jobs::{services_post_processor, services_pre_processor}, TangleEventListener, }; use sdk::tangle_subxt::tangle_testnet_runtime::api; -use std::convert::Infallible; +use std::path::PathBuf; +use std::sync::{Arc, Mutex}; -#[derive(Clone)] -pub struct ServiceContext { - pub config: sdk::config::StdGadgetConfiguration, +#[derive(TangleClientContext, ServicesContext)] +pub struct HyperlaneContext { + #[config] + pub env: StdGadgetConfiguration, + data_dir: PathBuf, + connection: Arc, + container: Mutex>, +} + +const IMAGE: &str = "gcr.io/abacus-labs-dev/hyperlane-agent:main"; +impl HyperlaneContext { + pub async fn new(env: StdGadgetConfiguration, data_dir: PathBuf) -> Result { + let connection = connect_to_docker(None).await?; + Ok(Self { + env, + data_dir, + connection, + container: Mutex::new(None), + }) + } } -/// Returns "Hello World!" if `who` is `None`, otherwise returns "Hello, {who}!" #[sdk::job( id = 0, - params(who), + params(config_urls, origin_chain_name), result(_), event_listener( - listener = TangleEventListener::, + listener = TangleEventListener, JobCalled>, pre_processor = services_pre_processor, post_processor = services_post_processor, ), )] -pub fn say_hello(who: Option, context: ServiceContext) -> Result { - match who { - Some(who) => Ok(format!("Hello, {who}!")), - None => Ok("Hello World!".to_string()), - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn it_works() { - let config = sdk::config::StdGadgetConfiguration::default(); - let context = ServiceContext { config }; - let result = say_hello(None, context.clone()).unwrap(); - assert_eq!(result, "Hello World!"); - let result = say_hello(Some("Alice".to_string()), context).unwrap(); - assert_eq!(result, "Hello, Alice!"); - } +pub async fn set_config( + ctx: Arc, + config_urls: Option>, + origin_chain_name: String, +) -> Result { + Ok(0) } diff --git a/src/main.rs b/src/main.rs index 0780974..a94980a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -3,22 +3,40 @@ use gadget_sdk as sdk; use hyperlane_relayer_blueprint as blueprint; use sdk::runners::tangle::TangleConfig; use sdk::runners::BlueprintRunner; +use std::path::{Path, PathBuf}; +use std::sync::Arc; + +fn default_data_dir() -> PathBuf { + const MANIFEST_DIR: &str = env!("CARGO_MANIFEST_DIR"); + Path::new(MANIFEST_DIR).join("data") +} #[sdk::main(env)] async fn main() -> Result<()> { - // Create your service context - // Here you can pass any configuration or context that your service needs. - let context = blueprint::ServiceContext { - config: env.clone(), - }; + color_eyre::install()?; + + let data_dir; + match env.data_dir.clone() { + Some(dir) => data_dir = dir, + None => { + tracing::warn!("Data dir not specified, using default"); + data_dir = default_data_dir(); + } + } + + if !data_dir.exists() { + tracing::warn!("Data dir does not exist, creating"); + std::fs::create_dir_all(&data_dir)?; + } + + let ctx = Arc::new(blueprint::HyperlaneContext::new(env.clone(), data_dir).await?); - // Create the event handler from the job - let say_hello_job = blueprint::SayHelloEventHandler::new(&env, context).await?; + let set_config = blueprint::SetConfigEventHandler::new(&env, ctx).await?; tracing::info!("Starting the event watcher ..."); let tangle_config = TangleConfig::default(); BlueprintRunner::new(tangle_config, env) - .job(say_hello_job) + .job(set_config) .run() .await?;