Skip to content

Commit c7da1aa

Browse files
committed
graphql-alt: MovePackage.packageAt
## Description Support fetching a different version of an existing package, similar to `Object.objectAt`, but navigating the package versioning scheme (where packages have their own IDs, but share an "original ID". ## Test plan New E2E tests: ``` sui$ cargo nextest run \ -p sui-indexer-alt-e2e-tests \ -- graphql/packages/package_at ```
1 parent a7cda47 commit c7da1aa

File tree

7 files changed

+175
-0
lines changed

7 files changed

+175
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright (c) Mysten Labs, Inc.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//# init --protocol-version 70 --accounts A --addresses P1=0x0 P2=0x0 P3=0x0 --simulator
5+
6+
//# publish --upgradeable --sender A
7+
module P1::M {
8+
public fun foo(): u64 { 42 }
9+
}
10+
11+
//# upgrade --package P1 --upgrade-capability 1,1 --sender A
12+
module P2::M {
13+
public fun foo(): u64 { 43 }
14+
}
15+
16+
//# create-checkpoint
17+
18+
//# upgrade --package P2 --upgrade-capability 1,1 --sender A
19+
module P3::M {
20+
public fun foo(): u64 { 44 }
21+
}
22+
23+
//# create-checkpoint
24+
25+
//# run-graphql
26+
{ # Fetching packages as objects, to confirm their addresses and versions
27+
p1: object(address: "@{obj_1_0}") {
28+
address
29+
version
30+
}
31+
32+
p2: object(address: "@{obj_2_0}") {
33+
address
34+
version
35+
}
36+
37+
p3: object(address: "@{obj_4_0}") {
38+
address
39+
version
40+
}
41+
}
42+
43+
//# run-graphql
44+
{
45+
package(address: "@{obj_1_0}") {
46+
address
47+
version
48+
49+
initial: packageAt(version: 1) {
50+
address
51+
version
52+
}
53+
54+
byCheckpoint: packageAt(checkpoint: 1) {
55+
address
56+
version
57+
}
58+
}
59+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
---
2+
source: external-crates/move/crates/move-transactional-test-runner/src/framework.rs
3+
---
4+
processed 8 tasks
5+
6+
init:
7+
A: object(0,0)
8+
9+
task 1, lines 6-9:
10+
//# publish --upgradeable --sender A
11+
created: object(1,0), object(1,1)
12+
mutated: object(0,0)
13+
gas summary: computation_cost: 1000000, storage_cost: 5092000, storage_rebate: 0, non_refundable_storage_fee: 0
14+
15+
task 2, lines 11-14:
16+
//# upgrade --package P1 --upgrade-capability 1,1 --sender A
17+
created: object(2,0)
18+
mutated: object(0,0), object(1,1)
19+
gas summary: computation_cost: 1000000, storage_cost: 5092000, storage_rebate: 2595780, non_refundable_storage_fee: 26220
20+
21+
task 3, line 16:
22+
//# create-checkpoint
23+
Checkpoint created: 1
24+
25+
task 4, lines 18-21:
26+
//# upgrade --package P2 --upgrade-capability 1,1 --sender A
27+
created: object(4,0)
28+
mutated: object(0,0), object(1,1)
29+
gas summary: computation_cost: 1000000, storage_cost: 5092000, storage_rebate: 2595780, non_refundable_storage_fee: 26220
30+
31+
task 5, line 23:
32+
//# create-checkpoint
33+
Checkpoint created: 2
34+
35+
task 6, lines 25-41:
36+
//# run-graphql
37+
Response: {
38+
"data": {
39+
"p1": {
40+
"address": "0x37c66e5033ffe07f458c76432c64848275451aaeb5d6d4420e14818318b93759",
41+
"version": 1
42+
},
43+
"p2": {
44+
"address": "0x57bf7d91755b58a6b82e41e490bd2f03e803d1c081fe85747312eb016f39314e",
45+
"version": 2
46+
},
47+
"p3": {
48+
"address": "0x50592365811b6d08409158a0917066ca3e822a4c49dd6ae4465150f8aeb9a1da",
49+
"version": 3
50+
}
51+
}
52+
}
53+
54+
task 7, lines 43-59:
55+
//# run-graphql
56+
Response: {
57+
"data": {
58+
"package": {
59+
"address": "0x50592365811b6d08409158a0917066ca3e822a4c49dd6ae4465150f8aeb9a1da",
60+
"version": 3,
61+
"initial": {
62+
"address": "0x37c66e5033ffe07f458c76432c64848275451aaeb5d6d4420e14818318b93759",
63+
"version": 1
64+
},
65+
"byCheckpoint": {
66+
"address": "0x57bf7d91755b58a6b82e41e490bd2f03e803d1c081fe85747312eb016f39314e",
67+
"version": 2
68+
}
69+
}
70+
}
71+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ type MovePackage implements IAddressable & IObject {
179179
"""
180180
objectVersionsBefore(first: Int, after: String, last: Int, before: String, filter: VersionFilter): ObjectConnection!
181181
"""
182+
Fetch the package with the same original ID, at a different version, root version bound, or checkpoint.
183+
184+
If no additional bound is provided, the latest version of this package is fetched at the latest checkpoint.
185+
"""
186+
packageAt(version: UInt53, checkpoint: UInt53): MovePackage
187+
"""
182188
The Base64-encoded BCS serialization of this package, as a `MovePackage`.
183189
"""
184190
packageBcs: Base64

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,27 @@ impl MovePackage {
133133
.await
134134
}
135135

136+
/// Fetch the package with the same original ID, at a different version, root version bound, or checkpoint.
137+
///
138+
/// If no additional bound is provided, the latest version of this package is fetched at the latest checkpoint.
139+
async fn package_at(
140+
&self,
141+
ctx: &Context<'_>,
142+
version: Option<UInt53>,
143+
checkpoint: Option<UInt53>,
144+
) -> Result<Option<MovePackage>, RpcError<Error>> {
145+
MovePackage::by_key(
146+
ctx,
147+
self.super_.super_.scope.clone(),
148+
PackageKey {
149+
address: self.super_.super_.address.into(),
150+
version,
151+
at_checkpoint: checkpoint,
152+
},
153+
)
154+
.await
155+
}
156+
136157
/// The Base64-encoded BCS serialization of this package, as a `MovePackage`.
137158
async fn package_bcs(&self) -> Result<Option<Base64>, RpcError> {
138159
let bytes = bcs::to_bytes(&self.contents).context("Failed to serialize MovePackage")?;

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ type MovePackage implements IAddressable & IObject {
183183
"""
184184
objectVersionsBefore(first: Int, after: String, last: Int, before: String, filter: VersionFilter): ObjectConnection!
185185
"""
186+
Fetch the package with the same original ID, at a different version, root version bound, or checkpoint.
187+
188+
If no additional bound is provided, the latest version of this package is fetched at the latest checkpoint.
189+
"""
190+
packageAt(version: UInt53, checkpoint: UInt53): MovePackage
191+
"""
186192
The Base64-encoded BCS serialization of this package, as a `MovePackage`.
187193
"""
188194
packageBcs: Base64

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ type MovePackage implements IAddressable & IObject {
183183
"""
184184
objectVersionsBefore(first: Int, after: String, last: Int, before: String, filter: VersionFilter): ObjectConnection!
185185
"""
186+
Fetch the package with the same original ID, at a different version, root version bound, or checkpoint.
187+
188+
If no additional bound is provided, the latest version of this package is fetched at the latest checkpoint.
189+
"""
190+
packageAt(version: UInt53, checkpoint: UInt53): MovePackage
191+
"""
186192
The Base64-encoded BCS serialization of this package, as a `MovePackage`.
187193
"""
188194
packageBcs: Base64

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ type MovePackage implements IAddressable & IObject {
179179
"""
180180
objectVersionsBefore(first: Int, after: String, last: Int, before: String, filter: VersionFilter): ObjectConnection!
181181
"""
182+
Fetch the package with the same original ID, at a different version, root version bound, or checkpoint.
183+
184+
If no additional bound is provided, the latest version of this package is fetched at the latest checkpoint.
185+
"""
186+
packageAt(version: UInt53, checkpoint: UInt53): MovePackage
187+
"""
182188
The Base64-encoded BCS serialization of this package, as a `MovePackage`.
183189
"""
184190
packageBcs: Base64

0 commit comments

Comments
 (0)