@helios-lang/contract-utils 0.2.37 → 0.2.39
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.
|
|
3
|
+
"version": "0.2.39",
|
|
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",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"prettify": "npx prettier . --write",
|
|
16
16
|
"test": "npm run test:pretty && npm run test:types && npm run test:suite",
|
|
17
17
|
"test:pretty": "npx prettier . --check",
|
|
18
|
-
"test:suite": "node --test
|
|
18
|
+
"test:suite": "node --test",
|
|
19
19
|
"test:types": "npm run build:types"
|
|
20
20
|
},
|
|
21
21
|
"author": "Christian Schmitz",
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@helios-lang/cli-utils": "^0.1.6",
|
|
39
|
-
"@helios-lang/codec-utils": "^0.1.
|
|
39
|
+
"@helios-lang/codec-utils": "^0.1.33",
|
|
40
40
|
"@helios-lang/compiler-utils": "^0.1.25",
|
|
41
|
-
"@helios-lang/ledger": "^0.
|
|
41
|
+
"@helios-lang/ledger": "^0.4.4",
|
|
42
42
|
"@helios-lang/type-utils": "^0.1.21",
|
|
43
|
-
"@helios-lang/uplc": "^0.
|
|
43
|
+
"@helios-lang/uplc": "^0.3.0"
|
|
44
44
|
}
|
|
45
45
|
}
|
package/src/cast/UserFunc.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { expectSome, isLeft } from "@helios-lang/type-utils"
|
|
1
|
+
import { expectSome, isLeft, isString } from "@helios-lang/type-utils"
|
|
2
2
|
import { ConstrData, UplcDataValue, UplcProgramV2 } from "@helios-lang/uplc"
|
|
3
3
|
import { Cast } from "./Cast.js"
|
|
4
4
|
|
|
@@ -108,7 +108,7 @@ export class UserFunc {
|
|
|
108
108
|
|
|
109
109
|
if (isLeft(result)) {
|
|
110
110
|
throw new Error(result.left.error)
|
|
111
|
-
} else if (result.right
|
|
111
|
+
} else if (!isString(result.right) && result.right.kind == "data") {
|
|
112
112
|
return result.right.value
|
|
113
113
|
} else {
|
|
114
114
|
throw new Error(`${result.right.toString()} isn't a UplcDataValue`)
|
|
@@ -155,7 +155,7 @@ export class UserFunc {
|
|
|
155
155
|
|
|
156
156
|
const cekResult = this.uplc.eval(argValues)
|
|
157
157
|
|
|
158
|
-
if (
|
|
158
|
+
if (this.uplc.alt?.plutusVersion == "PlutusScriptV2") {
|
|
159
159
|
const cekResultUnoptim = this.uplc.alt.eval(argValues)
|
|
160
160
|
const resultUnoptim = cekResultUnoptim.result
|
|
161
161
|
const resultUnoptimStr = evalResultToString(resultUnoptim)
|
|
@@ -203,9 +203,9 @@ function evalResultToString(result) {
|
|
|
203
203
|
console.error(result.left.error)
|
|
204
204
|
return "error"
|
|
205
205
|
} else {
|
|
206
|
-
if (
|
|
206
|
+
if (isString(result.right)) {
|
|
207
207
|
return result.right
|
|
208
|
-
} else if (result.right
|
|
208
|
+
} else if (result.right.kind == "data") {
|
|
209
209
|
return result.right.value.toString()
|
|
210
210
|
} else {
|
|
211
211
|
return result.right.toString()
|
|
@@ -96,17 +96,20 @@ class ContractContextCache {
|
|
|
96
96
|
for (let name in entry.validators) {
|
|
97
97
|
const props = entry.validators[name]
|
|
98
98
|
|
|
99
|
+
/**
|
|
100
|
+
* @type {UplcProgram}
|
|
101
|
+
*/
|
|
99
102
|
let program =
|
|
100
103
|
props.plutusVersion == "PlutusScriptV1"
|
|
101
104
|
? UplcProgramV1.fromCbor(props.optimizedCborHex)
|
|
102
105
|
: UplcProgramV2.fromCbor(props.optimizedCborHex)
|
|
103
106
|
|
|
104
107
|
if (props.unoptimizedCborHex) {
|
|
105
|
-
if (program
|
|
108
|
+
if (program.plutusVersion == "PlutusScriptV1") {
|
|
106
109
|
program = program.withAlt(
|
|
107
110
|
UplcProgramV1.fromCbor(props.unoptimizedCborHex)
|
|
108
111
|
)
|
|
109
|
-
} else if (program
|
|
112
|
+
} else if (program.plutusVersion == "PlutusScriptV2") {
|
|
110
113
|
program = program.withAlt(
|
|
111
114
|
UplcProgramV2.fromCbor(props.unoptimizedCborHex)
|
|
112
115
|
)
|
|
@@ -168,17 +171,20 @@ class ContractContextCache {
|
|
|
168
171
|
for (let name in entry.userFuncs) {
|
|
169
172
|
const props = entry.userFuncs[name]
|
|
170
173
|
|
|
174
|
+
/**
|
|
175
|
+
* @type {UplcProgram}
|
|
176
|
+
*/
|
|
171
177
|
let program =
|
|
172
178
|
props.plutusVersion == "PlutusScriptV1"
|
|
173
179
|
? UplcProgramV1.fromCbor(props.optimizedCborHex)
|
|
174
180
|
: UplcProgramV2.fromCbor(props.optimizedCborHex)
|
|
175
181
|
|
|
176
182
|
if (props.unoptimizedCborHex) {
|
|
177
|
-
if (program
|
|
183
|
+
if (program.plutusVersion == "PlutusScriptV1") {
|
|
178
184
|
program = program.withAlt(
|
|
179
185
|
UplcProgramV1.fromCbor(props.unoptimizedCborHex)
|
|
180
186
|
)
|
|
181
|
-
} else if (program
|
|
187
|
+
} else if (program.plutusVersion == "PlutusScriptV2") {
|
|
182
188
|
program = program.withAlt(
|
|
183
189
|
UplcProgramV2.fromCbor(props.unoptimizedCborHex)
|
|
184
190
|
)
|
|
@@ -186,7 +192,6 @@ class ContractContextCache {
|
|
|
186
192
|
throw new Error("unhandled Plutus version")
|
|
187
193
|
}
|
|
188
194
|
}
|
|
189
|
-
|
|
190
195
|
res.userFuncs[name] = program
|
|
191
196
|
}
|
|
192
197
|
|
|
@@ -163,7 +163,9 @@ export class DagCompiler {
|
|
|
163
163
|
isTestnet: isTestnet,
|
|
164
164
|
excludeUserFuncs: excludeUserFuncs,
|
|
165
165
|
onCompileUserFunc: (name, cborHex, plutusVersion) => {
|
|
166
|
-
const prev =
|
|
166
|
+
const prev = /** @type {any} */ (
|
|
167
|
+
expectSome(this.cachedUserFuncs[name])
|
|
168
|
+
)
|
|
167
169
|
|
|
168
170
|
this.cachedUserFuncs[name] = prev.withAlt(
|
|
169
171
|
restoreUplcProgram(plutusVersion, cborHex)
|
|
@@ -178,7 +180,9 @@ export class DagCompiler {
|
|
|
178
180
|
unoptimizedCborHex
|
|
179
181
|
)
|
|
180
182
|
|
|
181
|
-
const completeProgram = optimizedProgram.withAlt(
|
|
183
|
+
const completeProgram = optimizedProgram.withAlt(
|
|
184
|
+
/** @type {any} */ (unoptimizedProgram)
|
|
185
|
+
)
|
|
182
186
|
|
|
183
187
|
// add result to cache (unoptimizedProgram is attached to optimizedProgram)
|
|
184
188
|
this.addValidatorToCache(validator, completeProgram, ownHash)
|
|
@@ -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":"AA8TA,wDAA8D;4BAjTjD,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,QAoH1B;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":"
|
|
1
|
+
{"version":3,"file":"DagCompiler.d.ts","sourceRoot":"","sources":["../../src/context/DagCompiler.js"],"names":[],"mappings":"AA0UA;;;GAGG;AACH,iDAHW,eAAe,GACb,MAAM,EAAE,CAsBpB;AAvVD;;;;;;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,CA0H7B;IAED;;;;;OAKG;IACH,4BAsCC;IAED;;;;;OAKG;IACH,yBA0BC;IAED;;;;;OAKG;IACH,qBAoBC;IAED;;;;;OAKG;IACH,4BAeC;CACJ;0BA5TY,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"}
|