Skip to content

Commit

Permalink
fix: add TransactionPayment::TransactionPaidFee support (#1040)
Browse files Browse the repository at this point in the history
* fix: add TransactionPayment::TransactionPaidFee support

* add e2e-tests for kusama

* add e2e tests to polkadot

* add `fromEvent` dispatchFeeType
  • Loading branch information
TarikGul committed Sep 6, 2022
1 parent 4820342 commit 108a93b
Show file tree
Hide file tree
Showing 8 changed files with 9,433 additions and 26 deletions.
7 changes: 4 additions & 3 deletions docs/src/openapi-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2434,9 +2434,10 @@ components:
format: unsignedInteger
kind:
type: string
description: Information on the partialFee that is collected. Can be either `preDispatch` or `postDispatch`.
`preDispatch` means the information used to collect the fee was from `payment_queryInfo`, and `postDispatch` means
the information used to calculate the fee was from finalized weights for the extrinsic.
description: Information on the partialFee that is collected. Can be either `preDispatch`, `postDispatch` or `fromEvent`.
`preDispatch` means the information used to collect the fee was from `payment_queryInfo`, `postDispatch` means
the information used to calculate the fee was from finalized weights for the extrinsic, and `fromEvent` means that the partialFee was
abstracted from the `TransactionPayment::TransactionPaidFee` event.
description: RuntimeDispatchInfo for the transaction. Includes the `partialFee`.
RuntimeSpec:
type: object
Expand Down
2,440 changes: 2,440 additions & 0 deletions e2e-tests/endpoints/kusama/blocks/13556605.json

Large diffs are not rendered by default.

2,737 changes: 2,737 additions & 0 deletions e2e-tests/endpoints/kusama/blocks/14255072.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions e2e-tests/endpoints/kusama/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ import block11000000 from './11000000.json';
import block11100000 from './11100000.json';
import block11500000 from './11500000.json';
import block11800000 from './11800000.json';
import block13556605 from './13556605.json';
import block14255072 from './14255072.json';

export const kusamaBlockEndpoints = [
['/blocks/9253', JSON.stringify(block9253)], //v1020
Expand Down Expand Up @@ -86,4 +88,6 @@ export const kusamaBlockEndpoints = [
['/blocks/11100000', JSON.stringify(block11100000)], //v9151
['/blocks/11500000', JSON.stringify(block11500000)], //v9160
['/blocks/11800000', JSON.stringify(block11800000)], //v9170
['/blocks/13556605', JSON.stringify(block13556605)], //v9250
['/blocks/14255072', JSON.stringify(block14255072)], //v9271
];
1,965 changes: 1,965 additions & 0 deletions e2e-tests/endpoints/polkadot/blocks/11452239.json

Large diffs are not rendered by default.

2,245 changes: 2,245 additions & 0 deletions e2e-tests/endpoints/polkadot/blocks/11852237.json

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions e2e-tests/endpoints/polkadot/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import block8320000 from './8320000.json';
import block8500000 from './8500000.json';
import block8891183 from './8891183.json';
import block9500000 from './9500000.json';
import block11452239 from './11452239.json';
import block11852237 from './11852237.json';

export const polkadotBlockEndpoints = [
['/blocks/943438', JSON.stringify(block943438)], //v17
Expand All @@ -56,4 +58,6 @@ export const polkadotBlockEndpoints = [
['/blocks/8500000', JSON.stringify(block8500000)], //v9140
['/blocks/8891183', JSON.stringify(block8891183)], //v9151
['/blocks/9500000', JSON.stringify(block9500000)], //v9170
['/blocks/11452239', JSON.stringify(block11452239)], //v9250
['/blocks/11852237', JSON.stringify(block11852237)], //v9260
];
57 changes: 34 additions & 23 deletions src/services/blocks/BlocksService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ interface FetchBlockOptions {
enum Event {
success = 'ExtrinsicSuccess',
failure = 'ExtrinsicFailed',
transactionPaidFee = 'TransactionFeePaid',
}

export class BlocksService extends AbstractService {
Expand Down Expand Up @@ -264,40 +265,50 @@ export class BlocksService extends AbstractService {
previousBlockHash
);

const doesQueryFeeDetailsExist = this.hasQueryFeeApi.hasQueryFeeDetails(
specVersion.toNumber()
const transactionPaidFeeEvent = xtEvents.find(
({ method }) =>
isFrameMethod(method) && method.method === Event.transactionPaidFee
);

let finalPartialFee = partialFee.toString(),
dispatchFeeType = 'preDispatch';
/**
* Call queryFeeDetails. It may not be available in the runtime and will
* error automatically when we try to call it. We cache the runtimes it will error so we
* don't try to call it again given a specVersion.
*/
if (doesQueryFeeDetailsExist === 'available') {
finalPartialFee = await this.fetchQueryFeeDetails(
block.extrinsics[idx].toHex(),
previousBlockHash,
weightInfo.weight,
weight
if (transactionPaidFeeEvent) {
finalPartialFee = transactionPaidFeeEvent.data[1].toString();
dispatchFeeType = 'fromEvent';
} else {
/**
* Call queryFeeDetails. It may not be available in the runtime and will
* error automatically when we try to call it. We cache the runtimes it will error so we
* don't try to call it again given a specVersion.
*/
const doesQueryFeeDetailsExist = this.hasQueryFeeApi.hasQueryFeeDetails(
specVersion.toNumber()
);

dispatchFeeType = 'postDispatch';
} else if (doesQueryFeeDetailsExist === 'unknown') {
try {
if (doesQueryFeeDetailsExist === 'available') {
finalPartialFee = await this.fetchQueryFeeDetails(
block.extrinsics[idx].toHex(),
previousBlockHash,
weightInfo.weight,
weight
);

dispatchFeeType = 'postDispatch';
this.hasQueryFeeApi.setRegisterWithCall(specVersion.toNumber());
} catch {
this.hasQueryFeeApi.setRegisterWithoutCall(specVersion.toNumber());
console.warn(
'The error above is automatically emitted from polkadot-js, and can be ignored.'
);
} else if (doesQueryFeeDetailsExist === 'unknown') {
try {
finalPartialFee = await this.fetchQueryFeeDetails(
block.extrinsics[idx].toHex(),
previousBlockHash,
weightInfo.weight,
weight
);
dispatchFeeType = 'postDispatch';
this.hasQueryFeeApi.setRegisterWithCall(specVersion.toNumber());
} catch {
this.hasQueryFeeApi.setRegisterWithoutCall(specVersion.toNumber());
console.warn(
'The error above is automatically emitted from polkadot-js, and can be ignored.'
);
}
}
}

Expand Down

0 comments on commit 108a93b

Please sign in to comment.