Skip to content

Commit 20bea81

Browse files
committed
Move balance_changes to scope
1 parent a99a955 commit 20bea81

File tree

3 files changed

+16
-17
lines changed

3 files changed

+16
-17
lines changed

crates/sui-indexer-alt-graphql/src/api/types/transaction_effects.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,8 @@ impl EffectsContents {
221221
let limits = pagination.limits("TransactionEffects", "balanceChanges");
222222
let page = Page::from_params(limits, first, after, last, before)?;
223223

224-
// First try to get balance changes from execution context
225-
if let Some(grpc_balance_changes) = content.balance_changes() {
224+
// First try to get balance changes from execution context (scope)
225+
if let Some(grpc_balance_changes) = self.scope.balance_changes() {
226226
return page
227227
.paginate_indices(grpc_balance_changes.len(), |i| {
228228
BalanceChange::from_grpc(self.scope.clone(), &grpc_balance_changes[i])

crates/sui-indexer-alt-graphql/src/scope.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ pub(crate) struct Scope {
5858
/// This enables any Object GraphQL type to access fresh data without database queries.
5959
execution_objects: ExecutionObjectMap,
6060

61+
/// Balance changes from the executed transaction, only available in execution context.
62+
balance_changes: Option<Vec<grpc::BalanceChange>>,
63+
6164
/// Access to packages for type resolution.
6265
package_store: Arc<dyn PackageStore>,
6366

@@ -77,6 +80,7 @@ impl Scope {
7780
checkpoint_viewed_at: Some(watermark.high_watermark().checkpoint()),
7881
root_version: None,
7982
execution_objects: Arc::new(BTreeMap::new()),
83+
balance_changes: None,
8084
package_store: package_store.clone(),
8185
resolver_limits: limits.package_resolver(),
8286
})
@@ -90,6 +94,7 @@ impl Scope {
9094
checkpoint_viewed_at: Some(checkpoint_viewed_at),
9195
root_version: self.root_version,
9296
execution_objects: Arc::clone(&self.execution_objects),
97+
balance_changes: self.balance_changes.clone(),
9398
package_store: self.package_store.clone(),
9499
resolver_limits: self.resolver_limits.clone(),
95100
})
@@ -101,6 +106,7 @@ impl Scope {
101106
checkpoint_viewed_at: self.checkpoint_viewed_at,
102107
root_version: Some(root_version),
103108
execution_objects: Arc::clone(&self.execution_objects),
109+
balance_changes: self.balance_changes.clone(),
104110
package_store: self.package_store.clone(),
105111
resolver_limits: self.resolver_limits.clone(),
106112
}
@@ -112,6 +118,7 @@ impl Scope {
112118
checkpoint_viewed_at: self.checkpoint_viewed_at,
113119
root_version: None,
114120
execution_objects: Arc::clone(&self.execution_objects),
121+
balance_changes: self.balance_changes.clone(),
115122
package_store: self.package_store.clone(),
116123
resolver_limits: self.resolver_limits.clone(),
117124
}
@@ -163,7 +170,12 @@ impl Scope {
163170
.and_then(|(_, opt)| opt.as_ref())
164171
}
165172

166-
/// Create a nested scope with execution objects extracted from an ExecutedTransaction.
173+
/// Get balance changes from execution context, if available.
174+
pub(crate) fn balance_changes(&self) -> Option<&[grpc::BalanceChange]> {
175+
self.balance_changes.as_deref()
176+
}
177+
178+
/// Create a nested scope with execution objects and balance changes extracted from an ExecutedTransaction.
167179
pub(crate) fn with_executed_transaction(
168180
&self,
169181
executed_transaction: &grpc::ExecutedTransaction,
@@ -174,6 +186,7 @@ impl Scope {
174186
checkpoint_viewed_at: None,
175187
root_version: self.root_version,
176188
execution_objects,
189+
balance_changes: Some(executed_transaction.balance_changes.clone()),
177190
package_store: self.package_store.clone(),
178191
resolver_limits: self.resolver_limits.clone(),
179192
})

crates/sui-indexer-alt-reader/src/kv_loader.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ pub enum TransactionContents {
5454
events: Option<Vec<Event>>,
5555
transaction_data: Box<TransactionData>,
5656
signatures: Vec<GenericSignature>,
57-
balance_changes: Vec<grpc::BalanceChange>,
5857
},
5958
}
6059

@@ -241,15 +240,11 @@ impl TransactionContents {
241240
.transpose()?
242241
.map(|events: TransactionEvents| events.data);
243242

244-
// Extract balance changes from the gRPC response
245-
let balance_changes = executed_transaction.balance_changes.clone();
246-
247243
Ok(Self::ExecutedTransaction {
248244
effects: Box::new(effects),
249245
events,
250246
transaction_data: Box::new(transaction_data),
251247
signatures,
252-
balance_changes,
253248
})
254249
}
255250

@@ -316,15 +311,6 @@ impl TransactionContents {
316311
}
317312
}
318313

319-
pub fn balance_changes(&self) -> Option<Vec<grpc::BalanceChange>> {
320-
match self {
321-
Self::ExecutedTransaction {
322-
balance_changes, ..
323-
} => Some(balance_changes.clone()),
324-
_ => None,
325-
}
326-
}
327-
328314
pub fn raw_transaction(&self) -> anyhow::Result<Vec<u8>> {
329315
match self {
330316
Self::Pg(stored) => Ok(stored.raw_transaction.clone()),

0 commit comments

Comments
 (0)