@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.
- package/package.json +7 -7
- package/src/cast/Cast.js +149 -140
- package/src/cast/UserFunc.js +43 -50
- package/src/cast/index.js +2 -29
- package/src/codegen/LoadedScriptsWriter.js +55 -55
- package/src/codegen/TypeSchema.js +6 -14
- package/src/codegen/index.js +1 -14
- package/src/compiler/CompilerLib.js +1 -80
- package/src/compiler/CompilerLib_v0_16.js +14 -14
- package/src/compiler/CompilerLib_v0_17.js +25 -23
- package/src/compiler/index.js +0 -5
- package/src/compiler/ops.js +5 -7
- package/src/context/CacheEntry.js +86 -64
- package/src/context/ContractContextBuilder.js +37 -57
- package/src/context/ContractContextCache.js +5 -7
- package/src/context/DagCompiler.js +24 -20
- package/src/context/index.js +1 -7
- package/src/hl2ts.js +3 -6
- package/src/index.js +355 -9
- package/types/cast/Cast.d.ts +17 -103
- package/types/cast/Cast.d.ts.map +1 -1
- package/types/cast/UserFunc.d.ts +11 -94
- package/types/cast/UserFunc.d.ts.map +1 -1
- package/types/cast/index.d.ts +2 -9
- package/types/cast/index.d.ts.map +1 -1
- package/types/codegen/LoadedScriptsWriter.d.ts +8 -83
- package/types/codegen/LoadedScriptsWriter.d.ts.map +1 -1
- package/types/codegen/TypeCheckedValidator.d.ts +1 -1
- package/types/codegen/TypeCheckedValidator.d.ts.map +1 -1
- package/types/codegen/TypeSchema.d.ts +1 -1
- package/types/codegen/TypeSchema.d.ts.map +1 -1
- package/types/codegen/index.d.ts +1 -7
- package/types/codegen/index.d.ts.map +1 -1
- package/types/compiler/CompilerLib.d.ts +3 -138
- package/types/compiler/CompilerLib.d.ts.map +1 -1
- package/types/compiler/CompilerLib_v0_16.d.ts +8 -118
- package/types/compiler/CompilerLib_v0_16.d.ts.map +1 -1
- package/types/compiler/CompilerLib_v0_17.d.ts +12 -52
- package/types/compiler/CompilerLib_v0_17.d.ts.map +1 -1
- package/types/compiler/index.d.ts +0 -2
- package/types/compiler/index.d.ts.map +1 -1
- package/types/compiler/ops.d.ts +2 -2
- package/types/compiler/ops.d.ts.map +1 -1
- package/types/context/CacheEntry.d.ts +9 -22
- package/types/context/CacheEntry.d.ts.map +1 -1
- package/types/context/ContractContext.d.ts +8 -8
- package/types/context/ContractContext.d.ts.map +1 -1
- package/types/context/ContractContextBuilder.d.ts +5 -100
- package/types/context/ContractContextBuilder.d.ts.map +1 -1
- package/types/context/ContractContextCache.d.ts +5 -8
- package/types/context/ContractContextCache.d.ts.map +1 -1
- package/types/context/DagCompiler.d.ts +11 -15
- package/types/context/DagCompiler.d.ts.map +1 -1
- package/types/context/index.d.ts +1 -6
- package/types/context/index.d.ts.map +1 -1
- package/types/hl2ts.d.ts +0 -3
- package/types/hl2ts.d.ts.map +1 -1
- package/types/index.d.ts +284 -9
- package/types/index.d.ts.map +1 -1
- package/src/cast/PermissiveType.js +0 -18
- package/src/cast/StrictType.js +0 -18
- package/src/codegen/LoadedModule.js +0 -23
- package/src/codegen/LoadedValidator.js +0 -52
- package/src/codegen/TypeCheckedModule.js +0 -31
- package/src/codegen/TypeCheckedValidator.js +0 -15
- package/src/context/ContractContext.js +0 -130
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
import { bytesToHex } from "@helios-lang/codec-utils"
|
|
2
|
-
import {
|
|
3
|
-
import { UplcSourceMap } from "@helios-lang/uplc"
|
|
2
|
+
import { makeUplcSourceMap } from "@helios-lang/uplc"
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
|
-
* @
|
|
7
|
-
* @
|
|
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:
|
|
27
|
-
* }):
|
|
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
|
-
|
|
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 {
|
|
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 :
|
|
113
|
-
const altIr = options.debug ? alt?.ir :
|
|
114
|
-
const sourceMap =
|
|
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
|
-
?
|
|
119
|
-
alt.root
|
|
120
|
-
).toJsonSafe()
|
|
121
|
-
:
|
|
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 =
|
|
158
|
+
const sourceMap = makeUplcSourceMap({ term: uplc.root })
|
|
157
159
|
|
|
158
160
|
return {
|
|
159
161
|
cborHex: bytesToHex(uplc.toCbor()),
|
package/src/compiler/index.js
CHANGED
package/src/compiler/ops.js
CHANGED
|
@@ -3,13 +3,11 @@ import {
|
|
|
3
3
|
translateImportPaths as translateImportPathsInternal,
|
|
4
4
|
readHeader
|
|
5
5
|
} from "@helios-lang/compiler-utils"
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
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
|
-
* @
|
|
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
|
|
32
|
+
return makeCompilerLib_v0_16(unsafeLib)
|
|
35
33
|
case 17:
|
|
36
|
-
return
|
|
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
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
ValidatorHash
|
|
3
|
+
makeMintingPolicyHash,
|
|
4
|
+
makeStakingValidatorHash,
|
|
5
|
+
makeValidatorHash
|
|
7
6
|
} from "@helios-lang/ledger"
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
|
|
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
|
-
* @
|
|
14
|
-
* @
|
|
15
|
-
* @
|
|
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
|
|
85
|
+
hash.kind == "ValidatorHash"
|
|
91
86
|
? "spending"
|
|
92
|
-
: hash
|
|
87
|
+
: hash.kind == "MintingPolicyHash"
|
|
93
88
|
? "minting"
|
|
94
|
-
: hash
|
|
89
|
+
: hash.kind == "StakingValidatorHash"
|
|
95
90
|
? "staking"
|
|
96
|
-
:
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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
|
-
|
|
104
|
-
|
|
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 {
|
|
123
|
+
* @type {Cast<any, any> | undefined}
|
|
112
124
|
*/
|
|
113
|
-
let datum =
|
|
125
|
+
let datum = undefined
|
|
114
126
|
|
|
115
|
-
if (
|
|
116
|
-
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 {
|
|
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 {
|
|
139
|
-
optimizedSourceMap:
|
|
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
|
-
?
|
|
161
|
+
? makeUplcSourceMap({ term: program.alt.root }).toJsonSafe()
|
|
144
162
|
: undefined,
|
|
145
|
-
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 {
|
|
175
|
+
unoptimizedCborHex: /** @type {UplcProgramV2} */ (userFunc).alt
|
|
158
176
|
? bytesToHex(
|
|
159
|
-
/** @type {
|
|
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:
|
|
165
|
-
userFunc.root
|
|
166
|
-
).toJsonSafe(),
|
|
182
|
+
optimizedSourceMap: makeUplcSourceMap({
|
|
183
|
+
term: userFunc.root
|
|
184
|
+
}).toJsonSafe(),
|
|
167
185
|
unoptimizedSourceMap: userFunc.alt
|
|
168
|
-
?
|
|
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
|
-
?
|
|
221
|
+
? decodeUplcProgramV1FromCbor(props.optimizedCborHex, {
|
|
204
222
|
ir: props.optimizedIr,
|
|
205
223
|
sourceMap: props.optimizedSourceMap
|
|
206
224
|
})
|
|
207
|
-
:
|
|
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
|
-
|
|
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
|
-
|
|
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 =
|
|
250
|
+
let redeemer = makeCast(props.redeemer, props.castConfig)
|
|
233
251
|
|
|
234
252
|
switch (props.purpose) {
|
|
235
253
|
case "spending": {
|
|
236
|
-
res.validators[name] =
|
|
237
|
-
datum:
|
|
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] =
|
|
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] =
|
|
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
|
-
|
|
259
|
-
|
|
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
|
-
?
|
|
300
|
+
? decodeUplcProgramV1FromCbor(props.optimizedCborHex, {
|
|
279
301
|
ir: props.optimizedIr,
|
|
280
302
|
sourceMap: props.optimizedSourceMap
|
|
281
303
|
})
|
|
282
|
-
:
|
|
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
|
-
|
|
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
|
-
|
|
319
|
+
decodeUplcProgramV2FromCbor(props.unoptimizedCborHex, {
|
|
298
320
|
ir: props.unoptimizedIr,
|
|
299
321
|
sourceMap: props.unoptimizedSourceMap
|
|
300
322
|
})
|
|
@@ -1,44 +1,27 @@
|
|
|
1
|
-
import {
|
|
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
|
-
* @
|
|
9
|
-
* @
|
|
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
|
-
* @
|
|
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
|
-
|
|
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
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
207
|
-
|
|
208
|
-
.
|
|
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
|
-
|
|
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
|
|
3
|
+
import { JSON } from "@helios-lang/type-utils"
|
|
4
4
|
import { cacheEntryFromJson, cacheEntryToJsonSafe } from "./CacheEntry.js"
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
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
|
|
130
|
+
return undefined
|
|
133
131
|
} else {
|
|
134
132
|
if (this.i >= this.positionalCache.length) {
|
|
135
133
|
// TODO: lookup in explicitCache
|
|
136
|
-
return
|
|
134
|
+
return undefined
|
|
137
135
|
}
|
|
138
136
|
|
|
139
137
|
const res = this.positionalCache[this.i]
|