From 04ec1fe28491a1c68190813459154f741ff0cb70 Mon Sep 17 00:00:00 2001 From: 0o-de-lally <1364012+0o-de-lally@users.noreply.github.com> Date: Sat, 23 Nov 2024 16:11:05 -0500 Subject: [PATCH] wip parsing json file to tx --- src/json_rescue_v5_extract.rs | 26 ++++++++++++++++++++++---- tests/test_parse_json_rescue_v5.rs | 5 ++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/json_rescue_v5_extract.rs b/src/json_rescue_v5_extract.rs index 07f6a17..306e5d3 100644 --- a/src/json_rescue_v5_extract.rs +++ b/src/json_rescue_v5_extract.rs @@ -1,8 +1,9 @@ use crate::{ - json_rescue_v5_compat::TransactionViewV5, + json_rescue_v5_compat::{TransactionDataView, TransactionViewV5}, schema_transaction::{WarehouseEvent, WarehouseTxMaster}, }; use anyhow::Result; +use diem_types::account_address::AccountAddress; use std::path::Path; /// The canonical transaction archives for V5 were kept in a different format as in v6 and v7. @@ -12,10 +13,27 @@ use std::path::Path; pub fn extract_v5_json_rescue( one_json_file: &Path, ) -> Result<(Vec, Vec)> { - dbg!(&one_json_file); + // dbg!(&one_json_file); let json = std::fs::read_to_string(one_json_file)?; let txs: Vec = serde_json::from_str(&json)?; - dbg!(&txs); - todo!() + // dbg!(&txs); + + let mut tx_vec = vec![]; + let event_vec = vec![]; + + for t in txs { + let mut wtxs = WarehouseTxMaster::default(); + match t.transaction { + TransactionDataView::UserTransaction { + sender, .. + } => { + wtxs.sender = AccountAddress::from_hex_literal(&sender.to_hex_literal())?; + tx_vec.push(wtxs); + } + _ => {} + } + } + + Ok((tx_vec, event_vec)) } diff --git a/tests/test_parse_json_rescue_v5.rs b/tests/test_parse_json_rescue_v5.rs index aeabd92..411a915 100644 --- a/tests/test_parse_json_rescue_v5.rs +++ b/tests/test_parse_json_rescue_v5.rs @@ -21,7 +21,10 @@ fn test_rescue_v5_parse() -> anyhow::Result<()> { fn test_extract_v5_json_from_file() -> anyhow::Result<()> { let p = fixtures::v5_json_tx_path().join("example_user_tx.json"); - let r = extract_v5_json_rescue(&p)?; + let (tx, _) = extract_v5_json_rescue(&p)?; + let first = tx.first().unwrap(); + dbg!(&tx); + assert!(first.sender.to_hex_literal() == "0xc8336044cdf1878d9738ed0a041b235e"); Ok(()) }