diff --git a/src/json_rescue_v5_extract.rs b/src/json_rescue_v5_extract.rs index 78866c2..0c971ed 100644 --- a/src/json_rescue_v5_extract.rs +++ b/src/json_rescue_v5_extract.rs @@ -54,7 +54,7 @@ pub fn extract_v5_json_rescue( } decode_transaction_args(&mut wtxs, &t.bytes)?; - + dbg!(&wtxs); // TODO: // wtxs.events // TODO: @@ -62,7 +62,7 @@ pub fn extract_v5_json_rescue( // TODO: create arg to exclude tx without counter party match &wtxs.relation_label { - RelationLabel::Tx => {} + RelationLabel::Unknown => {} RelationLabel::Transfer(_) => tx_vec.push(wtxs), RelationLabel::Onboarding(_) => tx_vec.push(wtxs), RelationLabel::Vouch(_) => tx_vec.push(wtxs), @@ -88,7 +88,7 @@ pub fn extract_v5_json_rescue( _ => {} } } - + dbg!(&tx_vec); Ok((tx_vec, event_vec, unique_functions)) } @@ -103,115 +103,133 @@ pub fn decode_transaction_args(wtx: &mut WarehouseTxMaster, tx_bytes: &[u8]) -> })?; if let TransactionV5::UserTransaction(u) = &t { + // check this is actually a ScriptFunction if let TransactionPayload::ScriptFunction(_) = &u.raw_txn.payload { - if let Some(sf) = &ScriptFunctionCallGenesis::decode(&u.raw_txn.payload) { - wtx.entry_function = Some(EntryFunctionArgs::V5(sf.to_owned())); - // TODO: some script functions have very large payloads which clog the e.g. Miner. So those are only added for the catch-all txs which don't fall into categories we are interested in. - match sf { - ScriptFunctionCallGenesis::BalanceTransfer { destination, .. } => { - wtx.relation_label = - RelationLabel::Transfer(cast_legacy_account(destination)?); + maybe_decode_v5_genesis_function(wtx, &u.raw_txn.payload)?; + // if still unknown TX try again with v5.2.0 + if let RelationLabel::Unknown = wtx.relation_label { + maybe_decode_v520_function(wtx, &u.raw_txn.payload)?; + } + } + } + Ok(()) +} - wtx.entry_function = Some(EntryFunctionArgs::V5(sf.to_owned())); - } - ScriptFunctionCallGenesis::AutopayCreateInstruction { payee, .. } => { - wtx.relation_label = RelationLabel::Transfer(cast_legacy_account(payee)?); - wtx.entry_function = Some(EntryFunctionArgs::V5(sf.to_owned())); - } - ScriptFunctionCallGenesis::CreateAccUser { .. } => { - // onboards self - wtx.relation_label = RelationLabel::Onboarding(wtx.sender); - } - ScriptFunctionCallGenesis::CreateAccVal { .. } => { - // onboards self - wtx.relation_label = RelationLabel::Onboarding(wtx.sender); - } +fn maybe_decode_v5_genesis_function( + wtx: &mut WarehouseTxMaster, + payload: &TransactionPayload, +) -> Result<()> { + if let Some(sf) = &ScriptFunctionCallGenesis::decode(payload) { + dbg!(&sf); + wtx.entry_function = Some(EntryFunctionArgs::V5(sf.to_owned())); + // TODO: some script functions have very large payloads which clog the e.g. Miner. So those are only added for the catch-all txs which don't fall into categories we are interested in. + match sf { + ScriptFunctionCallGenesis::BalanceTransfer { destination, .. } => { + wtx.relation_label = RelationLabel::Transfer(cast_legacy_account(destination)?); - ScriptFunctionCallGenesis::CreateUserByCoinTx { account, .. } => { - wtx.relation_label = - RelationLabel::Onboarding(cast_legacy_account(account)?); - } - ScriptFunctionCallGenesis::CreateValidatorAccount { - sliding_nonce: _, - new_account_address, - .. - } => { - wtx.relation_label = - RelationLabel::Onboarding(cast_legacy_account(new_account_address)?); - } - ScriptFunctionCallGenesis::CreateValidatorOperatorAccount { - sliding_nonce: _, - new_account_address, - .. - } => { - wtx.relation_label = - RelationLabel::Onboarding(cast_legacy_account(new_account_address)?); - } + wtx.entry_function = Some(EntryFunctionArgs::V5(sf.to_owned())); + } + ScriptFunctionCallGenesis::AutopayCreateInstruction { payee, .. } => { + wtx.relation_label = RelationLabel::Transfer(cast_legacy_account(payee)?); + wtx.entry_function = Some(EntryFunctionArgs::V5(sf.to_owned())); + } + ScriptFunctionCallGenesis::CreateAccUser { .. } => { + // onboards self + wtx.relation_label = RelationLabel::Onboarding(wtx.sender); + } + ScriptFunctionCallGenesis::CreateAccVal { .. } => { + // onboards self + wtx.relation_label = RelationLabel::Onboarding(wtx.sender); + } - ScriptFunctionCallGenesis::MinerstateCommit { .. } => { - wtx.relation_label = RelationLabel::Miner; - } - ScriptFunctionCallGenesis::MinerstateCommitByOperator { .. } => { - wtx.relation_label = RelationLabel::Miner; - } - _ => { - wtx.relation_label = RelationLabel::Configuration; + ScriptFunctionCallGenesis::CreateUserByCoinTx { account, .. } => { + dbg!(&account); + wtx.relation_label = RelationLabel::Onboarding(cast_legacy_account(account)?); + } + ScriptFunctionCallGenesis::CreateValidatorAccount { + sliding_nonce: _, + new_account_address, + .. + } => { + wtx.relation_label = + RelationLabel::Onboarding(cast_legacy_account(new_account_address)?); + } + ScriptFunctionCallGenesis::CreateValidatorOperatorAccount { + sliding_nonce: _, + new_account_address, + .. + } => { + wtx.relation_label = + RelationLabel::Onboarding(cast_legacy_account(new_account_address)?); + } - wtx.entry_function = Some(EntryFunctionArgs::V5(sf.to_owned())); - } - } + ScriptFunctionCallGenesis::MinerstateCommit { .. } => { + wtx.relation_label = RelationLabel::Miner; } + ScriptFunctionCallGenesis::MinerstateCommitByOperator { .. } => { + wtx.relation_label = RelationLabel::Miner; + } + _ => { + wtx.relation_label = RelationLabel::Unknown; - if let Some(sf) = &ScriptFunctionCallV520::decode(&u.raw_txn.payload) { - wtx.entry_function = Some(EntryFunctionArgs::V520(sf.to_owned())); + wtx.entry_function = Some(EntryFunctionArgs::V5(sf.to_owned())); + } + } + } + Ok(()) +} - match sf { - ScriptFunctionCallV520::BalanceTransfer { destination, .. } => { - wtx.relation_label = - RelationLabel::Transfer(cast_legacy_account(destination)?); +fn maybe_decode_v520_function( + wtx: &mut WarehouseTxMaster, + payload: &TransactionPayload, +) -> Result<()> { + if let Some(sf) = &ScriptFunctionCallV520::decode(payload) { + wtx.entry_function = Some(EntryFunctionArgs::V520(sf.to_owned())); + match sf { + // NOTE: This balanceTransfer likely de/encodes to the same + // bytes as v5 genesis + ScriptFunctionCallV520::BalanceTransfer { destination, .. } => { + wtx.relation_label = RelationLabel::Transfer(cast_legacy_account(destination)?); - wtx.entry_function = Some(EntryFunctionArgs::V520(sf.to_owned())); - } - ScriptFunctionCallV520::CreateAccUser { .. } => { - wtx.relation_label = RelationLabel::Onboarding(wtx.sender); - } - ScriptFunctionCallV520::CreateAccVal { .. } => { - wtx.relation_label = RelationLabel::Onboarding(wtx.sender); - } + wtx.entry_function = Some(EntryFunctionArgs::V520(sf.to_owned())); + } + ScriptFunctionCallV520::CreateAccUser { .. } => { + wtx.relation_label = RelationLabel::Onboarding(wtx.sender); + } + ScriptFunctionCallV520::CreateAccVal { .. } => { + wtx.relation_label = RelationLabel::Onboarding(wtx.sender); + } - ScriptFunctionCallV520::CreateValidatorAccount { - sliding_nonce: _, - new_account_address, - .. - } => { - wtx.relation_label = - RelationLabel::Onboarding(cast_legacy_account(new_account_address)?); - } - ScriptFunctionCallV520::CreateValidatorOperatorAccount { - sliding_nonce: _, - new_account_address, - .. - } => { - wtx.relation_label = - RelationLabel::Onboarding(cast_legacy_account(new_account_address)?); - } - ScriptFunctionCallV520::MinerstateCommit { .. } => { - wtx.relation_label = RelationLabel::Miner; - } - ScriptFunctionCallV520::MinerstateCommitByOperator { .. } => { - wtx.relation_label = RelationLabel::Miner; - } - _ => { - wtx.relation_label = RelationLabel::Configuration; - wtx.entry_function = Some(EntryFunctionArgs::V520(sf.to_owned())); - } - } + ScriptFunctionCallV520::CreateValidatorAccount { + sliding_nonce: _, + new_account_address, + .. + } => { + wtx.relation_label = + RelationLabel::Onboarding(cast_legacy_account(new_account_address)?); + } + ScriptFunctionCallV520::CreateValidatorOperatorAccount { + sliding_nonce: _, + new_account_address, + .. + } => { + wtx.relation_label = + RelationLabel::Onboarding(cast_legacy_account(new_account_address)?); + } + ScriptFunctionCallV520::MinerstateCommit { .. } => { + wtx.relation_label = RelationLabel::Miner; + } + ScriptFunctionCallV520::MinerstateCommitByOperator { .. } => { + wtx.relation_label = RelationLabel::Miner; + } + _ => { + wtx.relation_label = RelationLabel::Unknown; + wtx.entry_function = Some(EntryFunctionArgs::V520(sf.to_owned())); } } } Ok(()) } - /// from a tgz file unwrap to temp path /// NOTE: we return the Temppath object for the directory /// for the enclosing function to handle diff --git a/src/schema_transaction.rs b/src/schema_transaction.rs index e511264..3e62a4c 100644 --- a/src/schema_transaction.rs +++ b/src/schema_transaction.rs @@ -17,7 +17,7 @@ use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] pub enum RelationLabel { - Tx, // undefined tx + Unknown, // undefined tx Transfer(AccountAddress), Onboarding(AccountAddress), Vouch(AccountAddress), @@ -30,7 +30,7 @@ pub enum RelationLabel { impl RelationLabel { pub fn to_cypher_label(&self) -> String { match self { - RelationLabel::Tx => "Tx".to_owned(), + RelationLabel::Unknown => "Tx".to_owned(), RelationLabel::Transfer(_) => "Tx".to_owned(), RelationLabel::Onboarding(_) => "Onboarding".to_owned(), RelationLabel::Vouch(_) => "Vouch".to_owned(), @@ -41,7 +41,7 @@ impl RelationLabel { pub fn get_recipient(&self) -> Option { match &self { - RelationLabel::Tx => None, + RelationLabel::Unknown => None, RelationLabel::Transfer(account_address) => Some(*account_address), RelationLabel::Onboarding(account_address) => Some(*account_address), RelationLabel::Vouch(account_address) => Some(*account_address), diff --git a/tests/test_json_rescue_v5_load.rs b/tests/test_json_rescue_v5_load.rs index 7fa7718..66661ca 100644 --- a/tests/test_json_rescue_v5_load.rs +++ b/tests/test_json_rescue_v5_load.rs @@ -67,6 +67,7 @@ async fn test_load_queue() -> anyhow::Result<()> { let path = fixtures::v5_json_tx_path(); let tx_count = json_rescue_v5_load::rip_concurrent_limited(&path, &pool, None).await?; + dbg!(&tx_count); assert!(tx_count == 13); let tx_count = json_rescue_v5_load::rip_concurrent_limited(&path, &pool, None).await?; diff --git a/tests/test_json_rescue_v5_parse.rs b/tests/test_json_rescue_v5_parse.rs index f54bf1f..f9bd952 100644 --- a/tests/test_json_rescue_v5_parse.rs +++ b/tests/test_json_rescue_v5_parse.rs @@ -71,8 +71,9 @@ fn test_json_format_example() -> anyhow::Result<()> { let p = fixtures::v5_json_tx_path().join("example_create_user.json"); let (tx, _, _) = extract_v5_json_rescue(&p)?; - let first = tx.first().unwrap(); + dbg!(&tx); + let first = tx.first().unwrap(); assert!(first.sender.to_hex_literal() == *"0xecaf65add1b785b0495e3099f4045ec0"); Ok(()) }