Add support for apiAt.tx(...) (#4696)
* Add support for apiAt.tx(...) * CHANGELOG
This commit is contained in:
@@ -199,18 +199,23 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
return this._rpcCore.provider.hasSubscriptions || !!this._rpcCore.state.queryStorageAt;
|
||||
}
|
||||
|
||||
protected _emptyDecorated (registry: Registry, blockHash?: Uint8Array): ApiDecoration<ApiType> {
|
||||
return {
|
||||
consts: {},
|
||||
errors: {},
|
||||
events: {},
|
||||
query: {},
|
||||
registry,
|
||||
rx: {
|
||||
query: {}
|
||||
},
|
||||
tx: createSubmittable(this._type, this._rx, this._decorateMethod, registry, blockHash)
|
||||
} as ApiDecoration<ApiType>;
|
||||
}
|
||||
|
||||
protected _createDecorated (registry: VersionedRegistry<ApiType>, fromEmpty: boolean, decoratedApi: ApiDecoration<ApiType> | null, blockHash?: Uint8Array): FullDecoration<ApiType> {
|
||||
if (!decoratedApi) {
|
||||
decoratedApi = {
|
||||
consts: {},
|
||||
errors: {},
|
||||
events: {},
|
||||
query: {},
|
||||
registry: registry.registry,
|
||||
rx: {
|
||||
query: {}
|
||||
}
|
||||
} as ApiDecoration<ApiType>;
|
||||
decoratedApi = this._emptyDecorated(registry.registry, blockHash);
|
||||
}
|
||||
|
||||
if (fromEmpty || !registry.decoratedMeta) {
|
||||
@@ -243,16 +248,7 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
||||
protected _injectMetadata (registry: VersionedRegistry<ApiType>, fromEmpty = false): void {
|
||||
// clear the decoration, we are redoing it here
|
||||
if (fromEmpty || !registry.decoratedApi) {
|
||||
registry.decoratedApi = {
|
||||
consts: {},
|
||||
errors: {},
|
||||
events: {},
|
||||
query: {},
|
||||
registry: registry.registry,
|
||||
rx: {
|
||||
query: {}
|
||||
}
|
||||
} as ApiDecoration<ApiType>;
|
||||
registry.decoratedApi = this._emptyDecorated(registry.registry);
|
||||
}
|
||||
|
||||
const { decoratedApi, decoratedMeta } = this._createDecorated(registry, fromEmpty, registry.decoratedApi);
|
||||
|
||||
@@ -21,6 +21,7 @@ import { SubmittableResult } from './Result';
|
||||
interface SubmittableOptions<ApiType extends ApiTypes> {
|
||||
api: ApiInterfaceRx;
|
||||
apiType: ApiTypes;
|
||||
blockHash?: Uint8Array;
|
||||
decorateMethod: ApiBase<ApiType>['_decorateMethod'];
|
||||
}
|
||||
|
||||
@@ -80,7 +81,7 @@ function optionsOrNonce (partialOptions: Partial<SignerOptions> = {}): Partial<S
|
||||
: partialOptions;
|
||||
}
|
||||
|
||||
export function createClass <ApiType extends ApiTypes> ({ api, apiType, decorateMethod }: SubmittableOptions<ApiType>): Constructor<SubmittableExtrinsic<ApiType>> {
|
||||
export function createClass <ApiType extends ApiTypes> ({ api, apiType, blockHash, decorateMethod }: SubmittableOptions<ApiType>): Constructor<SubmittableExtrinsic<ApiType>> {
|
||||
// an instance of the base extrinsic for us to extend
|
||||
const ExtrinsicBase = api.registry.createClass('Extrinsic');
|
||||
|
||||
@@ -97,10 +98,10 @@ export function createClass <ApiType extends ApiTypes> ({ api, apiType, decorate
|
||||
|
||||
// dry run an extrinsic
|
||||
public dryRun (account: AddressOrPair, optionsOrHash?: Partial<SignerOptions> | Uint8Array | string): SubmittableDryRunResult<ApiType> {
|
||||
if (isString(optionsOrHash) || isU8a(optionsOrHash)) {
|
||||
if (blockHash || isString(optionsOrHash) || isU8a(optionsOrHash)) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return decorateMethod(
|
||||
() => api.rpc.system.dryRun(this.toHex(), optionsOrHash)
|
||||
() => api.rpc.system.dryRun(this.toHex(), blockHash || optionsOrHash as string)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -115,10 +116,10 @@ export function createClass <ApiType extends ApiTypes> ({ api, apiType, decorate
|
||||
|
||||
// calculate the payment info for this transaction (if signed and submitted)
|
||||
public paymentInfo (account: AddressOrPair, optionsOrHash?: Partial<SignerOptions> | Uint8Array | string): SubmittablePaymentResult<ApiType> {
|
||||
if (isString(optionsOrHash) || isU8a(optionsOrHash)) {
|
||||
if (blockHash || isString(optionsOrHash) || isU8a(optionsOrHash)) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return decorateMethod(
|
||||
(): Observable<RuntimeDispatchInfo> => api.rpc.payment.queryInfo(this.toHex(), optionsOrHash)
|
||||
(): Observable<RuntimeDispatchInfo> => api.rpc.payment.queryInfo(this.toHex(), blockHash || optionsOrHash as string)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Call, Extrinsic } from '@polkadot/types/interfaces';
|
||||
import type { Registry } from '@polkadot/types-codec/types';
|
||||
import type { ApiInterfaceRx, ApiTypes } from '../types';
|
||||
import type { SubmittableExtrinsic } from './types';
|
||||
|
||||
@@ -10,9 +11,9 @@ import { createClass } from './createClass';
|
||||
|
||||
type Creator<ApiType extends ApiTypes> = (extrinsic: Call | Uint8Array | string) => SubmittableExtrinsic<ApiType>;
|
||||
|
||||
export function createSubmittable<ApiType extends ApiTypes> (apiType: ApiTypes, api: ApiInterfaceRx, decorateMethod: ApiBase<ApiType>['_decorateMethod']): Creator<ApiType> {
|
||||
const Submittable = createClass<ApiType>({ api, apiType, decorateMethod });
|
||||
export function createSubmittable<ApiType extends ApiTypes> (apiType: ApiTypes, api: ApiInterfaceRx, decorateMethod: ApiBase<ApiType>['_decorateMethod'], registry?: Registry, blockHash?: Uint8Array): Creator<ApiType> {
|
||||
const Submittable = createClass<ApiType>({ api, apiType, blockHash, decorateMethod });
|
||||
|
||||
return (extrinsic: Call | Extrinsic | Uint8Array | string): SubmittableExtrinsic<ApiType> =>
|
||||
new Submittable(api.registry, extrinsic);
|
||||
new Submittable(registry || api.registry, extrinsic);
|
||||
}
|
||||
|
||||
@@ -9,11 +9,12 @@ import type { DecoratedEvents } from '@polkadot/api-base/types/events';
|
||||
import type { QueryableStorage } from '@polkadot/api-base/types/storage';
|
||||
import type { ProviderInterface, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types';
|
||||
import type { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';
|
||||
import type { Hash } from '@polkadot/types/interfaces';
|
||||
import type { Call, Extrinsic, Hash } from '@polkadot/types/interfaces';
|
||||
import type { CallFunction, DefinitionRpc, DefinitionRpcSub, RegisteredTypes, Registry, RegistryError, SignatureOptions, Signer } from '@polkadot/types/types';
|
||||
import type { BN } from '@polkadot/util';
|
||||
import type { HexString } from '@polkadot/util/types';
|
||||
import type { ApiBase } from '../base';
|
||||
import type { SubmittableExtrinsic } from '../types/submittable';
|
||||
import type { AllDerives } from '../util/decorate';
|
||||
|
||||
export * from '@polkadot/api-base/types';
|
||||
@@ -96,7 +97,8 @@ export interface ApiDecoration<ApiType extends ApiTypes> {
|
||||
registry: Registry;
|
||||
rx: {
|
||||
query: QueryableStorage<'rxjs'>;
|
||||
}
|
||||
};
|
||||
tx: (extrinsic: Call | Extrinsic | Uint8Array | string) => SubmittableExtrinsic<ApiType>;
|
||||
|
||||
findCall (callIndex: Uint8Array | string): CallFunction;
|
||||
findError (errorIndex: Uint8Array | string): RegistryError;
|
||||
|
||||
Reference in New Issue
Block a user