diff --git a/.gitignore b/.gitignore index 817ddac4f2..a07a3567ba 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,6 @@ nym-network-monitor/__pycache__ nym-network-monitor/*.key nym-network-monitor/.envrc nym-network-monitor/.envrc + + +*.sqlite \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index d0caa221f9..a8f3de6c1b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5221,31 +5221,6 @@ dependencies = [ "zeroize", ] -[[package]] -name = "nym-data-observatory" -version = "0.1.0" -dependencies = [ - "anyhow", - "axum 0.7.7", - "chrono", - "clap 4.5.20", - "nym-bin-common", - "nym-network-defaults", - "nym-node-requests", - "nym-task", - "serde", - "serde_json", - "sqlx", - "tokio", - "tokio-util", - "tower-http", - "tracing", - "tracing-subscriber", - "utoipa", - "utoipa-swagger-ui", - "utoipauto", -] - [[package]] name = "nym-dkg" version = "0.1.0" @@ -6860,6 +6835,35 @@ dependencies = [ "url", ] +[[package]] +name = "nyx-chain-watcher" +version = "0.1.0" +dependencies = [ + "anyhow", + "axum 0.7.7", + "chrono", + "clap 4.5.20", + "nym-bin-common", + "nym-network-defaults", + "nym-node-requests", + "nym-task", + "nyxd-scraper", + "reqwest 0.12.4", + "rocket", + "serde", + "serde_json", + "sqlx", + "time", + "tokio", + "tokio-util", + "tower-http", + "tracing", + "tracing-subscriber", + "utoipa", + "utoipa-swagger-ui", + "utoipauto", +] + [[package]] name = "nyxd-scraper" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index a5b90d7dfd..cd44c15136 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -118,8 +118,8 @@ members = [ "nym-credential-proxy/nym-credential-proxy", "nym-credential-proxy/nym-credential-proxy-requests", "nym-credential-proxy/vpn-api-lib-wasm", - "nym-data-observatory", "nym-network-monitor", + "nyx-chain-watcher", "nym-node", "nym-node/nym-node-requests", "nym-node/nym-node-metrics", @@ -158,11 +158,11 @@ default-members = [ "explorer-api", "nym-api", "nym-credential-proxy/nym-credential-proxy", - "nym-data-observatory", "nym-node", "nym-node-status-api/nym-node-status-agent", "nym-node-status-api/nym-node-status-api", "nym-validator-rewarder", + "nyx-chain-watcher", "service-providers/authenticator", "service-providers/ip-packet-router", "service-providers/network-requester", diff --git a/nym-data-observatory/Cargo.toml b/nyx-chain-watcher/Cargo.toml similarity index 98% rename from nym-data-observatory/Cargo.toml rename to nyx-chain-watcher/Cargo.toml index 0270057477..58564b3d12 100644 --- a/nym-data-observatory/Cargo.toml +++ b/nyx-chain-watcher/Cargo.toml @@ -2,7 +2,7 @@ # SPDX-License-Identifier: Apache-2.0 [package] -name = "nym-data-observatory" +name = "nyx-chain-watcher" version = "0.1.0" authors.workspace = true repository.workspace = true diff --git a/nyx-chain-watcher/README.md b/nyx-chain-watcher/README.md new file mode 100644 index 0000000000..4142c4ecee --- /dev/null +++ b/nyx-chain-watcher/README.md @@ -0,0 +1,15 @@ +# Nyx Chain Watcher + +A simple binary to watch addresses on the Nyx chain and to call webhooks when particular message types are in a block. + +## Running locally + +``` +DATABASE_URL=nyx_chain_watcher.sqlite \ +NYXD_WEBSOCKET_URL=wss://rpc.nymtech.net:443/websocket \ +NYXD_RPC_URL=https://rpc.nymtech.net \ +PAYMENT_RECEIVE_ADDRESS=n1... \ +WEBHOOK_URL=https://webhook.site/... \ +cargo run +``` + diff --git a/nym-data-observatory/README_SQLX.md b/nyx-chain-watcher/README_SQLX.md similarity index 100% rename from nym-data-observatory/README_SQLX.md rename to nyx-chain-watcher/README_SQLX.md diff --git a/nym-data-observatory/build.rs b/nyx-chain-watcher/build.rs similarity index 98% rename from nym-data-observatory/build.rs rename to nyx-chain-watcher/build.rs index faedd8b4c7..eb28ed3bf5 100644 --- a/nym-data-observatory/build.rs +++ b/nyx-chain-watcher/build.rs @@ -5,7 +5,7 @@ use std::{collections::HashMap, fs::File, path::PathBuf, str::FromStr}; #[tokio::main] async fn main() -> Result<()> { - let db_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("data_observatory.sqlite"); + let db_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("nyx_chain_watcher.sqlite"); // Create the database directory if it doesn't exist if let Some(parent) = db_path.parent() { diff --git a/nym-data-observatory/docker-compose.yml b/nyx-chain-watcher/docker-compose.yml similarity index 100% rename from nym-data-observatory/docker-compose.yml rename to nyx-chain-watcher/docker-compose.yml diff --git a/nym-data-observatory/migrations/000_init.sql b/nyx-chain-watcher/migrations/000_init.sql similarity index 100% rename from nym-data-observatory/migrations/000_init.sql rename to nyx-chain-watcher/migrations/000_init.sql diff --git a/nym-data-observatory/migrations/001_price_data.sql b/nyx-chain-watcher/migrations/001_price_data.sql similarity index 100% rename from nym-data-observatory/migrations/001_price_data.sql rename to nyx-chain-watcher/migrations/001_price_data.sql diff --git a/nym-data-observatory/migrations/002_payment_transactions.sql b/nyx-chain-watcher/migrations/002_payment_transactions.sql similarity index 100% rename from nym-data-observatory/migrations/002_payment_transactions.sql rename to nyx-chain-watcher/migrations/002_payment_transactions.sql diff --git a/nym-data-observatory/src/chain_scraper/mod.rs b/nyx-chain-watcher/src/chain_scraper/mod.rs similarity index 100% rename from nym-data-observatory/src/chain_scraper/mod.rs rename to nyx-chain-watcher/src/chain_scraper/mod.rs diff --git a/nym-data-observatory/src/db/mod.rs b/nyx-chain-watcher/src/db/mod.rs similarity index 100% rename from nym-data-observatory/src/db/mod.rs rename to nyx-chain-watcher/src/db/mod.rs diff --git a/nym-data-observatory/src/db/models.rs b/nyx-chain-watcher/src/db/models.rs similarity index 100% rename from nym-data-observatory/src/db/models.rs rename to nyx-chain-watcher/src/db/models.rs diff --git a/nym-data-observatory/src/db/queries/mod.rs b/nyx-chain-watcher/src/db/queries/mod.rs similarity index 100% rename from nym-data-observatory/src/db/queries/mod.rs rename to nyx-chain-watcher/src/db/queries/mod.rs diff --git a/nym-data-observatory/src/db/queries/payments.rs b/nyx-chain-watcher/src/db/queries/payments.rs similarity index 100% rename from nym-data-observatory/src/db/queries/payments.rs rename to nyx-chain-watcher/src/db/queries/payments.rs diff --git a/nym-data-observatory/src/db/queries/price.rs b/nyx-chain-watcher/src/db/queries/price.rs similarity index 100% rename from nym-data-observatory/src/db/queries/price.rs rename to nyx-chain-watcher/src/db/queries/price.rs diff --git a/nym-data-observatory/src/http/api/mixnodes.rs b/nyx-chain-watcher/src/http/api/mixnodes.rs similarity index 100% rename from nym-data-observatory/src/http/api/mixnodes.rs rename to nyx-chain-watcher/src/http/api/mixnodes.rs diff --git a/nym-data-observatory/src/http/api/mod.rs b/nyx-chain-watcher/src/http/api/mod.rs similarity index 100% rename from nym-data-observatory/src/http/api/mod.rs rename to nyx-chain-watcher/src/http/api/mod.rs diff --git a/nym-data-observatory/src/http/api/price.rs b/nyx-chain-watcher/src/http/api/price.rs similarity index 92% rename from nym-data-observatory/src/http/api/price.rs rename to nyx-chain-watcher/src/http/api/price.rs index 1a239fcf54..354d3cbfa7 100644 --- a/nym-data-observatory/src/http/api/price.rs +++ b/nyx-chain-watcher/src/http/api/price.rs @@ -18,7 +18,7 @@ pub(crate) fn routes() -> Router { ) )] -/// Fetch the latest price cached by the data observatory +/// Fetch the latest price cached by this API async fn price(State(state): State) -> HttpResult> { get_latest_price(state.db_pool()) .await diff --git a/nym-data-observatory/src/http/api/server.rs b/nyx-chain-watcher/src/http/api/server.rs similarity index 100% rename from nym-data-observatory/src/http/api/server.rs rename to nyx-chain-watcher/src/http/api/server.rs diff --git a/nym-data-observatory/src/http/api_docs.rs b/nyx-chain-watcher/src/http/api_docs.rs similarity index 65% rename from nym-data-observatory/src/http/api_docs.rs rename to nyx-chain-watcher/src/http/api_docs.rs index c7dbe0118d..097bd3c4ba 100644 --- a/nym-data-observatory/src/http/api_docs.rs +++ b/nyx-chain-watcher/src/http/api_docs.rs @@ -4,11 +4,7 @@ use utoipauto::utoipauto; // manually import external structs which are behind feature flags because they // can't be automatically discovered // https://github.com/ProbablyClem/utoipauto/issues/13#issuecomment-1974911829 -#[utoipauto(paths = "./nym-data-observatory/src")] +#[utoipauto(paths = "./nyx-chain-watcher/src")] #[derive(OpenApi)] -#[openapi( - info(title = "Nym Data Observatory API"), - tags(), - components(schemas()) -)] +#[openapi(info(title = "Nyx Chain Watcher API"), tags(), components(schemas()))] pub(super) struct ApiDoc; diff --git a/nym-data-observatory/src/http/error.rs b/nyx-chain-watcher/src/http/error.rs similarity index 100% rename from nym-data-observatory/src/http/error.rs rename to nyx-chain-watcher/src/http/error.rs diff --git a/nym-data-observatory/src/http/mod.rs b/nyx-chain-watcher/src/http/mod.rs similarity index 100% rename from nym-data-observatory/src/http/mod.rs rename to nyx-chain-watcher/src/http/mod.rs diff --git a/nym-data-observatory/src/http/server.rs b/nyx-chain-watcher/src/http/server.rs similarity index 100% rename from nym-data-observatory/src/http/server.rs rename to nyx-chain-watcher/src/http/server.rs diff --git a/nym-data-observatory/src/http/state.rs b/nyx-chain-watcher/src/http/state.rs similarity index 100% rename from nym-data-observatory/src/http/state.rs rename to nyx-chain-watcher/src/http/state.rs diff --git a/nym-data-observatory/src/logging.rs b/nyx-chain-watcher/src/logging.rs similarity index 100% rename from nym-data-observatory/src/logging.rs rename to nyx-chain-watcher/src/logging.rs diff --git a/nym-data-observatory/src/main.rs b/nyx-chain-watcher/src/main.rs similarity index 84% rename from nym-data-observatory/src/main.rs rename to nyx-chain-watcher/src/main.rs index 4373f8850f..3eb513b889 100644 --- a/nym-data-observatory/src/main.rs +++ b/nyx-chain-watcher/src/main.rs @@ -15,18 +15,18 @@ mod price_scraper; #[command(version, about, long_about = None)] struct Args { /// Port to listen on - #[arg(long, default_value_t = 8000, env = "NYM_DATA_OBSERVATORY_HTTP_PORT")] + #[arg(long, default_value_t = 8000, env = "NYX_CHAIN_WATCHER_HTTP_PORT")] http_port: u16, /// Path to the environment variables file. If you don't provide one, variables for the mainnet will be used. - #[arg(short, long, default_value = None, env = "NYM_DATA_OBSERVATORY_ENV_FILE")] + #[arg(short, long, default_value = None, env = "NYX_CHAIN_WATCHER_ENV_FILE")] env_file: Option, /// SQLite database file path #[arg( long, - default_value = "data_observatory.sqlite", - env = "NYM_DATA_OBSERVATORY_DB_PATH" + default_value = "nyx_chain_watcher.sqlite", + env = "DATABASE_URL" )] db_path: String, } @@ -46,13 +46,13 @@ async fn main() -> anyhow::Result<()> { let connection_url = format!("sqlite://{}?mode=rwc", db_path); let storage = db::Storage::init(connection_url).await?; - let observatory_pool = storage.pool_owned().await; + let watcher_pool = storage.pool_owned().await; // Spawn the chain scraper and get its storage // Spawn the payment listener task let payment_listener_handle = tokio::spawn({ - let obs_pool = observatory_pool.clone(); + let obs_pool = watcher_pool.clone(); let chain_storage = run_chain_scraper().await?; async move { @@ -67,7 +67,7 @@ async fn main() -> anyhow::Result<()> { //let background_pool = db_pool.clone(); let price_scraper_handle = tokio::spawn(async move { - price_scraper::run_price_scraper(&observatory_pool).await; + price_scraper::run_price_scraper(&watcher_pool).await; }); let shutdown_handles = http::server::start_http_api(storage.pool_owned().await, args.http_port) diff --git a/nym-data-observatory/src/payment_listener/mod.rs b/nyx-chain-watcher/src/payment_listener/mod.rs similarity index 96% rename from nym-data-observatory/src/payment_listener/mod.rs rename to nyx-chain-watcher/src/payment_listener/mod.rs index 7006b413e6..bddfecbbda 100644 --- a/nym-data-observatory/src/payment_listener/mod.rs +++ b/nyx-chain-watcher/src/payment_listener/mod.rs @@ -14,7 +14,7 @@ struct TransferEvent { } pub(crate) async fn run_payment_listener( - observatory_pool: SqlitePool, + watcher_pool: SqlitePool, chain_storage: ScraperStorage, ) -> anyhow::Result<()> { let payment_receive_address = env::var("PAYMENT_RECEIVE_ADDRESS").map_err(|_| { @@ -26,7 +26,7 @@ pub(crate) async fn run_payment_listener( let client = Client::new(); loop { let last_checked_height = - queries::payments::get_last_checked_height(&observatory_pool).await?; + queries::payments::get_last_checked_height(&watcher_pool).await?; tracing::info!("Last checked height: {}", last_checked_height); let transactions = chain_storage @@ -44,7 +44,7 @@ pub(crate) async fn run_payment_listener( let amount: f64 = parse_unym_amount(&transfer.amount)?; queries::payments::insert_payment( - &observatory_pool, + &watcher_pool, tx.hash.clone(), transfer.sender.clone(), transfer.recipient.clone(), diff --git a/nym-data-observatory/src/price_scraper/mod.rs b/nyx-chain-watcher/src/price_scraper/mod.rs similarity index 100% rename from nym-data-observatory/src/price_scraper/mod.rs rename to nyx-chain-watcher/src/price_scraper/mod.rs