From e05d1f50c7410fc1cab9ff441dd54f35cc8e25fd Mon Sep 17 00:00:00 2001 From: Mark Sinclair Date: Tue, 2 Dec 2025 12:16:56 +0000 Subject: [PATCH] process events and logs --- .../sql_migrations/0002_cosmos.sql | 1 + .../nyxd-scraper-psql/src/storage/manager.rs | 9 ++++++--- .../src/storage/transaction.rs | 18 +++++++++++++----- .../migrations/0002_cosmos.sql | 1 + 4 files changed, 21 insertions(+), 8 deletions(-) diff --git a/common/nyxd-scraper-psql/sql_migrations/0002_cosmos.sql b/common/nyxd-scraper-psql/sql_migrations/0002_cosmos.sql index d33b75fae9..e0241f835c 100644 --- a/common/nyxd-scraper-psql/sql_migrations/0002_cosmos.sql +++ b/common/nyxd-scraper-psql/sql_migrations/0002_cosmos.sql @@ -57,6 +57,7 @@ CREATE TABLE transaction gas_used BIGINT DEFAULT 0, raw_log TEXT, logs JSONB, + events JSONB, CONSTRAINT unique_tx UNIQUE (hash) ); diff --git a/common/nyxd-scraper-psql/src/storage/manager.rs b/common/nyxd-scraper-psql/src/storage/manager.rs index cbe5003f82..b0bf11f2f5 100644 --- a/common/nyxd-scraper-psql/src/storage/manager.rs +++ b/common/nyxd-scraper-psql/src/storage/manager.rs @@ -345,6 +345,7 @@ pub(crate) async fn insert_transaction<'a, E>( gas_used: i64, raw_log: String, logs: JsonValue, + events: JsonValue, executor: E, ) -> Result<(), sqlx::Error> where @@ -356,8 +357,8 @@ where sqlx::query!( r#" INSERT INTO transaction - (hash, height, index, success, messages, memo, signatures, signer_infos, fee, gas_wanted, gas_used, raw_log, logs) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13) + (hash, height, index, success, messages, memo, signatures, signer_infos, fee, gas_wanted, gas_used, raw_log, logs, events) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) ON CONFLICT (hash) DO UPDATE SET height = excluded.height, index = excluded.index, @@ -370,7 +371,8 @@ where gas_wanted = excluded.gas_wanted, gas_used = excluded.gas_used, raw_log = excluded.raw_log, - logs = excluded.logs + logs = excluded.logs, + events = excluded.events "#, hash, height, @@ -385,6 +387,7 @@ where gas_used, raw_log, logs, + events, ) .execute(executor) .await?; diff --git a/common/nyxd-scraper-psql/src/storage/transaction.rs b/common/nyxd-scraper-psql/src/storage/transaction.rs index cfade24537..bdddf5a120 100644 --- a/common/nyxd-scraper-psql/src/storage/transaction.rs +++ b/common/nyxd-scraper-psql/src/storage/transaction.rs @@ -23,7 +23,7 @@ use serde_json::json; use sqlx::types::time::{OffsetDateTime, PrimitiveDateTime}; use sqlx::{Postgres, Transaction}; use std::ops::{Deref, DerefMut}; -use tracing::{debug, trace, warn}; +use tracing::{debug, error, trace, warn}; pub struct PostgresStorageTransaction { pub(super) inner: Transaction<'static, Postgres>, @@ -167,10 +167,17 @@ impl PostgresStorageTransaction { .map(|info| proto::cosmos::tx::v1beta1::SignerInfo::from(info.clone())) .collect::>(); + let hash = chain_tx.hash.to_string(); + let height = chain_tx.height.into(); + let index = chain_tx.index as i32; + + let log = serde_json::to_value(chain_tx.tx_result.log.clone()).map_err(|e| error!(hash, height, index, "Failed to parse logs: {e}")).unwrap_or_default(); + let events = &chain_tx.tx_result.events; + insert_transaction( - chain_tx.hash.to_string(), - chain_tx.height.into(), - chain_tx.index as i32, + hash, + height, + index, chain_tx.tx_result.code.is_ok(), serde_json::Value::Array(messages), chain_tx.tx.body.memo.clone(), @@ -180,7 +187,8 @@ impl PostgresStorageTransaction { chain_tx.tx_result.gas_wanted, chain_tx.tx_result.gas_used, chain_tx.tx_result.log.clone(), - json!("null"), + json!(log), + json!(events), self.inner.as_mut(), ) .await?; diff --git a/nym-data-observatory/migrations/0002_cosmos.sql b/nym-data-observatory/migrations/0002_cosmos.sql index d33b75fae9..e0241f835c 100644 --- a/nym-data-observatory/migrations/0002_cosmos.sql +++ b/nym-data-observatory/migrations/0002_cosmos.sql @@ -57,6 +57,7 @@ CREATE TABLE transaction gas_used BIGINT DEFAULT 0, raw_log TEXT, logs JSONB, + events JSONB, CONSTRAINT unique_tx UNIQUE (hash) );