Bump deps w/ eslint (#2302)
* Bump deps w/ eslint * Additional cleanups * Additional * @polkadot/types done * Additional * @polkadot/typegen done * Additional * @polkadot/rpc-core done * Additional * Additional * Additional * docs * @polkadot/api-derive done * @polkadot/api done * @polkadot/api-contracts done * Update tests
This commit is contained in:
@@ -62,7 +62,7 @@ export default abstract class AbstractArray<T extends Codec> extends Array<T> im
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
public eq (other?: any): boolean {
|
||||
public eq (other?: unknown): boolean {
|
||||
return compareArray(this, other);
|
||||
}
|
||||
|
||||
@@ -141,7 +141,7 @@ export default abstract class AbstractArray<T extends Codec> extends Array<T> im
|
||||
* @param callbackfn The filter function
|
||||
* @param thisArg The `this` object to apply the result to
|
||||
*/
|
||||
public filter (callbackfn: (value: T, index: number, array: T[]) => any, thisArg?: any): T[] {
|
||||
public filter (callbackfn: (value: T, index: number, array: T[]) => boolean, thisArg?: unknown): T[] {
|
||||
return this.toArray().filter(callbackfn, thisArg);
|
||||
}
|
||||
|
||||
@@ -150,14 +150,14 @@ export default abstract class AbstractArray<T extends Codec> extends Array<T> im
|
||||
* @param callbackfn The mapping function
|
||||
* @param thisArg The `this` onject to apply the result to
|
||||
*/
|
||||
public map<U> (callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: any): U[] {
|
||||
public map<U> (callbackfn: (value: T, index: number, array: T[]) => U, thisArg?: unknown): U[] {
|
||||
return this.toArray().map(callbackfn, thisArg);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Checks if the array includes a specific value
|
||||
*/
|
||||
public includes (check: any): boolean {
|
||||
return this.some((value: T): boolean => value.eq(check));
|
||||
public includes (check: unknown): boolean {
|
||||
return this.some((value: T) => value.eq(check));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ function decodeAbstracIntU8a (value: Uint8Array, bitLength: UIntBitLength, isNeg
|
||||
// NOTE When passing u8a in (typically from decoded data), it is always Little Endian
|
||||
return u8aToBn(value.subarray(0, bitLength / 8), { isLe: true, isNegative }).toString();
|
||||
} catch (error) {
|
||||
throw new Error(`AbstractInt: failed on ${JSON.stringify(value)}:: ${error.message}`);
|
||||
throw new Error(`AbstractInt: failed on ${JSON.stringify(value)}:: ${(error as Error).message}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,13 +111,13 @@ export default abstract class AbstractInt extends BN implements Codec {
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
public eq (other?: any): boolean {
|
||||
public eq (other?: unknown): boolean {
|
||||
// Here we are actually overriding the built-in .eq to take care of both
|
||||
// number and BN inputs (no `.eqn` needed) - numbers will be converted
|
||||
return super.eq(
|
||||
isHex(other)
|
||||
? hexToBn(other.toString(), { isLe: false, isNegative: this.#isSigned })
|
||||
: bnToBn(other)
|
||||
: bnToBn(other as string)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ describe('BTreeMap', (): void => {
|
||||
it('decodes within more complicated types', (): void => {
|
||||
const s = new Struct(registry, {
|
||||
placeholder: U32,
|
||||
value: 'BTreeMap<Text, U32>' as any
|
||||
value: 'BTreeMap<Text, U32>' as 'u32'
|
||||
});
|
||||
|
||||
s.set('value', new (BTreeMap.with(Text, U32))(registry, mockU32TextMap));
|
||||
|
||||
@@ -9,7 +9,7 @@ import CodecMap from './Map';
|
||||
export default class BTreeMap<K extends Codec = Codec, V extends Codec = Codec> extends CodecMap<K, V> {
|
||||
public static with<K extends Codec, V extends Codec> (keyType: Constructor<K> | keyof InterfaceTypes, valType: Constructor<V> | keyof InterfaceTypes): Constructor<CodecMap<K, V>> {
|
||||
return class extends BTreeMap<K, V> {
|
||||
constructor (registry: Registry, value?: any) {
|
||||
constructor (registry: Registry, value?: Uint8Array | string | Map<any, any>) {
|
||||
super(registry, 'BTreeMap', keyType, valType, value);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -39,7 +39,8 @@ function decodeSetFromSet<V extends Codec = Codec> (registry: Registry, ValClass
|
||||
try {
|
||||
output.add((val instanceof ValClass) ? val : new ValClass(registry, val));
|
||||
} catch (error) {
|
||||
console.error('Failed to decode BTreeSet key or value:', error.message);
|
||||
console.error('Failed to decode BTreeSet key or value:', (error as Error).message);
|
||||
|
||||
throw error;
|
||||
}
|
||||
});
|
||||
@@ -61,7 +62,7 @@ function decodeSetFromSet<V extends Codec = Codec> (registry: Registry, ValClass
|
||||
* @param jsonSet
|
||||
* @internal
|
||||
*/
|
||||
function decodeSet<V extends Codec = Codec> (registry: Registry, valType: Constructor<V> | keyof InterfaceTypes, value: Uint8Array | string | Set<any>): Set<V> {
|
||||
function decodeSet<V extends Codec = Codec> (registry: Registry, valType: Constructor<V> | keyof InterfaceTypes, value?: Uint8Array | string | Set<any>): Set<V> {
|
||||
if (!value) {
|
||||
return new Set<V>();
|
||||
}
|
||||
@@ -84,7 +85,7 @@ export default class BTreeSet<V extends Codec = Codec> extends Set<V> implements
|
||||
|
||||
readonly #ValClass: Constructor<V>;
|
||||
|
||||
constructor (registry: Registry, valType: Constructor<V> | keyof InterfaceTypes, rawValue: any) {
|
||||
constructor (registry: Registry, valType: Constructor<V> | keyof InterfaceTypes, rawValue?: Uint8Array | string | Set<any>) {
|
||||
super(decodeSet(registry, valType, rawValue));
|
||||
|
||||
this.registry = registry;
|
||||
@@ -93,7 +94,7 @@ export default class BTreeSet<V extends Codec = Codec> extends Set<V> implements
|
||||
|
||||
public static with<V extends Codec> (valType: Constructor<V> | keyof InterfaceTypes): Constructor<BTreeSet<V>> {
|
||||
return class extends BTreeSet<V> {
|
||||
constructor (registry: Registry, value?: any) {
|
||||
constructor (registry: Registry, value?: Uint8Array | string | Set<any>) {
|
||||
super(registry, valType, value);
|
||||
}
|
||||
};
|
||||
@@ -129,7 +130,7 @@ export default class BTreeSet<V extends Codec = Codec> extends Set<V> implements
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
public eq (other?: any): boolean {
|
||||
public eq (other?: unknown): boolean {
|
||||
return compareSet(this, other);
|
||||
}
|
||||
|
||||
@@ -144,7 +145,7 @@ export default class BTreeSet<V extends Codec = Codec> extends Set<V> implements
|
||||
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
||||
*/
|
||||
public toHuman (isExtended?: boolean): AnyJson {
|
||||
const json: any = [];
|
||||
const json: AnyJson = [];
|
||||
|
||||
this.forEach((v: V) => {
|
||||
json.push(v.toHuman(isExtended));
|
||||
@@ -157,7 +158,7 @@ export default class BTreeSet<V extends Codec = Codec> extends Set<V> implements
|
||||
* @description Converts the Object to JSON, typically used for RPC transfers
|
||||
*/
|
||||
public toJSON (): AnyJson {
|
||||
const json: any = [];
|
||||
const json: AnyJson = [];
|
||||
|
||||
this.forEach((v: V) => {
|
||||
json.push(v.toJSON());
|
||||
|
||||
@@ -18,7 +18,7 @@ export default abstract class Base<T extends Codec> implements Codec {
|
||||
|
||||
protected readonly _raw: T;
|
||||
|
||||
protected constructor (registry: Registry, value?: any) {
|
||||
protected constructor (registry: Registry, value: T) {
|
||||
this.registry = registry;
|
||||
this._raw = value;
|
||||
}
|
||||
@@ -47,7 +47,7 @@ export default abstract class Base<T extends Codec> implements Codec {
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
public eq (other?: any): boolean {
|
||||
public eq (other?: unknown): boolean {
|
||||
return this._raw.eq(other);
|
||||
}
|
||||
|
||||
|
||||
@@ -109,7 +109,7 @@ describe('Compact', (): void => {
|
||||
describe('constructor', (): void => {
|
||||
it('has support for BigInt', (): void => {
|
||||
expect(
|
||||
new Compact(registry, 'u128', 123_456_789_000_123_456_789n).toHuman()
|
||||
new Compact(registry, 'u128', 123456789000123456789n).toHuman()
|
||||
).toEqual('123,456,789,000,123,456,789');
|
||||
});
|
||||
|
||||
|
||||
@@ -28,12 +28,14 @@ export interface CompactEncodable extends Codec {
|
||||
*/
|
||||
export default class Compact<T extends CompactEncodable> extends Base<T> implements ICompact<T> {
|
||||
constructor (registry: Registry, Type: Constructor<T> | keyof InterfaceTypes, value: Compact<T> | AnyNumber = 0) {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
super(registry, Compact.decodeCompact<T>(registry, typeToConstructor(registry, Type), value));
|
||||
}
|
||||
|
||||
public static with<T extends CompactEncodable> (Type: Constructor<T> | keyof InterfaceTypes): Constructor<Compact<T>> {
|
||||
return class extends Compact<T> {
|
||||
constructor (registry: Registry, value?: any) {
|
||||
constructor (registry: Registry, value?: Compact<T> | AnyNumber) {
|
||||
super(registry, Type, value);
|
||||
}
|
||||
};
|
||||
@@ -79,7 +81,7 @@ export default class Compact<T extends CompactEncodable> extends Base<T> impleme
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
public eq (other?: any): boolean {
|
||||
public eq (other?: unknown): boolean {
|
||||
return this._raw.eq(
|
||||
other instanceof Compact
|
||||
? other._raw
|
||||
|
||||
@@ -33,13 +33,13 @@ export default class CodecDate extends Date implements Codec {
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
public static decodeDate (value: CodecDate | Date | AnyNumber): Date {
|
||||
public static decodeDate (value: CodecDate | Date | AnyNumber | unknown): Date {
|
||||
if (value instanceof Date) {
|
||||
return value;
|
||||
} else if (isU8a(value)) {
|
||||
value = u8aToBn(value.subarray(0, BITLENGTH / 8), true);
|
||||
} else if (isString(value)) {
|
||||
value = new BN(value, 10, 'le');
|
||||
value = new BN(value.toString(), 10, 'le');
|
||||
}
|
||||
|
||||
return new Date(
|
||||
@@ -71,7 +71,7 @@ export default class CodecDate extends Date implements Codec {
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
public eq (other?: any): boolean {
|
||||
public eq (other?: unknown): boolean {
|
||||
return CodecDate.decodeDate(other).getTime() === this.getTime();
|
||||
}
|
||||
|
||||
|
||||
@@ -123,7 +123,7 @@ export default class Enum extends Base<Codec> {
|
||||
|
||||
private _isBasic: boolean;
|
||||
|
||||
constructor (registry: Registry, def: Record<string, keyof InterfaceTypes | Constructor> | string[], value?: any, index?: number) {
|
||||
constructor (registry: Registry, def: Record<string, keyof InterfaceTypes | Constructor> | string[], value?: unknown, index?: number) {
|
||||
const defInfo = extractDef(registry, def);
|
||||
const decoded = decodeEnum(registry, defInfo.def, value, index);
|
||||
|
||||
@@ -137,7 +137,7 @@ export default class Enum extends Base<Codec> {
|
||||
|
||||
public static with (Types: Record<string, keyof InterfaceTypes | Constructor> | string[]): EnumConstructor<Enum> {
|
||||
return class extends Enum {
|
||||
constructor (registry: Registry, value?: any, index?: number) {
|
||||
constructor (registry: Registry, value?: unknown, index?: number) {
|
||||
super(registry, Types, value, index);
|
||||
|
||||
Object.keys(this._def).forEach((_key): void => {
|
||||
@@ -146,6 +146,7 @@ export default class Enum extends Base<Codec> {
|
||||
const iskey = `is${name}`;
|
||||
|
||||
// do not clobber existing properties on the object
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
if (isUndefined((this as any)[iskey])) {
|
||||
Object.defineProperty(this, iskey, {
|
||||
enumerable: true,
|
||||
@@ -153,10 +154,12 @@ export default class Enum extends Base<Codec> {
|
||||
});
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
if (isUndefined((this as any)[askey])) {
|
||||
Object.defineProperty(this, askey, {
|
||||
enumerable: true,
|
||||
get: (): Codec => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
assert((this as any)[iskey], `Cannot convert '${this.type}' via ${askey}`);
|
||||
|
||||
return this.value;
|
||||
@@ -234,7 +237,7 @@ export default class Enum extends Base<Codec> {
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
public eq (other?: any): boolean {
|
||||
public eq (other?: unknown): boolean {
|
||||
// cater for the case where we only pass the enum index
|
||||
if (isNumber(other)) {
|
||||
return this.toNumber() === other;
|
||||
|
||||
@@ -9,7 +9,7 @@ import CodecMap from './Map';
|
||||
export default class HashMap<K extends Codec = Codec, V extends Codec = Codec> extends CodecMap<K, V> {
|
||||
public static with<K extends Codec, V extends Codec> (keyType: Constructor<K> | keyof InterfaceTypes, valType: Constructor<V> | keyof InterfaceTypes): Constructor<CodecMap<K, V>> {
|
||||
return class extends HashMap<K, V> {
|
||||
constructor (registry: Registry, value?: any) {
|
||||
constructor (registry: Registry, value?: Uint8Array | string | Map<any, any>) {
|
||||
super(registry, 'HashMap', keyType, valType, value);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -23,7 +23,7 @@ export default class Int extends AbstractInt {
|
||||
|
||||
public static with (bitLength: UIntBitLength, typeName?: string): Constructor<Int> {
|
||||
return class extends Int {
|
||||
constructor (registry: Registry, value?: any) {
|
||||
constructor (registry: Registry, value?: AnyNumber) {
|
||||
super(registry, value, bitLength);
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ describe('Linkage', (): void => {
|
||||
).toEqual(LINKA);
|
||||
expect(
|
||||
registry.createType(
|
||||
'Linkage<AccountId>' as any,
|
||||
'Linkage<AccountId>' as 'u32',
|
||||
'0x0001da30b68f54f686f586ddb29de12b682dd8bd1404566fb8a8db5dec20aa5b6b36'
|
||||
).toHuman()
|
||||
).toEqual(LINKA);
|
||||
@@ -34,7 +34,7 @@ describe('Linkage', (): void => {
|
||||
// actual check
|
||||
expect(
|
||||
registry.createType(
|
||||
'(ValidatorPrefs, Linkage<AccountId>)' as any,
|
||||
'(ValidatorPrefs, Linkage<AccountId>)' as 'u32',
|
||||
'0x0284d7170001da30b68f54f686f586ddb29de12b682dd8bd1404566fb8a8db5dec20aa5b6b36'
|
||||
).toHuman()
|
||||
).toEqual([PREFS, LINKA]);
|
||||
|
||||
@@ -18,19 +18,19 @@ const EMPTY = new Uint8Array();
|
||||
* @description The wrapper for the result from a LinkedMap
|
||||
*/
|
||||
export default class Linkage<T extends Codec> extends Struct {
|
||||
constructor (registry: Registry, Type: Constructor | keyof InterfaceTypes, value?: any) {
|
||||
constructor (registry: Registry, Type: Constructor | keyof InterfaceTypes, value?: unknown) {
|
||||
super(registry, {
|
||||
previous: Option.with(Type),
|
||||
// eslint-disable-next-line sort-keys
|
||||
next: Option.with(Type)
|
||||
}, value);
|
||||
}, value as string);
|
||||
|
||||
console.error([...this.entries()]);
|
||||
}
|
||||
|
||||
public static withKey<O extends Codec> (Type: Constructor | keyof InterfaceTypes): Constructor<Linkage<O>> {
|
||||
return class extends Linkage<O> {
|
||||
constructor (registry: Registry, value?: any) {
|
||||
constructor (registry: Registry, value?: unknown) {
|
||||
super(registry, Type, value);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -48,7 +48,7 @@ function decodeMapFromMap<K extends Codec = Codec, V extends Codec = Codec> (reg
|
||||
: new ValClass(registry, val)
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Failed to decode Map key or value:', error.message);
|
||||
console.error('Failed to decode Map key or value:', (error as Error).message);
|
||||
|
||||
throw error;
|
||||
}
|
||||
@@ -72,7 +72,7 @@ function decodeMapFromMap<K extends Codec = Codec, V extends Codec = Codec> (reg
|
||||
* @param jsonMap
|
||||
* @internal
|
||||
*/
|
||||
function decodeMap<K extends Codec = Codec, V extends Codec = Codec> (registry: Registry, keyType: Constructor<K> | keyof InterfaceTypes, valType: Constructor<V> | keyof InterfaceTypes, value: Uint8Array | string | Map<any, any>): Map<K, V> {
|
||||
function decodeMap<K extends Codec = Codec, V extends Codec = Codec> (registry: Registry, keyType: Constructor<K> | keyof InterfaceTypes, valType: Constructor<V> | keyof InterfaceTypes, value?: Uint8Array | string | Map<any, any>): Map<K, V> {
|
||||
const KeyClass = typeToConstructor(registry, keyType);
|
||||
const ValClass = typeToConstructor(registry, valType);
|
||||
|
||||
@@ -100,7 +100,7 @@ export default class CodecMap<K extends Codec = Codec, V extends Codec = Codec>
|
||||
|
||||
readonly #type: string;
|
||||
|
||||
constructor (registry: Registry, type: 'BTreeMap' | 'HashMap', keyType: Constructor<K> | keyof InterfaceTypes, valType: Constructor<V> | keyof InterfaceTypes, rawValue: any) {
|
||||
constructor (registry: Registry, type: 'BTreeMap' | 'HashMap', keyType: Constructor<K> | keyof InterfaceTypes, valType: Constructor<V> | keyof InterfaceTypes, rawValue?: Uint8Array | string | Map<any, any>) {
|
||||
super(decodeMap(registry, keyType, valType, rawValue));
|
||||
|
||||
this.registry = registry;
|
||||
@@ -139,7 +139,7 @@ export default class CodecMap<K extends Codec = Codec, V extends Codec = Codec>
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
public eq (other?: any): boolean {
|
||||
public eq (other?: unknown): boolean {
|
||||
return compareMap(this, other);
|
||||
}
|
||||
|
||||
@@ -154,7 +154,7 @@ export default class CodecMap<K extends Codec = Codec, V extends Codec = Codec>
|
||||
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
||||
*/
|
||||
public toHuman (isExtended?: boolean): AnyJson {
|
||||
const json: any = {};
|
||||
const json: AnyJson = {};
|
||||
|
||||
this.forEach((v: V, k: K) => {
|
||||
json[k.toString()] = v.toHuman(isExtended);
|
||||
@@ -167,7 +167,7 @@ export default class CodecMap<K extends Codec = Codec, V extends Codec = Codec>
|
||||
* @description Converts the Object to JSON, typically used for RPC transfers
|
||||
*/
|
||||
public toJSON (): AnyJson {
|
||||
const json: any = {};
|
||||
const json: AnyJson = {};
|
||||
|
||||
this.forEach((v: V, k: K) => {
|
||||
json[k.toString()] = v.toJSON();
|
||||
|
||||
@@ -10,7 +10,7 @@ import Option from './Option';
|
||||
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
const testDecode = (type: string, input: any, expected: any): void =>
|
||||
const testDecode = (type: string, input: any, expected: string): void =>
|
||||
it(`can decode from ${type}`, (): void => {
|
||||
const o = new Option(registry, Text, input);
|
||||
|
||||
@@ -18,11 +18,11 @@ const testDecode = (type: string, input: any, expected: any): void =>
|
||||
expect(o.isNone).toBe(!expected.length);
|
||||
});
|
||||
|
||||
const testEncode = (to: string, expected: any): void =>
|
||||
const testEncode = (to: 'toHex' | 'toString' | 'toU8a', expected: any): void =>
|
||||
it(`can encode ${to}`, (): void => {
|
||||
const e = new Option(registry, Text, 'foo');
|
||||
|
||||
expect((e as any)[to]()).toEqual(expected);
|
||||
expect(e[to]()).toEqual(expected);
|
||||
});
|
||||
|
||||
describe('Option', (): void => {
|
||||
|
||||
@@ -18,7 +18,7 @@ function decodeOptionU8a (registry: Registry, Type: Constructor, value: Uint8Arr
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function decodeOption (registry: Registry, typeName: Constructor | keyof InterfaceTypes, value?: any): Codec {
|
||||
function decodeOption (registry: Registry, typeName: Constructor | keyof InterfaceTypes, value?: unknown): Codec {
|
||||
if (isNull(value) || isUndefined(value) || value instanceof Null) {
|
||||
return new Null(registry);
|
||||
}
|
||||
@@ -51,7 +51,9 @@ function decodeOption (registry: Registry, typeName: Constructor | keyof Interfa
|
||||
export default class Option<T extends Codec> extends Base<T> {
|
||||
readonly #Type: Constructor<T>;
|
||||
|
||||
constructor (registry: Registry, typeName: Constructor<T> | keyof InterfaceTypes, value?: any) {
|
||||
constructor (registry: Registry, typeName: Constructor<T> | keyof InterfaceTypes, value?: unknown) {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
super(registry, decodeOption(registry, typeName, value));
|
||||
|
||||
this.#Type = typeToConstructor(registry, typeName);
|
||||
@@ -59,7 +61,7 @@ export default class Option<T extends Codec> extends Base<T> {
|
||||
|
||||
public static with<O extends Codec> (Type: Constructor<O> | keyof InterfaceTypes): Constructor<Option<O>> {
|
||||
return class extends Option<O> {
|
||||
constructor (registry: Registry, value?: any) {
|
||||
constructor (registry: Registry, value?: unknown) {
|
||||
super(registry, Type, value);
|
||||
}
|
||||
};
|
||||
@@ -104,7 +106,7 @@ export default class Option<T extends Codec> extends Base<T> {
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
public eq (other?: any): boolean {
|
||||
public eq (other?: unknown): boolean {
|
||||
if (other instanceof Option) {
|
||||
return (this.isSome === other.isSome) && this.value.eq(other.value);
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ export default class Raw extends Uint8Array implements IU8a {
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
public eq (other?: any): boolean {
|
||||
public eq (other?: unknown): boolean {
|
||||
if (other instanceof Uint8Array) {
|
||||
return (this.length === other.length) &&
|
||||
!this.some((value, index): boolean => value !== other[index]);
|
||||
|
||||
@@ -14,7 +14,7 @@ import Enum from './Enum';
|
||||
* A Result maps to the Rust Result type, that can either wrap a success or error value
|
||||
*/
|
||||
export default class Result<O extends Codec, E extends Codec> extends Enum {
|
||||
constructor (registry: Registry, Ok: Constructor<O> | keyof InterfaceTypes, Error: Constructor<E> | keyof InterfaceTypes, value?: any) {
|
||||
constructor (registry: Registry, Ok: Constructor<O> | keyof InterfaceTypes, Error: Constructor<E> | keyof InterfaceTypes, value?: unknown) {
|
||||
// NOTE This is order-dependent, Ok (with index 0) needs to be first
|
||||
// eslint-disable-next-line sort-keys
|
||||
super(registry, { Ok, Error }, value);
|
||||
@@ -22,7 +22,7 @@ export default class Result<O extends Codec, E extends Codec> extends Enum {
|
||||
|
||||
public static with<O extends Codec, E extends Codec> (Types: { Ok: Constructor<O> | keyof InterfaceTypes; Error: Constructor<E> | keyof InterfaceTypes }): Constructor<Result<O, E>> {
|
||||
return class extends Result<O, E> {
|
||||
constructor (registry: Registry, value?: any) {
|
||||
constructor (registry: Registry, value?: unknown) {
|
||||
super(registry, Types.Ok, Types.Error, value);
|
||||
}
|
||||
};
|
||||
@@ -71,8 +71,8 @@ export default class Result<O extends Codec, E extends Codec> extends Enum {
|
||||
* @description Returns the base runtime type name for this instance
|
||||
*/
|
||||
public toRawType (): string {
|
||||
const Types = this._toRawStruct() as { Ok: any; Error: any };
|
||||
const Types = this._toRawStruct() as { Ok: unknown; Error: unknown };
|
||||
|
||||
return `Result<${Types.Ok},${Types.Error}>`;
|
||||
return `Result<${Types.Ok as string},${Types.Error as string}>`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ function decodeSetNumber (setValues: SetValues, _value: BN | number): string[] {
|
||||
|
||||
const computed = encodeSet(setValues, result);
|
||||
|
||||
assert(bn.eq(computed), `Set: Mismatch decoding '${bn}', computed as '${computed}' with ${result}`);
|
||||
assert(bn.eq(computed), `Set: Mismatch decoding '${bn.toString()}', computed as '${computed.toString()}' with ${result.join(', ')}`);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -96,14 +96,15 @@ export default class CodecSet extends Set<string> implements Codec {
|
||||
|
||||
public static with (values: SetValues, bitLength?: number): Constructor<CodecSet> {
|
||||
return class extends CodecSet {
|
||||
constructor (registry: Registry, value?: any) {
|
||||
super(registry, values, value, bitLength);
|
||||
constructor (registry: Registry, value?: unknown) {
|
||||
super(registry, values, value as undefined, bitLength);
|
||||
|
||||
Object.keys(values).forEach((_key): void => {
|
||||
const name = stringUpperFirst(stringCamelCase(_key));
|
||||
const iskey = `is${name}`;
|
||||
|
||||
// do not clobber existing properties on the object
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
if (isUndefined((this as any)[iskey])) {
|
||||
Object.defineProperty(this, iskey, {
|
||||
enumerable: true,
|
||||
@@ -167,14 +168,14 @@ export default class CodecSet extends Set<string> implements Codec {
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
public eq (other?: any): boolean {
|
||||
public eq (other?: unknown): boolean {
|
||||
if (Array.isArray(other)) {
|
||||
// we don't actually care about the order, sort the values
|
||||
return compareArray(this.strings.sort(), other.sort());
|
||||
} else if (other instanceof Set) {
|
||||
return this.eq([...other.values()]);
|
||||
} else if (isNumber(other) || isBn(other)) {
|
||||
return this.valueEncoded.eq(bnToBn(other));
|
||||
} else if (isNumber(other) || isBn(other as string)) {
|
||||
return this.valueEncoded.eq(bnToBn(other as string));
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -143,7 +143,9 @@ describe('Struct', (): void => {
|
||||
})
|
||||
)(registry, { txt: 'foo', u32: 0x123456 });
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call
|
||||
expect((struct as any).txt.toString()).toEqual('foo');
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call
|
||||
expect((struct as any).u32.toNumber()).toEqual(0x123456);
|
||||
});
|
||||
|
||||
|
||||
@@ -18,21 +18,26 @@ function decodeStructFromObject <T> (registry: Registry, Types: ConstructorDef,
|
||||
return Object.keys(Types).reduce((raw, key, index): T => {
|
||||
// The key in the JSON can be snake_case (or other cases), but in our
|
||||
// Types, result or any other maps, it's camelCase
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
const jsonKey = (jsonMap.get(key as any) && !value[key]) ? jsonMap.get(key as any) : key;
|
||||
|
||||
try {
|
||||
if (Array.isArray(value)) {
|
||||
// TS2322: Type 'Codec' is not assignable to type 'T[keyof S]'.
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
|
||||
(raw as any)[key] = value[index] instanceof Types[key]
|
||||
? value[index]
|
||||
: new Types[key](registry, value[index]);
|
||||
} else if (value instanceof Map) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const mapped = value.get(jsonKey);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
(raw as any)[key] = mapped instanceof Types[key]
|
||||
? mapped
|
||||
: new Types[key](registry, mapped);
|
||||
} else if (isObject(value)) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
|
||||
(raw as any)[key] = value[jsonKey as string] instanceof Types[key]
|
||||
? value[jsonKey as string]
|
||||
: new Types[key](registry, value[jsonKey as string]);
|
||||
@@ -40,7 +45,7 @@ function decodeStructFromObject <T> (registry: Registry, Types: ConstructorDef,
|
||||
throw new Error(`Struct: cannot decode type ${Types[key].name} with value ${JSON.stringify(value)}`);
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(`Struct: failed on '${jsonKey}':: ${error.message}`);
|
||||
throw new Error(`Struct: failed on '${jsonKey as string}':: ${(error as Error).message}`);
|
||||
}
|
||||
|
||||
return raw;
|
||||
@@ -63,7 +68,7 @@ function decodeStructFromObject <T> (registry: Registry, Types: ConstructorDef,
|
||||
* @param jsonMap
|
||||
* @internal
|
||||
*/
|
||||
function decodeStruct <T> (registry: Registry, Types: ConstructorDef, value: any, jsonMap: Map<any, string>): T {
|
||||
function decodeStruct <T> (registry: Registry, Types: ConstructorDef, value: unknown, jsonMap: Map<any, string>): T {
|
||||
if (isHex(value)) {
|
||||
return decodeStruct(registry, Types, hexToU8a(value as string), jsonMap);
|
||||
} else if (isU8a(value)) {
|
||||
@@ -72,6 +77,7 @@ function decodeStruct <T> (registry: Registry, Types: ConstructorDef, value: any
|
||||
// Transform array of values to {key: value} mapping
|
||||
return Object.keys(Types).reduce((raw, key, index): T => {
|
||||
// TS2322: Type 'Codec' is not assignable to type 'T[keyof S]'.
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
(raw as any)[key] = values[index];
|
||||
|
||||
return raw;
|
||||
@@ -109,7 +115,8 @@ export default class Struct<
|
||||
|
||||
readonly #Types: ConstructorDef;
|
||||
|
||||
constructor (registry: Registry, Types: S, value: V | Map<any, any> | any[] | string = {} as V, jsonMap: Map<keyof S, string> = new Map()) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
constructor (registry: Registry, Types: S, value: V | Map<unknown, unknown> | unknown[] | string = {} as V, jsonMap: Map<keyof S, string> = new Map()) {
|
||||
super(Object.entries(
|
||||
decodeStruct(registry, mapToTypeMap(registry, Types), value, jsonMap)
|
||||
) as [keyof S, Codec][]);
|
||||
@@ -121,11 +128,12 @@ export default class Struct<
|
||||
|
||||
public static with<S extends TypesDef> (Types: S, jsonMap?: Map<keyof S, string>): Constructor<Struct<S>> {
|
||||
return class extends Struct<S> {
|
||||
constructor (registry: Registry, value?: any) {
|
||||
super(registry, Types, value, jsonMap);
|
||||
constructor (registry: Registry, value?: unknown) {
|
||||
super(registry, Types, value as string, jsonMap);
|
||||
|
||||
(Object.keys(Types) as (keyof S)[]).forEach((key): void => {
|
||||
// do not clobber existing properties on the object
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
if (!isUndefined((this as any)[key])) {
|
||||
return;
|
||||
}
|
||||
@@ -168,6 +176,7 @@ export default class Struct<
|
||||
return (Object
|
||||
.entries(this.#Types) as [keyof S, Constructor][])
|
||||
.reduce((result: E, [key, Type]): E => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
(result as any)[key] = new Type(this.registry).toRawType();
|
||||
|
||||
return result;
|
||||
@@ -195,7 +204,7 @@ export default class Struct<
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
public eq (other?: any): boolean {
|
||||
public eq (other?: unknown): boolean {
|
||||
return compareMap(this, other);
|
||||
}
|
||||
|
||||
@@ -232,13 +241,13 @@ export default class Struct<
|
||||
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
||||
*/
|
||||
public toHuman (isExtended?: boolean): AnyJson {
|
||||
return [...this.keys()].reduce((json, key): any => {
|
||||
return [...this.keys()].reduce((json, key): Record<keyof S, AnyJson> => {
|
||||
const value = this.get(key);
|
||||
|
||||
json[key] = value && value.toHuman(isExtended);
|
||||
|
||||
return json;
|
||||
}, {} as any);
|
||||
}, {} as Record<keyof S, AnyJson>);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -247,14 +256,14 @@ export default class Struct<
|
||||
public toJSON (): AnyJson {
|
||||
// FIXME the return type string is only used by Extrinsic (extends Struct),
|
||||
// but its toJSON is the hex value
|
||||
return [...this.keys()].reduce((json, key): any => {
|
||||
return [...this.keys()].reduce((json, key): Record<keyof S, AnyJson> => {
|
||||
const jsonKey = this.#jsonMap.get(key) || key;
|
||||
const value = this.get(key);
|
||||
|
||||
json[jsonKey] = value && value.toJSON();
|
||||
|
||||
return json;
|
||||
}, {} as any);
|
||||
}, {} as Record<keyof S, AnyJson>);
|
||||
}
|
||||
|
||||
public static typesToMap (registry: Registry, Types: Record<string, Constructor>): Record<string, string> {
|
||||
|
||||
@@ -13,7 +13,7 @@ import Raw from './Raw';
|
||||
import { compareMap } from './utils';
|
||||
|
||||
/** @internal */
|
||||
function decodeJson (value?: { [index: string]: any } | null): [string, any][] {
|
||||
function decodeJson (value?: Record<string, unknown> | null): [string, any][] {
|
||||
return Object.entries(value || {});
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ function decodeJson (value?: { [index: string]: any } | null): [string, any][] {
|
||||
export default class StructAny extends Map<string, any> implements Codec {
|
||||
public readonly registry: Registry;
|
||||
|
||||
constructor (registry: Registry, value?: { [index: string]: any } | null) {
|
||||
constructor (registry: Registry, value?: Record<string, unknown> | null) {
|
||||
const decoded = decodeJson(value);
|
||||
|
||||
super(decoded);
|
||||
@@ -38,13 +38,14 @@ export default class StructAny extends Map<string, any> implements Codec {
|
||||
// like we are doing with structs, add the keys as getters
|
||||
decoded.forEach(([key]): void => {
|
||||
// do not clobber existing properties on the object
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
if (!isUndefined((this as any)[key])) {
|
||||
return;
|
||||
}
|
||||
|
||||
Object.defineProperty(this, key, {
|
||||
enumerable: true,
|
||||
get: (): Codec | undefined => this.get(key)
|
||||
get: (): Codec | undefined => this.get(key) as Codec
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -73,7 +74,7 @@ export default class StructAny extends Map<string, any> implements Codec {
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
public eq (other?: any): boolean {
|
||||
public eq (other?: unknown): boolean {
|
||||
return compareMap(this, other);
|
||||
}
|
||||
|
||||
@@ -95,8 +96,8 @@ export default class StructAny extends Map<string, any> implements Codec {
|
||||
* @description Converts the Object to JSON, typically used for RPC transfers
|
||||
*/
|
||||
public toJSON (): AnyJson {
|
||||
return [...this.entries()].reduce((json: { [index: string]: AnyJson }, [key, value]): { [index: string]: AnyJson } => {
|
||||
json[key] = value;
|
||||
return [...this.entries()].reduce((json: Record<string, AnyJson>, [key, value]): Record<string, AnyJson> => {
|
||||
json[key] = value as AnyJson;
|
||||
|
||||
return json;
|
||||
}, {});
|
||||
|
||||
@@ -54,7 +54,7 @@ describe('Tuple', (): void => {
|
||||
|
||||
it('decodes properly from complex types', (): void => {
|
||||
const INPUT = '0xcc0200000000';
|
||||
const test = registry.createType('(u32, [u32; 0], u16)' as any, INPUT);
|
||||
const test = registry.createType('(u32, [u32; 0], u16)' as 'u32', INPUT);
|
||||
|
||||
expect(test.encodedLength).toEqual(4 + 0 + 2);
|
||||
expect(test.toHex()).toEqual(INPUT);
|
||||
|
||||
@@ -9,6 +9,8 @@ import { isU8a, u8aConcat, isHex, hexToU8a } from '@polkadot/util';
|
||||
import { decodeU8a, mapToTypeMap, typeToConstructor } from './utils';
|
||||
import AbstractArray from './AbstractArray';
|
||||
|
||||
type AnyTuple = AnyU8a | string | (Codec | AnyU8a | AnyNumber | AnyString | undefined | null)[];
|
||||
|
||||
type TupleConstructors = Constructor[] | {
|
||||
[index: string]: Constructor;
|
||||
};
|
||||
@@ -18,7 +20,7 @@ type TupleTypes = (Constructor | keyof InterfaceTypes)[] | {
|
||||
};
|
||||
|
||||
/** @internal */
|
||||
function decodeTuple (registry: Registry, _Types: TupleConstructors, value: AnyU8a | string | (AnyU8a | AnyNumber | AnyString | undefined | null)[]): Codec[] {
|
||||
function decodeTuple (registry: Registry, _Types: TupleConstructors, value?: AnyTuple): Codec[] {
|
||||
if (isU8a(value)) {
|
||||
return decodeU8a(registry, value, _Types);
|
||||
} else if (isHex(value)) {
|
||||
@@ -31,11 +33,15 @@ function decodeTuple (registry: Registry, _Types: TupleConstructors, value: AnyU
|
||||
|
||||
return Types.map((Type, index): Codec => {
|
||||
try {
|
||||
if (value?.[index] instanceof Type) return value[index] as any;
|
||||
const entry = value?.[index];
|
||||
|
||||
return new Type(registry, value?.[index]);
|
||||
if (entry instanceof Type) {
|
||||
return entry;
|
||||
}
|
||||
|
||||
return new Type(registry, entry);
|
||||
} catch (error) {
|
||||
throw new Error(`Tuple: failed on ${index}:: ${error.message}`);
|
||||
throw new Error(`Tuple: failed on ${index}:: ${(error as Error).message}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -49,7 +55,7 @@ function decodeTuple (registry: Registry, _Types: TupleConstructors, value: AnyU
|
||||
export default class Tuple extends AbstractArray<Codec> {
|
||||
private _Types: TupleConstructors;
|
||||
|
||||
constructor (registry: Registry, Types: TupleTypes, value?: any) {
|
||||
constructor (registry: Registry, Types: TupleTypes, value?: AnyTuple) {
|
||||
const Clazzes = Array.isArray(Types)
|
||||
? Types.map((type): Constructor => typeToConstructor(registry, type))
|
||||
: mapToTypeMap(registry, Types);
|
||||
@@ -61,7 +67,7 @@ export default class Tuple extends AbstractArray<Codec> {
|
||||
|
||||
public static with (Types: TupleTypes): Constructor<Tuple> {
|
||||
return class extends Tuple {
|
||||
constructor (registry: Registry, value?: any) {
|
||||
constructor (registry: Registry, value?: AnyTuple) {
|
||||
super(registry, Types, value);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -48,7 +48,7 @@ export default class U8aFixed extends Raw {
|
||||
|
||||
public static with (bitLength: BitLength, typeName?: string): Constructor<U8aFixed> {
|
||||
return class extends U8aFixed {
|
||||
constructor (registry: Registry, value?: any) {
|
||||
constructor (registry: Registry, value?: AnyU8a) {
|
||||
super(registry, value, bitLength);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ describe('UInt', (): void => {
|
||||
|
||||
it('allows for construction via BigInt', (): void => {
|
||||
expect(
|
||||
new UInt(registry, 123_456_789_123_456_789_123_456_789n, 128).toHuman()
|
||||
new UInt(registry, 123456789123456789123456789n, 128).toHuman()
|
||||
).toEqual('123,456,789,123,456,789,123,456,789');
|
||||
});
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ export default class UInt extends AbstractInt {
|
||||
|
||||
public static with (bitLength: UIntBitLength, typeName?: string): Constructor<UInt> {
|
||||
return class extends UInt {
|
||||
constructor (registry: Registry, value?: any) {
|
||||
constructor (registry: Registry, value?: AnyNumber) {
|
||||
super(registry, value, bitLength);
|
||||
}
|
||||
|
||||
|
||||
@@ -124,7 +124,7 @@ describe('Vec', (): void => {
|
||||
|
||||
it('exposes a working reduce', (): void => {
|
||||
expect(
|
||||
vector.reduce((r, e): string => `${r}${e}`, '')
|
||||
vector.reduce((r, e): string => `${r}${e.toString()}`, '')
|
||||
).toEqual('123345456756789');
|
||||
});
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ const MAX_LENGTH = 32768;
|
||||
export default class Vec<T extends Codec> extends AbstractArray<T> {
|
||||
private _Type: Constructor<T>;
|
||||
|
||||
constructor (registry: Registry, Type: Constructor<T> | keyof InterfaceTypes, value: Vec<any> | Uint8Array | string | any[] = [] as any[]) {
|
||||
constructor (registry: Registry, Type: Constructor<T> | keyof InterfaceTypes, value: Vec<Codec> | Uint8Array | string | unknown[] = []) {
|
||||
const Clazz = typeToConstructor<T>(registry, Type);
|
||||
|
||||
super(registry, ...Vec.decodeVec(registry, Clazz, value));
|
||||
@@ -31,15 +31,16 @@ export default class Vec<T extends Codec> extends AbstractArray<T> {
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
public static decodeVec<T extends Codec> (registry: Registry, Type: Constructor<T>, value: Vec<any> | Uint8Array | string | any[]): T[] {
|
||||
public static decodeVec<T extends Codec> (registry: Registry, Type: Constructor<T>, value: Vec<Codec> | Uint8Array | string | unknown[]): T[] {
|
||||
if (Array.isArray(value)) {
|
||||
return value.map((entry, index): T => {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return (value as unknown[]).map((entry: unknown, index: number): T => {
|
||||
try {
|
||||
return entry instanceof Type
|
||||
? entry
|
||||
: new Type(registry, entry);
|
||||
} catch (error) {
|
||||
console.error(`Unable to decode Vec on index ${index}`, error.message);
|
||||
console.error(`Unable to decode Vec on index ${index}`, (error as Error).message);
|
||||
|
||||
throw error;
|
||||
}
|
||||
@@ -72,7 +73,7 @@ export default class Vec<T extends Codec> extends AbstractArray<T> {
|
||||
/**
|
||||
* @description Finds the index of the value in the array
|
||||
*/
|
||||
public indexOf (_other?: any): number {
|
||||
public indexOf (_other?: unknown): number {
|
||||
// convert type first, this removes overhead from the eq
|
||||
const other = _other instanceof this._Type
|
||||
? _other
|
||||
|
||||
@@ -2,15 +2,17 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { isFunction, isUndefined } from '@polkadot/util';
|
||||
import { isUndefined } from '@polkadot/util';
|
||||
|
||||
import { hasEq } from './util';
|
||||
|
||||
// NOTE These are used internally and when comparing objects, expects that
|
||||
// when the second is an Codec[] that the first has to be as well
|
||||
export default function compareArray (a: any[], b?: any): boolean {
|
||||
export default function compareArray (a: unknown[], b?: unknown): boolean {
|
||||
if (Array.isArray(b)) {
|
||||
return (a.length === b.length) && isUndefined(
|
||||
a.find((value, index): boolean =>
|
||||
isFunction(value.eq)
|
||||
hasEq(value)
|
||||
? !value.eq(b[index])
|
||||
: value !== b[index]
|
||||
)
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { isFunction, isObject, isUndefined } from '@polkadot/util';
|
||||
import { isObject, isUndefined } from '@polkadot/util';
|
||||
|
||||
function hasMismatch (a?: any, b?: any): boolean {
|
||||
import { hasEq } from './util';
|
||||
|
||||
function hasMismatch (a?: unknown, b?: unknown): boolean {
|
||||
return isUndefined(a) || (
|
||||
// Codec has .eq, use it here
|
||||
isFunction(a.eq)
|
||||
hasEq(a)
|
||||
? !a.eq(b)
|
||||
: a !== b
|
||||
);
|
||||
@@ -26,7 +27,7 @@ function compareMapArray (a: Map<any, any>, b: [any, any][]): boolean {
|
||||
|
||||
// NOTE These are used internally and when comparing objects, expects that
|
||||
// when the second is an Map<string, Codec> that the first has to be as well
|
||||
export default function compareMap (a: Map<any, any>, b?: any): boolean {
|
||||
export default function compareMap (a: Map<any, any>, b?: unknown): boolean {
|
||||
if (Array.isArray(b)) {
|
||||
return compareMapArray(a, b);
|
||||
} else if (b instanceof Map) {
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
|
||||
import { isObject } from '@polkadot/util';
|
||||
|
||||
function compareSetArray (a: Set<any>, b: any[]): boolean {
|
||||
function compareSetArray (a: Set<unknown>, b: any[]): boolean {
|
||||
// equal number of entries and each entry in the array should match
|
||||
return (a.size === b.length) && !b.some((entry): boolean => !a.has(entry));
|
||||
}
|
||||
|
||||
// NOTE These are used internally and when comparing objects, expects that
|
||||
// when the second is an Set<string, Codec> that the first has to be as well
|
||||
export default function compareSet (a: Set<any>, b?: any): boolean {
|
||||
export default function compareSet (a: Set<unknown>, b?: unknown): boolean {
|
||||
if (Array.isArray(b)) {
|
||||
return compareSetArray(a, b);
|
||||
} else if (b instanceof Set) {
|
||||
|
||||
@@ -20,6 +20,7 @@ export function paramsNotation (outer: string, inner?: string | any[], transform
|
||||
return `${outer}${arrayStr}`;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
function encodeWithParams (typeDef: Pick<TypeDef, any>, outer = typeDef.displayName || typeDef.type): string {
|
||||
const { info, params, sub } = typeDef;
|
||||
|
||||
@@ -39,11 +40,13 @@ function encodeWithParams (typeDef: Pick<TypeDef, any>, outer = typeDef.displayN
|
||||
(param: TypeDef) => displayType(param)
|
||||
);
|
||||
default:
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return outer;
|
||||
}
|
||||
}
|
||||
|
||||
function encodeDoNotConstruct ({ displayName }: TypeDef): string {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
return `DoNotEncode<${displayName}>`;
|
||||
}
|
||||
|
||||
@@ -79,6 +82,7 @@ function encodeEnum (typeDef: Pick<TypeDef, any>): string {
|
||||
if (isClikeEnum) {
|
||||
return `[${
|
||||
sub
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
.map(({ name }: TypeDef): string => `"${name}"`)
|
||||
.join(', ')
|
||||
}]`;
|
||||
@@ -117,6 +121,7 @@ function encodeUInt ({ length }: Pick<TypeDef, any>, type: 'Int' | 'UInt'): stri
|
||||
function encodeVecFixed ({ length, sub }: Pick<TypeDef, any>): string {
|
||||
assert(isNumber(length) && !isUndefined(sub), 'Unable to encode VecFixed type');
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/restrict-template-expressions
|
||||
return `[${sub.type};${length}]`;
|
||||
}
|
||||
|
||||
@@ -147,7 +152,7 @@ const encoders: Record<TypeDefInfo, (typeDef: TypeDef) => string> = {
|
||||
export function encodeType (typeDef: Pick<TypeDef, any>): string {
|
||||
const encoder = encoders[(typeDef as TypeDef).info];
|
||||
|
||||
assert(encoder, `Cannot encode type: ${typeDef}.`);
|
||||
assert(encoder, `Cannot encode type: ${typeDef.toString()}`);
|
||||
|
||||
return encoder(typeDef as TypeDef);
|
||||
}
|
||||
@@ -168,12 +173,14 @@ export function displayType (typeDef: Pick<TypeDef, any>): string {
|
||||
}
|
||||
|
||||
export function withTypeString (typeDef: Pick<TypeDef, any>): Pick<TypeDef, any> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const type = SPECIAL_TYPES.includes(typeDef.displayName)
|
||||
? typeDef.displayName
|
||||
: encodeType(typeDef);
|
||||
|
||||
return {
|
||||
...typeDef,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
type
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { isFunction } from '@polkadot/util';
|
||||
|
||||
export function hasEq (o: unknown): o is { eq: (other: unknown) => boolean } {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
return isFunction((o as any).eq);
|
||||
}
|
||||
@@ -43,6 +43,7 @@ export function ClassOfUnsafe<T extends Codec = Codec, K extends string = string
|
||||
export function ClassOf<K extends keyof InterfaceTypes> (registry: Registry, name: K): Constructor<InterfaceTypes[K]> {
|
||||
// TS2589: Type instantiation is excessively deep and possibly infinite.
|
||||
// The above happens with as Constructor<InterfaceTypes[K]>;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return ClassOfUnsafe<Codec, K>(registry, name) as any;
|
||||
}
|
||||
|
||||
@@ -67,7 +68,7 @@ function getTypeClassMap (value: TypeDef): Record<string, keyof InterfaceTypes>
|
||||
const result: Record<string, keyof InterfaceTypes> = {};
|
||||
|
||||
return getSubDefArray(value).reduce((result, sub): Record<string, keyof InterfaceTypes> => {
|
||||
result[sub.name as string] = sub.type as any;
|
||||
result[sub.name as string] = sub.type as keyof InterfaceTypes;
|
||||
|
||||
return result;
|
||||
}, result);
|
||||
@@ -113,7 +114,9 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
|
||||
// eslint-disable-next-line sort-keys
|
||||
const Clazz = Struct.with({ previous: type, next: type } as any);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
ClassOf.prototype.toRawType = function (): string {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call
|
||||
return `Linkage<${this.next.toRawType(true)}>`;
|
||||
};
|
||||
|
||||
|
||||
@@ -178,14 +178,18 @@ describe('createType', (): void => {
|
||||
}
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const cmpDef: any = createTypeUnsafe(registry, 'TestComplex');
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call
|
||||
expect(cmpDef.balance.bitLength()).toEqual(128);
|
||||
|
||||
registry.register({ Balance: 'u32' });
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const cmpu32: any = createTypeUnsafe(registry, 'TestComplex');
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call
|
||||
expect(cmpu32.balance.bitLength()).toEqual(32);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -44,6 +44,7 @@ function checkInstance<T extends Codec = Codec, K extends string = string> (valu
|
||||
// where isPedantic is specified (storage decoding), also check the format/structure
|
||||
function initType<T extends Codec = Codec, K extends string = string> (registry: Registry, Type: Constructor<FromReg<T, K>>, params: any[] = [], isPedantic?: boolean): FromReg<T, K> {
|
||||
const created = new Type(registry, ...params);
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const [value] = params;
|
||||
|
||||
if (isPedantic && isU8a(value)) {
|
||||
@@ -63,7 +64,7 @@ export function createTypeUnsafe<T extends Codec = Codec, K extends string = str
|
||||
// it provides false warning which is more hinderance than help
|
||||
return initType(registry, createClass<T, K>(registry, type), params); // , isPedantic);
|
||||
} catch (error) {
|
||||
throw new Error(`createType(${type}):: ${error.message}`);
|
||||
throw new Error(`createType(${type}):: ${(error as Error).message}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,8 @@ function _decodeSet (value: TypeDef, details: Record<string, number>): TypeDef {
|
||||
// decode a struct, set or enum
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function _decodeStruct (value: TypeDef, type: string, _: string): TypeDef {
|
||||
const parsed = JSON.parse(type);
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const parsed: Record<string, any> = JSON.parse(type);
|
||||
const keys = Object.keys(parsed);
|
||||
|
||||
if (keys.length === 1 && keys[0] === '_enum') {
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
|
||||
import { Codec, Constructor } from '../types';
|
||||
|
||||
import { isChildClass } from '@polkadot/util';
|
||||
@@ -70,6 +72,7 @@ describe('TypeRegistry', (): void => {
|
||||
const first = new Recursive(registry, { next: last });
|
||||
|
||||
expect((first as any).next.isSome).toBe(true);
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
expect((first as any).next.unwrap().next.isSome).toBe(false);
|
||||
});
|
||||
|
||||
@@ -122,7 +125,9 @@ describe('TypeRegistry', (): void => {
|
||||
});
|
||||
|
||||
expect(struct instanceof Struct).toBe(true);
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
expect(struct.foo.toNumber()).toEqual(42);
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||
expect(struct.bar.toString()).toEqual('testing');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -48,6 +48,7 @@ function decorateEvents (registry: Registry, metadata: RegistryMetadata, metadat
|
||||
section.events.unwrap().forEach((meta, methodIndex): void => {
|
||||
const methodName = meta.name.toString();
|
||||
const eventIndex = new Uint8Array([sectionIndex, methodIndex]);
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
||||
const typeDef = meta.args.map((arg): TypeDef => getTypeDef(arg.toString()));
|
||||
let Types: Constructor<Codec>[] = [];
|
||||
|
||||
@@ -79,9 +80,9 @@ function decorateExtrinsics (registry: Registry, metadata: RegistryMetadata, met
|
||||
}
|
||||
|
||||
export class TypeRegistry implements Registry {
|
||||
readonly #classes: Map<string, Constructor> = new Map();
|
||||
readonly #classes = new Map<string, Constructor>();
|
||||
|
||||
readonly #definitions: Map<string, string> = new Map();
|
||||
readonly #definitions = new Map<string, string>();
|
||||
|
||||
readonly #metadataCalls: Record<string, CallFunction> = {};
|
||||
|
||||
@@ -89,7 +90,7 @@ export class TypeRegistry implements Registry {
|
||||
|
||||
readonly #metadataEvents: Record<string, Constructor<EventData>> = {};
|
||||
|
||||
readonly #unknownTypes: Map<string, boolean> = new Map();
|
||||
readonly #unknownTypes = new Map<string, boolean>();
|
||||
|
||||
#chainProperties?: ChainProperties;
|
||||
|
||||
@@ -101,7 +102,9 @@ export class TypeRegistry implements Registry {
|
||||
// we only want to import these on creation, i.e. we want to avoid types
|
||||
// weird side-effects from circular references. (Since registry is injected
|
||||
// into types, this can be a real concern now)
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const baseTypes: RegistryTypes = require('../index.types');
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const definitions: Record<string, { types: RegistryTypes }> = require('../interfaces/definitions');
|
||||
|
||||
// since these are classes, they are injected first
|
||||
@@ -143,6 +146,7 @@ export class TypeRegistry implements Registry {
|
||||
* @describe Creates an instance of the class
|
||||
*/
|
||||
public createClass <K extends keyof InterfaceTypes> (type: K): Constructor<InterfaceTypes[K]> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return createClass(this, type) as any;
|
||||
}
|
||||
|
||||
@@ -158,7 +162,7 @@ export class TypeRegistry implements Registry {
|
||||
const hexIndex = u8aToHex(callIndex);
|
||||
const fn = this.#metadataCalls[hexIndex];
|
||||
|
||||
assert(!isUndefined(fn), `findMetaCall: Unable to find Call with index ${hexIndex}/[${callIndex}]`);
|
||||
assert(!isUndefined(fn), `findMetaCall: Unable to find Call with index ${hexIndex}/[${callIndex.toString()}]`);
|
||||
|
||||
return fn;
|
||||
}
|
||||
@@ -172,7 +176,7 @@ export class TypeRegistry implements Registry {
|
||||
);
|
||||
const error = this.#metadataErrors[hexIndex];
|
||||
|
||||
assert(!isUndefined(error), `findMetaError: Unable to find Error with index ${hexIndex}/[${errorIndex}]`);
|
||||
assert(!isUndefined(error), `findMetaError: Unable to find Error with index ${hexIndex}/[${errorIndex.toString()}]`);
|
||||
|
||||
return error;
|
||||
}
|
||||
@@ -181,7 +185,7 @@ export class TypeRegistry implements Registry {
|
||||
const hexIndex = u8aToHex(eventIndex);
|
||||
const Event = this.#metadataEvents[hexIndex];
|
||||
|
||||
assert(!isUndefined(Event), `findMetaEvent: Unable to find Event with index ${hexIndex}/[${eventIndex}]`);
|
||||
assert(!isUndefined(Event), `findMetaEvent: Unable to find Event with index ${hexIndex}/[${eventIndex.toString()}]`);
|
||||
|
||||
return Event;
|
||||
}
|
||||
|
||||
@@ -203,11 +203,11 @@ export class MortalEra extends Tuple {
|
||||
* The era for an extrinsic, indicating either a mortal or immortal extrinsic
|
||||
*/
|
||||
export default class ExtrinsicEra extends Enum implements IExtrinsicEra {
|
||||
constructor (registry: Registry, value?: any) {
|
||||
constructor (registry: Registry, value?: unknown) {
|
||||
super(registry, {
|
||||
ImmortalEra,
|
||||
MortalEra
|
||||
}, ExtrinsicEra._decodeExtrinsicEra(value));
|
||||
}, ExtrinsicEra._decodeExtrinsicEra(value as string));
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
|
||||
@@ -113,7 +113,7 @@ export default class ExtrinsicPayload extends Base<ExtrinsicPayloadVx> {
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
public eq (other?: any): boolean {
|
||||
public eq (other?: unknown): boolean {
|
||||
return this._raw.eq(other);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import Struct from '../codec/Struct';
|
||||
* A default handler for payloads where the version is not known (default throw)
|
||||
*/
|
||||
export default class ExtrinsicPayloadUnknown extends Struct {
|
||||
constructor (registry: Registry, value?: any, { version = 0 }: Partial<ExtrinsicPayloadOptions> = {}) {
|
||||
constructor (registry: Registry, value?: unknown, { version = 0 }: Partial<ExtrinsicPayloadOptions> = {}) {
|
||||
super(registry, {});
|
||||
|
||||
throw new Error(`Unsupported extrinsic payload version ${version}`);
|
||||
|
||||
@@ -14,7 +14,7 @@ import { UNMASK_VERSION } from './constants';
|
||||
* A default handler for extrinsics where the version is not known (default throw)
|
||||
*/
|
||||
export default class ExtrinsicUnknown extends Struct {
|
||||
constructor (registry: Registry, value?: any, { isSigned = false, version = 0 }: Partial<ExtrinsicOptions> = {}) {
|
||||
constructor (registry: Registry, value?: unknown, { isSigned = false, version = 0 }: Partial<ExtrinsicOptions> = {}) {
|
||||
super(registry, {});
|
||||
|
||||
throw new Error(`Unsupported ${isSigned ? '' : 'un'}signed extrinsic version ${version & UNMASK_VERSION}`);
|
||||
|
||||
@@ -29,7 +29,7 @@ export interface SignerPayloadType extends Codec {
|
||||
|
||||
// We explicitly cast the type here to get the actual TypeScript exports right
|
||||
// We can ignore the properties, added via Struct.with
|
||||
const _Payload: Constructor<SignerPayloadType> = Struct.with({
|
||||
const _Payload = Struct.with({
|
||||
address: 'Address',
|
||||
blockHash: 'Hash',
|
||||
blockNumber: 'BlockNumber',
|
||||
@@ -41,7 +41,7 @@ const _Payload: Constructor<SignerPayloadType> = Struct.with({
|
||||
signedExtensions: 'Vec<Text>',
|
||||
tip: 'Compact<Balance>',
|
||||
version: 'u8'
|
||||
}) as any;
|
||||
}) as unknown as Constructor<SignerPayloadType>;
|
||||
|
||||
/**
|
||||
* @name SignerPayload
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
|
||||
import { TypeRegistry } from '../create';
|
||||
import Raw from '../codec/Raw';
|
||||
import jsonVec from '../json/AccountIdVec.001.json';
|
||||
|
||||
@@ -10,7 +10,7 @@ import { decodeAddress, encodeAddress } from '@polkadot/util-crypto';
|
||||
import U8aFixed from '../codec/U8aFixed';
|
||||
|
||||
/** @internal */
|
||||
function decodeAccountId (value: AnyU8a | AnyString): Uint8Array {
|
||||
function decodeAccountId (value: AnyU8a | AnyString): AnyU8a {
|
||||
if (isU8a(value) || Array.isArray(value)) {
|
||||
return u8aToU8a(value);
|
||||
} else if (isHex(value)) {
|
||||
@@ -41,8 +41,8 @@ export default class AccountId extends U8aFixed {
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
public eq (other?: any): boolean {
|
||||
return super.eq(decodeAccountId(other));
|
||||
public eq (other?: unknown): boolean {
|
||||
return super.eq(decodeAccountId(other as AnyU8a));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -18,7 +18,7 @@ describe('AccountIndex', (): void => {
|
||||
|
||||
it('creates from BigInt', (): void => {
|
||||
expect(
|
||||
registry.createType('AccountIndex', 336_794_129n).toNumber()
|
||||
registry.createType('AccountIndex', 336794129n).toNumber()
|
||||
).toEqual(336794129);
|
||||
});
|
||||
|
||||
|
||||
@@ -85,9 +85,9 @@ export default class AccountIndex extends U32 {
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
public eq (other?: any): boolean {
|
||||
public eq (other?: unknown): boolean {
|
||||
// shortcut for BN or Number, don't create an object
|
||||
if (isBn(other) || isNumber(other)) {
|
||||
if (isBn(other as string) || isNumber(other)) {
|
||||
return super.eq(other);
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
/* eslint-disable sort-keys */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
|
||||
import Metadata from '@polkadot/metadata/Metadata';
|
||||
import metadataStatic from '@polkadot/metadata/Metadata/static';
|
||||
|
||||
@@ -12,7 +12,7 @@ import Struct from '../codec/Struct';
|
||||
import U8aFixed from '../codec/U8aFixed';
|
||||
|
||||
interface DecodeMethodInput {
|
||||
args: any;
|
||||
args: unknown;
|
||||
callIndex: CallIndex | Uint8Array;
|
||||
}
|
||||
|
||||
@@ -90,14 +90,14 @@ function decodeCallViaU8a (registry: Registry, value: Uint8Array, _meta?: Functi
|
||||
* necessary.
|
||||
* @internal
|
||||
*/
|
||||
function decodeCall (registry: Registry, value: DecodedMethod | Uint8Array | string = new Uint8Array(), _meta?: FunctionMetadataLatest): DecodedMethod {
|
||||
function decodeCall (registry: Registry, value: unknown | DecodedMethod | Uint8Array | string = new Uint8Array(), _meta?: FunctionMetadataLatest): DecodedMethod {
|
||||
if (isHex(value) || isU8a(value)) {
|
||||
return decodeCallViaU8a(registry, u8aToU8a(value), _meta);
|
||||
return decodeCallViaU8a(registry, u8aToU8a(value as string), _meta);
|
||||
} else if (isObject(value) && value.callIndex && value.args) {
|
||||
return decodeCallViaObject(registry, value, _meta);
|
||||
return decodeCallViaObject(registry, value as DecodedMethod, _meta);
|
||||
}
|
||||
|
||||
throw new Error(`Call: Cannot decode value '${value}' of type ${typeof value}`);
|
||||
throw new Error(`Call: Cannot decode value '${value as string}' of type ${typeof value}`);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,7 +120,7 @@ export class CallIndex extends U8aFixed {
|
||||
export default class Call extends Struct implements IMethod {
|
||||
protected _meta: FunctionMetadataLatest;
|
||||
|
||||
constructor (registry: Registry, value: any, meta?: FunctionMetadataLatest) {
|
||||
constructor (registry: Registry, value: unknown, meta?: FunctionMetadataLatest) {
|
||||
const decoded = decodeCall(registry, value, meta);
|
||||
|
||||
super(registry, {
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
|
||||
import { ExtrinsicStatus } from './types';
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
|
||||
@@ -8,9 +8,9 @@
|
||||
import { Definitions } from '../../types';
|
||||
|
||||
const AllHashers = {
|
||||
Blake2_128: null, // eslint-disable-line @typescript-eslint/camelcase
|
||||
Blake2_256: null, // eslint-disable-line @typescript-eslint/camelcase
|
||||
Blake2_128Concat: null, // eslint-disable-line @typescript-eslint/camelcase
|
||||
Blake2_128: null, // eslint-disable-line camelcase
|
||||
Blake2_256: null, // eslint-disable-line camelcase
|
||||
Blake2_128Concat: null, // eslint-disable-line camelcase
|
||||
Twox128: null,
|
||||
Twox256: null,
|
||||
Twox64Concat: null,
|
||||
@@ -238,8 +238,8 @@ export default {
|
||||
},
|
||||
StorageHasherV4: {
|
||||
_enum: {
|
||||
Blake2_128: null, // eslint-disable-line @typescript-eslint/camelcase
|
||||
Blake2_256: null, // eslint-disable-line @typescript-eslint/camelcase
|
||||
Blake2_128: null, // eslint-disable-line camelcase
|
||||
Blake2_256: null, // eslint-disable-line camelcase
|
||||
Twox128: null,
|
||||
Twox256: null,
|
||||
Twox64Concat: null
|
||||
@@ -440,9 +440,9 @@ export default {
|
||||
},
|
||||
StorageHasherV10: {
|
||||
_enum: {
|
||||
Blake2_128: null, // eslint-disable-line @typescript-eslint/camelcase
|
||||
Blake2_256: null, // eslint-disable-line @typescript-eslint/camelcase
|
||||
Blake2_128Concat: null, // eslint-disable-line @typescript-eslint/camelcase
|
||||
Blake2_128: null, // eslint-disable-line camelcase
|
||||
Blake2_256: null, // eslint-disable-line camelcase
|
||||
Blake2_128Concat: null, // eslint-disable-line camelcase
|
||||
Twox128: null,
|
||||
Twox256: null,
|
||||
Twox64Concat: null
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
import json3 from '../../json/Header.003.json';
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
|
||||
import Metadata from '@polkadot/metadata/Metadata';
|
||||
import metadataStatic from '@polkadot/metadata/Metadata/static';
|
||||
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
|
||||
import { RuntimeVersion } from './types';
|
||||
|
||||
import { TypeRegistry } from '../../create';
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
|
||||
import { TypeRegistry } from '@polkadot/types';
|
||||
|
||||
import json from '../../json/StorageChangeSet.001.json';
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
||||
|
||||
import Metadata from '@polkadot/metadata/Metadata';
|
||||
import rpcMetadataV1 from '@polkadot/metadata/Metadata/v1/static';
|
||||
import rpcMetadata from '@polkadot/metadata/Metadata/static';
|
||||
@@ -42,12 +45,12 @@ describe('EventRecord', (): void => {
|
||||
|
||||
it('decodes EventRecord with topics correctly', (): void => {
|
||||
const hex = json3.params.result.changes[0][1];
|
||||
const records = registry.createType('Vec<EventRecord>', hex, true) as any;
|
||||
const records = registry.createType('Vec<EventRecord>', hex, true);
|
||||
const er = records[0];
|
||||
|
||||
expect(er.phase.type).toEqual('ApplyExtrinsic');
|
||||
// additional payment info, weight u64 (vs u32)
|
||||
expect(records.toHex()).toEqual(hex + '000000000000' + '00000000');
|
||||
expect(records.toHex()).toEqual(`${hex as string}00000000000000000000`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -73,7 +73,7 @@ export default class Bool extends Boolean implements Codec {
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
public eq (other?: any): boolean {
|
||||
public eq (other?: unknown): boolean {
|
||||
return this.valueOf() === (
|
||||
other instanceof Boolean
|
||||
? other.valueOf()
|
||||
@@ -113,7 +113,7 @@ export default class Bool extends Boolean implements Codec {
|
||||
* @description Returns the string representation of the value
|
||||
*/
|
||||
public toString (): string {
|
||||
return `${this.toJSON()}`;
|
||||
return this.toJSON().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,7 +43,7 @@ export default class Null implements Codec {
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
public eq (other?: any): boolean {
|
||||
public eq (other?: unknown): boolean {
|
||||
return other instanceof Null || isNull(other);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,9 +34,9 @@ interface StorageKeyExtra {
|
||||
|
||||
const HASHER_MAP: Record<keyof typeof AllHashers, [number, boolean]> = {
|
||||
// opaque
|
||||
Blake2_128: [16, false], // eslint-disable-line @typescript-eslint/camelcase
|
||||
Blake2_128Concat: [16, true], // eslint-disable-line @typescript-eslint/camelcase
|
||||
Blake2_256: [32, false], // eslint-disable-line @typescript-eslint/camelcase
|
||||
Blake2_128: [16, false], // eslint-disable-line camelcase
|
||||
Blake2_128Concat: [16, true], // eslint-disable-line camelcase
|
||||
Blake2_256: [32, false], // eslint-disable-line camelcase
|
||||
Identity: [0, true],
|
||||
Twox128: [16, false],
|
||||
Twox256: [32, false],
|
||||
@@ -92,7 +92,7 @@ function decodeStorageKey (value?: AnyU8a | StorageKey | StorageEntry | [Storage
|
||||
section: value.section
|
||||
};
|
||||
} else if (Array.isArray(value)) {
|
||||
const [fn, ...arg]: [StorageEntry, ...any[]] = value as any;
|
||||
const [fn, ...arg] = value as [StorageEntry, ...any[]];
|
||||
|
||||
assert(isFunction(fn), 'Expected function input for key construction');
|
||||
|
||||
@@ -103,7 +103,7 @@ function decodeStorageKey (value?: AnyU8a | StorageKey | StorageEntry | [Storage
|
||||
};
|
||||
}
|
||||
|
||||
throw new Error(`Unable to convert input ${value} to StorageKey`);
|
||||
throw new Error(`Unable to convert input ${value as string} to StorageKey`);
|
||||
}
|
||||
|
||||
function decodeHashers (registry: Registry, value: Uint8Array, hashers: [StorageHasher, string][]): Codec[] {
|
||||
@@ -152,7 +152,7 @@ function decodeArgsFromMeta (registry: Registry, value: Uint8Array, meta?: Stora
|
||||
* constructed by passing in a raw key or a StorageEntry with (optional) arguments.
|
||||
*/
|
||||
export default class StorageKey extends Bytes {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-ignore
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore This is assigned via this.decodeArgsFromMeta()
|
||||
private _args: Codec[];
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ function decodeText (value: Text | string | AnyU8a | { toString: () => string })
|
||||
return u8aToString(value.subarray(offset, total));
|
||||
}
|
||||
|
||||
return `${value}`;
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -90,7 +90,7 @@ export default class Text extends String implements Codec {
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
public eq (other?: any): boolean {
|
||||
public eq (other?: unknown): boolean {
|
||||
return isString(other)
|
||||
? this.toString() === other.toString()
|
||||
: false;
|
||||
|
||||
@@ -14,7 +14,7 @@ import U32 from './U32';
|
||||
* It is not to be used, since it created consensus mismatches.
|
||||
*/
|
||||
export default class USize extends U32 {
|
||||
constructor (registry: Registry, value?: any) {
|
||||
constructor (registry: Registry, value?: unknown) {
|
||||
super(registry, value);
|
||||
|
||||
throw new Error('The `usize` type should not be used. Since it is platform-specific, it creates incompatibilities between native (generally u64) and WASM (always u32) code. Use one of the `u32` or `u64` types explicitly.');
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
/* eslint-disable @typescript-eslint/interface-name-prefix */
|
||||
|
||||
import { H256 } from '../interfaces/runtime';
|
||||
import { AnyJson, BareOpts } from './helpers';
|
||||
@@ -57,7 +56,7 @@ export interface Codec {
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
eq (other?: any): boolean;
|
||||
eq (other?: unknown): boolean;
|
||||
|
||||
/**
|
||||
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
||||
|
||||
@@ -8,8 +8,7 @@ export type DefinitionTypeEnum = { _enum: DefinitionTypeType[] } | { _enum: Reco
|
||||
|
||||
export type DefinitionTypeSet = { _set: Record<string, number> };
|
||||
|
||||
// Don't believe the `& object` here is proper, but cannot do `& Record<string, DefinitionTypeType>`
|
||||
export type DefinitionTypeStruct = Record<string, DefinitionTypeType> | { _alias?: Record<string, DefinitionTypeType> } & object;
|
||||
export type DefinitionTypeStruct = Record<string, DefinitionTypeType> | { _alias?: Record<string, DefinitionTypeType> } & Record<string, unknown>;
|
||||
|
||||
export type DefinitionType = string | DefinitionTypeEnum | DefinitionTypeSet | DefinitionTypeStruct;
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import { Codec } from './codec';
|
||||
import { AnyJson, AnyNumber, AnyU8a } from './helpers';
|
||||
import { ICompact, IKeyringPair, IMethod, IRuntimeVersion } from './interfaces';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
|
||||
export interface ISubmittableResult {
|
||||
readonly events: EventRecord[];
|
||||
readonly status: ExtrinsicStatus;
|
||||
@@ -85,34 +84,29 @@ export interface ExtrinsicPayloadValue {
|
||||
transactionVersion: AnyNumber;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
|
||||
export interface IExtrinsicSignature extends ExtrinsicSignatureBase, Codec {
|
||||
addSignature (signer: Address | Uint8Array | string, signature: Uint8Array | string, payload: Uint8Array | string): IExtrinsicSignature;
|
||||
sign (method: Call, account: IKeyringPair, options: SignatureOptions): IExtrinsicSignature;
|
||||
signFake (method: Call, address: Address | Uint8Array | string, options: SignatureOptions): IExtrinsicSignature;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
|
||||
export interface IExtrinsicEra extends Codec {
|
||||
asImmortalEra: Codec;
|
||||
asMortalEra: Codec;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
|
||||
interface IExtrinsicSignable<T> {
|
||||
addSignature (signer: Address | Uint8Array | string, signature: Uint8Array | string, payload: ExtrinsicPayloadValue | Uint8Array | string): T;
|
||||
sign (account: IKeyringPair, options: SignatureOptions): T;
|
||||
signFake (address: Address | Uint8Array | string, options: SignatureOptions): T;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
|
||||
export interface IExtrinsicImpl extends IExtrinsicSignable<IExtrinsicImpl>, Codec {
|
||||
readonly method: Call;
|
||||
readonly signature: IExtrinsicSignature;
|
||||
readonly version: number;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
|
||||
export interface IExtrinsic extends IExtrinsicSignable<IExtrinsic>, ExtrinsicSignatureBase, IMethod {
|
||||
readonly length: number;
|
||||
readonly method: Call;
|
||||
@@ -206,7 +200,6 @@ export interface SignerPayloadRaw extends SignerPayloadRawBase {
|
||||
type: 'bytes' | 'payload';
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
|
||||
export interface ISignerPayload {
|
||||
toPayload (): SignerPayloadJSON;
|
||||
toRaw (): SignerPayloadRaw;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
/* eslint-disable @typescript-eslint/interface-name-prefix */
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import { SignOptions } from '@polkadot/keyring/types';
|
||||
@@ -21,7 +20,6 @@ export interface IKeyringPair {
|
||||
sign: (data: Uint8Array, options?: SignOptions) => Uint8Array;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
|
||||
export interface IMethod extends Codec {
|
||||
readonly args: Codec[];
|
||||
readonly argsDef: ArgsDef;
|
||||
@@ -47,7 +45,6 @@ export interface IRuntimeVersion {
|
||||
|
||||
// A type alias for [Type1, Type2] & Codec, representing a tuple (Type1, Type2)
|
||||
// FIXME Implement this generic <Sub> on Tuple.ts itself.
|
||||
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
|
||||
export type ITuple<Sub extends Codec[]> = Sub & Codec
|
||||
|
||||
export interface IU8a extends Uint8Array, Codec {
|
||||
|
||||
@@ -115,7 +115,7 @@ export interface Registry {
|
||||
readonly signedExtensions: string[];
|
||||
|
||||
findMetaCall (callIndex: Uint8Array): CallFunction;
|
||||
findMetaError (errorIndex: Uint8Array): any;
|
||||
findMetaError (errorIndex: Uint8Array): RegistryError;
|
||||
// due to same circular imports where types don't really want to import from EventData,
|
||||
// keep this as a generic Codec, however the actual impl. returns the correct
|
||||
findMetaEvent (eventIndex: Uint8Array): Constructor<any>;
|
||||
|
||||
Reference in New Issue
Block a user