Skip to content

Commit

Permalink
wip parsing json file to tx
Browse files Browse the repository at this point in the history
  • Loading branch information
0o-de-lally committed Nov 23, 2024
1 parent 388dc78 commit 04ec1fe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
26 changes: 22 additions & 4 deletions src/json_rescue_v5_extract.rs
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -12,10 +13,27 @@ use std::path::Path;
pub fn extract_v5_json_rescue(
one_json_file: &Path,
) -> Result<(Vec<WarehouseTxMaster>, Vec<WarehouseEvent>)> {
dbg!(&one_json_file);
// dbg!(&one_json_file);
let json = std::fs::read_to_string(one_json_file)?;

let txs: Vec<TransactionViewV5> = 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))
}
5 changes: 4 additions & 1 deletion tests/test_parse_json_rescue_v5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

0 comments on commit 04ec1fe

Please sign in to comment.