Skip to content

Commit 2f577f8

Browse files
committed
graphql-alt: Object.objectAt
## Description Support fetching a different version of an existing object. This is mostly helpful if you have fetched an object in response to some nested query, and then want to modify the version of it you are looking at. ## Test plan New E2E tests: ``` sui$ cargo nextest run \ -p sui-indexer-alt-e2e-tests \ -- graphql/objects/object_at ```
1 parent 5c5bffc commit 2f577f8

File tree

8 files changed

+233
-0
lines changed

8 files changed

+233
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Copyright (c) Mysten Labs, Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//# init --protocol-version 70 --accounts A --simulator
5+
6+
//# programmable --sender A --inputs 1
7+
//> SplitCoins(Gas, [Input(0)]);
8+
//> MergeCoins(Gas, [Result(0)])
9+
10+
//# programmable --sender A --inputs 1
11+
//> SplitCoins(Gas, [Input(0)]);
12+
//> MergeCoins(Gas, [Result(0)])
13+
14+
//# create-checkpoint
15+
16+
//# programmable --sender A --inputs 1
17+
//> SplitCoins(Gas, [Input(0)]);
18+
//> MergeCoins(Gas, [Result(0)])
19+
20+
//# programmable --sender A --inputs 1
21+
//> SplitCoins(Gas, [Input(0)]);
22+
//> MergeCoins(Gas, [Result(0)])
23+
24+
//# create-checkpoint
25+
26+
//# programmable --sender A --inputs 1
27+
//> SplitCoins(Gas, [Input(0)]);
28+
//> MergeCoins(Gas, [Result(0)])
29+
30+
//# create-checkpoint
31+
32+
//# run-graphql
33+
{
34+
object(address: "@{obj_0_0}") {
35+
version
36+
37+
initial: objectAt(version: 1) { version }
38+
byCheckpoint: objectAt(checkpoint: 2) { version }
39+
byRootVersion: objectAt(rootVersion: 3) { version }
40+
}
41+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
---
2+
source: external-crates/move/crates/move-transactional-test-runner/src/framework.rs
3+
---
4+
processed 10 tasks
5+
6+
init:
7+
A: object(0,0)
8+
9+
task 1, lines 6-8:
10+
//# programmable --sender A --inputs 1
11+
//> SplitCoins(Gas, [Input(0)]);
12+
//> MergeCoins(Gas, [Result(0)])
13+
mutated: object(0,0)
14+
gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 0, non_refundable_storage_fee: 0
15+
16+
task 2, lines 10-12:
17+
//# programmable --sender A --inputs 1
18+
//> SplitCoins(Gas, [Input(0)]);
19+
//> MergeCoins(Gas, [Result(0)])
20+
mutated: object(0,0)
21+
gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880
22+
23+
task 3, line 14:
24+
//# create-checkpoint
25+
Checkpoint created: 1
26+
27+
task 4, lines 16-18:
28+
//# programmable --sender A --inputs 1
29+
//> SplitCoins(Gas, [Input(0)]);
30+
//> MergeCoins(Gas, [Result(0)])
31+
mutated: object(0,0)
32+
gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880
33+
34+
task 5, lines 20-22:
35+
//# programmable --sender A --inputs 1
36+
//> SplitCoins(Gas, [Input(0)]);
37+
//> MergeCoins(Gas, [Result(0)])
38+
mutated: object(0,0)
39+
gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880
40+
41+
task 6, line 24:
42+
//# create-checkpoint
43+
Checkpoint created: 2
44+
45+
task 7, lines 26-28:
46+
//# programmable --sender A --inputs 1
47+
//> SplitCoins(Gas, [Input(0)]);
48+
//> MergeCoins(Gas, [Result(0)])
49+
mutated: object(0,0)
50+
gas summary: computation_cost: 1000000, storage_cost: 988000, storage_rebate: 978120, non_refundable_storage_fee: 9880
51+
52+
task 8, line 30:
53+
//# create-checkpoint
54+
Checkpoint created: 3
55+
56+
task 9, lines 32-41:
57+
//# run-graphql
58+
Response: {
59+
"data": {
60+
"object": {
61+
"version": 6,
62+
"initial": {
63+
"version": 1
64+
},
65+
"byCheckpoint": {
66+
"version": 5
67+
},
68+
"byRootVersion": {
69+
"version": 3
70+
}
71+
}
72+
}
73+
}

crates/sui-indexer-alt-graphql/schema.graphql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ interface IObject {
122122
"""
123123
digest: String!
124124
"""
125+
Fetch the object with the same ID, at a different version, root version bound, or checkpoint.
126+
"""
127+
objectAt(version: UInt53, rootVersion: UInt53, checkpoint: UInt53): Object
128+
"""
125129
The Base64-encoded BCS serialization of this object, as an `Object`.
126130
"""
127131
objectBcs: Base64
@@ -157,6 +161,12 @@ type MovePackage implements IAddressable & IObject {
157161
"""
158162
digest: String!
159163
"""
164+
Fetch the package as an object with the same ID, at a different version, root version bound, or checkpoint.
165+
166+
If no additional bound is provided, the latest version of this object is fetched at the latest checkpoint.
167+
"""
168+
objectAt(version: UInt53, rootVersion: UInt53, checkpoint: UInt53): Object
169+
"""
160170
The Base64-encoded BCS serialization of this package, as an `Object`.
161171
"""
162172
objectBcs: Base64
@@ -201,6 +211,12 @@ type Object implements IAddressable & IObject {
201211
"""
202212
asMovePackage: MovePackage
203213
"""
214+
Fetch the object with the same ID, at a different version, root version bound, or checkpoint.
215+
216+
If no additional bound is provided, the latest version of this object is fetched at the latest checkpoint.
217+
"""
218+
objectAt(version: UInt53, rootVersion: UInt53, checkpoint: UInt53): Object
219+
"""
204220
The Base64-encoded BCS serialization of this object, as an `Object`.
205221
"""
206222
objectBcs: Base64

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,21 @@ impl MovePackage {
8080
ObjectImpl::from(&self.super_).digest()
8181
}
8282

83+
/// Fetch the package as an object with the same ID, at a different version, root version bound, or checkpoint.
84+
///
85+
/// If no additional bound is provided, the latest version of this object is fetched at the latest checkpoint.
86+
pub(crate) async fn object_at(
87+
&self,
88+
ctx: &Context<'_>,
89+
version: Option<UInt53>,
90+
root_version: Option<UInt53>,
91+
checkpoint: Option<UInt53>,
92+
) -> Result<Option<Object>, RpcError<object::Error>> {
93+
ObjectImpl::from(&self.super_)
94+
.object_at(ctx, version, root_version, checkpoint)
95+
.await
96+
}
97+
8398
/// The Base64-encoded BCS serialization of this package, as an `Object`.
8499
pub(crate) async fn object_bcs(
85100
&self,

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,14 @@ use super::{
5656
ty = "String",
5757
desc = "32-byte hash that identifies the object's contents, encoded in Base58.",
5858
),
59+
field(
60+
name = "object_at",
61+
arg(name = "version", ty = "Option<UInt53>"),
62+
arg(name = "root_version", ty = "Option<UInt53>"),
63+
arg(name = "checkpoint", ty = "Option<UInt53>"),
64+
ty = "Result<Option<Object>, RpcError<Error>>",
65+
desc = "Fetch the object with the same ID, at a different version, root version bound, or checkpoint.",
66+
),
5967
field(
6068
name = "object_bcs",
6169
ty = "Result<Option<Base64>, RpcError>",
@@ -174,6 +182,21 @@ impl Object {
174182
MovePackage::from_object(self, ctx).await
175183
}
176184

185+
/// Fetch the object with the same ID, at a different version, root version bound, or checkpoint.
186+
///
187+
/// If no additional bound is provided, the latest version of this object is fetched at the latest checkpoint.
188+
async fn object_at(
189+
&self,
190+
ctx: &Context<'_>,
191+
version: Option<UInt53>,
192+
root_version: Option<UInt53>,
193+
checkpoint: Option<UInt53>,
194+
) -> Result<Option<Self>, RpcError<Error>> {
195+
ObjectImpl::from(self)
196+
.object_at(ctx, version, root_version, checkpoint)
197+
.await
198+
}
199+
177200
/// The Base64-encoded BCS serialization of this object, as an `Object`.
178201
async fn object_bcs(&self, ctx: &Context<'_>) -> Result<Option<Base64>, RpcError<Error>> {
179202
ObjectImpl::from(self).object_bcs(ctx).await
@@ -490,6 +513,23 @@ impl ObjectImpl<'_> {
490513
Base58::encode(self.0.digest.inner())
491514
}
492515

516+
pub(crate) async fn object_at(
517+
&self,
518+
ctx: &Context<'_>,
519+
version: Option<UInt53>,
520+
root_version: Option<UInt53>,
521+
checkpoint: Option<UInt53>,
522+
) -> Result<Option<Object>, RpcError<Error>> {
523+
let key = ObjectKey {
524+
address: self.0.super_.address.into(),
525+
version,
526+
root_version,
527+
at_checkpoint: checkpoint,
528+
};
529+
530+
Object::by_key(ctx, self.0.super_.scope.clone(), key).await
531+
}
532+
493533
pub(crate) async fn object_bcs(
494534
&self,
495535
ctx: &Context<'_>,

crates/sui-indexer-alt-graphql/src/snapshots/sui_indexer_alt_graphql__tests__schema.graphql.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ interface IObject {
126126
"""
127127
digest: String!
128128
"""
129+
Fetch the object with the same ID, at a different version, root version bound, or checkpoint.
130+
"""
131+
objectAt(version: UInt53, rootVersion: UInt53, checkpoint: UInt53): Object
132+
"""
129133
The Base64-encoded BCS serialization of this object, as an `Object`.
130134
"""
131135
objectBcs: Base64
@@ -161,6 +165,12 @@ type MovePackage implements IAddressable & IObject {
161165
"""
162166
digest: String!
163167
"""
168+
Fetch the package as an object with the same ID, at a different version, root version bound, or checkpoint.
169+
170+
If no additional bound is provided, the latest version of this object is fetched at the latest checkpoint.
171+
"""
172+
objectAt(version: UInt53, rootVersion: UInt53, checkpoint: UInt53): Object
173+
"""
164174
The Base64-encoded BCS serialization of this package, as an `Object`.
165175
"""
166176
objectBcs: Base64
@@ -205,6 +215,12 @@ type Object implements IAddressable & IObject {
205215
"""
206216
asMovePackage: MovePackage
207217
"""
218+
Fetch the object with the same ID, at a different version, root version bound, or checkpoint.
219+
220+
If no additional bound is provided, the latest version of this object is fetched at the latest checkpoint.
221+
"""
222+
objectAt(version: UInt53, rootVersion: UInt53, checkpoint: UInt53): Object
223+
"""
208224
The Base64-encoded BCS serialization of this object, as an `Object`.
209225
"""
210226
objectBcs: Base64

crates/sui-indexer-alt-graphql/src/snapshots/sui_indexer_alt_graphql__tests__staging.graphql.snap

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ interface IObject {
126126
"""
127127
digest: String!
128128
"""
129+
Fetch the object with the same ID, at a different version, root version bound, or checkpoint.
130+
"""
131+
objectAt(version: UInt53, rootVersion: UInt53, checkpoint: UInt53): Object
132+
"""
129133
The Base64-encoded BCS serialization of this object, as an `Object`.
130134
"""
131135
objectBcs: Base64
@@ -161,6 +165,12 @@ type MovePackage implements IAddressable & IObject {
161165
"""
162166
digest: String!
163167
"""
168+
Fetch the package as an object with the same ID, at a different version, root version bound, or checkpoint.
169+
170+
If no additional bound is provided, the latest version of this object is fetched at the latest checkpoint.
171+
"""
172+
objectAt(version: UInt53, rootVersion: UInt53, checkpoint: UInt53): Object
173+
"""
164174
The Base64-encoded BCS serialization of this package, as an `Object`.
165175
"""
166176
objectBcs: Base64
@@ -205,6 +215,12 @@ type Object implements IAddressable & IObject {
205215
"""
206216
asMovePackage: MovePackage
207217
"""
218+
Fetch the object with the same ID, at a different version, root version bound, or checkpoint.
219+
220+
If no additional bound is provided, the latest version of this object is fetched at the latest checkpoint.
221+
"""
222+
objectAt(version: UInt53, rootVersion: UInt53, checkpoint: UInt53): Object
223+
"""
208224
The Base64-encoded BCS serialization of this object, as an `Object`.
209225
"""
210226
objectBcs: Base64

crates/sui-indexer-alt-graphql/staging.graphql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ interface IObject {
122122
"""
123123
digest: String!
124124
"""
125+
Fetch the object with the same ID, at a different version, root version bound, or checkpoint.
126+
"""
127+
objectAt(version: UInt53, rootVersion: UInt53, checkpoint: UInt53): Object
128+
"""
125129
The Base64-encoded BCS serialization of this object, as an `Object`.
126130
"""
127131
objectBcs: Base64
@@ -157,6 +161,12 @@ type MovePackage implements IAddressable & IObject {
157161
"""
158162
digest: String!
159163
"""
164+
Fetch the package as an object with the same ID, at a different version, root version bound, or checkpoint.
165+
166+
If no additional bound is provided, the latest version of this object is fetched at the latest checkpoint.
167+
"""
168+
objectAt(version: UInt53, rootVersion: UInt53, checkpoint: UInt53): Object
169+
"""
160170
The Base64-encoded BCS serialization of this package, as an `Object`.
161171
"""
162172
objectBcs: Base64
@@ -201,6 +211,12 @@ type Object implements IAddressable & IObject {
201211
"""
202212
asMovePackage: MovePackage
203213
"""
214+
Fetch the object with the same ID, at a different version, root version bound, or checkpoint.
215+
216+
If no additional bound is provided, the latest version of this object is fetched at the latest checkpoint.
217+
"""
218+
objectAt(version: UInt53, rootVersion: UInt53, checkpoint: UInt53): Object
219+
"""
204220
The Base64-encoded BCS serialization of this object, as an `Object`.
205221
"""
206222
objectBcs: Base64

0 commit comments

Comments
 (0)