@helios-lang/contract-utils 0.2.50 → 0.2.52
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/context/ContractContextBuilder.js +14 -9
- package/src/context/ContractContextCache.js +4 -0
- package/src/context/DagCompiler.js +15 -7
- package/types/context/ContractContextBuilder.d.ts +2 -0
- package/types/context/ContractContextBuilder.d.ts.map +1 -1
- package/types/context/ContractContextCache.d.ts +4 -0
- package/types/context/ContractContextCache.d.ts.map +1 -1
- package/types/context/DagCompiler.d.ts +13 -4
- package/types/context/DagCompiler.d.ts.map +1 -1
package/package.json
CHANGED
|
@@ -28,6 +28,7 @@ import { contractContextCache } from "./ContractContextCache.js"
|
|
|
28
28
|
* expectedHashes?: {[name: string]: string}
|
|
29
29
|
* parameters?: Record<string, any>
|
|
30
30
|
* dumpHashes?: boolean
|
|
31
|
+
* debug?: boolean
|
|
31
32
|
* }} ContractContextBuildProps
|
|
32
33
|
*/
|
|
33
34
|
|
|
@@ -115,18 +116,22 @@ export class ContractContextBuilder {
|
|
|
115
116
|
const castConfig = { isMainnet: props.isMainnet }
|
|
116
117
|
const lib = loadCompilerLib()
|
|
117
118
|
|
|
118
|
-
const dagCompiler = new DagCompiler(lib,
|
|
119
|
+
const dagCompiler = new DagCompiler(lib, {
|
|
120
|
+
debug: props.debug ?? false,
|
|
121
|
+
...castConfig
|
|
122
|
+
})
|
|
119
123
|
|
|
120
124
|
const cached = contractContextCache.shift()
|
|
121
125
|
|
|
122
|
-
const compiled =
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
126
|
+
const compiled =
|
|
127
|
+
cached && cached.debug === props.debug
|
|
128
|
+
? cached
|
|
129
|
+
: dagCompiler.build(
|
|
130
|
+
Object.values(this.validators),
|
|
131
|
+
props.parameters ?? {},
|
|
132
|
+
!props.isMainnet,
|
|
133
|
+
props.expectedHashes
|
|
134
|
+
)
|
|
130
135
|
|
|
131
136
|
// TODO: adapt to use generic cache interface
|
|
132
137
|
contractContextCache.push(compiled)
|
|
@@ -20,6 +20,7 @@ import { UplcProgramV2 } from "@helios-lang/uplc"
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* @typedef {{
|
|
23
|
+
* debug?: boolean
|
|
23
24
|
* validators: {[name: string]: AnyContractValidatorContext}
|
|
24
25
|
* userFuncs: {[name: string]: UplcProgram}
|
|
25
26
|
* }} CacheEntry
|
|
@@ -50,6 +51,7 @@ import { UplcProgramV2 } from "@helios-lang/uplc"
|
|
|
50
51
|
|
|
51
52
|
/**
|
|
52
53
|
* @typedef {{
|
|
54
|
+
* debug?: boolean
|
|
53
55
|
* validators: CacheEntryValidatorsJson
|
|
54
56
|
* userFuncs: CacheEntryUserFuncsJson
|
|
55
57
|
* }} CacheEntryJson
|
|
@@ -91,6 +93,7 @@ class ContractContextCache {
|
|
|
91
93
|
* @type {CacheEntry}
|
|
92
94
|
*/
|
|
93
95
|
const res = {
|
|
96
|
+
debug: entry.debug ?? false,
|
|
94
97
|
validators: {},
|
|
95
98
|
userFuncs: {}
|
|
96
99
|
}
|
|
@@ -336,6 +339,7 @@ class ContractContextCache {
|
|
|
336
339
|
}
|
|
337
340
|
|
|
338
341
|
return {
|
|
342
|
+
debug: entry.debug ?? false,
|
|
339
343
|
validators: resValidators,
|
|
340
344
|
userFuncs: resUserFuncs
|
|
341
345
|
}
|
|
@@ -17,8 +17,14 @@ import { configureCast } from "../cast/index.js"
|
|
|
17
17
|
* @typedef {import("./ContractContext.js").AnyContractValidatorContext} AnyContractValidatorContext
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* @typedef {CastConfig & {
|
|
22
|
+
* debug?: boolean
|
|
23
|
+
* }} DagCompilerConfig
|
|
24
|
+
*/
|
|
20
25
|
/**
|
|
21
26
|
* @typedef {{
|
|
27
|
+
* debug?: boolean
|
|
22
28
|
* validators: {[name: string]: AnyContractValidatorContext}
|
|
23
29
|
* userFuncs: {[name: string]: UplcProgram}
|
|
24
30
|
* }} DagCompilerOutput
|
|
@@ -38,7 +44,7 @@ export class DagCompiler {
|
|
|
38
44
|
/**
|
|
39
45
|
* @private
|
|
40
46
|
* @readonly
|
|
41
|
-
* @type {
|
|
47
|
+
* @type {DagCompilerConfig}
|
|
42
48
|
*/
|
|
43
49
|
config
|
|
44
50
|
|
|
@@ -58,11 +64,11 @@ export class DagCompiler {
|
|
|
58
64
|
|
|
59
65
|
/**
|
|
60
66
|
* @param {CompilerLib} lib
|
|
61
|
-
* @param {
|
|
67
|
+
* @param {DagCompilerConfig} config
|
|
62
68
|
*/
|
|
63
|
-
constructor(lib,
|
|
69
|
+
constructor(lib, config) {
|
|
64
70
|
this.lib = lib
|
|
65
|
-
this.
|
|
71
|
+
this.config = config
|
|
66
72
|
this.cachedValidators = {}
|
|
67
73
|
this.cachedUserFuncs = {}
|
|
68
74
|
}
|
|
@@ -168,6 +174,7 @@ export class DagCompiler {
|
|
|
168
174
|
Array.from(moduleDeps.values()),
|
|
169
175
|
{
|
|
170
176
|
optimize: false,
|
|
177
|
+
debug: this.config.debug,
|
|
171
178
|
hashDependencies: hashDepHashes,
|
|
172
179
|
allValidatorHashTypes: hashTypes,
|
|
173
180
|
allValidatorIndices: validatorIndices ?? undefined,
|
|
@@ -237,6 +244,7 @@ export class DagCompiler {
|
|
|
237
244
|
validators.forEach((v) => buildValidatorAltAndUserFuncs(v))
|
|
238
245
|
|
|
239
246
|
return {
|
|
247
|
+
debug: this.config.debug ?? false,
|
|
240
248
|
validators: this.cachedValidators,
|
|
241
249
|
userFuncs: this.cachedUserFuncs
|
|
242
250
|
}
|
|
@@ -250,21 +258,21 @@ export class DagCompiler {
|
|
|
250
258
|
*/
|
|
251
259
|
addValidatorToCache(validator, program, hash) {
|
|
252
260
|
const name = validator.$name
|
|
253
|
-
const redeemer = configureCast(validator.$Redeemer, this.
|
|
261
|
+
const redeemer = configureCast(validator.$Redeemer, this.config)
|
|
254
262
|
|
|
255
263
|
switch (validator.$purpose) {
|
|
256
264
|
case "spending":
|
|
257
265
|
this.cachedValidators[name] = new ValidatorHash(hash, {
|
|
258
266
|
program,
|
|
259
267
|
redeemer,
|
|
260
|
-
datum: configureCast(validator.$Datum, this.
|
|
268
|
+
datum: configureCast(validator.$Datum, this.config)
|
|
261
269
|
})
|
|
262
270
|
break
|
|
263
271
|
case "mixed":
|
|
264
272
|
this.cachedValidators[name] = new ScriptHash(hash, {
|
|
265
273
|
program,
|
|
266
274
|
redeemer,
|
|
267
|
-
datum: configureCast(validator.$Datum, this.
|
|
275
|
+
datum: configureCast(validator.$Datum, this.config)
|
|
268
276
|
})
|
|
269
277
|
break
|
|
270
278
|
case "minting":
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
* expectedHashes?: {[name: string]: string}
|
|
20
20
|
* parameters?: Record<string, any>
|
|
21
21
|
* dumpHashes?: boolean
|
|
22
|
+
* debug?: boolean
|
|
22
23
|
* }} ContractContextBuildProps
|
|
23
24
|
*/
|
|
24
25
|
/**
|
|
@@ -92,5 +93,6 @@ export type ContractContextBuildProps = {
|
|
|
92
93
|
};
|
|
93
94
|
parameters?: Record<string, any>;
|
|
94
95
|
dumpHashes?: boolean;
|
|
96
|
+
debug?: boolean;
|
|
95
97
|
};
|
|
96
98
|
//# sourceMappingURL=ContractContextBuilder.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContractContextBuilder.d.ts","sourceRoot":"","sources":["../../src/context/ContractContextBuilder.js"],"names":[],"mappings":"AAMA;;;;;GAKG;AAEH;;;GAGG;AAEH;;;;GAIG;AAEH
|
|
1
|
+
{"version":3,"file":"ContractContextBuilder.d.ts","sourceRoot":"","sources":["../../src/context/ContractContextBuilder.js"],"names":[],"mappings":"AAMA;;;;;GAKG;AAEH;;;GAGG;AAEH;;;;GAIG;AAEH;;;;;;;;GAQG;AAEH;;;GAGG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wCAItD;IACZ,SAAa,EAAE,OAAO,CAAA;IACtB,cAAkB,CAAC,EAAE;QAAC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;KAAC,CAAA;IAC7C,UAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACpC,UAAc,CAAC,EAAE,OAAO,CAAA;IACxB,KAAS,CAAC,EAAE,OAAO,CAAA;CAChB"}
|
|
@@ -5,6 +5,7 @@ export type CastConfig = import("../cast/index.js").CastConfig;
|
|
|
5
5
|
export type TypeSchema = import("../codegen/index.js").TypeSchema;
|
|
6
6
|
export type AnyContractValidatorContext = import("./ContractContext.js").AnyContractValidatorContext;
|
|
7
7
|
export type CacheEntry = {
|
|
8
|
+
debug?: boolean;
|
|
8
9
|
validators: {
|
|
9
10
|
[name: string]: AnyContractValidatorContext;
|
|
10
11
|
};
|
|
@@ -34,6 +35,7 @@ export type CacheEntryUserFuncsJson = {
|
|
|
34
35
|
};
|
|
35
36
|
};
|
|
36
37
|
export type CacheEntryJson = {
|
|
38
|
+
debug?: boolean;
|
|
37
39
|
validators: CacheEntryValidatorsJson;
|
|
38
40
|
userFuncs: CacheEntryUserFuncsJson;
|
|
39
41
|
};
|
|
@@ -46,6 +48,7 @@ export type CacheEntryJson = {
|
|
|
46
48
|
*/
|
|
47
49
|
/**
|
|
48
50
|
* @typedef {{
|
|
51
|
+
* debug?: boolean
|
|
49
52
|
* validators: {[name: string]: AnyContractValidatorContext}
|
|
50
53
|
* userFuncs: {[name: string]: UplcProgram}
|
|
51
54
|
* }} CacheEntry
|
|
@@ -73,6 +76,7 @@ export type CacheEntryJson = {
|
|
|
73
76
|
*/
|
|
74
77
|
/**
|
|
75
78
|
* @typedef {{
|
|
79
|
+
* debug?: boolean
|
|
76
80
|
* validators: CacheEntryValidatorsJson
|
|
77
81
|
* userFuncs: CacheEntryUserFuncsJson
|
|
78
82
|
* }} CacheEntryJson
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContractContextCache.d.ts","sourceRoot":"","sources":["../../src/context/ContractContextCache.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ContractContextCache.d.ts","sourceRoot":"","sources":["../../src/context/ContractContextCache.js"],"names":[],"mappings":"AA6VA,wDAA8D;4BAhVjD,OAAO,mBAAmB,EAAE,aAAa;0BACzC,OAAO,mBAAmB,EAAE,WAAW;yBACvC,OAAO,kBAAkB,EAAE,UAAU;yBACrC,OAAO,qBAAqB,EAAE,UAAU;0CACxC,OAAO,sBAAsB,EAAE,2BAA2B;yBAI1D;IACZ,KAAS,CAAC,EAAE,OAAO,CAAA;IACnB,UAAc,EAAE;QAAC,CAAC,IAAI,EAAE,MAAM,GAAG,2BAA2B,CAAA;KAAC,CAAA;IAC7D,SAAa,EAAE;QAAC,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAAA;KAAC,CAAA;CACzC;uCAIS;IAAC,CAAC,IAAI,EAAE,MAAM,GAAG;QAC7B,OAAa,EAAE,SAAS,GAAG,UAAU,GAAG,SAAS,GAAG,OAAO,CAAA;QAC3D,KAAW,EAAE,MAAM,EAAE,CAAA;QACrB,kBAAwB,CAAC,EAAE,MAAM,CAAA;QACjC,gBAAsB,EAAE,MAAM,CAAA;QAC9B,aAAmB,EAAE,aAAa,CAAA;QAClC,UAAgB,EAAE,UAAU,CAAA;QAC5B,KAAW,CAAC,EAAE,UAAU,CAAA;QACxB,QAAc,EAAE,UAAU,CAAA;KACrB,CAAA;CAAC;sCAIM;IAAC,CAAC,IAAI,EAAE,MAAM,GAAG;QAC7B,kBAAsB,CAAC,EAAE,MAAM,CAAA;QAC/B,aAAiB,CAAC,EAAE,MAAM,CAAA;QAC1B,gBAAoB,EAAE,MAAM,CAAA;QAC5B,WAAe,CAAC,EAAE,MAAM,CAAA;QACxB,aAAiB,EAAE,aAAa,CAAA;KAC7B,CAAA;CAAC;6BAIQ;IACZ,KAAS,CAAC,EAAE,OAAO,CAAA;IACnB,UAAc,EAAE,wBAAwB,CAAA;IACxC,SAAa,EAAE,uBAAuB,CAAA;CACnC;AA5CJ;;;;;;GAMG;AAEH;;;;;;GAMG;AAEH;;;;;;;;;;;GAWG;AAEH;;;;;;;;GAQG;AAEH;;;;;;GAMG;AAEH;IACI;;OAEG;IACH,OAFU,UAAU,EAAE,CAEjB;IAEL;;;OAGG;IACH,GAFU,MAAM,CAEf;IAED;;OAEG;IACH,SAFU,OAAO,CAEV;IAQP,eAEC;IAED;;OAEG;IACH,WAFW,cAAc,EAAE,QA2I1B;IAED;;OAEG;IACH,aAFW,UAAU,QAMpB;IAED;;OAEG;IACH,SAFa,MAAM,CAAC,UAAU,CAAC,CAY9B;IAED;;OAEG;IACH,UAFY,cAAc,EAAE,CA6F3B;CACJ"}
|
|
@@ -10,8 +10,14 @@ export function getModuleDependencies(validator: LoadedValidator): string[];
|
|
|
10
10
|
* @typedef {import("../compiler/index.js").CompilerLib} CompilerLib
|
|
11
11
|
* @typedef {import("./ContractContext.js").AnyContractValidatorContext} AnyContractValidatorContext
|
|
12
12
|
*/
|
|
13
|
+
/**
|
|
14
|
+
* @typedef {CastConfig & {
|
|
15
|
+
* debug?: boolean
|
|
16
|
+
* }} DagCompilerConfig
|
|
17
|
+
*/
|
|
13
18
|
/**
|
|
14
19
|
* @typedef {{
|
|
20
|
+
* debug?: boolean
|
|
15
21
|
* validators: {[name: string]: AnyContractValidatorContext}
|
|
16
22
|
* userFuncs: {[name: string]: UplcProgram}
|
|
17
23
|
* }} DagCompilerOutput
|
|
@@ -22,9 +28,9 @@ export function getModuleDependencies(validator: LoadedValidator): string[];
|
|
|
22
28
|
export class DagCompiler {
|
|
23
29
|
/**
|
|
24
30
|
* @param {CompilerLib} lib
|
|
25
|
-
* @param {
|
|
31
|
+
* @param {DagCompilerConfig} config
|
|
26
32
|
*/
|
|
27
|
-
constructor(lib: CompilerLib,
|
|
33
|
+
constructor(lib: CompilerLib, config: DagCompilerConfig);
|
|
28
34
|
/**
|
|
29
35
|
* @private
|
|
30
36
|
* @readonly
|
|
@@ -34,7 +40,7 @@ export class DagCompiler {
|
|
|
34
40
|
/**
|
|
35
41
|
* @private
|
|
36
42
|
* @readonly
|
|
37
|
-
* @type {
|
|
43
|
+
* @type {DagCompilerConfig}
|
|
38
44
|
*/
|
|
39
45
|
private readonly config;
|
|
40
46
|
/**
|
|
@@ -49,7 +55,6 @@ export class DagCompiler {
|
|
|
49
55
|
* @type {{[name: string]: UplcProgram}}
|
|
50
56
|
*/
|
|
51
57
|
private readonly cachedUserFuncs;
|
|
52
|
-
castConfig: import("../cast/Cast.js").CastConfig;
|
|
53
58
|
/**
|
|
54
59
|
* @param {LoadedValidator[]} validators
|
|
55
60
|
* @param {Record<string, any>} parameters
|
|
@@ -94,7 +99,11 @@ export type CastConfig = import("../cast/index.js").CastConfig;
|
|
|
94
99
|
export type LoadedValidator = import("../codegen/LoadedValidator.js").LoadedValidator;
|
|
95
100
|
export type CompilerLib = import("../compiler/index.js").CompilerLib;
|
|
96
101
|
export type AnyContractValidatorContext = import("./ContractContext.js").AnyContractValidatorContext;
|
|
102
|
+
export type DagCompilerConfig = CastConfig & {
|
|
103
|
+
debug?: boolean;
|
|
104
|
+
};
|
|
97
105
|
export type DagCompilerOutput = {
|
|
106
|
+
debug?: boolean;
|
|
98
107
|
validators: {
|
|
99
108
|
[name: string]: AnyContractValidatorContext;
|
|
100
109
|
};
|
|
@@ -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":"AAoYA;;;GAGG;AACH,iDAHW,eAAe,GACb,MAAM,EAAE,CAsBpB;AAjZD;;;;;;GAMG;AAEH;;;;GAIG;AACH;;;;;;GAMG;AAEH;;GAEG;AACH;IA6BI;;;OAGG;IACH,iBAHW,WAAW,UACX,iBAAiB,EAO3B;IArCD;;;;OAIG;IACH,qBAAG;IAEH;;;;OAIG;IACH,wBAAM;IAEN;;;;OAIG;IACH,kCAAgB;IAEhB;;;;OAIG;IACH,iCAAe;IAaf;;;;;;OAMG;IACH,kBANW,eAAe,EAAE,cACjB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,aACnB,OAAO,mBACP,MAAM,CAAC;QAAC,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAA;KAAC,CAAC,GAC9B,iBAAiB,CA0K7B;IAED;;;;;OAKG;IACH,4BAsCC;IAED;;;;;OAKG;IACH,yBA8BC;IAED;;;;;OAKG;IACH,qBAoBC;IAED;;;;;OAKG;IACH,4BAeC;CACJ;0BAtXY,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;gCAI1D,UAAU,GAAG;IACzB,KAAS,CAAC,EAAE,OAAO,CAAA;CAChB;gCAGS;IACZ,KAAS,CAAC,EAAE,OAAO,CAAA;IACnB,UAAc,EAAE;QAAC,CAAC,IAAI,EAAE,MAAM,GAAG,2BAA2B,CAAA;KAAC,CAAA;IAC7D,SAAa,EAAE;QAAC,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAAA;KAAC,CAAA;CACzC"}
|