@midnightntwrk/compact-js-command 0.0.0-stage → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. package/LICENSE +14 -0
  2. package/README.md +263 -2
  3. package/dist/dts/effect/CompiledContractReflection.d.ts +66 -0
  4. package/dist/dts/effect/CompiledContractReflection.d.ts.map +1 -0
  5. package/dist/dts/effect/ConfigCompilationError.d.ts +38 -0
  6. package/dist/dts/effect/ConfigCompilationError.d.ts.map +1 -0
  7. package/dist/dts/effect/ConfigCompiler.d.ts +63 -0
  8. package/dist/dts/effect/ConfigCompiler.d.ts.map +1 -0
  9. package/dist/dts/effect/ConfigError.d.ts +34 -0
  10. package/dist/dts/effect/ConfigError.d.ts.map +1 -0
  11. package/dist/dts/effect/index.d.ts +73 -0
  12. package/dist/dts/effect/index.d.ts.map +1 -0
  13. package/dist/dts/effect/internal/args.d.ts +7 -0
  14. package/dist/dts/effect/internal/args.d.ts.map +1 -0
  15. package/dist/dts/effect/internal/circuitCommand.d.ts +2 -0
  16. package/dist/dts/effect/internal/circuitCommand.d.ts.map +1 -0
  17. package/dist/dts/effect/internal/command.d.ts +98 -0
  18. package/dist/dts/effect/internal/command.d.ts.map +1 -0
  19. package/dist/dts/effect/internal/commandConfigProvider.d.ts +2 -0
  20. package/dist/dts/effect/internal/commandConfigProvider.d.ts.map +1 -0
  21. package/dist/dts/effect/internal/compiledContractReflection.d.ts +5 -0
  22. package/dist/dts/effect/internal/compiledContractReflection.d.ts.map +1 -0
  23. package/dist/dts/effect/internal/deployCommand.d.ts +2 -0
  24. package/dist/dts/effect/internal/deployCommand.d.ts.map +1 -0
  25. package/dist/dts/effect/internal/encodedZswapLocalStateSchema.d.ts +129 -0
  26. package/dist/dts/effect/internal/encodedZswapLocalStateSchema.d.ts.map +1 -0
  27. package/dist/dts/effect/internal/era/binding.d.ts +270 -0
  28. package/dist/dts/effect/internal/era/binding.d.ts.map +1 -0
  29. package/dist/dts/effect/internal/era/eras.d.ts +16 -0
  30. package/dist/dts/effect/internal/era/eras.d.ts.map +1 -0
  31. package/dist/dts/effect/internal/era/registry.d.ts +2 -0
  32. package/dist/dts/effect/internal/era/registry.d.ts.map +1 -0
  33. package/dist/dts/effect/internal/era/v8.d.ts +2 -0
  34. package/dist/dts/effect/internal/era/v8.d.ts.map +1 -0
  35. package/dist/dts/effect/internal/era/v9.d.ts +2 -0
  36. package/dist/dts/effect/internal/era/v9.d.ts.map +1 -0
  37. package/dist/dts/effect/internal/json.d.ts +2 -0
  38. package/dist/dts/effect/internal/json.d.ts.map +1 -0
  39. package/dist/dts/effect/internal/maintainCircuitCommand.d.ts +2 -0
  40. package/dist/dts/effect/internal/maintainCircuitCommand.d.ts.map +1 -0
  41. package/dist/dts/effect/internal/maintainCommand.d.ts +2 -0
  42. package/dist/dts/effect/internal/maintainCommand.d.ts.map +1 -0
  43. package/dist/dts/effect/internal/maintainContractCommand.d.ts +2 -0
  44. package/dist/dts/effect/internal/maintainContractCommand.d.ts.map +1 -0
  45. package/dist/dts/effect/internal/options.d.ts +7 -0
  46. package/dist/dts/effect/internal/options.d.ts.map +1 -0
  47. package/dist/dts/index.d.ts +2 -0
  48. package/dist/dts/index.d.ts.map +1 -0
  49. package/dist/esm/effect/CompiledContractReflection.js +33 -0
  50. package/dist/esm/effect/CompiledContractReflection.js.map +1 -0
  51. package/dist/esm/effect/ConfigCompilationError.js +40 -0
  52. package/dist/esm/effect/ConfigCompilationError.js.map +1 -0
  53. package/dist/esm/effect/ConfigCompiler.js +73 -0
  54. package/dist/esm/effect/ConfigCompiler.js.map +1 -0
  55. package/dist/esm/effect/ConfigError.js +40 -0
  56. package/dist/esm/effect/ConfigError.js.map +1 -0
  57. package/dist/esm/effect/index.js +53 -0
  58. package/dist/esm/effect/index.js.map +1 -0
  59. package/dist/esm/effect/internal/args.js +25 -0
  60. package/dist/esm/effect/internal/args.js.map +1 -0
  61. package/dist/esm/effect/internal/circuitCommand.js +282 -0
  62. package/dist/esm/effect/internal/circuitCommand.js.map +1 -0
  63. package/dist/esm/effect/internal/command.js +316 -0
  64. package/dist/esm/effect/internal/command.js.map +1 -0
  65. package/dist/esm/effect/internal/commandConfigProvider.js +19 -0
  66. package/dist/esm/effect/internal/commandConfigProvider.js.map +1 -0
  67. package/dist/esm/effect/internal/compiledContractReflection.js +296 -0
  68. package/dist/esm/effect/internal/compiledContractReflection.js.map +1 -0
  69. package/dist/esm/effect/internal/deployCommand.js +68 -0
  70. package/dist/esm/effect/internal/deployCommand.js.map +1 -0
  71. package/dist/esm/effect/internal/encodedZswapLocalStateSchema.js +51 -0
  72. package/dist/esm/effect/internal/encodedZswapLocalStateSchema.js.map +1 -0
  73. package/dist/esm/effect/internal/era/binding.js +16 -0
  74. package/dist/esm/effect/internal/era/binding.js.map +1 -0
  75. package/dist/esm/effect/internal/era/eras.js +50 -0
  76. package/dist/esm/effect/internal/era/eras.js.map +1 -0
  77. package/dist/esm/effect/internal/era/registry.js +46 -0
  78. package/dist/esm/effect/internal/era/registry.js.map +1 -0
  79. package/dist/esm/effect/internal/era/v8.js +75 -0
  80. package/dist/esm/effect/internal/era/v8.js.map +1 -0
  81. package/dist/esm/effect/internal/era/v9.js +61 -0
  82. package/dist/esm/effect/internal/era/v9.js.map +1 -0
  83. package/dist/esm/effect/internal/json.js +41 -0
  84. package/dist/esm/effect/internal/json.js.map +1 -0
  85. package/dist/esm/effect/internal/maintainCircuitCommand.js +62 -0
  86. package/dist/esm/effect/internal/maintainCircuitCommand.js.map +1 -0
  87. package/dist/esm/effect/internal/maintainCommand.js +35 -0
  88. package/dist/esm/effect/internal/maintainCommand.js.map +1 -0
  89. package/dist/esm/effect/internal/maintainContractCommand.js +64 -0
  90. package/dist/esm/effect/internal/maintainContractCommand.js.map +1 -0
  91. package/dist/esm/effect/internal/options.js +137 -0
  92. package/dist/esm/effect/internal/options.js.map +1 -0
  93. package/dist/esm/index.js +44 -0
  94. package/dist/esm/index.js.map +1 -0
  95. package/dist/esm/package.json +4 -0
  96. package/effect/CompiledContractReflection/package.json +5 -0
  97. package/effect/ConfigCompilationError/package.json +5 -0
  98. package/effect/ConfigCompiler/package.json +5 -0
  99. package/effect/ConfigError/package.json +5 -0
  100. package/effect/index/package.json +5 -0
  101. package/effect/package.json +5 -0
  102. package/package.json +96 -4
@@ -0,0 +1,2 @@
1
+ export * from './effect/index.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AA+DA,cAAc,mBAAmB,CAAC"}
@@ -0,0 +1,33 @@
1
+ /*
2
+ * This file is part of midnight-sdk.
3
+ * Copyright (C) 2025 Midnight Foundation
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * You may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import { Context } from 'effect';
16
+ import * as internal from './internal/compiledContractReflection.js';
17
+ /**
18
+ * Provides utilities for inspecting a compiled Compact contract.
19
+ *
20
+ * @category services
21
+ */
22
+ export class CompiledContractReflection extends Context.Tag('compact-js-command/CompiledContractReflection')() {
23
+ }
24
+ /**
25
+ * A {@link CompiledContractReflection} implementation that uses a TypeScript declaration file (*.d.ts) produced
26
+ * by the Compact compiler, to reflect over an associated contract's types.
27
+ *
28
+ * @param baseAssetFolderPath A base path to a folder containing the compiled contract assets.
29
+ *
30
+ * @category layers
31
+ */
32
+ export const layer = internal.layer;
33
+ //# sourceMappingURL=CompiledContractReflection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CompiledContractReflection.js","sourceRoot":"","sources":["../../../src/effect/CompiledContractReflection.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAKH,OAAO,EAAE,OAAO,EAA0B,MAAM,QAAQ,CAAC;AAEzD,OAAO,KAAK,QAAQ,MAAM,0CAA0C,CAAC;AAErE;;;;GAIG;AACH,MAAM,OAAO,0BAA2B,SAAQ,OAAO,CAAC,GAAG,CAAC,+CAA+C,CAAC,EAGzG;CAAG;AAsDN;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,KAAK,GAId,QAAQ,CAAC,KAAK,CAAC"}
@@ -0,0 +1,40 @@
1
+ /*
2
+ * This file is part of midnight-sdk.
3
+ * Copyright (C) 2025 Midnight Foundation
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * You may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import * as Error from '@effect/platform/Error';
16
+ import { hasProperty } from 'effect/Predicate';
17
+ const TypeId = Symbol.for('compact-js-command/effect/ConfigCompilationError');
18
+ /**
19
+ * An error occurred while compiling the contract configuration file.
20
+ *
21
+ * @category errors
22
+ */
23
+ export class ConfigCompilationError extends Error.TypeIdError(TypeId, 'ConfigCompilationError') {
24
+ }
25
+ /**
26
+ * Determines if a value is a config compilation error.
27
+ *
28
+ * @param u The value to check.
29
+ * @returns `true` if `u` is a {@link ConfigCompilationError}; `false` otherwise.
30
+ *
31
+ * @category guards
32
+ */
33
+ export const isConfigCompilationError = (u) => hasProperty(u, TypeId);
34
+ /**
35
+ * Creates a new {@link ConfigCompilationError}.
36
+ *
37
+ * @category constructors
38
+ */
39
+ export const make = (message, diagnostics) => new ConfigCompilationError({ message, diagnostics });
40
+ //# sourceMappingURL=ConfigCompilationError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigCompilationError.js","sourceRoot":"","sources":["../../../src/effect/ConfigCompilationError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,KAAK,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,MAAM,GAAkB,MAAM,CAAC,GAAG,CAAC,kDAAkD,CAAC,CAAC;AAG7F;;;;GAIG;AACH,MAAM,OAAO,sBAAuB,SAAQ,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,wBAAwB,CAK5F;CAAI;AAEN;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,CAAU,EAA+B,EAAE,CAAC,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAE5G;;;;GAIG;AACH,MAAM,CAAC,MAAM,IAAI,GACf,CAAC,OAAO,EAAE,WAAW,EAAE,EAAE,CAAC,IAAI,sBAAsB,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,CAAC,CAAC"}
@@ -0,0 +1,73 @@
1
+ /*
2
+ * This file is part of midnight-sdk.
3
+ * Copyright (C) 2025 Midnight Foundation
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * You may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import { FileSystem, Path } from '@effect/platform';
16
+ import { Context, Effect, Layer, Option } from 'effect';
17
+ import { create } from 'ts-node';
18
+ import * as ConfigCompilationError from './ConfigCompilationError.js';
19
+ import * as ConfigError from './ConfigError.js';
20
+ /**
21
+ * Compiles a contract configuration file into a JavaScript module.
22
+ *
23
+ * @category services
24
+ */
25
+ export class ConfigCompiler extends Context.Tag('compact-js-command/ConfigCompiler')() {
26
+ }
27
+ /**
28
+ * A {@link ConfigCompiler} implementation that uses TypeScript to compile the given file path and then load
29
+ * it as a JavaScript module.
30
+ *
31
+ * @category layers
32
+ */
33
+ export const layer = Layer.effect(ConfigCompiler, Effect.gen(function* () {
34
+ const path = yield* Path.Path;
35
+ const fs = yield* FileSystem.FileSystem;
36
+ const getFilePathProperties = (filePath) => Effect.gen(function* () {
37
+ const absoluteFilePath = path.resolve(filePath);
38
+ const parsedAbsoluteFilePath = path.parse(absoluteFilePath);
39
+ const absoluteFileImportPath = path.join(parsedAbsoluteFilePath.dir, `${parsedAbsoluteFilePath.name}.js`);
40
+ const filePathModifiedTime = (yield* fs.stat(absoluteFilePath)).mtime;
41
+ const fileImportPathModifiedTime = (yield* fs.exists(absoluteFileImportPath))
42
+ ? (yield* fs.stat(absoluteFileImportPath)).mtime
43
+ : Option.some(Option.getOrThrow(filePathModifiedTime));
44
+ return {
45
+ absoluteFilePath,
46
+ absoluteWorkingDirectory: parsedAbsoluteFilePath.dir,
47
+ absoluteFileImportPath,
48
+ requiresCompilation: Option.getOrThrow(fileImportPathModifiedTime) <= Option.getOrThrow(filePathModifiedTime)
49
+ };
50
+ });
51
+ const transpileTypeScript = ({ absoluteFilePath, absoluteFileImportPath, absoluteWorkingDirectory, requiresCompilation }) => Effect.gen(function* () {
52
+ if (!requiresCompilation) {
53
+ return absoluteFileImportPath;
54
+ }
55
+ try {
56
+ const tsNodeService = create({ cwd: absoluteWorkingDirectory });
57
+ yield* fs.writeFileString(absoluteFileImportPath, tsNodeService.compile(yield* fs.readFileString(absoluteFilePath), absoluteFilePath));
58
+ }
59
+ catch (err) { // eslint-disable-line @typescript-eslint/no-explicit-any
60
+ return yield* err?.name === 'TSError'
61
+ ? ConfigCompilationError.make('Failed to compile TypeScript configuration', err.diagnostics)
62
+ : ConfigError.make('Unexpected error while compiling TypeScript configuration', err);
63
+ }
64
+ return absoluteFileImportPath;
65
+ });
66
+ return ConfigCompiler.of({
67
+ compile: (filePath) => getFilePathProperties(filePath).pipe(Effect.flatMap(transpileTypeScript), Effect.flatMap((fileImportPath) => Effect.tryPromise(async () => ({
68
+ moduleImportDirectoryPath: path.dirname(fileImportPath),
69
+ module: await import(fileImportPath)
70
+ }))), Effect.mapError((err) => ConfigError.make(`Error loading configuration '${filePath}'`, err)))
71
+ });
72
+ }));
73
+ //# sourceMappingURL=ConfigCompiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigCompiler.js","sourceRoot":"","sources":["../../../src/effect/ConfigCompiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,UAAU,EAAC,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,OAAO,KAAK,sBAAsB,MAAM,6BAA6B,CAAC;AACtE,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC;AAGhD;;;;GAIG;AACH,MAAM,OAAO,cAAe,SAAQ,OAAO,CAAC,GAAG,CAAC,mCAAmC,CAAC,EAGjF;CAAG;AAiDN;;;;;GAKG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG,KAAK,CAAC,MAAM,CAC/B,cAAc,EACd,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC;IAClB,MAAM,IAAI,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;IAC9B,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC;IAExC,MAAM,qBAAqB,GAAG,CAAC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foundation
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * You may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import * as Error from '@effect/platform/Error';
16
+ import { hasProperty } from 'effect/Predicate';
17
+ const TypeId = Symbol.for('compact-js-command/effect/ConfigError');
18
+ /**
19
+ * An error occurred while reading or processing the contract configuration file.
20
+ *
21
+ * @category errors
22
+ */
23
+ export class ConfigError extends Error.TypeIdError(TypeId, 'ConfigError') {
24
+ }
25
+ /**
26
+ * Determines if a value is a configuration error.
27
+ *
28
+ * @param u The value to check.
29
+ * @returns `true` if `u` is a {@link ConfigError}; `false` otherwise.
30
+ *
31
+ * @category guards
32
+ */
33
+ export const isConfigError = (u) => hasProperty(u, TypeId);
34
+ /**
35
+ * Creates a new {@link ConfigError}.
36
+ *
37
+ * @category constructors
38
+ */
39
+ export const make = (message, cause) => new ConfigError({ message, cause });
40
+ //# sourceMappingURL=ConfigError.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigError.js","sourceRoot":"","sources":["../../../src/effect/ConfigError.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,KAAK,MAAM,wBAAwB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C,MAAM,MAAM,GAAkB,MAAM,CAAC,GAAG,CAAC,uCAAuC,CAAC,CAAC;AAGlF;;;;GAIG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK,CAAC,WAAW,CAAC,MAAM,EAAE,aAAa,CAKtE;CAAI;AAEN;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,CAAU,EAAoB,EAAE,CAAC,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAEtF;;;;GAIG;AACH,MAAM,CAAC,MAAM,IAAI,GAAsD,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CACxF,IAAI,WAAW,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC"}
@@ -0,0 +1,53 @@
1
+ /*
2
+ * This file is part of midnight-sdk.
3
+ * Copyright (C) 2025 Midnight Foundation
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * You may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import { Command } from '@effect/cli';
16
+ import * as InternalCircuitCommand from './internal/circuitCommand.js';
17
+ import * as InternalCommand from './internal/command.js';
18
+ import * as InternalDeployCommand from './internal/deployCommand.js';
19
+ import * as InternalEraRegistry from './internal/era/registry.js';
20
+ import * as InternalMaintainCircuitCommand from './internal/maintainCircuitCommand.js';
21
+ import * as InternalMaintainContractCommand from './internal/maintainContractCommand.js';
22
+ // Each command is handed a *selector* rather than a handler: the handler is chosen by the
23
+ // `--ledger-era` the invocation carries, out of that era's application of the handler factories
24
+ // (`internal/era/v8.ts`, `internal/era/v9.ts`). This module is the composition root for that choice
25
+ // and the only one that imports the registry, which is what keeps the era modules — they import the
26
+ // command modules — out of a cycle with `internal/command.ts`.
27
+ export const deployCommand = Command.make('deploy', {
28
+ ...InternalCommand.GlobalOptions,
29
+ ...InternalDeployCommand.Options,
30
+ ...InternalDeployCommand.Args
31
+ }).pipe(Command.withDescription('Initialize a new contract instance and returns a ContractDeploy intent for it.'), Command.withHandler(InternalCommand.invocationHandler((ledgerEra) => InternalEraRegistry.forLedgerEra(ledgerEra).deploy)));
32
+ export const circuitCommand = Command.make('circuit', {
33
+ ...InternalCommand.GlobalOptions,
34
+ ...InternalCircuitCommand.Options,
35
+ ...InternalCircuitCommand.Args
36
+ }).pipe(Command.withDescription('Invokes a circuit on a contract instance and returns a ContractCall intent for it.'), Command.withHandler(InternalCommand.invocationHandler((ledgerEra) => InternalEraRegistry.forLedgerEra(ledgerEra).circuit)));
37
+ export const maintainCommand = Command.make('maintain').pipe(Command.withDescription('Performs maintenance operations on deployed contract state and returns a MaintenanceUpdate intent for it.'), Command.withSubcommands([
38
+ Command.make('contract', {
39
+ ...InternalCommand.GlobalOptions,
40
+ ...InternalMaintainContractCommand.Options,
41
+ ...InternalMaintainContractCommand.Args
42
+ }).pipe(Command.withDescription('Updates the Contract Maintenance Authority for deployed contract state and returns a MaintenanceUpdate intent for it.'), Command.withHandler(InternalCommand.invocationHandler((ledgerEra) => InternalEraRegistry.forLedgerEra(ledgerEra).maintainContract))),
43
+ Command.make('circuit', {
44
+ ...InternalCommand.GlobalOptions,
45
+ ...InternalMaintainCircuitCommand.Options,
46
+ ...InternalMaintainCircuitCommand.Args
47
+ }).pipe(Command.withDescription('Updates the circuits associated with deployed contract state and returns a MaintenanceUpdate intent for it.'), Command.withHandler(InternalCommand.invocationHandler((ledgerEra) => InternalEraRegistry.forLedgerEra(ledgerEra).maintainCircuit)))
48
+ ]));
49
+ export * as CompiledContractReflection from './CompiledContractReflection.js';
50
+ export * as ConfigCompilationError from './ConfigCompilationError.js';
51
+ export * as ConfigCompiler from './ConfigCompiler.js';
52
+ export * as ConfigError from './ConfigError.js';
53
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/effect/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,OAA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,UAAU,CAAC,CAAC,IAAI,CACxD,OAAO,CAAC,eAAe,CAAC,2GAA2G,CAAC,EACpI,OAAO,CAAC,eAAe,CAAC;IACtB,OAAO,CAAC,IAAI,CACV,UAAU,EACV;QACE,GAAG,eAAe,CAAC,aAAa;QAChC,GAAG,+BAA+B,CAAC,OAAO;QAC1C,GAAG,+BAA+B,CAAC,IAAI;KACxC,CAAC,CAAC,IAAI,CACL,OAAO,CAAC,eAAe,CAAC,uHAAuH,CAAC,EAChJ,OAAO,CAAC,WAAW,CACjB,eAAe,CAAC,iBAAiB,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,mBAAmB,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,gBAAgB,CAAC,CAC/G,CACF;IACH,OAAO,CAAC,IAAI,CACV,SAAS,EACT;QACE,GAAG,eAAe,CAAC,aAAa;QAChC,GAAG,8BAA8B,CAAC,OAAO;QACzC,GAAG,8BAA8B,CAAC,IAAI;KACvC,CAAC,CAAC,IAAI,CACL,OAAO,CAAC,eAAe,CAAC,6GAA6G,CAAC,EACtI,OAAO,CAAC,WAAW,CACjB,eAAe,CAAC,iBAAiB,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,mBAAmB,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,eAAe,CAAC,CAC9G,CACF;CACJ,CAAC,CACH,CAAC;AAEJ,OAAO,KAAK,0BAA0B,MAAM,iCAAiC,CAAC;AAC9E,OAAO,KAAK,sBAAsB,MAAM,6BAA6B,CAAC;AACtE,OAAO,KAAK,cAAc,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,WAAW,MAAM,kBAAkB,CAAC"}
@@ -0,0 +1,25 @@
1
+ /*
2
+ * This file is part of midnight-sdk.
3
+ * Copyright (C) 2025 Midnight Foundation
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * You may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import { Args } from '@effect/cli';
16
+ import * as ContractAddress from '@midnight-ntwrk/platform-js/effect/ContractAddress';
17
+ import * as SigningKey from '@midnight-ntwrk/platform-js/effect/SigningKey';
18
+ import { Schema } from 'effect';
19
+ export const contractArgs = Args.text({ name: 'arg' }).pipe(Args.withDescription('An argument that will be forwarded (in order), to the constructor or circuit being invoked.'), Args.repeated);
20
+ export const contractAddress = Args.text({ name: 'contract_address' }).pipe(Args.withDescription('A contract address, hex-encoded.'), Args.withSchema(Schema.String.pipe(Schema.fromBrand(ContractAddress.ContractAddress)).annotations({ title: 'contract_address' })));
21
+ export const signingKey = Args.text({ name: 'signing_key' }).pipe(Args.withDescription('A secret signing key, hex-encoded, for the new maintenance authority. Its signature scheme is given by ' +
22
+ '--new-signing-kind.'), Args.withSchema(Schema.String.pipe(Schema.fromBrand(SigningKey.Value)).annotations({ title: 'signing_key' })));
23
+ export const circuitId = Args.text({ name: 'circuit_id' }).pipe(Args.withDescription('A circuit identifier.'));
24
+ export const verifierKeyPath = Args.file({ name: 'vk_path' }).pipe(Args.withDescription('A path to a verifier key.'), Args.optional);
25
+ //# sourceMappingURL=args.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"args.js","sourceRoot":"","sources":["../../../../src/effect/internal/args.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACnC,OAAO,KAAK,eAAe,MAAM,oDAAoD,CAAC;AACtF,OAAO,KAAK,UAAU,MAAM,+CAA+C,CAAC;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEhC,MAAM,CAAC,MAAM,YAAY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,0 +1,282 @@
1
+ /*
2
+ * This file is part of midnight-sdk.
3
+ * Copyright (C) 2025 Midnight Foundation
4
+ * SPDX-License-Identifier: Apache-2.0
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * You may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ * Unless required by applicable law or agreed to in writing, software
10
+ * distributed under the License is distributed on an "AS IS" BASIS,
11
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ * See the License for the specific language governing permissions and
13
+ * limitations under the License.
14
+ */
15
+ import { join } from 'node:path';
16
+ import { FileSystem } from '@effect/platform';
17
+ import { Contract, ContractKeyLocation, ContractRuntimeError } from '@midnightntwrk/compact-js/effect';
18
+ import { Array, Console, Effect, Option } from 'effect';
19
+ import * as CompiledContractReflection from '../CompiledContractReflection.js';
20
+ import * as InternalArgs from './args.js';
21
+ import * as InternalCommand from './command.js';
22
+ import { decodeZswapLocalStateObject, encodeZswapLocalStateObject } from './encodedZswapLocalStateSchema.js';
23
+ import { stringifyCircuitOutput } from './json.js';
24
+ import * as InternalOptions from './options.js';
25
+ /** @internal */
26
+ export const Args = {
27
+ address: InternalArgs.contractAddress,
28
+ circuitId: InternalArgs.circuitId,
29
+ args: InternalArgs.contractArgs
30
+ };
31
+ /**
32
+ * Reads and parses a JSON input file, naming the file in the failure.
33
+ *
34
+ * @remarks
35
+ * `JSON.parse` throws, and both call sites below sit in an `Effect.gen` body or an `Effect.flatMap`
36
+ * callback where a throw is a *defect*: it escapes {@link InternalCommand.invocationHandler}'s
37
+ * `catchAll` and the CLI, running with `disableErrorReporting`, exits non-zero printing nothing.
38
+ * A truncated or empty input file is ordinary — this handler writes `--output-ps` *after*
39
+ * `--output`, so an interrupted run leaves exactly that state behind.
40
+ *
41
+ * @internal
42
+ */
43
+ const readJsonFile = (fs, filePath) => // eslint-disable-line @typescript-eslint/no-explicit-any
44
+ fs.readFileString(filePath).pipe(Effect.flatMap((str) => Effect.try({
45
+ try: () => JSON.parse(str),
46
+ catch: (err) => ContractRuntimeError.make(`'${filePath}' does not contain valid JSON`, err)
47
+ })));
48
+ /**
49
+ * A placeholder block hash for the cross-contract state provider. A {@link
50
+ * FileSystemContractStateProvider} resolves state purely by address and ignores the block hash,
51
+ * but the runtime requires one to be present when a state provider is supplied.
52
+ *
53
+ * @internal
54
+ */
55
+ const PLACEHOLDER_BLOCK_HASH = '0'.repeat(64);
56
+ /** @internal */
57
+ export const Options = {
58
+ inputFilePath: InternalOptions.inputFilePath,
59
+ inputPrivateStateFilePath: InternalOptions.inputPrivateStateFilePath,
60
+ inputZswapLocalStateFilePath: InternalOptions.inputZswapLocalStateFilePath,
61
+ inputLedgerParamsFilePath: InternalOptions.inputLedgerParamsFilePath,
62
+ inputContractStatesDirPath: InternalOptions.inputContractStatesDirPath,
63
+ inputContractModulesDirPath: InternalOptions.inputContractModulesDirPath,
64
+ outputContractStatesDirPath: InternalOptions.outputContractStatesDirPath,
65
+ outputFilePath: InternalOptions.outputFilePath,
66
+ outputPublicFilePath: InternalOptions.outputPublicFilePath,
67
+ outputPrivateStateFilePath: InternalOptions.outputPrivateStateFilePath,
68
+ outputZswapLocalStateFilePath: InternalOptions.outputZswapLocalStateFilePath,
69
+ outputZswapCallsFilePath: InternalOptions.outputZswapCallsFilePath,
70
+ outputResultFilePath: InternalOptions.outputResultFilePath,
71
+ outputEventsFilePath: InternalOptions.outputEventsFilePath
72
+ };
73
+ /**
74
+ * Builds the `circuit` handler for one era.
75
+ *
76
+ * @param ledger The era's `Ledger` facade.
77
+ * @param runtime The compact-runtime facade that era pairs with.
78
+ * @param capabilities What this era can and cannot do; the two options that depend on a capability
79
+ * are rejected up front on an era that lacks it, rather than silently producing an empty result.
80
+ *
81
+ * @internal
82
+ */
83
+ export const makeHandler = (ledger, runtime, capabilities) => {
84
+ const { tryLedger, newIntent, serializeIntent } = InternalCommand.makeIntents(ledger);
85
+ const { makeContractStateProvider, makeContractModuleProvider } = capabilities;
86
+ return ({ address, circuitId, args, inputFilePath, inputPrivateStateFilePath, inputZswapLocalStateFilePath, inputLedgerParamsFilePath, inputContractStatesDirPath, inputContractModulesDirPath, outputContractStatesDirPath, outputFilePath, outputPublicFilePath, outputPrivateStateFilePath, outputZswapLocalStateFilePath, outputZswapCallsFilePath, outputResultFilePath, outputEventsFilePath }, moduleSpec) => Effect.gen(function* () {
87
+ // Both gates are checked before any input is read: an era that cannot honour the option should
88
+ // say so, not read files and then hand back an empty result that reads as "nothing happened".
89
+ // These are the CLI's half of #388's "absent, not present and failing"; the library's half is
90
+ // that such an era's `createExecutionContext` rejects the providers outright and types its event
91
+ // list `never[]`.
92
+ if ((makeContractStateProvider === undefined || makeContractModuleProvider === undefined) &&
93
+ (Option.isSome(inputContractStatesDirPath) ||
94
+ Option.isSome(inputContractModulesDirPath) ||
95
+ Option.isSome(outputContractStatesDirPath))) {
96
+ return yield* ContractRuntimeError.make(`Ledger era ${ledger.era.ledger} has no cross-contract calls, so --contract-states-dir, ` +
97
+ '--contract-modules-dir and --output-contract-states-dir cannot be honoured. Select a later ' +
98
+ 'era with --ledger-era, or drop the option.');
99
+ }
100
+ if (!capabilities.contractEvents && Option.isSome(outputEventsFilePath)) {
101
+ return yield* ContractRuntimeError.make(`Ledger era ${ledger.era.ledger} cannot emit contract log events, so --output-events would ` +
102
+ 'always write an empty list. Select a later era with --ledger-era, or drop the option.');
103
+ }
104
+ // A cross-contract call needs both the callee's state and the module implementing it, so the two
105
+ // directories are supplied together or not at all. Either one alone would surface much later, as
106
+ // a resolution failure that does not name the option that was left out.
107
+ if (Option.isSome(inputContractStatesDirPath) !== Option.isSome(inputContractModulesDirPath)) {
108
+ return yield* ContractRuntimeError.make('--contract-states-dir and --contract-modules-dir must be given together.');
109
+ }
110
+ const fs = yield* FileSystem.FileSystem;
111
+ const { module: { default: contractModule } } = moduleSpec;
112
+ const contractReflector = yield* CompiledContractReflection.CompiledContractReflection;
113
+ const argsParser = yield* contractReflector.createArgumentParser(contractModule.contractExecutable.compiledContract);
114
+ const ledgerContractState = yield* fs.readFile(inputFilePath).pipe(Effect.flatMap(ledger.contractStateFromBytes));
115
+ const rawPrivateState = yield* readJsonFile(fs, inputPrivateStateFilePath);
116
+ // `JSON.parse('null')` returns `null` rather than throwing, so `readJsonFile` cannot catch this
117
+ // one, and `--input-ps` is required (unlike `--input-zswap`): a `null` payload is never the
118
+ // user asking for a fresh state. There is exactly one contract shape for which it is faithful —
119
+ // one whose private state *is* `undefined`, which JSON cannot encode any other way. For every
120
+ // other contract it means the file has lost the state it was meant to carry, and substituting
121
+ // `createInitialPrivateState()` runs the circuit against an invented state, writes a
122
+ // well-formed signed intent, and exits 0: the user finds out on chain, with nothing pointing
123
+ // back at the state file. `createInitialPrivateState()` is the only thing that tells the two
124
+ // apart.
125
+ if (rawPrivateState === null || rawPrivateState === undefined) {
126
+ const initialPrivateState = yield* Effect.try({
127
+ try: () => contractModule.createInitialPrivateState(),
128
+ catch: (err) => ContractRuntimeError.make('Failed to create an initial private state for the contract', err)
129
+ });
130
+ if (initialPrivateState !== undefined) {
131
+ return yield* ContractRuntimeError.make(`'${inputPrivateStateFilePath}' contains no private state (the file holds JSON 'null'), but this ` +
132
+ `contract has one. Supply the private state written by a previous invocation, or the contract's ` +
133
+ `initial private state if it has not run yet.`);
134
+ }
135
+ }
136
+ // Guarded above: `null` here can only be the JSON encoding of a contract with no private state.
137
+ const privateState = rawPrivateState ?? undefined;
138
+ const encodedZswapLocalState = Option.map(inputZswapLocalStateFilePath, (filePath) => readJsonFile(fs, filePath).pipe(Effect.flatMap(decodeZswapLocalStateObject),
139
+ // `EncodedZswapLocalStateSchema` validates shape only — no length constraint on the key or
140
+ // the coin nonces/colours, and `value` is any bigint — so a hand-edited or cross-network
141
+ // file passes it and is rejected by the runtime instead. The decode belongs here, where
142
+ // `filePath` is in scope to name in the failure; left unwrapped in the `Effect.gen` body
143
+ // below it would be a defect, and the CLI would exit non-zero printing nothing at all.
144
+ Effect.flatMap((encoded) => runtime.tryRuntime(`Failed to decode the zswap local state read from '${filePath}'`, () => runtime.decodeZswapLocalState(encoded)))));
145
+ const decodedLedgerParameters = Option.map(inputLedgerParamsFilePath, (filePath) => fs.readFile(filePath).pipe(Effect.flatMap(ledger.parametersFromBytes)));
146
+ // When both directories are supplied, the circuit may make cross-contract calls: each target's
147
+ // state and module are resolved lazily, on demand, from the directories. The providers are built
148
+ // by the *era*, so the states handed to the runtime are decoded by the same conversions this
149
+ // handler uses for `--input`.
150
+ const crossContract = makeContractStateProvider === undefined || makeContractModuleProvider === undefined
151
+ ? Option.none()
152
+ : Option.zipWith(inputContractStatesDirPath, inputContractModulesDirPath, (statesDir, modulesDir) => ({
153
+ stateProvider: makeContractStateProvider(statesDir),
154
+ moduleProvider: makeContractModuleProvider(modulesDir)
155
+ }));
156
+ const baseCircuitContext = {
157
+ address,
158
+ contractState: yield* ledger.toRuntimeContractState(ledgerContractState),
159
+ privateState,
160
+ zswapLocalState: Option.isSome(encodedZswapLocalState)
161
+ ? yield* encodedZswapLocalState.value
162
+ : undefined,
163
+ ledgerParameters: Option.isSome(decodedLedgerParameters)
164
+ ? yield* decodedLedgerParameters.value
165
+ : undefined
166
+ };
167
+ const result = yield* contractModule.contractExecutable.circuit(Contract.ProvableCircuitId(circuitId), Option.match(crossContract, {
168
+ onSome: (providers) => ({ ...baseCircuitContext, ...providers, parentBlockHash: PLACEHOLDER_BLOCK_HASH }),
169
+ onNone: () => baseCircuitContext
170
+ }), ...(yield* argsParser.parseCircuitArgs(Contract.ProvableCircuitId(circuitId), args)));
171
+ yield* Console.log(stringifyCircuitOutput(result.result, 2));
172
+ // Build one contract-call prototype per call in the trace (callees first, the root call
173
+ // last), folding them into a single intent. Each call's `ContractOperation` comes from that
174
+ // contract's on-chain state: the root call uses the input state; sub-calls are read from the
175
+ // contract-states directory.
176
+ //
177
+ // `finalCalleeStates` is the updated ledger state of each cross-contract *callee*, keyed by
178
+ // address. The root contract is deliberately excluded — its updated state is the job of
179
+ // `--output-oc`, mirroring how the root's input state comes from `--input` rather than
180
+ // `--contract-states-dir`. A callee may be called more than once; folding in trace order means
181
+ // the last write for an address holds its final state. `ledgerState` carries the contract's
182
+ // operations/maintenance authority (unchanged by execution); `data` is its post-execution
183
+ // state value.
184
+ const { intent, finalCalleeStates } = yield* Effect.reduce(result.calls, {
185
+ intent: yield* newIntent(),
186
+ finalCalleeStates: new Map()
187
+ }, (acc, call) => Effect.gen(function* () {
188
+ let callLedgerState;
189
+ if (call.contractAddress === address) {
190
+ callLedgerState = ledgerContractState;
191
+ }
192
+ else if (Option.isSome(inputContractStatesDirPath)) {
193
+ const filePath = join(inputContractStatesDirPath.value, call.contractAddress);
194
+ const bytes = yield* fs.readFile(filePath);
195
+ callLedgerState = yield* ledger.contractStateFromBytes(bytes).pipe(Effect.mapError((err) => ContractRuntimeError.make(`Failed to read contract state for '${call.contractAddress}' from '${filePath}' ` +
196
+ `(expected ledger era ${ledger.era.ledger} encoding)`, err)));
197
+ }
198
+ else {
199
+ // A sub-call can only occur when a state provider (i.e. a contract-states directory) was
200
+ // supplied, so this branch is unreachable in practice; fail loudly if it is reached.
201
+ return yield* ContractRuntimeError.make(`Cannot resolve the operation for cross-contract call to '${call.contractAddress}': ` +
202
+ `no --contract-states-dir was provided.`);
203
+ }
204
+ const callOperation = yield* ledger.operationForCircuit(callLedgerState, call.circuitId, call.contractAddress);
205
+ const nextIntent = yield* tryLedger(`Failed to add the call to '${call.circuitId}' on '${call.contractAddress}' to the intent`, () => acc.intent.addCall(new ledger.ContractCallPrototype(call.contractAddress, call.circuitId, callOperation, call.public.partitionedTranscript[0], call.public.partitionedTranscript[1], call.private.privateTranscriptOutputs, call.private.input, call.private.output, Option.match(call.communicationCommitment, {
206
+ onSome: (c) => c.commCommRand,
207
+ onNone: () => ledger.communicationCommitmentRandomness()
208
+ }),
209
+ // The canonical key location routes the proof for this call to the key material of the
210
+ // specific deployed circuit (by contract address and verifier-key content), so that
211
+ // identically named circuits across contracts in one transaction cannot collide.
212
+ ContractKeyLocation.encodeContractKeyLocation({
213
+ contractAddress: call.contractAddress,
214
+ circuitId: call.circuitId,
215
+ verifierKeyHash: ContractKeyLocation.hashVerifierKey(callOperation.verifierKey)
216
+ }))));
217
+ // Record callee states only; the root's updated state is handled by `--output-oc`.
218
+ const nextFinalCalleeStates = call.contractAddress === address
219
+ ? acc.finalCalleeStates
220
+ : new Map(acc.finalCalleeStates).set(call.contractAddress, {
221
+ ledgerState: callLedgerState,
222
+ data: call.public.contractState
223
+ });
224
+ return { intent: nextIntent, finalCalleeStates: nextFinalCalleeStates };
225
+ }));
226
+ // The root call is always the last entry in the trace (callees first, root last); an empty
227
+ // trace would leave it absent, which is an invariant breach rather than a user error.
228
+ const maybeRootCall = Array.last(result.calls);
229
+ if (Option.isNone(maybeRootCall)) {
230
+ return yield* ContractRuntimeError.make('Circuit execution produced no calls; the root call is missing.');
231
+ }
232
+ const rootCall = maybeRootCall.value;
233
+ // Encoded before the first write, so a failure here leaves no partial output behind.
234
+ const callZswapStates = yield* Effect.forEach(Option.isSome(outputZswapCallsFilePath) ? result.calls : [], (call) => runtime.tryRuntime(`Failed to encode the zswap local state of the call to '${call.circuitId}' on '${call.contractAddress}'`, () => runtime.encodeZswapLocalState(call.private.zswapLocalState)).pipe(Effect.flatMap(encodeZswapLocalStateObject), Effect.map((zswapLocalState) => ({
235
+ contractAddress: call.contractAddress,
236
+ circuitId: call.circuitId,
237
+ zswapLocalState
238
+ }))));
239
+ // If the output public file path is provided, write the on-chain (public state) data to the specified file.
240
+ if (Option.isSome(outputPublicFilePath)) {
241
+ const rootState = yield* ledger.fromRuntimeStateValue(rootCall.public.contractState);
242
+ const rootStateBytes = yield* tryLedger(`Failed to serialize the updated contract state for '${address}'`, () => {
243
+ ledgerContractState.data = new ledger.ChargedState(rootState);
244
+ return ledgerContractState.serialize();
245
+ });
246
+ yield* fs.writeFile(outputPublicFilePath.value, rootStateBytes);
247
+ }
248
+ // If an output contract-states directory is provided, write the updated ledger state of each
249
+ // cross-contract callee, each file named by its address. Combined with `--output-oc` for the
250
+ // root, this lets callers thread state across cross-contract calls without applying the
251
+ // transaction: feed this directory back as `--contract-states-dir` (and the root via `--input`).
252
+ if (Option.isSome(outputContractStatesDirPath)) {
253
+ const dir = outputContractStatesDirPath.value;
254
+ yield* fs.makeDirectory(dir, { recursive: true });
255
+ for (const [contractAddress, { ledgerState, data }] of finalCalleeStates) {
256
+ const calleeState = yield* ledger.fromRuntimeStateValue(data);
257
+ const calleeStateBytes = yield* tryLedger(`Failed to serialize the updated contract state for '${contractAddress}'`, () => {
258
+ ledgerState.data = new ledger.ChargedState(calleeState);
259
+ return ledgerState.serialize();
260
+ });
261
+ yield* fs.writeFile(join(dir, contractAddress), calleeStateBytes);
262
+ }
263
+ }
264
+ yield* fs.writeFileString(outputResultFilePath, stringifyCircuitOutput(result.result));
265
+ yield* fs.writeFile(outputFilePath, yield* serializeIntent(intent));
266
+ yield* fs.writeFileString(outputPrivateStateFilePath, JSON.stringify(result.privateState));
267
+ yield* fs.writeFileString(outputZswapLocalStateFilePath, JSON.stringify(yield* encodeZswapLocalStateObject(
268
+ // The intent file is already written at this point, so an unwrapped throw here would be
269
+ // a defect that leaves a partially-written output directory and reports nothing at all.
270
+ yield* runtime.tryRuntime('Failed to encode the zswap local state produced by the circuit', () => runtime.encodeZswapLocalState(result.zswapLocalState)))));
271
+ if (Option.isSome(outputZswapCallsFilePath)) {
272
+ yield* fs.writeFileString(outputZswapCallsFilePath.value, JSON.stringify(callZswapStates));
273
+ }
274
+ // Contract log events (MIP-0002) are non-consensus output; only write them when a destination
275
+ // is requested. Unreachable on an era that cannot emit them — the gate at the top of this
276
+ // handler has already failed the invocation.
277
+ if (Option.isSome(outputEventsFilePath)) {
278
+ yield* fs.writeFileString(outputEventsFilePath.value, stringifyCircuitOutput(result.events));
279
+ }
280
+ }).pipe(Effect.mapError((err) => ContractRuntimeError.make('Failed to invoke circuit', err)));
281
+ };
282
+ //# sourceMappingURL=circuitCommand.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"circuitCommand.js","sourceRoot":"","sources":["../../../../src/effect/internal/circuitCommand.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAGjC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACvG,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAExD,OAAO,KAAK,0BAA0B,MAAM,kCAAkC,CAAC;AAC/E,OAAO,KAAK,YAAY,MAAM,WAAW,CAAC;AAC1C,OAAO,KAAK,eAAe,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,2BAA2B,EAAE,2BAA2B,EAAE,MAAM,mCAAmC,CAAA;AAE5G,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,KAAK,eAAe,MAAM,cAAc,CAAC;AAIhD,gBAAgB;AAChB,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,OAAO,EAAE,YAAY,CAAC,eAAe;IACrC,SAAS,EAAE,YAAY,CAAC,SAAS;IACjC,IAAI,EAAE,YAAY,CAAC,YAAY;CAChC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,YAAY,GAAG,CACnB,EAAyB,EACzB,QAAgB,EAC+D,EAAE,CAAC,yDAAyD;CAC3I,EAAE,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,IAAI,CAC9B,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CACrB,MAAM,CAAC,GAAG,CAAC;IACT,GAAG,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC;IAC1B,KAAK,EA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