From 05f2079b645a8a98887abe498a5e5cc0a1142bae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Stuczy=C5=84ski?= Date: Mon, 7 Jul 2025 15:00:27 +0100 Subject: [PATCH] involved addresses --- Cargo.lock | 48 ++----------------- Cargo.toml | 1 - common/nyxd-scraper-psql/Cargo.toml | 2 +- .../nyxd-scraper-psql/src/storage/helpers.rs | 22 +++++++++ .../src/storage/transaction.rs | 5 +- 5 files changed, 29 insertions(+), 49 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8d5e3fd20b..1cb0e05ba2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1354,7 +1354,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c2895653b4d9f1538a83970077cb01dfc77a4810524e51a110944688e916b18e" dependencies = [ "prost 0.11.9", - "prost-types 0.11.9", + "prost-types", "tonic 0.9.2", "tracing-core", ] @@ -1371,7 +1371,7 @@ dependencies = [ "futures", "hdrhistogram", "humantime", - "prost-types 0.11.9", + "prost-types", "serde", "serde_json", "thread_local", @@ -8112,8 +8112,8 @@ dependencies = [ "async-trait", "base64 0.22.1", "cosmrs", + "itertools 0.14.0", "nyxd-scraper-shared", - "prost-reflect", "serde", "serde_json", "sqlx", @@ -8845,16 +8845,6 @@ dependencies = [ "prost-derive 0.13.5", ] -[[package]] -name = "prost" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7231bd9b3d3d33c86b58adbac74b5ec0ad9f496b19d22801d773636feaa95f3d" -dependencies = [ - "bytes", - "prost-derive 0.14.1", -] - [[package]] name = "prost-derive" version = "0.11.9" @@ -8881,29 +8871,6 @@ dependencies = [ "syn 2.0.98", ] -[[package]] -name = "prost-derive" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9120690fafc389a67ba3803df527d0ec9cbbc9cc45e4cc20b332996dfb672425" -dependencies = [ - "anyhow", - "itertools 0.14.0", - "proc-macro2", - "quote", - "syn 2.0.98", -] - -[[package]] -name = "prost-reflect" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e6b545c556471033fc1099868fca468bff8cf034f7bb9153b445f24d00aa28d" -dependencies = [ - "prost 0.14.1", - "prost-types 0.14.1", -] - [[package]] name = "prost-types" version = "0.11.9" @@ -8913,15 +8880,6 @@ dependencies = [ "prost 0.11.9", ] -[[package]] -name = "prost-types" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9b4db3d6da204ed77bb26ba83b6122a73aeb2e87e25fbf7ad2e84c4ccbf8f72" -dependencies = [ - "prost 0.14.1", -] - [[package]] name = "protobuf" version = "3.7.2" diff --git a/Cargo.toml b/Cargo.toml index 2b997b2aff..393e549ae6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -390,7 +390,6 @@ cosmos-sdk-proto = { version = "0.26.1" } tendermint = "0.40.4" tendermint-rpc = "0.40.4" prost = { version = "0.13", default-features = false } -prost-reflect = { version = "0.16.0" } # wasm-related dependencies gloo-utils = "0.2.0" diff --git a/common/nyxd-scraper-psql/Cargo.toml b/common/nyxd-scraper-psql/Cargo.toml index 128096c275..0c2253cf9b 100644 --- a/common/nyxd-scraper-psql/Cargo.toml +++ b/common/nyxd-scraper-psql/Cargo.toml @@ -13,8 +13,8 @@ readme.workspace = true [dependencies] async-trait = { workspace = true } base64 = { workspace = true } +itertools = { workspace = true } serde = { workspace = true, features = ["derive"] } -prost-reflect = { workspace = true } serde_json = { workspace = true } sqlx = { workspace = true, features = ["runtime-tokio-rustls", "postgres", "macros", "migrate", "time"] } thiserror = { workspace = true } diff --git a/common/nyxd-scraper-psql/src/storage/helpers.rs b/common/nyxd-scraper-psql/src/storage/helpers.rs index 5561e57cb9..a71adf2191 100644 --- a/common/nyxd-scraper-psql/src/storage/helpers.rs +++ b/common/nyxd-scraper-psql/src/storage/helpers.rs @@ -1,7 +1,11 @@ // Copyright 2025 - Nym Technologies SA // SPDX-License-Identifier: Apache-2.0 +use cosmrs::AccountId; +use itertools::Itertools; +use nyxd_scraper_shared::ParsedTransactionResponse; use serde::Serialize; +use std::str::FromStr; #[derive(Serialize)] pub(crate) struct PlaceholderStruct { @@ -17,3 +21,21 @@ impl PlaceholderStruct { } } } + +// replicate behaviour of `CosmosMessageAddressesParser` from juno +pub(crate) fn parse_addresses_from_events(tx: &ParsedTransactionResponse) -> Vec { + let mut addresses: Vec = Vec::new(); + for event in &tx.tx_result.events { + for attribute in &event.attributes { + let Ok(value) = attribute.value_str() else { + continue; + }; + + // Try parsing the address as an account address + if let Ok(address) = AccountId::from_str(value) { + addresses.push(address.to_string()); + } + } + } + addresses.into_iter().unique().collect() +} diff --git a/common/nyxd-scraper-psql/src/storage/transaction.rs b/common/nyxd-scraper-psql/src/storage/transaction.rs index f7774703d4..a95709f6f1 100644 --- a/common/nyxd-scraper-psql/src/storage/transaction.rs +++ b/common/nyxd-scraper-psql/src/storage/transaction.rs @@ -2,7 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 use crate::error::PostgresScraperError; -use crate::storage::helpers::PlaceholderStruct; +use crate::storage::helpers::{parse_addresses_from_events, PlaceholderStruct}; use crate::storage::manager::{ insert_block, insert_message, insert_precommit, insert_transaction, insert_validator, }; @@ -209,13 +209,14 @@ impl PostgresStorageTransaction { debug!("persisting messages"); for chain_tx in txs { + let involved_addresses = parse_addresses_from_events(chain_tx); for (index, msg) in chain_tx.tx.body.messages.iter().enumerate() { insert_message( chain_tx.hash.to_string(), index as i64, msg.type_url.clone(), serde_json::to_value(self.decode_or_skip(msg))?, - vec!["PLACEHOLDER".to_owned()], + involved_addresses.clone(), chain_tx.height.into(), self.inner.as_mut(), )