Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added query to calc fees #1366

Merged
merged 6 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/dist/app.bundle.js

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions docs/src/openapi-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,13 @@ paths:
schema:
type: boolean
default: false
- name: noFees
in: query
description: When set to `true`, the fee won't be calculated for the extrinsics.
required: false
schema:
type: boolean
default: false
responses:
"200":
description: successful operation
Expand Down Expand Up @@ -621,6 +628,13 @@ paths:
schema:
type: boolean
default: false
- name: noFees
in: query
description: When set to `true`, the fee won't be calculated for the extrinsics.
required: false
schema:
type: boolean
default: false
- name: finalizedKey
in: query
description: When set to false, this will override the chain-config, and omit the
Expand Down Expand Up @@ -756,6 +770,13 @@ paths:
schema:
type: boolean
default: false
- name: noFees
in: query
description: When set to `true`, the fee won't be calculated for the extrinsics.
required: false
schema:
type: boolean
default: false
responses:
"200":
description: successful operation
Expand Down
12 changes: 9 additions & 3 deletions src/controllers/blocks/BlocksController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export default class BlocksController extends AbstractController<BlocksService>
* @param _req Express Request
* @param res Express Response
*/
private getLatestBlock: RequestHandler = async ({ query: { eventDocs, extrinsicDocs, finalized } }, res) => {
private getLatestBlock: RequestHandler = async ({ query: { eventDocs, extrinsicDocs, finalized, noFees } }, res) => {
const eventDocsArg = eventDocs === 'true';
const extrinsicDocsArg = extrinsicDocs === 'true';

Expand All @@ -138,13 +138,15 @@ export default class BlocksController extends AbstractController<BlocksService>
queryFinalizedHead = false;
hash = await this.api.rpc.chain.getFinalizedHead();
}
const noFeesArg = noFees === 'true';

const options = {
eventDocs: eventDocsArg,
extrinsicDocs: extrinsicDocsArg,
checkFinalized: false,
queryFinalizedHead,
omitFinalizedTag,
noFees: noFeesArg,
};

const historicApi = await this.api.at(hash);
Expand All @@ -159,7 +161,7 @@ export default class BlocksController extends AbstractController<BlocksService>
* @param res Express Response
*/
private getBlockById: RequestHandler<INumberParam> = async (
{ params: { number }, query: { eventDocs, extrinsicDocs, finalizedKey } },
{ params: { number }, query: { eventDocs, extrinsicDocs, noFees, finalizedKey } },
res,
): Promise<void> => {
const checkFinalized = isHex(number);
Expand All @@ -171,6 +173,7 @@ export default class BlocksController extends AbstractController<BlocksService>
const finalizeOverride = finalizedKey === 'false';

const queryFinalizedHead = !this.options.finalizes ? false : true;
const noFeesArg = noFees === 'true';
let omitFinalizedTag = !this.options.finalizes ? true : false;

if (finalizeOverride) {
Expand All @@ -183,6 +186,7 @@ export default class BlocksController extends AbstractController<BlocksService>
checkFinalized,
queryFinalizedHead,
omitFinalizedTag,
noFees: noFeesArg,
};

// HistoricApi to fetch any historic information that doesnt include the current runtime
Expand Down Expand Up @@ -225,7 +229,7 @@ export default class BlocksController extends AbstractController<BlocksService>
* @param res Express Response
*/
private getBlocks: RequestHandler<unknown, unknown, unknown, IRangeQueryParam> = async (
{ query: { range, eventDocs, extrinsicDocs } },
{ query: { range, eventDocs, extrinsicDocs, noFees } },
res,
): Promise<void> => {
if (!range) throw new BadRequest('range query parameter must be inputted.');
Expand All @@ -237,12 +241,14 @@ export default class BlocksController extends AbstractController<BlocksService>
const extrinsicDocsArg = extrinsicDocs === 'true';
const queryFinalizedHead = !this.options.finalizes ? false : true;
const omitFinalizedTag = !this.options.finalizes ? true : false;
const noFeesArg = noFees === 'true';
const options = {
eventDocs: eventDocsArg,
extrinsicDocs: extrinsicDocsArg,
checkFinalized: false,
queryFinalizedHead,
omitFinalizedTag,
noFees: noFeesArg,
};

const pQueue = new PromiseQueue(4);
Expand Down
4 changes: 3 additions & 1 deletion src/controllers/blocks/BlocksExtrinsicsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,22 @@ export default class BlocksExtrinsicsController extends AbstractController<Block
* @param res Express Response
*/
private getExtrinsicByTimepoint: RequestHandler<INumberParam> = async (
{ params: { blockId, extrinsicIndex }, query: { eventDocs, extrinsicDocs } },
{ params: { blockId, extrinsicIndex }, query: { eventDocs, extrinsicDocs, noFees } },
res,
): Promise<void> => {
const hash = await this.getHashForBlock(blockId);

const eventDocsArg = eventDocs === 'true';
const extrinsicDocsArg = extrinsicDocs === 'true';
const noFeesArg = noFees === 'true';

const options = {
eventDocs: eventDocsArg,
extrinsicDocs: extrinsicDocsArg,
checkFinalized: true,
queryFinalizedHead: false,
omitFinalizedTag: true,
noFees: noFeesArg,
};

const historicApi = await this.api.at(hash);
Expand Down
5 changes: 5 additions & 0 deletions src/services/blocks/BlocksService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ describe('BlocksService', () => {
checkFinalized: false,
queryFinalizedHead: false,
omitFinalizedTag: false,
noFees: false,
};

expect(sanitizeNumbers(await blocksService.fetchBlock(blockHash789629, mockHistoricApi, options))).toMatchObject(
Expand All @@ -146,6 +147,7 @@ describe('BlocksService', () => {
checkFinalized: false,
queryFinalizedHead: false,
omitFinalizedTag: false,
noFees: false,
};
const tempGetBlock = mockApi.rpc.chain.getBlock;
mockApi.rpc.chain.getBlock = (() =>
Expand All @@ -170,6 +172,7 @@ describe('BlocksService', () => {
checkFinalized: false,
queryFinalizedHead: false,
omitFinalizedTag: true,
noFees: false,
};

const block = await blocksService.fetchBlock(blockHash789629, mockHistoricApi, options);
Expand Down Expand Up @@ -357,6 +360,7 @@ describe('BlocksService', () => {
checkFinalized: false,
queryFinalizedHead: false,
omitFinalizedTag: false,
noFees: false,
};

it('Returns the correct extrinisics object for block 789629', async () => {
Expand Down Expand Up @@ -442,6 +446,7 @@ describe('BlocksService', () => {
checkFinalized: false,
queryFinalizedHead: false,
omitFinalizedTag: false,
noFees: false,
};

it('Should correctly store the most recent queried blocks', async () => {
Expand Down
8 changes: 7 additions & 1 deletion src/services/blocks/BlocksService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ interface FetchBlockOptions {
checkFinalized: boolean;
queryFinalizedHead: boolean;
omitFinalizedTag: boolean;
noFees: boolean;
}

/**
Expand Down Expand Up @@ -101,7 +102,7 @@ export class BlocksService extends AbstractService {
async fetchBlock(
hash: BlockHash,
historicApi: ApiDecoration<'promise'>,
{ eventDocs, extrinsicDocs, checkFinalized, queryFinalizedHead, omitFinalizedTag }: FetchBlockOptions,
{ eventDocs, extrinsicDocs, checkFinalized, queryFinalizedHead, omitFinalizedTag, noFees }: FetchBlockOptions,
): Promise<IBlock> {
const { api } = this;

Expand Down Expand Up @@ -168,6 +169,11 @@ export class BlocksService extends AbstractService {
const previousBlockHash = await this.fetchPreviousBlockHash(number);

for (let idx = 0; idx < block.extrinsics.length; ++idx) {
if (noFees) {
extrinsics[idx].info = {};
continue;
}

if (!extrinsics[idx].paysFee || !block.extrinsics[idx].isSigned) {
continue;
}
Expand Down
Loading