Skip to content

Commit

Permalink
fix: purge accounts from types before generating definedTypes so it d…
Browse files Browse the repository at this point in the history
…oes not cause duplicate definitions in generated clients.
  • Loading branch information
kespinola committed May 17, 2024
1 parent 46bfc2d commit 2d3fe1d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 2 additions & 2 deletions packages/nodes-from-anchor/src/v01/ProgramNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ export function programNodeFromAnchorV01(idl: IdlV01): ProgramNode {
const instructions = idl.instructions ?? [];
const errors = idl.errors ?? [];

const definedTypes = types.map(definedTypeNodeFromAnchorV01);
const filteredTypes = types.filter(type => !accounts.some(account => account.name === type.name));
const definedTypes = filteredTypes.map(definedTypeNodeFromAnchorV01);
const accountNodeFromAnchorV01 = accountNodeFromAnchorV01WithTypeDefinition(types);
const pdas = instructions
.flatMap<IdlV01InstructionAccount>(instruction => instruction.accounts)
.filter(account => !!account.pda && !account.pda?.program)
.map(pdaNodeFromAnchorV01);

return programNode({
accounts: accounts.map(accountNodeFromAnchorV01),
definedTypes,
Expand Down
3 changes: 1 addition & 2 deletions packages/nodes-from-anchor/test/v01/ProgramNode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {
accountNode,
bytesTypeNode,
constantPdaSeedNode,
definedTypeNode,
errorNode,
fieldDiscriminatorNode,
instructionAccountNode,
Expand Down Expand Up @@ -65,7 +64,7 @@ test('it creates program nodes', () => {
name: 'myAccount',
}),
],
definedTypes: [definedTypeNode({ name: 'myAccount', type: structTypeNode([]) })],
definedTypes: [],
errors: [
errorNode({
code: 42,
Expand Down

0 comments on commit 2d3fe1d

Please sign in to comment.