Skip to content

Commit

Permalink
refactor(experimental): graphql: token-2022 extensions: UpdateField (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
nasjuice authored May 9, 2024
1 parent d525f91 commit b7aa602
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/rpc-graphql/src/__tests__/__setup__.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
47 changes: 47 additions & 0 deletions packages/rpc-graphql/src/__tests__/transaction-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
]),
},
},
},
});
});
});
});
});
7 changes: 7 additions & 0 deletions packages/rpc-graphql/src/resolvers/instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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') {
Expand Down
11 changes: 11 additions & 0 deletions packages/rpc-graphql/src/schema/instruction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b7aa602

Please sign in to comment.