Use call.transactionPaymentApi.queryInfo (#5160)

* Use call.transactionPaymentApi.queryInfo

* Asserts for availability
This commit is contained in:
Jaco
2022-08-15 10:48:24 +03:00
committed by GitHub
parent d6b2760de5
commit 5382cb60b0
4 changed files with 32 additions and 8 deletions
+7
View File
@@ -1,5 +1,12 @@
# CHANGELOG # CHANGELOG
## master
Changes:
- Replace `rpc.payment.queryInfo` usage with `call.transactionPaymentApi.queryInfo`
## 9.2.1 Aug 13, 2022 ## 9.2.1 Aug 13, 2022
- **Important** If using `import { WellKnownChain } from '@polkadot/rpc-provider'` it is recommended that you rather use `ScProvider.WellKnownChain` (the import may be dropped in a future major version) - **Important** If using `import { WellKnownChain } from '@polkadot/rpc-provider'` it is recommended that you rather use `ScProvider.WellKnownChain` (the import may be dropped in a future major version)
+4 -2
View File
@@ -10,7 +10,7 @@ import type { Registry, Signer } from '@polkadot/types/types';
// A smaller interface of ApiRx, used in derive and in SubmittableExtrinsic // A smaller interface of ApiRx, used in derive and in SubmittableExtrinsic
export interface ApiInterfaceRx { export interface ApiInterfaceRx {
call: QueryableCalls<'rxjs'>, call: QueryableCalls<'rxjs'>;
consts: QueryableConsts<'rxjs'>; consts: QueryableConsts<'rxjs'>;
extrinsicType: number; extrinsicType: number;
genesisHash?: Hash; genesisHash?: Hash;
@@ -19,9 +19,11 @@ export interface ApiInterfaceRx {
runtimeMetadata: Metadata; runtimeMetadata: Metadata;
runtimeVersion: RuntimeVersion; runtimeVersion: RuntimeVersion;
query: QueryableStorage<'rxjs'>; query: QueryableStorage<'rxjs'>;
queryAt: (blockHash: Uint8Array | string, knownVersion?: RuntimeVersion) => Observable<QueryableStorage<'rxjs'>>;
queryMulti: QueryableStorageMulti<'rxjs'>; queryMulti: QueryableStorageMulti<'rxjs'>;
rpc: DecoratedRpc<'rxjs', RpcInterface>; rpc: DecoratedRpc<'rxjs', RpcInterface>;
tx: SubmittableExtrinsics<'rxjs'>; tx: SubmittableExtrinsics<'rxjs'>;
signer?: Signer; signer?: Signer;
callAt: (blockHash: Uint8Array | string, knownVersion?: RuntimeVersion) => Observable<QueryableCalls<'rxjs'>>;
queryAt: (blockHash: Uint8Array | string, knownVersion?: RuntimeVersion) => Observable<QueryableStorage<'rxjs'>>;
} }
+2
View File
@@ -160,6 +160,8 @@ export abstract class Decorate<ApiType extends ApiTypes> extends Events {
this.#instanceId = `${++instanceCounter}`; this.#instanceId = `${++instanceCounter}`;
this.#registry = options.source?.registry || options.registry || new TypeRegistry(); this.#registry = options.source?.registry || options.registry || new TypeRegistry();
this._rx.callAt = (blockHash: Uint8Array | string, knownVersion?: RuntimeVersion) =>
from(this.at(blockHash, knownVersion)).pipe(map((a) => a.rx.call));
this._rx.queryAt = (blockHash: Uint8Array | string, knownVersion?: RuntimeVersion) => this._rx.queryAt = (blockHash: Uint8Array | string, knownVersion?: RuntimeVersion) =>
from(this.at(blockHash, knownVersion)).pipe(map((a) => a.rx.query)); from(this.at(blockHash, knownVersion)).pipe(map((a) => a.rx.query));
this._rx.registry = this.#registry; this._rx.registry = this.#registry;
+19 -6
View File
@@ -102,6 +102,10 @@ export function createClass <ApiType extends ApiTypes> ({ api, apiType, blockHas
// dry run an extrinsic // dry run an extrinsic
public dryRun (account: AddressOrPair, optionsOrHash?: Partial<SignerOptions> | Uint8Array | string): SubmittableDryRunResult<ApiType> { public dryRun (account: AddressOrPair, optionsOrHash?: Partial<SignerOptions> | Uint8Array | string): SubmittableDryRunResult<ApiType> {
if (!api.rpc.system || !api.rpc.system.dryRun) {
throw new Error('The system.dryRun RPC call is not available in your environment');
}
if (blockHash || isString(optionsOrHash) || isU8a(optionsOrHash)) { if (blockHash || isString(optionsOrHash) || isU8a(optionsOrHash)) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return // eslint-disable-next-line @typescript-eslint/no-unsafe-return
return decorateMethod( return decorateMethod(
@@ -120,11 +124,21 @@ export function createClass <ApiType extends ApiTypes> ({ api, apiType, blockHas
// calculate the payment info for this transaction (if signed and submitted) // calculate the payment info for this transaction (if signed and submitted)
public paymentInfo (account: AddressOrPair, optionsOrHash?: Partial<SignerOptions> | Uint8Array | string): SubmittablePaymentResult<ApiType> { public paymentInfo (account: AddressOrPair, optionsOrHash?: Partial<SignerOptions> | Uint8Array | string): SubmittablePaymentResult<ApiType> {
if (!api.call.transactionPaymentApi || !api.call.transactionPaymentApi.queryInfo) {
throw new Error('The transactionPaymentApi.queryInfo runtime call is not available in your environment');
}
if (blockHash || isString(optionsOrHash) || isU8a(optionsOrHash)) { if (blockHash || isString(optionsOrHash) || isU8a(optionsOrHash)) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return // eslint-disable-next-line @typescript-eslint/no-unsafe-return
return decorateMethod( return decorateMethod(
(): Observable<RuntimeDispatchInfo> => (): Observable<RuntimeDispatchInfo> =>
api.rpc.payment.queryInfo(this.toHex(), blockHash || optionsOrHash as string) api.callAt(blockHash || optionsOrHash as string).pipe(
switchMap((callAt): Observable<RuntimeDispatchInfo> => {
const u8a = this.toU8a();
return callAt.transactionPaymentApi.queryInfo(u8a, u8a.length);
})
)
); );
} }
@@ -140,12 +154,11 @@ export function createClass <ApiType extends ApiTypes> ({ api, apiType, blockHas
// setup our options (same way as in signAndSend) // setup our options (same way as in signAndSend)
const eraOptions = makeEraOptions(api, this.registry, allOptions, signingInfo); const eraOptions = makeEraOptions(api, this.registry, allOptions, signingInfo);
const signOptions = makeSignOptions(api, eraOptions, {}); const signOptions = makeSignOptions(api, eraOptions, {});
const u8a = this.isSigned
? api.tx(this).signFake(address, signOptions).toU8a()
: this.signFake(address, signOptions).toU8a();
return api.rpc.payment.queryInfo( return api.call.transactionPaymentApi.queryInfo(u8a, u8a.length);
this.isSigned
? api.tx(this).signFake(address, signOptions).toHex()
: this.signFake(address, signOptions).toHex()
);
}) })
) )
)(); )();