@helios-lang/contract-utils 0.3.20 → 0.4.0
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.
|
|
3
|
+
"version": "0.4.0",
|
|
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",
|
|
@@ -40,9 +40,9 @@
|
|
|
40
40
|
"@helios-lang/codec-utils": "^0.3.4",
|
|
41
41
|
"@helios-lang/compiler-utils": "^0.5.13",
|
|
42
42
|
"@helios-lang/crypto": "0.2.3",
|
|
43
|
-
"@helios-lang/ledger": "^0.
|
|
43
|
+
"@helios-lang/ledger": "^0.8.0",
|
|
44
44
|
"@helios-lang/type-utils": "^0.2.9",
|
|
45
|
-
"@helios-lang/uplc": "^0.
|
|
45
|
+
"@helios-lang/uplc": "^0.8.0"
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "pnpm run prettify && pnpm run build:types && pnpm run test:suite",
|
package/src/cast/Cast.js
CHANGED
|
@@ -475,15 +475,17 @@ function convertSchemaDataToUplcData(schema, x, context) {
|
|
|
475
475
|
defs[schema.id] = schema
|
|
476
476
|
const variantName = Object.keys(x)[0]
|
|
477
477
|
const variantFields = Object.values(x)[0]
|
|
478
|
-
const
|
|
478
|
+
const foundVariant = schema.variantTypes.find(
|
|
479
479
|
(v) => v.name == variantName
|
|
480
480
|
)
|
|
481
|
-
|
|
482
|
-
if (tag == -1) {
|
|
481
|
+
if (!foundVariant) {
|
|
483
482
|
throw new Error(
|
|
484
|
-
`invalid variant ${variantName} (expected: ${schema.variantTypes
|
|
483
|
+
`invalid enum variant '${variantName}' (expected one of: ${schema.variantTypes
|
|
484
|
+
.map((v) => v.name)
|
|
485
|
+
.join(", ")})`
|
|
485
486
|
)
|
|
486
487
|
}
|
|
488
|
+
const tag = foundVariant.tag
|
|
487
489
|
|
|
488
490
|
return convertEnumVariantDataToConstrData(
|
|
489
491
|
schema,
|
|
@@ -523,7 +525,14 @@ function convertSchemaDataToUplcData(schema, x, context) {
|
|
|
523
525
|
* @returns {ConstrData}
|
|
524
526
|
*/
|
|
525
527
|
function convertEnumVariantDataToConstrData(schema, tag, data, context) {
|
|
526
|
-
const variantSchema = schema.variantTypes
|
|
528
|
+
const variantSchema = schema.variantTypes.find((v) => v.tag == tag)
|
|
529
|
+
if (!variantSchema) {
|
|
530
|
+
throw new Error(
|
|
531
|
+
`invalid enum variant tag ${tag} (expected one of: ${schema.variantTypes
|
|
532
|
+
.map((v) => v.tag)
|
|
533
|
+
.join(", ")})`
|
|
534
|
+
)
|
|
535
|
+
}
|
|
527
536
|
const variantName = variantSchema.name
|
|
528
537
|
|
|
529
538
|
if (
|
|
@@ -867,10 +876,14 @@ function uplcToSchema(schema, data, context) {
|
|
|
867
876
|
function convertConstrDataFieldsToEnumVariantFields(schema, data, context) {
|
|
868
877
|
const { tag, fields } = data
|
|
869
878
|
|
|
870
|
-
const variantSchema = schema.variantTypes
|
|
879
|
+
const variantSchema = schema.variantTypes.find((v) => v.tag == tag)
|
|
871
880
|
|
|
872
881
|
if (!variantSchema) {
|
|
873
|
-
throw new Error(
|
|
882
|
+
throw new Error(
|
|
883
|
+
`invalid enum variant tag ${tag} (expected one of: ${schema.variantTypes
|
|
884
|
+
.map((v) => v.tag)
|
|
885
|
+
.join(", ")})`
|
|
886
|
+
)
|
|
874
887
|
}
|
|
875
888
|
|
|
876
889
|
const nExpected = variantSchema.fieldTypes.length
|
package/src/cast/UserFunc.js
CHANGED
|
@@ -3,7 +3,7 @@ import { expectDefined, isLeft, isString } from "@helios-lang/type-utils"
|
|
|
3
3
|
import {
|
|
4
4
|
makeConstrData,
|
|
5
5
|
makeUplcDataValue,
|
|
6
|
-
|
|
6
|
+
makeUplcRuntimeError
|
|
7
7
|
} from "@helios-lang/uplc"
|
|
8
8
|
import { makeCast } from "./Cast.js"
|
|
9
9
|
|
|
@@ -159,7 +159,7 @@ export function evalUserFuncUnsafe(
|
|
|
159
159
|
const result = profileUserFunc(program, props, namedArgs, logOptions).result
|
|
160
160
|
|
|
161
161
|
if (isLeft(result)) {
|
|
162
|
-
throw
|
|
162
|
+
throw makeUplcRuntimeError(result.left.error, result.left.callSites)
|
|
163
163
|
} else if (!isString(result.right) && result.right.kind == "data") {
|
|
164
164
|
return /** @type {any} */ (result.right.value)
|
|
165
165
|
} else if (props.returns) {
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import { bytesToHex } from "@helios-lang/codec-utils"
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
makeUplcApply,
|
|
4
|
+
makeUplcDelay,
|
|
5
|
+
makeUplcForce,
|
|
6
|
+
makeUplcLambda,
|
|
7
|
+
makeUplcSourceMap
|
|
8
|
+
} from "@helios-lang/uplc"
|
|
3
9
|
|
|
4
10
|
/**
|
|
5
|
-
* @import { UplcData, UplcProgramV2 } from "@helios-lang/uplc"
|
|
11
|
+
* @import { UplcData, UplcProgramV2, UplcTerm } from "@helios-lang/uplc"
|
|
6
12
|
* @import { CompilerLib, CompileOptions, CompileOutput, ScriptHashType, TypeCheckOutput } from "../index.js"
|
|
7
13
|
*/
|
|
8
14
|
|
|
@@ -114,11 +120,13 @@ class CompilerLib_v0_17 {
|
|
|
114
120
|
const ir = options.debug ? uplc.ir : undefined
|
|
115
121
|
const altIr = options.debug ? alt?.ir : undefined
|
|
116
122
|
const sourceMap = makeUplcSourceMap({
|
|
117
|
-
term: uplc.root
|
|
123
|
+
term: changeUplcCallTermsToUplcApply(uplc.root)
|
|
118
124
|
}).toJsonSafe()
|
|
119
125
|
const altSourceMap = alt
|
|
120
126
|
? makeUplcSourceMap({
|
|
121
|
-
term:
|
|
127
|
+
term: changeUplcCallTermsToUplcApply(
|
|
128
|
+
alt.root
|
|
129
|
+
)
|
|
122
130
|
}).toJsonSafe()
|
|
123
131
|
: undefined
|
|
124
132
|
|
|
@@ -155,7 +163,9 @@ class CompilerLib_v0_17 {
|
|
|
155
163
|
: {})
|
|
156
164
|
})
|
|
157
165
|
|
|
158
|
-
const sourceMap = makeUplcSourceMap({
|
|
166
|
+
const sourceMap = makeUplcSourceMap({
|
|
167
|
+
term: changeUplcCallTermsToUplcApply(uplc.root)
|
|
168
|
+
})
|
|
159
169
|
|
|
160
170
|
return {
|
|
161
171
|
cborHex: bytesToHex(uplc.toCbor()),
|
|
@@ -176,3 +186,43 @@ class CompilerLib_v0_17 {
|
|
|
176
186
|
return analyzeMulti(validatorSources, moduleSources)
|
|
177
187
|
}
|
|
178
188
|
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* @param {UplcTerm} root
|
|
192
|
+
* @returns {UplcTerm}
|
|
193
|
+
*/
|
|
194
|
+
function changeUplcCallTermsToUplcApply(root) {
|
|
195
|
+
if (
|
|
196
|
+
root.kind == "apply" ||
|
|
197
|
+
root.kind == "builtin" ||
|
|
198
|
+
root.kind == "case" ||
|
|
199
|
+
root.kind == "const" ||
|
|
200
|
+
root.kind == "constr" ||
|
|
201
|
+
root.kind == "error" ||
|
|
202
|
+
root.kind == "var"
|
|
203
|
+
) {
|
|
204
|
+
return root
|
|
205
|
+
} else if (root.kind == "delay") {
|
|
206
|
+
return makeUplcDelay({
|
|
207
|
+
arg: changeUplcCallTermsToUplcApply(root.arg),
|
|
208
|
+
site: root.site
|
|
209
|
+
})
|
|
210
|
+
} else if (root.kind == "force") {
|
|
211
|
+
return makeUplcForce({
|
|
212
|
+
arg: changeUplcCallTermsToUplcApply(root.arg),
|
|
213
|
+
site: root.site
|
|
214
|
+
})
|
|
215
|
+
} else if (root.kind == "lambda") {
|
|
216
|
+
return makeUplcLambda({
|
|
217
|
+
body: changeUplcCallTermsToUplcApply(root.children[0]),
|
|
218
|
+
site: root.site
|
|
219
|
+
})
|
|
220
|
+
} else {
|
|
221
|
+
const term = /** @type {any} */ (root)
|
|
222
|
+
return makeUplcApply({
|
|
223
|
+
fn: changeUplcCallTermsToUplcApply(term.fn),
|
|
224
|
+
arg: changeUplcCallTermsToUplcApply(term.arg),
|
|
225
|
+
site: term.site
|
|
226
|
+
})
|
|
227
|
+
}
|
|
228
|
+
}
|
package/types/cast/Cast.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Cast.d.ts","sourceRoot":"","sources":["../../src/cast/Cast.js"],"names":[],"mappings":"AAsDA;;;;;GAKG;AAEH;;;;;GAKG;AAEH;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,yBANa,OAAO,EACP,WAAW,UACb,UAAU,UACV,UAAU,GACR,KAAK,OAAO,EAAE,WAAW,CAAC,CAItC;AAsED;;;;;;;;;;GAUG;AACH,oCAVa,CAAC,UACH,UAAU,QACV,QAAQ,WACR;IACN,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6BAA6B,CAAC,EAAE,OAAO,CAAA;CACxC,GACS,CAAC,CASb;AAED;;;;;;;;;GASG;AACH,kCATa,CAAC,UACH,UAAU,KACV,CAAC,YACD;IACN,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6BAA6B,CAAC,EAAE,OAAO,CAAA;CACxC,GACS,QAAQ,CAUpB;
|
|
1
|
+
{"version":3,"file":"Cast.d.ts","sourceRoot":"","sources":["../../src/cast/Cast.js"],"names":[],"mappings":"AAsDA;;;;;GAKG;AAEH;;;;;GAKG;AAEH;;;;;;GAMG;AAEH;;;;;;GAMG;AACH,yBANa,OAAO,EACP,WAAW,UACb,UAAU,UACV,UAAU,GACR,KAAK,OAAO,EAAE,WAAW,CAAC,CAItC;AAsED;;;;;;;;;;GAUG;AACH,oCAVa,CAAC,UACH,UAAU,QACV,QAAQ,WACR;IACN,SAAS,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6BAA6B,CAAC,EAAE,OAAO,CAAA;CACxC,GACS,CAAC,CASb;AAED;;;;;;;;;GASG;AACH,kCATa,CAAC,UACH,UAAU,KACV,CAAC,YACD;IACN,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,6BAA6B,CAAC,EAAE,OAAO,CAAA;CACxC,GACS,QAAQ,CAUpB;AA0tBD;;;;;;GAMG;AACH,8BANa,OAAO,EACP,WAAW,QACb,SAAS,OAAO,EAAE,WAAW,CAAC,UAC9B,UAAU,GACR,KAAK,OAAO,EAAE,WAAW,CAAC,CAQtC;;;;;UAz2BS,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;;;;cAC1B,MAAM;;;;mCACN,OAAO;;;;;;UAKP,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC;;;;cAC1B,MAAM;;;;mCACN,OAAO;eACP,OAAO;;gCAjB8B,yBAAyB;gCAEzB,aAAa;0BAAb,aAAa;8BADnB,mBAAmB;8BACb,aAAa;gDAFb,yBAAyB"}
|
|
@@ -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":"AASA;;;GAGG;AAEH;;;;;;;;;;;;;;GAcG;AAEH;;;GAGG;AACH,2CAHW,GAAG,GACD,WAAW,CAIvB;sBArBY;IACR,IAAI,EAAE,MAAM,CAAA;IACZ,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAA;IACtC,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAA;IAC/C,OAAO,CAAC,OAAO,EAAE;QACf,QAAQ,CAAC,EAAE,OAAO,CAAC;QACnB,gBAAgB,CAAC,EAAE,OAAO,CAAC;QAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACzC,gBAAgB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACzC,gBAAgB,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;QAC9B,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,aAAa,KAAK,IAAI,CAAA;KAChE,GAAG,aAAa,CAAA;CAClB;iCAhB4F,aAAa;8BADvD,mBAAmB;mCAAnB,mBAAmB"}
|