@@ -1367,6 +1367,14 @@ export class BigNum {
1367
1367
return this.toJsValue().toString();
1368
1368
}
1369
1369
1370
+ to_json(): String {
1371
+ return '"' + this.to_str() + '"';
1372
+ }
1373
+
1374
+ toJSON(): String {
1375
+ return this.to_json();
1376
+ }
1377
+
1370
1378
static zero(): BigNum {
1371
1379
return new BigNum(0n);
1372
1380
}
@@ -2212,6 +2220,14 @@ export class CSLBigInt {
2212
2220
return this.toJsValue().toString();
2213
2221
}
2214
2222
2223
+ to_json(): String {
2224
+ return '"' + this.to_str() + '"';
2225
+ }
2226
+
2227
+ toJSON(): String {
2228
+ return this.to_json();
2229
+ }
2230
+
2215
2231
static zero(): CSLBigInt {
2216
2232
return new CSLBigInt(0n);
2217
2233
}
@@ -3940,6 +3956,71 @@ export class Costmdls {
3940
3956
}
3941
3957
return result;
3942
3958
}
3959
+
3960
+ language_views_encoding(): Uint8Array {
3961
+ // Compare two byte arrays lexicographically
3962
+ function compareBytes(a: Uint8Array, b: Uint8Array): number {
3963
+ const minLen = Math.min(a.length, b.length);
3964
+ for (let i = 0; i < minLen; i++) {
3965
+ if (a[i] < b[i]) return -1;
3966
+ if (a[i] > b[i]) return 1;
3967
+ }
3968
+ return a.length - b.length;
3969
+ }
3970
+
3971
+ function keyLen(lang: Language): number {
3972
+ if (lang.kind() === LanguageKind.plutus_v1) {
3973
+ const w = new CBORWriter();
3974
+ w.writeBytes(lang.to_bytes());
3975
+ return w.getBytes().length;
3976
+ } else {
3977
+ return lang.to_bytes().length;
3978
+ }
3979
+ }
3980
+
3981
+ const keys = this._items.map(([k, _]) => k);
3982
+
3983
+ // keys must be in canonical ordering first
3984
+ keys.sort((lhs, rhs) => {
3985
+ const lhsLen = keyLen(lhs);
3986
+ const rhsLen = keyLen(rhs);
3987
+ if (lhsLen !== rhsLen) {
3988
+ return lhsLen - rhsLen;
3989
+ }
3990
+ return compareBytes(lhs.to_bytes(), rhs.to_bytes());
3991
+ });
3992
+
3993
+ const writer = new CBORWriter();
3994
+ writer.writeMapTag(keys.length);
3995
+
3996
+ for (let i = 0; i < keys.length; i++) {
3997
+ const key = keys[i];
3998
+ const costModel = this.get(key);
3999
+ if (!costModel) {
4000
+ throw new Error(
4001
+ "No cost model found for key in language_views_encoding.",
4002
+ );
4003
+ }
4004
+
4005
+ if (key.kind() === LanguageKind.plutus_v1) {
4006
+ writer.writeBytes(key.to_bytes());
4007
+
4008
+ const subWriter = new CBORWriter();
4009
+ subWriter.writeArray(
4010
+ costModel["items"],
4011
+ (sw, costInt) => costInt.serialize(sw),
4012
+ false,
4013
+ );
4014
+
4015
+ writer.writeBytes(subWriter.getBytes());
4016
+ } else {
4017
+ key.serialize(writer);
4018
+ costModel.serialize(writer);
4019
+ }
4020
+ }
4021
+
4022
+ return writer.getBytes();
4023
+ }
3943
4024
}
3944
4025
3945
4026
export class Credentials {
@@ -5040,6 +5121,10 @@ export class DataCost {
5040
5121
clone(path: string[]): DataCost {
5041
5122
return DataCost.from_bytes(this.to_bytes(), path);
5042
5123
}
5124
+
5125
+ static new_coins_per_byte(coins_per_byte: BigNum) {
5126
+ return new DataCost(coins_per_byte);
5127
+ }
5043
5128
}
5044
5129
5045
5130
export class DataHash {
@@ -13087,6 +13172,18 @@ export class Redeemer {
13087
13172
) {
13088
13173
return new Redeemer(new RedeemersArrayItem(tag, index, data, ex_units));
13089
13174
}
13175
+ tag(): RedeemerTag {
13176
+ return this.inner.tag();
13177
+ }
13178
+ index(): BigNum {
13179
+ return this.inner.index();
13180
+ }
13181
+ data(): PlutusData {
13182
+ return this.inner.data();
13183
+ }
13184
+ ex_units(): ExUnits {
13185
+ return this.inner.ex_units();
13186
+ }
13090
13187
}
13091
13188
13092
13189
export enum RedeemerTagKind {
@@ -14344,10 +14441,6 @@ export class ScriptAll {
14344
14441
return new ScriptAll(native_scripts);
14345
14442
}
14346
14443
14347
- serialize(writer: CBORWriter): void {
14348
- this._native_scripts.serialize(writer);
14349
- }
14350
-
14351
14444
// no-op
14352
14445
free(): void {}
14353
14446
@@ -14376,6 +14469,14 @@ export class ScriptAll {
14376
14469
clone(path: string[]): ScriptAll {
14377
14470
return ScriptAll.from_bytes(this.to_bytes(), path);
14378
14471
}
14472
+
14473
+ serialize(writer: CBORWriter): void {
14474
+ let ns = new NativeScripts(true, false);
14475
+ for (let i = 0; i < this._native_scripts.len(); i++) {
14476
+ ns.add(this._native_scripts.get(i));
14477
+ }
14478
+ ns.serialize(writer);
14479
+ }
14379
14480
}
14380
14481
14381
14482
export class ScriptAny {
@@ -14406,10 +14507,6 @@ export class ScriptAny {
14406
14507
return new ScriptAny(native_scripts);
14407
14508
}
14408
14509
14409
- serialize(writer: CBORWriter): void {
14410
- this._native_scripts.serialize(writer);
14411
- }
14412
-
14413
14510
// no-op
14414
14511
free(): void {}
14415
14512
@@ -14438,6 +14535,14 @@ export class ScriptAny {
14438
14535
clone(path: string[]): ScriptAny {
14439
14536
return ScriptAny.from_bytes(this.to_bytes(), path);
14440
14537
}
14538
+
14539
+ serialize(writer: CBORWriter): void {
14540
+ let ns = new NativeScripts(true, false);
14541
+ for (let i = 0; i < this._native_scripts.len(); i++) {
14542
+ ns.add(this._native_scripts.get(i));
14543
+ }
14544
+ ns.serialize(writer);
14545
+ }
14441
14546
}
14442
14547
14443
14548
export class ScriptDataHash {
@@ -14693,11 +14798,6 @@ export class ScriptNOfK {
14693
14798
return new ScriptNOfK(n, native_scripts);
14694
14799
}
14695
14800
14696
- serialize(writer: CBORWriter): void {
14697
- writer.writeInt(BigInt(this._n));
14698
- this._native_scripts.serialize(writer);
14699
- }
14700
-
14701
14801
// no-op
14702
14802
free(): void {}
14703
14803
@@ -14729,6 +14829,15 @@ export class ScriptNOfK {
14729
14829
clone(path: string[]): ScriptNOfK {
14730
14830
return ScriptNOfK.from_bytes(this.to_bytes(), path);
14731
14831
}
14832
+
14833
+ serialize(writer: CBORWriter): void {
14834
+ writer.writeInt(BigInt(this._n));
14835
+ let ns = new NativeScripts(true, false);
14836
+ for (let i = 0; i < this._native_scripts.len(); i++) {
14837
+ ns.add(this._native_scripts.get(i));
14838
+ }
14839
+ ns.serialize(writer);
14840
+ }
14732
14841
}
14733
14842
14734
14843
export class ScriptPubkey {
0 commit comments