Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions contracts/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 16 additions & 16 deletions nym-wallet/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions nyx-chain-watcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[package]
name = "nyx-chain-watcher"
version = "0.1.12"
version = "0.1.13"
authors.workspace = true
repository.workspace = true
homepage.workspace = true
Expand All @@ -29,7 +29,6 @@ nym-node-requests = { path = "../nym-node/nym-node-requests", features = [
nym-validator-client = { path = "../common/client-libs/validator-client" }
nyxd-scraper = { path = "../common/nyxd-scraper" }
reqwest = { workspace = true, features = ["rustls-tls"] }
rocket = { workspace = true }
schemars = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
Expand Down
28 changes: 12 additions & 16 deletions nyx-chain-watcher/src/chain_scraper/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::config::PaymentWatcherConfig;
use crate::config::PaymentWatchersConfig;
use crate::env::vars::{
NYXD_SCRAPER_START_HEIGHT, NYXD_SCRAPER_UNSAFE_NUKE_DB,
NYXD_SCRAPER_USE_BEST_EFFORT_START_HEIGHT,
Expand All @@ -10,7 +10,7 @@ use nyxd_scraper::{
};
use sqlx::SqlitePool;
use std::fs;
use tracing::{info, warn};
use tracing::{error, info, warn};

pub(crate) async fn run_chain_scraper(
config: &crate::config::Config,
Expand Down Expand Up @@ -60,7 +60,7 @@ pub(crate) async fn run_chain_scraper(
})
.with_tx_module(EventScraperModule::new(
db_pool,
config.payment_watcher_config.clone().unwrap_or_default(),
config.payment_watcher_config.clone(),
));

let instance = scraper.build_and_start().await?;
Expand All @@ -73,11 +73,11 @@ pub(crate) async fn run_chain_scraper(

pub struct EventScraperModule {
db_pool: SqlitePool,
payment_config: PaymentWatcherConfig,
payment_config: PaymentWatchersConfig,
}

impl EventScraperModule {
pub fn new(db_pool: SqlitePool, payment_config: PaymentWatcherConfig) -> Self {
pub fn new(db_pool: SqlitePool, payment_config: PaymentWatchersConfig) -> Self {
Self {
db_pool,
payment_config,
Expand Down Expand Up @@ -132,6 +132,12 @@ impl TxModule for EventScraperModule {
return Ok(());
}

if tx.tx.body.messages.len() > 1 {
error!(
"this transaction has more than 1 message in it - payment information will be lost"
);
}

// Process each event
for event in events {
// Only process transfer events
Expand All @@ -157,17 +163,7 @@ impl TxModule for EventScraperModule {
// If we have all required fields, check if recipient is watched and store
if let (Some(recipient), Some(sender), Some(amount)) = (recipient, sender, amount) {
// Check if any watcher is watching this recipient
let is_watched = self.payment_config.watchers.iter().any(|watcher| {
if let Some(watched_accounts) =
&watcher.watch_for_transfer_recipient_accounts
{
watched_accounts
.iter()
.any(|account| account.to_string() == recipient)
} else {
false
}
});
let is_watched = self.payment_config.is_being_watched(&recipient);

if is_watched {
if let Err(e) = self
Expand Down
16 changes: 8 additions & 8 deletions nyx-chain-watcher/src/cli/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

use crate::cli::DEFAULT_NYX_CHAIN_WATCHER_ID;
use crate::config::payments_watcher::HttpAuthenticationOptions::AuthorizationBearerToken;
use crate::config::payments_watcher::PaymentWatcherEntry;
use crate::config::{default_config_filepath, Config, ConfigBuilder, PaymentWatcherConfig};
use crate::config::payments_watcher::PaymentWatcherConfig;
use crate::config::{default_config_filepath, Config, ConfigBuilder, PaymentWatchersConfig};
use crate::error::NyxChainWatcherError;
use nym_config::save_unformatted_config_to_file;
use nym_validator_client::nyxd::AccountId;
Expand All @@ -18,22 +18,22 @@ pub(crate) async fn execute(_args: Args) -> Result<(), NyxChainWatcherError> {
let data_dir = Config::default_data_directory(&config_path)?;

let builder = ConfigBuilder::new(config_path.clone(), data_dir).with_payment_watcher_config(
PaymentWatcherConfig {
watchers: vec![PaymentWatcherEntry {
PaymentWatchersConfig {
watchers: vec![PaymentWatcherConfig {
id: DEFAULT_NYX_CHAIN_WATCHER_ID.to_string(),
webhook_url: "https://webhook.site".to_string(),
watch_for_transfer_recipient_accounts: Some(vec![AccountId::from_str(
watch_for_transfer_recipient_accounts: vec![AccountId::from_str(
"n17g9a2pwwkg8m60wf59pq6mv0c2wusg9ukparkz",
)
.unwrap()]),
.unwrap()],
authentication: Some(AuthorizationBearerToken {
token: "1234".to_string(),
}),
description: None,
watch_for_chain_message_types: Some(vec![
watch_for_chain_message_types: vec![
"/cosmos.bank.v1beta1.MsgSend".to_string(),
"/ibc.applications.transfer.v1.MsgTransfer".to_string(),
]),
],
}],
},
);
Expand Down
4 changes: 2 additions & 2 deletions nyx-chain-watcher/src/cli/commands/run/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ pub(crate) struct Args {
value_delimiter = ',',
env = NYX_CHAIN_WATCHER_WATCH_ACCOUNTS
)]
pub watch_for_transfer_recipient_accounts: Option<Vec<AccountId>>,
pub watch_for_transfer_recipient_accounts: Vec<AccountId>,

/// (Override) Watch for chain messages of these types
#[clap(
long,
value_delimiter = ',',
env = NYX_CHAIN_WATCHER_WATCH_CHAIN_MESSAGE_TYPES
)]
pub watch_for_chain_message_types: Option<Vec<String>>,
pub watch_for_chain_message_types: Vec<String>,

/// (Override) The webhook to call when we find something
#[clap(
Expand Down
18 changes: 9 additions & 9 deletions nyx-chain-watcher/src/cli/commands/run/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::cli::commands::run::args::Args;
use crate::cli::DEFAULT_NYX_CHAIN_WATCHER_ID;
use crate::config::payments_watcher::{HttpAuthenticationOptions, PaymentWatcherEntry};
use crate::config::{default_config_filepath, Config, ConfigBuilder, PaymentWatcherConfig};
use crate::config::payments_watcher::{HttpAuthenticationOptions, PaymentWatcherConfig};
use crate::config::{default_config_filepath, Config, ConfigBuilder, PaymentWatchersConfig};
use crate::error::NyxChainWatcherError;
use tracing::{info, warn};

Expand All @@ -18,21 +18,21 @@ pub(crate) fn get_run_config(args: Args) -> Result<Config, NyxChainWatcherError>
} = args;

// if there are no args set, then try load the config
if args.watch_for_transfer_recipient_accounts.is_none()
&& args.watch_for_transfer_recipient_accounts.is_none()
if args.watch_for_transfer_recipient_accounts.is_empty()
&& args.watch_for_transfer_recipient_accounts.is_empty()
&& args.chain_watcher_db_path.is_none()
{
info!("Loading default config file...");
return Config::read_from_toml_file_in_default_location();
}

// set default messages
if watch_for_chain_message_types.is_none() {
watch_for_chain_message_types = Some(vec!["/cosmos.bank.v1beta1.MsgSend".to_string()]);
if watch_for_chain_message_types.is_empty() {
watch_for_chain_message_types = vec!["/cosmos.bank.v1beta1.MsgSend".to_string()];
}

// warn if no accounts set
if watch_for_transfer_recipient_accounts.is_none() {
if watch_for_transfer_recipient_accounts.is_empty() {
warn!(
"You did not specify any accounts to watch in {}. Only chain data will be stored.",
crate::env::vars::NYX_CHAIN_WATCHER_WATCH_ACCOUNTS
Expand All @@ -58,8 +58,8 @@ pub(crate) fn get_run_config(args: Args) -> Result<Config, NyxChainWatcherError>
let authentication =
webhook_auth.map(|token| HttpAuthenticationOptions::AuthorizationBearerToken { token });

let watcher_config = PaymentWatcherConfig {
watchers: vec![PaymentWatcherEntry {
let watcher_config = PaymentWatchersConfig {
watchers: vec![PaymentWatcherConfig {
id: DEFAULT_NYX_CHAIN_WATCHER_ID.to_string(),
description: None,
watch_for_transfer_recipient_accounts: watch_for_transfer_recipient_accounts
Expand Down
Loading
Loading