BigInt support (& some TS typing cleanups) (#1919)

* Some TS typing cleanups

* docs building again

* yarn.lock rewrite

* tweaks

* BigInt support

* Checktypes with BigInt

* AccountIndex support for BigInt

* Fix ApiPromise signAsync
This commit is contained in:
Jaco Greeff
2020-02-21 17:26:05 +01:00
committed by GitHub
parent 429b797b23
commit 4540495a44
34 changed files with 401 additions and 434 deletions
+3 -2
View File
@@ -1,7 +1,8 @@
# 1.4.0-beta.x
- Add support for `api.rpc.chain.subscribeAllHeads` (not just best) (Thanks to https://github.com/jak-pan)
- Add support for `api.rpc.engine.*` for manual seal support
- Add `api.rpc.chain.subscribeAllHeads` (not just best) (Thanks to https://github.com/jak-pan)
- Add `api.rpc.engine.*` for manual seal support
- Support JS `BigInt` inputs in any `UInt` and `Int` object, `api.tx.balances.transfer(..., 9876543210123456789n)`
- Expand `.toHuman` on `ExtrinsicEra`, `SubmittableResult` & `Vote`
- Remove `GenericDigestItem`, the `DigestItem` is now a type interface via `@polkadot/types/interfaces`
- Move `Fixed64`, `H160`, `H256` & `H512` to interfaces in `@polkadot/types/interfaces`
+2 -2
View File
@@ -8,7 +8,7 @@
"packages/*"
],
"resolutions": {
"typescript": "^3.7.5"
"typescript": "^3.8.2"
},
"scripts": {
"build": "yarn build:interfaces && polkadot-dev-build-ts && (cd packages/typegen && copyfiles scripts/* build)",
@@ -26,7 +26,7 @@
"@babel/core": "^7.8.4",
"@babel/register": "^7.8.3",
"@babel/runtime": "^7.8.4",
"@polkadot/dev": "^0.40.19",
"@polkadot/dev": "^0.40.22",
"@polkadot/ts": "^0.2.3",
"copyfiles": "^2.2.0"
}
+15 -3
View File
@@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountId, Header } from '@polkadot/types/interfaces';
import { AnyJsonObject, Constructor, Registry } from '@polkadot/types/types';
import { AnyJson, Constructor, Registry } from '@polkadot/types/types';
import runtimeTypes from '@polkadot/types/interfaces/runtime/definitions';
import { Struct } from '@polkadot/types';
@@ -54,12 +54,24 @@ export default class HeaderExtended extends _Header {
return this._author;
}
/**
* @description Creates a human-friendly JSON representation
*/
public toHuman (isExtended?: boolean): AnyJson {
return {
...super.toHuman(isExtended) as { [index: string]: AnyJson },
author: this.author
? this.author.toHuman()
: undefined
};
}
/**
* @description Creates the JSON representation
*/
public toJSON (): AnyJsonObject {
public toJSON (): AnyJson {
return {
...super.toJSON() as AnyJsonObject,
...super.toJSON() as { [index: string]: AnyJson },
author: this.author
? this.author.toJSON()
: undefined
@@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { ReferendumIndex, ReferendumInfo } from '@polkadot/types/interfaces/democracy';
import { AnyJsonObject, Constructor, Registry } from '@polkadot/types/types';
import { AnyJson, Constructor, Registry } from '@polkadot/types/types';
import BN from 'bn.js';
import democracyTypes from '@polkadot/types/interfaces/democracy/definitions';
@@ -35,12 +35,22 @@ export default class ReferendumInfoExtended extends _ReferendumInfo {
return this._index;
}
/**
* @description Creates a human-friendly JSON representation
*/
public toHuman (isExtended?: boolean): AnyJson {
return {
...super.toHuman(isExtended) as { [index: string]: AnyJson },
index: this.index.toHuman(isExtended)
};
}
/**
* @description Creates the JSON representation
*/
public toJSON (): AnyJsonObject {
public toJSON (): AnyJson {
return {
...super.toJSON() as AnyJsonObject,
...super.toJSON() as { [index: string]: AnyJson },
index: this.index.toJSON()
};
}
+2 -1
View File
@@ -89,7 +89,8 @@ function types (): void {
}
async function tx (api: ApiPromise, keyring: TestKeyringMap): Promise<void> {
const transfer = api.tx.balances.transfer(keyring.bob.address, 12345);
// transfer, also allows for BigInt inputs here
const transfer = api.tx.balances.transfer(keyring.bob.address, 123_456_789n);
console.log('transfer as Call', transfer as IMethod);
console.log('transfer as Extrinsic', transfer as IExtrinsic);
+2 -5
View File
@@ -121,15 +121,12 @@ describe('ApiPromise', (): void => {
const signer = new SingleAccountSigner(registry, aliceEd);
const api = await ApiPromise.create({ provider, registry, signer });
const transfer = api.tx.balances.transfer(keyring.getPair('0xe659a7a1628cdd93febc04a4e0646ea20e9f5f0ce097d9a05290d4a9e054df4e').address, 12345);
const transfer = api.tx.balances.transfer(keyring.getPair('0xe659a7a1628cdd93febc04a4e0646ea20e9f5f0ce097d9a05290d4a9e054df4e').address, 321_564_789_876_512_345n);
await transfer.signAsync(aliceEd.address, {});
expect(transfer.signature.toHex()).toEqual(
// v1 extrinsic
// '0x6b9ccc95afbd4e916d30c65c720f4f7b70a77db545735b48a763844aa5210e695aa346686bad1224af77d00bcfbf6fc8d2c216a60731027835d5a414186a2607'
// v4 extrinsic
'0x0716cbdc3b649dad8741238bcc8e4336f859c518cf2b17a3427b2f5d0b8a79cf518da71b9ac71d92c517342e0978f297f5e05362babf5987d3f1c5ba3314af08'
'0x62bfcd07a9f50ba32ed9e2c41ca11267ac62a24c95949e25efdccc4989d48573f84754dbbaa1d0937ceb888ad8a2cf71daced1545a839d9d6cceac33a5771401'
);
});
});
@@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { Call } from '@polkadot/types/interfaces';
import { AnyJsonObject, CallFunction, Registry, RegistryMetadataCall } from '@polkadot/types/types';
import { AnyJson, CallFunction, Registry, RegistryMetadataCall } from '@polkadot/types/types';
// we do a direct import here to remove all circular dependencies (importing from
// /types, /types/codec or /types/create makes all hell break loose)
@@ -31,7 +31,7 @@ export default function createDescriptor (registry: Registry, section: string, s
extrinsicFn.meta = callMetadata;
extrinsicFn.method = funcName;
extrinsicFn.section = section;
extrinsicFn.toJSON = (): string | AnyJsonObject =>
extrinsicFn.toJSON = (): AnyJson =>
callMetadata.toJSON();
return extrinsicFn as CallFunction;
@@ -3,12 +3,12 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { MetadataLatest } from '@polkadot/types/interfaces/metadata';
import { AnyJsonObject, Registry } from '@polkadot/types/types';
import { AnyJson, Registry } from '@polkadot/types/types';
import { createType } from '@polkadot/types/create';
/** @internal */
export default function toCallsOnly (registry: Registry, { extrinsic, modules }: MetadataLatest): AnyJsonObject | string {
export default function toCallsOnly (registry: Registry, { extrinsic, modules }: MetadataLatest): AnyJson {
return createType(registry, 'MetadataLatest', {
// FIXME, this needs typing, not any
modules: modules.map(({ calls, name }): any => ({
+3 -3
View File
@@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { H256 } from '../interfaces/runtime';
import { AnyJson, AnyJsonArray, Codec, Registry } from '../types';
import { AnyJson, Codec, Registry } from '../types';
import { u8aConcat, u8aToHex } from '@polkadot/util';
import { blake2AsU8a } from '@polkadot/util-crypto';
@@ -83,7 +83,7 @@ export default abstract class AbstractArray<T extends Codec> extends Array<T> im
/**
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
*/
public toHuman (isExtended?: boolean): AnyJsonArray {
public toHuman (isExtended?: boolean): AnyJson {
return this.map((entry): AnyJson =>
entry.toHuman(isExtended)
);
@@ -92,7 +92,7 @@ export default abstract class AbstractArray<T extends Codec> extends Array<T> im
/**
* @description Converts the Object to JSON, typically used for RPC transfers
*/
public toJSON (): AnyJsonArray {
public toJSON (): AnyJson {
return this.map((entry): AnyJson =>
entry.toJSON()
);
+7
View File
@@ -15,6 +15,11 @@ export type UIntBitLength = 8 | 16 | 32 | 64 | 128 | 256;
export const DEFAULT_UINT_BITS = 64;
// TODO Impot this from util once supported there
export function isBigInt (value: any): value is BigInt {
return typeof value === 'bigint';
}
/**
* @name AbstractInt
* @ignore
@@ -51,6 +56,8 @@ export default abstract class AbstractInt extends BN implements Codec {
return hexToBn(value, { isLe: false, isNegative }).toString();
} else if (isU8a(value)) {
return AbstractInt.decodeAbstracIntU8a(value, bitLength, isNegative);
} else if (isBigInt(value)) {
return value.toString();
} else if (isString(value)) {
return new BN(value, 10).toString();
}
+3 -3
View File
@@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { H256 } from '../interfaces/runtime';
import { AnyJsonArray, Constructor, Codec, InterfaceTypes, Registry } from '../types';
import { AnyJson, Constructor, Codec, InterfaceTypes, Registry } from '../types';
import { isHex, hexToU8a, isU8a, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
import { blake2AsU8a } from '@polkadot/util-crypto';
@@ -144,7 +144,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): AnyJsonArray {
public toHuman (isExtended?: boolean): AnyJson {
const json: any = [];
this.forEach((v: V) => {
@@ -157,7 +157,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 (): AnyJsonArray {
public toJSON (): AnyJson {
const json: any = [];
this.forEach((v: V) => {
+6
View File
@@ -107,6 +107,12 @@ 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()
).toEqual('123,456,789,000,123,456,789');
});
it('has the correct bitLength for constructor values (BlockNumber)', (): void => {
expect(
new (Compact.with(ClassOf(registry, 'BlockNumber')))(registry, 0xfffffff9).bitLength()
+3 -1
View File
@@ -9,7 +9,7 @@ import { compactAddLength, compactFromU8a, compactStripLength, compactToU8a, isB
import { DEFAULT_BITLENGTH } from '@polkadot/util/compact/defaults';
import { typeToConstructor } from './utils';
import { UIntBitLength } from './AbstractInt';
import { UIntBitLength, isBigInt } from './AbstractInt';
import Base from './Base';
export interface CompactEncodable extends Codec {
@@ -60,6 +60,8 @@ export default class Compact<T extends CompactEncodable> extends Base<T> impleme
public static decodeCompact<T extends CompactEncodable> (registry: Registry, Type: Constructor<T>, value: Compact<T> | AnyNumber): CompactEncodable {
if (value instanceof Compact) {
return new Type(registry, value.raw);
} else if (isBigInt(value)) {
return new Type(registry, value.toString());
} else if (isString(value) || isNumber(value) || isBn(value)) {
return new Type(registry, value);
}
+3 -3
View File
@@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { H256 } from '../interfaces/runtime';
import { AnyJsonObject, BareOpts, Codec, Constructor, ConstructorDef, InterfaceTypes, Registry } from '../types';
import { AnyJson, BareOpts, Codec, Constructor, ConstructorDef, InterfaceTypes, Registry } from '../types';
import { hexToU8a, isBoolean, isHex, isObject, isU8a, isUndefined, u8aConcat, u8aToHex } from '@polkadot/util';
import { blake2AsU8a } from '@polkadot/util-crypto';
@@ -232,7 +232,7 @@ 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): AnyJsonObject {
public toHuman (isExtended?: boolean): AnyJson {
return [...this.keys()].reduce((json, key): any => {
const jsonKey = this._jsonMap.get(key) || key;
const value = this.get(key);
@@ -246,7 +246,7 @@ export default class Struct<
/**
* @description Converts the Object to JSON, typically used for RPC transfers
*/
public toJSON (): AnyJsonObject {
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 => {
+5 -5
View File
@@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { H256 } from '../interfaces/runtime';
import { AnyJsonObject, Codec, Registry } from '../types';
import { AnyJson, Codec, Registry } from '../types';
import { isUndefined } from '@polkadot/util';
import { blake2AsU8a } from '@polkadot/util-crypto';
@@ -87,19 +87,19 @@ export default class StructAny extends Map<string, any> implements Codec {
/**
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
*/
public toHuman (): AnyJsonObject {
public toHuman (): AnyJson {
return this.toJSON();
}
/**
* @description Converts the Object to JSON, typically used for RPC transfers
*/
public toJSON (): AnyJsonObject {
return [...this.entries()].reduce((json, [key, value]): AnyJsonObject => {
public toJSON (): AnyJson {
return [...this.entries()].reduce((json: { [index: string]: AnyJson }, [key, value]): { [index: string]: AnyJson } => {
json[key] = value;
return json;
}, {} as any);
}, {});
}
/**
+6
View File
@@ -16,6 +16,12 @@ describe('UInt', (): void => {
).toThrow('u32: Input too large. Found input with 164 bits, expected 32');
});
it('allows for construction via BigInt', (): void => {
expect(
new UInt(registry, 123_456_789_123_456_789_123_456_789n, 128).toHuman()
).toEqual('123,456,789,123,456,789,123,456,789');
});
it('provides a toBn interface', (): void => {
expect(
new UInt(registry, 987).toBn().toNumber()
+2 -2
View File
@@ -5,7 +5,7 @@
import { FunctionMetadataLatest } from '../interfaces/metadata/types';
import { EcdsaSignature, Ed25519Signature, ExtrinsicUnknown, ExtrinsicV1, ExtrinsicV2, ExtrinsicV3, ExtrinsicV4, Sr25519Signature } from '../interfaces/extrinsics';
import { Address, Balance, Call, Index } from '../interfaces/runtime';
import { ArgsDef, AnyJsonObject, AnyU8a, Codec, ExtrinsicPayloadValue, IExtrinsic, IKeyringPair, InterfaceTypes, Registry, SignatureOptions } from '../types';
import { AnyJson, AnyU8a, ArgsDef, Codec, ExtrinsicPayloadValue, IExtrinsic, IKeyringPair, InterfaceTypes, Registry, SignatureOptions } from '../types';
import { assert, isHex, isU8a, u8aConcat, u8aToHex, u8aToU8a } from '@polkadot/util';
@@ -253,7 +253,7 @@ export default class Extrinsic extends Base<ExtrinsicVx | ExtrinsicUnknown> impl
/**
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
*/
public toHuman (isExpanded?: boolean): AnyJsonObject {
public toHuman (isExpanded?: boolean): AnyJson {
return {
method: this.method.toHuman(isExpanded),
isSigned: this.isSigned,
@@ -4,7 +4,7 @@
import { ExtrinsicPayloadV1, ExtrinsicPayloadV2, ExtrinsicPayloadV3, ExtrinsicPayloadV4 } from '../interfaces/extrinsics';
import { Balance, Hash, Index } from '../interfaces/runtime';
import { AnyJsonObject, BareOpts, ExtrinsicPayloadValue, IKeyringPair, InterfaceTypes, Registry } from '../types';
import { AnyJson, BareOpts, ExtrinsicPayloadValue, IKeyringPair, InterfaceTypes, Registry } from '../types';
import { u8aToHex } from '@polkadot/util';
@@ -128,7 +128,7 @@ export default class ExtrinsicPayload extends Base<ExtrinsicPayloadVx> {
/**
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
*/
public toHuman (isExtended?: boolean): AnyJsonObject {
public toHuman (isExtended?: boolean): AnyJson {
return this.raw.toHuman(isExtended);
}
@@ -29,7 +29,7 @@ describe('ExtrinsicV2', (): void => {
expect(
new Extrinsic(
registry,
decorated.tx.balances.transfer(keyring.bob.publicKey, 6969)
decorated.tx.balances.transfer(keyring.bob.publicKey, 6969n)
).toHex()
).toEqual(
'0x' +
@@ -44,7 +44,7 @@ describe('ExtrinsicV2', (): void => {
expect(
new Extrinsic(
registry,
decorated.tx.balances.transfer(keyring.bob.publicKey, 6969)
decorated.tx.balances.transfer(keyring.bob.publicKey, 6969n)
).sign(keyring.alice, {
blockHash: '0xec7afaf1cca720ce88c1d1b689d81f0583cc15a97d621cf046dd9abf605ef22f',
genesisHash: '0xdcd1346701ca8396496e52aa2785b1748deb6db09551b72159dcb3e08991025b',
@@ -29,7 +29,7 @@ describe('ExtrinsicV3', (): void => {
expect(
new Extrinsic(
registry,
decorated.tx.balances.transfer(keyring.bob.publicKey, 6969)
decorated.tx.balances.transfer(keyring.bob.publicKey, 6969n)
).toHex()
).toEqual(
'0x' +
@@ -44,7 +44,7 @@ describe('ExtrinsicV3', (): void => {
expect(
new Extrinsic(
registry,
decorated.tx.balances.transfer(keyring.bob.publicKey, 6969)
decorated.tx.balances.transfer(keyring.bob.publicKey, 6969n)
).sign(keyring.alice, {
blockHash: '0xec7afaf1cca720ce88c1d1b689d81f0583cc15a97d621cf046dd9abf605ef22f',
genesisHash: '0xdcd1346701ca8396496e52aa2785b1748deb6db09551b72159dcb3e08991025b',
@@ -29,7 +29,7 @@ describe('ExtrinsicV4', (): void => {
expect(
new Extrinsic(
registry,
decorated.tx.balances.transfer(keyring.bob.publicKey, 6969)
decorated.tx.balances.transfer(keyring.bob.publicKey, 6969n)
).toHex()
).toEqual(
'0x' +
@@ -44,7 +44,7 @@ describe('ExtrinsicV4', (): void => {
expect(
new Extrinsic(
registry,
decorated.tx.balances.transfer(keyring.bob.publicKey, 6969)
decorated.tx.balances.transfer(keyring.bob.publicKey, 6969n)
).sign(keyring.alice, {
blockHash: '0xec7afaf1cca720ce88c1d1b689d81f0583cc15a97d621cf046dd9abf605ef22f',
genesisHash: '0xdcd1346701ca8396496e52aa2785b1748deb6db09551b72159dcb3e08991025b',
@@ -16,6 +16,12 @@ describe('AccountIndex', (): void => {
).toEqual(336794129);
});
it('creates from BigInt', (): void => {
expect(
createType(registry, 'AccountIndex', 336_794_129n).toNumber()
).toEqual(336794129);
});
it('creates a BN representation (from ss-58)', (): void => {
expect(
createType(registry, 'AccountIndex', 'Mwz15xP2').toNumber()
+16 -14
View File
@@ -9,6 +9,7 @@ import { bnToBn, isBn, isNumber, isU8a, isHex } from '@polkadot/util';
import { decodeAddress, encodeAddress } from '@polkadot/util-crypto';
import { createType } from '../create';
import { isBigInt } from '../codec/AbstractInt';
import U32 from '../primitive/U32';
export const ENUMSET_SIZE = new BN(64);
@@ -21,6 +22,20 @@ const MAX_1BYTE = new BN(PREFIX_1BYTE);
const MAX_2BYTE = new BN(1).shln(16);
const MAX_4BYTE = new BN(1).shln(32);
/** @internal */
function decodeAccountIndex (value: AnyNumber): BN | BigInt | Uint8Array | number | string {
// eslint-disable-next-line @typescript-eslint/no-use-before-define
if (value instanceof AccountIndex) {
// `value.toBn()` on AccountIndex returns a pure BN (i.e. not an
// AccountIndex), which has the initial `toString()` implementation.
return value.toBn();
} else if (isBn(value) || isNumber(value) || isHex(value) || isU8a(value) || isBigInt(value)) {
return value;
}
return decodeAccountIndex(decodeAddress(value));
}
/**
* @name AccountIndex
* @description
@@ -29,20 +44,7 @@ const MAX_4BYTE = new BN(1).shln(32);
*/
export default class AccountIndex extends U32 {
constructor (registry: Registry, value: AnyNumber = new BN(0)) {
super(registry, AccountIndex.decodeAccountIndex(value));
}
/** @internal */
public static decodeAccountIndex (value: AnyNumber): BN | Uint8Array | number | string {
if (value instanceof AccountIndex) {
// `value.toBn()` on AccountIndex returns a pure BN (i.e. not an
// AccountIndex), which has the initial `toString()` implementation.
return value.toBn();
} else if (isBn(value) || isNumber(value) || isHex(value) || isU8a(value)) {
return value;
}
return AccountIndex.decodeAccountIndex(decodeAddress(value));
super(registry, decodeAccountIndex(value));
}
public static calcLength (_value: BN | number): number {
+1 -1
View File
@@ -55,7 +55,7 @@ export default class Address extends Base<AccountId | AccountIndex> {
}
/** @internal */
public static decodeAddress (registry: Registry, value: AnyAddress): AccountId | AccountIndex {
private static decodeAddress (registry: Registry, value: AnyAddress): AccountId | AccountIndex {
if (value instanceof AccountId || value instanceof AccountIndex) {
return value;
} else if (value instanceof Address) {
+2 -2
View File
@@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { FunctionArgumentMetadataLatest, FunctionMetadataLatest } from '../interfaces/metadata';
import { AnyJsonObject, AnyU8a, ArgsDef, CallFunction, Codec, IMethod, Registry } from '../types';
import { AnyJson, AnyU8a, ArgsDef, CallFunction, Codec, IMethod, Registry } from '../types';
import { isHex, isObject, isU8a, u8aToHex, u8aToU8a } from '@polkadot/util';
@@ -202,7 +202,7 @@ export default class Call extends Struct implements IMethod {
/**
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
*/
public toHuman (isExpanded?: boolean): AnyJsonObject {
public toHuman (isExpanded?: boolean): AnyJson {
let call: CallFunction | undefined;
try {
+2 -2
View File
@@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { DigestItem } from '../interfaces/runtime';
import { Registry, AnyJsonObject } from '../types';
import { AnyJson, Registry } from '../types';
import Struct from '../codec/Struct';
import Vec from '../codec/Vec';
@@ -44,7 +44,7 @@ export default class Digest extends Struct {
/**
* @desrcript The JSON representation as it goes over RPC
*/
public toJSON (): AnyJsonObject {
public toJSON (): AnyJson {
return {
logs: this.logs.map((log): string => log.toHex())
};
+2 -2
View File
@@ -5,7 +5,7 @@
import { TypeDef } from '../create/types';
import { EventMetadataLatest } from '../interfaces/metadata';
import { EventId } from '../interfaces/system';
import { AnyJsonObject, Constructor, Registry, RegistryMetadataEvent } from '../types';
import { AnyJson, Constructor, Registry, RegistryMetadataEvent } from '../types';
import Struct from '../codec/Struct';
import Tuple from '../codec/Tuple';
@@ -146,7 +146,7 @@ export default class Event extends Struct {
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public toHuman (isExpanded?: boolean): AnyJsonObject {
public toHuman (isExpanded?: boolean): AnyJson {
// FIXME May this human-friendly
return this.toJSON();
}
+2 -2
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { AnyJsonObject, ArrayElementType, Registry } from '../types';
import { AnyJson, ArrayElementType, Registry } from '../types';
import democracyDef from '../interfaces/democracy/definitions';
import { Conviction } from '../interfaces/democracy';
@@ -104,7 +104,7 @@ export default class Vote extends U8aFixed {
/**
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
*/
public toHuman (isExpanded?: boolean): AnyJsonObject {
public toHuman (isExpanded?: boolean): AnyJson {
return {
vote: this.isAye ? 'Aye' : 'Nay',
conviction: this.conviction.toHuman(isExpanded)
@@ -31,11 +31,11 @@ export default {
},
WithdrawReasons: {
_set: {
TransactionPayment: 0b00000001,
Transfer: 0b00000010,
Reserve: 0b00000100,
Fee: 0b00001000,
Tip: 0b00010000
TransactionPayment: 0b0000_0001,
Transfer: 0b0000_0010,
Reserve: 0b0000_0100,
Fee: 0b0000_1000,
Tip: 0b0001_0000
}
}
}
@@ -7,16 +7,15 @@ export default {
IdentityFields: {
_set: {
_bitLength: 64,
// Mapped here to the least amount of bits visible, in Rust it is preceded by
// `00000000000000000000000000000000000000000000000000000000' for 64-bits
Display: 0b00000001,
Legal: 0b00000010,
Web: 0b00000100,
Riot: 0b00001000,
Email: 0b00010000,
PgpFingerprint: 0b00100000,
Image: 0b01000000,
Twitter: 0b10000000
// Mapped here to 32 bits, in Rust these are 64-bit values
Display: 0b00000000_00000000_00000000_0000_0001,
Legal: 0b00000000_00000000_00000000_0000_0010,
Web: 0b00000000_00000000_00000000_0000_0100,
Riot: 0b00000000_00000000_00000000_0000_1000,
Email: 0b00000000_00000000_00000000_0001_0000,
PgpFingerprint: 0b00000000_00000000_00000000_0010_0000,
Image: 0b00000000_00000000_00000000_0100_0000,
Twitter: 0b00000000_00000000_00000000_1000_0000
}
},
IdentityInfoAdditional: '(Data, Data)',
+2 -5
View File
@@ -11,14 +11,11 @@ import BN from 'bn.js';
export type ArgsDef = Record<string, Constructor>;
// We cannot inline this into CodecArg, TS thrws up when building docs
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface CodecArgArray extends Array<CodecArg> {}
interface CodecArgObject {
[index: string]: CodecArg;
}
export type CodecArg = Codec | BN | boolean | string | Uint8Array | boolean | number | string | undefined | CodecArgArray | CodecArgObject;
export type CodecArg = Codec | BN | boolean | string | Uint8Array | boolean | number | string | undefined | CodecArgArray | { [index: string]: CodecArg };
export type CodecTo = 'toHex' | 'toJSON' | 'toString' | 'toU8a';
+15 -17
View File
@@ -8,6 +8,21 @@ import { InterfaceRegistry } from '../interfaceRegistry';
export type InterfaceTypes = keyof InterfaceRegistry;
// We cannot inline this into CodecArg, TS thrws up when building docs
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type AnyFunction = (...args: any[]) => any;
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface AnyJsonArray extends Array<AnyJson> {}
export type AnyJson = string | number | boolean | null | undefined | AnyJsonArray | { [index: string]: AnyJson };
export type AnyNumber = BN | BigInt | Uint8Array | number | string;
export type AnyString = string | string;
export type AnyU8a = Uint8Array | number[] | string;
// helper to extract keys from an array
export type ArrayElementType<T extends ReadonlyArray<unknown>> = T extends ReadonlyArray<infer ElementType>
? ElementType
@@ -16,20 +31,3 @@ export type ArrayElementType<T extends ReadonlyArray<unknown>> = T extends Reado
export type BareOpts = boolean | Record<string, boolean>;
export type Callback<T> = (result: T) => void | Promise<void>;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export type AnyFunction = (...args: any[]) => any;
export type AnyNumber = BN | Uint8Array | number | string;
export type AnyString = string | string;
export type AnyU8a = Uint8Array | number[] | string;
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface AnyJsonObject extends Record<string, AnyJson> {}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface AnyJsonArray extends Array<AnyJson> {}
export type AnyJson = string | number | boolean | null | undefined | AnyJsonObject | AnyJsonArray;
+5 -8
View File
@@ -8,7 +8,7 @@ import BN from 'bn.js';
import { CallFunction } from './calls';
import { Codec, Constructor } from './codec';
import { AnyJsonObject, InterfaceTypes } from './helpers';
import { AnyJson, InterfaceTypes } from './helpers';
export type RegistryTypes = Record<string, Constructor | string | Record<string, string> | { _enum: string[] | Record<string, string | null> } | { _set: Record<string, number> }>;
@@ -25,7 +25,7 @@ export interface RegistryMetadataCall {
args: RegistryMetadataCallArg[];
name: RegistryMetadataText;
toJSON (): string | AnyJsonObject;
toJSON (): AnyJson;
}
export interface RegistryMetadataCalls {
@@ -41,10 +41,8 @@ export interface RegistryError {
}
export interface RegistryMetadataError {
// eslint-disable-next-line @typescript-eslint/ban-types
name: String;
// eslint-disable-next-line @typescript-eslint/ban-types
documentation: String[];
name: RegistryMetadataText;
documentation: RegistryMetadataText[];
}
export type RegistryMetadataErrors = RegistryMetadataError[];
@@ -61,8 +59,7 @@ export interface RegistryMetadataEvents {
export interface RegistryMetadataExtrinsic {
version: BN;
// eslint-disable-next-line @typescript-eslint/ban-types
signedExtensions: String[];
signedExtensions: RegistryMetadataText[];
}
export interface RegistryMetadataModule {
+247 -321
View File
File diff suppressed because it is too large Load Diff