@typeberry/convert 0.5.3-c402c56 → 0.5.3-fb6e98a

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.
Files changed (3) hide show
  1. package/index.js +30 -31
  2. package/index.js.map +1 -1
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -5346,7 +5346,7 @@ const bytesBlobComparator = (a, b) => a.compare(b);
5346
5346
  const asTypedNumber = (v) => v;
5347
5347
  const MAX_VALUE_U8 = 0xff;
5348
5348
  const MAX_VALUE_U16 = 0xffff;
5349
- const MAX_VALUE_U32 = 0xffff_ffff;
5349
+ const numbers_MAX_VALUE_U32 = 0xffff_ffff;
5350
5350
  const MAX_VALUE_U64 = 0xffffffffffffffffn;
5351
5351
  /** Attempt to cast an input number into U8. */
5352
5352
  const tryAsU8 = (v) => {
@@ -5368,7 +5368,7 @@ const numbers_tryAsU32 = (v) => {
5368
5368
  return asTypedNumber(v);
5369
5369
  };
5370
5370
  /** Check if given number is a valid U32 number. */
5371
- const isU32 = (v) => (v & MAX_VALUE_U32) >>> 0 === v;
5371
+ const isU32 = (v) => (v & numbers_MAX_VALUE_U32) >>> 0 === v;
5372
5372
  /** Attempt to cast an input number into U64. */
5373
5373
  const numbers_tryAsU64 = (x) => {
5374
5374
  const v = BigInt(x);
@@ -7743,6 +7743,7 @@ const ZERO_HASH = bytes_Bytes.zero(hash_HASH_SIZE);
7743
7743
  class WithHash extends WithDebug {
7744
7744
  hash;
7745
7745
  data;
7746
+ // TODO [ToDr] use static method and make constructor private
7746
7747
  constructor(hash, data) {
7747
7748
  super();
7748
7749
  this.hash = hash;
@@ -9859,6 +9860,12 @@ class WorkExecResult extends WithDebug {
9859
9860
  }
9860
9861
  return { kind: x.kind };
9861
9862
  }, (x) => new WorkExecResult(x.kind, x.kind === WorkExecResultKind.ok ? x.okBlob : null));
9863
+ static ok(blob) {
9864
+ return new WorkExecResult(WorkExecResultKind.ok, blob);
9865
+ }
9866
+ static error(kind) {
9867
+ return new WorkExecResult(kind, null);
9868
+ }
9862
9869
  constructor(
9863
9870
  /** The execution result tag. */
9864
9871
  kind,
@@ -10949,22 +10956,22 @@ const workExecResultFromJson = json.object({
10949
10956
  }, (val) => {
10950
10957
  const { ok, out_of_gas, panic, bad_code, code_oversize, output_oversize } = val;
10951
10958
  if (ok !== undefined) {
10952
- return new WorkExecResult(numbers_tryAsU32(WorkExecResultKind.ok), ok);
10959
+ return WorkExecResult.ok(ok);
10953
10960
  }
10954
10961
  if (out_of_gas === null) {
10955
- return new WorkExecResult(numbers_tryAsU32(WorkExecResultKind.outOfGas));
10962
+ return WorkExecResult.error(WorkExecResultKind.outOfGas);
10956
10963
  }
10957
10964
  if (panic === null) {
10958
- return new WorkExecResult(numbers_tryAsU32(WorkExecResultKind.panic));
10965
+ return WorkExecResult.error(WorkExecResultKind.panic);
10959
10966
  }
10960
10967
  if (bad_code === null) {
10961
- return new WorkExecResult(numbers_tryAsU32(WorkExecResultKind.badCode));
10968
+ return WorkExecResult.error(WorkExecResultKind.badCode);
10962
10969
  }
10963
10970
  if (code_oversize === null) {
10964
- return new WorkExecResult(numbers_tryAsU32(WorkExecResultKind.codeOversize));
10971
+ return WorkExecResult.error(WorkExecResultKind.codeOversize);
10965
10972
  }
10966
10973
  if (output_oversize === null) {
10967
- return new WorkExecResult(numbers_tryAsU32(WorkExecResultKind.digestTooBig));
10974
+ return WorkExecResult.error(WorkExecResultKind.digestTooBig);
10968
10975
  }
10969
10976
  throw new Error("Invalid WorkExecResult");
10970
10977
  });
@@ -12314,13 +12321,6 @@ function hashComparator(a, b) {
12314
12321
  return a.compare(b);
12315
12322
  }
12316
12323
 
12317
- ;// CONCATENATED MODULE: ./packages/core/pvm-interpreter/ops/math-consts.ts
12318
- const math_consts_MAX_VALUE = 4294967295;
12319
- const math_consts_MAX_VALUE_U64 = (/* unused pure expression or super */ null && (2n ** 63n));
12320
- const math_consts_MIN_VALUE = (/* unused pure expression or super */ null && (-(2 ** 31)));
12321
- const math_consts_MAX_SHIFT_U32 = 32;
12322
- const math_consts_MAX_SHIFT_U64 = 64n;
12323
-
12324
12324
  ;// CONCATENATED MODULE: ./packages/jam/state/recent-blocks.ts
12325
12325
 
12326
12326
 
@@ -13300,7 +13300,6 @@ class UpdateStorage {
13300
13300
 
13301
13301
 
13302
13302
 
13303
-
13304
13303
 
13305
13304
 
13306
13305
  var UpdateError;
@@ -13733,7 +13732,7 @@ class InMemoryState extends WithDebug {
13733
13732
  manager: tryAsServiceId(0),
13734
13733
  assigners: tryAsPerCore(new Array(spec.coresCount).fill(tryAsServiceId(0)), spec),
13735
13734
  delegator: tryAsServiceId(0),
13736
- registrar: tryAsServiceId(math_consts_MAX_VALUE),
13735
+ registrar: tryAsServiceId(numbers_MAX_VALUE_U32),
13737
13736
  autoAccumulateServices: new Map(),
13738
13737
  }),
13739
13738
  accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
@@ -17893,22 +17892,22 @@ class memory_builder_MemoryBuilder {
17893
17892
  * Overflowing addition for two-complement representation of 32-bit signed numbers.
17894
17893
  */
17895
17894
  function math_utils_addWithOverflowU32(a, b) {
17896
- if (a > MAX_VALUE - b) {
17895
+ if (a > MAX_VALUE_U32 - b) {
17897
17896
  /**
17898
- * MAX_VALUE is equal to 2 ** 32 - 1
17899
- * MAX_VALUE - ( (MAX_VALUE - a) + (MAX_VALUE - b) ) - 1
17900
- * = MAX_VALUE - (2MAX_VALUE - a - b) -1
17901
- * = MAX_VALUE - 2MAX_VALUE + a + b - 1
17902
- * = a + b - MAX_VALUE - 1
17897
+ * MAX_VALUE_U32 is equal to 2 ** 32 - 1
17898
+ * MAX_VALUE_U32 - ( (MAX_VALUE_U32 - a) + (MAX_VALUE_U32 - b) ) - 1
17899
+ * = MAX_VALUE_U32 - (2MAX_VALUE_U32 - a - b) -1
17900
+ * = MAX_VALUE_U32 - 2MAX_VALUE_U32 + a + b - 1
17901
+ * = a + b - MAX_VALUE_U32 - 1
17903
17902
  * = a + b - 2 ** 32
17904
- * but we know that 2MAX_VALUE > a + b > MAX_VALUE so in this case:
17903
+ * but we know that 2MAX_VALUE_U32 > a + b > MAX_VALUE_U32 so in this case:
17905
17904
  * a + b - 2 ** 32 <=> (a + b) % 2 ** 32
17906
- * = (a + b) % (MAX_VALUE + 1)
17905
+ * = (a + b) % (MAX_VALUE_U32 + 1)
17907
17906
  */
17908
- const spaceToMaxA = MAX_VALUE - a;
17909
- const spaceToMaxB = MAX_VALUE - b;
17907
+ const spaceToMaxA = MAX_VALUE_U32 - a;
17908
+ const spaceToMaxB = MAX_VALUE_U32 - b;
17910
17909
  const overflowSum = spaceToMaxA + spaceToMaxB;
17911
- return MAX_VALUE - overflowSum - 1;
17910
+ return MAX_VALUE_U32 - overflowSum - 1;
17912
17911
  }
17913
17912
  return a + b;
17914
17913
  }
@@ -17923,7 +17922,7 @@ function math_utils_addWithOverflowU64(a, b) {
17923
17922
  */
17924
17923
  function math_utils_subU32(a, b) {
17925
17924
  if (b > a) {
17926
- return MAX_VALUE - b + a + 1;
17925
+ return MAX_VALUE_U32 - b + a + 1;
17927
17926
  }
17928
17927
  return a - b;
17929
17928
  }
@@ -18509,7 +18508,7 @@ class math_ops_MathOps {
18509
18508
  if (this.regs.getLowerU32(secondIndex) === 0) {
18510
18509
  this.regs.setU64(resultIndex, 2n ** 64n - 1n);
18511
18510
  }
18512
- else if (this.regs.getLowerI32(secondIndex) === -1 && this.regs.getLowerI32(firstIndex) === MIN_VALUE) {
18511
+ else if (this.regs.getLowerI32(secondIndex) === -1 && this.regs.getLowerI32(firstIndex) === MIN_VALUE_I32) {
18513
18512
  this.regs.setU64(resultIndex, signExtend32To64(this.regs.getLowerU32(firstIndex)));
18514
18513
  }
18515
18514
  else {
@@ -18547,7 +18546,7 @@ class math_ops_MathOps {
18547
18546
  if (this.regs.getLowerU32(secondIndex) === 0) {
18548
18547
  this.regs.setU64(resultIndex, BigInt(this.regs.getLowerI32(firstIndex)));
18549
18548
  }
18550
- else if (this.regs.getLowerI32(secondIndex) === -1 && this.regs.getLowerI32(firstIndex) === MIN_VALUE) {
18549
+ else if (this.regs.getLowerI32(secondIndex) === -1 && this.regs.getLowerI32(firstIndex) === MIN_VALUE_I32) {
18551
18550
  this.regs.setU64(resultIndex, 0n);
18552
18551
  }
18553
18552
  else {