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
2,677 changes: 2,117 additions & 560 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 11 additions & 13 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "openzeppelin-monitor"
version = "1.1.0"
edition = "2021"
rust-version = "1.86" #MSRV
rust-version = "1.90" #MSRV

[profile.release]
opt-level = 0
Expand All @@ -15,14 +15,6 @@ opt-level = 0
overflow-checks = true
panic = 'unwind'

[patch."https://github.com/input-output-hk/midnight-ledger-prototype"]
mn-ledger-storage = { git = "https://github.com/midnightntwrk/midnight-ledger-prototype", package = "midnight-storage", tag = "ledger-4.0.0" }
coin-structure = { git = "https://github.com/midnightntwrk/midnight-ledger-prototype", package = "midnight-coin-structure", tag = "ledger-4.0.0" }
onchain-runtime = { git = "https://github.com/midnightntwrk/midnight-ledger-prototype", package = "midnight-onchain-runtime", tag = "ledger-4.0.0" }
midnight-serialize = { git = "https://github.com/midnightntwrk/midnight-ledger-prototype", tag = "ledger-4.0.0" }
base-crypto = { git = "https://github.com/midnightntwrk/midnight-ledger-prototype", package = "midnight-base-crypto", tag = "ledger-4.0.0" }
transient-crypto = { git = "https://github.com/midnightntwrk/midnight-ledger-prototype", package = "midnight-transient-crypto", tag = "ledger-4.0.0" }

[dependencies]
actix-rt = "2.2.0"
actix-web = "4"
Expand All @@ -48,14 +40,20 @@ lazy_static = "1.5"
lettre = { version = "0.11.11", features = ["tokio1", "tokio1-native-tls"] }
libc = "0.2"
log = "0.4"
midnight-ledger = { git = "https://github.com/midnightntwrk/midnight-ledger-prototype", package = "midnight-ledger", tag = "ledger-4.0.0" }
midnight-node-ledger = { git = "https://github.com/midnightntwrk/midnight-node", package = "midnight-node-ledger", tag = "node-0.12.0" }
midnight-node-ledger-helpers = { git = "https://github.com/midnightntwrk/midnight-node", package = "midnight-node-ledger-helpers", tag = "node-0.12.0" }
midnight-ledger = { git = "https://github.com/midnightntwrk/midnight-ledger", package = "midnight-ledger", tag = "ledger-6.1.0-alpha.3" }
midnight-base-crypto = { git = "https://github.com/midnightntwrk/midnight-ledger", package = "midnight-base-crypto", tag = "ledger-6.1.0-alpha.3" }
midnight-transient-crypto = { git = "https://github.com/midnightntwrk/midnight-ledger", package = "midnight-transient-crypto", tag = "ledger-6.1.0-alpha.3" }
midnight-storage = { git = "https://github.com/midnightntwrk/midnight-ledger", package = "midnight-storage", tag = "ledger-6.1.0-alpha.3" }
midnight-serialize = { git = "https://github.com/midnightntwrk/midnight-ledger", tag = "ledger-6.1.0-alpha.3" }
midnight-coin-structure = { git = "https://github.com/midnightntwrk/midnight-ledger", package = "midnight-coin-structure", tag = "ledger-6.1.0-alpha.3" }
midnight-zswap = { git = "https://github.com/midnightntwrk/midnight-ledger", package = "midnight-zswap", tag = "ledger-6.1.0-alpha.3" }
midnight-node-ledger = { git = "https://github.com/midnightntwrk/midnight-node", package = "midnight-node-ledger", tag = "node-0.17.0-rc.4" }
midnight-node-ledger-helpers = { git = "https://github.com/midnightntwrk/midnight-node", package = "midnight-node-ledger-helpers", tag = "node-0.17.0-rc.4" }
oz-keystore = "0.1.4"
prometheus = "0.14"
pulldown-cmark = "0.13.0"
regex = "1.11.0"
reqwest = { version = "=0.12.15", features = ["json"] }
reqwest = { version = "0.12.24", features = ["json"] }
reqwest-middleware = { version = "0.4.1", features = ["json"] }
reqwest-retry = "0.7.0"
rust_decimal = "1.37.1"
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
channel = "1.86.0"
channel = "1.90.0"
profile = "minimal"
components = [
"rustc",
Expand Down
73 changes: 39 additions & 34 deletions src/models/blockchain/midnight/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
//! <https://github.com/midnightntwrk/midnight-node/blob/39dbdf54afc5f0be7e7913b387637ac52d0c50f2/pallets/midnight/rpc/src/lib.rs>

use alloy::hex::ToHexExt;
use midnight_ledger::structure::{
ContractAction, Proof, Proofish, Transaction as MidnightNodeTransaction,
};
use midnight_ledger::structure::{ContractAction, Transaction as MidnightNodeTransaction};

use midnight_node_ledger_helpers::DB;
use midnight_storage::DefaultDB;

use serde::{Deserialize, Serialize};
use std::ops::Deref;
Expand Down Expand Up @@ -216,7 +214,9 @@ impl From<Transaction> for MidnightRpcTransaction {
}
}

impl<P: Proofish<D>, D: DB> From<ContractAction<P, D>> for Operation {
impl<P: midnight_ledger::structure::ProofKind<D>, D: midnight_storage::db::DB>
From<ContractAction<P, D>> for Operation
{
/// Converts a ContractAction into an Operation
///
/// This implementation handles the conversion of different types of contract actions
Expand Down Expand Up @@ -244,32 +244,46 @@ impl<P: Proofish<D>, D: DB> From<ContractAction<P, D>> for Operation {
}
}

impl<D: DB>
impl Deref for Transaction {
type Target = MidnightRpcTransaction;

/// Dereferences the Transaction to access the underlying MidnightRpcTransaction
///
/// # Returns
/// A reference to the underlying MidnightRpcTransaction
fn deref(&self) -> &Self::Target {
&self.0
}
}

// Specific implementation for DefaultDB to match the actual usage
impl
TryFrom<(
Transaction,
Option<MidnightNodeTransaction<Proof, D>>,
Option<
MidnightNodeTransaction<
midnight_base_crypto::signatures::Signature,
(),
midnight_transient_crypto::commitment::Pedersen,
midnight_storage::DefaultDB,
>,
>,
&Vec<ChainConfiguration>,
)> for Transaction
{
type Error = anyhow::Error;

/// Attempts to create a Transaction from a tuple of transaction data and chain configuration
///
/// This implementation processes the transaction data and attempts to decrypt any coins
/// using the provided chain configuration's viewing keys.
///
/// # Arguments
/// * `(block_tx, ledger_tx, chain_configurations)` - A tuple containing:
/// - The block transaction
/// - An optional ledger transaction
/// - A reference to chain configurations
///
/// # Returns
/// * `Result<Self, Self::Error>` - The processed transaction or an error
fn try_from(
(block_tx, ledger_tx, chain_configurations): (
Transaction,
Option<MidnightNodeTransaction<Proof, D>>,
Option<
MidnightNodeTransaction<
midnight_base_crypto::signatures::Signature,
(),
midnight_transient_crypto::commitment::Pedersen,
midnight_storage::DefaultDB,
>,
>,
&Vec<ChainConfiguration>,
),
) -> Result<Self, Self::Error> {
Expand All @@ -281,7 +295,10 @@ impl<D: DB>
let viewing_key_str = secret.as_str();
if let Some(ref ledger_tx) = ledger_tx {
// TODO: Do something with the coins...
let _ = process_transaction_for_coins::<D>(viewing_key_str, ledger_tx);
let _ = process_transaction_for_coins::<DefaultDB>(
viewing_key_str,
ledger_tx,
);
}
}
}
Expand All @@ -292,18 +309,6 @@ impl<D: DB>
}
}

impl Deref for Transaction {
type Target = MidnightRpcTransaction;

/// Dereferences the Transaction to access the underlying MidnightRpcTransaction
///
/// # Returns
/// A reference to the underlying MidnightRpcTransaction
fn deref(&self) -> &Self::Target {
&self.0
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
1 change: 1 addition & 0 deletions src/models/blockchain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ impl BlockType {

/// Transaction data from different blockchain platforms
#[derive(Debug, Clone, Serialize, Deserialize)]
#[allow(clippy::large_enum_variant)]
pub enum TransactionType {
/// EVM transaction
EVM(evm::EVMTransaction),
Expand Down
14 changes: 7 additions & 7 deletions src/models/blockchain/stellar/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,13 +241,6 @@ pub struct ContractInput {
pub kind: String,
}

/// Stellar-specific configuration
///
/// This configuration is used to for additional fields in the monitor configuration
/// that are specific to Stellar.
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Default)]
pub struct MonitorConfig {}

/// Event parameter location (indexed or data)
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Default)]
pub enum EventParamLocation {
Expand Down Expand Up @@ -295,6 +288,13 @@ pub struct ContractEvent {
pub signature: String,
}

/// Stellar-specific configuration
///
/// This configuration is used to for additional fields in the monitor configuration
/// that are specific to Stellar.
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq, Default)]
pub struct MonitorConfig {}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
4 changes: 2 additions & 2 deletions src/models/config/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ mod tests {

#[test]
fn test_error_source_chain() {
let io_error = std::io::Error::new(std::io::ErrorKind::Other, "while reading config");
let io_error = std::io::Error::other("while reading config");

let outer_error =
ConfigError::file_error("Failed to initialize", Some(Box::new(io_error)), None);
Expand Down Expand Up @@ -199,7 +199,7 @@ mod tests {
assert_eq!(config_error.trace_id(), original_trace_id);

// Test trace ID propagation through error chain
let source_error = IoError::new(ErrorKind::Other, "Source error");
let source_error = IoError::other("Source error");
let error_context = ErrorContext::new("Middle error", Some(Box::new(source_error)), None);
let original_trace_id = error_context.trace_id.clone();

Expand Down
4 changes: 2 additions & 2 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub use blockchain::stellar::{
StellarBlock, StellarContractEvent, StellarContractEventParam, StellarContractFunction,
StellarContractInput, StellarContractSpec, StellarDecodedParamEntry, StellarDecodedTransaction,
StellarEvent, StellarEventParamLocation, StellarFormattedContractSpec, StellarLedgerInfo,
StellarMatchArguments, StellarMatchParamEntry, StellarMatchParamsMap, StellarMonitorMatch,
StellarParsedOperationResult, StellarTransaction, StellarTransactionInfo,
StellarMatchArguments, StellarMatchParamEntry, StellarMatchParamsMap, StellarMonitorConfig,
StellarMonitorMatch, StellarParsedOperationResult, StellarTransaction, StellarTransactionInfo,
};

pub use blockchain::midnight::{
Expand Down
4 changes: 2 additions & 2 deletions src/models/security/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ mod tests {

#[test]
fn test_error_source_chain() {
let io_error = std::io::Error::new(std::io::ErrorKind::Other, "while reading config");
let io_error = std::io::Error::other("while reading config");

let outer_error =
SecurityError::parse_error("Failed to initialize", Some(Box::new(io_error)), None);
Expand Down Expand Up @@ -201,7 +201,7 @@ mod tests {
assert_eq!(security_error.trace_id(), original_trace_id);

// Test trace ID propagation through error chain
let source_error = IoError::new(ErrorKind::Other, "Source error");
let source_error = IoError::other("Source error");
let error_context = ErrorContext::new("Middle error", Some(Box::new(source_error)), None);
let original_trace_id = error_context.trace_id.clone();

Expand Down
4 changes: 2 additions & 2 deletions src/repositories/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ mod tests {

#[test]
fn test_error_source_chain() {
let io_error = std::io::Error::new(std::io::ErrorKind::Other, "while reading config");
let io_error = std::io::Error::other("while reading config");

let outer_error =
RepositoryError::load_error("Failed to initialize", Some(Box::new(io_error)), None);
Expand Down Expand Up @@ -169,7 +169,7 @@ mod tests {
assert_eq!(repository_error.trace_id(), original_trace_id);

// Test trace ID propagation through error chain
let source_error = IoError::new(ErrorKind::Other, "Source error");
let source_error = IoError::other("Source error");
let error_context = ErrorContext::new("Middle error", Some(Box::new(source_error)), None);
let original_trace_id = error_context.trace_id.clone();

Expand Down
2 changes: 1 addition & 1 deletion src/services/blockchain/clients/stellar/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ mod tests {

#[test]
fn test_error_source_chain() {
let io_error = std::io::Error::new(std::io::ErrorKind::Other, "while reading config");
let io_error = std::io::Error::other("while reading config");

let outer_error =
StellarClientError::rpc_error("Failed to initialize", Some(Box::new(io_error)), None);
Expand Down
4 changes: 2 additions & 2 deletions src/services/blockchain/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ mod tests {

#[test]
fn test_error_source_chain() {
let io_error = std::io::Error::new(std::io::ErrorKind::Other, "while reading config");
let io_error = std::io::Error::other("while reading config");

let outer_error =
BlockChainError::request_error("Failed to initialize", Some(Box::new(io_error)), None);
Expand Down Expand Up @@ -258,7 +258,7 @@ mod tests {
assert_eq!(block_chain_error.trace_id(), original_trace_id);

// Test trace ID propagation through error chain
let source_error = IoError::new(ErrorKind::Other, "Source error");
let source_error = IoError::other("Source error");
let error_context = ErrorContext::new("Middle error", Some(Box::new(source_error)), None);
let original_trace_id = error_context.trace_id.clone();

Expand Down
4 changes: 2 additions & 2 deletions src/services/blockchain/transports/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ mod tests {

#[test]
fn test_error_source_chain() {
let io_error = std::io::Error::new(std::io::ErrorKind::Other, "while reading config");
let io_error = std::io::Error::other("while reading config");

let outer_error = TransportError::http(
reqwest::StatusCode::INTERNAL_SERVER_ERROR,
Expand Down Expand Up @@ -239,7 +239,7 @@ mod tests {
assert_eq!(transport_error.trace_id(), original_trace_id);

// Test trace ID propagation through error chain
let source_error = IoError::new(ErrorKind::Other, "Source error");
let source_error = IoError::other("Source error");
let error_context = ErrorContext::new("Middle error", Some(Box::new(source_error)), None);
let original_trace_id = error_context.trace_id.clone();

Expand Down
4 changes: 2 additions & 2 deletions src/services/blockwatcher/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ mod tests {

#[test]
fn test_error_source_chain() {
let io_error = std::io::Error::new(std::io::ErrorKind::Other, "while reading config");
let io_error = std::io::Error::other("while reading config");

let outer_error = BlockWatcherError::scheduler_error(
"Failed to initialize",
Expand Down Expand Up @@ -230,7 +230,7 @@ mod tests {
assert_eq!(block_watcher_error.trace_id(), original_trace_id);

// Test trace ID propagation through error chain
let source_error = IoError::new(ErrorKind::Other, "Source error");
let source_error = IoError::other("Source error");
let error_context = ErrorContext::new("Middle error", Some(Box::new(source_error)), None);
let original_trace_id = error_context.trace_id.clone();

Expand Down
4 changes: 2 additions & 2 deletions src/services/filter/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ mod tests {

#[test]
fn test_error_source_chain() {
let io_error = std::io::Error::new(std::io::ErrorKind::Other, "while reading config");
let io_error = std::io::Error::other("while reading config");

let outer_error = FilterError::block_type_mismatch(
"Failed to initialize",
Expand Down Expand Up @@ -171,7 +171,7 @@ mod tests {
assert_eq!(filter_error.trace_id(), original_trace_id);

// Test trace ID propagation through error chain
let source_error = IoError::new(ErrorKind::Other, "Source error");
let source_error = IoError::other("Source error");
let error_context = ErrorContext::new("Middle error", Some(Box::new(source_error)), None);
let original_trace_id = error_context.trace_id.clone();

Expand Down
2 changes: 1 addition & 1 deletion src/services/filter/expression/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<'a> ConditionLeft<'a> {
/// If ConditionLeft is a simple variable, it returns an empty slice.
/// If it is a path, it returns the accessors of that path.
/// Used during evaluation to traverse nested structures.
pub fn accessors(&self) -> &[Accessor] {
pub fn accessors(&self) -> &[Accessor<'a>] {
match self {
ConditionLeft::Simple(_) => &[],
ConditionLeft::Path(path) => &path.accessors,
Expand Down
2 changes: 1 addition & 1 deletion src/services/filter/filters/evm/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1811,7 +1811,7 @@ mod tests {
.build();

filter.find_matching_functions_for_transaction(
&[contract_with_spec.clone()],
std::slice::from_ref(&contract_with_spec),
&transaction,
&monitor,
&mut matched_functions,
Expand Down
3 changes: 1 addition & 2 deletions src/services/filter/filters/midnight/filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#![allow(clippy::result_large_err)]

use async_trait::async_trait;
use midnight_ledger::structure::Proof;
use midnight_node_ledger_helpers::NetworkId;
use std::marker::PhantomData;
use tracing::instrument;
Expand Down Expand Up @@ -221,7 +220,7 @@ impl<T> MidnightBlockFilter<T> {

let transaction = MidnightTransaction::from(tx.clone());
let (_hash, deserialized_ledger_transaction) =
match parse_tx_index_item::<Proof>(&hash, &raw_tx_data, network_id) {
match parse_tx_index_item(&hash, &raw_tx_data, network_id) {
Ok(res) => res,
Err(e) => {
return Err(FilterError::network_error(
Expand Down
Loading