55using System . Linq ;
66using System . Text ;
77using Solana . Unity . Programs ;
8+ using Solana . Unity . Programs . Utilities ;
89using Solana . Unity . Wallet ;
910using Solana . Unity . Rpc . Models ;
1011using GplSession . Program ;
@@ -16,6 +17,10 @@ namespace Program
1617 public partial class WorldProgram
1718 {
1819 public static readonly PublicKey CpiAuthAddress = new ( "B2f2y3QTBv346wE6nWKor72AUhUvFF6mPk7TWCF2QVhi" ) ;
20+ private static readonly byte [ ] IX_APPLY = new byte [ ] { 248 , 243 , 145 , 24 , 105 , 50 , 162 , 225 } ;
21+ private static readonly byte [ ] IX_APPLY_WITH_DISCRIMINATOR = new byte [ ] { 126 , 75 , 184 , 115 , 193 , 245 , 69 , 15 } ;
22+ private static readonly byte [ ] IX_APPLY_WITH_SESSION = new byte [ ] { 213 , 69 , 29 , 230 , 142 , 107 , 134 , 103 } ;
23+ private static readonly byte [ ] IX_APPLY_WITH_SESSION_AND_DISCRIMINATOR = new byte [ ] { 156 , 187 , 1 , 148 , 179 , 240 , 139 , 27 } ;
1924 public static Solana . Unity . Rpc . Models . TransactionInstruction AddEntity ( AddEntityAccounts accounts , PublicKey programId = null )
2025 {
2126 programId ??= new ( ID ) ;
@@ -221,19 +226,6 @@ public static Solana.Unity.Rpc.Models.TransactionInstruction ApplySystem(
221226 throw new ArgumentException ( "Component IDs and PDAs must be the same length" ) ;
222227 }
223228
224- var discriminators = new List < byte [ ] > ( ) ;
225- foreach ( var entity in systemInput )
226- {
227- if ( sessionToken != null )
228- {
229- discriminators . Add ( Bolt . World . GetDiscriminator ( "global:update_with_session" ) ) ;
230- }
231- else
232- {
233- discriminators . Add ( Bolt . World . GetDiscriminator ( "global:update" ) ) ;
234- }
235- }
236-
237229 Solana . Unity . Rpc . Models . TransactionInstruction instruction ;
238230 if ( sessionToken != null ) {
239231 var apply = new ApplyWithSessionAccounts ( ) {
@@ -243,28 +235,125 @@ public static Solana.Unity.Rpc.Models.TransactionInstruction ApplySystem(
243235 World = world ,
244236 SessionToken = sessionToken ,
245237 } ;
246- instruction = ApplyWithSession ( apply , Bolt . World . GetDiscriminator ( "global:bolt_execute" ) , discriminators . ToArray ( ) , args , programId ) ;
238+ instruction = ApplyWithSession ( apply , args , programId ) ;
247239 } else {
248240 var apply = new ApplyAccounts ( ) {
249241 BoltSystem = system ,
250242 Authority = authority ,
251243 CpiAuth = CpiAuthAddress ,
252244 World = world ,
253245 } ;
254- instruction = Apply ( apply , Bolt . World . GetDiscriminator ( "global:bolt_execute" ) , discriminators . ToArray ( ) , args , programId ) ;
246+ instruction = Apply ( apply , args , programId ) ;
255247 }
256248 for ( int i = 0 ; i < componentIds . Count ; i ++ ) {
257249 instruction . Keys . Add ( AccountMeta . ReadOnly ( componentIds [ i ] , false ) ) ;
258250 instruction . Keys . Add ( AccountMeta . Writable ( componentPdas [ i ] , false ) ) ;
259251 }
260252
261- if ( componentIds . Count > 0 ) {
262- // program id delimits the end of the component list
263- instruction . Keys . Add ( AccountMeta . ReadOnly ( new PublicKey ( WorldProgram . ID ) , false ) ) ;
264- }
265-
266253 return instruction ;
267254 }
255+
256+ public static Solana . Unity . Rpc . Models . TransactionInstruction Apply ( ApplyAccounts accounts , byte [ ] args , PublicKey programId = null )
257+ {
258+ programId ??= new ( ID ) ;
259+ List < Solana . Unity . Rpc . Models . AccountMeta > keys = new ( )
260+ {
261+ Solana . Unity . Rpc . Models . AccountMeta . ReadOnly ( accounts . BoltSystem , false ) ,
262+ Solana . Unity . Rpc . Models . AccountMeta . ReadOnly ( accounts . Authority , true ) ,
263+ Solana . Unity . Rpc . Models . AccountMeta . ReadOnly ( accounts . CpiAuth , false ) ,
264+ Solana . Unity . Rpc . Models . AccountMeta . ReadOnly ( accounts . World , false )
265+ } ;
266+ byte [ ] _data = new byte [ 1200 ] ;
267+ int offset = 0 ;
268+ _data . WriteSpan ( IX_APPLY , offset ) ;
269+ offset += 8 ;
270+ _data . WriteS32 ( args . Length , offset ) ;
271+ offset += 4 ;
272+ _data . WriteSpan ( args , offset ) ;
273+ offset += args . Length ;
274+ byte [ ] resultData = new byte [ offset ] ;
275+ Array . Copy ( _data , resultData , offset ) ;
276+ return new Solana . Unity . Rpc . Models . TransactionInstruction { Keys = keys , ProgramId = programId . KeyBytes , Data = resultData } ;
277+ }
278+
279+ public static Solana . Unity . Rpc . Models . TransactionInstruction ApplyWithDiscriminator ( ApplyAccounts accounts , byte [ ] system_discriminator , byte [ ] args , PublicKey programId = null )
280+ {
281+ programId ??= new ( ID ) ;
282+ List < Solana . Unity . Rpc . Models . AccountMeta > keys = new ( )
283+ {
284+ Solana . Unity . Rpc . Models . AccountMeta . ReadOnly ( accounts . BoltSystem , false ) ,
285+ Solana . Unity . Rpc . Models . AccountMeta . ReadOnly ( accounts . Authority , true ) ,
286+ Solana . Unity . Rpc . Models . AccountMeta . ReadOnly ( accounts . CpiAuth , false ) ,
287+ Solana . Unity . Rpc . Models . AccountMeta . ReadOnly ( accounts . World , false )
288+ } ;
289+ byte [ ] _data = new byte [ 1200 ] ;
290+ int offset = 0 ;
291+ _data . WriteSpan ( IX_APPLY_WITH_DISCRIMINATOR , offset ) ;
292+ offset += 8 ;
293+ _data . WriteS32 ( system_discriminator . Length , offset ) ;
294+ offset += 4 ;
295+ _data . WriteSpan ( system_discriminator , offset ) ;
296+ offset += system_discriminator . Length ;
297+ _data . WriteS32 ( args . Length , offset ) ;
298+ offset += 4 ;
299+ _data . WriteSpan ( args , offset ) ;
300+ offset += args . Length ;
301+ byte [ ] resultData = new byte [ offset ] ;
302+ Array . Copy ( _data , resultData , offset ) ;
303+ return new Solana . Unity . Rpc . Models . TransactionInstruction { Keys = keys , ProgramId = programId . KeyBytes , Data = resultData } ;
304+ }
305+
306+ public static Solana . Unity . Rpc . Models . TransactionInstruction ApplyWithSession ( ApplyWithSessionAccounts accounts , byte [ ] args , PublicKey programId = null )
307+ {
308+ programId ??= new ( ID ) ;
309+ List < Solana . Unity . Rpc . Models . AccountMeta > keys = new ( )
310+ {
311+ Solana . Unity . Rpc . Models . AccountMeta . ReadOnly ( accounts . BoltSystem , false ) ,
312+ Solana . Unity . Rpc . Models . AccountMeta . ReadOnly ( accounts . Authority , true ) ,
313+ Solana . Unity . Rpc . Models . AccountMeta . ReadOnly ( accounts . CpiAuth , false ) ,
314+ Solana . Unity . Rpc . Models . AccountMeta . ReadOnly ( accounts . World , false ) ,
315+ Solana . Unity . Rpc . Models . AccountMeta . ReadOnly ( accounts . SessionToken , false )
316+ } ;
317+ byte [ ] _data = new byte [ 1200 ] ;
318+ int offset = 0 ;
319+ _data . WriteSpan ( IX_APPLY_WITH_SESSION , offset ) ;
320+ offset += 8 ;
321+ _data . WriteS32 ( args . Length , offset ) ;
322+ offset += 4 ;
323+ _data . WriteSpan ( args , offset ) ;
324+ offset += args . Length ;
325+ byte [ ] resultData = new byte [ offset ] ;
326+ Array . Copy ( _data , resultData , offset ) ;
327+ return new Solana . Unity . Rpc . Models . TransactionInstruction { Keys = keys , ProgramId = programId . KeyBytes , Data = resultData } ;
328+ }
329+
330+ public static Solana . Unity . Rpc . Models . TransactionInstruction ApplyWithSessionAndDiscriminator ( ApplyWithSessionAccounts accounts , byte [ ] system_discriminator , byte [ ] args , PublicKey programId = null )
331+ {
332+ programId ??= new ( ID ) ;
333+ List < Solana . Unity . Rpc . Models . AccountMeta > keys = new ( )
334+ {
335+ Solana . Unity . Rpc . Models . AccountMeta . ReadOnly ( accounts . BoltSystem , false ) ,
336+ Solana . Unity . Rpc . Models . AccountMeta . ReadOnly ( accounts . Authority , true ) ,
337+ Solana . Unity . Rpc . Models . AccountMeta . ReadOnly ( accounts . CpiAuth , false ) ,
338+ Solana . Unity . Rpc . Models . AccountMeta . ReadOnly ( accounts . World , false ) ,
339+ Solana . Unity . Rpc . Models . AccountMeta . ReadOnly ( accounts . SessionToken , false )
340+ } ;
341+ byte [ ] _data = new byte [ 1200 ] ;
342+ int offset = 0 ;
343+ _data . WriteSpan ( IX_APPLY_WITH_SESSION_AND_DISCRIMINATOR , offset ) ;
344+ offset += 8 ;
345+ _data . WriteS32 ( system_discriminator . Length , offset ) ;
346+ offset += 4 ;
347+ _data . WriteSpan ( system_discriminator , offset ) ;
348+ offset += system_discriminator . Length ;
349+ _data . WriteS32 ( args . Length , offset ) ;
350+ offset += 4 ;
351+ _data . WriteSpan ( args , offset ) ;
352+ offset += args . Length ;
353+ byte [ ] resultData = new byte [ offset ] ;
354+ Array . Copy ( _data , resultData , offset ) ;
355+ return new Solana . Unity . Rpc . Models . TransactionInstruction { Keys = keys , ProgramId = programId . KeyBytes , Data = resultData } ;
356+ }
268357 }
269358 }
270359}
0 commit comments