Skip to content

Commit

Permalink
Vladilen11/main (#20684)
Browse files Browse the repository at this point in the history
## Description 

Describe the changes or additions included in this PR.

## Test plan 

How did you test the new or updated feature?

---

## 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: 
- [ ] GraphQL: 
- [ ] CLI: 
- [ ] Rust SDK:
- [ ] REST API:

---------

Co-authored-by: vladilen11 <[email protected]>
  • Loading branch information
hayes-mysten and vladilen11 authored Dec 19, 2024
1 parent d5fd4de commit b2928a9
Show file tree
Hide file tree
Showing 12 changed files with 355 additions and 67 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-lions-battle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@mysten/sui': minor
---

Update generated openrpc types which removes deprecated/non-functional filters for events
1 change: 1 addition & 0 deletions apps/core/src/utils/transaction/getOwnerType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const getOwnerType = (change: SuiObjectChange) => {
if ('AddressOwner' in change.owner) return 'AddressOwner';
if ('ObjectOwner' in change.owner) return 'ObjectOwner';
if ('Shared' in change.owner) return 'Shared';
if ('ConsensusV2' in change.owner) return 'ConsensusV2';
}
return change.owner;
};
1 change: 1 addition & 0 deletions apps/core/src/utils/transaction/groupByOwner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const getOwner = (change: SuiObjectChangeWithDisplay) => {
if ('AddressOwner' in change.owner) return change.owner.AddressOwner;
if ('ObjectOwner' in change.owner) return change.owner.ObjectOwner;
if ('Shared' in change.owner) return change.objectId;
if ('ConsensusV2' in change.owner) return change.owner.ConsensusV2.authenticator.SingleOwner;
}
return '';
};
Expand Down
137 changes: 132 additions & 5 deletions sdk/graphql-transport/src/generated/queries.ts

Large diffs are not rendered by default.

41 changes: 41 additions & 0 deletions sdk/graphql-transport/src/mappers/move.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {
MoveStruct,
MoveValue,
SuiMoveAbility,
SuiMoveNormalizedEnum,
SuiMoveNormalizedFunction,
SuiMoveNormalizedModule,
SuiMoveNormalizedStruct,
Expand All @@ -13,6 +14,7 @@ import type {
import { normalizeSuiAddress, parseStructTag } from '@mysten/sui/utils';

import type {
Rpc_Move_Enum_FieldsFragment,
Rpc_Move_Function_FieldsFragment,
Rpc_Move_Module_FieldsFragment,
Rpc_Move_Struct_FieldsFragment,
Expand Down Expand Up @@ -156,6 +158,7 @@ export function mapNormalizedMoveModule(
): SuiMoveNormalizedModule {
const exposedFunctions: Record<string, SuiMoveNormalizedFunction> = {};
const structs: Record<string, SuiMoveNormalizedStruct> = {};
const enums: Record<string, SuiMoveNormalizedEnum> = {};

module.functions?.nodes
.filter((func) => func.visibility === 'PUBLIC' || func.isEntry || func.visibility === 'FRIEND')
Expand All @@ -167,6 +170,10 @@ export function mapNormalizedMoveModule(
structs[struct.name] = mapNormalizedMoveStruct(struct);
});

module.enums?.nodes.forEach((enumNode) => {
enums[enumNode.name] = mapNormalizedMoveEnum(enumNode);
});

return {
address: toShortTypeString(address),
name: module.name,
Expand All @@ -177,6 +184,7 @@ export function mapNormalizedMoveModule(
name: friend.name,
})) ?? [],
structs,
enums: module.enums ? enums : undefined,
exposedFunctions,
};
}
Expand Down Expand Up @@ -295,3 +303,36 @@ export function moveDataToRpcContent(data: MoveData, layout: MoveTypeLayout): Mo

throw new Error('Invalid move data: ' + JSON.stringify(data));
}

export function mapNormalizedMoveEnum(
enumNode: Rpc_Move_Enum_FieldsFragment,
): SuiMoveNormalizedEnum {
return {
abilities: {
abilities:
enumNode.abilities?.map(
(ability) => `${ability[0]}${ability.slice(1).toLowerCase()}` as SuiMoveAbility,
) ?? [],
},
typeParameters:
enumNode.typeParameters?.map((param) => ({
isPhantom: param.isPhantom!,
constraints: {
abilities:
param.constraints?.map(
(constraint) =>
`${constraint[0]}${constraint.slice(1).toLowerCase()}` as SuiMoveAbility,
) ?? [],
},
})) ?? [],
variants: Object.fromEntries(
enumNode.variants?.map((variant) => [
variant.name,
variant.fields?.map((field) => ({
name: field.name,
type: mapOpenMoveType(field.type?.signature),
})) ?? [],
]) ?? [],
),
};
}
1 change: 1 addition & 0 deletions sdk/graphql-transport/src/mappers/transaction-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export function mapGraphQLTransactionBlockToRpcTransactionBlock(
timestampMs: new Date(event.timestamp).getTime().toString(),
transactionModule: `${event.sendingModule?.package.address}::${event.sendingModule?.name}`,
type: toShortTypeString(event.contents.type?.repr)!,
bcsEncoding: 'base64',
})) ?? [],
rawTransaction: options?.showRawInput ? mapRawTransaction(transactionBlock) : undefined,
...(options?.showInput
Expand Down
18 changes: 17 additions & 1 deletion sdk/graphql-transport/src/methods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,11 @@ export const RPC_METHODS: {
let hasMoreFriends = moveModule.friends?.pageInfo.hasNextPage ?? false;
let hasMoreFunctions = moveModule.functions?.pageInfo.hasNextPage ?? false;
let hasMoreStructs = moveModule.structs?.pageInfo.hasNextPage ?? false;
let hasMoreEnums = moveModule.enums?.pageInfo.hasNextPage ?? false;
let afterFriends = moveModule.friends?.pageInfo.endCursor;
let afterFunctions = moveModule.functions?.pageInfo.endCursor;
let afterStructs = moveModule.structs?.pageInfo.endCursor;
let afterEnums = moveModule.enums?.pageInfo.endCursor;

while (hasMoreFriends || hasMoreStructs || hasMoreFunctions) {
const page = await transport.graphqlQuery(
Expand All @@ -339,9 +341,11 @@ export const RPC_METHODS: {
hasMoreFriends,
hasMoreFunctions,
hasMoreStructs,
hasMoreEnums,
afterFriends,
afterFunctions,
afterStructs,
afterEnums,
},
},
(data) => data.object?.asMovePackage?.module,
Expand All @@ -350,12 +354,15 @@ export const RPC_METHODS: {
moveModule.friends.nodes.push(...(page.friends?.nodes ?? []));
moveModule.functions?.nodes.push(...(page.functions?.nodes ?? []));
moveModule.structs?.nodes.push(...(page.structs?.nodes ?? []));
moveModule.enums?.nodes.push(...(page.enums?.nodes ?? []));
hasMoreFriends = page.friends?.pageInfo.hasNextPage ?? false;
hasMoreFunctions = page.functions?.pageInfo.hasNextPage ?? false;
hasMoreStructs = page.structs?.pageInfo.hasNextPage ?? false;
hasMoreEnums = page.enums?.pageInfo.hasNextPage ?? false;
afterFriends = page.friends?.pageInfo.endCursor;
afterFunctions = page.functions?.pageInfo.endCursor;
afterStructs = page.structs?.pageInfo.endCursor;
afterEnums = page.enums?.pageInfo.endCursor;
}
}

Expand All @@ -380,11 +387,13 @@ export const RPC_METHODS: {
let hasMoreFriends = moveModule.friends?.pageInfo.hasNextPage ?? false;
let hasMoreFunctions = moveModule.functions?.pageInfo.hasNextPage ?? false;
let hasMoreStructs = moveModule.structs?.pageInfo.hasNextPage ?? false;
let hasMoreEnums = moveModule.enums?.pageInfo.hasNextPage ?? false;
let afterFriends = moveModule.friends?.pageInfo.endCursor;
let afterFunctions = moveModule.functions?.pageInfo.endCursor;
let afterStructs = moveModule.structs?.pageInfo.endCursor;
let afterEnums = moveModule.enums?.pageInfo.endCursor;

while (hasMoreFriends || hasMoreStructs || hasMoreFunctions) {
while (hasMoreFriends || hasMoreStructs || hasMoreFunctions || hasMoreEnums) {
const page = await transport.graphqlQuery(
{
query: PaginateMoveModuleListsDocument,
Expand All @@ -394,9 +403,11 @@ export const RPC_METHODS: {
hasMoreFriends,
hasMoreFunctions,
hasMoreStructs,
hasMoreEnums,
afterFriends,
afterFunctions,
afterStructs,
afterEnums,
},
},
(data) => data.object?.asMovePackage?.module,
Expand All @@ -405,12 +416,15 @@ export const RPC_METHODS: {
moveModule.friends.nodes.push(...(page.friends?.nodes ?? []));
moveModule.functions?.nodes.push(...(page.functions?.nodes ?? []));
moveModule.structs?.nodes.push(...(page.structs?.nodes ?? []));
moveModule.enums?.nodes.push(...(page.enums?.nodes ?? []));
hasMoreFriends = page.friends?.pageInfo.hasNextPage ?? false;
hasMoreFunctions = page.functions?.pageInfo.hasNextPage ?? false;
hasMoreStructs = page.structs?.pageInfo.hasNextPage ?? false;
hasMoreEnums = page.enums?.pageInfo.hasNextPage ?? false;
afterFriends = page.friends?.pageInfo.endCursor;
afterFunctions = page.functions?.pageInfo.endCursor;
afterStructs = page.structs?.pageInfo.endCursor;
afterEnums = page.enums?.pageInfo.endCursor;
}

return mapNormalizedMoveModule(moveModule, normalizeSuiAddress(pkg));
Expand Down Expand Up @@ -889,6 +903,7 @@ export const RPC_METHODS: {
nextCursor: (pagination.last ? pageInfo.startCursor : pageInfo.endCursor) as never,
data: events.map((event) => ({
bcs: event.contents.bcs,
bcsEncoding: 'base64',
id: {
eventSeq: '', // TODO
txDigest: '', // TODO
Expand Down Expand Up @@ -975,6 +990,7 @@ export const RPC_METHODS: {
return {
data: fields.map((field) => ({
bcsName: field.name?.bcs && toBase58(fromBase64(field.name.bcs)),
bcsEncoding: 'base58',
digest: (field.value?.__typename === 'MoveObject' ? field.value.digest : undefined)!,
name: {
type: toShortTypeString(field.name?.type.repr)!,
Expand Down
38 changes: 38 additions & 0 deletions sdk/graphql-transport/src/queries/getNormalizedMoveModule.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ query paginateMoveModuleLists(
$hasMoreFriends: Boolean!
$hasMoreStructs: Boolean!
$hasMoreFunctions: Boolean!
$hasMoreEnums: Boolean!
$afterFriends: String
$afterStructs: String
$afterFunctions: String
$afterEnums: String
) {
object(address: $packageId) {
asMovePackage {
Expand All @@ -45,6 +47,15 @@ query paginateMoveModuleLists(
...RPC_MOVE_STRUCT_FIELDS
}
}
enums(after: $afterEnums) @include(if: $hasMoreEnums) {
pageInfo {
hasNextPage
endCursor
}
nodes {
...RPC_MOVE_ENUM_FIELDS
}
}
functions(after: $afterFunctions) @include(if: $hasMoreFunctions) {
pageInfo {
hasNextPage
Expand Down Expand Up @@ -82,6 +93,15 @@ fragment RPC_MOVE_MODULE_FIELDS on MoveModule {
...RPC_MOVE_STRUCT_FIELDS
}
}
enums {
pageInfo {
hasNextPage
endCursor
}
nodes {
...RPC_MOVE_ENUM_FIELDS
}
}
fileFormatVersion
functions {
pageInfo {
Expand All @@ -93,3 +113,21 @@ fragment RPC_MOVE_MODULE_FIELDS on MoveModule {
}
}
}

fragment RPC_MOVE_ENUM_FIELDS on MoveEnum {
name
abilities
typeParameters {
isPhantom
constraints
}
variants {
name
fields {
name
type {
signature
}
}
}
}
3 changes: 3 additions & 0 deletions sdk/typescript/scripts/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,9 @@ async function generateTypeReference(
await Promise.all(type.items.map((t) => generateTypeReference(t, namespace))),
);
}
if (!type.items) {
return ts.factory.createTupleTypeNode([]);
}
return ts.factory.createArrayTypeNode(await generateTypeReference(type.items, namespace));
case 'object':
return withDescription(
Expand Down
Loading

0 comments on commit b2928a9

Please sign in to comment.