@helios-lang/contract-utils 0.2.81 → 0.3.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 (66) hide show
  1. package/package.json +7 -7
  2. package/src/cast/Cast.js +149 -140
  3. package/src/cast/UserFunc.js +43 -50
  4. package/src/cast/index.js +2 -29
  5. package/src/codegen/LoadedScriptsWriter.js +55 -55
  6. package/src/codegen/TypeSchema.js +6 -14
  7. package/src/codegen/index.js +1 -14
  8. package/src/compiler/CompilerLib.js +1 -80
  9. package/src/compiler/CompilerLib_v0_16.js +14 -14
  10. package/src/compiler/CompilerLib_v0_17.js +25 -23
  11. package/src/compiler/index.js +0 -5
  12. package/src/compiler/ops.js +5 -7
  13. package/src/context/CacheEntry.js +86 -64
  14. package/src/context/ContractContextBuilder.js +37 -57
  15. package/src/context/ContractContextCache.js +5 -7
  16. package/src/context/DagCompiler.js +24 -20
  17. package/src/context/index.js +1 -7
  18. package/src/hl2ts.js +3 -6
  19. package/src/index.js +355 -9
  20. package/types/cast/Cast.d.ts +17 -103
  21. package/types/cast/Cast.d.ts.map +1 -1
  22. package/types/cast/UserFunc.d.ts +11 -94
  23. package/types/cast/UserFunc.d.ts.map +1 -1
  24. package/types/cast/index.d.ts +2 -9
  25. package/types/cast/index.d.ts.map +1 -1
  26. package/types/codegen/LoadedScriptsWriter.d.ts +8 -83
  27. package/types/codegen/LoadedScriptsWriter.d.ts.map +1 -1
  28. package/types/codegen/TypeCheckedValidator.d.ts +1 -1
  29. package/types/codegen/TypeCheckedValidator.d.ts.map +1 -1
  30. package/types/codegen/TypeSchema.d.ts +1 -1
  31. package/types/codegen/TypeSchema.d.ts.map +1 -1
  32. package/types/codegen/index.d.ts +1 -7
  33. package/types/codegen/index.d.ts.map +1 -1
  34. package/types/compiler/CompilerLib.d.ts +3 -138
  35. package/types/compiler/CompilerLib.d.ts.map +1 -1
  36. package/types/compiler/CompilerLib_v0_16.d.ts +8 -118
  37. package/types/compiler/CompilerLib_v0_16.d.ts.map +1 -1
  38. package/types/compiler/CompilerLib_v0_17.d.ts +12 -52
  39. package/types/compiler/CompilerLib_v0_17.d.ts.map +1 -1
  40. package/types/compiler/index.d.ts +0 -2
  41. package/types/compiler/index.d.ts.map +1 -1
  42. package/types/compiler/ops.d.ts +2 -2
  43. package/types/compiler/ops.d.ts.map +1 -1
  44. package/types/context/CacheEntry.d.ts +9 -22
  45. package/types/context/CacheEntry.d.ts.map +1 -1
  46. package/types/context/ContractContext.d.ts +8 -8
  47. package/types/context/ContractContext.d.ts.map +1 -1
  48. package/types/context/ContractContextBuilder.d.ts +5 -100
  49. package/types/context/ContractContextBuilder.d.ts.map +1 -1
  50. package/types/context/ContractContextCache.d.ts +5 -8
  51. package/types/context/ContractContextCache.d.ts.map +1 -1
  52. package/types/context/DagCompiler.d.ts +11 -15
  53. package/types/context/DagCompiler.d.ts.map +1 -1
  54. package/types/context/index.d.ts +1 -6
  55. package/types/context/index.d.ts.map +1 -1
  56. package/types/hl2ts.d.ts +0 -3
  57. package/types/hl2ts.d.ts.map +1 -1
  58. package/types/index.d.ts +284 -9
  59. package/types/index.d.ts.map +1 -1
  60. package/src/cast/PermissiveType.js +0 -18
  61. package/src/cast/StrictType.js +0 -18
  62. package/src/codegen/LoadedModule.js +0 -23
  63. package/src/codegen/LoadedValidator.js +0 -52
  64. package/src/codegen/TypeCheckedModule.js +0 -31
  65. package/src/codegen/TypeCheckedValidator.js +0 -15
  66. package/src/context/ContractContext.js +0 -130
@@ -1,15 +1,9 @@
1
1
  import { bytesToHex } from "@helios-lang/codec-utils"
2
- import { None } from "@helios-lang/type-utils"
3
- import { UplcSourceMap } from "@helios-lang/uplc"
2
+ import { makeUplcSourceMap } from "@helios-lang/uplc"
4
3
 
5
4
  /**
6
- * @typedef {import("@helios-lang/uplc").UplcData} UplcData
7
- * @typedef {import("@helios-lang/uplc").UplcProgramV2I} UplcProgramV2I
8
- * @typedef {import("./CompilerLib.js").CompilerLib} CompilerLib
9
- * @typedef {import("./CompilerLib.js").CompileOptions} CompileOptions
10
- * @typedef {import("./CompilerLib.js").CompileOutput} CompileOutput
11
- * @typedef {import("./CompilerLib.js").ScriptHashType} ScriptHashType
12
- * @typedef {import("./CompilerLib.js").TypeCheckOutput} TypeCheckOutput
5
+ * @import { UplcData, UplcProgramV2 } from "@helios-lang/uplc"
6
+ * @import { CompilerLib, CompileOptions, CompileOutput, ScriptHashType, TypeCheckOutput } from "../index.js"
13
7
  */
14
8
 
15
9
  /**
@@ -23,15 +17,23 @@ import { UplcSourceMap } from "@helios-lang/uplc"
23
17
  * hashDependencies?: Record<string, string>
24
18
  * validatorIndices?: Record<string, number>
25
19
  * excludeUserFuncs?: Set<string>
26
- * onCompileUserFunc?: (name: string, uplc: UplcProgramV2I) => void
27
- * }): UplcProgramV2I
20
+ * onCompileUserFunc?: (name: string, uplc: UplcProgramV2) => void
21
+ * }): UplcProgramV2
28
22
  * }} Program
29
23
  */
30
24
 
25
+ /**
26
+ * @param {any} lib
27
+ * @returns {CompilerLib}
28
+ */
29
+ export function makeCompilerLib_v0_17(lib) {
30
+ return new CompilerLib_v0_17(lib)
31
+ }
32
+
31
33
  /**
32
34
  * @implements {CompilerLib}
33
35
  */
34
- export class CompilerLib_v0_17 {
36
+ class CompilerLib_v0_17 {
35
37
  /**
36
38
  * @private
37
39
  * @type {any}
@@ -90,7 +92,7 @@ export class CompilerLib_v0_17 {
90
92
  const onCompileUserFunc = options.onCompileUserFunc
91
93
 
92
94
  /**
93
- * @type {UplcProgramV2I}
95
+ * @type {UplcProgramV2}
94
96
  */
95
97
  const uplc = program.compile({
96
98
  optimize: options.optimize,
@@ -109,16 +111,16 @@ export class CompilerLib_v0_17 {
109
111
  ? {
110
112
  onCompileUserFunc: (name, uplc) => {
111
113
  const alt = uplc.alt
112
- const ir = options.debug ? uplc.ir : None
113
- const altIr = options.debug ? alt?.ir : None
114
- const sourceMap = UplcSourceMap.fromUplcTerm(
115
- uplc.root
116
- ).toJsonSafe()
114
+ const ir = options.debug ? uplc.ir : undefined
115
+ const altIr = options.debug ? alt?.ir : undefined
116
+ const sourceMap = makeUplcSourceMap({
117
+ term: uplc.root
118
+ }).toJsonSafe()
117
119
  const altSourceMap = alt
118
- ? UplcSourceMap.fromUplcTerm(
119
- alt.root
120
- ).toJsonSafe()
121
- : None
120
+ ? makeUplcSourceMap({
121
+ term: alt.root
122
+ }).toJsonSafe()
123
+ : undefined
122
124
 
123
125
  onCompileUserFunc({
124
126
  name: name,
@@ -153,7 +155,7 @@ export class CompilerLib_v0_17 {
153
155
  : {})
154
156
  })
155
157
 
156
- const sourceMap = UplcSourceMap.fromUplcTerm(uplc.root)
158
+ const sourceMap = makeUplcSourceMap({ term: uplc.root })
157
159
 
158
160
  return {
159
161
  cborHex: bytesToHex(uplc.toCbor()),
@@ -1,6 +1 @@
1
1
  export { loadCompilerLib, typeCheckFiles, typeCheckScripts } from "./ops.js"
2
-
3
- /**
4
- * @typedef {import("./CompilerLib.js").CompilerLib} CompilerLib
5
- * @typedef {import("./CompilerLib.js").TypeCheckOutput} TypeCheckOutput
6
- */
@@ -3,13 +3,11 @@ import {
3
3
  translateImportPaths as translateImportPathsInternal,
4
4
  readHeader
5
5
  } from "@helios-lang/compiler-utils"
6
- import { CompilerLib_v0_16 } from "./CompilerLib_v0_16.js"
7
- import { CompilerLib_v0_17 } from "./CompilerLib_v0_17.js"
6
+ import { makeCompilerLib_v0_16 } from "./CompilerLib_v0_16.js"
7
+ import { makeCompilerLib_v0_17 } from "./CompilerLib_v0_17.js"
8
8
 
9
9
  /**
10
- * @typedef {import("./CompilerLib.js").CompilerLib} CompilerLib
11
- * @typedef {import("./CompilerLib.js")}
12
- * @typedef {import("./CompilerLib.js").TypeCheckOutput} TypeCheckOutput
10
+ * @import { CompilerLib, TypeCheckOutput } from "../index.js"
13
11
  */
14
12
 
15
13
  /**
@@ -31,9 +29,9 @@ export function loadCompilerLib() {
31
29
  case 0:
32
30
  switch (minor) {
33
31
  case 16:
34
- return new CompilerLib_v0_16(unsafeLib)
32
+ return makeCompilerLib_v0_16(unsafeLib)
35
33
  case 17:
36
- return new CompilerLib_v0_17(unsafeLib)
34
+ return makeCompilerLib_v0_17(unsafeLib)
37
35
  }
38
36
  default:
39
37
  throw new Error(
@@ -1,26 +1,21 @@
1
1
  import { bytesToHex } from "@helios-lang/codec-utils"
2
2
  import {
3
- MintingPolicyHash,
4
- ScriptHash,
5
- StakingValidatorHash,
6
- ValidatorHash
3
+ makeMintingPolicyHash,
4
+ makeStakingValidatorHash,
5
+ makeValidatorHash
7
6
  } from "@helios-lang/ledger"
8
- import { None, expectSome } from "@helios-lang/type-utils"
9
- import { UplcProgramV1, UplcProgramV2, UplcSourceMap } from "@helios-lang/uplc"
10
- import { Cast } from "../cast/Cast.js"
7
+ import { expectDefined } from "@helios-lang/type-utils"
8
+ import {
9
+ decodeUplcProgramV1FromCbor,
10
+ decodeUplcProgramV2FromCbor,
11
+ makeUplcSourceMap
12
+ } from "@helios-lang/uplc"
13
+ import { makeCast } from "../cast/Cast.js"
11
14
 
12
15
  /**
13
- * @typedef {import("@helios-lang/type-utils").TypeSchema} TypeSchema
14
- * @typedef {import("@helios-lang/uplc").UplcData} UplcData
15
- * @typedef {import("@helios-lang/uplc").PlutusVersion} PlutusVersion
16
- * @typedef {import("@helios-lang/uplc").UplcProgram} UplcProgram
17
- * @typedef {import("@helios-lang/uplc").UplcProgramV1I} UplcProgramV1I
18
- * @typedef {import("@helios-lang/uplc").UplcProgramV2I} UplcProgramV2I
19
- * @typedef {import("@helios-lang/uplc").UplcSourceMapJsonSafe} UplcSourceMapJsonSafe
20
- * @typedef {import("../cast/index.js").CastConfig} CastConfig
21
- * @typedef {import("../codegen/LoadedModule.js").LoadedModule} LoadedModule
22
- * @typedef {import("../codegen/LoadedValidator.js").LoadedValidator} LoadedValidator
23
- * @typedef {import("./ContractContext.js").AnyContractValidatorContext} AnyContractValidatorContext
16
+ * @import { TypeSchema } from "@helios-lang/type-utils"
17
+ * @import { PlutusVersion, UplcData, UplcProgram, UplcProgramV1, UplcProgramV2, UplcSourceMapJsonSafe } from "@helios-lang/uplc"
18
+ * @import { AnyContractValidatorContext, Cast, CastConfig, LoadedModule, LoadedValidator } from "../index.js"
24
19
  */
25
20
 
26
21
  /**
@@ -87,33 +82,57 @@ export function cacheEntryToJsonSafe(entry) {
87
82
  const hash = entry.validators[name]
88
83
 
89
84
  const purpose =
90
- hash instanceof ValidatorHash
85
+ hash.kind == "ValidatorHash"
91
86
  ? "spending"
92
- : hash instanceof MintingPolicyHash
87
+ : hash.kind == "MintingPolicyHash"
93
88
  ? "minting"
94
- : hash instanceof StakingValidatorHash
89
+ : hash.kind == "StakingValidatorHash"
95
90
  ? "staking"
96
- : hash instanceof ScriptHash
97
- ? "mixed"
98
- : "unknown"
99
- if (purpose == "unknown") {
100
- throw new Error("unhandled hash type")
91
+ : "mixed"
92
+
93
+ const context = hash.context
94
+
95
+ if (
96
+ !(
97
+ typeof hash.context == "object" &&
98
+ hash.context !== null &&
99
+ "redeemer" in hash.context &&
100
+ "program" in hash.context
101
+ )
102
+ ) {
103
+ throw new Error("invalid context")
101
104
  }
102
105
 
103
- const redeemer =
104
- hash.context.redeemer instanceof Cast ? hash.context.redeemer : None
106
+ /**
107
+ * @type {Cast<any, any> | undefined}
108
+ */
109
+ const redeemer = /** @type {any} */ (
110
+ typeof hash.context.redeemer == "object" &&
111
+ hash.context.redeemer !== null &&
112
+ "kind" in hash.context.redeemer &&
113
+ hash.context.redeemer.kind == "Cast"
114
+ ? hash.context.redeemer
115
+ : undefined
116
+ )
105
117
 
106
118
  if (!redeemer) {
107
119
  throw new Error("Redeemer is not a Cast type")
108
120
  }
109
121
 
110
122
  /**
111
- * @type {Option<Cast>}
123
+ * @type {Cast<any, any> | undefined}
112
124
  */
113
- let datum = None
125
+ let datum = undefined
114
126
 
115
- if (hash.context.datum && hash.context.datum instanceof Cast) {
116
- datum = hash.context.datum
127
+ if (
128
+ "datum" in hash.context &&
129
+ hash.context.datum &&
130
+ typeof hash.context.datum == "object" &&
131
+ hash.context.datum !== null &&
132
+ "kind" in hash.context.datum &&
133
+ hash.context.datum.kind == "Cast"
134
+ ) {
135
+ datum = /** @type {any} */ (hash.context.datum)
117
136
  }
118
137
 
119
138
  if (["spending", "mixed"].includes(purpose) && !datum) {
@@ -121,9 +140,9 @@ export function cacheEntryToJsonSafe(entry) {
121
140
  }
122
141
 
123
142
  /**
124
- * @type {UplcProgramV1I | UplcProgramV2I}
143
+ * @type {UplcProgramV1 | UplcProgramV2}
125
144
  */
126
- const program = hash.context.program
145
+ const program = /** @type {any} */ (hash.context.program)
127
146
 
128
147
  resValidators[name] = {
129
148
  purpose: purpose,
@@ -132,17 +151,16 @@ export function cacheEntryToJsonSafe(entry) {
132
151
  unoptimizedCborHex: program.alt
133
152
  ? bytesToHex(program.alt.toCbor())
134
153
  : undefined,
135
- optimizedIr:
136
- /** @type {UplcProgramV2I} */ (program).ir ?? undefined,
154
+ optimizedIr: /** @type {UplcProgramV2} */ (program).ir ?? undefined,
137
155
  unoptimizedIr:
138
- /** @type {UplcProgramV2I} */ (program).alt?.ir ?? undefined,
139
- optimizedSourceMap: UplcSourceMap.fromUplcTerm(
140
- program.root
141
- ).toJsonSafe(),
156
+ /** @type {UplcProgramV2} */ (program).alt?.ir ?? undefined,
157
+ optimizedSourceMap: makeUplcSourceMap({
158
+ term: program.root
159
+ }).toJsonSafe(),
142
160
  unoptimizedSourceMap: program.alt
143
- ? UplcSourceMap.fromUplcTerm(program.alt.root).toJsonSafe()
161
+ ? makeUplcSourceMap({ term: program.alt.root }).toJsonSafe()
144
162
  : undefined,
145
- plutusVersion: hash.context.program.plutusVersion,
163
+ plutusVersion: program.plutusVersion,
146
164
  castConfig: redeemer.config,
147
165
  redeemer: redeemer.schema,
148
166
  datum: datum?.schema
@@ -154,18 +172,18 @@ export function cacheEntryToJsonSafe(entry) {
154
172
 
155
173
  resUserFuncs[name] = {
156
174
  optimizedCborHex: bytesToHex(userFunc.toCbor()),
157
- unoptimizedCborHex: /** @type {UplcProgramV2I} */ (userFunc).alt
175
+ unoptimizedCborHex: /** @type {UplcProgramV2} */ (userFunc).alt
158
176
  ? bytesToHex(
159
- /** @type {UplcProgramV2I} */ (userFunc).alt.toCbor()
177
+ /** @type {UplcProgramV2} */ (userFunc).alt.toCbor()
160
178
  )
161
179
  : undefined,
162
180
  optimizedIr: userFunc.ir ?? undefined,
163
181
  unoptimizedIr: userFunc.alt?.ir ?? undefined,
164
- optimizedSourceMap: UplcSourceMap.fromUplcTerm(
165
- userFunc.root
166
- ).toJsonSafe(),
182
+ optimizedSourceMap: makeUplcSourceMap({
183
+ term: userFunc.root
184
+ }).toJsonSafe(),
167
185
  unoptimizedSourceMap: userFunc.alt
168
- ? UplcSourceMap.fromUplcTerm(userFunc.alt.root).toJsonSafe()
186
+ ? makeUplcSourceMap({ term: userFunc.alt.root }).toJsonSafe()
169
187
  : undefined,
170
188
  plutusVersion: userFunc.plutusVersion
171
189
  }
@@ -200,11 +218,11 @@ export function cacheEntryFromJson(entry) {
200
218
  */
201
219
  let program =
202
220
  props.plutusVersion == "PlutusScriptV1"
203
- ? UplcProgramV1.fromCbor(props.optimizedCborHex, {
221
+ ? decodeUplcProgramV1FromCbor(props.optimizedCborHex, {
204
222
  ir: props.optimizedIr,
205
223
  sourceMap: props.optimizedSourceMap
206
224
  })
207
- : UplcProgramV2.fromCbor(props.optimizedCborHex, {
225
+ : decodeUplcProgramV2FromCbor(props.optimizedCborHex, {
208
226
  ir: props.optimizedIr,
209
227
  sourceMap: props.optimizedSourceMap
210
228
  })
@@ -212,14 +230,14 @@ export function cacheEntryFromJson(entry) {
212
230
  if (props.unoptimizedCborHex) {
213
231
  if (program.plutusVersion == "PlutusScriptV1") {
214
232
  program = program.withAlt(
215
- UplcProgramV1.fromCbor(props.unoptimizedCborHex, {
233
+ decodeUplcProgramV1FromCbor(props.unoptimizedCborHex, {
216
234
  ir: props.unoptimizedIr,
217
235
  sourceMap: props.unoptimizedSourceMap
218
236
  })
219
237
  )
220
238
  } else if (program.plutusVersion == "PlutusScriptV2") {
221
239
  program = program.withAlt(
222
- UplcProgramV2.fromCbor(props.unoptimizedCborHex, {
240
+ decodeUplcProgramV2FromCbor(props.unoptimizedCborHex, {
223
241
  ir: props.unoptimizedIr,
224
242
  sourceMap: props.unoptimizedSourceMap
225
243
  })
@@ -229,37 +247,41 @@ export function cacheEntryFromJson(entry) {
229
247
  }
230
248
  }
231
249
 
232
- let redeemer = new Cast(props.redeemer, props.castConfig)
250
+ let redeemer = makeCast(props.redeemer, props.castConfig)
233
251
 
234
252
  switch (props.purpose) {
235
253
  case "spending": {
236
- res.validators[name] = new ValidatorHash(props.bytes, {
237
- datum: new Cast(expectSome(props.datum), props.castConfig),
254
+ res.validators[name] = makeValidatorHash(props.bytes, {
255
+ datum: makeCast(
256
+ expectDefined(props.datum),
257
+ props.castConfig
258
+ ),
238
259
  redeemer: redeemer,
239
260
  program: program
240
261
  })
241
262
  break
242
263
  }
243
264
  case "minting": {
244
- res.validators[name] = new MintingPolicyHash(props.bytes, {
265
+ res.validators[name] = makeMintingPolicyHash(props.bytes, {
245
266
  redeemer: redeemer,
246
267
  program: program
247
268
  })
248
269
  break
249
270
  }
250
271
  case "staking": {
251
- res.validators[name] = new StakingValidatorHash(props.bytes, {
272
+ res.validators[name] = makeStakingValidatorHash(props.bytes, {
252
273
  redeemer: redeemer,
253
274
  program: program
254
275
  })
255
276
  break
256
277
  }
257
278
  case "mixed": {
258
- res.validators[name] = new ScriptHash(props.bytes, {
259
- datum: new Cast(expectSome(props.datum), props.castConfig),
279
+ throw new Error("implement ScriptHash type")
280
+ /*res.validators[name] = new ScriptHash(props.bytes, {
281
+ datum: makeCast(expectDefined(props.datum), props.castConfig),
260
282
  redeemer: redeemer,
261
283
  program: program
262
- })
284
+ })*/
263
285
  break
264
286
  }
265
287
  default:
@@ -275,11 +297,11 @@ export function cacheEntryFromJson(entry) {
275
297
  */
276
298
  let program =
277
299
  props.plutusVersion == "PlutusScriptV1"
278
- ? UplcProgramV1.fromCbor(props.optimizedCborHex, {
300
+ ? decodeUplcProgramV1FromCbor(props.optimizedCborHex, {
279
301
  ir: props.optimizedIr,
280
302
  sourceMap: props.optimizedSourceMap
281
303
  })
282
- : UplcProgramV2.fromCbor(props.optimizedCborHex, {
304
+ : decodeUplcProgramV2FromCbor(props.optimizedCborHex, {
283
305
  ir: props.optimizedIr,
284
306
  sourceMap: props.optimizedSourceMap
285
307
  })
@@ -287,14 +309,14 @@ export function cacheEntryFromJson(entry) {
287
309
  if (props.unoptimizedCborHex) {
288
310
  if (program.plutusVersion == "PlutusScriptV1") {
289
311
  program = program.withAlt(
290
- UplcProgramV1.fromCbor(props.unoptimizedCborHex, {
312
+ decodeUplcProgramV1FromCbor(props.unoptimizedCborHex, {
291
313
  ir: props.unoptimizedIr,
292
314
  sourceMap: props.unoptimizedSourceMap
293
315
  })
294
316
  )
295
317
  } else if (program.plutusVersion == "PlutusScriptV2") {
296
318
  program = program.withAlt(
297
- UplcProgramV2.fromCbor(props.unoptimizedCborHex, {
319
+ decodeUplcProgramV2FromCbor(props.unoptimizedCborHex, {
298
320
  ir: props.unoptimizedIr,
299
321
  sourceMap: props.unoptimizedSourceMap
300
322
  })
@@ -1,44 +1,27 @@
1
- import { expectSome } from "@helios-lang/type-utils"
1
+ import { expectDefined } from "@helios-lang/type-utils"
2
2
  import { configureCast } from "../cast/Cast.js"
3
3
  import { loadCompilerLib } from "../compiler/index.js"
4
4
  import { DagCompiler } from "./DagCompiler.js"
5
5
  import { contractContextCache } from "./ContractContextCache.js"
6
6
 
7
7
  /**
8
- * @typedef {import("@helios-lang/uplc").UplcData} UplcData
9
- * @typedef {import("../cast/index.js").CastConfig} CastConfig
10
- * @typedef {import("../codegen/LoadedModule.js").LoadedModule} LoadedModule
11
- * @typedef {import("../codegen/LoadedValidator.js").LoadedValidator} LoadedValidator
12
- * @typedef {import("../compiler/index.js").CompilerLib} CompilerLib
8
+ * @import { UplcData } from "@helios-lang/uplc"
9
+ * @import { CastConfig, CompilerLib, ContractContext, ContractContextBuilder, ContractContextBuilderProps, ExtractDependencies, LoadedModule, LoadedValidator } from "../index.js"
13
10
  */
14
11
 
15
12
  /**
16
- * @template {LoadedValidator} V
17
- * @typedef {import("../codegen/LoadedValidator.js").ExtractDependencies<V>} ExtractDependencies
18
- */
19
-
20
- /**
21
- * @template {{[name: string]: LoadedValidator}} Vs
22
- * @template {{[name: string]: LoadedModule}} Ms
23
- * @typedef {import("./ContractContext.js").ContractContext<Vs, Ms>} ContractContext
24
- */
25
-
26
- /**
27
- * if `debug` is true, the ir is included where possible
28
- * @typedef {{
29
- * isMainnet: boolean
30
- * expectedHashes?: {[name: string]: string}
31
- * parameters?: Record<string, UplcData>
32
- * dumpHashes?: boolean
33
- * debug?: boolean
34
- * }} ContractContextBuildProps
13
+ * @returns {ContractContextBuilder<{}, {}>}
35
14
  */
15
+ export function makeContractContextBuilder() {
16
+ return new ContractContextBuilderImpl({}, {})
17
+ }
36
18
 
37
19
  /**
38
20
  * @template {{[name: string]: LoadedValidator}} Vs
39
21
  * @template {{[name: string]: LoadedModule}} Ms
22
+ * @implements {ContractContextBuilder<Vs, Ms>}
40
23
  */
41
- export class ContractContextBuilder {
24
+ class ContractContextBuilderImpl {
42
25
  /**
43
26
  * @private
44
27
  * @readonly
@@ -54,7 +37,6 @@ export class ContractContextBuilder {
54
37
  modules
55
38
 
56
39
  /**
57
- * @private
58
40
  * @param {Vs} validators
59
41
  * @param {Ms} modules
60
42
  */
@@ -63,13 +45,6 @@ export class ContractContextBuilder {
63
45
  this.modules = modules
64
46
  }
65
47
 
66
- /**
67
- * @returns {ContractContextBuilder<{}, {}>}
68
- */
69
- static new() {
70
- return new ContractContextBuilder({}, {})
71
- }
72
-
73
48
  /**
74
49
  * @template {LoadedValidator} V
75
50
  * @param {V} validator
@@ -79,17 +54,19 @@ export class ContractContextBuilder {
79
54
  * >}
80
55
  */
81
56
  with(validator) {
82
- return new ContractContextBuilder(
83
- /** @type {any} */ ({
84
- ...this.validators,
85
- [validator.$name]: validator
86
- }),
87
- /** @type {any} */ ({
88
- ...this.modules,
89
- ...Object.fromEntries(
90
- validator.$dependencies.map((d) => [d.$name, d])
91
- )
92
- })
57
+ return /** @type {any} */ (
58
+ new ContractContextBuilderImpl(
59
+ /** @type {any} */ ({
60
+ ...this.validators,
61
+ [validator.$name]: validator
62
+ }),
63
+ /** @type {any} */ ({
64
+ ...this.modules,
65
+ ...Object.fromEntries(
66
+ validator.$dependencies.map((d) => [d.$name, d])
67
+ )
68
+ })
69
+ )
93
70
  )
94
71
  }
95
72
 
@@ -102,17 +79,19 @@ export class ContractContextBuilder {
102
79
  * >}
103
80
  */
104
81
  withModule(m) {
105
- return new ContractContextBuilder(
106
- this.validators,
107
- /** @type {any} */ ({
108
- ...this.modules,
109
- [m.$name]: m
110
- })
82
+ return /** @type {any} */ (
83
+ new ContractContextBuilderImpl(
84
+ this.validators,
85
+ /** @type {any} */ ({
86
+ ...this.modules,
87
+ [m.$name]: m
88
+ })
89
+ )
111
90
  )
112
91
  }
113
92
 
114
93
  /**
115
- * @param {ContractContextBuildProps} props
94
+ * @param {ContractContextBuilderProps} props
116
95
  * @returns {ContractContext<Vs, Ms>}
117
96
  */
118
97
  build(props) {
@@ -173,7 +152,7 @@ export class ContractContextBuilder {
173
152
  ([funcKey, userFunc]) => [
174
153
  funcKey,
175
154
  userFunc(
176
- expectSome(
155
+ expectDefined(
177
156
  compiled.userFuncs[`${name}::${funcKey}`]
178
157
  ),
179
158
  castConfig
@@ -203,9 +182,10 @@ export class ContractContextBuilder {
203
182
  return [
204
183
  funcKey,
205
184
  userFunc(
206
- expectSome(
207
- compiled.validators[name].context
208
- .program
185
+ expectDefined(
186
+ /** @type {any} */ (
187
+ compiled.validators[name]
188
+ ).context.program
209
189
  ),
210
190
  castConfig
211
191
  )
@@ -214,7 +194,7 @@ export class ContractContextBuilder {
214
194
  return [
215
195
  funcKey,
216
196
  userFunc(
217
- expectSome(
197
+ expectDefined(
218
198
  compiled.userFuncs[
219
199
  `${name}::${funcKey}`
220
200
  ]
@@ -1,13 +1,11 @@
1
1
  import { bytesToHex, encodeUtf8 } from "@helios-lang/codec-utils"
2
2
  import { blake2b } from "@helios-lang/crypto"
3
- import { JSON, None } from "@helios-lang/type-utils"
3
+ import { JSON } from "@helios-lang/type-utils"
4
4
  import { cacheEntryFromJson, cacheEntryToJsonSafe } from "./CacheEntry.js"
5
5
 
6
6
  /**
7
- * @typedef {import("@helios-lang/uplc").UplcData} UplcData
8
- * @typedef {import("@helios-lang/uplc").UplcProgram} UplcProgram
9
- * @typedef {import("../codegen/LoadedModule.js").LoadedModule} LoadedModule
10
- * @typedef {import("../codegen/LoadedValidator.js").LoadedValidator} LoadedValidator
7
+ * @import { UplcData, UplcProgram } from "@helios-lang/uplc"
8
+ * @import { LoadedModule, LoadedValidator } from "../index.js"
11
9
  * @typedef {import("./CacheEntry.js").CacheEntry} CacheEntry
12
10
  * @typedef {import("./CacheEntry.js").CacheEntryJson} CacheEntryJson
13
11
  * @typedef {import("./CacheEntry.js").CacheEntryUserFuncsJson} CacheEntryUserFuncsJson
@@ -129,11 +127,11 @@ class ContractContextCache {
129
127
  )
130
128
  }
131
129
 
132
- return None
130
+ return undefined
133
131
  } else {
134
132
  if (this.i >= this.positionalCache.length) {
135
133
  // TODO: lookup in explicitCache
136
- return None
134
+ return undefined
137
135
  }
138
136
 
139
137
  const res = this.positionalCache[this.i]