@helios-lang/contract-utils 0.2.82 → 0.3.1
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 +39 -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 +15 -15
- package/src/compiler/CompilerLib_v0_17.js +26 -24
- 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 +8 -9
- package/src/context/DagCompiler.js +25 -21
- package/src/context/index.js +1 -7
- package/src/context/set-fs-build-cache.js +1 -0
- package/src/hl2ts.js +3 -6
- package/src/index.js +356 -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 +14 -54
- 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 +11 -12
- package/types/context/ContractContextCache.d.ts.map +1 -1
- package/types/context/DagCompiler.d.ts +12 -16
- 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/context/set-fs-build-cache.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 +285 -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
package/src/cast/UserFunc.js
CHANGED
|
@@ -1,46 +1,35 @@
|
|
|
1
1
|
import { bytesToHex } from "@helios-lang/codec-utils"
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
2
|
+
import { expectDefined, isLeft, isString } from "@helios-lang/type-utils"
|
|
3
|
+
import {
|
|
4
|
+
makeConstrData,
|
|
5
|
+
makeUplcDataValue,
|
|
6
|
+
UplcRuntimeError
|
|
7
|
+
} from "@helios-lang/uplc"
|
|
8
|
+
import { makeCast } from "./Cast.js"
|
|
5
9
|
|
|
6
10
|
/**
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
9
|
-
* @
|
|
10
|
-
* @typedef {import("@helios-lang/uplc").UplcLoggingI} UplcLoggingI
|
|
11
|
-
* @typedef {import("@helios-lang/uplc").UplcProgram} UplcProgram
|
|
12
|
-
* @typedef {import("@helios-lang/uplc").UplcValue} UplcValue
|
|
13
|
-
* @typedef {import("./Cast.js").CastConfig} CastConfig
|
|
11
|
+
* @import { Either, TypeSchema } from "@helios-lang/type-utils"
|
|
12
|
+
* @import { CekResult, UplcData, UplcLogger, UplcProgram, UplcValue } from "@helios-lang/uplc"
|
|
13
|
+
* @import { Cast, CastConfig, UnsafeArgsT, UserFunc, UserFuncProps } from "../index.js"
|
|
14
14
|
*/
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* @
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* requiresCurrentScript: boolean
|
|
23
|
-
* arguments: {
|
|
24
|
-
* name: string
|
|
25
|
-
* type: TypeSchema
|
|
26
|
-
* isOptional: boolean
|
|
27
|
-
* }[]
|
|
28
|
-
* returns?: TypeSchema
|
|
29
|
-
* validatorIndices?: Record<string, number>
|
|
30
|
-
* castConfig: CastConfig
|
|
31
|
-
* }} UserFuncProps
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @template ArgsT
|
|
36
|
-
* @typedef {{[K in keyof ArgsT]: K extends "$currentScript" ? string : UplcData}} UnsafeArgsT
|
|
17
|
+
* @template {{[argName: string]: any}} ArgsT
|
|
18
|
+
* @template RetT
|
|
19
|
+
* @param {UplcProgram} uplc
|
|
20
|
+
* @param {UserFuncProps} props
|
|
21
|
+
* @returns {UserFunc<ArgsT, RetT>}
|
|
37
22
|
*/
|
|
23
|
+
export function makeUserFunc(uplc, props) {
|
|
24
|
+
return new UserFuncImpl(uplc, props)
|
|
25
|
+
}
|
|
38
26
|
|
|
39
27
|
/**
|
|
40
28
|
* @template {{[argName: string]: any}} ArgsT
|
|
41
29
|
* @template RetT
|
|
30
|
+
* @implements {UserFunc<ArgsT, RetT>}
|
|
42
31
|
*/
|
|
43
|
-
|
|
32
|
+
class UserFuncImpl {
|
|
44
33
|
/**
|
|
45
34
|
* @readonly
|
|
46
35
|
* @type {UplcProgram}
|
|
@@ -72,10 +61,10 @@ export class UserFunc {
|
|
|
72
61
|
|
|
73
62
|
/**
|
|
74
63
|
* @param {ArgsT} namedArgs
|
|
75
|
-
* @param {
|
|
64
|
+
* @param {UplcLogger | undefined} logOptions
|
|
76
65
|
* @returns {RetT}
|
|
77
66
|
*/
|
|
78
|
-
eval(namedArgs, logOptions =
|
|
67
|
+
eval(namedArgs, logOptions = undefined) {
|
|
79
68
|
/**
|
|
80
69
|
* @type {{[argName: string]: any}}
|
|
81
70
|
*/
|
|
@@ -89,7 +78,7 @@ export class UserFunc {
|
|
|
89
78
|
if (argDetails) {
|
|
90
79
|
const typeSchema = argDetails.type
|
|
91
80
|
|
|
92
|
-
unsafeNamedArgs[argName] =
|
|
81
|
+
unsafeNamedArgs[argName] = makeCast(
|
|
93
82
|
typeSchema,
|
|
94
83
|
this.props.castConfig
|
|
95
84
|
).toUplcData(argValue)
|
|
@@ -108,10 +97,10 @@ export class UserFunc {
|
|
|
108
97
|
)
|
|
109
98
|
|
|
110
99
|
if (this.props.returns) {
|
|
111
|
-
return
|
|
100
|
+
return makeCast(
|
|
112
101
|
this.props.returns,
|
|
113
102
|
this.props.castConfig
|
|
114
|
-
).fromUplcData(
|
|
103
|
+
).fromUplcData(expectDefined(/** @type {any} */ (result)))
|
|
115
104
|
} else {
|
|
116
105
|
return /** @type {any} */ (undefined)
|
|
117
106
|
}
|
|
@@ -119,10 +108,10 @@ export class UserFunc {
|
|
|
119
108
|
|
|
120
109
|
/**
|
|
121
110
|
* @param {UnsafeArgsT<ArgsT>} namedArgs
|
|
122
|
-
* @param {
|
|
111
|
+
* @param {UplcLogger | undefined} logOptions
|
|
123
112
|
* @returns {RetT extends void ? void : UplcData}
|
|
124
113
|
*/
|
|
125
|
-
evalUnsafe(namedArgs, logOptions =
|
|
114
|
+
evalUnsafe(namedArgs, logOptions = undefined) {
|
|
126
115
|
const result = this.profile(namedArgs, logOptions).result
|
|
127
116
|
|
|
128
117
|
if (isLeft(result)) {
|
|
@@ -138,10 +127,10 @@ export class UserFunc {
|
|
|
138
127
|
|
|
139
128
|
/**
|
|
140
129
|
* @param {UnsafeArgsT<ArgsT>} namedArgs
|
|
141
|
-
* @param {
|
|
130
|
+
* @param {UplcLogger | undefined} logOptions - optional, passed to UplcProgram.eval if provided
|
|
142
131
|
* @returns {CekResult}
|
|
143
132
|
*/
|
|
144
|
-
profile(namedArgs, logOptions =
|
|
133
|
+
profile(namedArgs, logOptions = undefined) {
|
|
145
134
|
const isMain = this.name == "main"
|
|
146
135
|
|
|
147
136
|
/**
|
|
@@ -157,38 +146,38 @@ export class UserFunc {
|
|
|
157
146
|
args.push(namedArgs[name])
|
|
158
147
|
}
|
|
159
148
|
} else {
|
|
160
|
-
args.push(
|
|
149
|
+
args.push(expectDefined(namedArgs[name]))
|
|
161
150
|
}
|
|
162
151
|
} else {
|
|
163
152
|
if (isOptional) {
|
|
164
153
|
if (name in namedArgs && namedArgs[name]) {
|
|
165
|
-
args.push(
|
|
154
|
+
args.push(makeConstrData(0, [namedArgs[name]]))
|
|
166
155
|
} else {
|
|
167
|
-
args.push(
|
|
156
|
+
args.push(makeConstrData(1, []))
|
|
168
157
|
}
|
|
169
158
|
} else {
|
|
170
|
-
args.push(
|
|
159
|
+
args.push(expectDefined(namedArgs[name]))
|
|
171
160
|
}
|
|
172
161
|
}
|
|
173
162
|
})
|
|
174
163
|
|
|
175
164
|
if (this.props.requiresScriptContext) {
|
|
176
|
-
args.push(
|
|
165
|
+
args.push(expectDefined(namedArgs["$scriptContext"]))
|
|
177
166
|
}
|
|
178
167
|
|
|
179
168
|
if (this.props.requiresCurrentScript) {
|
|
180
|
-
const currentScriptName =
|
|
169
|
+
const currentScriptName = expectDefined(
|
|
181
170
|
/** @type {any} */ (namedArgs)["$currentScript"]
|
|
182
171
|
)
|
|
183
172
|
|
|
184
|
-
const index =
|
|
185
|
-
|
|
173
|
+
const index = expectDefined(
|
|
174
|
+
expectDefined(this.props.validatorIndices)[currentScriptName]
|
|
186
175
|
)
|
|
187
176
|
|
|
188
|
-
args.push(
|
|
177
|
+
args.push(makeConstrData(index, []))
|
|
189
178
|
}
|
|
190
179
|
|
|
191
|
-
const argValues = args.map((a) =>
|
|
180
|
+
const argValues = args.map((a) => makeUplcDataValue(a))
|
|
192
181
|
|
|
193
182
|
const cekResult = this.uplc.eval(argValues, {
|
|
194
183
|
logOptions: logOptions ?? undefined
|
package/src/cast/index.js
CHANGED
|
@@ -1,30 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
export { Cast }
|
|
1
|
+
export { makeCast } from "./Cast.js"
|
|
3
2
|
export { configureCast } from "./Cast.js"
|
|
4
|
-
export {
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* @typedef {import("./Cast.js").CastConfig} CastConfig
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @template TStrict
|
|
12
|
-
* @template TPermissive
|
|
13
|
-
* @typedef {import("./Cast.js").ConfigurableCast<TStrict, TPermissive>} ConfigurableCast
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @template TStrict
|
|
18
|
-
* @template TPermissive
|
|
19
|
-
* @typedef {import("./Cast.js").CastLike<TStrict, TPermissive>} CastLike
|
|
20
|
-
*/
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @template {CastLike<any, any>} C
|
|
24
|
-
* @typedef {import("./PermissiveType.js").PermissiveType<C>} PermissiveType
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @template {CastLike<any, any>} C
|
|
29
|
-
* @typedef {import("./StrictType.js").StrictType<C>} StrictType
|
|
30
|
-
*/
|
|
3
|
+
export { makeUserFunc } from "./UserFunc.js"
|
|
@@ -1,34 +1,30 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { isSome } from "@helios-lang/type-utils"
|
|
1
|
+
import { makeStringWriter } from "@helios-lang/codec-utils"
|
|
2
|
+
import { isDefined as isSome } from "@helios-lang/type-utils"
|
|
3
3
|
import { genTypes } from "./TypeSchema.js"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* @
|
|
7
|
-
* @
|
|
8
|
-
* @typedef {import("./TypeCheckedValidator.js").TypeCheckedValidator} TypeCheckedValidator
|
|
9
|
-
* @typedef {import("./TypeSchema.js").TypeSchema} TypeSchema
|
|
6
|
+
* @import { TypeSchema } from "@helios-lang/type-utils"
|
|
7
|
+
* @import { LoadedScriptsWriter, TypeCheckedModule, TypeCheckedUserFunc, TypeCheckedValidator } from "../index.js"
|
|
10
8
|
*/
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.combined = new StringWriter()
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Constructs a LoadedScriptsWriter instance and initializes it be writing the header
|
|
24
|
-
* @returns {LoadedScriptsWriter}
|
|
25
|
-
*/
|
|
26
|
-
static new() {
|
|
27
|
-
const w = new LoadedScriptsWriter()
|
|
10
|
+
/**
|
|
11
|
+
* Constructs a LoadedScriptsWriter instance and initializes it be writing the header
|
|
12
|
+
* @returns {LoadedScriptsWriter}
|
|
13
|
+
*/
|
|
14
|
+
export function makeLoadedScriptsWriter() {
|
|
15
|
+
return new LoadedScriptsWriterImpl()
|
|
16
|
+
}
|
|
28
17
|
|
|
29
|
-
|
|
18
|
+
/**
|
|
19
|
+
* @implements {LoadedScriptsWriter}
|
|
20
|
+
*/
|
|
21
|
+
class LoadedScriptsWriterImpl {
|
|
22
|
+
constructor() {
|
|
23
|
+
this.definition = makeStringWriter()
|
|
24
|
+
this.declaration = makeStringWriter()
|
|
25
|
+
this.combined = makeStringWriter()
|
|
30
26
|
|
|
31
|
-
|
|
27
|
+
this.writeHeaders()
|
|
32
28
|
}
|
|
33
29
|
|
|
34
30
|
/**
|
|
@@ -132,31 +128,28 @@ export class LoadedScriptsWriter {
|
|
|
132
128
|
}
|
|
133
129
|
|
|
134
130
|
/**
|
|
131
|
+
* @private
|
|
135
132
|
* @param {string} path
|
|
136
|
-
* @param {string}
|
|
137
|
-
* @param {string[]} typeParams
|
|
133
|
+
* @param {string[]} typeNames
|
|
138
134
|
* @returns {LoadedScriptsWriter}
|
|
139
135
|
*/
|
|
140
|
-
writeImportType(path,
|
|
136
|
+
writeImportType(path, ...typeNames) {
|
|
141
137
|
this.definition.writeLine("/**")
|
|
142
138
|
|
|
143
|
-
for (let tp of typeParams) {
|
|
144
|
-
this.definition.writeLine(` * @template ${tp}`)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
139
|
this.definition
|
|
148
|
-
.writeLine(
|
|
149
|
-
` * @typedef {import("${path}").${typeName}${typeParams.length > 0 ? `<${typeParams.join(", ")}>` : ""}} ${typeName}`
|
|
150
|
-
)
|
|
140
|
+
.writeLine(` * @import { ${typeNames.join(", ")} } from "${path}";`)
|
|
151
141
|
.writeLine(" */")
|
|
152
142
|
;[this.declaration, this.combined].forEach((w) => {
|
|
153
|
-
w.writeLine(
|
|
143
|
+
w.writeLine(
|
|
144
|
+
`import type { ${typeNames.join(", ")} } from "${path}";`
|
|
145
|
+
)
|
|
154
146
|
})
|
|
155
147
|
|
|
156
148
|
return this
|
|
157
149
|
}
|
|
158
150
|
|
|
159
151
|
/**
|
|
152
|
+
* @private
|
|
160
153
|
* @param {string} path
|
|
161
154
|
* @param {string[]} objectNames
|
|
162
155
|
* @returns {LoadedScriptsWriter}
|
|
@@ -173,8 +166,21 @@ export class LoadedScriptsWriter {
|
|
|
173
166
|
* @private
|
|
174
167
|
*/
|
|
175
168
|
writeHeaders() {
|
|
176
|
-
this.writeImport("@helios-lang/contract-utils", "Cast", "UserFunc")
|
|
177
169
|
this.writeImport(
|
|
170
|
+
"@helios-lang/contract-utils",
|
|
171
|
+
"makeCast",
|
|
172
|
+
"makeUserFunc"
|
|
173
|
+
)
|
|
174
|
+
|
|
175
|
+
this.writeImportType("@helios-lang/codec-utils", "IntLike")
|
|
176
|
+
this.writeImportType(
|
|
177
|
+
"@helios-lang/contract-utils",
|
|
178
|
+
"Cast",
|
|
179
|
+
"CastConfig",
|
|
180
|
+
"ConfigurableCast",
|
|
181
|
+
"UserFunc"
|
|
182
|
+
)
|
|
183
|
+
this.writeImportType(
|
|
178
184
|
"@helios-lang/ledger",
|
|
179
185
|
"Address",
|
|
180
186
|
"AssetClass",
|
|
@@ -186,8 +192,8 @@ export class LoadedScriptsWriter {
|
|
|
186
192
|
"ScriptHash",
|
|
187
193
|
"SpendingCredential",
|
|
188
194
|
"StakingCredential",
|
|
189
|
-
"StakingHash",
|
|
190
195
|
"StakingValidatorHash",
|
|
196
|
+
"TimeLike",
|
|
191
197
|
"TimeRange",
|
|
192
198
|
"TxId",
|
|
193
199
|
"TxInput",
|
|
@@ -197,19 +203,11 @@ export class LoadedScriptsWriter {
|
|
|
197
203
|
"ValidatorHash",
|
|
198
204
|
"Value"
|
|
199
205
|
)
|
|
200
|
-
this.writeImportType("@helios-lang/
|
|
201
|
-
this.writeImportType("@helios-lang/contract-utils", "CastConfig")
|
|
202
|
-
this.writeImportType(
|
|
203
|
-
"@helios-lang/contract-utils",
|
|
204
|
-
"ConfigurableCast",
|
|
205
|
-
["TStrict", "TPermissive"]
|
|
206
|
-
)
|
|
207
|
-
this.writeImportType("@helios-lang/ledger", "TimeLike")
|
|
208
|
-
this.writeImportType("@helios-lang/uplc", "UplcData")
|
|
209
|
-
this.writeImportType("@helios-lang/uplc", "UplcProgram")
|
|
206
|
+
this.writeImportType("@helios-lang/uplc", "UplcData", "UplcProgram")
|
|
210
207
|
}
|
|
211
208
|
|
|
212
209
|
/**
|
|
210
|
+
* @private
|
|
213
211
|
* @param {Record<string, TypeSchema>} types
|
|
214
212
|
*/
|
|
215
213
|
writeTypes(types) {
|
|
@@ -222,13 +220,13 @@ export class LoadedScriptsWriter {
|
|
|
222
220
|
const tsTypes = genTypes(t)
|
|
223
221
|
|
|
224
222
|
this.definition.write(
|
|
225
|
-
` ${key}: (config) => /** @type {Cast<${tsTypes[0]}, ${tsTypes[1]}>} */ (
|
|
223
|
+
` ${key}: (config) => /** @type {Cast<${tsTypes[0]}, ${tsTypes[1]}>} */ (makeCast(${JSON.stringify(t)}, config)),\n`
|
|
226
224
|
)
|
|
227
225
|
this.declaration.write(
|
|
228
226
|
` ${key}: ConfigurableCast<${tsTypes[0]}, ${tsTypes[1]}>,\n`
|
|
229
227
|
)
|
|
230
228
|
this.combined.write(
|
|
231
|
-
` ${key}: (config: CastConfig) =>
|
|
229
|
+
` ${key}: (config: CastConfig) => makeCast<${tsTypes[0]}, ${tsTypes[1]}>(${JSON.stringify(t)}, config),\n`
|
|
232
230
|
)
|
|
233
231
|
}
|
|
234
232
|
|
|
@@ -238,6 +236,7 @@ export class LoadedScriptsWriter {
|
|
|
238
236
|
}
|
|
239
237
|
|
|
240
238
|
/**
|
|
239
|
+
* @private
|
|
241
240
|
* @param {Record<string, TypeCheckedUserFunc>} functions
|
|
242
241
|
*/
|
|
243
242
|
writeFunctions(functions) {
|
|
@@ -252,13 +251,13 @@ export class LoadedScriptsWriter {
|
|
|
252
251
|
const propsStr = `{...(${JSON.stringify(fn)}), castConfig: config, validatorIndices: __validatorIndices}`
|
|
253
252
|
|
|
254
253
|
this.definition.write(
|
|
255
|
-
` "${key}": (uplc, config) => /** @type {UserFunc<${argsType}, ${retType}>} */ (
|
|
254
|
+
` "${key}": (uplc, config) => /** @type {UserFunc<${argsType}, ${retType}>} */ (makeUserFunc(uplc, ${propsStr})),\n`
|
|
256
255
|
)
|
|
257
256
|
this.declaration.write(
|
|
258
257
|
` "${key}": (uplc: UplcProgram, config: CastConfig) => UserFunc<${argsType}, ${retType}>,\n`
|
|
259
258
|
)
|
|
260
259
|
this.combined.write(
|
|
261
|
-
` "${key}": (uplc: UplcProgram, config: CastConfig) =>
|
|
260
|
+
` "${key}": (uplc: UplcProgram, config: CastConfig) => makeUserFunc<${argsType}, ${retType}>(uplc, ${propsStr}),\n`
|
|
262
261
|
)
|
|
263
262
|
}
|
|
264
263
|
|
|
@@ -320,8 +319,8 @@ ${isSome(currentScriptIndex) ? ` $currentScriptIndex: /** @type {const} */ ($
|
|
|
320
319
|
$dependencies: /** @type {const} */ ([${v.moduleDepedencies.join(", ")}]),
|
|
321
320
|
$hashDependencies: [${v.hashDependencies.filter((d) => d != v.name).join(", ")}],
|
|
322
321
|
$dependsOnOwnHash: ${v.hashDependencies.some((d) => d == v.name)},
|
|
323
|
-
$Redeemer: (config) => /** @type {Cast<${redeemerTypes[0]}, ${redeemerTypes[1]}>} */ (
|
|
324
|
-
${datumTypes ? ` $Datum: (config) => /** @type {Cast<${datumTypes[0]}, ${datumTypes[1]}>} */ (
|
|
322
|
+
$Redeemer: (config) => /** @type {Cast<${redeemerTypes[0]}, ${redeemerTypes[1]}>} */ (makeCast(${JSON.stringify(v.Redeemer)}, config)),
|
|
323
|
+
${datumTypes ? ` $Datum: (config) => /** @type {Cast<${datumTypes[0]}, ${datumTypes[1]}>} */ (makeCast(${JSON.stringify(v.Datum)}, config)),\n` : ""}`
|
|
325
324
|
)
|
|
326
325
|
|
|
327
326
|
this.declaration.write(
|
|
@@ -349,8 +348,8 @@ ${isSome(currentScriptIndex) ? ` $currentScriptIndex: ${currentScriptIndex} a
|
|
|
349
348
|
$dependencies: [${v.moduleDepedencies.join(", ")}] as const,
|
|
350
349
|
$hashDependencies: [${v.hashDependencies.filter((d) => d != v.name).join(", ")}],
|
|
351
350
|
$dependsOnOwnHash: ${v.hashDependencies.some((d) => d == v.name)} as boolean,
|
|
352
|
-
$Redeemer: (config: CastConfig) =>
|
|
353
|
-
${datumTypes ? ` $Datum: (config: CastConfig) =>
|
|
351
|
+
$Redeemer: (config: CastConfig) => makeCast<${redeemerTypes[0]}, ${redeemerTypes[1]}>(${JSON.stringify(v.Redeemer)}, config),
|
|
352
|
+
${datumTypes ? ` $Datum: (config: CastConfig) => makeCast<${datumTypes[0]}, ${datumTypes[1]}>(${JSON.stringify(v.Datum)}, config),\n` : ""}`
|
|
354
353
|
)
|
|
355
354
|
|
|
356
355
|
this.writeTypes(v.types)
|
|
@@ -362,6 +361,7 @@ ${datumTypes ? ` $Datum: (config: CastConfig) => new Cast<${datumTypes[0]}, $
|
|
|
362
361
|
}
|
|
363
362
|
|
|
364
363
|
/**
|
|
364
|
+
* @private
|
|
365
365
|
* @param {Record<string, TypeCheckedValidator>} validators
|
|
366
366
|
*/
|
|
367
367
|
writeValidatorIndices(validators) {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @import { TypeSchema } from "@helios-lang/type-utils"
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
const NONE = "
|
|
5
|
+
const NONE = "undefined"
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* TODO: handle recursive data structures
|
|
@@ -50,20 +50,12 @@ export function genTypes(schema) {
|
|
|
50
50
|
case "Real":
|
|
51
51
|
return ["number", "number"]
|
|
52
52
|
case "SpendingCredential":
|
|
53
|
-
return [
|
|
54
|
-
"SpendingCredential",
|
|
55
|
-
"SpendingCredential | PubKeyHash | ValidatorHash"
|
|
56
|
-
]
|
|
53
|
+
return ["SpendingCredential", "SpendingCredential"]
|
|
57
54
|
case "StakingCredential":
|
|
58
|
-
return [
|
|
59
|
-
"StakingCredential",
|
|
60
|
-
"StakingCredential | StakingHash | PubKeyHash | StakingValidatorHash"
|
|
61
|
-
]
|
|
55
|
+
return ["StakingCredential", "StakingCredential"]
|
|
62
56
|
case "StakingHash":
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
"StakingHash | PubKeyHash | StakingValidatorHash"
|
|
66
|
-
]
|
|
57
|
+
// TODO: implement this
|
|
58
|
+
return ["never", "never"]
|
|
67
59
|
case "StakingValidatorHash":
|
|
68
60
|
return [
|
|
69
61
|
"StakingValidatorHash",
|
package/src/codegen/index.js
CHANGED
|
@@ -1,14 +1 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @typedef {import("./LoadedModule.js").LoadedModule} LoadedModule
|
|
5
|
-
* @typedef {import("./LoadedValidator.js").LoadedValidator} LoadedValidator
|
|
6
|
-
* @typedef {import("./TypeCheckedModule.js").TypeCheckedModule} TypeCheckedModule
|
|
7
|
-
* @typedef {import("./TypeCheckedValidator.js").TypeCheckedValidator} TypeCheckedValidator
|
|
8
|
-
* @typedef {import("./TypeSchema.js").TypeSchema} TypeSchema
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @template {LoadedValidator} V
|
|
13
|
-
* @typedef {import("./LoadedValidator.js").ExtractDependencies<V>} ExtractDependencies
|
|
14
|
-
*/
|
|
1
|
+
export { makeLoadedScriptsWriter } from "./LoadedScriptsWriter.js"
|
|
@@ -1,86 +1,7 @@
|
|
|
1
1
|
import { readHeader } from "@helios-lang/compiler-utils"
|
|
2
2
|
|
|
3
|
-
export {}
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* @typedef {import("@helios-lang/uplc").PlutusVersion} PlutusVersion
|
|
7
|
-
* @typedef {import("@helios-lang/uplc").UplcData} UplcData
|
|
8
|
-
* @typedef {import("@helios-lang/uplc").UplcSourceMapJsonSafe} UplcSourceMapJsonSafe
|
|
9
|
-
* @typedef {import("../codegen/index.js").TypeSchema} InternalTypeDetails
|
|
10
|
-
* @typedef {import("../codegen/index.js").TypeCheckedModule} TypeCheckedModule
|
|
11
|
-
* @typedef {import("../codegen/index.js").TypeCheckedValidator} TypeCheckedValidator
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @typedef {any} ScriptHashType
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* if `debug` is true, the ir is included in the user functions where possible
|
|
20
|
-
* @typedef {{
|
|
21
|
-
* allValidatorHashTypes: Record<string, ScriptHashType>
|
|
22
|
-
* allValidatorIndices?: Record<string, number>
|
|
23
|
-
* hashDependencies: Record<string, string>
|
|
24
|
-
* dependsOnOwnHash?: boolean
|
|
25
|
-
* ownHash?: string
|
|
26
|
-
* parameters?: Record<string, UplcData>
|
|
27
|
-
* isTestnet: boolean
|
|
28
|
-
* optimize: boolean
|
|
29
|
-
* debug?: boolean
|
|
30
|
-
* excludeUserFuncs?: Set<string>
|
|
31
|
-
* onCompileUserFunc?: (props: {
|
|
32
|
-
* name: string
|
|
33
|
-
* cborHex: string
|
|
34
|
-
* plutusVersion: PlutusVersion
|
|
35
|
-
* ir?: string
|
|
36
|
-
* sourceMap?: UplcSourceMapJsonSafe
|
|
37
|
-
* alt?: {
|
|
38
|
-
* cborHex: string
|
|
39
|
-
* ir?: string
|
|
40
|
-
* sourceMap?: UplcSourceMapJsonSafe
|
|
41
|
-
* }
|
|
42
|
-
* }) => void
|
|
43
|
-
* }} CompileOptions
|
|
44
|
-
*/
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* @typedef {{
|
|
48
|
-
* cborHex: string
|
|
49
|
-
* plutusVersion: PlutusVersion
|
|
50
|
-
* ir?: string
|
|
51
|
-
* sourceMap?: import("@helios-lang/uplc").UplcSourceMapJsonSafe
|
|
52
|
-
* }} CompileOutput
|
|
53
|
-
*/
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @typedef {{
|
|
57
|
-
* modules: {[name: string]: TypeCheckedModule}
|
|
58
|
-
* validators: {[name: string]: TypeCheckedValidator}
|
|
59
|
-
* }} TypeCheckOutput
|
|
60
|
-
*/
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* @typedef {{
|
|
64
|
-
* name: string
|
|
65
|
-
* purpose: string
|
|
66
|
-
* sourceCode: string
|
|
67
|
-
* }} SourceDetails
|
|
68
|
-
*/
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @typedef {{
|
|
72
|
-
* version: string
|
|
73
|
-
* getScriptHashType: (purpose: string) => ScriptHashType
|
|
74
|
-
* typeCheck: (validators: string[], modules: string[]) => ({
|
|
75
|
-
* modules: {[name: string]: TypeCheckedModule},
|
|
76
|
-
* validators: {[name: string]: TypeCheckedValidator}
|
|
77
|
-
* })
|
|
78
|
-
* compile: (main: string, modules: string[], options: CompileOptions) => CompileOutput
|
|
79
|
-
* }} CompilerLib
|
|
80
|
-
*/
|
|
81
|
-
|
|
82
3
|
/**
|
|
83
|
-
* @
|
|
4
|
+
* @import { CompilerLib, ScriptHashType } from "../index.js"
|
|
84
5
|
*/
|
|
85
6
|
|
|
86
7
|
/**
|
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
import { bytesToHex } from "@helios-lang/codec-utils"
|
|
2
2
|
import { readHeader } from "@helios-lang/compiler-utils"
|
|
3
|
-
import {
|
|
3
|
+
import { expectDefined } from "@helios-lang/type-utils"
|
|
4
4
|
import { getValidatorTypes } from "./CompilerLib.js"
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* @
|
|
8
|
-
* @
|
|
9
|
-
* @
|
|
10
|
-
* @typedef {import("../codegen/index.js").TypeSchema} TypeSchema
|
|
11
|
-
* @typedef {import("./CompilerLib.js").CompileOptions} CompileOptions
|
|
12
|
-
* @typedef {import("./CompilerLib.js").CompileOutput} CompileOutput
|
|
13
|
-
* @typedef {import("./CompilerLib.js").CompilerLib} CompilerLib
|
|
14
|
-
* @typedef {import("./CompilerLib.js").DagDependencies} DagDependencies
|
|
15
|
-
* @typedef {import("./CompilerLib.js").ScriptHashType} ScriptHashType
|
|
16
|
-
* @typedef {import("./CompilerLib.js").SourceDetails} SourceDetails
|
|
17
|
-
* @typedef {import("./CompilerLib.js").TypeCheckOutput} TypeCheckOutput
|
|
7
|
+
* @import { TypeSchema } from "@helios-lang/type-utils"
|
|
8
|
+
* @import { UplcData } from "@helios-lang/uplc"
|
|
9
|
+
* @import { CompileOptions, CompileOutput, CompilerLib, DagDependencies, ScriptHashType, SourceDetails, TypeCheckOutput, TypeCheckedModule, TypeCheckedValidator } from "../index.js"
|
|
18
10
|
*/
|
|
19
11
|
|
|
20
12
|
/**
|
|
@@ -130,10 +122,18 @@ import { getValidatorTypes } from "./CompilerLib.js"
|
|
|
130
122
|
* }} UserTypes
|
|
131
123
|
*/
|
|
132
124
|
|
|
125
|
+
/**
|
|
126
|
+
* @param {any} lib
|
|
127
|
+
* @returns {CompilerLib}
|
|
128
|
+
*/
|
|
129
|
+
export function makeCompilerLib_v0_16(lib) {
|
|
130
|
+
return new CompilerLib_v0_16(lib)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
133
|
/**
|
|
134
134
|
* @implements {CompilerLib}
|
|
135
135
|
*/
|
|
136
|
-
|
|
136
|
+
class CompilerLib_v0_16 {
|
|
137
137
|
/**
|
|
138
138
|
* @param {any} lib
|
|
139
139
|
*/
|
|
@@ -570,7 +570,7 @@ export class CompilerLib_v0_16 {
|
|
|
570
570
|
const module_ =
|
|
571
571
|
moduleName.value == program.name
|
|
572
572
|
? program.mainModule
|
|
573
|
-
:
|
|
573
|
+
: expectDefined(
|
|
574
574
|
program.mainImportedModules.find(
|
|
575
575
|
(m) => m.name.value == moduleName.value
|
|
576
576
|
),
|
|
@@ -602,7 +602,7 @@ export class CompilerLib_v0_16 {
|
|
|
602
602
|
/**
|
|
603
603
|
* @private
|
|
604
604
|
* @param {any} program
|
|
605
|
-
* @param {
|
|
605
|
+
* @param {Record<string, UplcData> | undefined} parameters
|
|
606
606
|
*/
|
|
607
607
|
setParameters(program, parameters) {
|
|
608
608
|
if (!parameters) {
|