@helios-lang/contract-utils 0.1.25 → 0.1.27
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/examples/multi-validator/index.d.ts +4 -3
- package/examples/multi-validator/index.js +4 -3
- package/examples/multi-validator/utils.hl +4 -0
- package/package.json +2 -2
- package/src/cast/Cast.js +6 -8
- package/src/codegen/LoadedScriptsWriter.js +42 -21
- package/src/compiler/CompilerLib_v0_16.js +151 -62
- package/types/cast/Cast.d.ts.map +1 -1
- package/types/codegen/LoadedScriptsWriter.d.ts +7 -0
- package/types/codegen/LoadedScriptsWriter.d.ts.map +1 -1
- package/types/compiler/CompilerLib_v0_16.d.ts +50 -25
- package/types/compiler/CompilerLib_v0_16.d.ts.map +1 -1
|
@@ -5,7 +5,8 @@ export const utils: {
|
|
|
5
5
|
$name: string
|
|
6
6
|
$purpose: string
|
|
7
7
|
$sourceCode: string
|
|
8
|
-
$dependencies: []
|
|
8
|
+
$dependencies: [],
|
|
9
|
+
MyUtilType: Cast<{hello: bigint}, {hello: bigint | number | string}>,
|
|
9
10
|
}
|
|
10
11
|
export const match_string_policy: {
|
|
11
12
|
$name: "match_string_policy"
|
|
@@ -15,7 +16,6 @@ export const match_string_policy: {
|
|
|
15
16
|
$hashDependencies: []
|
|
16
17
|
$dependsOnOwnHash: boolean
|
|
17
18
|
$Redeemer: Cast<boolean, boolean>
|
|
18
|
-
|
|
19
19
|
}
|
|
20
20
|
export const match_string: {
|
|
21
21
|
$name: "match_string"
|
|
@@ -25,5 +25,6 @@ export const match_string: {
|
|
|
25
25
|
$hashDependencies: [typeof match_string_policy]
|
|
26
26
|
$dependsOnOwnHash: boolean
|
|
27
27
|
$Redeemer: Cast<string, string>
|
|
28
|
-
$Datum: Cast<{One: {message: string}} | {Two: {code: bigint}}, {One: {message: string}} | {Two: {code: bigint | number | string}}
|
|
28
|
+
$Datum: Cast<{One: {message: string}} | {Two: {code: bigint}}, {One: {message: string}} | {Two: {code: bigint | number | string}}>,
|
|
29
|
+
Datum: Cast<{One: {message: string}} | {Two: {code: bigint}}, {One: {message: string}} | {Two: {code: bigint | number | string}}>,
|
|
29
30
|
}
|
|
@@ -2,8 +2,9 @@ import { Cast } from "@helios-lang/contract-utils";
|
|
|
2
2
|
export const utils = {
|
|
3
3
|
$name: "utils",
|
|
4
4
|
$purpose: "module",
|
|
5
|
-
$sourceCode: "module utils\n\nconst my_assetclass: AssetClass = AssetClass::new(Scripts::match_string_policy, #)\n\nconst my_hash: ValidatorHash = Scripts::match_string\n\nfunc compare(a: String, b: String) -> Bool {\n a == b\n}",
|
|
5
|
+
$sourceCode: "module utils\n\nstruct MyUtilType {\n hello: Int\n}\n\nconst my_assetclass: AssetClass = AssetClass::new(Scripts::match_string_policy, #)\n\nconst my_hash: ValidatorHash = Scripts::match_string\n\nfunc compare(a: String, b: String) -> Bool {\n a == b\n}",
|
|
6
6
|
$dependencies: [],
|
|
7
|
+
MyUtilType: new Cast({"structFieldTypes":[{"name":"hello","type":{"primitiveType":"Int"}}]}),
|
|
7
8
|
}
|
|
8
9
|
export const match_string_policy = {
|
|
9
10
|
$name: "match_string_policy",
|
|
@@ -13,7 +14,6 @@ export const match_string_policy = {
|
|
|
13
14
|
$hashDependencies: [],
|
|
14
15
|
$dependsOnOwnHash: false,
|
|
15
16
|
$Redeemer: new Cast({"primitiveType":"Bool"}),
|
|
16
|
-
|
|
17
17
|
}
|
|
18
18
|
export const match_string = {
|
|
19
19
|
$name: "match_string",
|
|
@@ -23,5 +23,6 @@ export const match_string = {
|
|
|
23
23
|
$hashDependencies: [match_string_policy],
|
|
24
24
|
$dependsOnOwnHash: true,
|
|
25
25
|
$Redeemer: new Cast({"primitiveType":"String"}),
|
|
26
|
-
$Datum: new Cast({"enumVariantTypes":[{"name":"One","fieldTypes":[{"name":"message","type":{"primitiveType":"String"}}]},{"name":"Two","fieldTypes":[{"name":"code","type":{"primitiveType":"Int"}}]}]})
|
|
26
|
+
$Datum: new Cast({"enumVariantTypes":[{"name":"One","fieldTypes":[{"name":"message","type":{"primitiveType":"String"}}]},{"name":"Two","fieldTypes":[{"name":"code","type":{"primitiveType":"Int"}}]}]}),
|
|
27
|
+
Datum: new Cast({"enumVariantTypes":[{"name":"One","fieldTypes":[{"name":"message","type":{"primitiveType":"String"}}]},{"name":"Two","fieldTypes":[{"name":"code","type":{"primitiveType":"Int"}}]}]}),
|
|
27
28
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@helios-lang/contract-utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.27",
|
|
4
4
|
"description": "Convenience and type-safety utilities for using Helios validators from within Typescript",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"types": "types/index.d.ts",
|
|
@@ -40,6 +40,6 @@
|
|
|
40
40
|
"@helios-lang/compiler-utils": "^0.1.21",
|
|
41
41
|
"@helios-lang/ledger": "^0.1.21",
|
|
42
42
|
"@helios-lang/type-utils": "^0.1.8",
|
|
43
|
-
"@helios-lang/uplc": "^0.1.
|
|
43
|
+
"@helios-lang/uplc": "^0.1.23"
|
|
44
44
|
}
|
|
45
45
|
}
|
package/src/cast/Cast.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
1
|
import { decodeUtf8, encodeUtf8 } from "@helios-lang/codec-utils"
|
|
2
|
-
import { REAL_PRECISION } from "@helios-lang/compiler-utils"
|
|
3
|
-
import { None } from "@helios-lang/type-utils"
|
|
4
2
|
import {
|
|
5
3
|
Address,
|
|
6
4
|
AssetClass,
|
|
@@ -19,6 +17,7 @@ import {
|
|
|
19
17
|
ValidatorHash,
|
|
20
18
|
Value
|
|
21
19
|
} from "@helios-lang/ledger"
|
|
20
|
+
import { None } from "@helios-lang/type-utils"
|
|
22
21
|
import {
|
|
23
22
|
ByteArrayData,
|
|
24
23
|
ConstrData,
|
|
@@ -27,8 +26,10 @@ import {
|
|
|
27
26
|
MapData,
|
|
28
27
|
decodeBoolData,
|
|
29
28
|
decodeOptionData,
|
|
29
|
+
decodeRealData,
|
|
30
30
|
encodeBoolData,
|
|
31
|
-
encodeOptionData
|
|
31
|
+
encodeOptionData,
|
|
32
|
+
encodeRealData
|
|
32
33
|
} from "@helios-lang/uplc"
|
|
33
34
|
|
|
34
35
|
/**
|
|
@@ -103,7 +104,7 @@ function schemaToUplc(schema, x) {
|
|
|
103
104
|
case "PubKeyHash":
|
|
104
105
|
return PubKeyHash.fromAlike(x).toUplcData()
|
|
105
106
|
case "Real":
|
|
106
|
-
return
|
|
107
|
+
return encodeRealData(x)
|
|
107
108
|
case "ScriptHash":
|
|
108
109
|
return ScriptHash.fromAlike(x).toUplcData()
|
|
109
110
|
case "StakingCredential":
|
|
@@ -217,10 +218,7 @@ function uplcToSchema(schema, data) {
|
|
|
217
218
|
case "PubKeyHash":
|
|
218
219
|
return PubKeyHash.fromUplcData(data)
|
|
219
220
|
case "Real":
|
|
220
|
-
return (
|
|
221
|
-
Number(IntData.expect(data).value) /
|
|
222
|
-
Math.pow(10, REAL_PRECISION)
|
|
223
|
-
)
|
|
221
|
+
return decodeRealData(data)
|
|
224
222
|
case "ScriptHash":
|
|
225
223
|
return ScriptHash.fromUplcData(data)
|
|
226
224
|
case "StakingCredential":
|
|
@@ -4,6 +4,7 @@ import { genTypes } from "./TypeSchema.js"
|
|
|
4
4
|
/**
|
|
5
5
|
* @typedef {import("./TypeCheckedModule.js").TypeCheckedModule} TypeCheckedModule
|
|
6
6
|
* @typedef {import("./TypeCheckedValidator.js").TypeCheckedValidator} TypeCheckedValidator
|
|
7
|
+
* @typedef {import("./TypeSchema.js").TypeSchema} TypeSchema
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
10
|
export class LoadedScriptsWriter {
|
|
@@ -142,29 +143,44 @@ export class LoadedScriptsWriter {
|
|
|
142
143
|
})
|
|
143
144
|
}
|
|
144
145
|
|
|
146
|
+
/**
|
|
147
|
+
*
|
|
148
|
+
* @param {Record<string, TypeSchema>} types
|
|
149
|
+
*/
|
|
150
|
+
writeTypes(types) {
|
|
151
|
+
for (let key in types) {
|
|
152
|
+
const t = types[key]
|
|
153
|
+
const tsTypes = genTypes(t)
|
|
154
|
+
|
|
155
|
+
this.definition.write(
|
|
156
|
+
` ${key}: new Cast(${JSON.stringify(t)}),\n`
|
|
157
|
+
)
|
|
158
|
+
this.declaration.write(
|
|
159
|
+
` ${key}: Cast<${tsTypes[0]}, ${tsTypes[1]}>,\n`
|
|
160
|
+
)
|
|
161
|
+
this.combined.write(
|
|
162
|
+
` ${key}: new Cast<${tsTypes[0]}, ${tsTypes[1]}>(${JSON.stringify(t)}),\n`
|
|
163
|
+
)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
145
167
|
/**
|
|
146
168
|
* @private
|
|
147
169
|
* @param {TypeCheckedModule} m
|
|
148
170
|
*/
|
|
149
171
|
writeModule(m) {
|
|
150
|
-
this.definition.write(
|
|
151
|
-
`export const ${m.name} = {
|
|
172
|
+
this.definition.write(`export const ${m.name} = {
|
|
152
173
|
$name: "${m.name}",
|
|
153
174
|
$purpose: "${m.purpose}",
|
|
154
175
|
$sourceCode: ${JSON.stringify(m.sourceCode)},
|
|
155
|
-
$dependencies: [${m.moduleDepedencies.join(", ")}]
|
|
156
|
-
}
|
|
157
|
-
`
|
|
158
|
-
)
|
|
176
|
+
$dependencies: [${m.moduleDepedencies.join(", ")}],\n`)
|
|
159
177
|
|
|
160
178
|
this.declaration.write(
|
|
161
179
|
`export const ${m.name}: {
|
|
162
180
|
$name: string
|
|
163
181
|
$purpose: string
|
|
164
182
|
$sourceCode: string
|
|
165
|
-
$dependencies: [${m.moduleDepedencies.map((d) => `typeof ${d}`).join(", ")}]
|
|
166
|
-
}
|
|
167
|
-
`
|
|
183
|
+
$dependencies: [${m.moduleDepedencies.map((d) => `typeof ${d}`).join(", ")}],\n`
|
|
168
184
|
)
|
|
169
185
|
|
|
170
186
|
this.combined.write(
|
|
@@ -172,10 +188,14 @@ export class LoadedScriptsWriter {
|
|
|
172
188
|
$name: "${m.name}" as "${m.name}",
|
|
173
189
|
$purpose: "${m.purpose}" as "${m.purpose}",
|
|
174
190
|
$sourceCode: ${JSON.stringify(m.sourceCode)} as string,
|
|
175
|
-
$dependencies: [${m.moduleDepedencies.join(", ")}]
|
|
176
|
-
}
|
|
177
|
-
`
|
|
191
|
+
$dependencies: [${m.moduleDepedencies.join(", ")}],\n`
|
|
178
192
|
)
|
|
193
|
+
|
|
194
|
+
this.writeTypes(m.types)
|
|
195
|
+
|
|
196
|
+
this.definition.write(`}\n`)
|
|
197
|
+
this.declaration.write(`}\n`)
|
|
198
|
+
this.combined.write(`}\n`)
|
|
179
199
|
}
|
|
180
200
|
|
|
181
201
|
/**
|
|
@@ -195,10 +215,9 @@ export class LoadedScriptsWriter {
|
|
|
195
215
|
$hashDependencies: [${v.hashDependencies.filter((d) => d != v.name).join(", ")}],
|
|
196
216
|
$dependsOnOwnHash: ${v.hashDependencies.some((d) => d == v.name)},
|
|
197
217
|
$Redeemer: new Cast(${JSON.stringify(v.Redeemer)}),
|
|
198
|
-
|
|
199
|
-
}
|
|
200
|
-
`
|
|
218
|
+
${datumTypes ? ` $Datum: new Cast(${JSON.stringify(v.Datum)}),\n` : ""}`
|
|
201
219
|
)
|
|
220
|
+
|
|
202
221
|
this.declaration.write(
|
|
203
222
|
`export const ${v.name}: {
|
|
204
223
|
$name: "${v.name}"
|
|
@@ -211,9 +230,7 @@ export class LoadedScriptsWriter {
|
|
|
211
230
|
.join(", ")}]
|
|
212
231
|
$dependsOnOwnHash: boolean
|
|
213
232
|
$Redeemer: Cast<${redeemerTypes[0]}, ${redeemerTypes[1]}>
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
`
|
|
233
|
+
${datumTypes ? ` $Datum: Cast<${datumTypes[0]}, ${datumTypes[1]}>,\n` : ""}`
|
|
217
234
|
)
|
|
218
235
|
|
|
219
236
|
this.combined.write(
|
|
@@ -225,9 +242,13 @@ export class LoadedScriptsWriter {
|
|
|
225
242
|
$hashDependencies: [${v.hashDependencies.filter((d) => d != v.name).join(", ")}],
|
|
226
243
|
$dependsOnOwnHash: ${v.hashDependencies.some((d) => d == v.name)} as boolean,
|
|
227
244
|
$Redeemer: new Cast<${redeemerTypes[0]}, ${redeemerTypes[1]}>(${JSON.stringify(v.Redeemer)}),
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
`
|
|
245
|
+
${datumTypes ? ` $Datum: new Cast<${datumTypes[0]}, ${datumTypes[1]}>(${JSON.stringify(v.Datum)}),\n` : ""}`
|
|
231
246
|
)
|
|
247
|
+
|
|
248
|
+
this.writeTypes(v.types)
|
|
249
|
+
|
|
250
|
+
this.definition.write(`}\n`)
|
|
251
|
+
this.declaration.write(`}\n`)
|
|
252
|
+
this.combined.write(`}\n`)
|
|
232
253
|
}
|
|
233
254
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { bytesToHex } from "@helios-lang/compiler"
|
|
2
2
|
import { readHeader } from "@helios-lang/compiler-utils"
|
|
3
|
+
import { expectSome } from "@helios-lang/type-utils"
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* @typedef {import("../codegen/index.js").TypeCheckedModule} TypeCheckedModule
|
|
@@ -31,18 +32,8 @@ import { readHeader } from "@helios-lang/compiler-utils"
|
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
* @typedef {{
|
|
34
|
-
* name:
|
|
35
|
-
* }}
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @typedef {{
|
|
40
|
-
* name: string
|
|
41
|
-
* }} StructStatement
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @typedef {StructStatement | EnumStatement | any} Statement
|
|
35
|
+
* name: WordToken
|
|
36
|
+
* }} Statement
|
|
46
37
|
*/
|
|
47
38
|
|
|
48
39
|
/**
|
|
@@ -71,14 +62,34 @@ import { readHeader } from "@helios-lang/compiler-utils"
|
|
|
71
62
|
* @typedef {{
|
|
72
63
|
* name: string
|
|
73
64
|
* purpose: "testing" | "minting" | "spending" | "staking" | "endpoint" | "module" | "unknown"
|
|
74
|
-
* toIR
|
|
65
|
+
* toIR(ctx: any, extra: Map<string, IR>): IR
|
|
75
66
|
* types: UserTypes
|
|
76
67
|
* mainImportedModules: Module[]
|
|
77
68
|
* mainModule: Module
|
|
78
69
|
* mainArgTypes: DataType[]
|
|
70
|
+
* throwErrors()
|
|
71
|
+
* evalTypes(validatorTypes: {[name: string]: ScriptHashType}): TopScope
|
|
79
72
|
* }} Program
|
|
80
73
|
*/
|
|
81
74
|
|
|
75
|
+
/**
|
|
76
|
+
* @typedef {{
|
|
77
|
+
* getModuleScope(name: WordToken): Scope
|
|
78
|
+
* }} TopScope
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* @typedef {{
|
|
83
|
+
* asDataType?: DataType
|
|
84
|
+
* }} HeliosType
|
|
85
|
+
*/
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @typedef {{
|
|
89
|
+
* loopTypes(callback: (name: string, type: HeliosType) => void)
|
|
90
|
+
* }} Scope
|
|
91
|
+
*/
|
|
92
|
+
|
|
82
93
|
/**
|
|
83
94
|
* @typedef {{
|
|
84
95
|
* typeDetails?: TypeDetails
|
|
@@ -161,6 +172,53 @@ export class CompilerLib_v0_16 {
|
|
|
161
172
|
}
|
|
162
173
|
}
|
|
163
174
|
|
|
175
|
+
/**
|
|
176
|
+
* @param {string} main
|
|
177
|
+
* @param {string[]} modules
|
|
178
|
+
* @param {CompileOptions} options
|
|
179
|
+
* @returns {CompileOutput}
|
|
180
|
+
*/
|
|
181
|
+
compile(main, modules, options) {
|
|
182
|
+
const [purpose, name] = readHeader(main)
|
|
183
|
+
|
|
184
|
+
// use `Program.newInternal()` instead of `Program.new()` so we can inject custom IR before finally compiling to a UplcProgram
|
|
185
|
+
const program = this.lib.Program.newInternal(
|
|
186
|
+
main,
|
|
187
|
+
modules,
|
|
188
|
+
options.allValidatorHashTypes,
|
|
189
|
+
{
|
|
190
|
+
allowPosParams: false,
|
|
191
|
+
invertEntryPoint: true
|
|
192
|
+
}
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
const extra = this.generateExtraIRDefinitions(
|
|
196
|
+
name,
|
|
197
|
+
purpose,
|
|
198
|
+
program.nPosParams,
|
|
199
|
+
options
|
|
200
|
+
)
|
|
201
|
+
const optimize = options.optimize
|
|
202
|
+
const ir = program.toIR(new this.lib.ToIRContext(optimize), extra)
|
|
203
|
+
|
|
204
|
+
const irProgram =
|
|
205
|
+
program.nPosParams > 0
|
|
206
|
+
? this.lib.IRParametricProgram.new(
|
|
207
|
+
ir,
|
|
208
|
+
purpose,
|
|
209
|
+
program.nPosParams,
|
|
210
|
+
optimize
|
|
211
|
+
)
|
|
212
|
+
: this.lib.IRProgram.new(ir, purpose, optimize)
|
|
213
|
+
|
|
214
|
+
const cborHex = bytesToHex(irProgram.toUplc().toCbor())
|
|
215
|
+
|
|
216
|
+
return {
|
|
217
|
+
prettyIR: irProgram.program.annotate(),
|
|
218
|
+
cborHex
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
164
222
|
/**
|
|
165
223
|
* @param {string[]} validators
|
|
166
224
|
* @param {string[]} modules
|
|
@@ -200,6 +258,7 @@ export class CompilerLib_v0_16 {
|
|
|
200
258
|
const purpose = v.purpose
|
|
201
259
|
const sourceCode = v.mainModule.name.site.src.raw
|
|
202
260
|
const hashDependencies = dag[name]
|
|
261
|
+
const allTypes = this.getProgramTypes(v, validatorTypes)
|
|
203
262
|
|
|
204
263
|
const allModules = v.mainImportedModules
|
|
205
264
|
const moduleDepedencies = v.mainModule
|
|
@@ -212,7 +271,14 @@ export class CompilerLib_v0_16 {
|
|
|
212
271
|
sourceCode: sourceCode,
|
|
213
272
|
hashDependencies: hashDependencies,
|
|
214
273
|
moduleDepedencies: moduleDepedencies,
|
|
215
|
-
types:
|
|
274
|
+
types: Object.fromEntries(
|
|
275
|
+
Object.entries(allTypes[name]).map(
|
|
276
|
+
([typeName, typeDetails]) => [
|
|
277
|
+
typeName,
|
|
278
|
+
this.getInternalTypeDetails(typeDetails)
|
|
279
|
+
]
|
|
280
|
+
)
|
|
281
|
+
),
|
|
216
282
|
Redeemer: this.getInternalTypeDetails(
|
|
217
283
|
v.mainArgTypes[purpose == "spending" ? 1 : 0]
|
|
218
284
|
),
|
|
@@ -238,7 +304,14 @@ export class CompilerLib_v0_16 {
|
|
|
238
304
|
moduleDepedencies: m
|
|
239
305
|
.filterDependencies(allModules)
|
|
240
306
|
.map((m) => m.name.value),
|
|
241
|
-
types:
|
|
307
|
+
types: Object.fromEntries(
|
|
308
|
+
Object.entries(allTypes[name]).map(
|
|
309
|
+
([typeName, typeDetails]) => [
|
|
310
|
+
typeName,
|
|
311
|
+
this.getInternalTypeDetails(typeDetails)
|
|
312
|
+
]
|
|
313
|
+
)
|
|
314
|
+
)
|
|
242
315
|
}
|
|
243
316
|
}
|
|
244
317
|
}
|
|
@@ -315,53 +388,6 @@ export class CompilerLib_v0_16 {
|
|
|
315
388
|
return extra
|
|
316
389
|
}
|
|
317
390
|
|
|
318
|
-
/**
|
|
319
|
-
* @param {string} main
|
|
320
|
-
* @param {string[]} modules
|
|
321
|
-
* @param {CompileOptions} options
|
|
322
|
-
* @returns {CompileOutput}
|
|
323
|
-
*/
|
|
324
|
-
compile(main, modules, options) {
|
|
325
|
-
const [purpose, name] = readHeader(main)
|
|
326
|
-
|
|
327
|
-
// use `Program.newInternal()` instead of `Program.new()` so we can inject custom IR before finally compiling to a UplcProgram
|
|
328
|
-
const program = this.lib.Program.newInternal(
|
|
329
|
-
main,
|
|
330
|
-
modules,
|
|
331
|
-
options.allValidatorHashTypes,
|
|
332
|
-
{
|
|
333
|
-
allowPosParams: false,
|
|
334
|
-
invertEntryPoint: true
|
|
335
|
-
}
|
|
336
|
-
)
|
|
337
|
-
|
|
338
|
-
const extra = this.generateExtraIRDefinitions(
|
|
339
|
-
name,
|
|
340
|
-
purpose,
|
|
341
|
-
program.nPosParams,
|
|
342
|
-
options
|
|
343
|
-
)
|
|
344
|
-
const optimize = options.optimize
|
|
345
|
-
const ir = program.toIR(new this.lib.ToIRContext(optimize), extra)
|
|
346
|
-
|
|
347
|
-
const irProgram =
|
|
348
|
-
program.nPosParams > 0
|
|
349
|
-
? this.lib.IRParametricProgram.new(
|
|
350
|
-
ir,
|
|
351
|
-
purpose,
|
|
352
|
-
program.nPosParams,
|
|
353
|
-
optimize
|
|
354
|
-
)
|
|
355
|
-
: this.lib.IRProgram.new(ir, purpose, optimize)
|
|
356
|
-
|
|
357
|
-
const cborHex = bytesToHex(irProgram.toUplc().toCbor())
|
|
358
|
-
|
|
359
|
-
return {
|
|
360
|
-
prettyIR: irProgram.program.annotate(),
|
|
361
|
-
cborHex
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
391
|
/**
|
|
366
392
|
* @private
|
|
367
393
|
* @param {string[]} validators
|
|
@@ -472,9 +498,72 @@ export class CompilerLib_v0_16 {
|
|
|
472
498
|
} catch (e) {
|
|
473
499
|
if (e.message.includes("Data")) {
|
|
474
500
|
return { primitiveType: "Data" }
|
|
501
|
+
} else if (e.message.includes("DCert")) {
|
|
502
|
+
return { primitiveType: "DCert" }
|
|
503
|
+
} else if (e.message.includes("Credential")) {
|
|
504
|
+
return { primitiveType: "SpendingCredential" }
|
|
505
|
+
} else if (e.message.includes("OutputDatum")) {
|
|
506
|
+
return { primitiveType: "TxOutputDatum" }
|
|
507
|
+
} else if (e.message.includes("PubKey")) {
|
|
508
|
+
return { primitiveType: "PubKey" }
|
|
509
|
+
} else if (e.message.includes("ScriptHash")) {
|
|
510
|
+
return { primitiveType: "ScriptHash" }
|
|
475
511
|
} else {
|
|
476
512
|
throw e
|
|
477
513
|
}
|
|
478
514
|
}
|
|
479
515
|
}
|
|
516
|
+
|
|
517
|
+
/**
|
|
518
|
+
* @private
|
|
519
|
+
* @param {Program} program
|
|
520
|
+
* @param {{[name: string]: ScriptHashType}} validatorTypes
|
|
521
|
+
* @returns {Record<string, Record<string, DataType>>}}
|
|
522
|
+
*/
|
|
523
|
+
getProgramTypes(program, validatorTypes) {
|
|
524
|
+
const topScope = program.evalTypes(validatorTypes)
|
|
525
|
+
|
|
526
|
+
program.throwErrors()
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* @type {Record<string, Record<string, DataType>>}
|
|
530
|
+
*/
|
|
531
|
+
const result = {}
|
|
532
|
+
|
|
533
|
+
if (program.purpose != "endpoint") {
|
|
534
|
+
const moduleNames = [program.mainModule.name].concat(
|
|
535
|
+
program.mainImportedModules.map((m) => m.name)
|
|
536
|
+
)
|
|
537
|
+
|
|
538
|
+
for (let moduleName of moduleNames) {
|
|
539
|
+
const module_ =
|
|
540
|
+
moduleName.value == program.name
|
|
541
|
+
? program.mainModule
|
|
542
|
+
: expectSome(
|
|
543
|
+
program.mainImportedModules.find(
|
|
544
|
+
(m) => m.name.value == moduleName.value
|
|
545
|
+
)
|
|
546
|
+
)
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* @type {Record<string, DataType>}
|
|
550
|
+
*/
|
|
551
|
+
const moduleTypes = {}
|
|
552
|
+
|
|
553
|
+
const moduleScope = topScope.getModuleScope(moduleName)
|
|
554
|
+
|
|
555
|
+
moduleScope.loopTypes((name, type) => {
|
|
556
|
+
if (module_.statements.some((s) => s.name.value == name)) {
|
|
557
|
+
if (type?.asDataType) {
|
|
558
|
+
moduleTypes[name] = type.asDataType
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
})
|
|
562
|
+
|
|
563
|
+
result[moduleName.value] = moduleTypes
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
return result
|
|
568
|
+
}
|
|
480
569
|
}
|
package/types/cast/Cast.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cast.d.ts","sourceRoot":"","sources":["../../src/cast/Cast.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Cast.d.ts","sourceRoot":"","sources":["../../src/cast/Cast.js"],"names":[],"mappings":"AAkCA;;;GAGG;AAEH;;;GAGG;AACH;IAOI;;OAEG;IACH,oBAFW,UAAU,EAIpB;IAXD;;;OAGG;IACH,iBAFU,UAAU,CAEd;IASN;;;OAGG;IACH,mBAHW,QAAQ,GACN,OAAO,CAInB;IAED;;;OAGG;IACH,cAHW,WAAW,GACT,QAAQ,CAIpB;CACJ;uBArCY,OAAO,mBAAmB,EAAE,QAAQ;yBACpC,OAAO,qBAAqB,EAAE,UAAU"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @typedef {import("./TypeCheckedModule.js").TypeCheckedModule} TypeCheckedModule
|
|
3
3
|
* @typedef {import("./TypeCheckedValidator.js").TypeCheckedValidator} TypeCheckedValidator
|
|
4
|
+
* @typedef {import("./TypeSchema.js").TypeSchema} TypeSchema
|
|
4
5
|
*/
|
|
5
6
|
export class LoadedScriptsWriter {
|
|
6
7
|
/**
|
|
@@ -40,6 +41,11 @@ export class LoadedScriptsWriter {
|
|
|
40
41
|
* @private
|
|
41
42
|
*/
|
|
42
43
|
private writeHeaders;
|
|
44
|
+
/**
|
|
45
|
+
*
|
|
46
|
+
* @param {Record<string, TypeSchema>} types
|
|
47
|
+
*/
|
|
48
|
+
writeTypes(types: Record<string, TypeSchema>): void;
|
|
43
49
|
/**
|
|
44
50
|
* @private
|
|
45
51
|
* @param {TypeCheckedModule} m
|
|
@@ -53,5 +59,6 @@ export class LoadedScriptsWriter {
|
|
|
53
59
|
}
|
|
54
60
|
export type TypeCheckedModule = import("./TypeCheckedModule.js").TypeCheckedModule;
|
|
55
61
|
export type TypeCheckedValidator = import("./TypeCheckedValidator.js").TypeCheckedValidator;
|
|
62
|
+
export type TypeSchema = import("./TypeSchema.js").TypeSchema;
|
|
56
63
|
import { StringWriter } from "@helios-lang/codec-utils";
|
|
57
64
|
//# sourceMappingURL=LoadedScriptsWriter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LoadedScriptsWriter.d.ts","sourceRoot":"","sources":["../../src/codegen/LoadedScriptsWriter.js"],"names":[],"mappings":"AAGA
|
|
1
|
+
{"version":3,"file":"LoadedScriptsWriter.d.ts","sourceRoot":"","sources":["../../src/codegen/LoadedScriptsWriter.js"],"names":[],"mappings":"AAGA;;;;GAIG;AAEH;IAUI;;;OAGG;IACH,gBAFa,mBAAmB,CAQ/B;IAfG,yBAAoC;IACpC,0BAAqC;IACrC,uBAAkC;IAetC;;;OAGG;IACH;;QAFa,mBAAmB,CAgC/B;IAED;;;OAGG;IACH;;QAFa,mBAAmB,CAkC/B;IAED;;OAEG;IACH,YAFa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAQpC;IAED;;;;;OAKG;IACH,cAKC;IAED;;OAEG;IACH,qBAWC;IAED;;;OAGG;IACH,kBAFW,OAAO,MAAM,EAAE,UAAU,CAAC,QAiBpC;IAED;;;OAGG;IACH,oBA4BC;IAED;;;OAGG;IACH,uBAgDC;CACJ;gCAzPY,OAAO,wBAAwB,EAAE,iBAAiB;mCAClD,OAAO,2BAA2B,EAAE,oBAAoB;yBACxD,OAAO,iBAAiB,EAAE,UAAU;6BANpB,0BAA0B"}
|
|
@@ -24,16 +24,8 @@
|
|
|
24
24
|
*/
|
|
25
25
|
/**
|
|
26
26
|
* @typedef {{
|
|
27
|
-
* name:
|
|
28
|
-
* }}
|
|
29
|
-
*/
|
|
30
|
-
/**
|
|
31
|
-
* @typedef {{
|
|
32
|
-
* name: string
|
|
33
|
-
* }} StructStatement
|
|
34
|
-
*/
|
|
35
|
-
/**
|
|
36
|
-
* @typedef {StructStatement | EnumStatement | any} Statement
|
|
27
|
+
* name: WordToken
|
|
28
|
+
* }} Statement
|
|
37
29
|
*/
|
|
38
30
|
/**
|
|
39
31
|
* @typedef {{
|
|
@@ -59,13 +51,30 @@
|
|
|
59
51
|
* @typedef {{
|
|
60
52
|
* name: string
|
|
61
53
|
* purpose: "testing" | "minting" | "spending" | "staking" | "endpoint" | "module" | "unknown"
|
|
62
|
-
* toIR
|
|
54
|
+
* toIR(ctx: any, extra: Map<string, IR>): IR
|
|
63
55
|
* types: UserTypes
|
|
64
56
|
* mainImportedModules: Module[]
|
|
65
57
|
* mainModule: Module
|
|
66
58
|
* mainArgTypes: DataType[]
|
|
59
|
+
* throwErrors()
|
|
60
|
+
* evalTypes(validatorTypes: {[name: string]: ScriptHashType}): TopScope
|
|
67
61
|
* }} Program
|
|
68
62
|
*/
|
|
63
|
+
/**
|
|
64
|
+
* @typedef {{
|
|
65
|
+
* getModuleScope(name: WordToken): Scope
|
|
66
|
+
* }} TopScope
|
|
67
|
+
*/
|
|
68
|
+
/**
|
|
69
|
+
* @typedef {{
|
|
70
|
+
* asDataType?: DataType
|
|
71
|
+
* }} HeliosType
|
|
72
|
+
*/
|
|
73
|
+
/**
|
|
74
|
+
* @typedef {{
|
|
75
|
+
* loopTypes(callback: (name: string, type: HeliosType) => void)
|
|
76
|
+
* }} Scope
|
|
77
|
+
*/
|
|
69
78
|
/**
|
|
70
79
|
* @typedef {{
|
|
71
80
|
* typeDetails?: TypeDetails
|
|
@@ -126,6 +135,13 @@ export class CompilerLib_v0_16 implements CompilerLib {
|
|
|
126
135
|
* @returns {ScriptHashType}
|
|
127
136
|
*/
|
|
128
137
|
getScriptHashType(purpose: string): ScriptHashType;
|
|
138
|
+
/**
|
|
139
|
+
* @param {string} main
|
|
140
|
+
* @param {string[]} modules
|
|
141
|
+
* @param {CompileOptions} options
|
|
142
|
+
* @returns {CompileOutput}
|
|
143
|
+
*/
|
|
144
|
+
compile(main: string, modules: string[], options: CompileOptions): CompileOutput;
|
|
129
145
|
/**
|
|
130
146
|
* @param {string[]} validators
|
|
131
147
|
* @param {string[]} modules
|
|
@@ -145,13 +161,6 @@ export class CompilerLib_v0_16 implements CompilerLib {
|
|
|
145
161
|
* @returns {Map<string, IR>}
|
|
146
162
|
*/
|
|
147
163
|
private generateExtraIRDefinitions;
|
|
148
|
-
/**
|
|
149
|
-
* @param {string} main
|
|
150
|
-
* @param {string[]} modules
|
|
151
|
-
* @param {CompileOptions} options
|
|
152
|
-
* @returns {CompileOutput}
|
|
153
|
-
*/
|
|
154
|
-
compile(main: string, modules: string[], options: CompileOptions): CompileOutput;
|
|
155
164
|
/**
|
|
156
165
|
* @private
|
|
157
166
|
* @param {string[]} validators
|
|
@@ -188,6 +197,13 @@ export class CompilerLib_v0_16 implements CompilerLib {
|
|
|
188
197
|
* @returns {InternalTypeDetails}
|
|
189
198
|
*/
|
|
190
199
|
private getInternalTypeDetails;
|
|
200
|
+
/**
|
|
201
|
+
* @private
|
|
202
|
+
* @param {Program} program
|
|
203
|
+
* @param {{[name: string]: ScriptHashType}} validatorTypes
|
|
204
|
+
* @returns {Record<string, Record<string, DataType>>}}
|
|
205
|
+
*/
|
|
206
|
+
private getProgramTypes;
|
|
191
207
|
}
|
|
192
208
|
export type TypeCheckedModule = import("../codegen/index.js").TypeCheckedModule;
|
|
193
209
|
export type TypeCheckedValidator = import("../codegen/index.js").TypeCheckedValidator;
|
|
@@ -204,13 +220,9 @@ export type ScriptHashType = {};
|
|
|
204
220
|
export type IR = {
|
|
205
221
|
includes: (m: string) => boolean;
|
|
206
222
|
};
|
|
207
|
-
export type
|
|
208
|
-
name:
|
|
209
|
-
};
|
|
210
|
-
export type StructStatement = {
|
|
211
|
-
name: string;
|
|
223
|
+
export type Statement = {
|
|
224
|
+
name: WordToken;
|
|
212
225
|
};
|
|
213
|
-
export type Statement = StructStatement | EnumStatement | any;
|
|
214
226
|
export type Site = {
|
|
215
227
|
src: {
|
|
216
228
|
raw: string;
|
|
@@ -228,11 +240,24 @@ export type Module = {
|
|
|
228
240
|
export type Program = {
|
|
229
241
|
name: string;
|
|
230
242
|
purpose: "testing" | "minting" | "spending" | "staking" | "endpoint" | "module" | "unknown";
|
|
231
|
-
toIR
|
|
243
|
+
toIR(ctx: any, extra: Map<string, IR>): IR;
|
|
232
244
|
types: UserTypes;
|
|
233
245
|
mainImportedModules: Module[];
|
|
234
246
|
mainModule: Module;
|
|
235
247
|
mainArgTypes: DataType[];
|
|
248
|
+
throwErrors(): any;
|
|
249
|
+
evalTypes(validatorTypes: {
|
|
250
|
+
[name: string]: ScriptHashType;
|
|
251
|
+
}): TopScope;
|
|
252
|
+
};
|
|
253
|
+
export type TopScope = {
|
|
254
|
+
getModuleScope(name: WordToken): Scope;
|
|
255
|
+
};
|
|
256
|
+
export type HeliosType = {
|
|
257
|
+
asDataType?: DataType;
|
|
258
|
+
};
|
|
259
|
+
export type Scope = {
|
|
260
|
+
loopTypes(callback: (name: string, type: HeliosType) => void): any;
|
|
236
261
|
};
|
|
237
262
|
export type DataType = {
|
|
238
263
|
typeDetails?: TypeDetails;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CompilerLib_v0_16.d.ts","sourceRoot":"","sources":["../../src/compiler/CompilerLib_v0_16.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CompilerLib_v0_16.d.ts","sourceRoot":"","sources":["../../src/compiler/CompilerLib_v0_16.js"],"names":[],"mappings":"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"}
|