@helios-lang/contract-utils 0.2.40 → 0.2.41
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 +1 -1
- package/src/compiler/CompilerLib.js +1 -1
- package/src/compiler/CompilerLib_v0_17.js +6 -1
- package/src/context/DagCompiler.js +103 -18
- package/types/compiler/CompilerLib.d.ts +2 -2
- package/types/compiler/CompilerLib.d.ts.map +1 -1
- package/types/compiler/CompilerLib_v0_17.d.ts +4 -2
- package/types/compiler/CompilerLib_v0_17.d.ts.map +1 -1
- package/types/context/DagCompiler.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -25,7 +25,7 @@ export {}
|
|
|
25
25
|
* isTestnet: boolean
|
|
26
26
|
* optimize: boolean
|
|
27
27
|
* excludeUserFuncs?: Set<string>
|
|
28
|
-
* onCompileUserFunc?: (name: string, cborHex: string, plutusVersion: PlutusVersion) => void
|
|
28
|
+
* onCompileUserFunc?: (name: string, cborHex: string, altCborHex: Option<string>, plutusVersion: PlutusVersion) => void
|
|
29
29
|
* }} CompileOptions
|
|
30
30
|
*/
|
|
31
31
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { bytesToHex } from "@helios-lang/codec-utils"
|
|
2
|
+
import { None } from "@helios-lang/type-utils"
|
|
2
3
|
import { UplcProgramV2 } from "@helios-lang/uplc"
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* @typedef {import("@helios-lang/uplc").UplcData} UplcData
|
|
7
|
+
* @typedef {import("@helios-lang/uplc").UplcProgramV2I} UplcProgramV2I
|
|
6
8
|
* @typedef {import("./CompilerLib.js").CompilerLib} CompilerLib
|
|
7
9
|
* @typedef {import("./CompilerLib.js").CompileOptions} CompileOptions
|
|
8
10
|
* @typedef {import("./CompilerLib.js").CompileOutput} CompileOutput
|
|
@@ -21,7 +23,7 @@ import { UplcProgramV2 } from "@helios-lang/uplc"
|
|
|
21
23
|
* hashDependencies?: Record<string, string>
|
|
22
24
|
* validatorIndices?: Record<string, number>
|
|
23
25
|
* excludeUserFuncs?: Set<string>
|
|
24
|
-
* onCompileUserFunc?: (name: string, uplc:
|
|
26
|
+
* onCompileUserFunc?: (name: string, uplc: UplcProgramV2I) => void
|
|
25
27
|
* }): UplcProgramV2
|
|
26
28
|
* }} Program
|
|
27
29
|
*/
|
|
@@ -106,9 +108,12 @@ export class CompilerLib_v0_17 {
|
|
|
106
108
|
...(onCompileUserFunc
|
|
107
109
|
? {
|
|
108
110
|
onCompileUserFunc: (name, uplc) => {
|
|
111
|
+
const alt = uplc.alt
|
|
112
|
+
|
|
109
113
|
onCompileUserFunc(
|
|
110
114
|
name,
|
|
111
115
|
bytesToHex(uplc.toCbor()),
|
|
116
|
+
alt ? bytesToHex(alt.toCbor()) : None,
|
|
112
117
|
"PlutusScriptV2"
|
|
113
118
|
)
|
|
114
119
|
}
|
|
@@ -116,15 +116,7 @@ export class DagCompiler {
|
|
|
116
116
|
dependsOnOwnHash: validator.$dependsOnOwnHash,
|
|
117
117
|
parameters: parameters,
|
|
118
118
|
isTestnet: isTestnet,
|
|
119
|
-
excludeUserFuncs: excludeUserFuncs
|
|
120
|
-
onCompileUserFunc: (name, cborHex, plutusVersion) => {
|
|
121
|
-
// this compilation process is potentially very slow, so print messages indicating progress
|
|
122
|
-
console.log(`Compiled user function ${name}`)
|
|
123
|
-
this.cachedUserFuncs[name] = restoreUplcProgram(
|
|
124
|
-
plutusVersion,
|
|
125
|
-
cborHex
|
|
126
|
-
)
|
|
127
|
-
}
|
|
119
|
+
excludeUserFuncs: excludeUserFuncs
|
|
128
120
|
})
|
|
129
121
|
|
|
130
122
|
// this compilation process is potentially very slow, so print messages indicating progress
|
|
@@ -162,14 +154,26 @@ export class DagCompiler {
|
|
|
162
154
|
parameters: parameters,
|
|
163
155
|
isTestnet: isTestnet,
|
|
164
156
|
excludeUserFuncs: excludeUserFuncs,
|
|
165
|
-
onCompileUserFunc: (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
157
|
+
onCompileUserFunc: (
|
|
158
|
+
name,
|
|
159
|
+
cborHex,
|
|
160
|
+
cborHexAlt,
|
|
161
|
+
plutusVersion
|
|
162
|
+
) => {
|
|
163
|
+
let uplc = restoreUplcProgram(plutusVersion, cborHex)
|
|
164
|
+
|
|
165
|
+
if (cborHexAlt) {
|
|
166
|
+
uplc = uplc.withAlt(
|
|
167
|
+
/** @type {any} */ (
|
|
168
|
+
restoreUplcProgram(
|
|
169
|
+
plutusVersion,
|
|
170
|
+
cborHexAlt
|
|
171
|
+
)
|
|
172
|
+
)
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
this.cachedUserFuncs[name] = uplc
|
|
173
177
|
}
|
|
174
178
|
}
|
|
175
179
|
)
|
|
@@ -188,8 +192,85 @@ export class DagCompiler {
|
|
|
188
192
|
this.addValidatorToCache(validator, completeProgram, ownHash)
|
|
189
193
|
}
|
|
190
194
|
|
|
195
|
+
/**
|
|
196
|
+
* @param {LoadedValidator} validator
|
|
197
|
+
*/
|
|
198
|
+
const buildValidatorAltAndUserFuncs = (validator) => {
|
|
199
|
+
const hashDepHashes = this.getHashDepHashes(
|
|
200
|
+
validator,
|
|
201
|
+
Object.keys(hashTypes)
|
|
202
|
+
)
|
|
203
|
+
const moduleDeps = getModuleDependencies(validator)
|
|
204
|
+
const excludeUserFuncs = new Set(Object.keys(this.cachedUserFuncs))
|
|
205
|
+
|
|
206
|
+
const optimizedHash = expectSome(
|
|
207
|
+
this.cachedValidators[validator.$name]
|
|
208
|
+
)
|
|
209
|
+
const optimizedHashHex = optimizedHash.toHex()
|
|
210
|
+
const optimizedProgram = optimizedHash.context.program
|
|
211
|
+
|
|
212
|
+
// unoptimized compilation (so traces are untouched)
|
|
213
|
+
const {
|
|
214
|
+
cborHex: unoptimizedCborHex,
|
|
215
|
+
plutusVersion: unoptimPlutusVersion
|
|
216
|
+
} = this.lib.compile(
|
|
217
|
+
validator.$sourceCode,
|
|
218
|
+
Array.from(moduleDeps.values()),
|
|
219
|
+
{
|
|
220
|
+
optimize: false,
|
|
221
|
+
hashDependencies: hashDepHashes,
|
|
222
|
+
allValidatorHashTypes: hashTypes,
|
|
223
|
+
ownHash: validator.$dependsOnOwnHash
|
|
224
|
+
? optimizedHashHex
|
|
225
|
+
: undefined,
|
|
226
|
+
parameters: parameters,
|
|
227
|
+
isTestnet: isTestnet,
|
|
228
|
+
excludeUserFuncs: excludeUserFuncs,
|
|
229
|
+
onCompileUserFunc: (
|
|
230
|
+
name,
|
|
231
|
+
cborHex,
|
|
232
|
+
cborHexAlt,
|
|
233
|
+
plutusVersion
|
|
234
|
+
) => {
|
|
235
|
+
let uplc = restoreUplcProgram(plutusVersion, cborHex)
|
|
236
|
+
|
|
237
|
+
if (cborHexAlt) {
|
|
238
|
+
uplc = uplc.withAlt(
|
|
239
|
+
/** @type {any} */ (
|
|
240
|
+
restoreUplcProgram(
|
|
241
|
+
plutusVersion,
|
|
242
|
+
cborHexAlt
|
|
243
|
+
)
|
|
244
|
+
)
|
|
245
|
+
)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
this.cachedUserFuncs[name] = uplc
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
)
|
|
252
|
+
|
|
253
|
+
// TODO: with source mapping
|
|
254
|
+
const unoptimizedProgram = restoreUplcProgram(
|
|
255
|
+
unoptimPlutusVersion,
|
|
256
|
+
unoptimizedCborHex
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
const completeProgram = optimizedProgram.withAlt(
|
|
260
|
+
/** @type {any} */ (unoptimizedProgram)
|
|
261
|
+
)
|
|
262
|
+
|
|
263
|
+
this.addValidatorToCache(
|
|
264
|
+
validator,
|
|
265
|
+
completeProgram,
|
|
266
|
+
optimizedHashHex
|
|
267
|
+
)
|
|
268
|
+
}
|
|
269
|
+
|
|
191
270
|
validators.forEach((v) => buildValidator(v))
|
|
192
271
|
|
|
272
|
+
validators.forEach((v) => buildValidatorAltAndUserFuncs(v))
|
|
273
|
+
|
|
193
274
|
return {
|
|
194
275
|
validators: this.cachedValidators,
|
|
195
276
|
userFuncs: this.cachedUserFuncs
|
|
@@ -269,7 +350,11 @@ export class DagCompiler {
|
|
|
269
350
|
|
|
270
351
|
allValidators.forEach((v) => {
|
|
271
352
|
if (!(v in hashes)) {
|
|
272
|
-
|
|
353
|
+
if (v in this.cachedValidators) {
|
|
354
|
+
hashes[v] = `#${this.cachedValidators[v].toHex()}`
|
|
355
|
+
} else {
|
|
356
|
+
hashes[v] = "#"
|
|
357
|
+
}
|
|
273
358
|
}
|
|
274
359
|
})
|
|
275
360
|
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
* isTestnet: boolean
|
|
20
20
|
* optimize: boolean
|
|
21
21
|
* excludeUserFuncs?: Set<string>
|
|
22
|
-
* onCompileUserFunc?: (name: string, cborHex: string, plutusVersion: PlutusVersion) => void
|
|
22
|
+
* onCompileUserFunc?: (name: string, cborHex: string, altCborHex: Option<string>, plutusVersion: PlutusVersion) => void
|
|
23
23
|
* }} CompileOptions
|
|
24
24
|
*/
|
|
25
25
|
/**
|
|
@@ -79,7 +79,7 @@ export type CompileOptions = {
|
|
|
79
79
|
isTestnet: boolean;
|
|
80
80
|
optimize: boolean;
|
|
81
81
|
excludeUserFuncs?: Set<string> | undefined;
|
|
82
|
-
onCompileUserFunc?: ((name: string, cborHex: string, plutusVersion: PlutusVersion) => void) | undefined;
|
|
82
|
+
onCompileUserFunc?: ((name: string, cborHex: string, altCborHex: Option<string>, plutusVersion: PlutusVersion) => void) | undefined;
|
|
83
83
|
};
|
|
84
84
|
export type CompileOutput = {
|
|
85
85
|
cborHex: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CompilerLib.d.ts","sourceRoot":"","sources":["../../src/compiler/CompilerLib.js"],"names":[],"mappings":"AAIA;;;;;;GAMG;AAEH;;GAEG;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;IACnB,aAAiB,EAAE,aAAa,CAAA;CAC7B;;;;;;;;;4BAWS;IACZ,MAAU,MAAM,CAAA;IAChB,OAAW,EAAE,MAAM,CAAA;IACnB,UAAc,EAAE,MAAM,CAAA;CACnB;;aAKU,MAAM;iCACc,MAAM,KAAK,cAAc;4BAC9B,MAAM,EAAE,WAAW,MAAM,EAAE;;;;;;;;oBAInC,MAAM,WAAW,MAAM,EAAE,WAAW,cAAc,KAAK,aAAa;;8BAK5E,OAAO,MAAM,EAAE,MAAM,EAAE,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @typedef {import("@helios-lang/uplc").UplcData} UplcData
|
|
3
|
+
* @typedef {import("@helios-lang/uplc").UplcProgramV2I} UplcProgramV2I
|
|
3
4
|
* @typedef {import("./CompilerLib.js").CompilerLib} CompilerLib
|
|
4
5
|
* @typedef {import("./CompilerLib.js").CompileOptions} CompileOptions
|
|
5
6
|
* @typedef {import("./CompilerLib.js").CompileOutput} CompileOutput
|
|
@@ -17,7 +18,7 @@
|
|
|
17
18
|
* hashDependencies?: Record<string, string>
|
|
18
19
|
* validatorIndices?: Record<string, number>
|
|
19
20
|
* excludeUserFuncs?: Set<string>
|
|
20
|
-
* onCompileUserFunc?: (name: string, uplc:
|
|
21
|
+
* onCompileUserFunc?: (name: string, uplc: UplcProgramV2I) => void
|
|
21
22
|
* }): UplcProgramV2
|
|
22
23
|
* }} Program
|
|
23
24
|
*/
|
|
@@ -58,6 +59,7 @@ export class CompilerLib_v0_17 implements CompilerLib {
|
|
|
58
59
|
typeCheck(validatorSources: string[], moduleSources: string[]): TypeCheckOutput;
|
|
59
60
|
}
|
|
60
61
|
export type UplcData = import("@helios-lang/uplc").UplcData;
|
|
62
|
+
export type UplcProgramV2I = import("@helios-lang/uplc").UplcProgramV2I;
|
|
61
63
|
export type CompilerLib = import("./CompilerLib.js").CompilerLib;
|
|
62
64
|
export type CompileOptions = import("./CompilerLib.js").CompileOptions;
|
|
63
65
|
export type CompileOutput = import("./CompilerLib.js").CompileOutput;
|
|
@@ -73,7 +75,7 @@ export type Program = {
|
|
|
73
75
|
hashDependencies?: Record<string, string> | undefined;
|
|
74
76
|
validatorIndices?: Record<string, number> | undefined;
|
|
75
77
|
excludeUserFuncs?: Set<string> | undefined;
|
|
76
|
-
onCompileUserFunc?: ((name: string, uplc:
|
|
78
|
+
onCompileUserFunc?: ((name: string, uplc: UplcProgramV2I) => void) | undefined;
|
|
77
79
|
}): UplcProgramV2;
|
|
78
80
|
};
|
|
79
81
|
import { UplcProgramV2 } from "@helios-lang/uplc";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CompilerLib_v0_17.d.ts","sourceRoot":"","sources":["../../src/compiler/CompilerLib_v0_17.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"CompilerLib_v0_17.d.ts","sourceRoot":"","sources":["../../src/compiler/CompilerLib_v0_17.js"],"names":[],"mappings":"AAIA;;;;;;;;GAQG;AAEH;;;;;;;;;;;;;;GAcG;AAEH;;GAEG;AACH;IAOI;;OAEG;IACH,iBAFW,GAAG,EAIb;IAXD;;;OAGG;IACH,YAAG;IASH;;OAEG;IACH,sBAEC;IAED;;;OAGG;IACH,2BAHW,MAAM,GACJ,cAAc,CAM1B;IAED;;;;;OAKG;IACH,oBALW,MAAM,iBACN,MAAM,EAAE,WACR,cAAc,GACZ,aAAa,CA2DzB;IAED;;;;OAIG;IACH,4BAJW,MAAM,EAAE,iBACR,MAAM,EAAE,GACN,eAAe,CAM3B;CACJ;uBAtIY,OAAO,mBAAmB,EAAE,QAAQ;6BACpC,OAAO,mBAAmB,EAAE,cAAc;0BAC1C,OAAO,kBAAkB,EAAE,WAAW;6BACtC,OAAO,kBAAkB,EAAE,cAAc;4BACzC,OAAO,kBAAkB,EAAE,aAAa;6BACxC,OAAO,kBAAkB,EAAE,cAAc;8BACzC,OAAO,kBAAkB,EAAE,eAAe;;UAK5C,MAAM;wBACQ,OAAO,MAAM,CAAC;qBACjB,MAAM,SAAS,QAAQ,GAAG,IAAI;;;;;;;oCAOlB,MAAM,QAAQ,cAAc,KAAK,IAAI;QAC9D,aAAa;;8BAxBQ,mBAAmB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DagCompiler.d.ts","sourceRoot":"","sources":["../../src/context/DagCompiler.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DagCompiler.d.ts","sourceRoot":"","sources":["../../src/context/DagCompiler.js"],"names":[],"mappings":"AA+ZA;;;GAGG;AACH,iDAHW,eAAe,GACb,MAAM,EAAE,CAsBpB;AA5aD;;;;;;GAMG;AAEH;;;;;GAKG;AAEH;;GAEG;AACH;IA6BI;;;OAGG;IACH,iBAHW,WAAW,cACX,UAAU,EAOpB;IArCD;;;;OAIG;IACH,qBAAG;IAEH;;;;OAIG;IACH,wBAAM;IAEN;;;;OAIG;IACH,kCAAgB;IAEhB;;;;OAIG;IACH,iCAAe;IAQX,sDAA4B;IAKhC;;;;;;OAMG;IACH,kBANW,eAAe,EAAE,cACjB,OAAO,MAAM,EAAE,GAAG,CAAC,aACnB,OAAO;;SAEL,iBAAiB,CA2M7B;IAED;;;;;OAKG;IACH,4BAsCC;IAED;;;;;OAKG;IACH,yBA8BC;IAED;;;;;OAKG;IACH,qBAoBC;IAED;;;;;OAKG;IACH,4BAeC;CACJ;0BAjZY,OAAO,mBAAmB,EAAE,WAAW;yBACvC,OAAO,kBAAkB,EAAE,UAAU;8BACrC,OAAO,+BAA+B,EAAE,eAAe;0BACvD,OAAO,sBAAsB,EAAE,WAAW;0CAC1C,OAAO,sBAAsB,EAAE,2BAA2B"}
|