@helios-lang/contract-utils 0.2.69 → 0.2.70

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.69",
3
+ "version": "0.2.70",
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",
@@ -28,9 +28,9 @@
28
28
  "@helios-lang/cli-utils": "^0.1.6",
29
29
  "@helios-lang/codec-utils": "^0.1.35",
30
30
  "@helios-lang/compiler-utils": "^0.1.57",
31
- "@helios-lang/ledger": "^0.5.4",
31
+ "@helios-lang/ledger": "^0.5.5",
32
32
  "@helios-lang/type-utils": "^0.1.22",
33
- "@helios-lang/uplc": "^0.3.12"
33
+ "@helios-lang/uplc": "^0.3.13"
34
34
  },
35
35
  "scripts": {
36
36
  "build": "pnpm run prettify && pnpm run build:types && pnpm run test:suite",
@@ -2,6 +2,7 @@ import { bytesToHex } from "@helios-lang/codec-utils"
2
2
  import { expectSome, isLeft, isString } from "@helios-lang/type-utils"
3
3
  import { ConstrData, IntData, UplcDataValue } from "@helios-lang/uplc"
4
4
  import { Cast } from "./Cast.js"
5
+ import { None } from "@helios-lang/type-utils"
5
6
  import { BasicUplcLogger } from "@helios-lang/uplc"
6
7
 
7
8
  /**
@@ -15,6 +16,7 @@ import { BasicUplcLogger } from "@helios-lang/uplc"
15
16
  */
16
17
 
17
18
  /**
19
+ * TODO: add logOptions here as well (which can be overridden by logOptions passed directly to eval(), evalUnsafe() and profile())?
18
20
  * `returns` is optional to accomodate main functions that return void
19
21
  * @typedef {{
20
22
  * name: string
@@ -72,10 +74,10 @@ export class UserFunc {
72
74
 
73
75
  /**
74
76
  * @param {ArgsT} namedArgs
75
- * @param {UplcLoggingI} [logOptions]
77
+ * @param {Option<UplcLoggingI>} logOptions
76
78
  * @returns {RetT}
77
79
  */
78
- eval(namedArgs, logOptions) {
80
+ eval(namedArgs, logOptions = None) {
79
81
  /**
80
82
  * @type {{[argName: string]: any}}
81
83
  */
@@ -119,10 +121,10 @@ export class UserFunc {
119
121
 
120
122
  /**
121
123
  * @param {UnsafeArgsT<ArgsT>} namedArgs
122
- * @param {UplcLoggingI} [logOptions]
124
+ * @param {Option<UplcLoggingI>} logOptions
123
125
  * @returns {RetT extends void ? void : UplcData}
124
126
  */
125
- evalUnsafe(namedArgs, logOptions) {
127
+ evalUnsafe(namedArgs, logOptions = None) {
126
128
  const result = this.profile(namedArgs, logOptions).result
127
129
 
128
130
  if (isLeft(result)) {
@@ -130,7 +132,9 @@ export class UserFunc {
130
132
 
131
133
  let msg = result.left.error
132
134
 
133
- if (stackTrace.length > 0) {
135
+ // only add the stackTrace if the logOptions aren't given
136
+ // TODO: make sure logOptions actually logs the stack trace
137
+ if (!logOptions && stackTrace.length > 0) {
134
138
  msg = `Stack trace:\n ${stackTrace.join("\n ")}\n${msg}`
135
139
  }
136
140
 
@@ -146,10 +150,10 @@ export class UserFunc {
146
150
 
147
151
  /**
148
152
  * @param {UnsafeArgsT<ArgsT>} namedArgs
149
- * @param {UplcLoggingI} [logOptions] - optional, passed to UplcProgram.eval if provided
153
+ * @param {Option<UplcLoggingI>} logOptions - optional, passed to UplcProgram.eval if provided
150
154
  * @returns {CekResult}
151
155
  */
152
- profile(namedArgs, logOptions) {
156
+ profile(namedArgs, logOptions = None) {
153
157
  const isMain = this.name == "main"
154
158
 
155
159
  /**
@@ -198,11 +202,13 @@ export class UserFunc {
198
202
 
199
203
  const argValues = args.map((a) => new UplcDataValue(a))
200
204
 
201
- const cekResult = this.uplc.eval(argValues, { logOptions })
205
+ const cekResult = this.uplc.eval(argValues, {
206
+ logOptions: logOptions ?? undefined
207
+ })
202
208
 
203
209
  if (this.uplc.alt?.plutusVersion == "PlutusScriptV2") {
204
210
  const cekResultUnoptim = this.uplc.alt.eval(argValues, {
205
- logOptions
211
+ logOptions: logOptions ?? undefined
206
212
  })
207
213
  const resultUnoptim = cekResultUnoptim.result
208
214
  const resultUnoptimStr = evalResultToString(resultUnoptim)
@@ -243,6 +249,9 @@ export class UserFunc {
243
249
  `Warning: optimizer didn't improve cost of ${this.props.name}`
244
250
  )
245
251
  }
252
+
253
+ // overwrite the optimized cekResult.result with the unoptimized result because it contains more information
254
+ cekResult.result = resultUnoptim
246
255
  }
247
256
 
248
257
  return cekResult
@@ -159,7 +159,7 @@ export class CompilerLib_v0_17 {
159
159
  cborHex: bytesToHex(uplc.toCbor()),
160
160
  plutusVersion: uplc.plutusVersion,
161
161
  sourceMap: sourceMap.toJsonSafe(),
162
- ir: uplc.ir ?? undefined
162
+ ir: options.debug ? (uplc.ir ?? undefined) : undefined
163
163
  }
164
164
  }
165
165
 
@@ -8,6 +8,7 @@
8
8
  * @typedef {import("./Cast.js").CastConfig} CastConfig
9
9
  */
10
10
  /**
11
+ * TODO: add logOptions here as well (which can be overridden by logOptions passed directly to eval(), evalUnsafe() and profile())?
11
12
  * `returns` is optional to accomodate main functions that return void
12
13
  * @typedef {{
13
14
  * name: string
@@ -56,22 +57,22 @@ export class UserFunc<ArgsT extends {
56
57
  get name(): string;
57
58
  /**
58
59
  * @param {ArgsT} namedArgs
59
- * @param {UplcLoggingI} [logOptions]
60
+ * @param {Option<UplcLoggingI>} logOptions
60
61
  * @returns {RetT}
61
62
  */
62
- eval(namedArgs: ArgsT, logOptions?: import("@helios-lang/uplc/types/logging/UplcLoggingI.js").UplcLoggingI | undefined): RetT;
63
+ eval(namedArgs: ArgsT, logOptions?: Option<UplcLoggingI>): RetT;
63
64
  /**
64
65
  * @param {UnsafeArgsT<ArgsT>} namedArgs
65
- * @param {UplcLoggingI} [logOptions]
66
+ * @param {Option<UplcLoggingI>} logOptions
66
67
  * @returns {RetT extends void ? void : UplcData}
67
68
  */
68
- evalUnsafe(namedArgs: UnsafeArgsT<ArgsT>, logOptions?: import("@helios-lang/uplc/types/logging/UplcLoggingI.js").UplcLoggingI | undefined): RetT extends void ? void : UplcData;
69
+ evalUnsafe(namedArgs: UnsafeArgsT<ArgsT>, logOptions?: Option<UplcLoggingI>): RetT extends void ? void : UplcData;
69
70
  /**
70
71
  * @param {UnsafeArgsT<ArgsT>} namedArgs
71
- * @param {UplcLoggingI} [logOptions] - optional, passed to UplcProgram.eval if provided
72
+ * @param {Option<UplcLoggingI>} logOptions - optional, passed to UplcProgram.eval if provided
72
73
  * @returns {CekResult}
73
74
  */
74
- profile(namedArgs: UnsafeArgsT<ArgsT>, logOptions?: import("@helios-lang/uplc/types/logging/UplcLoggingI.js").UplcLoggingI | undefined): CekResult;
75
+ profile(namedArgs: UnsafeArgsT<ArgsT>, logOptions?: Option<UplcLoggingI>): CekResult;
75
76
  }
76
77
  export type TypeSchema = import("@helios-lang/type-utils").TypeSchema;
77
78
  export type CekResult = import("@helios-lang/uplc").CekResult;
@@ -81,6 +82,7 @@ export type UplcProgram = import("@helios-lang/uplc").UplcProgram;
81
82
  export type UplcValue = import("@helios-lang/uplc").UplcValue;
82
83
  export type CastConfig = import("./Cast.js").CastConfig;
83
84
  /**
85
+ * TODO: add logOptions here as well (which can be overridden by logOptions passed directly to eval(), evalUnsafe() and profile())?
84
86
  * `returns` is optional to accomodate main functions that return void
85
87
  */
86
88
  export type UserFuncProps = {
@@ -1 +1 @@
1
- {"version":3,"file":"UserFunc.d.ts","sourceRoot":"","sources":["../../src/cast/UserFunc.js"],"names":[],"mappings":"AAMA;;;;;;;;GAQG;AAEH;;;;;;;;;;;;;;;GAeG;AAEH;;;GAGG;AAEH;;;GAGG;AACH,sBAHwC,KAAK,SAAhC;IAAE,CAAC,OAAO,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,EAC1B,IAAI;IAgBb;;;OAGG;IACH,kBAHW,WAAW,SACX,aAAa,EAKvB;IApBD;;;OAGG;IACH,eAFU,WAAW,CAEjB;IAEJ;;;;OAIG;IACH,uBAAK;IAWL;;OAEG;IACH,mBAEC;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