@helios-lang/contract-utils 0.2.25 → 0.2.28

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@helios-lang/contract-utils",
3
- "version": "0.2.25",
3
+ "version": "0.2.28",
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",
@@ -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 result = this.uplc.eval(
95
- args.map((a) => new UplcDataValue(a))
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
+ }
@@ -263,15 +263,12 @@ class ContractContextCache {
263
263
  */
264
264
  let datum = None
265
265
 
266
- if (hash instanceof ValidatorHash) {
267
- datum =
268
- hash.context.datum instanceof Cast
269
- ? hash.context.datum
270
- : None
271
-
272
- if (!datum) {
273
- throw new Error("Datum is not a Cast type")
274
- }
266
+ if (hash.context.datum && hash.context.datum instanceof Cast) {
267
+ datum = hash.context.datum
268
+ }
269
+
270
+ if (["spending", "mixed"].includes(purpose) && !datum) {
271
+ throw new Error("Datum is not a Cast type")
275
272
  }
276
273
 
277
274
  resValidators[name] = {
@@ -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)
@@ -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":"AASA;;;;;;;;;;;;GAYG;AAEH;;GAEG;AACH;IAeI;;;OAGG;IACH,kBAHW,WAAW,SACX,aAAa,EAKvB;IArBD;;;;OAIG;IACH,sBAAI;IAEJ;;;;OAIG;IACH,uBAAK;IAWL;;OAEG;IACH,oBAuDC;CACJ;yBA5GY,OAAO,yBAAyB,EAAE,UAAU;uBAC5C,OAAO,mBAAmB,EAAE,QAAQ;0BACpC,OAAO,mBAAmB,EAAE,WAAW;4BAOvC;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
+ {"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":"ContractContextCache.d.ts","sourceRoot":"","sources":["../../src/context/ContractContextCache.js"],"names":[],"mappings":"AA2TA,wDAA8D;4BA9SjD,OAAO,mBAAmB,EAAE,aAAa;0BACzC,OAAO,mBAAmB,EAAE,WAAW;yBACvC,OAAO,kBAAkB,EAAE,UAAU;yBACrC,OAAO,qBAAqB,EAAE,UAAU;0CACxC,OAAO,sBAAsB,EAAE,2BAA2B;;;;;;;;;;;iBAYvD,SAAS,GAAG,UAAU,GAAG,SAAS,GAAG,OAAO;eAC9C,MAAM,EAAE;;0BAEG,MAAM;uBACT,aAAa;oBAChB,UAAU;;kBAEZ,UAAU;;;;;;0BAOJ,MAAM;uBACT,aAAa;;;6BAKpB;IACZ,UAAc,EAAE,wBAAwB,CAAA;IACxC,SAAa,EAAE,uBAAuB,CAAA;CACnC;AAxCJ;;;;;;GAMG;AAEH;;;;;GAKG;AAEH;;;;;;;;;;;GAWG;AAEH;;;;;;GAMG;AAEH;;;;;GAKG;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,QA8G1B;IAED;;OAEG;IACH,aAFW,UAAU,QAMpB;IAED;;OAEG;IACH,SAFa,OAAO,UAAU,CAAC,CAY9B;IAED;;OAEG;IACH,UAFY,cAAc,EAAE,CA4F3B;CACJ"}
1
+ {"version":3,"file":"ContractContextCache.d.ts","sourceRoot":"","sources":["../../src/context/ContractContextCache.js"],"names":[],"mappings":"AAwTA,wDAA8D;4BA3SjD,OAAO,mBAAmB,EAAE,aAAa;0BACzC,OAAO,mBAAmB,EAAE,WAAW;yBACvC,OAAO,kBAAkB,EAAE,UAAU;yBACrC,OAAO,qBAAqB,EAAE,UAAU;0CACxC,OAAO,sBAAsB,EAAE,2BAA2B;;;;;;;;;;;iBAYvD,SAAS,GAAG,UAAU,GAAG,SAAS,GAAG,OAAO;eAC9C,MAAM,EAAE;;0BAEG,MAAM;uBACT,aAAa;oBAChB,UAAU;;kBAEZ,UAAU;;;;;;0BAOJ,MAAM;uBACT,aAAa;;;6BAKpB;IACZ,UAAc,EAAE,wBAAwB,CAAA;IACxC,SAAa,EAAE,uBAAuB,CAAA;CACnC;AAxCJ;;;;;;GAMG;AAEH;;;;;GAKG;AAEH;;;;;;;;;;;GAWG;AAEH;;;;;;GAMG;AAEH;;;;;GAKG;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,QA8G1B;IAED;;OAEG;IACH,aAFW,UAAU,QAMpB;IAED;;OAEG;IACH,SAFa,OAAO,UAAU,CAAC,CAY9B;IAED;;OAEG;IACH,UAFY,cAAc,EAAE,CAyF3B;CACJ"}
@@ -1 +1 @@
1
- {"version":3,"file":"DagCompiler.d.ts","sourceRoot":"","sources":["../../src/context/DagCompiler.js"],"names":[],"mappings":"AAgVA;;;GAGG;AACH,iDAHW,eAAe,GACb,MAAM,EAAE,CAsBpB;AA7VD;;;;;;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,CAgI7B;IAED;;;;;OAKG;IACH,4BAsCC;IAED;;;;;OAKG;IACH,yBA0BC;IAED;;;;;OAKG;IACH,qBAoBC;IAED;;;;;OAKG;IACH,4BAeC;CACJ;0BAlUY,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"}
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"}