@polkadot/types-codec 6.12.2-2
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/abstract/AbstractArray.cjs +208 -0
- package/abstract/AbstractArray.d.ts +84 -0
- package/abstract/AbstractArray.js +197 -0
- package/abstract/AbstractInt.cjs +254 -0
- package/abstract/AbstractInt.d.ts +75 -0
- package/abstract/AbstractInt.js +231 -0
- package/abstract/index.cjs +21 -0
- package/abstract/index.d.ts +2 -0
- package/abstract/index.js +4 -0
- package/base/Base.cjs +109 -0
- package/base/Base.d.ts +54 -0
- package/base/Base.js +100 -0
- package/base/Compact.cjs +201 -0
- package/base/Compact.d.ts +83 -0
- package/base/Compact.js +186 -0
- package/base/DoNotConstruct.cjs +101 -0
- package/base/DoNotConstruct.d.ts +33 -0
- package/base/DoNotConstruct.js +88 -0
- package/base/Enum.cjs +437 -0
- package/base/Enum.d.ts +101 -0
- package/base/Enum.js +413 -0
- package/base/Int.cjs +45 -0
- package/base/Int.d.ts +16 -0
- package/base/Int.js +33 -0
- package/base/Null.cjs +111 -0
- package/base/Null.d.ts +54 -0
- package/base/Null.js +101 -0
- package/base/Option.cjs +256 -0
- package/base/Option.d.ts +88 -0
- package/base/Option.js +240 -0
- package/base/Result.cjs +109 -0
- package/base/Result.d.ts +46 -0
- package/base/Result.js +98 -0
- package/base/Tuple.cjs +132 -0
- package/base/Tuple.d.ts +39 -0
- package/base/Tuple.js +116 -0
- package/base/UInt.cjs +39 -0
- package/base/UInt.d.ts +15 -0
- package/base/UInt.js +29 -0
- package/base/Vec.cjs +126 -0
- package/base/Vec.d.ts +28 -0
- package/base/Vec.js +104 -0
- package/base/VecAny.cjs +31 -0
- package/base/VecAny.d.ts +15 -0
- package/base/VecAny.js +21 -0
- package/base/VecFixed.cjs +111 -0
- package/base/VecFixed.d.ts +26 -0
- package/base/VecFixed.js +93 -0
- package/base/index.cjs +109 -0
- package/base/index.d.ts +13 -0
- package/base/index.js +15 -0
- package/bundle.cjs +100 -0
- package/bundle.d.ts +7 -0
- package/bundle.js +9 -0
- package/detectPackage.cjs +9 -0
- package/detectPackage.d.ts +1 -0
- package/detectPackage.js +5 -0
- package/extended/BTreeMap.cjs +24 -0
- package/extended/BTreeMap.d.ts +5 -0
- package/extended/BTreeMap.js +14 -0
- package/extended/BTreeSet.cjs +227 -0
- package/extended/BTreeSet.d.ts +55 -0
- package/extended/BTreeSet.js +212 -0
- package/extended/BitVec.cjs +97 -0
- package/extended/BitVec.d.ts +26 -0
- package/extended/BitVec.js +82 -0
- package/extended/Bytes.cjs +86 -0
- package/extended/Bytes.d.ts +25 -0
- package/extended/Bytes.js +75 -0
- package/extended/HashMap.cjs +24 -0
- package/extended/HashMap.d.ts +5 -0
- package/extended/HashMap.js +14 -0
- package/extended/Linkage.cjs +89 -0
- package/extended/Linkage.d.ts +31 -0
- package/extended/Linkage.js +71 -0
- package/extended/Map.cjs +244 -0
- package/extended/Map.d.ts +50 -0
- package/extended/Map.js +225 -0
- package/extended/Range.cjs +92 -0
- package/extended/Range.d.ts +30 -0
- package/extended/Range.js +75 -0
- package/extended/Type.cjs +39 -0
- package/extended/Type.d.ts +16 -0
- package/extended/Type.js +27 -0
- package/extended/U8aFixed.cjs +66 -0
- package/extended/U8aFixed.d.ts +16 -0
- package/extended/U8aFixed.js +53 -0
- package/extended/WrapperOpaque.cjs +68 -0
- package/extended/WrapperOpaque.d.ts +18 -0
- package/extended/WrapperOpaque.js +57 -0
- package/extended/index.cjs +105 -0
- package/extended/index.d.ts +11 -0
- package/extended/index.js +13 -0
- package/index.cjs +20 -0
- package/index.d.ts +2 -0
- package/index.js +4 -0
- package/native/Bool.cjs +141 -0
- package/native/Bool.d.ts +62 -0
- package/native/Bool.js +130 -0
- package/native/Date.cjs +170 -0
- package/native/Date.d.ts +76 -0
- package/native/Date.js +158 -0
- package/native/Json.cjs +133 -0
- package/native/Json.d.ts +55 -0
- package/native/Json.js +117 -0
- package/native/Raw.cjs +192 -0
- package/native/Raw.d.ts +90 -0
- package/native/Raw.js +182 -0
- package/native/Set.cjs +268 -0
- package/native/Set.d.ts +76 -0
- package/native/Set.js +251 -0
- package/native/Struct.cjs +289 -0
- package/native/Struct.d.ts +92 -0
- package/native/Struct.js +273 -0
- package/native/Text.cjs +193 -0
- package/native/Text.d.ts +71 -0
- package/native/Text.js +178 -0
- package/native/index.cjs +79 -0
- package/native/index.d.ts +7 -0
- package/native/index.js +9 -0
- package/package.json +387 -0
- package/packageInfo.cjs +14 -0
- package/packageInfo.d.ts +4 -0
- package/packageInfo.js +7 -0
- package/primitive/I128.cjs +26 -0
- package/primitive/I128.d.ts +11 -0
- package/primitive/I128.js +16 -0
- package/primitive/I16.cjs +26 -0
- package/primitive/I16.d.ts +11 -0
- package/primitive/I16.js +16 -0
- package/primitive/I256.cjs +26 -0
- package/primitive/I256.d.ts +11 -0
- package/primitive/I256.js +16 -0
- package/primitive/I32.cjs +26 -0
- package/primitive/I32.d.ts +11 -0
- package/primitive/I32.js +16 -0
- package/primitive/I64.cjs +26 -0
- package/primitive/I64.d.ts +11 -0
- package/primitive/I64.js +16 -0
- package/primitive/I8.cjs +26 -0
- package/primitive/I8.d.ts +11 -0
- package/primitive/I8.js +16 -0
- package/primitive/U128.cjs +26 -0
- package/primitive/U128.d.ts +11 -0
- package/primitive/U128.js +16 -0
- package/primitive/U16.cjs +26 -0
- package/primitive/U16.d.ts +11 -0
- package/primitive/U16.js +16 -0
- package/primitive/U256.cjs +26 -0
- package/primitive/U256.d.ts +11 -0
- package/primitive/U256.js +16 -0
- package/primitive/U32.cjs +26 -0
- package/primitive/U32.d.ts +11 -0
- package/primitive/U32.js +16 -0
- package/primitive/U64.cjs +26 -0
- package/primitive/U64.d.ts +11 -0
- package/primitive/U64.js +16 -0
- package/primitive/U8.cjs +26 -0
- package/primitive/U8.d.ts +11 -0
- package/primitive/U8.js +16 -0
- package/primitive/USize.cjs +28 -0
- package/primitive/USize.d.ts +12 -0
- package/primitive/USize.js +18 -0
- package/primitive/index.cjs +187 -0
- package/primitive/index.d.ts +13 -0
- package/primitive/index.js +15 -0
- package/types/codec.cjs +1 -0
- package/types/codec.d.ts +77 -0
- package/types/codec.js +1 -0
- package/types/helpers.cjs +1 -0
- package/types/helpers.d.ts +14 -0
- package/types/helpers.js +1 -0
- package/types/index.cjs +57 -0
- package/types/index.d.ts +4 -0
- package/types/index.js +6 -0
- package/types/interfaces.cjs +1 -0
- package/types/interfaces.d.ts +68 -0
- package/types/interfaces.js +1 -0
- package/types/registry.cjs +1 -0
- package/types/registry.d.ts +44 -0
- package/types/registry.js +1 -0
- package/utils/compareArray.cjs +22 -0
- package/utils/compareArray.d.ts +1 -0
- package/utils/compareArray.js +13 -0
- package/utils/compareMap.cjs +39 -0
- package/utils/compareMap.d.ts +1 -0
- package/utils/compareMap.js +31 -0
- package/utils/compareSet.cjs +29 -0
- package/utils/compareSet.d.ts +1 -0
- package/utils/compareSet.js +22 -0
- package/utils/decodeU8a.cjs +69 -0
- package/utils/decodeU8a.d.ts +13 -0
- package/utils/decodeU8a.js +60 -0
- package/utils/index.cjs +95 -0
- package/utils/index.d.ts +9 -0
- package/utils/index.js +11 -0
- package/utils/mapToTypeMap.cjs +25 -0
- package/utils/mapToTypeMap.d.ts +5 -0
- package/utils/mapToTypeMap.js +17 -0
- package/utils/sanitize.cjs +242 -0
- package/utils/sanitize.d.ts +16 -0
- package/utils/sanitize.js +215 -0
- package/utils/sortValues.cjs +89 -0
- package/utils/sortValues.d.ts +13 -0
- package/utils/sortValues.js +73 -0
- package/utils/typeToConstructor.cjs +14 -0
- package/utils/typeToConstructor.d.ts +2 -0
- package/utils/typeToConstructor.js +6 -0
- package/utils/typesToMap.cjs +20 -0
- package/utils/typesToMap.d.ts +2 -0
- package/utils/typesToMap.js +13 -0
- package/utils/util.cjs +15 -0
- package/utils/util.d.ts +3 -0
- package/utils/util.js +7 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AbstractArray = void 0;
|
|
7
|
+
|
|
8
|
+
var _util = require("@polkadot/util");
|
|
9
|
+
|
|
10
|
+
var _compareArray = require("../utils/compareArray.cjs");
|
|
11
|
+
|
|
12
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
13
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* @name AbstractArray
|
|
17
|
+
* @description
|
|
18
|
+
* This manages codec arrays. It is an extension to Array, providing
|
|
19
|
+
* specific encoding/decoding on top of the base type.
|
|
20
|
+
* @noInheritDoc
|
|
21
|
+
*/
|
|
22
|
+
class AbstractArray extends Array {
|
|
23
|
+
constructor(registry, values, initialU8aLength) {
|
|
24
|
+
super(values.length); // explicitly set the values here - this removes the need for any extra allocations
|
|
25
|
+
|
|
26
|
+
this.registry = void 0;
|
|
27
|
+
this.createdAtHash = void 0;
|
|
28
|
+
this.initialU8aLength = void 0;
|
|
29
|
+
|
|
30
|
+
for (let i = 0; i < values.length; i++) {
|
|
31
|
+
this[i] = values[i];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
this.registry = registry;
|
|
35
|
+
this.initialU8aLength = initialU8aLength;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
get encodedLength() {
|
|
43
|
+
// We need to loop through all entries since they may have a variable length themselves,
|
|
44
|
+
// e.g. when a Vec or Compact is contained withing, it has a variable length based on data
|
|
45
|
+
let total = (0, _util.compactToU8a)(this.length).length;
|
|
46
|
+
|
|
47
|
+
for (let i = 0; i < this.length; i++) {
|
|
48
|
+
total += this[i].encodedLength;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return total;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* @description returns a hash of the contents
|
|
55
|
+
*/
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
get hash() {
|
|
59
|
+
return this.registry.hash(this.toU8a());
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* @description Checks if the value is an empty value
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
get isEmpty() {
|
|
67
|
+
return this.length === 0;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @description The length of the value
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
get length() {
|
|
75
|
+
// only included here since we ignore inherited docs
|
|
76
|
+
return super.length;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @description Compares the value of the input to see if there is a match
|
|
80
|
+
*/
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
eq(other) {
|
|
84
|
+
return (0, _compareArray.compareArray)(this, other);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* @description Converts the Object to an standard JavaScript Array
|
|
88
|
+
*/
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
toArray() {
|
|
92
|
+
return Array.from(this);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* @description Returns a hex string representation of the value
|
|
96
|
+
*/
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
toHex() {
|
|
100
|
+
return (0, _util.u8aToHex)(this.toU8a());
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
104
|
+
*/
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
toHuman(isExtended) {
|
|
108
|
+
const result = new Array(this.length);
|
|
109
|
+
|
|
110
|
+
for (let i = 0; i < this.length; i++) {
|
|
111
|
+
result[i] = this[i].toHuman(isExtended);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return result;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
toJSON() {
|
|
122
|
+
const result = new Array(this.length);
|
|
123
|
+
|
|
124
|
+
for (let i = 0; i < this.length; i++) {
|
|
125
|
+
result[i] = this[i].toJSON();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return result;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* @description Returns the base runtime type name for this instance
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* @description Returns the string representation of the value
|
|
137
|
+
*/
|
|
138
|
+
toString() {
|
|
139
|
+
const result = new Array(this.length);
|
|
140
|
+
|
|
141
|
+
for (let i = 0; i < this.length; i++) {
|
|
142
|
+
result[i] = this[i].toString();
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return `[${result.join(', ')}]`;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
149
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
toU8a(isBare) {
|
|
154
|
+
const encoded = new Array(this.length);
|
|
155
|
+
|
|
156
|
+
for (let i = 0; i < this.length; i++) {
|
|
157
|
+
encoded[i] = this[i].toU8a(isBare);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return isBare ? (0, _util.u8aConcat)(...encoded) : (0, _util.u8aConcat)((0, _util.compactToU8a)(this.length), ...encoded);
|
|
161
|
+
} // Below are methods that we override. When we do a `new Vec(...).map()`,
|
|
162
|
+
// we want it to return an Array. We only override the methods that return a
|
|
163
|
+
// new instance.
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @description Concatenates two arrays
|
|
167
|
+
*/
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
concat(other) {
|
|
171
|
+
return this.toArray().concat(other instanceof AbstractArray ? other.toArray() : other);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* @description Filters the array with the callback
|
|
175
|
+
*/
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
filter(callbackfn, thisArg) {
|
|
179
|
+
return this.toArray().filter(callbackfn, thisArg);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* @description Maps the array with the callback
|
|
183
|
+
*/
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
map(callbackfn, thisArg) {
|
|
187
|
+
return this.toArray().map(callbackfn, thisArg);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* @description Checks if the array includes a specific value
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
includes(check) {
|
|
195
|
+
return this.some(value => value.eq(check));
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* @description Returns a slice of an array
|
|
199
|
+
*/
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
slice(start, end) {
|
|
203
|
+
return this.toArray().slice(start, end);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
exports.AbstractArray = AbstractArray;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import type { HexString } from '@polkadot/util/types';
|
|
2
|
+
import type { AnyJson, Codec, CodecRegistry, IU8a, IVec } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* @name AbstractArray
|
|
5
|
+
* @description
|
|
6
|
+
* This manages codec arrays. It is an extension to Array, providing
|
|
7
|
+
* specific encoding/decoding on top of the base type.
|
|
8
|
+
* @noInheritDoc
|
|
9
|
+
*/
|
|
10
|
+
export declare abstract class AbstractArray<T extends Codec> extends Array<T> implements IVec<T> {
|
|
11
|
+
readonly registry: CodecRegistry;
|
|
12
|
+
createdAtHash?: IU8a;
|
|
13
|
+
readonly initialU8aLength?: number;
|
|
14
|
+
protected constructor(registry: CodecRegistry, values: T[], initialU8aLength?: number);
|
|
15
|
+
/**
|
|
16
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
17
|
+
*/
|
|
18
|
+
get encodedLength(): number;
|
|
19
|
+
/**
|
|
20
|
+
* @description returns a hash of the contents
|
|
21
|
+
*/
|
|
22
|
+
get hash(): IU8a;
|
|
23
|
+
/**
|
|
24
|
+
* @description Checks if the value is an empty value
|
|
25
|
+
*/
|
|
26
|
+
get isEmpty(): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* @description The length of the value
|
|
29
|
+
*/
|
|
30
|
+
get length(): number;
|
|
31
|
+
/**
|
|
32
|
+
* @description Compares the value of the input to see if there is a match
|
|
33
|
+
*/
|
|
34
|
+
eq(other?: unknown): boolean;
|
|
35
|
+
/**
|
|
36
|
+
* @description Converts the Object to an standard JavaScript Array
|
|
37
|
+
*/
|
|
38
|
+
toArray(): T[];
|
|
39
|
+
/**
|
|
40
|
+
* @description Returns a hex string representation of the value
|
|
41
|
+
*/
|
|
42
|
+
toHex(): HexString;
|
|
43
|
+
/**
|
|
44
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
45
|
+
*/
|
|
46
|
+
toHuman(isExtended?: boolean): AnyJson;
|
|
47
|
+
/**
|
|
48
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
49
|
+
*/
|
|
50
|
+
toJSON(): AnyJson;
|
|
51
|
+
/**
|
|
52
|
+
* @description Returns the base runtime type name for this instance
|
|
53
|
+
*/
|
|
54
|
+
abstract toRawType(): string;
|
|
55
|
+
/**
|
|
56
|
+
* @description Returns the string representation of the value
|
|
57
|
+
*/
|
|
58
|
+
toString(): string;
|
|
59
|
+
/**
|
|
60
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
61
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
62
|
+
*/
|
|
63
|
+
toU8a(isBare?: boolean): Uint8Array;
|
|
64
|
+
/**
|
|
65
|
+
* @description Concatenates two arrays
|
|
66
|
+
*/
|
|
67
|
+
concat(other: T[]): T[];
|
|
68
|
+
/**
|
|
69
|
+
* @description Filters the array with the callback
|
|
70
|
+
*/
|
|
71
|
+
filter(callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: unknown): T[];
|
|
72
|
+
/**
|
|
73
|
+
* @description Maps the array with the callback
|
|
74
|
+
*/
|
|
75
|
+
map<U>(callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: unknown): U[];
|
|
76
|
+
/**
|
|
77
|
+
* @description Checks if the array includes a specific value
|
|
78
|
+
*/
|
|
79
|
+
includes(check: unknown): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* @description Returns a slice of an array
|
|
82
|
+
*/
|
|
83
|
+
slice(start?: number, end?: number): T[];
|
|
84
|
+
}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { compactToU8a, u8aConcat, u8aToHex } from '@polkadot/util';
|
|
4
|
+
import { compareArray } from "../utils/compareArray.js";
|
|
5
|
+
/**
|
|
6
|
+
* @name AbstractArray
|
|
7
|
+
* @description
|
|
8
|
+
* This manages codec arrays. It is an extension to Array, providing
|
|
9
|
+
* specific encoding/decoding on top of the base type.
|
|
10
|
+
* @noInheritDoc
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export class AbstractArray extends Array {
|
|
14
|
+
constructor(registry, values, initialU8aLength) {
|
|
15
|
+
super(values.length); // explicitly set the values here - this removes the need for any extra allocations
|
|
16
|
+
|
|
17
|
+
this.registry = void 0;
|
|
18
|
+
this.createdAtHash = void 0;
|
|
19
|
+
this.initialU8aLength = void 0;
|
|
20
|
+
|
|
21
|
+
for (let i = 0; i < values.length; i++) {
|
|
22
|
+
this[i] = values[i];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
this.registry = registry;
|
|
26
|
+
this.initialU8aLength = initialU8aLength;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
get encodedLength() {
|
|
34
|
+
// We need to loop through all entries since they may have a variable length themselves,
|
|
35
|
+
// e.g. when a Vec or Compact is contained withing, it has a variable length based on data
|
|
36
|
+
let total = compactToU8a(this.length).length;
|
|
37
|
+
|
|
38
|
+
for (let i = 0; i < this.length; i++) {
|
|
39
|
+
total += this[i].encodedLength;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return total;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* @description returns a hash of the contents
|
|
46
|
+
*/
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
get hash() {
|
|
50
|
+
return this.registry.hash(this.toU8a());
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @description Checks if the value is an empty value
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
get isEmpty() {
|
|
58
|
+
return this.length === 0;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* @description The length of the value
|
|
62
|
+
*/
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
get length() {
|
|
66
|
+
// only included here since we ignore inherited docs
|
|
67
|
+
return super.length;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* @description Compares the value of the input to see if there is a match
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
eq(other) {
|
|
75
|
+
return compareArray(this, other);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* @description Converts the Object to an standard JavaScript Array
|
|
79
|
+
*/
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
toArray() {
|
|
83
|
+
return Array.from(this);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* @description Returns a hex string representation of the value
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
toHex() {
|
|
91
|
+
return u8aToHex(this.toU8a());
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
95
|
+
*/
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
toHuman(isExtended) {
|
|
99
|
+
const result = new Array(this.length);
|
|
100
|
+
|
|
101
|
+
for (let i = 0; i < this.length; i++) {
|
|
102
|
+
result[i] = this[i].toHuman(isExtended);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
109
|
+
*/
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
toJSON() {
|
|
113
|
+
const result = new Array(this.length);
|
|
114
|
+
|
|
115
|
+
for (let i = 0; i < this.length; i++) {
|
|
116
|
+
result[i] = this[i].toJSON();
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return result;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* @description Returns the base runtime type name for this instance
|
|
123
|
+
*/
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @description Returns the string representation of the value
|
|
128
|
+
*/
|
|
129
|
+
toString() {
|
|
130
|
+
const result = new Array(this.length);
|
|
131
|
+
|
|
132
|
+
for (let i = 0; i < this.length; i++) {
|
|
133
|
+
result[i] = this[i].toString();
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return `[${result.join(', ')}]`;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
140
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
141
|
+
*/
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
toU8a(isBare) {
|
|
145
|
+
const encoded = new Array(this.length);
|
|
146
|
+
|
|
147
|
+
for (let i = 0; i < this.length; i++) {
|
|
148
|
+
encoded[i] = this[i].toU8a(isBare);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return isBare ? u8aConcat(...encoded) : u8aConcat(compactToU8a(this.length), ...encoded);
|
|
152
|
+
} // Below are methods that we override. When we do a `new Vec(...).map()`,
|
|
153
|
+
// we want it to return an Array. We only override the methods that return a
|
|
154
|
+
// new instance.
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @description Concatenates two arrays
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
concat(other) {
|
|
162
|
+
return this.toArray().concat(other instanceof AbstractArray ? other.toArray() : other);
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* @description Filters the array with the callback
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
filter(callbackfn, thisArg) {
|
|
170
|
+
return this.toArray().filter(callbackfn, thisArg);
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* @description Maps the array with the callback
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
map(callbackfn, thisArg) {
|
|
178
|
+
return this.toArray().map(callbackfn, thisArg);
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* @description Checks if the array includes a specific value
|
|
182
|
+
*/
|
|
183
|
+
|
|
184
|
+
|
|
185
|
+
includes(check) {
|
|
186
|
+
return this.some(value => value.eq(check));
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* @description Returns a slice of an array
|
|
190
|
+
*/
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
slice(start, end) {
|
|
194
|
+
return this.toArray().slice(start, end);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
}
|