Don't make types depend on api (dev deps) (#1869)

* Don't make types depend on api (dev deps)

* Naming cleanups

* Remove skipped tests

* Splt types/types into chunks

* Re-add setChainProperties (properties?: ChainProperties): void;
This commit is contained in:
Jaco Greeff
2020-02-16 13:13:56 +01:00
committed by GitHub
parent 1ddad84d7e
commit 6e535b0502
15 changed files with 556 additions and 505 deletions
+3 -3
View File
@@ -2,9 +2,9 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ApiTypes, DecorateMethod, SubmittableResultImpl } from '@polkadot/api/types';
import { ApiTypes, DecorateMethod } from '@polkadot/api/types';
import { AccountId, Address, Hash } from '@polkadot/types/interfaces';
import { IKeyringPair } from '@polkadot/types/types';
import { IKeyringPair, ISubmittableResult } from '@polkadot/types/types';
import { ApiObject, ContractABIPre } from '../types';
import BN from 'bn.js';
@@ -27,7 +27,7 @@ export interface BlueprintCreate<ApiType extends ApiTypes> {
class BlueprintCreateResult<ApiType extends ApiTypes> extends SubmittableResult {
public readonly contract?: Contract<ApiType>;
constructor (result: SubmittableResultImpl, contract?: Contract<ApiType>) {
constructor (result: ISubmittableResult, contract?: Contract<ApiType>) {
super(result);
this.contract = contract;
+4 -4
View File
@@ -2,9 +2,9 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ApiTypes, DecorateMethod, SubmittableResultImpl } from '@polkadot/api/types';
import { ApiTypes, DecorateMethod } from '@polkadot/api/types';
import { AccountId, Address, Hash } from '@polkadot/types/interfaces';
import { IKeyringPair } from '@polkadot/types/types';
import { IKeyringPair, ISubmittableResult } from '@polkadot/types/types';
import { ApiObject, ContractABIPre } from '../types';
import BN from 'bn.js';
@@ -27,7 +27,7 @@ export interface CodePutCode<ApiType extends ApiTypes> {
class CodePutCodeResult<ApiType extends ApiTypes> extends SubmittableResult {
public readonly blueprint?: Blueprint<ApiType>;
constructor (result: SubmittableResultImpl, blueprint?: Blueprint<ApiType>) {
constructor (result: ISubmittableResult, blueprint?: Blueprint<ApiType>) {
super(result);
this.blueprint = blueprint;
@@ -55,7 +55,7 @@ export default class Code<ApiType extends ApiTypes> extends BaseWithTx<ApiType>
};
}
private createResult = (result: SubmittableResultImpl): CodePutCodeResult<ApiType> => {
private createResult = (result: ISubmittableResult): CodePutCodeResult<ApiType> => {
let blueprint: Blueprint<ApiType> | undefined;
if (result.isInBlock) {
+3 -2
View File
@@ -3,9 +3,10 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { ExtrinsicStatus, EventRecord } from '@polkadot/types/interfaces';
import { SubmittableResultImpl, SubmittableResultValue } from './types';
import { ISubmittableResult } from '@polkadot/types/types';
import { SubmittableResultValue } from './types';
export default class SubmittableResult implements SubmittableResultImpl {
export default class SubmittableResult implements ISubmittableResult {
public readonly events: EventRecord[];
public readonly status: ExtrinsicStatus;
+14 -14
View File
@@ -4,9 +4,9 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountData, Address, Call, ExtrinsicEra, ExtrinsicStatus, Hash, Header, Index, RuntimeDispatchInfo } from '@polkadot/types/interfaces';
import { Callback, Codec, Constructor, IKeyringPair, ITuple, Registry, SignatureOptions } from '@polkadot/types/types';
import { Callback, Codec, Constructor, IKeyringPair, ITuple, Registry, SignatureOptions, ISubmittableResult } from '@polkadot/types/types';
import { ApiInterfaceRx, ApiTypes, SignerResult } from '../types';
import { AddressOrPair, SignerOptions, SubmittableExtrinsic, SubmittablePaymentResult, SubmittableResultImpl, SubmittableResultResult, SubmittableResultSubscription, SubmittableThis } from './types';
import { AddressOrPair, SignerOptions, SubmittableExtrinsic, SubmittablePaymentResult, SubmittableResultResult, SubmittableResultSubscription, SubmittableThis } from './types';
import { Observable, combineLatest, of } from 'rxjs';
import { first, map, mapTo, mergeMap, switchMap, tap } from 'rxjs/operators';
@@ -93,20 +93,20 @@ export default function createClass <ApiType extends ApiTypes> ({ api, apiType,
public signAndSend (account: AddressOrPair, options?: Partial<SignerOptions>): SubmittableResultResult<ApiType>;
// signAndSend with a subscription, i.e. callback provided
public signAndSend (account: AddressOrPair, statusCb: Callback<SubmittableResultImpl>): SubmittableResultSubscription<ApiType>;
public signAndSend (account: AddressOrPair, statusCb: Callback<ISubmittableResult>): SubmittableResultSubscription<ApiType>;
// signAndSend with options and a callback
public signAndSend (account: AddressOrPair, options: Partial<SignerOptions>, statusCb?: Callback<SubmittableResultImpl>): SubmittableResultSubscription<ApiType>;
public signAndSend (account: AddressOrPair, options: Partial<SignerOptions>, statusCb?: Callback<ISubmittableResult>): SubmittableResultSubscription<ApiType>;
// signAndSend implementation for all 3 cases above
public signAndSend (account: AddressOrPair, optionsOrStatus?: Partial<SignerOptions> | Callback<SubmittableResultImpl>, optionalStatusCb?: Callback<SubmittableResultImpl>): SubmittableResultResult<ApiType> | SubmittableResultSubscription<ApiType> {
public signAndSend (account: AddressOrPair, optionsOrStatus?: Partial<SignerOptions> | Callback<ISubmittableResult>, optionalStatusCb?: Callback<ISubmittableResult>): SubmittableResultResult<ApiType> | SubmittableResultSubscription<ApiType> {
const [options, statusCb] = this._makeSignAndSendOptions(optionsOrStatus, optionalStatusCb);
const isSubscription = this._api.hasSubscriptions && (this._ignoreStatusCb || !!statusCb);
return this._decorateMethod(
(): Observable<Codec> => (
this._signObservable(account, options).pipe(
switchMap((updateId: number | undefined): Observable<SubmittableResultImpl> | Observable<Hash> =>
switchMap((updateId: number | undefined): Observable<ISubmittableResult> | Observable<Hash> =>
isSubscription
? this._subscribeObservable(updateId)
: this._sendObservable(updateId)
@@ -119,10 +119,10 @@ export default function createClass <ApiType extends ApiTypes> ({ api, apiType,
public send (): SubmittableResultResult<ApiType>;
// send with a status callback
public send (statusCb: Callback<SubmittableResultImpl>): SubmittableResultSubscription<ApiType>;
public send (statusCb: Callback<ISubmittableResult>): SubmittableResultSubscription<ApiType>;
// send implementation for both immediate Hash and statusCb variants
public send (statusCb?: Callback<SubmittableResultImpl>): SubmittableResultResult<ApiType> | SubmittableResultSubscription<ApiType> {
public send (statusCb?: Callback<ISubmittableResult>): SubmittableResultResult<ApiType> | SubmittableResultSubscription<ApiType> {
const isSubscription = this._api.hasSubscriptions && (this._ignoreStatusCb || !!statusCb);
return this._decorateMethod(
@@ -132,7 +132,7 @@ export default function createClass <ApiType extends ApiTypes> ({ api, apiType,
)(statusCb);
}
private _makeSignAndSendOptions (optionsOrStatus?: Partial<SignerOptions> | Callback<SubmittableResultImpl>, statusCb?: Callback<SubmittableResultImpl>): [Partial<SignerOptions>, Callback<SubmittableResultImpl>?] {
private _makeSignAndSendOptions (optionsOrStatus?: Partial<SignerOptions> | Callback<ISubmittableResult>, statusCb?: Callback<ISubmittableResult>): [Partial<SignerOptions>, Callback<ISubmittableResult>?] {
let options: Partial<SignerOptions> = {};
if (isFunction(optionsOrStatus)) {
@@ -249,13 +249,13 @@ export default function createClass <ApiType extends ApiTypes> ({ api, apiType,
]);
}
private _updateSigner (updateId: number, status: Hash | SubmittableResultImpl): void {
private _updateSigner (updateId: number, status: Hash | ISubmittableResult): void {
if ((updateId !== -1) && this._api.signer && this._api.signer.update) {
this._api.signer.update(updateId, status);
}
}
private _statusObservable (status: ExtrinsicStatus): Observable<SubmittableResultImpl> {
private _statusObservable (status: ExtrinsicStatus): Observable<ISubmittableResult> {
if (!status.isFinalized && !status.isInBlock) {
return of(new SubmittableResult({ status }));
}
@@ -268,7 +268,7 @@ export default function createClass <ApiType extends ApiTypes> ({ api, apiType,
this._api.rpc.chain.getBlock(blockHash),
this._api.query.system.events.at(blockHash)
]).pipe(
map(([signedBlock, allEvents]): SubmittableResultImpl =>
map(([signedBlock, allEvents]): ISubmittableResult =>
new SubmittableResult({
events: filterEvents(this.hash, signedBlock, allEvents),
status
@@ -287,11 +287,11 @@ export default function createClass <ApiType extends ApiTypes> ({ api, apiType,
);
}
private _subscribeObservable = (updateId = -1): Observable<SubmittableResultImpl> => {
private _subscribeObservable = (updateId = -1): Observable<ISubmittableResult> => {
return this._api.rpc.author
.submitAndWatchExtrinsic(this)
.pipe(
switchMap((status): Observable<SubmittableResultImpl> =>
switchMap((status): Observable<ISubmittableResult> =>
this._statusObservable(status)
),
tap((status): void => {
+7 -19
View File
@@ -3,23 +3,11 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountId, Address, ExtrinsicStatus, EventRecord, Hash, RuntimeDispatchInfo } from '@polkadot/types/interfaces';
import { AnyNumber, AnyU8a, Callback, Codec, IExtrinsic, IExtrinsicEra, IKeyringPair, SignatureOptions } from '@polkadot/types/types';
import { ApiTypes, Signer } from '../types';
import { AnyNumber, AnyU8a, Callback, Codec, IExtrinsic, IExtrinsicEra, IKeyringPair, SignatureOptions, Signer, ISubmittableResult } from '@polkadot/types/types';
import { ApiTypes } from '../types';
import { Observable } from 'rxjs';
export interface SubmittableResultImpl {
readonly events: EventRecord[];
readonly status: ExtrinsicStatus;
readonly isCompleted: boolean;
readonly isError: boolean;
readonly isFinalized: boolean;
readonly isInBlock: boolean;
filterRecords (section: string, method: string): EventRecord[];
findRecord (section: string, method: string): EventRecord | undefined;
}
export interface SubmittableResultValue {
events?: EventRecord[];
status: ExtrinsicStatus;
@@ -32,12 +20,12 @@ export type SubmittablePaymentResult<ApiType extends ApiTypes> =
export type SubmittableResultResult<ApiType extends ApiTypes> =
ApiType extends 'rxjs'
? Observable<SubmittableResultImpl>
? Observable<ISubmittableResult>
: Promise<Hash>;
export type SubmittableResultSubscription<ApiType extends ApiTypes> =
ApiType extends 'rxjs'
? Observable<SubmittableResultImpl>
? Observable<ISubmittableResult>
: Promise<() => void>;
export type SubmittableThis<ApiType extends ApiTypes, THIS> =
@@ -60,7 +48,7 @@ export interface SubmittableExtrinsic<ApiType extends ApiTypes> extends IExtrins
send(): SubmittableResultResult<ApiType>;
send(statusCb: Callback<SubmittableResultImpl>): SubmittableResultSubscription<ApiType>;
send(statusCb: Callback<ISubmittableResult>): SubmittableResultSubscription<ApiType>;
sign(account: IKeyringPair, _options: Partial<SignatureOptions>): this;
@@ -68,7 +56,7 @@ export interface SubmittableExtrinsic<ApiType extends ApiTypes> extends IExtrins
signAndSend(account: AddressOrPair, options?: Partial<SignerOptions>): SubmittableResultResult<ApiType>;
signAndSend(account: AddressOrPair, statusCb: Callback<SubmittableResultImpl>): SubmittableResultSubscription<ApiType>;
signAndSend(account: AddressOrPair, statusCb: Callback<ISubmittableResult>): SubmittableResultSubscription<ApiType>;
signAndSend(account: AddressOrPair, options: Partial<SignerOptions>, statusCb?: Callback<SubmittableResultImpl>): SubmittableResultSubscription<ApiType>;
signAndSend(account: AddressOrPair, options: Partial<SignerOptions>, statusCb?: Callback<ISubmittableResult>): SubmittableResultSubscription<ApiType>;
}
+2 -32
View File
@@ -11,10 +11,9 @@ import { Constants } from '@polkadot/metadata/Decorated/types';
import { RpcInterface, UserRpc } from '@polkadot/rpc-core/types';
import { Metadata } from '@polkadot/types';
import { Hash, RuntimeVersion } from '@polkadot/types/interfaces';
import { RegistryTypes, SignatureOptions, SignerPayloadJSON, SignerPayloadRaw, Registry } from '@polkadot/types/types';
import { RegistryTypes, Signer, SignerResult, SignatureOptions, Registry } from '@polkadot/types/types';
import ApiBase from '../base';
import { SubmittableResultImpl } from '../submittable/types';
import { DeriveAllSections } from '../util/decorate';
import { DecoratedRpc } from './rpc';
import { QueryableStorage, QueryableStorageMulti } from './storage';
@@ -98,33 +97,4 @@ export interface SignerOptions extends SignatureOptions {
genesisHash: Hash;
}
export interface SignerResult {
/**
* @description The id for this request
*/
id: number;
/**
* @description The resulting signature in hex
*/
signature: string;
}
export interface Signer {
/**
* @description signs an extrinsic payload from a serialized form
*/
signPayload?: (payload: SignerPayloadJSON) => Promise<SignerResult>;
/**
* @description signs a raw payload, only the bytes data as supplied
*/
signRaw?: (raw: SignerPayloadRaw) => Promise<SignerResult>;
/**
* @description Receives an update for the extrinsic signed by a `signer.sign`
*/
update?: (id: number, status: Hash | SubmittableResultImpl) => void;
}
export { ApiBase };
export { ApiBase, Signer, SignerResult };
-431
View File
@@ -1,431 +0,0 @@
// 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 { SignOptions } from '@polkadot/keyring/types';
import { FunctionMetadataLatest } from './interfaces/metadata';
import { ChainProperties } from './interfaces/rpc';
import { Address, Balance, Call, EcdsaSignature, Ed25519Signature, Index, Sr25519Signature } from './interfaces/runtime';
import BN from 'bn.js';
import { InterfaceRegistry } from './interfaceRegistry';
import { Signer } from '@polkadot/api/types';
export * from './codec/types';
// helper to xtract keys from an array
export type ArrayElementType<T extends ReadonlyArray<unknown>> = T extends ReadonlyArray<infer ElementType>
? ElementType
: never;
export type BareOpts = boolean | Record<string, boolean>;
export type InterfaceTypes = keyof InterfaceRegistry;
export interface CallBase {
callIndex: Uint8Array;
meta: FunctionMetadataLatest;
method: string;
section: string;
toJSON: () => any;
}
export interface CallFunction extends CallBase {
(...args: any[]): Call;
}
export type Calls = Record<string, CallFunction>;
export type ModulesWithCalls = Record<string, Calls>;
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
export interface IKeyringPair {
address: string;
publicKey: Uint8Array;
sign: (data: Uint8Array, options?: SignOptions) => Uint8Array;
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
interface CodecArgArray extends Array<CodecArg> {}
export type CodecArg = Codec | BN | boolean | string | Uint8Array | boolean | number | string | undefined | CodecArgArray | CodecArgObject;
export type Callback<T> = (result: T) => void | Promise<void>;
interface CodecArgObject {
[index: string]: CodecArg;
}
// 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;
/**
* @name Codec
* @description
* The base Codec interface. All types implement the interface provided here. Additionally
* implementors can add their own specific interfaces and helpers with getters and functions.
* The Codec Base is however required for operating as an encoding/decoding layer
*/
export interface Codec {
/**
* @description The length of the value when encoded as a Uint8Array
*/
readonly encodedLength: number;
/**
* @description Returns a hash of the value
*/
readonly hash: IHash;
/**
* @description Checks if the value is an empty value
*/
readonly isEmpty: boolean;
/**
* @description The registry associated with this object
*/
readonly registry: Registry;
/**
* @description Compares the value of the input to see if there is a match
*/
eq (other?: any): boolean;
/**
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
*/
toHex (isLe?: boolean): string;
/**
* @description Converts the Object to JSON, typically used for RPC transfers
*/
toJSON (): AnyJson;
/**
* @description Returns the base runtime type name for this instance
*/
toRawType (): string;
/**
* @description Returns the string representation of the value
*/
toString (): string;
/**
* @description Encodes the value as a Uint8Array as per the SCALE specifications
* @param isBare true when the value has none of the type-specific prefixes (internal)
*/
toU8a (isBare?: BareOpts): Uint8Array;
}
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
export interface IU8a extends Uint8Array, Codec {
bitLength (): number;
toJSON (): any;
}
// eslint-disable-next-line @typescript-eslint/interface-name-prefix,@typescript-eslint/no-empty-interface
export interface IHash extends IU8a { }
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
export interface ICompact<T> extends Codec {
toBn (): BN;
toNumber (): number;
unwrap (): T;
}
export type CodecTo = 'toHex' | 'toJSON' | 'toString' | 'toU8a';
export interface Constructor<T = Codec> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
new(registry: Registry, ...value: any[]): T;
}
export type ConstructorDef<T = Codec> = Record<string, Constructor<T>>;
export type RegistryTypes = Record<string, Constructor | string | Record<string, string> | { _enum: string[] | Record<string, string | null> } | { _set: Record<string, number> }>;
export interface RuntimeVersionInterface {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
readonly apis: any[];
readonly authoringVersion: BN;
// eslint-disable-next-line @typescript-eslint/ban-types
readonly implName: String;
readonly implVersion: BN;
// eslint-disable-next-line @typescript-eslint/ban-types
readonly specName: String;
readonly specVersion: BN;
}
export interface SignatureOptions {
blockHash: AnyU8a;
era?: IExtrinsicEra;
genesisHash: AnyU8a;
nonce: AnyNumber;
runtimeVersion: RuntimeVersionInterface;
signer?: Signer;
tip?: AnyNumber;
}
export type ArgsDef = Record<string, Constructor>;
// 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
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
export interface IMethod extends Codec {
readonly args: Codec[];
readonly argsDef: ArgsDef;
readonly callIndex: Uint8Array;
readonly data: Uint8Array;
readonly hash: IHash;
readonly hasOrigin: boolean;
readonly meta: FunctionMetadataLatest;
}
interface ExtrinsicSignatureBase {
readonly isSigned: boolean;
readonly era: IExtrinsicEra;
readonly nonce: ICompact<Index>;
readonly signature: EcdsaSignature | Ed25519Signature | Sr25519Signature;
readonly signer: Address;
readonly tip: ICompact<Balance>;
}
export interface ExtrinsicPayloadValue {
blockHash: AnyU8a;
era: AnyU8a | IExtrinsicEra;
genesisHash: AnyU8a;
method: AnyU8a | IMethod;
nonce: AnyNumber;
specVersion: AnyNumber;
tip: 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;
readonly type: number;
readonly version: number;
}
export interface SignerPayloadJSON {
/**
* @description The ss-58 encoded address
*/
address: string;
/**
* @description The checkpoint hash of the block, in hex
*/
blockHash: string;
/**
* @description The checkpoint block number, in hex
*/
blockNumber: string;
/**
* @description The era for this transaction, in hex
*/
era: string;
/**
* @description The genesis hash of the chain, in hex
*/
genesisHash: string;
/**
* @description The encoded method (with arguments) in hex
*/
method: string;
/**
* @description The nonce for this transaction, in hex
*/
nonce: string;
/**
* @description The current spec version for the runtime
*/
specVersion: string;
/**
* @description The tip for this transaction, in hex
*/
tip: string;
/**
* @description The version of the extrinsic we are dealing with
*/
version: number;
}
export interface SignerPayloadRawBase {
/**
* @description The hex-encoded data for this request
*/
data: string;
/**
* @description The type of the contained data
*/
type?: 'bytes' | 'payload';
}
export interface SignerPayloadRaw extends SignerPayloadRawBase {
/**
* @description The ss-58 encoded address
*/
address: string;
/**
* @description The type of the contained data
*/
type: 'bytes' | 'payload';
}
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
export interface ISignerPayload {
toPayload (): SignerPayloadJSON;
toRaw (): SignerPayloadRaw;
}
export interface RegistryMetadataText extends String, Codec {
setOverride (override: string): void;
}
export interface RegistryMetadataCallArg {
name: RegistryMetadataText;
type: RegistryMetadataText;
}
export interface RegistryMetadataCall {
args: RegistryMetadataCallArg[];
name: RegistryMetadataText;
toJSON (): string | AnyJsonObject;
}
export interface RegistryMetadataCalls {
isSome: boolean;
unwrap (): RegistryMetadataCall[];
}
export interface RegistryError {
documentation: string[];
index: number;
name: string;
section: string;
}
export interface RegistryMetadataError {
// eslint-disable-next-line @typescript-eslint/ban-types
name: String;
// eslint-disable-next-line @typescript-eslint/ban-types
documentation: String[];
}
export type RegistryMetadataErrors = RegistryMetadataError[];
export interface RegistryMetadataEvent {
args: any[];
name: RegistryMetadataText;
}
export interface RegistryMetadataEvents {
isSome: boolean;
unwrap (): RegistryMetadataEvent[];
}
export interface RegistryMetadataExtrinsic {
version: BN;
// eslint-disable-next-line @typescript-eslint/ban-types
signedExtensions: String[];
}
export interface RegistryMetadataModule {
calls: RegistryMetadataCalls;
errors: RegistryMetadataErrors;
events: RegistryMetadataEvents;
name: RegistryMetadataText;
}
export interface RegistryMetadataLatest {
modules: RegistryMetadataModule[];
extrinsic: RegistryMetadataExtrinsic;
}
export interface RegistryMetadata {
asLatest: RegistryMetadataLatest;
}
export interface Registry {
readonly chainDecimals: number;
readonly chainSS58: number | undefined;
readonly chainToken: string;
findMetaCall (callIndex: Uint8Array): CallFunction;
findMetaError (errorIndex: Uint8Array): any;
// 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>;
get <T extends Codec = Codec> (name: string): Constructor<T> | undefined;
getChainProperties (): ChainProperties | undefined;
getDefinition (name: string): string | undefined;
getOrThrow <T extends Codec = Codec> (name: string, msg?: string): Constructor<T>;
getSignedExtensionExtra (): Record<string, InterfaceTypes>;
getSignedExtensionTypes (): Record<string, InterfaceTypes>;
hasClass (name: string): boolean;
hasDef (name: string): boolean;
hasType (name: string): boolean;
register (type: Constructor | RegistryTypes): void;
register (name: string, type: Constructor): void;
register (arg1: string | Constructor | RegistryTypes, arg2?: Constructor): void;
setChainProperties (properties?: ChainProperties): void;
setMetadata (metadata: RegistryMetadata): void;
}
+22
View File
@@ -0,0 +1,22 @@
// 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 { FunctionMetadataLatest } from '../interfaces/metadata';
import { Call } from '../interfaces/runtime';
export interface CallBase {
callIndex: Uint8Array;
meta: FunctionMetadataLatest;
method: string;
section: string;
toJSON: () => any;
}
export interface CallFunction extends CallBase {
(...args: any[]): Call;
}
export type Calls = Record<string, CallFunction>;
export type ModulesWithCalls = Record<string, Calls>;
+89
View File
@@ -0,0 +1,89 @@
// 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 { AnyJson, BareOpts } from './helpers';
import { IHash } from './interfaces';
import { Registry } from './registry';
import BN from 'bn.js';
export type ArgsDef = Record<string, Constructor>;
// 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 CodecTo = 'toHex' | 'toJSON' | 'toString' | 'toU8a';
export interface Constructor<T = Codec> {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
new(registry: Registry, ...value: any[]): T;
}
export type ConstructorDef<T = Codec> = Record<string, Constructor<T>>;
/**
* @name Codec
* @description
* The base Codec interface. All types implement the interface provided here. Additionally
* implementors can add their own specific interfaces and helpers with getters and functions.
* The Codec Base is however required for operating as an encoding/decoding layer
*/
export interface Codec {
/**
* @description The length of the value when encoded as a Uint8Array
*/
readonly encodedLength: number;
/**
* @description Returns a hash of the value
*/
readonly hash: IHash;
/**
* @description Checks if the value is an empty value
*/
readonly isEmpty: boolean;
/**
* @description The registry associated with this object
*/
readonly registry: Registry;
/**
* @description Compares the value of the input to see if there is a match
*/
eq (other?: any): boolean;
/**
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
*/
toHex (isLe?: boolean): string;
/**
* @description Converts the Object to JSON, typically used for RPC transfers
*/
toJSON (): AnyJson;
/**
* @description Returns the base runtime type name for this instance
*/
toRawType (): string;
/**
* @description Returns the string representation of the value
*/
toString (): string;
/**
* @description Encodes the value as a Uint8Array as per the SCALE specifications
* @param isBare true when the value has none of the type-specific prefixes (internal)
*/
toU8a (isBare?: BareOpts): Uint8Array;
}
+198
View File
@@ -0,0 +1,198 @@
// 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 { ExtrinsicStatus } from '../interfaces/rpc';
import { Address, Balance, Call, EcdsaSignature, Ed25519Signature, Index, Sr25519Signature } from '../interfaces/runtime';
import { EventRecord } from '../interfaces/system';
import { Codec } from './codec';
import { AnyNumber, AnyU8a } from './helpers';
import { ICompact, IHash, IKeyringPair, IMethod, IRuntimeVersion } from './interfaces';
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
export interface ISubmittableResult {
readonly events: EventRecord[];
readonly status: ExtrinsicStatus;
readonly isCompleted: boolean;
readonly isError: boolean;
readonly isFinalized: boolean;
readonly isInBlock: boolean;
filterRecords (section: string, method: string): EventRecord[];
findRecord (section: string, method: string): EventRecord | undefined;
}
export interface SignerResult {
/**
* @description The id for this request
*/
id: number;
/**
* @description The resulting signature in hex
*/
signature: string;
}
export interface Signer {
/**
* @description signs an extrinsic payload from a serialized form
*/
signPayload?: (payload: SignerPayloadJSON) => Promise<SignerResult>;
/**
* @description signs a raw payload, only the bytes data as supplied
*/
signRaw?: (raw: SignerPayloadRaw) => Promise<SignerResult>;
/**
* @description Receives an update for the extrinsic signed by a `signer.sign`
*/
update?: (id: number, status: IHash | ISubmittableResult) => void;
}
export interface SignatureOptions {
blockHash: AnyU8a;
era?: IExtrinsicEra;
genesisHash: AnyU8a;
nonce: AnyNumber;
runtimeVersion: IRuntimeVersion;
signer?: Signer;
tip?: AnyNumber;
}
interface ExtrinsicSignatureBase {
readonly isSigned: boolean;
readonly era: IExtrinsicEra;
readonly nonce: ICompact<Index>;
readonly signature: EcdsaSignature | Ed25519Signature | Sr25519Signature;
readonly signer: Address;
readonly tip: ICompact<Balance>;
}
export interface ExtrinsicPayloadValue {
blockHash: AnyU8a;
era: AnyU8a | IExtrinsicEra;
genesisHash: AnyU8a;
method: AnyU8a | IMethod;
nonce: AnyNumber;
specVersion: AnyNumber;
tip: 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;
readonly type: number;
readonly version: number;
}
export interface SignerPayloadJSON {
/**
* @description The ss-58 encoded address
*/
address: string;
/**
* @description The checkpoint hash of the block, in hex
*/
blockHash: string;
/**
* @description The checkpoint block number, in hex
*/
blockNumber: string;
/**
* @description The era for this transaction, in hex
*/
era: string;
/**
* @description The genesis hash of the chain, in hex
*/
genesisHash: string;
/**
* @description The encoded method (with arguments) in hex
*/
method: string;
/**
* @description The nonce for this transaction, in hex
*/
nonce: string;
/**
* @description The current spec version for the runtime
*/
specVersion: string;
/**
* @description The tip for this transaction, in hex
*/
tip: string;
/**
* @description The version of the extrinsic we are dealing with
*/
version: number;
}
export interface SignerPayloadRawBase {
/**
* @description The hex-encoded data for this request
*/
data: string;
/**
* @description The type of the contained data
*/
type?: 'bytes' | 'payload';
}
export interface SignerPayloadRaw extends SignerPayloadRawBase {
/**
* @description The ss-58 encoded address
*/
address: string;
/**
* @description The type of the contained data
*/
type: 'bytes' | 'payload';
}
// eslint-disable-next-line @typescript-eslint/interface-name-prefix
export interface ISignerPayload {
toPayload (): SignerPayloadJSON;
toRaw (): SignerPayloadRaw;
}
+35
View File
@@ -0,0 +1,35 @@
// 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 BN from 'bn.js';
import { InterfaceRegistry } from '../interfaceRegistry';
export type InterfaceTypes = keyof InterfaceRegistry;
// helper to extract keys from an array
export type ArrayElementType<T extends ReadonlyArray<unknown>> = T extends ReadonlyArray<infer ElementType>
? ElementType
: never;
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;
+11
View File
@@ -0,0 +1,11 @@
// 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.
export * from '../codec/types';
export * from './calls';
export * from './codec';
export * from './extrinsic';
export * from './helpers';
export * from './interfaces';
export * from './registry';
+59
View File
@@ -0,0 +1,59 @@
// 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 { SignOptions } from '@polkadot/keyring/types';
import { FunctionMetadataLatest } from '../interfaces/metadata';
import BN from 'bn.js';
import { ArgsDef, Codec } from './codec';
export interface ICompact<T> extends Codec {
toBn (): BN;
toNumber (): number;
unwrap (): T;
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface IHash extends IU8a { }
export interface IKeyringPair {
address: string;
publicKey: Uint8Array;
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;
readonly callIndex: Uint8Array;
readonly data: Uint8Array;
readonly hash: IHash;
readonly hasOrigin: boolean;
readonly meta: FunctionMetadataLatest;
}
export interface IRuntimeVersion {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
readonly apis: any[];
readonly authoringVersion: BN;
// eslint-disable-next-line @typescript-eslint/ban-types
readonly implName: String;
readonly implVersion: BN;
// eslint-disable-next-line @typescript-eslint/ban-types
readonly specName: String;
readonly specVersion: BN;
}
// 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 {
bitLength (): number;
toJSON (): any;
}
+109
View File
@@ -0,0 +1,109 @@
// 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 { ChainProperties } from '../interfaces/rpc';
import BN from 'bn.js';
import { CallFunction } from './calls';
import { Codec, Constructor } from './codec';
import { AnyJsonObject, InterfaceTypes } from './helpers';
export type RegistryTypes = Record<string, Constructor | string | Record<string, string> | { _enum: string[] | Record<string, string | null> } | { _set: Record<string, number> }>;
export interface RegistryMetadataText extends String, Codec {
setOverride (override: string): void;
}
export interface RegistryMetadataCallArg {
name: RegistryMetadataText;
type: RegistryMetadataText;
}
export interface RegistryMetadataCall {
args: RegistryMetadataCallArg[];
name: RegistryMetadataText;
toJSON (): string | AnyJsonObject;
}
export interface RegistryMetadataCalls {
isSome: boolean;
unwrap (): RegistryMetadataCall[];
}
export interface RegistryError {
documentation: string[];
index: number;
name: string;
section: string;
}
export interface RegistryMetadataError {
// eslint-disable-next-line @typescript-eslint/ban-types
name: String;
// eslint-disable-next-line @typescript-eslint/ban-types
documentation: String[];
}
export type RegistryMetadataErrors = RegistryMetadataError[];
export interface RegistryMetadataEvent {
args: any[];
name: RegistryMetadataText;
}
export interface RegistryMetadataEvents {
isSome: boolean;
unwrap (): RegistryMetadataEvent[];
}
export interface RegistryMetadataExtrinsic {
version: BN;
// eslint-disable-next-line @typescript-eslint/ban-types
signedExtensions: String[];
}
export interface RegistryMetadataModule {
calls: RegistryMetadataCalls;
errors: RegistryMetadataErrors;
events: RegistryMetadataEvents;
name: RegistryMetadataText;
}
export interface RegistryMetadataLatest {
modules: RegistryMetadataModule[];
extrinsic: RegistryMetadataExtrinsic;
}
export interface RegistryMetadata {
asLatest: RegistryMetadataLatest;
}
export interface Registry {
readonly chainDecimals: number;
readonly chainSS58: number | undefined;
readonly chainToken: string;
findMetaCall (callIndex: Uint8Array): CallFunction;
findMetaError (errorIndex: Uint8Array): any;
// 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>;
get <T extends Codec = Codec> (name: string): Constructor<T> | undefined;
getChainProperties (): ChainProperties | undefined;
getDefinition (name: string): string | undefined;
getOrThrow <T extends Codec = Codec> (name: string, msg?: string): Constructor<T>;
getSignedExtensionExtra (): Record<string, InterfaceTypes>;
getSignedExtensionTypes (): Record<string, InterfaceTypes>;
hasClass (name: string): boolean;
hasDef (name: string): boolean;
hasType (name: string): boolean;
register (type: Constructor | RegistryTypes): void;
register (name: string, type: Constructor): void;
register (arg1: string | Constructor | RegistryTypes, arg2?: Constructor): void;
setChainProperties (properties?: ChainProperties): void;
setMetadata (metadata: RegistryMetadata): void;
}