From 03a7784a594b3ee72ea4ef1676a33c8234899a81 Mon Sep 17 00:00:00 2001 From: Naasir Jusab Date: Wed, 8 May 2024 21:18:16 -0400 Subject: [PATCH] refactor(experimental): graphql: token-2022 extensions: UpdateField --- .../rpc-graphql/src/__tests__/__setup__.ts | 14 ++++++ .../src/__tests__/transaction-tests.ts | 47 +++++++++++++++++++ .../rpc-graphql/src/resolvers/instruction.ts | 7 +++ .../rpc-graphql/src/schema/instruction.ts | 11 +++++ 4 files changed, 79 insertions(+) diff --git a/packages/rpc-graphql/src/__tests__/__setup__.ts b/packages/rpc-graphql/src/__tests__/__setup__.ts index 2661fe043915..c2c4dd1e1e1a 100644 --- a/packages/rpc-graphql/src/__tests__/__setup__.ts +++ b/packages/rpc-graphql/src/__tests__/__setup__.ts @@ -2659,6 +2659,20 @@ export const mockTransactionToken2022AllExtensions = { programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb', stackHeight: null, }, + { + parsed: { + info: { + metadata: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ', + updateAuthority: 'FsHcsGiY43QmZc6yTgwYC1DA5U3ZgycXxn3bd2oBjrEZ', + field: 'newField', + value: 'newValue', + }, + type: 'updateTokenMetadataField', + }, + program: 'spl-token', + programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb', + stackHeight: null, + }, // TODO (more) ... ], recentBlockhash: '6vRS7MoToVccMqfQecdVC6UbmARaT5mha91zhreqnce9', diff --git a/packages/rpc-graphql/src/__tests__/transaction-tests.ts b/packages/rpc-graphql/src/__tests__/transaction-tests.ts index 4ecd854575a3..dab4cdef1238 100644 --- a/packages/rpc-graphql/src/__tests__/transaction-tests.ts +++ b/packages/rpc-graphql/src/__tests__/transaction-tests.ts @@ -3607,6 +3607,53 @@ describe('transaction', () => { }, }); }); + + it('update-token-metadata-field', async () => { + expect.assertions(1); + const source = /* GraphQL */ ` + query testQuery($signature: Signature!) { + transaction(signature: $signature) { + message { + instructions { + programId + ... on SplTokenMetadataUpdateField { + field + metadata { + address + } + updateAuthority { + address + } + value + } + } + } + } + } + `; + const result = await rpcGraphQL.query(source, { signature }); + expect(result).toMatchObject({ + data: { + transaction: { + message: { + instructions: expect.arrayContaining([ + { + field: expect.any(String), + metadata: { + address: expect.any(String), + }, + programId: 'TokenzQdBNbLqP5VEhdkAS6EPFLC1PHnBqCXEpPxuEb', + updateAuthority: { + address: expect.any(String), + }, + value: expect.any(String), + }, + ]), + }, + }, + }, + }); + }); }); }); }); diff --git a/packages/rpc-graphql/src/resolvers/instruction.ts b/packages/rpc-graphql/src/resolvers/instruction.ts index 0e80cd3c2c9e..ac01b1dfbb41 100644 --- a/packages/rpc-graphql/src/resolvers/instruction.ts +++ b/packages/rpc-graphql/src/resolvers/instruction.ts @@ -407,6 +407,10 @@ export const instructionResolvers = { mintAuthority: resolveAccount('mintAuthority'), updateAuthority: resolveAccount('updateAuthority'), }, + SplTokenMetadataUpdateField: { + metadata: resolveAccount('metadata'), + updateAuthority: resolveAccount('updateAuthority'), + }, SplTokenMintToCheckedInstruction: { account: resolveAccount('account'), authority: resolveAccount('authority'), @@ -925,6 +929,9 @@ export const instructionResolvers = { if (jsonParsedConfigs.instructionType === 'initializeTokenMetadata') { return 'SplTokenMetadataInitialize'; } + if (jsonParsedConfigs.instructionType === 'updateTokenMetadataField') { + return 'SplTokenMetadataUpdateField'; + } } if (jsonParsedConfigs.programName === 'stake') { if (jsonParsedConfigs.instructionType === 'initialize') { diff --git a/packages/rpc-graphql/src/schema/instruction.ts b/packages/rpc-graphql/src/schema/instruction.ts index 3e047cac40bb..9edf6827f031 100644 --- a/packages/rpc-graphql/src/schema/instruction.ts +++ b/packages/rpc-graphql/src/schema/instruction.ts @@ -1072,6 +1072,17 @@ export const instructionTypeDefs = /* GraphQL */ ` uri: String } + """ + Spl Token Metadata: UpdateField instruction + """ + type SplTokenMetadataUpdateField implements TransactionInstruction { + programId: Address + field: String + metadata: Account + updateAuthority: Account + value: String + } + type Lockup { custodian: Account epoch: Epoch