Skip to content

Commit

Permalink
chore: update to latest sdk
Browse files Browse the repository at this point in the history
  • Loading branch information
drewstone committed Jan 24, 2025
1 parent 7546355 commit a6741a0
Show file tree
Hide file tree
Showing 11 changed files with 10,777 additions and 4,523 deletions.
15,183 changes: 10,720 additions & 4,463 deletions Cargo.lock

Large diffs are not rendered by default.

18 changes: 5 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,38 +13,30 @@ keywords = ["tangle", "blueprint", "avs"]
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"] }
serde_json = "1.0.133"
serde = "1.0.215"
lazy_static = "1.5.0"
alloy-json-abi = { version = "0.8.12", features = ["serde_json"] }
alloy-sol-types = "0.8.12"
alloy-primitives = "0.8.12"
tempfile = "3.14.0"
tempfile = "3.13"
uuid = "1.11.0"
thiserror = "2.0.3"
schemars = "0.8"
kube = { version = "0.96.0", features = ["runtime", "derive"] }
k8s-openapi = { version = "0.23.0", features = ["v1_31"] }
gadget-sdk = { version = "0.4.0", default-features = false, features = ["getrandom"] }
blueprint-sdk = { git = "https://github.com/tangle-network/gadget", features = ["tangle", "evm", "macros", "local-store"] }
bytes = "1.8.0"
reqwest = "0.12.9"
wiremock = "0.6.2"
fake = "3.0.1"
rand = "0.8.5"
regex = "1.11.1"
ethers = { version = "2.0.14" }
anyhow = "1.0.93"
enigo = "0.3.0"
rexpect = "0.6.0"
bollard = "0.16.1"
bollard = "0.17"
futures = "0.3.31"
testcontainers = "0.20.0"
testcontainers = "0.23.0"
chrono = "0.4.39"

[dev-dependencies]
Expand All @@ -61,7 +53,7 @@ blueprint-metadata = "0.1.6"

[features]
default = ["std"]
std = ["gadget-sdk/std"]
std = ["blueprint-sdk/std"]

[lib]
path = "src/lib.rs"
Expand Down
4 changes: 2 additions & 2 deletions src/envio_utils/docker.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use blueprint_sdk::std::collections::HashMap;
use blueprint_sdk::tokio::time::{sleep, Duration};
use bollard::container::{Config, CreateContainerOptions, StartContainerOptions};
use bollard::models::HostConfig;
use bollard::Docker;
use futures::StreamExt;
use std::collections::HashMap;
use tokio::time::{sleep, Duration};

use crate::envio_utils::project::EnvioError;

Expand Down
19 changes: 6 additions & 13 deletions src/envio_utils/project.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
use super::config::{ContractConfig, ContractSource};
use super::docker::EnvioDocker;
use anyhow::Result;
use blueprint_sdk::std::path::PathBuf;
use blueprint_sdk::tokio::process::{Child, Command};
use rexpect::spawn;
// use expectrl::{spawn, Regex, Session, WaitStatus};
use std::path::PathBuf;
use thiserror::Error;
use tokio::process::{Child, Command};

use crate::network::SUPPORTED_NETWORKS;

use super::config::{ContractConfig, ContractSource};
use super::docker::EnvioDocker;

#[derive(Error, Debug)]
pub enum EnvioError {
Expand All @@ -26,10 +22,8 @@ pub enum EnvioError {
ReqwestError(#[from] reqwest::Error),
#[error("Serde JSON error: {0}")]
SerdeJsonError(#[from] serde_json::Error),
#[error("Enigo error: {0}")]
EnigoError(#[from] enigo::InputError),
#[error("Join error: {0}")]
JoinError(#[from] tokio::task::JoinError),
JoinError(#[from] blueprint_sdk::tokio::task::JoinError),
#[error("rexpect error: {0}")]
RexpectError(#[from] rexpect::error::Error),
}
Expand Down Expand Up @@ -171,7 +165,6 @@ impl EnvioManager {
loop {
match Self::handle_envio_prompts(
&mut session,
&project_dir_clone,
&contracts,
&mut current_contract_idx,
&mut current_deployment_idx,
Expand Down Expand Up @@ -257,7 +250,6 @@ impl EnvioManager {

async fn handle_envio_prompts(
session: &mut rexpect::session::PtySession,
project_dir: &PathBuf,
contracts: &[ContractConfig],
current_contract_idx: &mut usize,
current_deployment_idx: &mut usize,
Expand Down Expand Up @@ -495,6 +487,7 @@ async fn fetch_abi_from_url(url: &str) -> Result<String, EnvioError> {
mod tests {
use super::*;
use crate::test_utils::create_test_contract;
use blueprint_sdk::tokio;

#[tokio::test]
async fn test_project_lifecycle() {
Expand Down
14 changes: 8 additions & 6 deletions src/jobs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ use crate::{
},
service_context::SpawnIndexerParams,
};
use gadget_sdk::event_listener::tangle::jobs::services_pre_processor;
use gadget_sdk::event_listener::tangle::TangleEventListener;
use gadget_sdk::job;
use gadget_sdk::tangle_subxt::tangle_testnet_runtime::api::services::events::JobCalled;
use blueprint_sdk::event_listeners::tangle::{
events::TangleEventListener, services::services_pre_processor,
};
use blueprint_sdk::job;
use blueprint_sdk::tangle_subxt::tangle_testnet_runtime::api::services::events::JobCalled;
use k8s_openapi::{apimachinery::pkg::apis::meta::v1::Time, chrono};

use crate::service_context::ServiceContext;
Expand Down Expand Up @@ -154,9 +155,9 @@ mod tests {
use crate::{
envio_utils::IndexerConfig,
service_context::{DeploymentMode, SpawnIndexerResult},
test_utils::{create_test_contract, create_test_explorer_contract},
test_utils::create_test_contract,
};
use gadget_sdk::config::StdGadgetConfiguration;
use blueprint_sdk::{config::StdGadgetConfiguration, tokio};
use std::path::PathBuf;

#[tokio::test]
Expand All @@ -181,6 +182,7 @@ mod tests {
}

#[tokio::test]
#[ignore = "requires kubernetes cluster"]
async fn test_kube_spawn_multi_contract_indexer() {
// Setup test environment
let mut context =
Expand Down
3 changes: 2 additions & 1 deletion src/kubernetes/deployment.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use super::*;
use std::collections::BTreeMap;
use blueprint_sdk::std::collections::BTreeMap;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ServiceConfig {
Expand Down Expand Up @@ -180,6 +180,7 @@ impl ResourceManager for DeploymentManager {
#[cfg(test)]
mod tests {
use super::*;
use blueprint_sdk::tokio;
use kube::{Client, Config};
use rustls::crypto::aws_lc_rs::default_provider;

Expand Down
12 changes: 7 additions & 5 deletions src/kubernetes/service.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::fmt::Debug;

use super::*;
use blueprint_sdk::std::fmt::Debug;
use blueprint_sdk::tokio::time::{sleep, Duration};
use deployment::DeploymentConfig;
use gadget_sdk::futures::TryStreamExt;
use futures::TryStreamExt;
use k8s_openapi::apimachinery::pkg::apis::meta::v1::Time;
use k8s_openapi::chrono;
use kube::api::{Patch, PatchParams};
Expand All @@ -11,7 +11,6 @@ use kube::runtime::watcher::{watcher, Config, Event};
use kube::Resource;
use schemars::JsonSchema;
use serde::de::DeserializeOwned;
use tokio::time::{sleep, Duration};

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct TimeWrapper(pub Time);
Expand Down Expand Up @@ -149,7 +148,10 @@ where
match event {
Event::Apply(svc) => {
if let Err(e) = self.reconcile_service(&svc).await {
tracing::error!("Failed to reconcile service: {}", e);
blueprint_sdk::logging::error!(
"Failed to reconcile service: {}",
e
);
}
}
Event::Delete(_) => {}
Expand Down
14 changes: 9 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ pub mod test_utils;
mod tests {
use super::*;

use blueprint_sdk::std::sync::Arc;
use blueprint_sdk::std::{collections::HashMap, path::PathBuf};
use blueprint_sdk::tokio;
use blueprint_sdk::tokio::sync::RwLock;
use envio_utils::{project::EnvioManager, IndexerConfig};
use http::{Request, Response};
use jobs::spawn_indexer_kube;
Expand All @@ -18,10 +22,7 @@ mod tests {
K8sManager,
};
use service_context::{DeploymentMode, ServiceContext, SpawnIndexerParams};
use std::sync::Arc;
use std::{collections::HashMap, path::PathBuf};
use test_utils::create_test_contract;
use tokio::sync::RwLock;
use tower_test::mock;

// Mock types for unit testing
Expand All @@ -34,7 +35,8 @@ mod tests {
let client = Client::new(mock_service, "test-namespace");

let context = ServiceContext {
config: gadget_sdk::config::StdGadgetConfiguration::default(),
config: blueprint_sdk::config::StdGadgetConfiguration::default(),
call_id: None,
indexers: Arc::new(RwLock::new(HashMap::new())),
envio_manager: Arc::new(EnvioManager::new(PathBuf::from("/tmp"))),
deployment_mode: DeploymentMode::Kubernetes,
Expand All @@ -52,6 +54,7 @@ mod tests {
}

#[tokio::test]
#[ignore = "requires kubernetes cluster"]
async fn test_spawn_indexer_kube_mock() {
let (context, mut handle) = setup_mock_context().await;

Expand Down Expand Up @@ -98,7 +101,8 @@ mod tests {
async fn test_spawn_indexer_kube_integration() {
let client = Client::try_default().await.unwrap();
let context = ServiceContext {
config: gadget_sdk::config::StdGadgetConfiguration::default(),
config: blueprint_sdk::config::StdGadgetConfiguration::default(),
call_id: None,
indexers: Arc::new(RwLock::new(HashMap::new())),
envio_manager: Arc::new(EnvioManager::new(PathBuf::from("/tmp"))),
deployment_mode: DeploymentMode::Kubernetes,
Expand Down
12 changes: 5 additions & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
use blueprint_sdk::runners::{core::runner::BlueprintRunner, tangle::tangle::TangleConfig};
use color_eyre::Result;
use envio_hyperindex_blueprint::service_context::ServiceContext;
use gadget_sdk as sdk;
use sdk::runners::tangle::TangleConfig;
use sdk::runners::BlueprintRunner;

#[sdk::main(env)]
#[blueprint_sdk::main(env)]
async fn main() -> Result<()> {
let base_dir = env
.clone()
.data_dir
.map(|dir| dir.join("indexers"))
.unwrap_or_default();
let context = ServiceContext::new(env.clone(), base_dir);
let _context = ServiceContext::new(env.clone(), base_dir);

tracing::info!("Starting the event watcher ...");
blueprint_sdk::logging::info!("Starting the event watcher ...");
let tangle_config = TangleConfig::default();
BlueprintRunner::new(tangle_config, env).run().await?;

tracing::info!("Exiting...");
blueprint_sdk::logging::info!("Exiting...");
Ok(())
}
2 changes: 1 addition & 1 deletion src/network/definitions.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use blueprint_sdk::std::collections::HashMap;
use lazy_static::lazy_static;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct NetworkInfo {
Expand Down
19 changes: 12 additions & 7 deletions src/service_context.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use blueprint_sdk::macros::contexts::TangleClientContext;
use blueprint_sdk::std::collections::HashMap;
use blueprint_sdk::std::path::PathBuf;
use blueprint_sdk::std::sync::Arc;
use blueprint_sdk::tokio::process::Child;
use blueprint_sdk::tokio::sync::RwLock;
use blueprint_sdk::{config::StdGadgetConfiguration, macros::contexts::ServicesContext};
use envio_utils::{EnvioManager, EnvioProject};
use gadget_sdk::config::StdGadgetConfiguration;
use schemars::JsonSchema;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
use tokio::process::Child;
use tokio::sync::RwLock;

use crate::{
envio_utils::{self, IndexerConfig},
Expand Down Expand Up @@ -49,9 +50,12 @@ pub enum DeploymentMode {
Kubernetes,
}

#[derive(Clone)]
#[derive(Clone, ServicesContext, TangleClientContext)]
pub struct ServiceContext {
#[config]
pub config: StdGadgetConfiguration,
#[call_id]
pub call_id: Option<u64>,
pub indexers: Arc<RwLock<HashMap<String, IndexerProcess>>>,
pub envio_manager: Arc<EnvioManager>,
pub deployment_mode: DeploymentMode,
Expand All @@ -62,6 +66,7 @@ impl ServiceContext {
pub fn new(config: StdGadgetConfiguration, data_dir: PathBuf) -> Self {
Self {
config,
call_id: None,
indexers: Arc::new(RwLock::new(HashMap::new())),
envio_manager: Arc::new(EnvioManager::new(data_dir)),
deployment_mode: DeploymentMode::Local,
Expand Down

0 comments on commit a6741a0

Please sign in to comment.