Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cypher] include cumulative tx amount in Lifetime relation #14

Merged
merged 18 commits into from
Jan 28, 2025
Next Next commit
cleanup
Peregrine Fitz Bittern committed Jan 25, 2025
commit 735ec85297c5234c1aeb50e7df50831639f17e55
58 changes: 1 addition & 57 deletions src/decode_entry_function.rs
Original file line number Diff line number Diff line change
@@ -5,19 +5,12 @@ use libra_backwards_compatibility::sdk::{
v6_libra_framework_sdk_builder::EntryFunctionCall as V6EntryFunctionCall,
v7_libra_framework_sdk_builder::EntryFunctionCall as V7EntryFunctionCall,
};
// use libra_cached_packages::libra_stdlib::EntryFunctionCall as CurrentVersionEntryFunctionCall;

/// test all entry function decoders for the current bytes
/// EntryFuntion decoding for V6, V7 eras
pub fn decode_entry_function_all_versions(
user_tx: &SignedTransaction,
events: &[WarehouseEvent],
) -> anyhow::Result<(EntryFunctionArgs, RelationLabel)> {
// TODO: current version encoding

// if let Some((args, relation)) = maybe_get_current_version_relation(user_tx, events) {
// return Ok((args, relation));
// }

if let Some((ef, rel)) = maybe_get_v7_relation(user_tx, events) {
return Ok((ef, rel));
}
@@ -29,47 +22,6 @@ pub fn decode_entry_function_all_versions(
bail!("no entry function found")
}

// TODO: the CurrentVersionEntryFunctionCall needs serde derives
// Using HEAD libra-framework code base try to decode transaction
// fn maybe_get_current_version_relation(
// user_tx: &SignedTransaction,
// events: &[WarehouseEvent],
// ) -> Option<(EntryFunctionArgs, RelationLabel)> {
// let ef = CurrentVersionEntryFunctionCall::decode(user_tx.payload());

// let relation = match ef {
// Some(EntryFunctionCall::OlAccountTransfer { to, amount: _ }) => {
// if is_onboarding_event(events) {
// RelationLabel::Onboarding(to)
// } else {
// RelationLabel::Transfer(to)
// }
// }
// Some(EntryFunctionCall::OlAccountCreateAccount { auth_key }) => {
// RelationLabel::Onboarding(auth_key)
// }
// Some(EntryFunctionCall::VouchVouchFor { friend_account }) => {
// RelationLabel::Vouch(friend_account)
// }
// Some(EntryFunctionCall::VouchInsistVouchFor { friend_account }) => {
// RelationLabel::Vouch(friend_account)
// }
// Some(EntryFunctionCall::CoinTransfer { to, .. }) => RelationLabel::Transfer(to),
// Some(EntryFunctionCall::AccountRotateAuthenticationKeyWithRotationCapability {
// rotation_cap_offerer_address,
// ..
// }) => RelationLabel::Transfer(rotation_cap_offerer_address),

// // TODO: get other entry functions with known counter parties
// // if nothing is found try to decipher from events
// _ => return None,
// };

// let args = EntryFunctionArgs::Current(ef.unwrap());

// Some((args, relation))
// }

fn maybe_get_v7_relation(
user_tx: &SignedTransaction,
events: &[WarehouseEvent],
@@ -94,10 +46,6 @@ fn maybe_get_v7_relation(
RelationLabel::Vouch(friend_account)
}
Some(V7EntryFunctionCall::CoinTransfer { to, .. }) => RelationLabel::Transfer(to),
Some(V7EntryFunctionCall::AccountRotateAuthenticationKeyWithRotationCapability {
rotation_cap_offerer_address,
..
}) => RelationLabel::Transfer(rotation_cap_offerer_address),

// TODO: get other entry functions with known counter parties
// if nothing is found try to decipher from events
@@ -132,10 +80,6 @@ fn maybe_get_v6_relation(
RelationLabel::Vouch(wanna_be_my_friend)
}
Some(V6EntryFunctionCall::CoinTransfer { to, .. }) => RelationLabel::Transfer(to),
Some(V6EntryFunctionCall::AccountRotateAuthenticationKeyWithRotationCapability {
rotation_cap_offerer_address,
..
}) => RelationLabel::Transfer(rotation_cap_offerer_address),

// TODO: get other entry functions with known counter parties
// if nothing is found try to decipher from events
143 changes: 0 additions & 143 deletions src/extract_transactions.rs
Original file line number Diff line number Diff line change
@@ -184,146 +184,3 @@ pub fn decode_events(

Ok(list)
}

// fn pick_relation(user_tx: &SignedTransaction, events: &[WarehouseEvent]) -> RelationLabel {
// if let Some(r) = maybe_get_current_relation(user_tx, events) {
// return r;
// }
// if let Some(r) = maybe_get_v7_relation(user_tx, events) {
// return r;
// }

// if let Some(r) = maybe_get_v6_relation(user_tx, events) {
// return r;
// }

// RelationLabel::Configuration
// }

// // Using HEAD libra-framework code base try to decode transaction
// fn maybe_get_current_relation(
// user_tx: &SignedTransaction,
// events: &[WarehouseEvent],
// ) -> Option<RelationLabel> {
// let r = match EntryFunctionCall::decode(user_tx.payload()) {
// Some(EntryFunctionCall::OlAccountTransfer { to, amount: _ }) => {
// if is_onboarding_event(events) {
// RelationLabel::Onboarding(to)
// } else {
// RelationLabel::Transfer(to)
// }
// }
// Some(EntryFunctionCall::OlAccountCreateAccount { auth_key }) => {
// RelationLabel::Onboarding(auth_key)
// }
// Some(EntryFunctionCall::VouchVouchFor { friend_account }) => {
// RelationLabel::Vouch(friend_account)
// }
// Some(EntryFunctionCall::VouchInsistVouchFor { friend_account }) => {
// RelationLabel::Vouch(friend_account)
// }
// Some(EntryFunctionCall::CoinTransfer { to, .. }) => RelationLabel::Transfer(to),
// Some(EntryFunctionCall::AccountRotateAuthenticationKeyWithRotationCapability {
// rotation_cap_offerer_address,
// ..
// }) => RelationLabel::Transfer(rotation_cap_offerer_address),

// // TODO: get other entry functions with known counter parties
// // if nothing is found try to decipher from events
// _ => return None,
// };
// Some(r)
// }

// fn maybe_get_v7_relation(
// user_tx: &SignedTransaction,
// events: &[WarehouseEvent],
// ) -> Option<RelationLabel> {
// let r = match V7EntryFunctionCall::decode(user_tx.payload()) {
// Some(V7EntryFunctionCall::OlAccountTransfer { to, amount: _ }) => {
// if is_onboarding_event(events) {
// RelationLabel::Onboarding(to)
// } else {
// RelationLabel::Transfer(to)
// }
// }
// Some(V7EntryFunctionCall::OlAccountCreateAccount { auth_key }) => {
// RelationLabel::Onboarding(auth_key)
// }
// Some(V7EntryFunctionCall::VouchVouchFor { friend_account }) => {
// RelationLabel::Vouch(friend_account)
// }
// Some(V7EntryFunctionCall::VouchInsistVouchFor { friend_account }) => {
// RelationLabel::Vouch(friend_account)
// }
// Some(V7EntryFunctionCall::CoinTransfer { to, .. }) => RelationLabel::Transfer(to),
// Some(V7EntryFunctionCall::AccountRotateAuthenticationKeyWithRotationCapability {
// rotation_cap_offerer_address,
// ..
// }) => RelationLabel::Transfer(rotation_cap_offerer_address),

// // TODO: get other entry functions with known counter parties
// // if nothing is found try to decipher from events
// _ => return None,
// };
// Some(r)
// }

// fn maybe_get_v6_relation(
// user_tx: &SignedTransaction,
// events: &[WarehouseEvent],
// ) -> Option<RelationLabel> {
// let r = match V6EntryFunctionCall::decode(user_tx.payload()) {
// Some(V6EntryFunctionCall::OlAccountTransfer { to, amount: _ }) => {
// if is_onboarding_event(events) {
// RelationLabel::Onboarding(to)
// } else {
// RelationLabel::Transfer(to)
// }
// }
// Some(V6EntryFunctionCall::OlAccountCreateAccount { auth_key }) => {
// RelationLabel::Onboarding(auth_key)
// }
// Some(V6EntryFunctionCall::VouchVouchFor { wanna_be_my_friend }) => {
// RelationLabel::Vouch(wanna_be_my_friend)
// }
// Some(V6EntryFunctionCall::VouchInsistVouchFor { wanna_be_my_friend }) => {
// RelationLabel::Vouch(wanna_be_my_friend)
// }
// Some(V6EntryFunctionCall::CoinTransfer { to, .. }) => RelationLabel::Transfer(to),
// Some(V6EntryFunctionCall::AccountRotateAuthenticationKeyWithRotationCapability {
// rotation_cap_offerer_address,
// ..
// }) => RelationLabel::Transfer(rotation_cap_offerer_address),

// // TODO: get other entry functions with known counter parties
// // if nothing is found try to decipher from events
// _ => return None,
// };
// Some(r)
// }

// fn is_onboarding_event(events: &[WarehouseEvent]) -> bool {
// let withdraw = events.iter().any(|e| {
// if let UserEventTypes::Withdraw(_) = e.event {
// return true;
// }
// false
// });

// let deposit = events.iter().any(|e| {
// if let UserEventTypes::Deposit(_) = e.event {
// return true;
// }
// false
// });

// let onboard = events.iter().any(|e| {
// if let UserEventTypes::Onboard(_) = e.event {
// return true;
// }
// false
// });

// withdraw && deposit && onboard
// }
12 changes: 9 additions & 3 deletions src/json_rescue_v5_extract.rs
Original file line number Diff line number Diff line change
@@ -32,6 +32,12 @@ pub fn extract_v5_json_rescue(
let txs: Vec<TransactionViewV5> = serde_json::from_str(&json)
.map_err(|e| anyhow!("could not parse JSON to TransactionViewV5, {:?}", e))?;

decode_transaction_dataview_v5(&txs)
}

pub fn decode_transaction_dataview_v5(
txs: &[TransactionViewV5],
) -> Result<(Vec<WarehouseTxMaster>, Vec<WarehouseEvent>, Vec<String>)> {
let mut tx_vec = vec![];
let event_vec = vec![];
let mut unique_functions = vec![];
@@ -53,11 +59,11 @@ pub fn extract_v5_json_rescue(
unique_functions.push(wtxs.function.clone());
}

decode_transaction_args(&mut wtxs, &t.bytes)?;
decode_entry_function_v5(&mut wtxs, &t.bytes)?;

// TODO:
// wtxs.events
// TODO:

wtxs.block_timestamp = timestamp;

// TODO: create arg to exclude tx without counter party
@@ -92,7 +98,7 @@ pub fn extract_v5_json_rescue(
Ok((tx_vec, event_vec, unique_functions))
}

pub fn decode_transaction_args(wtx: &mut WarehouseTxMaster, tx_bytes: &[u8]) -> Result<()> {
pub fn decode_entry_function_v5(wtx: &mut WarehouseTxMaster, tx_bytes: &[u8]) -> Result<()> {
// test we can bcs decode to the transaction object
let t: TransactionV5 = bcs::from_bytes(tx_bytes).map_err(|err| {
anyhow!(