@polkadot/types-codec 9.5.1 → 9.6.1

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 (152) hide show
  1. package/abstract/Array.js +15 -44
  2. package/abstract/Base.js +12 -28
  3. package/abstract/BigInt.js +3 -2
  4. package/abstract/Int.js +25 -52
  5. package/abstract/index.js +1 -0
  6. package/base/Compact.js +21 -45
  7. package/base/DoNotConstruct.js +3 -19
  8. package/base/Enum.js +37 -88
  9. package/base/Int.js +2 -5
  10. package/base/Null.js +12 -23
  11. package/base/Option.js +23 -59
  12. package/base/Result.js +8 -19
  13. package/base/Tuple.js +12 -29
  14. package/base/UInt.js +2 -4
  15. package/base/Vec.js +7 -25
  16. package/base/VecAny.js +2 -2
  17. package/base/VecFixed.js +8 -20
  18. package/base/index.js +1 -0
  19. package/bundle.js +1 -0
  20. package/cjs/abstract/Array.js +13 -47
  21. package/cjs/abstract/Base.js +12 -30
  22. package/cjs/abstract/BigInt.js +1 -4
  23. package/cjs/abstract/Int.js +25 -55
  24. package/cjs/abstract/index.js +0 -3
  25. package/cjs/base/Compact.js +21 -48
  26. package/cjs/base/DoNotConstruct.js +3 -21
  27. package/cjs/base/Enum.js +34 -92
  28. package/cjs/base/Int.js +0 -7
  29. package/cjs/base/Null.js +10 -25
  30. package/cjs/base/Option.js +23 -63
  31. package/cjs/base/Result.js +6 -21
  32. package/cjs/base/Tuple.js +12 -33
  33. package/cjs/base/UInt.js +0 -6
  34. package/cjs/base/Vec.js +7 -31
  35. package/cjs/base/VecAny.js +0 -4
  36. package/cjs/base/VecFixed.js +8 -25
  37. package/cjs/base/index.js +0 -12
  38. package/cjs/bundle.js +0 -13
  39. package/cjs/detectPackage.js +2 -4
  40. package/cjs/extended/BTreeMap.js +1 -5
  41. package/cjs/extended/BTreeSet.js +17 -57
  42. package/cjs/extended/BitVec.js +11 -25
  43. package/cjs/extended/Bytes.js +9 -20
  44. package/cjs/extended/HashMap.js +1 -5
  45. package/cjs/extended/Linkage.js +5 -20
  46. package/cjs/extended/Map.js +16 -62
  47. package/cjs/extended/OptionBool.js +8 -21
  48. package/cjs/extended/Range.js +3 -13
  49. package/cjs/extended/RangeInclusive.js +1 -6
  50. package/cjs/extended/Type.js +1 -7
  51. package/cjs/extended/U8aFixed.js +2 -15
  52. package/cjs/extended/WrapperKeepOpaque.js +8 -28
  53. package/cjs/extended/WrapperOpaque.js +2 -8
  54. package/cjs/extended/index.js +0 -14
  55. package/cjs/index.js +0 -3
  56. package/cjs/native/Bool.js +14 -32
  57. package/cjs/native/Date.js +18 -40
  58. package/cjs/native/Float.js +11 -29
  59. package/cjs/native/Json.js +14 -33
  60. package/cjs/native/Raw.js +18 -41
  61. package/cjs/native/Set.js +21 -67
  62. package/cjs/native/Struct.data.js +1 -0
  63. package/cjs/native/Struct.js +33 -83
  64. package/cjs/native/Text.js +20 -44
  65. package/cjs/native/index.js +0 -8
  66. package/cjs/packageInfo.js +3 -1
  67. package/cjs/primitive/F32.js +0 -3
  68. package/cjs/primitive/F64.js +0 -3
  69. package/cjs/primitive/I128.js +0 -3
  70. package/cjs/primitive/I16.js +0 -3
  71. package/cjs/primitive/I256.js +0 -3
  72. package/cjs/primitive/I32.js +0 -3
  73. package/cjs/primitive/I64.js +0 -3
  74. package/cjs/primitive/I8.js +0 -3
  75. package/cjs/primitive/U128.js +0 -3
  76. package/cjs/primitive/U16.js +0 -3
  77. package/cjs/primitive/U256.js +0 -3
  78. package/cjs/primitive/U32.js +0 -3
  79. package/cjs/primitive/U64.js +0 -3
  80. package/cjs/primitive/U8.js +0 -3
  81. package/cjs/primitive/USize.js +0 -4
  82. package/cjs/primitive/index.js +0 -15
  83. package/cjs/types/index.js +0 -8
  84. package/cjs/utils/compareArray.js +1 -4
  85. package/cjs/utils/compareMap.js +4 -9
  86. package/cjs/utils/compareSet.js +4 -6
  87. package/cjs/utils/decodeU8a.js +7 -17
  88. package/cjs/utils/index.js +0 -9
  89. package/cjs/utils/mapToTypeMap.js +0 -4
  90. package/cjs/utils/sanitize.js +66 -71
  91. package/cjs/utils/sortValues.js +5 -18
  92. package/cjs/utils/typeToConstructor.js +1 -2
  93. package/cjs/utils/typesToMap.js +1 -3
  94. package/cjs/utils/util.js +1 -2
  95. package/detectOther.js +2 -0
  96. package/detectPackage.js +2 -0
  97. package/extended/BTreeMap.js +1 -2
  98. package/extended/BTreeSet.js +17 -53
  99. package/extended/BitVec.js +13 -22
  100. package/extended/Bytes.js +11 -17
  101. package/extended/HashMap.js +1 -2
  102. package/extended/Linkage.js +5 -12
  103. package/extended/Map.js +16 -54
  104. package/extended/OptionBool.js +8 -17
  105. package/extended/Range.js +4 -11
  106. package/extended/RangeInclusive.js +1 -3
  107. package/extended/Type.js +3 -4
  108. package/extended/U8aFixed.js +4 -12
  109. package/extended/WrapperKeepOpaque.js +8 -23
  110. package/extended/WrapperOpaque.js +2 -5
  111. package/extended/index.js +1 -0
  112. package/index.js +1 -0
  113. package/native/Bool.js +16 -30
  114. package/native/Date.js +18 -37
  115. package/native/Float.js +12 -27
  116. package/native/Json.js +16 -30
  117. package/native/Raw.js +20 -39
  118. package/native/Set.js +21 -63
  119. package/native/Struct.data.js +1 -0
  120. package/native/Struct.js +33 -80
  121. package/native/Text.js +20 -40
  122. package/native/index.js +1 -0
  123. package/package.json +4 -4
  124. package/packageInfo.js +3 -1
  125. package/primitive/F32.js +2 -1
  126. package/primitive/F64.js +2 -1
  127. package/primitive/I128.js +2 -1
  128. package/primitive/I16.js +2 -1
  129. package/primitive/I256.js +2 -1
  130. package/primitive/I32.js +2 -1
  131. package/primitive/I64.js +2 -1
  132. package/primitive/I8.js +2 -1
  133. package/primitive/U128.js +2 -1
  134. package/primitive/U16.js +2 -1
  135. package/primitive/U256.js +2 -1
  136. package/primitive/U32.js +2 -1
  137. package/primitive/U64.js +2 -1
  138. package/primitive/U8.js +2 -1
  139. package/primitive/USize.js +2 -2
  140. package/primitive/index.js +1 -0
  141. package/types/index.js +1 -0
  142. package/utils/compareArray.js +4 -3
  143. package/utils/compareMap.js +4 -7
  144. package/utils/compareSet.js +4 -5
  145. package/utils/decodeU8a.js +9 -14
  146. package/utils/index.js +1 -0
  147. package/utils/mapToTypeMap.js +2 -3
  148. package/utils/sanitize.js +66 -60
  149. package/utils/sortValues.js +6 -15
  150. package/utils/typeToConstructor.js +1 -0
  151. package/utils/typesToMap.js +1 -2
  152. package/utils/util.js +1 -0
@@ -4,20 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.WrapperKeepOpaque = void 0;
7
-
8
7
  var _util = require("@polkadot/util");
9
-
10
8
  var _Raw = require("../native/Raw");
11
-
12
9
  var _utils = require("../utils");
13
-
14
10
  var _Bytes = require("./Bytes");
15
-
16
11
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
17
12
  // SPDX-License-Identifier: Apache-2.0
13
+
18
14
  function decodeRaw(registry, typeName, value) {
19
15
  const Type = (0, _utils.typeToConstructor)(registry, typeName);
20
-
21
16
  if ((0, _util.isU8a)(value) || (0, _util.isHex)(value)) {
22
17
  try {
23
18
  const [, u8a] = (0, _util.isHex)(value) ? [0, (0, _util.u8aToU8a)(value)] : value instanceof _Raw.Raw ? [0, value.subarray()] : (0, _util.compactStripLength)(value);
@@ -26,16 +21,13 @@ function decodeRaw(registry, typeName, value) {
26
21
  return [Type, null, value];
27
22
  }
28
23
  }
29
-
30
24
  const instance = new Type(registry, value);
31
25
  return [Type, instance, (0, _util.compactAddLength)(instance.toU8a())];
32
26
  }
33
-
34
27
  class WrapperKeepOpaque extends _Bytes.Bytes {
35
28
  #Type;
36
29
  #decoded;
37
30
  #opaqueName;
38
-
39
31
  constructor(registry, typeName, value) {
40
32
  let {
41
33
  opaqueName = 'WrapperKeepOpaque'
@@ -46,28 +38,24 @@ class WrapperKeepOpaque extends _Bytes.Bytes {
46
38
  this.#decoded = decoded;
47
39
  this.#opaqueName = opaqueName;
48
40
  }
49
-
50
41
  static with(Type) {
51
42
  return class extends WrapperKeepOpaque {
52
43
  constructor(registry, value) {
53
44
  super(registry, Type, value);
54
45
  }
55
-
56
46
  };
57
47
  }
48
+
58
49
  /**
59
50
  * @description Checks if the wrapper is decodable
60
51
  */
61
-
62
-
63
52
  get isDecoded() {
64
53
  return !!this.#decoded;
65
54
  }
55
+
66
56
  /**
67
57
  * @description Returns a breakdown of the hex encoding for this Codec
68
58
  */
69
-
70
-
71
59
  inspect() {
72
60
  return this.#decoded ? {
73
61
  inner: [this.#decoded.inspect()],
@@ -76,51 +64,43 @@ class WrapperKeepOpaque extends _Bytes.Bytes {
76
64
  outer: [(0, _util.compactToU8a)(this.length), this.toU8a(true)]
77
65
  };
78
66
  }
67
+
79
68
  /**
80
69
  * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
81
70
  */
82
-
83
-
84
71
  toHuman(isExtended) {
85
72
  return this.#decoded ? this.#decoded.toHuman(isExtended) : super.toHuman();
86
73
  }
74
+
87
75
  /**
88
76
  * @description Converts the value in a best-fit primitive form
89
77
  */
90
-
91
-
92
78
  toPrimitive() {
93
79
  return this.#decoded ? this.#decoded.toPrimitive() : super.toPrimitive();
94
80
  }
81
+
95
82
  /**
96
83
  * @description Returns the base runtime type name for this instance
97
84
  */
98
-
99
-
100
85
  toRawType() {
101
86
  return `${this.#opaqueName}<${this.registry.getClassName(this.#Type) || (this.#decoded ? this.#decoded.toRawType() : new this.#Type(this.registry).toRawType())}>`;
102
87
  }
88
+
103
89
  /**
104
90
  * @description Converts the Object to to a string (either decoded or bytes)
105
91
  */
106
-
107
-
108
92
  toString() {
109
93
  return this.#decoded ? this.#decoded.toString() : super.toString();
110
94
  }
95
+
111
96
  /**
112
97
  * @description Returns the decoded that the WrapperKeepOpaque represents (if available), throws if non-decodable
113
98
  */
114
-
115
-
116
99
  unwrap() {
117
100
  if (!this.#decoded) {
118
101
  throw new Error(`${this.#opaqueName}: unwrapping an undecodable value`);
119
102
  }
120
-
121
103
  return this.#decoded;
122
104
  }
123
-
124
105
  }
125
-
126
106
  exports.WrapperKeepOpaque = WrapperKeepOpaque;
@@ -4,35 +4,29 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.WrapperOpaque = void 0;
7
-
8
7
  var _WrapperKeepOpaque = require("./WrapperKeepOpaque");
9
-
10
8
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
11
9
  // SPDX-License-Identifier: Apache-2.0
10
+
12
11
  class WrapperOpaque extends _WrapperKeepOpaque.WrapperKeepOpaque {
13
12
  constructor(registry, typeName, value) {
14
13
  super(registry, typeName, value, {
15
14
  opaqueName: 'WrapperOpaque'
16
15
  });
17
16
  }
18
-
19
17
  static with(Type) {
20
18
  return class extends WrapperOpaque {
21
19
  constructor(registry, value) {
22
20
  super(registry, Type, value);
23
21
  }
24
-
25
22
  };
26
23
  }
24
+
27
25
  /**
28
26
  * @description The inner value for this wrapper, in all cases it _should_ be decodable (unlike KeepOpaque)
29
27
  */
30
-
31
-
32
28
  get inner() {
33
29
  return this.unwrap();
34
30
  }
35
-
36
31
  }
37
-
38
32
  exports.WrapperOpaque = WrapperOpaque;
@@ -93,31 +93,17 @@ Object.defineProperty(exports, "WrapperOpaque", {
93
93
  return _WrapperOpaque.WrapperOpaque;
94
94
  }
95
95
  });
96
-
97
96
  var _BitVec = require("./BitVec");
98
-
99
97
  var _BTreeMap = require("./BTreeMap");
100
-
101
98
  var _BTreeSet = require("./BTreeSet");
102
-
103
99
  var _Bytes = require("./Bytes");
104
-
105
100
  var _HashMap = require("./HashMap");
106
-
107
101
  var _Linkage = require("./Linkage");
108
-
109
102
  var _Map = require("./Map");
110
-
111
103
  var _OptionBool = require("./OptionBool");
112
-
113
104
  var _Range = require("./Range");
114
-
115
105
  var _RangeInclusive = require("./RangeInclusive");
116
-
117
106
  var _Type = require("./Type");
118
-
119
107
  var _U8aFixed = require("./U8aFixed");
120
-
121
108
  var _WrapperKeepOpaque = require("./WrapperKeepOpaque");
122
-
123
109
  var _WrapperOpaque = require("./WrapperOpaque");
package/cjs/index.js CHANGED
@@ -3,11 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
-
7
6
  require("./detectPackage");
8
-
9
7
  var _bundle = require("./bundle");
10
-
11
8
  Object.keys(_bundle).forEach(function (key) {
12
9
  if (key === "default" || key === "__esModule") return;
13
10
  if (key in exports && exports[key] === _bundle[key]) return;
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.bool = void 0;
7
-
8
7
  var _util = require("@polkadot/util");
9
-
10
8
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
11
9
  // SPDX-License-Identifier: Apache-2.0
12
10
 
@@ -22,123 +20,107 @@ class bool extends Boolean {
22
20
  super((0, _util.isU8a)(value) ? value[0] === 1 : value instanceof Boolean ? value.valueOf() : !!value);
23
21
  this.registry = registry;
24
22
  }
23
+
25
24
  /**
26
25
  * @description The length of the value when encoded as a Uint8Array
27
26
  */
28
-
29
-
30
27
  get encodedLength() {
31
28
  return 1;
32
29
  }
30
+
33
31
  /**
34
32
  * @description returns a hash of the contents
35
33
  */
36
-
37
-
38
34
  get hash() {
39
35
  return this.registry.hash(this.toU8a());
40
36
  }
37
+
41
38
  /**
42
39
  * @description Checks if the value is an empty value (true when it wraps false/default)
43
40
  */
44
-
45
-
46
41
  get isEmpty() {
47
42
  return this.isFalse;
48
43
  }
44
+
49
45
  /**
50
46
  * @description Checks if the value is an empty value (always false)
51
47
  */
52
-
53
-
54
48
  get isFalse() {
55
49
  return !this.isTrue;
56
50
  }
51
+
57
52
  /**
58
53
  * @description Checks if the value is an empty value (always false)
59
54
  */
60
-
61
-
62
55
  get isTrue() {
63
56
  return this.valueOf();
64
57
  }
58
+
65
59
  /**
66
60
  * @description Compares the value of the input to see if there is a match
67
61
  */
68
-
69
-
70
62
  eq(other) {
71
63
  return this.valueOf() === (other instanceof Boolean ? other.valueOf() : other);
72
64
  }
65
+
73
66
  /**
74
67
  * @description Returns a breakdown of the hex encoding for this Codec
75
68
  */
76
-
77
-
78
69
  inspect() {
79
70
  return {
80
71
  outer: [this.toU8a()]
81
72
  };
82
73
  }
74
+
83
75
  /**
84
76
  * @description Returns a hex string representation of the value
85
77
  */
86
-
87
-
88
78
  toHex() {
89
79
  return (0, _util.u8aToHex)(this.toU8a());
90
80
  }
81
+
91
82
  /**
92
83
  * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
93
84
  */
94
-
95
-
96
85
  toHuman() {
97
86
  return this.toJSON();
98
87
  }
88
+
99
89
  /**
100
90
  * @description Converts the Object to JSON, typically used for RPC transfers
101
91
  */
102
-
103
-
104
92
  toJSON() {
105
93
  return this.valueOf();
106
94
  }
95
+
107
96
  /**
108
97
  * @description Converts the value in a best-fit primitive form
109
98
  */
110
-
111
-
112
99
  toPrimitive() {
113
100
  return this.toJSON();
114
101
  }
102
+
115
103
  /**
116
104
  * @description Returns the base runtime type name for this instance
117
105
  */
118
-
119
-
120
106
  toRawType() {
121
107
  return 'bool';
122
108
  }
109
+
123
110
  /**
124
111
  * @description Returns the string representation of the value
125
112
  */
126
-
127
-
128
113
  toString() {
129
114
  return this.toJSON().toString();
130
115
  }
116
+
131
117
  /**
132
118
  * @description Encodes the value as a Uint8Array as per the SCALE specifications
133
119
  * @param isBare true when the value has none of the type-specific prefixes (internal)
134
120
  */
135
121
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
136
-
137
-
138
122
  toU8a(isBare) {
139
123
  return new Uint8Array([this.valueOf() ? 1 : 0]);
140
124
  }
141
-
142
125
  }
143
-
144
126
  exports.bool = bool;
@@ -4,17 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.CodecDate = void 0;
7
-
8
7
  var _util = require("@polkadot/util");
9
-
10
8
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
11
9
  // SPDX-License-Identifier: Apache-2.0
10
+
12
11
  const BITLENGTH = 64;
13
12
  const U8A_OPTS = {
14
13
  bitLength: BITLENGTH,
15
14
  isLe: true
16
15
  };
17
-
18
16
  function decodeDate(value) {
19
17
  if ((0, _util.isU8a)(value)) {
20
18
  value = (0, _util.u8aToBn)(value.subarray(0, BITLENGTH / 8));
@@ -23,9 +21,9 @@ function decodeDate(value) {
23
21
  } else if ((0, _util.isString)(value)) {
24
22
  value = new _util.BN(value.toString(), 10, 'le');
25
23
  }
26
-
27
24
  return new Date((0, _util.bnToBn)(value).toNumber() * 1000);
28
25
  }
26
+
29
27
  /**
30
28
  * @name Date
31
29
  * @description
@@ -36,85 +34,74 @@ function decodeDate(value) {
36
34
  * and has all the methods available that are applicable to any `Date`
37
35
  * @noInheritDoc
38
36
  */
39
-
40
-
41
37
  class CodecDate extends Date {
42
38
  constructor(registry) {
43
39
  let value = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
44
40
  super(decodeDate(value));
45
41
  this.registry = registry;
46
42
  }
43
+
47
44
  /**
48
45
  * @description The length of the value when encoded as a Uint8Array
49
46
  */
50
-
51
-
52
47
  get encodedLength() {
53
48
  return BITLENGTH / 8;
54
49
  }
50
+
55
51
  /**
56
52
  * @description returns a hash of the contents
57
53
  */
58
-
59
-
60
54
  get hash() {
61
55
  return this.registry.hash(this.toU8a());
62
56
  }
57
+
63
58
  /**
64
59
  * @description Checks if the value is an empty value
65
60
  */
66
-
67
-
68
61
  get isEmpty() {
69
62
  return this.getTime() === 0;
70
63
  }
64
+
71
65
  /**
72
66
  * @description Returns the number of bits in the value
73
67
  */
74
-
75
-
76
68
  bitLength() {
77
69
  return BITLENGTH;
78
70
  }
71
+
79
72
  /**
80
73
  * @description Compares the value of the input to see if there is a match
81
74
  */
82
-
83
-
84
75
  eq(other) {
85
76
  return decodeDate(other).getTime() === this.getTime();
86
77
  }
78
+
87
79
  /**
88
80
  * @description Returns a breakdown of the hex encoding for this Codec
89
81
  */
90
-
91
-
92
82
  inspect() {
93
83
  return {
94
84
  outer: [this.toU8a()]
95
85
  };
96
86
  }
87
+
97
88
  /**
98
89
  * @description Returns a BigInt representation of the number
99
90
  */
100
-
101
-
102
91
  toBigInt() {
103
92
  return BigInt(this.toNumber());
104
93
  }
94
+
105
95
  /**
106
96
  * @description Returns the BN representation of the timestamp
107
97
  */
108
-
109
-
110
98
  toBn() {
111
99
  return new _util.BN(this.toNumber());
112
100
  }
101
+
113
102
  /**
114
103
  * @description Returns a hex string representation of the value
115
104
  */
116
-
117
-
118
105
  toHex() {
119
106
  let isLe = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
120
107
  return (0, _util.bnToHex)(this.toBn(), {
@@ -123,68 +110,59 @@ class CodecDate extends Date {
123
110
  isNegative: false
124
111
  });
125
112
  }
113
+
126
114
  /**
127
115
  * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
128
116
  */
129
-
130
-
131
117
  toHuman() {
132
118
  return this.toISOString();
133
119
  }
120
+
134
121
  /**
135
122
  * @description Converts the Object to JSON, typically used for RPC transfers
136
123
  */
137
-
138
-
139
124
  toJSON() {
140
125
  // FIXME Return type should be number, but conflicts with Date.toJSON()
141
126
  // which returns string
142
127
  return this.toNumber();
143
128
  }
129
+
144
130
  /**
145
131
  * @description Returns the number representation for the timestamp
146
132
  */
147
-
148
-
149
133
  toNumber() {
150
134
  return Math.ceil(this.getTime() / 1000);
151
135
  }
136
+
152
137
  /**
153
138
  * @description Converts the value in a best-fit primitive form
154
139
  */
155
-
156
-
157
140
  toPrimitive() {
158
141
  return this.toNumber();
159
142
  }
143
+
160
144
  /**
161
145
  * @description Returns the base runtime type name for this instance
162
146
  */
163
-
164
-
165
147
  toRawType() {
166
148
  return 'Moment';
167
149
  }
150
+
168
151
  /**
169
152
  * @description Returns the string representation of the value
170
153
  */
171
-
172
-
173
154
  toString() {
174
155
  // only included here since we do not inherit docs
175
156
  return super.toString();
176
157
  }
158
+
177
159
  /**
178
160
  * @description Encodes the value as a Uint8Array as per the SCALE specifications
179
161
  * @param isBare true when the value has none of the type-specific prefixes (internal)
180
162
  */
181
163
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
182
-
183
-
184
164
  toU8a(isBare) {
185
165
  return (0, _util.bnToU8a)(this.toNumber(), U8A_OPTS);
186
166
  }
187
-
188
167
  }
189
-
190
168
  exports.CodecDate = CodecDate;
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.Float = void 0;
7
-
8
7
  var _util = require("@polkadot/util");
9
-
10
8
  // Copyright 2017-2022 @polkadot/types-codec authors & contributors
11
9
  // SPDX-License-Identifier: Apache-2.0
12
10
 
@@ -20,7 +18,6 @@ var _util = require("@polkadot/util");
20
18
  */
21
19
  class Float extends Number {
22
20
  #bitLength;
23
-
24
21
  constructor(registry, value) {
25
22
  let {
26
23
  bitLength = 32
@@ -33,7 +30,6 @@ class Float extends Number {
33
30
  this.initialU8aLength = this.encodedLength;
34
31
  this.registry = registry;
35
32
  }
36
-
37
33
  static with(bitLength) {
38
34
  return class extends Float {
39
35
  constructor(registry, value) {
@@ -41,104 +37,90 @@ class Float extends Number {
41
37
  bitLength
42
38
  });
43
39
  }
44
-
45
40
  };
46
41
  }
42
+
47
43
  /**
48
44
  * @description returns a hash of the contents
49
45
  */
50
-
51
-
52
46
  get hash() {
53
47
  return this.registry.hash(this.toU8a());
54
48
  }
49
+
55
50
  /**
56
51
  * @description Returns true if the type wraps an empty/default all-0 value
57
52
  */
58
-
59
-
60
53
  get isEmpty() {
61
54
  return this.valueOf() === 0;
62
55
  }
56
+
63
57
  /**
64
58
  * @description Compares the value of the input to see if there is a match
65
59
  */
66
-
67
-
68
60
  eq(other) {
69
61
  return this.valueOf() === Number(other);
70
62
  }
63
+
71
64
  /**
72
65
  * @description Returns a breakdown of the hex encoding for this Codec
73
66
  */
74
-
75
-
76
67
  inspect() {
77
68
  return {
78
69
  outer: [this.toU8a()]
79
70
  };
80
71
  }
72
+
81
73
  /**
82
74
  * @description Returns a hex string representation of the value
83
75
  */
84
-
85
-
86
76
  toHex() {
87
77
  return (0, _util.u8aToHex)(this.toU8a());
88
78
  }
79
+
89
80
  /**
90
81
  * @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
91
82
  */
92
-
93
-
94
83
  toHuman() {
95
84
  return this.toString();
96
85
  }
86
+
97
87
  /**
98
88
  * @description Converts the Object to JSON, typically used for RPC transfers
99
89
  */
100
-
101
-
102
90
  toJSON() {
103
91
  // Not sure if this is actually a hex or a string value
104
92
  // (would need to check against RPCs to see the result here)
105
93
  return this.toHex();
106
94
  }
95
+
107
96
  /**
108
97
  * @description Returns the number representation (Same as valueOf)
109
98
  */
110
-
111
-
112
99
  toNumber() {
113
100
  return this.valueOf();
114
101
  }
102
+
115
103
  /**
116
104
  * @description Converts the value in a best-fit primitive form
117
105
  */
118
-
119
-
120
106
  toPrimitive() {
121
107
  return this.toNumber();
122
108
  }
109
+
123
110
  /**
124
111
  * @description Returns the base runtime type name for this instance
125
112
  */
126
-
127
-
128
113
  toRawType() {
129
114
  return `f${this.#bitLength}`;
130
115
  }
116
+
131
117
  /**
132
118
  * @description Encodes the value as a Uint8Array as per the SCALE specifications
133
119
  */
134
-
135
-
136
120
  toU8a() {
137
121
  return (0, _util.floatToU8a)(this, {
138
122
  bitLength: this.#bitLength
139
123
  });
140
124
  }
141
-
142
125
  }
143
-
144
126
  exports.Float = Float;