11/* eslint-disable @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-argument */
22import { ZkProgram } from "o1js" ;
3- import { DependencyContainer , injectable } from "tsyringe" ;
3+ import { container , DependencyContainer , injectable } from "tsyringe" ;
44import {
55 StringKeyOf ,
66 ModuleContainer ,
@@ -11,11 +11,16 @@ import {
1111 PlainZkProgram ,
1212 AreProofsEnabled ,
1313 ChildContainerProvider ,
14+ CompilableModule ,
15+ CompileRegistry ,
1416} from "@proto-kit/common" ;
1517import {
1618 MethodPublicOutput ,
1719 StateServiceProvider ,
1820 SimpleAsyncStateService ,
21+ RuntimeMethodExecutionContext ,
22+ RuntimeTransaction ,
23+ NetworkState ,
1924} from "@proto-kit/protocol" ;
2025
2126import {
@@ -227,9 +232,10 @@ export class RuntimeZkProgrammable<
227232 return buckets ;
228233 } ;
229234
230- return splitRuntimeMethods ( ) . map ( ( bucket ) => {
235+ return splitRuntimeMethods ( ) . map ( ( bucket , index ) => {
236+ const name = `RuntimeProgram-${ index } ` ;
231237 const program = ZkProgram ( {
232- name : "RuntimeProgram" ,
238+ name,
233239 publicOutput : MethodPublicOutput ,
234240 methods : bucket ,
235241 } ) ;
@@ -245,6 +251,7 @@ export class RuntimeZkProgrammable<
245251 ) ;
246252
247253 return {
254+ name,
248255 compile : program . compile . bind ( program ) ,
249256 verify : program . verify . bind ( program ) ,
250257 analyzeMethods : program . analyzeMethods . bind ( program ) ,
@@ -262,7 +269,7 @@ export class RuntimeZkProgrammable<
262269@injectable ( )
263270export class Runtime < Modules extends RuntimeModulesRecord >
264271 extends ModuleContainer < Modules >
265- implements RuntimeEnvironment
272+ implements RuntimeEnvironment , CompilableModule
266273{
267274 public static from < Modules extends RuntimeModulesRecord > (
268275 definition : RuntimeDefinition < Modules >
@@ -375,5 +382,14 @@ export class Runtime<Modules extends RuntimeModulesRecord>
375382 public get runtimeModuleNames ( ) {
376383 return Object . keys ( this . definition . modules ) ;
377384 }
385+
386+ public async compile ( registry : CompileRegistry ) {
387+ const context = container . resolve ( RuntimeMethodExecutionContext ) ;
388+ context . setup ( {
389+ transaction : RuntimeTransaction . dummyTransaction ( ) ,
390+ networkState : NetworkState . empty ( ) ,
391+ } ) ;
392+ return await this . zkProgrammable . compile ( registry ) ;
393+ }
378394}
379395/* eslint-enable @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-argument */
0 commit comments