@@ -161,6 +161,54 @@ func (c Chain) DeployProgram(logger logger.Logger, programInfo ProgramInfo, isUp
161161 return parseProgramID (output , prefix )
162162}
163163
164+ func (c Chain ) SetIDL (logger logger.Logger , programID string , programName string , isUpgrade bool ) error {
165+ if _ , err := exec .LookPath ("anchor" ); err != nil {
166+ logger .Infow ("Skipping setIDL, anchor CLI not installed" , "program" , programName )
167+ }
168+
169+ idlFile := filepath .Join (c .ProgramsPath , ".." , "idl" , programName + ".json" )
170+ if _ , err := os .Stat (idlFile ); err != nil {
171+ return fmt .Errorf ("IDL file not found: %w" , err )
172+ }
173+
174+ // TODO: if isUpgrade
175+ // cliCommand = upgrade
176+
177+ baseArgs := []string {
178+ "idl" ,
179+ "init" ,
180+ "-f" ,
181+ idlFile ,
182+ "--provider.wallet" , c .KeypairPath , // deployer keypair
183+ "--provider.cluster" , c .URL , // rpc url
184+ "--allow-localnet" ,
185+ programID ,
186+ }
187+
188+ cmd := exec .CommandContext (context .TODO (), "anchor" , baseArgs ... ) // #nosec G204
189+ logger .Infof ("Setting IDL with command: %s" , cmd .String ())
190+
191+ // Capture the command output
192+ var stdout , stderr bytes.Buffer
193+ cmd .Stdout = & stdout
194+ cmd .Stderr = & stderr
195+
196+ // Run the command
197+ if err := cmd .Run (); err != nil {
198+ logger .Errorw ("Error setting IDL" ,
199+ "error" , err ,
200+ "stdout" , stdout .String (),
201+ "stderr" , stderr .String ())
202+
203+ return err
204+ }
205+ logger .Infow ("Set IDL" ,
206+ "stdout" , stdout .String (),
207+ "stderr" , stderr .String ())
208+
209+ return nil
210+ }
211+
164212func (c Chain ) GetAccountDataBorshInto (ctx context.Context , pubkey sollib.PublicKey , accountState interface {}) error {
165213 err := solCommonUtil .GetAccountDataBorshInto (ctx , c .Client , pubkey , SolDefaultCommitment , accountState )
166214 if err != nil {
0 commit comments