@helios-lang/contract-utils 0.2.40 → 0.2.42
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 +59 -21
- 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
|
|
@@ -147,6 +139,26 @@ export class DagCompiler {
|
|
|
147
139
|
}
|
|
148
140
|
}
|
|
149
141
|
|
|
142
|
+
this.addValidatorToCache(validator, optimizedProgram, ownHash)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @param {LoadedValidator} validator
|
|
147
|
+
*/
|
|
148
|
+
const buildValidatorAltAndUserFuncs = (validator) => {
|
|
149
|
+
const hashDepHashes = this.getHashDepHashes(
|
|
150
|
+
validator,
|
|
151
|
+
Object.keys(hashTypes)
|
|
152
|
+
)
|
|
153
|
+
const moduleDeps = getModuleDependencies(validator)
|
|
154
|
+
const excludeUserFuncs = new Set(Object.keys(this.cachedUserFuncs))
|
|
155
|
+
|
|
156
|
+
const optimizedHash = expectSome(
|
|
157
|
+
this.cachedValidators[validator.$name]
|
|
158
|
+
)
|
|
159
|
+
const optimizedHashHex = optimizedHash.toHex()
|
|
160
|
+
const optimizedProgram = optimizedHash.context.program
|
|
161
|
+
|
|
150
162
|
// unoptimized compilation (so traces are untouched)
|
|
151
163
|
const {
|
|
152
164
|
cborHex: unoptimizedCborHex,
|
|
@@ -158,22 +170,39 @@ export class DagCompiler {
|
|
|
158
170
|
optimize: false,
|
|
159
171
|
hashDependencies: hashDepHashes,
|
|
160
172
|
allValidatorHashTypes: hashTypes,
|
|
161
|
-
ownHash: validator.$dependsOnOwnHash
|
|
173
|
+
ownHash: validator.$dependsOnOwnHash
|
|
174
|
+
? optimizedHashHex
|
|
175
|
+
: undefined,
|
|
162
176
|
parameters: parameters,
|
|
163
177
|
isTestnet: isTestnet,
|
|
164
178
|
excludeUserFuncs: excludeUserFuncs,
|
|
165
|
-
onCompileUserFunc: (
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
)
|
|
179
|
+
onCompileUserFunc: (
|
|
180
|
+
name,
|
|
181
|
+
cborHex,
|
|
182
|
+
cborHexAlt,
|
|
183
|
+
plutusVersion
|
|
184
|
+
) => {
|
|
185
|
+
console.log(`Compiled user function ${name}`)
|
|
186
|
+
let uplc = restoreUplcProgram(plutusVersion, cborHex)
|
|
187
|
+
|
|
188
|
+
if (cborHexAlt) {
|
|
189
|
+
uplc = uplc.withAlt(
|
|
190
|
+
/** @type {any} */ (
|
|
191
|
+
restoreUplcProgram(
|
|
192
|
+
plutusVersion,
|
|
193
|
+
cborHexAlt
|
|
194
|
+
)
|
|
195
|
+
)
|
|
196
|
+
)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
this.cachedUserFuncs[name] = uplc
|
|
173
200
|
}
|
|
174
201
|
}
|
|
175
202
|
)
|
|
176
203
|
|
|
204
|
+
console.log(`Compiled validator ${validator.$name} (unoptimized)`)
|
|
205
|
+
|
|
177
206
|
// TODO: with source mapping
|
|
178
207
|
const unoptimizedProgram = restoreUplcProgram(
|
|
179
208
|
unoptimPlutusVersion,
|
|
@@ -184,12 +213,17 @@ export class DagCompiler {
|
|
|
184
213
|
/** @type {any} */ (unoptimizedProgram)
|
|
185
214
|
)
|
|
186
215
|
|
|
187
|
-
|
|
188
|
-
|
|
216
|
+
this.addValidatorToCache(
|
|
217
|
+
validator,
|
|
218
|
+
completeProgram,
|
|
219
|
+
optimizedHashHex
|
|
220
|
+
)
|
|
189
221
|
}
|
|
190
222
|
|
|
191
223
|
validators.forEach((v) => buildValidator(v))
|
|
192
224
|
|
|
225
|
+
validators.forEach((v) => buildValidatorAltAndUserFuncs(v))
|
|
226
|
+
|
|
193
227
|
return {
|
|
194
228
|
validators: this.cachedValidators,
|
|
195
229
|
userFuncs: this.cachedUserFuncs
|
|
@@ -269,7 +303,11 @@ export class DagCompiler {
|
|
|
269
303
|
|
|
270
304
|
allValidators.forEach((v) => {
|
|
271
305
|
if (!(v in hashes)) {
|
|
272
|
-
|
|
306
|
+
if (v in this.cachedValidators) {
|
|
307
|
+
hashes[v] = `#${this.cachedValidators[v].toHex()}`
|
|
308
|
+
} else {
|
|
309
|
+
hashes[v] = "#"
|
|
310
|
+
}
|
|
273
311
|
}
|
|
274
312
|
})
|
|
275
313
|
|
|
@@ -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;AAEH;;;;;;;;;;;;;GAaG;AAEH;;;;;GAKG;AAEH;;;;;GAKG;AAEH;;;;;;GAMG;AAEH;;;;;;;;;;GAUG;AAEH;;GAEG;AAEH;;;;GAIG;AACH,uCAJW,WAAW,cACX,MAAM,EAAE;;EAUlB;4BA5EY,OAAO,mBAAmB,EAAE,aAAa;uBACzC,OAAO,mBAAmB,EAAE,QAAQ;kCACpC,OAAO,qBAAqB,EAAE,UAAU;gCACxC,OAAO,qBAAqB,EAAE,iBAAiB;mCAC/C,OAAO,qBAAqB,EAAE,oBAAoB;6BAIlD,GAAG;;2BAKY,OAAO,MAAM,EAAE,cAAc,CAAC;;sBAEnC,OAAO,MAAM,EAAE,MAAM,CAAC;;;;eAI7B,OAAO;cACR,OAAO;;gCAEU,MAAM,WAAW,MAAM,iBAAiB,aAAa,KAAK,IAAI;;
|
|
1
|
+
{"version":3,"file":"CompilerLib.d.ts","sourceRoot":"","sources":["../../src/compiler/CompilerLib.js"],"names":[],"mappings":"AAIA;;;;;;GAMG;AAEH;;GAEG;AAEH;;;;;;;;;;;;;GAaG;AAEH;;;;;GAKG;AAEH;;;;;GAKG;AAEH;;;;;;GAMG;AAEH;;;;;;;;;;GAUG;AAEH;;GAEG;AAEH;;;;GAIG;AACH,uCAJW,WAAW,cACX,MAAM,EAAE;;EAUlB;4BA5EY,OAAO,mBAAmB,EAAE,aAAa;uBACzC,OAAO,mBAAmB,EAAE,QAAQ;kCACpC,OAAO,qBAAqB,EAAE,UAAU;gCACxC,OAAO,qBAAqB,EAAE,iBAAiB;mCAC/C,OAAO,qBAAqB,EAAE,oBAAoB;6BAIlD,GAAG;;2BAKY,OAAO,MAAM,EAAE,cAAc,CAAC;;sBAEnC,OAAO,MAAM,EAAE,MAAM,CAAC;;;;eAI7B,OAAO;cACR,OAAO;;gCAEU,MAAM,WAAW,MAAM,cAAc,OAAO,MAAM,CAAC,iBAAiB,aAAa,KAAK,IAAI;;4BAK7G;IACZ,OAAW,EAAE,MAAM,CAAA;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":"AAgXA;;;GAGG;AACH,iDAHW,eAAe,GACb,MAAM,EAAE,CAsBpB;AA7XD;;;;;;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,CA4J7B;IAED;;;;;OAKG;IACH,4BAsCC;IAED;;;;;OAKG;IACH,yBA8BC;IAED;;;;;OAKG;IACH,qBAoBC;IAED;;;;;OAKG;IACH,4BAeC;CACJ;0BAlWY,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"}
|