sui_graphql_rpc/types/
object_change.rs

1// Copyright (c) Mysten Labs, Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4use async_graphql::*;
5use sui_types::effects::{IDOperation, ObjectChange as NativeObjectChange};
6
7use super::{object::Object, sui_address::SuiAddress};
8
9pub(crate) struct ObjectChange {
10    pub native: NativeObjectChange,
11    /// The checkpoint sequence number this was viewed at.
12    pub checkpoint_viewed_at: u64,
13}
14
15/// Effect on an individual Object (keyed by its ID).
16#[Object]
17impl ObjectChange {
18    /// The address of the object that has changed.
19    async fn address(&self) -> SuiAddress {
20        self.native.id.into()
21    }
22
23    /// The contents of the object immediately before the transaction.
24    async fn input_state(&self, ctx: &Context<'_>) -> Result<Option<Object>> {
25        let Some(version) = self.native.input_version else {
26            return Ok(None);
27        };
28
29        Object::query(
30            ctx,
31            self.native.id.into(),
32            Object::at_version(version.value(), self.checkpoint_viewed_at),
33        )
34        .await
35        .extend()
36    }
37
38    /// The contents of the object immediately after the transaction.
39    async fn output_state(&self, ctx: &Context<'_>) -> Result<Option<Object>> {
40        let Some(version) = self.native.output_version else {
41            return Ok(None);
42        };
43
44        Object::query(
45            ctx,
46            self.native.id.into(),
47            Object::at_version(version.value(), self.checkpoint_viewed_at),
48        )
49        .await
50        .extend()
51    }
52
53    /// Whether the ID was created in this transaction.
54    async fn id_created(&self) -> Option<bool> {
55        Some(self.native.id_operation == IDOperation::Created)
56    }
57
58    /// Whether the ID was deleted in this transaction.
59    async fn id_deleted(&self) -> Option<bool> {
60        Some(self.native.id_operation == IDOperation::Deleted)
61    }
62}