@polkadot/types-codec 6.12.2-10
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 +137 -0
- package/base/Base.d.ts +56 -0
- package/base/Base.js +125 -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 +445 -0
- package/base/Enum.d.ts +105 -0
- package/base/Enum.js +421 -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 +60 -0
- package/extended/WrapperOpaque.d.ts +14 -0
- package/extended/WrapperOpaque.js +49 -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 +137 -0
- package/native/Json.d.ts +56 -0
- package/native/Json.js +121 -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 +302 -0
- package/native/Struct.d.ts +93 -0
- package/native/Struct.js +286 -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 +69 -0
- package/types/interfaces.js +1 -0
- package/types/registry.cjs +1 -0
- package/types/registry.d.ts +61 -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
package/base/Base.cjs
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.Base = void 0;
|
|
9
|
+
|
|
10
|
+
var _classPrivateFieldLooseBase2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldLooseBase"));
|
|
11
|
+
|
|
12
|
+
var _classPrivateFieldLooseKey2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldLooseKey"));
|
|
13
|
+
|
|
14
|
+
var _registry = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("registry");
|
|
15
|
+
|
|
16
|
+
var _raw = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("raw");
|
|
17
|
+
|
|
18
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
19
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @name Base
|
|
23
|
+
* @description A type extends the Base class, when it holds a value
|
|
24
|
+
*/
|
|
25
|
+
class Base {
|
|
26
|
+
constructor(registry, value, initialU8aLength) {
|
|
27
|
+
Object.defineProperty(this, _registry, {
|
|
28
|
+
writable: true,
|
|
29
|
+
value: void 0
|
|
30
|
+
});
|
|
31
|
+
this.createdAtHash = void 0;
|
|
32
|
+
this.initialU8aLength = void 0;
|
|
33
|
+
Object.defineProperty(this, _raw, {
|
|
34
|
+
writable: true,
|
|
35
|
+
value: void 0
|
|
36
|
+
});
|
|
37
|
+
(0, _classPrivateFieldLooseBase2.default)(this, _registry)[_registry] = registry;
|
|
38
|
+
(0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw] = value;
|
|
39
|
+
this.initialU8aLength = initialU8aLength;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
get encodedLength() {
|
|
47
|
+
return this.toU8a().length;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* @description returns a hash of the contents
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
get hash() {
|
|
55
|
+
return this.registry.hash(this.toU8a());
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
get inner() {
|
|
59
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw];
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* @description Checks if the value is an empty value
|
|
63
|
+
*/
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
get isEmpty() {
|
|
67
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].isEmpty;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get registry() {
|
|
71
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _registry)[_registry];
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* @description Compares the value of the input to see if there is a match
|
|
75
|
+
*/
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
eq(other) {
|
|
79
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].eq(other);
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
83
|
+
*/
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
toHex(isLe) {
|
|
87
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].toHex(isLe);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
91
|
+
*/
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
toHuman(isExtended) {
|
|
95
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].toHuman(isExtended);
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
99
|
+
*/
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
toJSON() {
|
|
103
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].toJSON();
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* @description Returns the string representation of the value
|
|
107
|
+
*/
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
toString() {
|
|
111
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].toString();
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
115
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
116
|
+
*/
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
toU8a(isBare) {
|
|
120
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].toU8a(isBare);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* @description Returns the base runtime type name for this instance
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
toRawType() {
|
|
128
|
+
return 'Base';
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
unwrap() {
|
|
132
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw];
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
exports.Base = Base;
|
package/base/Base.d.ts
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { HexString } from '@polkadot/util/types';
|
|
2
|
+
import type { AnyJson, BareOpts, Codec, CodecRegistry, IU8a } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* @name Base
|
|
5
|
+
* @description A type extends the Base class, when it holds a value
|
|
6
|
+
*/
|
|
7
|
+
export declare abstract class Base<T extends Codec> implements Codec {
|
|
8
|
+
#private;
|
|
9
|
+
createdAtHash?: IU8a;
|
|
10
|
+
readonly initialU8aLength?: number;
|
|
11
|
+
protected constructor(registry: CodecRegistry, value: T, initialU8aLength?: number);
|
|
12
|
+
/**
|
|
13
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
14
|
+
*/
|
|
15
|
+
get encodedLength(): number;
|
|
16
|
+
/**
|
|
17
|
+
* @description returns a hash of the contents
|
|
18
|
+
*/
|
|
19
|
+
get hash(): IU8a;
|
|
20
|
+
get inner(): T;
|
|
21
|
+
/**
|
|
22
|
+
* @description Checks if the value is an empty value
|
|
23
|
+
*/
|
|
24
|
+
get isEmpty(): boolean;
|
|
25
|
+
get registry(): CodecRegistry;
|
|
26
|
+
/**
|
|
27
|
+
* @description Compares the value of the input to see if there is a match
|
|
28
|
+
*/
|
|
29
|
+
eq(other?: unknown): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
32
|
+
*/
|
|
33
|
+
toHex(isLe?: boolean): HexString;
|
|
34
|
+
/**
|
|
35
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
36
|
+
*/
|
|
37
|
+
toHuman(isExtended?: boolean): AnyJson;
|
|
38
|
+
/**
|
|
39
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
40
|
+
*/
|
|
41
|
+
toJSON(): AnyJson;
|
|
42
|
+
/**
|
|
43
|
+
* @description Returns the string representation of the value
|
|
44
|
+
*/
|
|
45
|
+
toString(): string;
|
|
46
|
+
/**
|
|
47
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
48
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
49
|
+
*/
|
|
50
|
+
toU8a(isBare?: BareOpts): Uint8Array;
|
|
51
|
+
/**
|
|
52
|
+
* @description Returns the base runtime type name for this instance
|
|
53
|
+
*/
|
|
54
|
+
toRawType(): string;
|
|
55
|
+
unwrap(): T;
|
|
56
|
+
}
|
package/base/Base.js
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import _classPrivateFieldLooseBase from "@babel/runtime/helpers/esm/classPrivateFieldLooseBase";
|
|
2
|
+
import _classPrivateFieldLooseKey from "@babel/runtime/helpers/esm/classPrivateFieldLooseKey";
|
|
3
|
+
|
|
4
|
+
var _registry = /*#__PURE__*/_classPrivateFieldLooseKey("registry");
|
|
5
|
+
|
|
6
|
+
var _raw = /*#__PURE__*/_classPrivateFieldLooseKey("raw");
|
|
7
|
+
|
|
8
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
9
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @name Base
|
|
13
|
+
* @description A type extends the Base class, when it holds a value
|
|
14
|
+
*/
|
|
15
|
+
export class Base {
|
|
16
|
+
constructor(registry, value, initialU8aLength) {
|
|
17
|
+
Object.defineProperty(this, _registry, {
|
|
18
|
+
writable: true,
|
|
19
|
+
value: void 0
|
|
20
|
+
});
|
|
21
|
+
this.createdAtHash = void 0;
|
|
22
|
+
this.initialU8aLength = void 0;
|
|
23
|
+
Object.defineProperty(this, _raw, {
|
|
24
|
+
writable: true,
|
|
25
|
+
value: void 0
|
|
26
|
+
});
|
|
27
|
+
_classPrivateFieldLooseBase(this, _registry)[_registry] = registry;
|
|
28
|
+
_classPrivateFieldLooseBase(this, _raw)[_raw] = value;
|
|
29
|
+
this.initialU8aLength = initialU8aLength;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
get encodedLength() {
|
|
37
|
+
return this.toU8a().length;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @description returns a hash of the contents
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
get hash() {
|
|
45
|
+
return this.registry.hash(this.toU8a());
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
get inner() {
|
|
49
|
+
return _classPrivateFieldLooseBase(this, _raw)[_raw];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* @description Checks if the value is an empty value
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
get isEmpty() {
|
|
57
|
+
return _classPrivateFieldLooseBase(this, _raw)[_raw].isEmpty;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get registry() {
|
|
61
|
+
return _classPrivateFieldLooseBase(this, _registry)[_registry];
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* @description Compares the value of the input to see if there is a match
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
eq(other) {
|
|
69
|
+
return _classPrivateFieldLooseBase(this, _raw)[_raw].eq(other);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
toHex(isLe) {
|
|
77
|
+
return _classPrivateFieldLooseBase(this, _raw)[_raw].toHex(isLe);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
toHuman(isExtended) {
|
|
85
|
+
return _classPrivateFieldLooseBase(this, _raw)[_raw].toHuman(isExtended);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
toJSON() {
|
|
93
|
+
return _classPrivateFieldLooseBase(this, _raw)[_raw].toJSON();
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* @description Returns the string representation of the value
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
toString() {
|
|
101
|
+
return _classPrivateFieldLooseBase(this, _raw)[_raw].toString();
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
105
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
106
|
+
*/
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
toU8a(isBare) {
|
|
110
|
+
return _classPrivateFieldLooseBase(this, _raw)[_raw].toU8a(isBare);
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* @description Returns the base runtime type name for this instance
|
|
114
|
+
*/
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
toRawType() {
|
|
118
|
+
return 'Base';
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
unwrap() {
|
|
122
|
+
return _classPrivateFieldLooseBase(this, _raw)[_raw];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
}
|
package/base/Compact.cjs
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.Compact = void 0;
|
|
9
|
+
|
|
10
|
+
var _classPrivateFieldLooseBase2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldLooseBase"));
|
|
11
|
+
|
|
12
|
+
var _classPrivateFieldLooseKey2 = _interopRequireDefault(require("@babel/runtime/helpers/classPrivateFieldLooseKey"));
|
|
13
|
+
|
|
14
|
+
var _util = require("@polkadot/util");
|
|
15
|
+
|
|
16
|
+
var _index = require("../utils/index.cjs");
|
|
17
|
+
|
|
18
|
+
// Copyright 2017-2021 @polkadot/types-codec authors & contributors
|
|
19
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
20
|
+
var _Type = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("Type");
|
|
21
|
+
|
|
22
|
+
var _raw = /*#__PURE__*/(0, _classPrivateFieldLooseKey2.default)("raw");
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* @name Compact
|
|
26
|
+
* @description
|
|
27
|
+
* A compact length-encoding codec wrapper. It performs the same function as Length, however
|
|
28
|
+
* differs in that it uses a variable number of bytes to do the actual encoding. This is mostly
|
|
29
|
+
* used by other types to add length-prefixed encoding, or in the case of wrapped types, taking
|
|
30
|
+
* a number and making the compact representation thereof
|
|
31
|
+
*/
|
|
32
|
+
class Compact {
|
|
33
|
+
constructor(registry, Type) {
|
|
34
|
+
let value = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
35
|
+
this.registry = void 0;
|
|
36
|
+
this.createdAtHash = void 0;
|
|
37
|
+
this.initialU8aLength = void 0;
|
|
38
|
+
Object.defineProperty(this, _Type, {
|
|
39
|
+
writable: true,
|
|
40
|
+
value: void 0
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(this, _raw, {
|
|
43
|
+
writable: true,
|
|
44
|
+
value: void 0
|
|
45
|
+
});
|
|
46
|
+
this.registry = registry;
|
|
47
|
+
(0, _classPrivateFieldLooseBase2.default)(this, _Type)[_Type] = (0, _index.typeToConstructor)(registry, Type);
|
|
48
|
+
const [raw, decodedLength] = Compact.decodeCompact(registry, (0, _classPrivateFieldLooseBase2.default)(this, _Type)[_Type], value);
|
|
49
|
+
this.initialU8aLength = decodedLength;
|
|
50
|
+
(0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw] = raw;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static with(Type) {
|
|
54
|
+
return class extends Compact {
|
|
55
|
+
constructor(registry, value) {
|
|
56
|
+
super(registry, Type, value);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/** @internal */
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
static decodeCompact(registry, Type, value) {
|
|
65
|
+
if (value instanceof Compact) {
|
|
66
|
+
return [new Type(registry, (0, _classPrivateFieldLooseBase2.default)(value, _raw)[_raw]), 0];
|
|
67
|
+
} else if (value instanceof Type) {
|
|
68
|
+
return [value, 0];
|
|
69
|
+
} else if ((0, _util.isString)(value) || (0, _util.isNumber)(value) || (0, _util.isBn)(value) || (0, _util.isBigInt)(value)) {
|
|
70
|
+
return [new Type(registry, value), 0];
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const [decodedLength, bn] = (0, _util.compactFromU8a)(value);
|
|
74
|
+
return [new Type(registry, bn), decodedLength];
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
get encodedLength() {
|
|
82
|
+
return this.toU8a().length;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* @description returns a hash of the contents
|
|
86
|
+
*/
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
get hash() {
|
|
90
|
+
return this.registry.hash(this.toU8a());
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* @description Checks if the value is an empty value
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
get isEmpty() {
|
|
98
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].isEmpty;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* @description Returns the number of bits in the value
|
|
102
|
+
*/
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
bitLength() {
|
|
106
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].bitLength();
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* @description Compares the value of the input to see if there is a match
|
|
110
|
+
*/
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
eq(other) {
|
|
114
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].eq(other instanceof Compact ? (0, _classPrivateFieldLooseBase2.default)(other, _raw)[_raw] : other);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* @description Returns a BigInt representation of the number
|
|
118
|
+
*/
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
toBigInt() {
|
|
122
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].toBigInt();
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* @description Returns the BN representation of the number
|
|
126
|
+
*/
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
toBn() {
|
|
130
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].toBn();
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
toHex(isLe) {
|
|
138
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].toHex(isLe);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
142
|
+
*/
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
toHuman(isExtended) {
|
|
146
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].toHuman(isExtended);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
150
|
+
*/
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
toJSON() {
|
|
154
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].toJSON();
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* @description Returns the number representation for the value
|
|
158
|
+
*/
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
toNumber() {
|
|
162
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].toNumber();
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* @description Returns the base runtime type name for this instance
|
|
166
|
+
*/
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
toRawType() {
|
|
170
|
+
return `Compact<${this.registry.getClassName((0, _classPrivateFieldLooseBase2.default)(this, _Type)[_Type]) || (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].toRawType()}>`;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* @description Returns the string representation of the value
|
|
174
|
+
*/
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
toString() {
|
|
178
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].toString();
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
182
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
183
|
+
*/
|
|
184
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
toU8a(isBare) {
|
|
188
|
+
return (0, _util.compactToU8a)((0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw].toBn());
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* @description Returns the embedded [[UInt]] or [[Moment]] value
|
|
192
|
+
*/
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
unwrap() {
|
|
196
|
+
return (0, _classPrivateFieldLooseBase2.default)(this, _raw)[_raw];
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
exports.Compact = Compact;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/// <reference types="bn.js" />
|
|
2
|
+
import type { BN } from '@polkadot/util';
|
|
3
|
+
import type { HexString } from '@polkadot/util/types';
|
|
4
|
+
import type { AnyJson, AnyNumber, CodecClass, CodecRegistry, ICompact, INumber, IU8a } from '../types';
|
|
5
|
+
/**
|
|
6
|
+
* @name Compact
|
|
7
|
+
* @description
|
|
8
|
+
* A compact length-encoding codec wrapper. It performs the same function as Length, however
|
|
9
|
+
* differs in that it uses a variable number of bytes to do the actual encoding. This is mostly
|
|
10
|
+
* used by other types to add length-prefixed encoding, or in the case of wrapped types, taking
|
|
11
|
+
* a number and making the compact representation thereof
|
|
12
|
+
*/
|
|
13
|
+
export declare class Compact<T extends INumber> implements ICompact<T> {
|
|
14
|
+
#private;
|
|
15
|
+
readonly registry: CodecRegistry;
|
|
16
|
+
createdAtHash?: IU8a;
|
|
17
|
+
readonly initialU8aLength?: number;
|
|
18
|
+
constructor(registry: CodecRegistry, Type: CodecClass<T> | string, value?: Compact<T> | AnyNumber);
|
|
19
|
+
static with<T extends INumber>(Type: CodecClass<T> | string): CodecClass<Compact<T>>;
|
|
20
|
+
/** @internal */
|
|
21
|
+
static decodeCompact<T extends INumber>(registry: CodecRegistry, Type: CodecClass<T>, value: Compact<T> | AnyNumber): [T, number];
|
|
22
|
+
/**
|
|
23
|
+
* @description The length of the value when encoded as a Uint8Array
|
|
24
|
+
*/
|
|
25
|
+
get encodedLength(): number;
|
|
26
|
+
/**
|
|
27
|
+
* @description returns a hash of the contents
|
|
28
|
+
*/
|
|
29
|
+
get hash(): IU8a;
|
|
30
|
+
/**
|
|
31
|
+
* @description Checks if the value is an empty value
|
|
32
|
+
*/
|
|
33
|
+
get isEmpty(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* @description Returns the number of bits in the value
|
|
36
|
+
*/
|
|
37
|
+
bitLength(): number;
|
|
38
|
+
/**
|
|
39
|
+
* @description Compares the value of the input to see if there is a match
|
|
40
|
+
*/
|
|
41
|
+
eq(other?: unknown): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* @description Returns a BigInt representation of the number
|
|
44
|
+
*/
|
|
45
|
+
toBigInt(): bigint;
|
|
46
|
+
/**
|
|
47
|
+
* @description Returns the BN representation of the number
|
|
48
|
+
*/
|
|
49
|
+
toBn(): BN;
|
|
50
|
+
/**
|
|
51
|
+
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
|
52
|
+
*/
|
|
53
|
+
toHex(isLe?: boolean): HexString;
|
|
54
|
+
/**
|
|
55
|
+
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
|
56
|
+
*/
|
|
57
|
+
toHuman(isExtended?: boolean): AnyJson;
|
|
58
|
+
/**
|
|
59
|
+
* @description Converts the Object to JSON, typically used for RPC transfers
|
|
60
|
+
*/
|
|
61
|
+
toJSON(): AnyJson;
|
|
62
|
+
/**
|
|
63
|
+
* @description Returns the number representation for the value
|
|
64
|
+
*/
|
|
65
|
+
toNumber(): number;
|
|
66
|
+
/**
|
|
67
|
+
* @description Returns the base runtime type name for this instance
|
|
68
|
+
*/
|
|
69
|
+
toRawType(): string;
|
|
70
|
+
/**
|
|
71
|
+
* @description Returns the string representation of the value
|
|
72
|
+
*/
|
|
73
|
+
toString(): string;
|
|
74
|
+
/**
|
|
75
|
+
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
|
76
|
+
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
|
77
|
+
*/
|
|
78
|
+
toU8a(isBare?: boolean): Uint8Array;
|
|
79
|
+
/**
|
|
80
|
+
* @description Returns the embedded [[UInt]] or [[Moment]] value
|
|
81
|
+
*/
|
|
82
|
+
unwrap(): T;
|
|
83
|
+
}
|