From 99fcadf4f738d2513ae8453bb2d1d8276b2633f6 Mon Sep 17 00:00:00 2001 From: Patrick Kuo Date: Mon, 25 Nov 2024 16:56:56 +0000 Subject: [PATCH] [cherrypick][1.38] - rosetta failed pt fix (#20411) (#20416) ## Description do not attempt to parse programmable transaction for failed transactions to avoid parsing error ## Test plan How did you test the new or updated feature? --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: - [ ] REST API: ## Description Describe the changes or additions included in this PR. ## Test plan How did you test the new or updated feature? --- ## Release notes Check each box that your changes affect. If none of the boxes relate to your changes, release notes aren't required. For each box you select, include information after the relevant heading that describes the impact of your changes that a user might notice and any actions they must take to implement updates. - [ ] Protocol: - [ ] Nodes (Validators and Full nodes): - [ ] Indexer: - [ ] JSON-RPC: - [ ] GraphQL: - [ ] CLI: - [ ] Rust SDK: - [ ] REST API: --- crates/sui-rosetta/src/operations.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/crates/sui-rosetta/src/operations.rs b/crates/sui-rosetta/src/operations.rs index ced23f58e402b..8ea99ad1d2275 100644 --- a/crates/sui-rosetta/src/operations.rs +++ b/crates/sui-rosetta/src/operations.rs @@ -252,7 +252,9 @@ impl Operations { status: Option, ) -> Result, Error> { Ok(match tx { - SuiTransactionBlockKind::ProgrammableTransaction(pt) => { + SuiTransactionBlockKind::ProgrammableTransaction(pt) + if status != Some(OperationStatus::Failure) => + { Self::parse_programmable_transaction(sender, status, pt)? } _ => vec![Operation::generic_op(status, sender, tx)], @@ -558,14 +560,16 @@ impl Operations { } } -impl TryFrom for Operations { - type Error = Error; - fn try_from(data: SuiTransactionBlockData) -> Result { +impl Operations { + fn try_from_data( + data: SuiTransactionBlockData, + status: Option, + ) -> Result { let sender = *data.sender(); Ok(Self::new(Self::from_transaction( data.transaction().clone(), sender, - None, + status, )?)) } } @@ -588,8 +592,8 @@ impl Operations { - gas_summary.computation_cost as i128; let status = Some(effect.into_status().into()); - let ops: Operations = tx.data.try_into()?; - let ops = ops.set_status(status).into_iter(); + let ops = Operations::try_from_data(tx.data, status)?; + let ops = ops.into_iter(); // We will need to subtract the operation amounts from the actual balance // change amount extracted from event to prevent double counting. @@ -735,7 +739,10 @@ impl TryFrom for Operations { } } // Rosetta don't need the call args to be parsed into readable format - SuiTransactionBlockData::try_from(data, &&mut NoOpsModuleResolver)?.try_into() + Ok(Operations::try_from_data( + SuiTransactionBlockData::try_from(data, &&mut NoOpsModuleResolver)?, + None, + )?) } }