Move nym-data-observatory (v0) to nyx-chain-watcher
This commit is contained in:
@@ -54,3 +54,6 @@ nym-network-monitor/__pycache__
|
||||
nym-network-monitor/*.key
|
||||
nym-network-monitor/.envrc
|
||||
nym-network-monitor/.envrc
|
||||
|
||||
|
||||
*.sqlite
|
||||
Generated
+29
-25
@@ -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"
|
||||
|
||||
+2
-2
@@ -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",
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
```
|
||||
|
||||
@@ -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() {
|
||||
+1
-1
@@ -18,7 +18,7 @@ pub(crate) fn routes() -> Router<AppState> {
|
||||
)
|
||||
)]
|
||||
|
||||
/// Fetch the latest price cached by the data observatory
|
||||
/// Fetch the latest price cached by this API
|
||||
async fn price(State(state): State<AppState>) -> HttpResult<Json<PriceHistory>> {
|
||||
get_latest_price(state.db_pool())
|
||||
.await
|
||||
@@ -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;
|
||||
@@ -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<String>,
|
||||
|
||||
/// 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)
|
||||
+3
-3
@@ -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(),
|
||||
Reference in New Issue
Block a user