|
1 | 1 | import { ProgramNode, programNode, ProgramVersion } from '@codama/nodes'; |
2 | 2 |
|
3 | | -import { accountNodeFromAnchorV01WithTypeDefinition } from './AccountNode'; |
| 3 | +import { accountNodeFromAnchorV01 } from './AccountNode'; |
4 | 4 | import { definedTypeNodeFromAnchorV01 } from './DefinedTypeNode'; |
5 | 5 | import { errorNodeFromAnchorV01 } from './ErrorNode'; |
6 | 6 | import { IdlV01 } from './idl'; |
7 | 7 | import { instructionNodeFromAnchorV01 } from './InstructionNode'; |
| 8 | +import { extractGenerics } from './unwrapGenerics'; |
8 | 9 |
|
9 | 10 | export function programNodeFromAnchorV01(idl: IdlV01): ProgramNode { |
10 | | - const types = idl.types ?? []; |
| 11 | + const [types, generics] = extractGenerics(idl.types ?? []); |
11 | 12 | const accounts = idl.accounts ?? []; |
12 | 13 | const instructions = idl.instructions ?? []; |
13 | 14 | const errors = idl.errors ?? []; |
14 | 15 |
|
15 | 16 | const filteredTypes = types.filter(type => !accounts.some(account => account.name === type.name)); |
16 | | - const definedTypes = filteredTypes.map(definedTypeNodeFromAnchorV01); |
17 | | - const accountNodeFromAnchorV01 = accountNodeFromAnchorV01WithTypeDefinition(types); |
18 | | - const accountNodes = accounts.map(accountNodeFromAnchorV01); |
| 17 | + const definedTypes = filteredTypes.map(type => definedTypeNodeFromAnchorV01(type, generics)); |
| 18 | + const accountNodes = accounts.map(account => accountNodeFromAnchorV01(account, types, generics)); |
19 | 19 |
|
20 | 20 | return programNode({ |
21 | 21 | accounts: accountNodes, |
22 | 22 | definedTypes, |
23 | 23 | errors: errors.map(errorNodeFromAnchorV01), |
24 | | - instructions: instructions.map(instruction => instructionNodeFromAnchorV01(accountNodes, instruction)), |
| 24 | + instructions: instructions.map(instruction => |
| 25 | + instructionNodeFromAnchorV01(accountNodes, instruction, generics), |
| 26 | + ), |
25 | 27 | name: idl.metadata.name, |
26 | 28 | origin: 'anchor', |
27 | 29 | publicKey: idl.address, |
|
0 commit comments