diff --git a/src/services/blocks/BlocksService.ts b/src/services/blocks/BlocksService.ts index b612815de..608529b30 100644 --- a/src/services/blocks/BlocksService.ts +++ b/src/services/blocks/BlocksService.ts @@ -18,6 +18,7 @@ import { ApiPromise } from '@polkadot/api'; import { ApiDecoration } from '@polkadot/api/types'; import { extractAuthor } from '@polkadot/api-derive/type/util'; import { Compact, GenericCall, Option, Struct, Vec } from '@polkadot/types'; +import { GenericExtrinsic } from '@polkadot/types/extrinsic'; import { AccountId32, Block, @@ -27,6 +28,7 @@ import { EventRecord, Header, InclusionFee, + RuntimeDispatchInfo, Weight, } from '@polkadot/types/interfaces'; import { AnyJson, Codec, Registry } from '@polkadot/types/types'; @@ -260,10 +262,7 @@ export class BlocksService extends AbstractService { class: dispatchClass, partialFee, weight, - } = await api.rpc.payment.queryInfo( - block.extrinsics[idx].toHex(), - previousBlockHash - ); + } = await this.fetchQueryInfo(block.extrinsics[idx], previousBlockHash); const transactionPaidFeeEvent = xtEvents.find( ({ method }) => @@ -286,7 +285,7 @@ export class BlocksService extends AbstractService { ); if (doesQueryFeeDetailsExist === 'available') { finalPartialFee = await this.fetchQueryFeeDetails( - block.extrinsics[idx].toHex(), + block.extrinsics[idx], previousBlockHash, weightInfo.weight, weight @@ -296,7 +295,7 @@ export class BlocksService extends AbstractService { } else if (doesQueryFeeDetailsExist === 'unknown') { try { finalPartialFee = await this.fetchQueryFeeDetails( - block.extrinsics[idx].toHex(), + block.extrinsics[idx], previousBlockHash, weightInfo.weight, weight @@ -343,22 +342,36 @@ export class BlocksService extends AbstractService { /** * Fetch `payment_queryFeeDetails`. * - * @param extHex + * @param ext * @param previousBlockHash * @param extrinsicSuccessWeight * @param estWeight */ private async fetchQueryFeeDetails( - extHex: `0x${string}`, + ext: GenericExtrinsic, previousBlockHash: BlockHash, extrinsicSuccessWeight: Weight, estWeight: Weight ): Promise { const { api } = this; - const { inclusionFee } = await api.rpc.payment.queryFeeDetails( - extHex, - previousBlockHash - ); + const apiAt = await api.at(previousBlockHash); + + let inclusionFee; + if (apiAt.call.transactionPaymentApi.queryFeeDetails) { + const u8a = ext.toU8a(); + const result = await apiAt.call.transactionPaymentApi.queryFeeDetails( + u8a, + u8a.length + ); + inclusionFee = result.inclusionFee; + } else { + const result = await api.rpc.payment.queryFeeDetails( + ext.toHex(), + previousBlockHash + ); + inclusionFee = result.inclusionFee; + } + const finalPartialFee = this.calcPartialFee( extrinsicSuccessWeight, estWeight, @@ -368,6 +381,27 @@ export class BlocksService extends AbstractService { return finalPartialFee; } + /** + * Fetch `payment_queryInfo`. + * + * @param ext + * @param previousBlockHash + */ + private async fetchQueryInfo( + ext: GenericExtrinsic, + previousBlockHash: BlockHash + ): Promise { + const { api } = this; + const apiAt = await api.at(previousBlockHash); + if (apiAt.call.transactionPaymentApi.queryInfo) { + const u8a = ext.toU8a(); + return apiAt.call.transactionPaymentApi.queryInfo(u8a, u8a.length); + } else { + // fallback to rpc call + return api.rpc.payment.queryInfo(ext.toHex(), previousBlockHash); + } + } + /** * Retrieve the blockHash for the previous block to the one getting queried. * If the block is the geneisis hash it will return the same blockHash.