1- import {
2- InstructionAccountNode ,
3- InstructionInputValueNode ,
4- InstructionNode ,
5- pascalCase ,
6- ProgramNode ,
7- } from '@codama/nodes' ;
8- import { LinkableDictionary } from '@codama/visitors-core' ;
1+ import { InstructionAccountNode , InstructionInputValueNode , InstructionNode , pascalCase } from '@codama/nodes' ;
2+ import { LinkableDictionary , NodeStack } from '@codama/visitors-core' ;
93
104import type { GlobalFragmentScope } from '../getRenderMapVisitor' ;
115import { ImportMap } from '../ImportMap' ;
@@ -16,10 +10,10 @@ export function getInstructionAccountTypeParamFragment(
1610 allowAccountMeta : boolean ;
1711 instructionAccountNode : InstructionAccountNode ;
1812 instructionNode : InstructionNode ;
19- programNode : ProgramNode ;
13+ instructionStack : NodeStack ;
2014 } ,
2115) : Fragment {
22- const { instructionNode, instructionAccountNode, programNode , allowAccountMeta, linkables } = scope ;
16+ const { instructionNode, instructionAccountNode, instructionStack , allowAccountMeta, linkables } = scope ;
2317 const typeParam = `TAccount${ pascalCase ( instructionAccountNode . name ) } ` ;
2418 const accountMeta = allowAccountMeta ? ' | IAccountMeta<string>' : '' ;
2519 const imports = new ImportMap ( ) ;
@@ -31,7 +25,11 @@ export function getInstructionAccountTypeParamFragment(
3125 return fragment ( `${ typeParam } extends string${ accountMeta } | undefined = undefined` , imports ) ;
3226 }
3327
34- const defaultAddress = getDefaultAddress ( instructionAccountNode . defaultValue , programNode . publicKey , linkables ) ;
28+ const defaultAddress = getDefaultAddress (
29+ instructionAccountNode . defaultValue ,
30+ instructionStack . getProgram ( ) ! . publicKey ,
31+ linkables ,
32+ ) ;
3533
3634 return fragment ( `${ typeParam } extends string${ accountMeta } = ${ defaultAddress } ` , imports ) ;
3735}
@@ -45,8 +43,9 @@ function getDefaultAddress(
4543 case 'publicKeyValueNode' :
4644 return `"${ defaultValue . publicKey } "` ;
4745 case 'programLinkNode' :
46+ // FIXME(loris): No need for a stack here.
4847 // eslint-disable-next-line no-case-declarations
49- const programNode = linkables . get ( defaultValue ) ;
48+ const programNode = linkables . get ( defaultValue , new NodeStack ( ) ) ;
5049 return programNode ? `"${ programNode . publicKey } "` : 'string' ;
5150 case 'programIdValueNode' :
5251 return `"${ programId } "` ;
0 commit comments