@helios-lang/contract-utils 0.2.25 → 0.2.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/package.json
CHANGED
package/src/cast/UserFunc.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { expectSome, isLeft } from "@helios-lang/type-utils"
|
|
2
|
+
import { ConstrData, UplcDataValue, UplcProgramV2 } from "@helios-lang/uplc"
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* @typedef {import("@helios-lang/type-utils").TypeSchema} TypeSchema
|
|
3
6
|
* @typedef {import("@helios-lang/uplc").UplcData} UplcData
|
|
4
7
|
* @typedef {import("@helios-lang/uplc").UplcProgram} UplcProgram
|
|
8
|
+
* @typedef {import("@helios-lang/uplc").UplcValue} UplcValue
|
|
5
9
|
*/
|
|
6
10
|
|
|
7
|
-
import { expectSome, isLeft } from "@helios-lang/type-utils"
|
|
8
|
-
import { ConstrData, UplcDataValue } from "@helios-lang/uplc"
|
|
9
|
-
|
|
10
11
|
/**
|
|
11
12
|
* @typedef {{
|
|
12
13
|
* requiresScriptContext: boolean
|
|
@@ -91,9 +92,24 @@ export class UserFunc {
|
|
|
91
92
|
args.push(new ConstrData(index, []))
|
|
92
93
|
}
|
|
93
94
|
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
).result
|
|
95
|
+
const argValues = args.map((a) => new UplcDataValue(a))
|
|
96
|
+
|
|
97
|
+
const result = this.uplc.eval(argValues).result
|
|
98
|
+
|
|
99
|
+
if (
|
|
100
|
+
"alt" in this.uplc &&
|
|
101
|
+
this.uplc.alt instanceof UplcProgramV2
|
|
102
|
+
) {
|
|
103
|
+
const resultUnoptim = this.uplc.alt.eval(argValues).result
|
|
104
|
+
const resultUnoptimStr = evalResultToString(resultUnoptim)
|
|
105
|
+
const resultStr = evalResultToString(result)
|
|
106
|
+
|
|
107
|
+
if (resultStr != resultUnoptimStr) {
|
|
108
|
+
throw new Error(
|
|
109
|
+
`Critical error: contact Helios maintainers, expected ${resultUnoptimStr}, got ${resultStr}`
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
97
113
|
|
|
98
114
|
if (isLeft(result)) {
|
|
99
115
|
throw new Error(result.left.error)
|
|
@@ -108,3 +124,22 @@ export class UserFunc {
|
|
|
108
124
|
)
|
|
109
125
|
}
|
|
110
126
|
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* @param {Either<{error: string}, string | UplcValue>} result
|
|
130
|
+
* @returns {string}
|
|
131
|
+
*/
|
|
132
|
+
function evalResultToString(result) {
|
|
133
|
+
if (isLeft(result)) {
|
|
134
|
+
console.error(result.left.error)
|
|
135
|
+
return "error"
|
|
136
|
+
} else {
|
|
137
|
+
if (typeof result.right == "string") {
|
|
138
|
+
return result.right
|
|
139
|
+
} else if (result.right instanceof UplcDataValue) {
|
|
140
|
+
return result.right.value.toString()
|
|
141
|
+
} else {
|
|
142
|
+
return result.right.toString()
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
}
|
|
@@ -118,6 +118,7 @@ export class DagCompiler {
|
|
|
118
118
|
isTestnet: isTestnet,
|
|
119
119
|
excludeUserFuncs: excludeUserFuncs,
|
|
120
120
|
onCompileUserFunc: (name, cborHex, plutusVersion) => {
|
|
121
|
+
console.log(`Compiled user function ${name}`)
|
|
121
122
|
this.cachedUserFuncs[name] =
|
|
122
123
|
plutusVersion == "PlutusScriptV1"
|
|
123
124
|
? UplcProgramV1.fromCbor(cborHex)
|
package/types/cast/UserFunc.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef {import("@helios-lang/type-utils").TypeSchema} TypeSchema
|
|
3
|
+
* @typedef {import("@helios-lang/uplc").UplcData} UplcData
|
|
4
|
+
* @typedef {import("@helios-lang/uplc").UplcProgram} UplcProgram
|
|
5
|
+
* @typedef {import("@helios-lang/uplc").UplcValue} UplcValue
|
|
6
|
+
*/
|
|
1
7
|
/**
|
|
2
8
|
* @typedef {{
|
|
3
9
|
* requiresScriptContext: boolean
|
|
@@ -40,6 +46,7 @@ export class UserFunc<T> {
|
|
|
40
46
|
export type TypeSchema = import("@helios-lang/type-utils").TypeSchema;
|
|
41
47
|
export type UplcData = import("@helios-lang/uplc").UplcData;
|
|
42
48
|
export type UplcProgram = import("@helios-lang/uplc").UplcProgram;
|
|
49
|
+
export type UplcValue = import("@helios-lang/uplc").UplcValue;
|
|
43
50
|
export type UserFuncProps = {
|
|
44
51
|
requiresScriptContext: boolean;
|
|
45
52
|
requiresCurrentScript: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserFunc.d.ts","sourceRoot":"","sources":["../../src/cast/UserFunc.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"UserFunc.d.ts","sourceRoot":"","sources":["../../src/cast/UserFunc.js"],"names":[],"mappings":"AAGA;;;;;GAKG;AAEH;;;;;;;;;;;;GAYG;AAEH;;GAEG;AACH;IAeI;;;OAGG;IACH,kBAHW,WAAW,SACX,aAAa,EAKvB;IArBD;;;;OAIG;IACH,sBAAI;IAEJ;;;;OAIG;IACH,uBAAK;IAWL;;OAEG;IACH,oBAsEC;CACJ;yBAzHY,OAAO,yBAAyB,EAAE,UAAU;uBAC5C,OAAO,mBAAmB,EAAE,QAAQ;0BACpC,OAAO,mBAAmB,EAAE,WAAW;wBACvC,OAAO,mBAAmB,EAAE,SAAS;4BAIrC;IACZ,qBAAyB,EAAE,OAAO,CAAA;IAClC,qBAAyB,EAAE,OAAO,CAAA;IAClC,SAAa,EAAE;QACf,MAAY,MAAM,CAAA;QAClB,IAAU,EAAE,UAAU,CAAA;QACtB,UAAgB,EAAE,OAAO,CAAA;KACpB,EAAE,CAAA;IACP,OAAW,EAAE,UAAU,CAAA;IACvB,gBAAoB,CAAC,EAAE,OAAO,MAAM,EAAE,MAAM,CAAC,CAAA;CAC1C"}
|
|
@@ -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":"AAiVA;;;GAGG;AACH,iDAHW,eAAe,GACb,MAAM,EAAE,CAsBpB;AA9VD;;;;;;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,iDAA4B;IAKhC;;;;;;OAMG;IACH,kBANW,eAAe,EAAE,cACjB,OAAO,MAAM,EAAE,GAAG,CAAC,aACnB,OAAO;;SAEL,iBAAiB,CAiI7B;IAED;;;;;OAKG;IACH,4BAsCC;IAED;;;;;OAKG;IACH,yBA0BC;IAED;;;;;OAKG;IACH,qBAoBC;IAED;;;;;OAKG;IACH,4BAeC;CACJ;0BAnUY,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"}
|