@helios-lang/contract-utils 0.1.36 → 0.1.38
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.1.
|
|
3
|
+
"version": "0.1.38",
|
|
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",
|
|
@@ -36,10 +36,10 @@
|
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@helios-lang/cli-utils": "^0.1.2",
|
|
39
|
-
"@helios-lang/codec-utils": "^0.1.
|
|
39
|
+
"@helios-lang/codec-utils": "^0.1.29",
|
|
40
40
|
"@helios-lang/compiler-utils": "^0.1.21",
|
|
41
|
-
"@helios-lang/ledger": "^0.1.
|
|
41
|
+
"@helios-lang/ledger": "^0.1.44",
|
|
42
42
|
"@helios-lang/type-utils": "^0.1.8",
|
|
43
|
-
"@helios-lang/uplc": "^0.1.
|
|
43
|
+
"@helios-lang/uplc": "^0.1.26"
|
|
44
44
|
}
|
|
45
45
|
}
|
package/src/cast/Cast.js
CHANGED
|
@@ -81,60 +81,58 @@ function schemaToUplc(schema, x) {
|
|
|
81
81
|
if ("primitiveType" in schema) {
|
|
82
82
|
switch (schema.primitiveType) {
|
|
83
83
|
case "Address":
|
|
84
|
-
return Address.
|
|
84
|
+
return Address.new(x).toUplcData()
|
|
85
85
|
case "Any":
|
|
86
86
|
return new IntData(0n)
|
|
87
87
|
case "AssetClass":
|
|
88
|
-
return AssetClass.
|
|
88
|
+
return AssetClass.new(x).toUplcData()
|
|
89
89
|
case "Bool":
|
|
90
90
|
return encodeBoolData(x)
|
|
91
91
|
case "ByteArray":
|
|
92
92
|
return new ByteArrayData(x)
|
|
93
93
|
case "Credential":
|
|
94
94
|
case "PaymentCredential":
|
|
95
|
-
return SpendingCredential.
|
|
95
|
+
return SpendingCredential.new(x).toUplcData()
|
|
96
96
|
case "Data":
|
|
97
97
|
return x
|
|
98
98
|
case "DatumHash":
|
|
99
|
-
return DatumHash.
|
|
99
|
+
return DatumHash.new(x).toUplcData()
|
|
100
100
|
case "DCert":
|
|
101
101
|
return x.toUplcData()
|
|
102
102
|
case "Duration":
|
|
103
103
|
case "Int":
|
|
104
104
|
return new IntData(x)
|
|
105
105
|
case "MintingPolicyHash":
|
|
106
|
-
return MintingPolicyHash.
|
|
106
|
+
return MintingPolicyHash.new(x).toUplcData()
|
|
107
107
|
case "PubKeyHash":
|
|
108
|
-
return PubKeyHash.
|
|
108
|
+
return PubKeyHash.new(x).toUplcData()
|
|
109
109
|
case "Real":
|
|
110
110
|
return encodeRealData(x)
|
|
111
111
|
case "ScriptHash":
|
|
112
|
-
return ScriptHash.
|
|
112
|
+
return ScriptHash.new(x).toUplcData()
|
|
113
113
|
case "StakingCredential":
|
|
114
|
-
return StakingCredential.
|
|
114
|
+
return StakingCredential.new(x).toUplcData()
|
|
115
115
|
case "StakingHash":
|
|
116
|
-
return StakingHash.
|
|
116
|
+
return StakingHash.new(x).toUplcData()
|
|
117
117
|
case "String":
|
|
118
118
|
return new ByteArrayData(encodeUtf8(x))
|
|
119
119
|
case "Time":
|
|
120
|
-
|
|
121
|
-
const ms = x instanceof Date ? x.getTime() : x
|
|
122
|
-
return new IntData(ms)
|
|
120
|
+
return new IntData(x)
|
|
123
121
|
case "TimeRange":
|
|
124
|
-
return TimeRange.
|
|
122
|
+
return TimeRange.new(x).toUplcData()
|
|
125
123
|
case "TxId":
|
|
126
|
-
return TxId.
|
|
124
|
+
return TxId.new(x).toUplcData()
|
|
127
125
|
case "TxOutputDatum":
|
|
128
126
|
return x
|
|
129
|
-
? TxOutputDatum.
|
|
127
|
+
? TxOutputDatum.new(x)?.toUplcData() ??
|
|
130
128
|
new ConstrData(0, [])
|
|
131
129
|
: new ConstrData(0, [])
|
|
132
130
|
case "TxOutputId":
|
|
133
|
-
return TxOutputId.
|
|
131
|
+
return TxOutputId.new(x).toUplcData()
|
|
134
132
|
case "ValidatorHash":
|
|
135
|
-
return ValidatorHash.
|
|
133
|
+
return ValidatorHash.new(x).toUplcData()
|
|
136
134
|
case "Value":
|
|
137
|
-
return Value.
|
|
135
|
+
return Value.new(x).toUplcData()
|
|
138
136
|
default:
|
|
139
137
|
throw new Error(
|
|
140
138
|
`not yet implemented for ${schema.primitiveType}`
|
|
@@ -241,7 +239,7 @@ function uplcToSchema(schema, data) {
|
|
|
241
239
|
case "String":
|
|
242
240
|
return decodeUtf8(ByteArrayData.expect(data).bytes)
|
|
243
241
|
case "Time":
|
|
244
|
-
return
|
|
242
|
+
return Number(IntData.expect(data).value) // a number has enough precision to represent ms since 1970 for another 142000 years
|
|
245
243
|
case "TimeRange":
|
|
246
244
|
return TimeRange.fromUplcData(data)
|
|
247
245
|
case "TxId":
|
|
@@ -135,11 +135,16 @@ export class LoadedScriptsWriter {
|
|
|
135
135
|
'import { Cast } from "@helios-lang/contract-utils";'
|
|
136
136
|
)
|
|
137
137
|
;[this.declaration, this.combined].forEach((w) => {
|
|
138
|
-
w.writeLine('import type {UplcData} from "@helios-lang/ledger";')
|
|
139
138
|
w.writeLine(
|
|
140
|
-
'import {
|
|
139
|
+
'import type { IntLike } from "@helios-lang/codec-utils";'
|
|
141
140
|
)
|
|
142
141
|
w.writeLine('import { Cast } from "@helios-lang/contract-utils";')
|
|
142
|
+
w.writeLine(
|
|
143
|
+
'import type { TimeLike, UplcData } from "@helios-lang/ledger";'
|
|
144
|
+
)
|
|
145
|
+
w.writeLine(
|
|
146
|
+
'import { Address, AssetClass, DatumHash, MintingPolicyHash, PubKey, PubKeyHash, SpendingCredential, StakingCredential, StakingHash, StakingValidatorHash, TimeRange, TxId, TxOutputDatum, ValidatorHash, Value } from "@helios-lang/ledger";'
|
|
147
|
+
)
|
|
143
148
|
})
|
|
144
149
|
}
|
|
145
150
|
|
|
@@ -56,9 +56,9 @@ export function genTypes(schema) {
|
|
|
56
56
|
case "Data":
|
|
57
57
|
return ["UplcData", "UplcData"]
|
|
58
58
|
case "Duration":
|
|
59
|
-
return ["bigint", "
|
|
59
|
+
return ["bigint", "IntLike"]
|
|
60
60
|
case "Int":
|
|
61
|
-
return ["bigint", "
|
|
61
|
+
return ["bigint", "IntLike"]
|
|
62
62
|
case "MintingPolicyHash":
|
|
63
63
|
return [
|
|
64
64
|
"MintingPolicyHash",
|
|
@@ -88,11 +88,11 @@ export function genTypes(schema) {
|
|
|
88
88
|
case "String":
|
|
89
89
|
return ["string", "string"]
|
|
90
90
|
case "Time":
|
|
91
|
-
return ["
|
|
91
|
+
return ["number", "TimeLike"]
|
|
92
92
|
case "TimeRange":
|
|
93
93
|
return [
|
|
94
94
|
"TimeRange",
|
|
95
|
-
"TimeRange | [
|
|
95
|
+
"TimeRange | [TimeLike, TimeLike] | {start?: TimeLike, excludeStart?: boolean, end?: TimeLike, excludeEnd?: boolean}"
|
|
96
96
|
]
|
|
97
97
|
case "TxId":
|
|
98
98
|
return ["TxId", "TxId | string | number[]"]
|
|
@@ -108,7 +108,7 @@ export function genTypes(schema) {
|
|
|
108
108
|
case "Value":
|
|
109
109
|
return [
|
|
110
110
|
"Value",
|
|
111
|
-
"Value | [MintingPolicyHash | string | number[], [number[] | string,
|
|
111
|
+
"Value | [MintingPolicyHash | string | number[], [number[] | string, IntLike][]][] | {mph: MintingPolicyHash | string | number[], tokens: {name: number[] | string, qty: IntLike}[]}[]"
|
|
112
112
|
]
|
|
113
113
|
default:
|
|
114
114
|
throw new Error(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LoadedScriptsWriter.d.ts","sourceRoot":"","sources":["../../src/codegen/LoadedScriptsWriter.js"],"names":[],"mappings":"AAGA;;;;GAIG;AAEH;IAUI;;;OAGG;IACH,gBAFa,mBAAmB,CAQ/B;IAfG,yBAAoC;IACpC,0BAAqC;IACrC,uBAAkC;IAetC;;;OAGG;IACH;;QAFa,mBAAmB,CAgC/B;IAED;;;OAGG;IACH;;QAFa,mBAAmB,CAkC/B;IAED;;OAEG;IACH,YAFa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAQpC;IAED;;;;;OAKG;IACH,cAKC;IAED;;OAEG;IACH,
|
|
1
|
+
{"version":3,"file":"LoadedScriptsWriter.d.ts","sourceRoot":"","sources":["../../src/codegen/LoadedScriptsWriter.js"],"names":[],"mappings":"AAGA;;;;GAIG;AAEH;IAUI;;;OAGG;IACH,gBAFa,mBAAmB,CAQ/B;IAfG,yBAAoC;IACpC,0BAAqC;IACrC,uBAAkC;IAetC;;;OAGG;IACH;;QAFa,mBAAmB,CAgC/B;IAED;;;OAGG;IACH;;QAFa,mBAAmB,CAkC/B;IAED;;OAEG;IACH,YAFa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAQpC;IAED;;;;;OAKG;IACH,cAKC;IAED;;OAEG;IACH,qBAgBC;IAED;;;OAGG;IACH,kBAFW,OAAO,MAAM,EAAE,UAAU,CAAC,QAiBpC;IAED;;;OAGG;IACH,oBA4BC;IAED;;;OAGG;IACH,uBAgDC;CACJ;gCA9PY,OAAO,wBAAwB,EAAE,iBAAiB;mCAClD,OAAO,2BAA2B,EAAE,oBAAoB;yBACxD,OAAO,iBAAiB,EAAE,UAAU;6BANpB,0BAA0B"}
|