Skip to content

Commit

Permalink
chore: cleanup after rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
polachok committed Jan 29, 2024
1 parent d694414 commit 08a9cdf
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 74 deletions.
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.

2 changes: 0 additions & 2 deletions common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
pub use ethnum;
pub use evm_loader;
pub mod types;

// ===== Reexports =====
Expand Down
3 changes: 1 addition & 2 deletions parse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ edition = "2021"
[dependencies]
thiserror = "1"
base64 = "0.21"
solana-transaction-status = "1.16"
solana-sdk = "1.16"
tracing = "0.1"
hex = "0.4"

Expand All @@ -19,3 +17,4 @@ common = { path = "../common", package = "neon-proxy-common" }
solana-rpc-client = "1.16"
test-log = { version = "0.2", default-features = false, features = ["trace"] }
serde_json = "1"
serde = { version = "1", features = ["derive"] }
77 changes: 9 additions & 68 deletions parse/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use common::types::NeonTxInfo;
use solana_sdk::signature::Signature;
use solana_transaction_status::option_serializer::OptionSerializer;
use solana_transaction_status::EncodedConfirmedTransactionWithStatusMeta;
use thiserror::Error;

use common::solana_sdk::signature::Signature;
use common::types::{NeonTxInfo, SolanaTransaction};

mod log;
mod transaction;

Expand All @@ -30,13 +29,8 @@ struct SolTxMetaInfo {
pub ident: SolTxSigSlotInfo,
}

pub fn parse(
transaction: EncodedConfirmedTransactionWithStatusMeta,
) -> Result<Vec<NeonTxInfo>, Error> {
let EncodedConfirmedTransactionWithStatusMeta {
slot, transaction, ..
} = transaction;
let tx = transaction.transaction.decode().ok_or(Error::Solana)?;
pub fn parse(transaction: SolanaTransaction) -> Result<Vec<NeonTxInfo>, Error> {
let SolanaTransaction { slot, tx, .. } = transaction;
let sig_slot_info = SolTxSigSlotInfo {
signature: tx.signatures[0],
block_slot: slot,
Expand All @@ -48,63 +42,10 @@ pub fn parse(
let neon_tx = transaction::parse(&ix.data)?;
tracing::info!("neon tx {:?}", neon_tx);
}
let _log_info = if let Some(OptionSerializer::Some(msgs)) =
transaction.meta.map(|meta| meta.log_messages)
{
match log::parse(msgs) {
Ok(log) => log,
Err(err) => panic!("log parsing error {:?}", err),
}
} else {
todo!("no logs?")
let log_info = match log::parse(transaction.log_messages) {
Ok(log) => log,
Err(err) => panic!("log parsing error {:?}", err),
};
tracing::info!("log info {:?}", _log_info);
tracing::info!("log info {:?}", log_info);
Ok(Vec::new())
}

#[cfg(test)]
mod tests {
use solana_rpc_client::rpc_client::RpcClient;
use solana_sdk::signature::Signature;
use solana_transaction_status::UiTransactionEncoding;

use super::*;
use std::str::FromStr;
use test_log::test;

// use this to retrieve some transaction from network and store it locally
#[allow(unused)]
fn get_transaction_net(signature: &str) -> EncodedConfirmedTransactionWithStatusMeta {
use std::path::PathBuf;
let client = RpcClient::new("https://api.mainnet-beta.solana.com".to_string());
let signature = Signature::from_str(signature).unwrap();
let tx = client
.get_transaction(&signature, UiTransactionEncoding::Base64)
.unwrap();
let mut path = PathBuf::from_str("./tests/data").unwrap();
path.push(format!("{}.json", signature));
std::fs::write(path, serde_json::to_vec(&tx).unwrap()).unwrap();
tx
}

fn get_transaction(signature: &str) -> EncodedConfirmedTransactionWithStatusMeta {
use std::path::PathBuf;
let mut path = PathBuf::from_str("./tests/data").unwrap();
path.push(format!("{}.json", signature));
let buf = std::fs::read_to_string(&path).unwrap();
let tx: EncodedConfirmedTransactionWithStatusMeta = serde_json::from_str(&buf).unwrap();
tx
}

#[test]
pub fn parse_4y() {
let tx = get_transaction("4YcHMcHwXkpqTfuqafaJigL9SKoYcRhUD9LimTHKjbkhJeLSpdjdsJCirjTqrM7VZC4RBrDJZdrjW5ZAUbqHqhq5");
parse(tx).unwrap();
}

#[test]
pub fn parse_2y() {
let tx = get_transaction("2yUjfHPDAEiMnZPFgj4YgEMa9yQ91zjoCx82i6JuZpnWJjXS3UMKNHnvZCCsjdicg5nfTq2CCUfvcpQkiKL6yCss");
parse(tx).unwrap();
}
}
31 changes: 31 additions & 0 deletions parse/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,34 @@ pub fn parse(lines: impl IntoIterator<Item = impl AsRef<str>>) -> Result<NeonLog
};
Ok(log_info)
}

#[cfg(test)]
mod tests {
use serde::Deserialize;
use test_log::test;

#[derive(Debug, Deserialize)]
struct Meta {
#[serde(rename = "logMessages")]
log_messages: Vec<String>,
}

#[derive(Debug, Deserialize)]
struct DumbTx {
meta: Meta,
}

#[test]
fn parse_logs() {
let path = "tests/data/";
for entry in std::fs::read_dir(path).unwrap() {
let entry = entry.unwrap();
if entry.metadata().unwrap().is_file() {
let buf = std::fs::read(entry.path()).unwrap();
let tx: DumbTx = serde_json::from_slice(&buf).unwrap();
println!("Parsing: {:?}", entry.path());
super::parse(tx.meta.log_messages).unwrap();
}
}
}
}

0 comments on commit 08a9cdf

Please sign in to comment.