From cc2a65fa5921a3ae34475fbab18eb41f3ce16af5 Mon Sep 17 00:00:00 2001 From: Ashok Menon Date: Fri, 11 Oct 2024 17:43:32 +0100 Subject: [PATCH] graphql: expose MovePackage as BCS (packageBcs) (#19818) ## Description Add a new field -- `MovePackage.packageBcs` -- that exposes the BCS representation of the MovePackage. This complements `bcs` (which is the BCS representation of its `Object` form), and `moduleBcs` (which is the BCS representation of its `Vec`s). ## Test plan New E2E test: ``` sui$ cargo nextest run -p sui-graphql-e2e-tests -- packages/bcs.move ``` ## Stack - #19817 --- ## 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: - [x] GraphQL: Adds `MovePackage.packageBcs` to expose the BCS representation of the `MovePackage` struct (as opposed to the BCS representation of the outer `Object` struct. - [ ] CLI: - [ ] Rust SDK: - [ ] REST API: --- .../tests/stable/packages/bcs.exp | 23 +++++++++++++++++++ .../tests/stable/packages/bcs.move | 20 ++++++++++++++++ crates/sui-graphql-rpc/schema.graphql | 4 ++++ .../sui-graphql-rpc/src/types/move_package.rs | 11 +++++++++ crates/sui-graphql-rpc/staging.graphql | 4 ++++ .../snapshot_tests__schema.graphql.snap | 4 ++++ .../snapshot_tests__staging.graphql.snap | 4 ++++ 7 files changed, 70 insertions(+) create mode 100644 crates/sui-graphql-e2e-tests/tests/stable/packages/bcs.exp create mode 100644 crates/sui-graphql-e2e-tests/tests/stable/packages/bcs.move diff --git a/crates/sui-graphql-e2e-tests/tests/stable/packages/bcs.exp b/crates/sui-graphql-e2e-tests/tests/stable/packages/bcs.exp new file mode 100644 index 0000000000000..f0e668bcd3410 --- /dev/null +++ b/crates/sui-graphql-e2e-tests/tests/stable/packages/bcs.exp @@ -0,0 +1,23 @@ +processed 4 tasks + +task 1, lines 6-9: +//# publish +created: object(1,0) +mutated: object(0,0) +gas summary: computation_cost: 1000000, storage_cost: 3442800, storage_rebate: 0, non_refundable_storage_fee: 0 + +task 2, line 11: +//# create-checkpoint +Checkpoint created: 1 + +task 3, lines 13-20: +//# run-graphql +Response: { + "data": { + "package": { + "bcs": "Adz1CN2mPNeBZVYbv5RqhGYkv1DQpl31VsxGSdfjr8viAQAAAAAAAAABAW1aoRzrCwYAAAAGAQACAwIFBQcDBwoECA4gDC4QAAEAAAABAAABAwFmAW3c9QjdpjzXgWVWG7+UaoRmJL9Q0KZd9VbMRknX46/L4gABAAAAAgYqAAAAAAAAAAIAAAIAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAQAAAAAAAAADIDoneo4Y+M2qKottIwlwrhAoW7myDDdD4qGyoq6coLMGEHUlAAAAAAA=", + "packageBcs": "3PUI3aY814FlVhu/lGqEZiS/UNCmXfVWzEZJ1+Ovy+IBAAAAAAAAAAEBbVqhHOsLBgAAAAYBAAIDAgUFBwMHCgQIDiAMLhAAAQAAAAEAAAEDAWYBbdz1CN2mPNeBZVYbv5RqhGYkv1DQpl31VsxGSdfjr8viAAEAAAACBioAAAAAAAAAAgAAAgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEBAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIBAAAAAAAAAA==", + "moduleBcs": "AQFtWqEc6wsGAAAABgEAAgMCBQUHAwcKBAgOIAwuEAABAAAAAQAAAQMBZgFt3PUI3aY814FlVhu/lGqEZiS/UNCmXfVWzEZJ1+Ovy+IAAQAAAAIGKgAAAAAAAAACAA==" + } + } +} diff --git a/crates/sui-graphql-e2e-tests/tests/stable/packages/bcs.move b/crates/sui-graphql-e2e-tests/tests/stable/packages/bcs.move new file mode 100644 index 0000000000000..1f80bd62d0dde --- /dev/null +++ b/crates/sui-graphql-e2e-tests/tests/stable/packages/bcs.move @@ -0,0 +1,20 @@ +// Copyright (c) Mysten Labs, Inc. +// SPDX-License-Identifier: Apache-2.0 + +//# init --protocol-version 51 --addresses P=0x0 --simulator + +//# publish +module P::m { + public fun f(): u64 { 42 } +} + +//# create-checkpoint + +//# run-graphql +{ + package(address: "@{P}") { + bcs + packageBcs + moduleBcs + } +} diff --git a/crates/sui-graphql-rpc/schema.graphql b/crates/sui-graphql-rpc/schema.graphql index 8b655ef59120f..2fce825c4472c 100644 --- a/crates/sui-graphql-rpc/schema.graphql +++ b/crates/sui-graphql-rpc/schema.graphql @@ -2375,6 +2375,10 @@ type MovePackage implements IObject & IOwner { """ typeOrigins: [TypeOrigin!] """ + BCS representation of the package itself, as a MovePackage. + """ + packageBcs: Base64 + """ BCS representation of the package's modules. Modules appear as a sequence of pairs (module name, followed by module bytes), in alphabetic order by module name. """ diff --git a/crates/sui-graphql-rpc/src/types/move_package.rs b/crates/sui-graphql-rpc/src/types/move_package.rs index 5d46cab757ddc..ff4762f529a79 100644 --- a/crates/sui-graphql-rpc/src/types/move_package.rs +++ b/crates/sui-graphql-rpc/src/types/move_package.rs @@ -548,6 +548,17 @@ impl MovePackage { Some(type_origins) } + /// BCS representation of the package itself, as a MovePackage. + async fn package_bcs(&self) -> Result> { + let bcs = bcs::to_bytes(&self.native) + .map_err(|_| { + Error::Internal(format!("Failed to serialize package {}", self.native.id())) + }) + .extend()?; + + Ok(Some(bcs.into())) + } + /// BCS representation of the package's modules. Modules appear as a sequence of pairs (module /// name, followed by module bytes), in alphabetic order by module name. async fn module_bcs(&self) -> Result> { diff --git a/crates/sui-graphql-rpc/staging.graphql b/crates/sui-graphql-rpc/staging.graphql index 70b408f1cf1cf..21062b22f11f4 100644 --- a/crates/sui-graphql-rpc/staging.graphql +++ b/crates/sui-graphql-rpc/staging.graphql @@ -2375,6 +2375,10 @@ type MovePackage implements IObject & IOwner { """ typeOrigins: [TypeOrigin!] """ + BCS representation of the package itself, as a MovePackage. + """ + packageBcs: Base64 + """ BCS representation of the package's modules. Modules appear as a sequence of pairs (module name, followed by module bytes), in alphabetic order by module name. """ diff --git a/crates/sui-graphql-rpc/tests/snapshots/snapshot_tests__schema.graphql.snap b/crates/sui-graphql-rpc/tests/snapshots/snapshot_tests__schema.graphql.snap index 5f4d538f1d53a..221d0249310d9 100644 --- a/crates/sui-graphql-rpc/tests/snapshots/snapshot_tests__schema.graphql.snap +++ b/crates/sui-graphql-rpc/tests/snapshots/snapshot_tests__schema.graphql.snap @@ -2379,6 +2379,10 @@ type MovePackage implements IObject & IOwner { """ typeOrigins: [TypeOrigin!] """ + BCS representation of the package itself, as a MovePackage. + """ + packageBcs: Base64 + """ BCS representation of the package's modules. Modules appear as a sequence of pairs (module name, followed by module bytes), in alphabetic order by module name. """ diff --git a/crates/sui-graphql-rpc/tests/snapshots/snapshot_tests__staging.graphql.snap b/crates/sui-graphql-rpc/tests/snapshots/snapshot_tests__staging.graphql.snap index 8ccb3da1cf947..f16cb7f75c5af 100644 --- a/crates/sui-graphql-rpc/tests/snapshots/snapshot_tests__staging.graphql.snap +++ b/crates/sui-graphql-rpc/tests/snapshots/snapshot_tests__staging.graphql.snap @@ -2379,6 +2379,10 @@ type MovePackage implements IObject & IOwner { """ typeOrigins: [TypeOrigin!] """ + BCS representation of the package itself, as a MovePackage. + """ + packageBcs: Base64 + """ BCS representation of the package's modules. Modules appear as a sequence of pairs (module name, followed by module bytes), in alphabetic order by module name. """