@helios-lang/contract-utils
Advanced tools
Comparing version
{ | ||
"name": "@helios-lang/contract-utils", | ||
"version": "0.3.20", | ||
"version": "0.3.21", | ||
"description": "Convenience and type-safety utilities for using Helios validators from within Typescript", | ||
@@ -41,7 +41,7 @@ "main": "src/index.js", | ||
"@helios-lang/codec-utils": "^0.3.4", | ||
"@helios-lang/compiler-utils": "^0.5.13", | ||
"@helios-lang/compiler-utils": "^0.5.15", | ||
"@helios-lang/crypto": "0.2.3", | ||
"@helios-lang/ledger": "^0.7.4", | ||
"@helios-lang/type-utils": "^0.2.9", | ||
"@helios-lang/uplc": "^0.7.14" | ||
"@helios-lang/ledger": "^0.7.8", | ||
"@helios-lang/type-utils": "^0.3.0", | ||
"@helios-lang/uplc": "^0.7.15" | ||
}, | ||
@@ -48,0 +48,0 @@ "scripts": { |
@@ -478,11 +478,13 @@ import { decodeUtf8, encodeUtf8 } from "@helios-lang/codec-utils" | ||
const variantFields = Object.values(x)[0] | ||
const tag = schema.variantTypes.findIndex( | ||
const foundVariant = schema.variantTypes.find( | ||
(v) => v.name == variantName | ||
) | ||
if (tag == -1) { | ||
if (!foundVariant) { | ||
throw new Error( | ||
`invalid variant ${variantName} (expected: ${schema.variantTypes.map((v) => v.name).join(", ")})` | ||
`invalid enum variant '${variantName}' (expected one of: ${schema.variantTypes | ||
.map((v) => v.name) | ||
.join(", ")})` | ||
) | ||
} | ||
const tag = foundVariant.tag | ||
@@ -527,3 +529,10 @@ return convertEnumVariantDataToConstrData( | ||
function convertEnumVariantDataToConstrData(schema, tag, data, context) { | ||
const variantSchema = schema.variantTypes[tag] | ||
const variantSchema = schema.variantTypes.find((v) => v.tag == tag) | ||
if (!variantSchema) { | ||
throw new Error( | ||
`invalid enum variant tag ${tag} (expected one of: ${schema.variantTypes | ||
.map((v) => v.tag) | ||
.join(", ")})` | ||
) | ||
} | ||
const variantName = variantSchema.name | ||
@@ -872,6 +881,10 @@ | ||
const variantSchema = schema.variantTypes[tag] | ||
const variantSchema = schema.variantTypes.find((v) => v.tag == tag) | ||
if (!variantSchema) { | ||
throw new Error(`tag ${tag} out of range`) | ||
throw new Error( | ||
`invalid enum variant tag ${tag} (expected one of: ${schema.variantTypes | ||
.map((v) => v.tag) | ||
.join(", ")})` | ||
) | ||
} | ||
@@ -878,0 +891,0 @@ |
Sorry, the diff of this file is not supported yet
306927
0.17%7532
0.19%