@@ -13,7 +13,7 @@ export interface ApiInterfaceRx {
|
||||
call: QueryableCalls<'rxjs'>;
|
||||
consts: QueryableConsts<'rxjs'>;
|
||||
extrinsicType: number;
|
||||
genesisHash?: Hash;
|
||||
genesisHash?: Hash | undefined;
|
||||
hasSubscriptions: boolean;
|
||||
registry: Registry;
|
||||
runtimeMetadata: Metadata;
|
||||
@@ -22,7 +22,7 @@ export interface ApiInterfaceRx {
|
||||
queryMulti: QueryableStorageMulti<'rxjs'>;
|
||||
rpc: DecoratedRpc<'rxjs', RpcInterface>;
|
||||
tx: SubmittableExtrinsics<'rxjs'>;
|
||||
signer?: Signer;
|
||||
signer?: Signer | undefined;
|
||||
|
||||
callAt: (blockHash: Uint8Array | string, knownVersion?: RuntimeVersion) => Observable<QueryableCalls<'rxjs'>>;
|
||||
queryAt: (blockHash: Uint8Array | string, knownVersion?: RuntimeVersion) => Observable<QueryableStorage<'rxjs'>>;
|
||||
|
||||
@@ -40,13 +40,13 @@ export type SubmittablePaymentResult<ApiType extends ApiTypes> =
|
||||
: Promise<RuntimeDispatchInfo>;
|
||||
|
||||
export interface SubmittableResultValue {
|
||||
dispatchError?: DispatchError;
|
||||
dispatchInfo?: DispatchInfo;
|
||||
dispatchError?: DispatchError | undefined;
|
||||
dispatchInfo?: DispatchInfo | undefined;
|
||||
events?: EventRecord[];
|
||||
internalError?: Error;
|
||||
internalError?: Error | undefined;
|
||||
status: ExtrinsicStatus;
|
||||
txHash: Hash;
|
||||
txIndex?: number;
|
||||
txIndex?: number | undefined;
|
||||
blockNumber?: BlockNumber;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ export interface BlueprintConstructor<ApiType extends ApiTypes> {
|
||||
}
|
||||
|
||||
export class BlueprintSubmittableResult<ApiType extends ApiTypes> extends SubmittableResult {
|
||||
readonly contract?: Contract<ApiType>;
|
||||
readonly contract?: Contract<ApiType> | undefined;
|
||||
|
||||
constructor (result: ISubmittableResult, contract?: Contract<ApiType>) {
|
||||
super(result);
|
||||
|
||||
@@ -25,10 +25,10 @@ export interface CodeConstructor<ApiType extends ApiTypes> {
|
||||
}
|
||||
|
||||
export class CodeSubmittableResult<ApiType extends ApiTypes> extends SubmittableResult {
|
||||
readonly blueprint?: Blueprint<ApiType>;
|
||||
readonly contract?: Contract<ApiType>;
|
||||
readonly blueprint?: Blueprint<ApiType> | undefined;
|
||||
readonly contract?: Contract<ApiType> | undefined;
|
||||
|
||||
constructor (result: ISubmittableResult, blueprint?: Blueprint<ApiType>, contract?: Contract<ApiType>) {
|
||||
constructor (result: ISubmittableResult, blueprint?: Blueprint<ApiType> | undefined, contract?: Contract<ApiType> | undefined) {
|
||||
super(result);
|
||||
|
||||
this.blueprint = blueprint;
|
||||
@@ -77,14 +77,14 @@ export class Code<ApiType extends ApiTypes> extends Base<ApiType> {
|
||||
encodeSalt(salt)
|
||||
).withResultTransform((result: ISubmittableResult) =>
|
||||
new CodeSubmittableResult(result, ...(applyOnEvent(result, ['CodeStored', 'Instantiated'], (records: EventRecord[]) =>
|
||||
records.reduce<[Blueprint<ApiType>?, Contract<ApiType>?]>(([blueprint, contract], { event }) =>
|
||||
records.reduce<[Blueprint<ApiType> | undefined, Contract<ApiType> | undefined]>(([blueprint, contract], { event }) =>
|
||||
this.api.events.contracts.Instantiated.is(event)
|
||||
? [blueprint, new Contract<ApiType>(this.api, this.abi, (event as unknown as { data: [Codec, AccountId] }).data[1], this._decorateMethod)]
|
||||
: this.api.events.contracts.CodeStored.is(event)
|
||||
? [new Blueprint<ApiType>(this.api, this.abi, (event as unknown as { data: [AccountId] }).data[0], this._decorateMethod), contract]
|
||||
: [blueprint, contract],
|
||||
[])
|
||||
) || []))
|
||||
[undefined, undefined])
|
||||
) || [undefined, undefined]))
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ function createTx <ApiType extends ApiTypes> (meta: AbiMessage, fn: (options: Co
|
||||
}
|
||||
|
||||
export class ContractSubmittableResult extends SubmittableResult {
|
||||
readonly contractEvents?: DecodedEvent[];
|
||||
readonly contractEvents?: DecodedEvent[] | undefined;
|
||||
|
||||
constructor (result: ISubmittableResult, contractEvents?: DecodedEvent[]) {
|
||||
super(result);
|
||||
|
||||
@@ -86,6 +86,6 @@ export interface WeightAll {
|
||||
v1Weight: BN;
|
||||
v2Weight: {
|
||||
refTime: BN;
|
||||
proofSize?: BN;
|
||||
proofSize?: BN | undefined;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ function retrieveNick (api: DeriveApi, accountId?: AccountId): Observable<string
|
||||
export function info (instanceId: string, api: DeriveApi): (address?: AccountIndex | AccountId | Address | Uint8Array | string | null) => Observable<DeriveAccountInfo> {
|
||||
return memo(instanceId, (address?: AccountIndex | AccountId | Address | Uint8Array | string | null): Observable<DeriveAccountInfo> =>
|
||||
api.derive.accounts.idAndIndex(address).pipe(
|
||||
switchMap(([accountId, accountIndex]): Observable<[Partial<DeriveAccountInfo>, DeriveAccountRegistration, string?]> =>
|
||||
switchMap(([accountId, accountIndex]): Observable<[Partial<DeriveAccountInfo>, DeriveAccountRegistration, string | undefined]> =>
|
||||
combineLatest([
|
||||
of({ accountId, accountIndex }),
|
||||
api.derive.accounts.identity(accountId),
|
||||
|
||||
@@ -3,22 +3,22 @@
|
||||
|
||||
import type { AccountId, AccountIndex, RegistrationJudgement } from '@polkadot/types/interfaces';
|
||||
|
||||
export type AccountIdAndIndex = [AccountId?, AccountIndex?];
|
||||
export type AccountIdAndIndex = [AccountId | undefined, AccountIndex | undefined];
|
||||
|
||||
export type AccountIndexes = Record<string, AccountIndex>;
|
||||
|
||||
export interface DeriveAccountRegistration {
|
||||
display?: string;
|
||||
displayParent?: string;
|
||||
email?: string;
|
||||
image?: string;
|
||||
legal?: string;
|
||||
other?: Record<string, string>;
|
||||
parent?: AccountId;
|
||||
pgp?: string;
|
||||
riot?: string;
|
||||
twitter?: string;
|
||||
web?: string;
|
||||
display?: string | undefined;
|
||||
displayParent?: string | undefined;
|
||||
email?: string | undefined;
|
||||
image?: string | undefined;
|
||||
legal?: string | undefined;
|
||||
other?: Record<string, string> | undefined;
|
||||
parent?: AccountId | undefined;
|
||||
pgp?: string | undefined;
|
||||
riot?: string | undefined;
|
||||
twitter?: string | undefined;
|
||||
web?: string | undefined;
|
||||
judgements: RegistrationJudgement[];
|
||||
}
|
||||
|
||||
@@ -30,14 +30,14 @@ export interface DeriveAccountFlags {
|
||||
}
|
||||
|
||||
export interface DeriveAccountInfo {
|
||||
accountId?: AccountId;
|
||||
accountIndex?: AccountIndex;
|
||||
accountId?: AccountId | undefined;
|
||||
accountIndex?: AccountIndex | undefined;
|
||||
identity: DeriveAccountRegistration;
|
||||
nickname?: string;
|
||||
nickname?: string | undefined;
|
||||
}
|
||||
|
||||
export interface DeriveHasIdentity {
|
||||
display?: string;
|
||||
display?: string | undefined;
|
||||
hasIdentity: boolean;
|
||||
parentId?: string;
|
||||
parentId?: string | undefined;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ export interface DeriveDemocracyLock {
|
||||
|
||||
export interface DeriveProposalImage extends AtBlock {
|
||||
balance: Balance;
|
||||
proposal?: Call;
|
||||
proposal?: Call | undefined;
|
||||
proposalHash?: HexString;
|
||||
proposalLen?: number;
|
||||
proposer: AccountId;
|
||||
@@ -32,27 +32,27 @@ export interface DeriveProposalImage extends AtBlock {
|
||||
export interface DeriveDispatch extends AtBlock {
|
||||
index: ReferendumIndex;
|
||||
imageHash: HexString;
|
||||
image?: DeriveProposalImage;
|
||||
image?: DeriveProposalImage | undefined;
|
||||
}
|
||||
|
||||
export interface DeriveProposal {
|
||||
balance?: Balance;
|
||||
index: PropIndex;
|
||||
image?: DeriveProposalImage;
|
||||
image?: DeriveProposalImage | undefined;
|
||||
imageHash: Hash;
|
||||
proposer: AccountId;
|
||||
seconds: Vec<AccountId>;
|
||||
}
|
||||
|
||||
export interface DeriveProposalExternal {
|
||||
image?: DeriveProposalImage;
|
||||
image?: DeriveProposalImage | undefined;
|
||||
imageHash: HexString;
|
||||
threshold: PalletDemocracyVoteThreshold;
|
||||
}
|
||||
|
||||
export interface DeriveReferendum {
|
||||
index: ReferendumIndex;
|
||||
image?: DeriveProposalImage;
|
||||
image?: DeriveProposalImage | undefined;
|
||||
imageHash: HexString;
|
||||
status: PalletDemocracyReferendumStatus | ReferendumInfoTo239;
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ import type { PalletSocietyBid, PalletSocietyBidKind, PalletSocietyVote, PalletS
|
||||
|
||||
export interface DeriveSociety {
|
||||
bids: PalletSocietyBid[];
|
||||
defender?: AccountId;
|
||||
defender?: AccountId | undefined;
|
||||
hasDefender: boolean;
|
||||
head?: AccountId;
|
||||
founder?: AccountId;
|
||||
head?: AccountId | undefined;
|
||||
founder?: AccountId | undefined;
|
||||
maxMembers: u32;
|
||||
pot: BalanceOf;
|
||||
}
|
||||
@@ -28,6 +28,6 @@ export interface DeriveSocietyMember {
|
||||
isSuspended: boolean;
|
||||
payouts: [BlockNumber, Balance][];
|
||||
strikes: StrikeCount;
|
||||
vote?: PalletSocietyVote;
|
||||
vouching?: PalletSocietyVouchingStatus;
|
||||
vote?: PalletSocietyVote | undefined;
|
||||
vouching?: PalletSocietyVouchingStatus | undefined;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ export function createHeaderExtended (registry: Registry, header?: Header, valid
|
||||
const HeaderBase = registry.createClass('Header');
|
||||
|
||||
class Implementation extends HeaderBase implements HeaderExtended {
|
||||
readonly #author?: AccountId;
|
||||
readonly #author?: AccountId | undefined;
|
||||
|
||||
constructor (registry: Registry, header?: Header, validators?: AccountId[] | null, author?: AccountId | null) {
|
||||
super(registry, header);
|
||||
|
||||
@@ -36,7 +36,7 @@ export function createSignedBlockExtended (registry: Registry, block?: SignedBlo
|
||||
const SignedBlockBase = registry.createClass('SignedBlock');
|
||||
|
||||
class Implementation extends SignedBlockBase implements SignedBlockExtended {
|
||||
readonly #author?: AccountId;
|
||||
readonly #author?: AccountId | undefined;
|
||||
readonly #events: EventRecord[];
|
||||
readonly #extrinsics: TxWithEvent[];
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ export interface SignedBlockExtended extends SignedBlock {
|
||||
}
|
||||
|
||||
export interface TxWithEvent {
|
||||
dispatchError?: DispatchError;
|
||||
dispatchInfo?: DispatchInfo;
|
||||
dispatchError?: DispatchError | undefined;
|
||||
dispatchInfo?: DispatchInfo | undefined;
|
||||
events: Event[];
|
||||
extrinsic: Extrinsic;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ interface MetaDecoration {
|
||||
}
|
||||
|
||||
interface FullDecoration<ApiType extends ApiTypes> {
|
||||
createdAt?: Uint8Array;
|
||||
createdAt?: Uint8Array | undefined;
|
||||
decoratedApi: ApiDecoration<ApiType>;
|
||||
decoratedMeta: DecoratedMeta;
|
||||
}
|
||||
|
||||
@@ -35,11 +35,11 @@ function extractInfo (events: EventRecord[] = []): DispatchInfo | undefined {
|
||||
}
|
||||
|
||||
export class SubmittableResult implements ISubmittableResult {
|
||||
readonly dispatchError?: DispatchError;
|
||||
readonly dispatchError?: DispatchError | undefined;
|
||||
|
||||
readonly dispatchInfo?: DispatchInfo;
|
||||
readonly dispatchInfo?: DispatchInfo | undefined;
|
||||
|
||||
readonly internalError?: Error;
|
||||
readonly internalError?: Error | undefined;
|
||||
|
||||
readonly events: EventRecord[];
|
||||
|
||||
@@ -47,9 +47,9 @@ export class SubmittableResult implements ISubmittableResult {
|
||||
|
||||
readonly txHash: Hash;
|
||||
|
||||
readonly txIndex?: number;
|
||||
readonly txIndex?: number | undefined;
|
||||
|
||||
readonly blockNumber?: BlockNumber;
|
||||
readonly blockNumber?: BlockNumber | undefined;
|
||||
|
||||
constructor ({ blockNumber, dispatchError, dispatchInfo, events, internalError, status, txHash, txIndex }: SubmittableResultValue) {
|
||||
this.dispatchError = dispatchError || extractError(events);
|
||||
|
||||
@@ -21,7 +21,7 @@ import { SubmittableResult } from './Result.js';
|
||||
interface SubmittableOptions<ApiType extends ApiTypes> {
|
||||
api: ApiInterfaceRx;
|
||||
apiType: ApiTypes;
|
||||
blockHash?: Uint8Array;
|
||||
blockHash?: Uint8Array | undefined;
|
||||
decorateMethod: ApiBase<ApiType>['_decorateMethod'];
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ function makeEraOptions (api: ApiInterfaceRx, registry: Registry, partialOptions
|
||||
});
|
||||
}
|
||||
|
||||
function makeSignAndSendOptions (partialOptions?: Partial<SignerOptions> | Callback<ISubmittableResult>, statusCb?: Callback<ISubmittableResult>): [Partial<SignerOptions>, Callback<ISubmittableResult>?] {
|
||||
function makeSignAndSendOptions (partialOptions?: Partial<SignerOptions> | Callback<ISubmittableResult>, statusCb?: Callback<ISubmittableResult>): [Partial<SignerOptions>, Callback<ISubmittableResult> | undefined] {
|
||||
let options: Partial<SignerOptions> = {};
|
||||
|
||||
if (isFunction(partialOptions)) {
|
||||
|
||||
@@ -130,7 +130,7 @@ class InnerChecker {
|
||||
let parsedResponse: {id: string, result?: SmoldotHealth, params?: { subscription: string }};
|
||||
|
||||
try {
|
||||
parsedResponse = JSON.parse(jsonRpcResponse) as { id: string, result: undefined | SmoldotHealth };
|
||||
parsedResponse = JSON.parse(jsonRpcResponse) as { id: string, result?: SmoldotHealth };
|
||||
} catch {
|
||||
return jsonRpcResponse;
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ export class ScProvider implements ProviderInterface {
|
||||
readonly #Sc: SubstrateConnect;
|
||||
readonly #coder: RpcCoder = new RpcCoder();
|
||||
readonly #spec: string | ScType.WellKnownChain;
|
||||
readonly #sharedSandbox?: ScProvider;
|
||||
readonly #sharedSandbox?: ScProvider | undefined;
|
||||
readonly #subscriptions: Map<string, [ResponseCallback, { unsubscribeMethod: string; id: string | number }]> = new Map();
|
||||
readonly #resubscribeMethods: Map<string, ActiveSubs> = new Map();
|
||||
readonly #requests: Map<number, ResponseCallback> = new Map();
|
||||
|
||||
@@ -26,7 +26,7 @@ interface WsStateAwaiting {
|
||||
method: string;
|
||||
params: unknown[];
|
||||
start: number;
|
||||
subscription?: SubscriptionHandler;
|
||||
subscription?: SubscriptionHandler | undefined;
|
||||
}
|
||||
|
||||
interface WsStateSubscription extends SubscriptionHandler {
|
||||
|
||||
@@ -12,7 +12,7 @@ import type { ExtraTypes } from './types.js';
|
||||
import Handlebars from 'handlebars';
|
||||
|
||||
import * as defaultDefs from '@polkadot/types/interfaces/definitions';
|
||||
import { unwrapStorageSi } from '@polkadot/types/primitive/StorageKey';
|
||||
import { unwrapStorageSi } from '@polkadot/types/util';
|
||||
import lookupDefinitions from '@polkadot/types-augment/lookup/definitions';
|
||||
import { stringCamelCase } from '@polkadot/util';
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import { Metadata, TypeRegistry, Vec } from '@polkadot/types';
|
||||
import * as definitions from '@polkadot/types/interfaces/definitions';
|
||||
import { getStorage as getSubstrateStorage } from '@polkadot/types/metadata/decorate/storage/getStorage';
|
||||
import { Text } from '@polkadot/types/primitive';
|
||||
import { unwrapStorageType } from '@polkadot/types/primitive/StorageKey';
|
||||
import { unwrapStorageType } from '@polkadot/types/util';
|
||||
import kusamaMeta, { rpc as kusamaRpc, version as kusamaVer } from '@polkadot/types-support/metadata/static-kusama';
|
||||
import polkadotMeta, { rpc as polkadotRpc, version as polkadotVer } from '@polkadot/types-support/metadata/static-polkadot';
|
||||
import substrateMeta from '@polkadot/types-support/metadata/static-substrate';
|
||||
|
||||
@@ -11,8 +11,8 @@ import type { AnyJson, BareOpts, Codec, Inspect, IU8a, Registry } from '../types
|
||||
export abstract class AbstractBase<T extends Codec> implements Codec {
|
||||
readonly registry: Registry;
|
||||
|
||||
public createdAtHash?: IU8a;
|
||||
public initialU8aLength?: number;
|
||||
public createdAtHash?: IU8a | undefined;
|
||||
public initialU8aLength?: number | undefined;
|
||||
public isStorageFallback?: boolean;
|
||||
|
||||
readonly #raw: T;
|
||||
|
||||
@@ -12,7 +12,7 @@ export abstract class AbstractObject<T extends ToString> implements CodecObject<
|
||||
readonly registry: Registry;
|
||||
|
||||
public createdAtHash?: IU8a;
|
||||
public initialU8aLength?: number;
|
||||
public initialU8aLength?: number | undefined;
|
||||
public isStorageFallback?: boolean;
|
||||
|
||||
readonly $: T;
|
||||
|
||||
@@ -3,17 +3,12 @@
|
||||
|
||||
import type { BN } from '@polkadot/util';
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { AnyJson, AnyNumber, CodecClass, ICompact, Inspect, INumber, IU8a, Registry } from '../types/index.js';
|
||||
import type { AnyJson, AnyNumber, CodecClass, DefinitionSetter, ICompact, Inspect, INumber, IU8a, Registry } from '../types/index.js';
|
||||
|
||||
import { compactFromU8a, compactFromU8aLim, compactToU8a, isU8a } from '@polkadot/util';
|
||||
|
||||
import { typeToConstructor } from '../utils/index.js';
|
||||
|
||||
interface Options<T> {
|
||||
definition?: CodecClass<T>;
|
||||
setDefinition?: (d: CodecClass<T>) => CodecClass<T>;
|
||||
}
|
||||
|
||||
function noopSetDefinition <T> (d: CodecClass<T>): CodecClass<T> {
|
||||
return d;
|
||||
}
|
||||
@@ -56,7 +51,7 @@ export class Compact<T extends INumber> implements ICompact<T> {
|
||||
readonly #Type: CodecClass<T>;
|
||||
readonly #raw: T;
|
||||
|
||||
constructor (registry: Registry, Type: CodecClass<T> | string, value: Compact<T> | AnyNumber = 0, { definition, setDefinition = noopSetDefinition }: Options<T> = {}) {
|
||||
constructor (registry: Registry, Type: CodecClass<T> | string, value: Compact<T> | AnyNumber = 0, { definition, setDefinition = noopSetDefinition }: DefinitionSetter<CodecClass<T>> = {}) {
|
||||
this.registry = registry;
|
||||
this.#Type = definition || setDefinition(typeToConstructor(registry, Type));
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { AnyJson, Codec, CodecClass, IEnum, Inspect, IU8a, Registry } from '../types/index.js';
|
||||
import type { AnyJson, Codec, CodecClass, DefinitionSetter, IEnum, Inspect, IU8a, Registry } from '../types/index.js';
|
||||
|
||||
import { isHex, isNumber, isObject, isString, isU8a, objectProperties, stringCamelCase, stringify, stringPascalCase, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
@@ -32,11 +32,6 @@ interface Decoded {
|
||||
value: Codec;
|
||||
}
|
||||
|
||||
interface Options {
|
||||
definition?: Definition;
|
||||
setDefinition?: (d: Definition) => Definition;
|
||||
}
|
||||
|
||||
function noopSetDefinition (d: Definition): Definition {
|
||||
return d;
|
||||
}
|
||||
@@ -196,7 +191,7 @@ export class Enum implements IEnum {
|
||||
readonly #isIndexed: boolean;
|
||||
readonly #raw: Codec;
|
||||
|
||||
constructor (registry: Registry, Types: Record<string, string | CodecClass> | Record<string, number> | string[], value?: unknown, index?: number, { definition, setDefinition = noopSetDefinition }: Options = {}) {
|
||||
constructor (registry: Registry, Types: Record<string, string | CodecClass> | Record<string, number> | string[], value?: unknown, index?: number, { definition, setDefinition = noopSetDefinition }: DefinitionSetter<Definition> = {}) {
|
||||
const { def, isBasic, isIndexed } = definition || setDefinition(extractDef(registry, Types));
|
||||
|
||||
// shortcut isU8a as used in SCALE decoding
|
||||
|
||||
@@ -2,18 +2,13 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { AnyJson, Codec, CodecClass, Inspect, IOption, IU8a, Registry } from '../types/index.js';
|
||||
import type { AnyJson, Codec, CodecClass, DefinitionSetter, Inspect, IOption, IU8a, Registry } from '../types/index.js';
|
||||
|
||||
import { isCodec, isNull, isU8a, isUndefined, u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { typeToConstructor } from '../utils/index.js';
|
||||
import { Null } from './Null.js';
|
||||
|
||||
interface Options<T> {
|
||||
definition?: CodecClass<T>;
|
||||
setDefinition?: (d: CodecClass<T>) => CodecClass<T>;
|
||||
}
|
||||
|
||||
function noopSetDefinition <T extends Codec> (d: CodecClass<T>): CodecClass<T> {
|
||||
return d;
|
||||
}
|
||||
@@ -75,7 +70,7 @@ export class Option<T extends Codec> implements IOption<T> {
|
||||
readonly #Type: CodecClass<T>;
|
||||
readonly #raw: T;
|
||||
|
||||
constructor (registry: Registry, typeName: CodecClass<T> | string, value?: unknown, { definition, setDefinition = noopSetDefinition }: Options<T> = {}) {
|
||||
constructor (registry: Registry, typeName: CodecClass<T> | string, value?: unknown, { definition, setDefinition = noopSetDefinition }: DefinitionSetter<CodecClass<T>> = {}) {
|
||||
const Type = definition || setDefinition(typeToConstructor(registry, typeName));
|
||||
const decoded = isU8a(value) && value.length && !isCodec(value)
|
||||
? value[0] === 0
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2023 @polkadot/types-codec authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { AnyTupleValue, Codec, CodecClass, Inspect, ITuple, Registry } from '../types/index.js';
|
||||
import type { AnyTupleValue, Codec, CodecClass, DefinitionSetter, Inspect, ITuple, Registry } from '../types/index.js';
|
||||
|
||||
import { isFunction, isHex, isString, isU8a, stringify, u8aConcatStrict, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
@@ -16,11 +16,6 @@ type TupleTypes = TupleType[] | {
|
||||
|
||||
type Definition = [CodecClass[], string[]];
|
||||
|
||||
interface Options {
|
||||
definition?: Definition;
|
||||
setDefinition?: (d: Definition) => Definition;
|
||||
}
|
||||
|
||||
function noopSetDefinition (d: Definition): Definition {
|
||||
return d;
|
||||
}
|
||||
@@ -67,7 +62,7 @@ function decodeTuple (registry: Registry, result: Codec[], value: Exclude<AnyTup
|
||||
export class Tuple extends AbstractArray<Codec> implements ITuple<Codec[]> {
|
||||
#Types: Definition;
|
||||
|
||||
constructor (registry: Registry, Types: TupleTypes | TupleType, value?: AnyTupleValue, { definition, setDefinition = noopSetDefinition }: Options = {}) {
|
||||
constructor (registry: Registry, Types: TupleTypes | TupleType, value?: AnyTupleValue, { definition, setDefinition = noopSetDefinition }: DefinitionSetter<Definition> = {}) {
|
||||
const Classes = definition || setDefinition(
|
||||
Array.isArray(Types)
|
||||
? [Types.map((t) => typeToConstructor(registry, t)), []]
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { Codec, CodecClass, Registry } from '../types/index.js';
|
||||
import type { Codec, CodecClass, DefinitionSetter, Registry } from '../types/index.js';
|
||||
|
||||
import { compactFromU8aLim, isHex, isU8a, logger, stringify, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
@@ -13,11 +13,6 @@ const MAX_LENGTH = 64 * 1024;
|
||||
|
||||
const l = logger('Vec');
|
||||
|
||||
interface Options<T> {
|
||||
definition?: CodecClass<T>;
|
||||
setDefinition?: (d: CodecClass<T>) => CodecClass<T>;
|
||||
}
|
||||
|
||||
function noopSetDefinition <T extends Codec> (d: CodecClass<T>): CodecClass<T> {
|
||||
return d;
|
||||
}
|
||||
@@ -80,7 +75,7 @@ export function decodeVec<T extends Codec> (registry: Registry, result: T[], val
|
||||
export class Vec<T extends Codec> extends AbstractArray<T> {
|
||||
#Type: CodecClass<T>;
|
||||
|
||||
constructor (registry: Registry, Type: CodecClass<T> | string, value: Uint8Array | HexString | unknown[] = [], { definition, setDefinition = noopSetDefinition }: Options<T> = {}) {
|
||||
constructor (registry: Registry, Type: CodecClass<T> | string, value: Uint8Array | HexString | unknown[] = [], { definition, setDefinition = noopSetDefinition }: DefinitionSetter<CodecClass<T>> = {}) {
|
||||
const [decodeFrom, length, startAt] = decodeVecLength(value);
|
||||
|
||||
super(registry, length);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { Codec, CodecClass, Inspect, Registry } from '../types/index.js';
|
||||
import type { Codec, CodecClass, DefinitionSetter, Inspect, Registry } from '../types/index.js';
|
||||
|
||||
import { isU8a, u8aConcatStrict } from '@polkadot/util';
|
||||
|
||||
@@ -10,11 +10,6 @@ import { AbstractArray } from '../abstract/Array.js';
|
||||
import { decodeU8aVec, typeToConstructor } from '../utils/index.js';
|
||||
import { decodeVec } from './Vec.js';
|
||||
|
||||
interface Options<T> {
|
||||
definition?: CodecClass<T>;
|
||||
setDefinition?: (d: CodecClass<T>) => CodecClass<T>;
|
||||
}
|
||||
|
||||
function noopSetDefinition <T extends Codec> (d: CodecClass<T>): CodecClass<T> {
|
||||
return d;
|
||||
}
|
||||
@@ -27,7 +22,7 @@ function noopSetDefinition <T extends Codec> (d: CodecClass<T>): CodecClass<T> {
|
||||
export class VecFixed<T extends Codec> extends AbstractArray<T> {
|
||||
#Type: CodecClass<T>;
|
||||
|
||||
constructor (registry: Registry, Type: CodecClass<T> | string, length: number, value: Uint8Array | HexString | unknown[] = [] as unknown[], { definition, setDefinition = noopSetDefinition }: Options<T> = {}) {
|
||||
constructor (registry: Registry, Type: CodecClass<T> | string, length: number, value: Uint8Array | HexString | unknown[] = [] as unknown[], { definition, setDefinition = noopSetDefinition }: DefinitionSetter<CodecClass<T>> = {}) {
|
||||
super(registry, length);
|
||||
|
||||
this.#Type = definition || setDefinition(typeToConstructor<T>(registry, Type));
|
||||
|
||||
@@ -18,8 +18,8 @@ import { isAscii, isUndefined, isUtf8, u8aToHex, u8aToString, u8aToU8a } from '@
|
||||
export class Raw extends Uint8Array implements IU8a {
|
||||
readonly registry: Registry;
|
||||
|
||||
public createdAtHash?: IU8a;
|
||||
public initialU8aLength?: number;
|
||||
public createdAtHash?: IU8a | undefined;
|
||||
public initialU8aLength?: number | undefined;
|
||||
public isStorageFallback?: boolean;
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { AnyJson, BareOpts, Codec, CodecClass, Inspect, IStruct, IU8a, Registry } from '../types/index.js';
|
||||
import type { AnyJson, BareOpts, Codec, CodecClass, DefinitionSetter, Inspect, IStruct, IU8a, Registry } from '../types/index.js';
|
||||
|
||||
import { isBoolean, isHex, isObject, isU8a, isUndefined, objectProperties, stringCamelCase, stringify, u8aConcatStrict, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
@@ -12,11 +12,6 @@ type TypesDef<T = Codec> = Record<string, string | CodecClass<T>>;
|
||||
|
||||
type Definition = [CodecClass[], string[]];
|
||||
|
||||
interface Options {
|
||||
definition?: Definition;
|
||||
setDefinition?: (d: Definition) => Definition;
|
||||
}
|
||||
|
||||
function noopSetDefinition (d: Definition): Definition {
|
||||
return d;
|
||||
}
|
||||
@@ -105,14 +100,14 @@ export class Struct<
|
||||
E extends { [K in keyof S]: string } = { [K in keyof S]: string }> extends Map<keyof S, Codec> implements IStruct<keyof S> {
|
||||
readonly registry: Registry;
|
||||
|
||||
public createdAtHash?: IU8a;
|
||||
public createdAtHash?: IU8a | undefined;
|
||||
public initialU8aLength?: number;
|
||||
public isStorageFallback?: boolean;
|
||||
|
||||
readonly #jsonMap: Map<keyof S, string>;
|
||||
readonly #Types: Definition;
|
||||
|
||||
constructor (registry: Registry, Types: S, value?: V | Map<unknown, unknown> | unknown[] | HexString | null, jsonMap = new Map<string, string>(), { definition, setDefinition = noopSetDefinition }: Options = {}) {
|
||||
constructor (registry: Registry, Types: S, value?: V | Map<unknown, unknown> | unknown[] | HexString | null, jsonMap = new Map<string, string>(), { definition, setDefinition = noopSetDefinition }: DefinitionSetter<Definition> = {}) {
|
||||
const typeMap = definition || setDefinition(mapToTypeMap(registry, Types));
|
||||
const [decoded, decodedLength] = isU8a(value) || isHex(value)
|
||||
? decodeU8aStruct(registry, new Array<[string, Codec]>(typeMap[0].length), u8aToU8a(value), typeMap)
|
||||
|
||||
@@ -9,7 +9,7 @@ import type { Registry } from './registry.js';
|
||||
export type BareOpts = boolean | Record<string, boolean>;
|
||||
|
||||
export interface Inspect {
|
||||
inner?: Inspect[];
|
||||
inner?: Inspect[] | undefined;
|
||||
name?: string;
|
||||
outer?: Uint8Array[];
|
||||
}
|
||||
@@ -28,14 +28,14 @@ export interface Codec {
|
||||
* The block at which this value was retrieved/created (set to non-empty when
|
||||
* retrieved from storage)
|
||||
*/
|
||||
createdAtHash?: IU8a;
|
||||
createdAtHash?: IU8a | undefined;
|
||||
|
||||
/**
|
||||
* @description
|
||||
* The length of the initial encoded value (Only available when the value was
|
||||
* constructed from a Uint8Array input)
|
||||
*/
|
||||
initialU8aLength?: number;
|
||||
initialU8aLength?: number | undefined;
|
||||
|
||||
/**
|
||||
* @description
|
||||
|
||||
@@ -42,4 +42,9 @@ export interface ToBn {
|
||||
toBn: () => BN;
|
||||
}
|
||||
|
||||
export interface DefinitionSetter <T> {
|
||||
definition?: T | undefined;
|
||||
setDefinition?: (d: T) => T;
|
||||
}
|
||||
|
||||
export type LookupString = `Lookup${number}`;
|
||||
|
||||
@@ -31,7 +31,7 @@ export type RegistryTypes =
|
||||
{ _set: Record<string, number> }>;
|
||||
|
||||
export interface CodecCreateOptions {
|
||||
blockHash?: Uint8Array | string | null;
|
||||
blockHash?: Uint8Array | string | null | undefined;
|
||||
isFallback?: boolean;
|
||||
isOptional?: boolean;
|
||||
isPedantic?: boolean;
|
||||
|
||||
@@ -28,20 +28,20 @@ export enum TypeDefInfo {
|
||||
}
|
||||
|
||||
export interface TypeDef {
|
||||
alias?: Map<string, string>;
|
||||
displayName?: string;
|
||||
docs?: string[];
|
||||
fallbackType?: string;
|
||||
alias?: Map<string, string> | undefined;
|
||||
displayName?: string | undefined;
|
||||
docs?: string[] | undefined;
|
||||
fallbackType?: string | undefined;
|
||||
info: TypeDefInfo;
|
||||
index?: number;
|
||||
isFromSi?: boolean;
|
||||
length?: number;
|
||||
lookupIndex?: number;
|
||||
lookupName?: string;
|
||||
lookupNameRoot?: string;
|
||||
name?: string;
|
||||
namespace?: string;
|
||||
lookupName?: string | undefined;
|
||||
lookupNameRoot?: string | undefined;
|
||||
name?: string | undefined;
|
||||
namespace?: string | undefined;
|
||||
sub?: TypeDef | TypeDef[];
|
||||
type: string;
|
||||
typeName?: string;
|
||||
typeName?: string | undefined;
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ export * from './metadata/index.js';
|
||||
export { TypeDefInfo } from '@polkadot/types-create';
|
||||
|
||||
export { convertSiV0toV1 } from './metadata/PortableRegistry/index.js';
|
||||
export { unwrapStorageType } from './util/index.js';
|
||||
export { packageInfo } from './packageInfo.js';
|
||||
export { unwrapStorageType } from './primitive/StorageKey.js';
|
||||
|
||||
export { typeDefinitions, rpcDefinitions };
|
||||
|
||||
@@ -177,7 +177,7 @@ export class TypeRegistry implements Registry {
|
||||
#metadataVersion = 0;
|
||||
#signedExtensions: string[] = fallbackExtensions;
|
||||
#unknownTypes = new Map<string, boolean>();
|
||||
#userExtensions?: ExtDef;
|
||||
#userExtensions?: ExtDef | undefined;
|
||||
|
||||
readonly #knownDefaults: Record<string, CodecClass>;
|
||||
readonly #knownDefinitions: Record<string, Definitions>;
|
||||
|
||||
@@ -234,7 +234,7 @@ abstract class ExtrinsicBase<A extends AnyTuple> extends AbstractBase<ExtrinsicV
|
||||
* - left as is, to create an inherent
|
||||
*/
|
||||
export class GenericExtrinsic<A extends AnyTuple = AnyTuple> extends ExtrinsicBase<A> implements IExtrinsic<A> {
|
||||
#hashCache?: CodecHash;
|
||||
#hashCache?: CodecHash | undefined;
|
||||
|
||||
static LATEST_EXTRINSIC_VERSION = LATEST_EXTRINSIC_VERSION;
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import path from 'node:path';
|
||||
import { hexToU8a, stringCamelCase, stringify, u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { TypeRegistry } from '../../create/index.js';
|
||||
import { unwrapStorageSi, unwrapStorageType } from '../../primitive/StorageKey.js';
|
||||
import { unwrapStorageSi, unwrapStorageType } from '../../util/index.js';
|
||||
import { Metadata } from '../Metadata.js';
|
||||
import { getUniqTypes } from './getUniqTypes.js';
|
||||
|
||||
|
||||
@@ -3,20 +3,21 @@
|
||||
|
||||
import type { AnyJson, AnyTuple, Codec } from '@polkadot/types-codec/types';
|
||||
import type { AllHashers } from '../interfaces/metadata/definitions.js';
|
||||
import type { StorageEntryMetadataLatest, StorageEntryTypeLatest, StorageHasher } from '../interfaces/metadata/index.js';
|
||||
import type { StorageEntryMetadataLatest, StorageHasher } from '../interfaces/metadata/index.js';
|
||||
import type { SiLookupTypeId } from '../interfaces/scaleInfo/index.js';
|
||||
import type { InterfaceTypes, IStorageKey, Registry } from '../types/index.js';
|
||||
import type { IStorageKey, Registry } from '../types/index.js';
|
||||
import type { StorageEntry } from './types.js';
|
||||
|
||||
import { Bytes } from '@polkadot/types-codec';
|
||||
import { isFunction, isString, isU8a } from '@polkadot/util';
|
||||
|
||||
import { getSiName } from '../metadata/util/index.js';
|
||||
import { unwrapStorageType } from '../util/index.js';
|
||||
|
||||
interface Decoded {
|
||||
key?: Uint8Array | string;
|
||||
method?: string;
|
||||
section?: string;
|
||||
key?: Uint8Array | string | undefined;
|
||||
method?: string | undefined;
|
||||
section?: string | undefined;
|
||||
}
|
||||
|
||||
interface StorageKeyExtra {
|
||||
@@ -36,21 +37,6 @@ const HASHER_MAP: Record<keyof typeof AllHashers, [number, boolean]> = {
|
||||
Twox64Concat: [8, true]
|
||||
};
|
||||
|
||||
export function unwrapStorageSi (type: StorageEntryTypeLatest): SiLookupTypeId {
|
||||
return type.isPlain
|
||||
? type.asPlain
|
||||
: type.asMap.value;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function unwrapStorageType (registry: Registry, type: StorageEntryTypeLatest, isOptional?: boolean): keyof InterfaceTypes {
|
||||
const outputType = getSiName(registry.lookup, unwrapStorageSi(type));
|
||||
|
||||
return isOptional
|
||||
? `Option<${outputType}>` as unknown as keyof InterfaceTypes
|
||||
: outputType as keyof InterfaceTypes;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
function decodeStorageKey (value?: string | Uint8Array | StorageKey | StorageEntry | [StorageEntry, unknown[]?]): Decoded {
|
||||
if (isU8a(value) || !value || isString(value)) {
|
||||
@@ -172,10 +158,10 @@ export class StorageKey<A extends AnyTuple = AnyTuple> extends Bytes implements
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore This is assigned via this.decodeArgsFromMeta()
|
||||
#args: A;
|
||||
#meta?: StorageEntryMetadataLatest;
|
||||
#meta?: StorageEntryMetadataLatest | undefined;
|
||||
#outputType: string;
|
||||
#method?: string;
|
||||
#section?: string;
|
||||
#method?: string | undefined;
|
||||
#section?: string | undefined;
|
||||
|
||||
constructor (registry: Registry, value?: string | Uint8Array | StorageKey | StorageEntry | [StorageEntry, unknown[]?], override: Partial<StorageKeyExtra> = {}) {
|
||||
const { key, method, section } = decodeStorageKey(value);
|
||||
|
||||
@@ -11,10 +11,10 @@ import type { ICompact, IKeyringPair, IMethod, INumber, IRuntimeVersionBase } fr
|
||||
import type { Registry } from './registry.js';
|
||||
|
||||
export interface ISubmittableResult {
|
||||
readonly dispatchError?: DispatchError;
|
||||
readonly dispatchInfo?: DispatchInfo;
|
||||
readonly dispatchError?: DispatchError | undefined;
|
||||
readonly dispatchInfo?: DispatchInfo | undefined;
|
||||
readonly events: EventRecord[];
|
||||
readonly internalError?: Error;
|
||||
readonly internalError?: Error | undefined;
|
||||
readonly status: ExtrinsicStatus;
|
||||
readonly isCompleted: boolean;
|
||||
readonly isError: boolean;
|
||||
@@ -22,7 +22,7 @@ export interface ISubmittableResult {
|
||||
readonly isInBlock: boolean;
|
||||
readonly isWarning: boolean;
|
||||
readonly txHash: Hash;
|
||||
readonly txIndex?: number;
|
||||
readonly txIndex?: number | undefined;
|
||||
|
||||
filterRecords (section: string, method: string): EventRecord[];
|
||||
findRecord (section: string, method: string): EventRecord | undefined;
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// Copyright 2017-2023 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from './storage.js';
|
||||
@@ -0,0 +1,24 @@
|
||||
// Copyright 2017-2023 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { StorageEntryTypeLatest } from '../interfaces/metadata/index.js';
|
||||
import type { SiLookupTypeId } from '../interfaces/scaleInfo/index.js';
|
||||
import type { InterfaceTypes, Registry } from '../types/index.js';
|
||||
|
||||
import { getSiName } from '../metadata/util/index.js';
|
||||
|
||||
/** @internal */
|
||||
export function unwrapStorageSi (type: StorageEntryTypeLatest): SiLookupTypeId {
|
||||
return type.isPlain
|
||||
? type.asPlain
|
||||
: type.asMap.value;
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function unwrapStorageType (registry: Registry, type: StorageEntryTypeLatest, isOptional?: boolean): keyof InterfaceTypes {
|
||||
const outputType = getSiName(registry.lookup, unwrapStorageSi(type));
|
||||
|
||||
return isOptional
|
||||
? `Option<${outputType}>` as unknown as keyof InterfaceTypes
|
||||
: outputType as keyof InterfaceTypes;
|
||||
}
|
||||
Reference in New Issue
Block a user