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

[sdk] use updated encoding 5.2.0 file #13

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ diem-crypto = { git = "https://github.com/0LNetworkCommunity/diem.git", branch =
env_logger = "^0.11"
flate2 = "^1.0"
glob = "^0.3"
libra-backwards-compatibility = { git = "https://github.com/0o-de-lally/libra-framework.git", branch = "legacy-compat" }
libra-cached-packages = { git = "https://github.com/0o-de-lally/libra-framework.git", branch = "legacy-compat" }
libra-storage = { git = "https://github.com/0o-de-lally/libra-framework.git", branch = "legacy-compat" }
libra-types = { git = "https://github.com/0o-de-lally/libra-framework.git", branch = "legacy-compat" }
libra-backwards-compatibility = { git = "https://github.com/0LNetworkCommunity/libra-framework.git", branch = "patch-compat-5.2.0" }
libra-cached-packages = { git = "https://github.com/0LNetworkCommunity/libra-framework.git", branch = "patch-compat-5.2.0" }
libra-storage = { git = "https://github.com/0LNetworkCommunity/libra-framework.git", branch = "patch-compat-5.2.0" }
libra-types = { git = "https://github.com/0LNetworkCommunity/libra-framework.git", branch = "patch-compat-5.2.0" }
log = "^0.4"
neo4rs = "0.8.0"
once_cell = "^1.2"
Expand Down
208 changes: 116 additions & 92 deletions src/json_rescue_v5_extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ pub fn extract_v5_json_rescue(
}

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

dbg!(&wtxs);
// TODO:
// wtxs.events
// TODO:
wtxs.block_timestamp = timestamp;

// 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),
Expand All @@ -88,7 +88,7 @@ pub fn extract_v5_json_rescue(
_ => {}
}
}

dbg!(&tx_vec);
Ok((tx_vec, event_vec, unique_functions))
}

Expand All @@ -103,109 +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::CreateAccUser { .. } => {
wtx.relation_label = RelationLabel::Onboarding(wtx.sender);
}
ScriptFunctionCallV520::CreateAccVal { .. } => {
wtx.relation_label = RelationLabel::Onboarding(wtx.sender);
}
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)?);

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()));
}
}
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::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
Expand Down
6 changes: 3 additions & 3 deletions src/schema_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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(),
Expand All @@ -41,7 +41,7 @@ impl RelationLabel {

pub fn get_recipient(&self) -> Option<AccountAddress> {
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),
Expand Down
1 change: 1 addition & 0 deletions tests/test_json_rescue_v5_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;
Expand Down
3 changes: 2 additions & 1 deletion tests/test_json_rescue_v5_parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand Down
Loading