Additional export cleanups (root & types) (#694)
This commit is contained in:
@@ -3,9 +3,8 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { KeyringPair } from '@polkadot/keyring/types';
|
||||
import { AccountId, Address, Extrinsic, ExtrinsicStatus, EventRecord, Hash, Index, Method, RuntimeVersion, SignedBlock, Struct, Text, Vector } from '@polkadot/types/index';
|
||||
import { SignatureOptions } from '@polkadot/types/ExtrinsicSignature';
|
||||
import { AnyNumber, AnyU8a, CodecCallback } from '@polkadot/types/types';
|
||||
import { AccountId, Address, Extrinsic, ExtrinsicStatus, EventRecord, Hash, Index, Method, SignedBlock, Struct, Text, Vector } from '@polkadot/types/index';
|
||||
import { CodecCallback, SignatureOptions } from '@polkadot/types/types';
|
||||
import { ApiInterface$Rx, ApiType, OnCallDefinition, Signer } from './types';
|
||||
|
||||
import { Observable, of, combineLatest } from 'rxjs';
|
||||
@@ -14,13 +13,6 @@ import { assert, isBn, isFunction, isNumber, isUndefined } from '@polkadot/util'
|
||||
|
||||
import filterEvents from './util/filterEvents';
|
||||
|
||||
type SignatureOptionsPartial = {
|
||||
blockHash?: AnyU8a,
|
||||
era?: Uint8Array,
|
||||
nonce: AnyNumber,
|
||||
version?: RuntimeVersion
|
||||
};
|
||||
|
||||
type StatusCb = (result: SubmittableResult) => any;
|
||||
|
||||
type SumbitableResultResult<CodecResult, SubscriptionResult> =
|
||||
@@ -132,12 +124,12 @@ export default class SubmittableExtrinsic<CodecResult, SubscriptionResult> exten
|
||||
);
|
||||
}
|
||||
|
||||
private expandOptions (options: SignatureOptionsPartial): SignatureOptions {
|
||||
private expandOptions (options: Partial<SignatureOptions>): SignatureOptions {
|
||||
return {
|
||||
blockHash: this._api.genesisHash,
|
||||
version: this._api.runtimeVersion,
|
||||
...options
|
||||
};
|
||||
} as SignatureOptions;
|
||||
}
|
||||
|
||||
send (): SumbitableResultResult<CodecResult, SubscriptionResult>;
|
||||
@@ -158,10 +150,10 @@ export default class SubmittableExtrinsic<CodecResult, SubscriptionResult> exten
|
||||
// NOTE with the nonce hack, we don't add a signature overload for 2 reasons -
|
||||
// - it makes it incompatible with the base Extrinsic
|
||||
// - for those using TS, we would like to move them towards the new version
|
||||
sign (account: KeyringPair, _options: SignatureOptionsPartial): SubmittableExtrinsic<CodecResult, SubscriptionResult> {
|
||||
sign (account: KeyringPair, _options: Partial<SignatureOptions>): SubmittableExtrinsic<CodecResult, SubscriptionResult> {
|
||||
// HACK here we actually override nonce if it was specified (backwards compat for
|
||||
// the previous signature - don't let userspace break, but allow then time to upgrade)
|
||||
const options: SignatureOptionsPartial = isBn(_options) || isNumber(_options)
|
||||
const options: Partial<SignatureOptions> = isBn(_options) || isNumber(_options)
|
||||
? { nonce: _options as any as number }
|
||||
: _options;
|
||||
|
||||
@@ -170,10 +162,10 @@ export default class SubmittableExtrinsic<CodecResult, SubscriptionResult> exten
|
||||
return this;
|
||||
}
|
||||
|
||||
signAndSend (account: KeyringPair | string | AccountId | Address, options?: Partial<SignatureOptionsPartial>): SumbitableResultResult<CodecResult, SubscriptionResult>;
|
||||
signAndSend (account: KeyringPair | string | AccountId | Address, options?: Partial<Partial<SignatureOptions>>): SumbitableResultResult<CodecResult, SubscriptionResult>;
|
||||
signAndSend (account: KeyringPair | string | AccountId | Address, statusCb: StatusCb): SumbitableResultSubscription<CodecResult, SubscriptionResult>;
|
||||
signAndSend (account: KeyringPair | string | AccountId | Address, _options?: Partial<SignatureOptionsPartial> | StatusCb, statusCb?: StatusCb): SumbitableResultResult<CodecResult, SubscriptionResult> | SumbitableResultSubscription<CodecResult, SubscriptionResult> {
|
||||
let options: Partial<SignatureOptionsPartial> = {};
|
||||
signAndSend (account: KeyringPair | string | AccountId | Address, _options?: Partial<Partial<SignatureOptions>> | StatusCb, statusCb?: StatusCb): SumbitableResultResult<CodecResult, SubscriptionResult> | SumbitableResultSubscription<CodecResult, SubscriptionResult> {
|
||||
let options: Partial<Partial<SignatureOptions>> = {};
|
||||
|
||||
if (isFunction(_options)) {
|
||||
statusCb = _options;
|
||||
|
||||
@@ -6,8 +6,7 @@ import { Observable } from 'rxjs';
|
||||
import { ProviderInterface } from '@polkadot/rpc-provider/types';
|
||||
import { RpcRxInterface$Events } from '@polkadot/rpc-rx/types';
|
||||
import { Extrinsic, Hash, Metadata, RuntimeVersion, u64 as U64 } from '@polkadot/types/index';
|
||||
import { SignatureOptions } from '@polkadot/types/ExtrinsicSignature';
|
||||
import { CodecArg, CodecCallback, RegistryTypes } from '@polkadot/types/types';
|
||||
import { CodecArg, CodecCallback, RegistryTypes, SignatureOptions } from '@polkadot/types/types';
|
||||
import { MethodFunction } from '@polkadot/types/Method';
|
||||
import { StorageFunction } from '@polkadot/types/StorageKey';
|
||||
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { KeyringPair } from '@polkadot/keyring/types';
|
||||
import { SignatureOptions } from '@polkadot/types/ExtrinsicSignature';
|
||||
import { SignatureOptions } from '@polkadot/types/types';
|
||||
|
||||
import { Extrinsic } from '@polkadot/types/index';
|
||||
|
||||
let id = 0;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { KeyringPair } from '@polkadot/keyring/types';
|
||||
import { AnyNumber, AnyU8a, Codec } from './types';
|
||||
import { AnyNumber, AnyU8a, Codec, SignatureOptions } from './types';
|
||||
|
||||
import { isHex, isU8a, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
@@ -11,7 +11,7 @@ import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
import Compact from './codec/Compact';
|
||||
import Struct from './codec/Struct';
|
||||
import Address from './Address';
|
||||
import ExtrinsicSignature, { SignatureOptions } from './ExtrinsicSignature';
|
||||
import ExtrinsicSignature from './ExtrinsicSignature';
|
||||
import Hash from './Hash';
|
||||
import { FunctionMetadata } from './Metadata/v0/Modules';
|
||||
import Method from './Method';
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { KeyringPair } from '@polkadot/keyring/types';
|
||||
import { AnyNumber, AnyU8a } from './types';
|
||||
import { AnyNumber, SignatureOptions } from './types';
|
||||
|
||||
import Struct from './codec/Struct';
|
||||
import Address from './Address';
|
||||
@@ -15,13 +15,6 @@ import Signature from './Signature';
|
||||
import SignaturePayload from './SignaturePayload';
|
||||
import U8 from './U8';
|
||||
|
||||
export type SignatureOptions = {
|
||||
blockHash: AnyU8a,
|
||||
era?: Uint8Array,
|
||||
nonce: AnyNumber,
|
||||
version?: RuntimeVersion
|
||||
};
|
||||
|
||||
export const IMMORTAL_ERA = new Uint8Array([0]);
|
||||
|
||||
const BIT_SIGNED = 0b10000000;
|
||||
@@ -155,7 +148,7 @@ export default class ExtrinsicSignature extends Struct {
|
||||
era: era || IMMORTAL_ERA,
|
||||
blockHash
|
||||
});
|
||||
const signature = new Signature(signingPayload.sign(account, version));
|
||||
const signature = new Signature(signingPayload.sign(account, version as RuntimeVersion));
|
||||
|
||||
return this.injectSignature(signature, signer, signingPayload.nonce, signingPayload.era);
|
||||
}
|
||||
|
||||
@@ -28,14 +28,14 @@ export type HeaderValue = {
|
||||
* A [[Block]] header
|
||||
*/
|
||||
export default class Header extends Struct {
|
||||
constructor (value?: HeaderValue | Uint8Array) {
|
||||
constructor (value?: HeaderValue | Uint8Array | null) {
|
||||
super({
|
||||
parentHash: Hash,
|
||||
number: Compact.with(BlockNumber),
|
||||
stateRoot: Hash,
|
||||
extrinsicsRoot: Hash,
|
||||
digest: Digest
|
||||
}, value);
|
||||
}, value || {});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,11 +91,10 @@ export default class Header extends Struct {
|
||||
export class HeaderExtended extends Header {
|
||||
private _author?: AccountId;
|
||||
|
||||
constructor (header: Header, sessionValidators: Array<AccountId> = []) {
|
||||
constructor (header: Header | null = null, sessionValidators: Array<AccountId> = []) {
|
||||
super(header);
|
||||
|
||||
const { digest: { logs } } = header;
|
||||
const digestItem = logs.find(({ type }) => type === 'Seal');
|
||||
const digestItem = header && header.digest && header.digest.logs.find(({ type }) => type === 'Seal');
|
||||
|
||||
this._author = digestItem && sessionValidators.length
|
||||
? sessionValidators[digestItem.asSeal.slot.toNumber() % sessionValidators.length]
|
||||
|
||||
@@ -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 { AnyNumber, AnyU8a } from './types';
|
||||
import { AnyNumber, AnyU8a, RuntimeVersionInterface } from './types';
|
||||
|
||||
import Struct from './codec/Struct';
|
||||
import Tuple from './codec/Tuple';
|
||||
@@ -69,7 +69,7 @@ type RuntimeVersionValue = {
|
||||
* @description
|
||||
* A defintion of the runtime and the associated versions thereof
|
||||
*/
|
||||
export default class RuntimeVersion extends Struct {
|
||||
export default class RuntimeVersion extends Struct implements RuntimeVersionInterface {
|
||||
constructor (value?: RuntimeVersionValue | Uint8Array) {
|
||||
super({
|
||||
specName: Text,
|
||||
|
||||
@@ -24,7 +24,7 @@ export { default as Bytes } from './Bytes';
|
||||
export { default as ChainProperties } from './ChainProperties';
|
||||
export { default as CodeHash } from './CodeHash';
|
||||
export { default as Data } from './Data';
|
||||
export { default as Digest } from './Digest';
|
||||
export { default as Digest, DigestItem } from './Digest';
|
||||
export { default as Event } from './Event';
|
||||
export { default as EventRecord } from './EventRecord';
|
||||
export { default as Extrinsic } from './Extrinsic';
|
||||
@@ -37,7 +37,7 @@ export { default as Gas } from './Gas';
|
||||
export { default as H256 } from './H256';
|
||||
export { default as H512 } from './H512';
|
||||
export { default as Hash } from './Hash';
|
||||
export { default as Header } from './Header';
|
||||
export { default as Header, HeaderExtended } from './Header';
|
||||
export { default as Health } from './Health';
|
||||
export { default as i8 } from './I8';
|
||||
export { default as i16 } from './I16';
|
||||
|
||||
@@ -71,3 +71,19 @@ export type TypeDef = { [index: string]: Codec };
|
||||
export type RegistryTypes = {
|
||||
[name: string]: Constructor | string | { [name: string]: string }
|
||||
};
|
||||
|
||||
export interface RuntimeVersionInterface {
|
||||
readonly apis: Array<any>;
|
||||
readonly authoringVersion: BN;
|
||||
readonly implName: String;
|
||||
readonly implVersion: BN;
|
||||
readonly specName: String;
|
||||
readonly specVersion: BN;
|
||||
}
|
||||
|
||||
export type SignatureOptions = {
|
||||
blockHash: AnyU8a,
|
||||
era?: Uint8Array,
|
||||
nonce: AnyNumber,
|
||||
version?: RuntimeVersionInterface
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user