Skip to content

Commit

Permalink
feat: add blocks raw extrinsics endpoint (#1334)
Browse files Browse the repository at this point in the history
* add fetchBlockRaw to block service

* add unit test
update latest e2e tests

* feat: add endpoint that queries a block by hash and returns it along with the raw values of its extrinsic(s)

* build docs

* update inline doc

* update number to 0xstring

* update BlockRaw docs summary and description

* update schema pattern

* update docs
  • Loading branch information
marshacb authored Oct 2, 2023
1 parent fbdca75 commit f486aa9
Show file tree
Hide file tree
Showing 41 changed files with 278 additions and 3 deletions.
2 changes: 1 addition & 1 deletion docs/dist/app.bundle.js

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions docs/src/openapi-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,35 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/Error'
/blocks/{blockId}/extrinsics-raw:
get:
tags:
- blocks
summary: Get a blocks header & its extrinsics as hex values.
description: Returns a block & its extrinsics as hex values. BlockId can either be a block hash or a
block height.
operationId: getBlockRawExtrinsics
parameters:
- name: blockId
in: path
description: Block identifier, as the block height or block hash.
required: true
schema:
pattern: '^0[xX][0-9a-fA-F]{1,64}$|[0-9]{1,12}'
type: string
responses:
"200":
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/BlockRaw'
"400":
description: invalid Block identifier supplied
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/contracts/ink/{address}/query:
post:
tags:
Expand Down Expand Up @@ -2483,6 +2512,39 @@ components:
Note: Block finalization does not correspond to consensus, i.e. whether
the block is in the canonical chain. It denotes the finalization of block
_construction._
BlockRaw:
type: object
properties:
number:
type: string
description: The block's height.
format: unsignedInteger
parentHash:
type: string
description: The hash of the parent block.
format: hex
stateRoot:
type: string
description: The state root after executing this block.
format: hex
extrinsicRoot:
type: string
description: The Merkle root of the extrinsics.
format: hex
digest:
type: object
properties:
logs:
type: array
items:
$ref: '#/components/schemas/DigestItem'
description: Array of `DigestItem`s associated with the block.
extrinsics:
type: array
description: Array of raw extrinsics (inherents and transactions) within the
block.
items:
type: string
Blocks:
type: array
items:
Expand Down
4 changes: 4 additions & 0 deletions e2e-tests/latest/endpoints/acala.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ export const acala: IConfig = {
path: '/blocks/head',
queryParams: [],
},
'/blocks/{blockId}/extrinsics-raw': {
path: `/blocks/{blockId}/extrinsics-raw`,
queryParams: [],
},
'/node/network': {
path: '/node/network',
queryParams: [],
Expand Down
4 changes: 4 additions & 0 deletions e2e-tests/latest/endpoints/kusama.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export const kusama: IConfig = {
path: '/blocks/head',
queryParams: [],
},
'/blocks/{blockId}/extrinsics-raw': {
path: `/blocks/{blockId}/extrinsics-raw`,
queryParams: [],
},
'/node/network': {
path: '/node/network',
queryParams: [],
Expand Down
4 changes: 4 additions & 0 deletions e2e-tests/latest/endpoints/polkadot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ export const polkadot: IConfig = {
path: '/blocks/head',
queryParams: [],
},
'/blocks/{blockId}/extrinsics-raw': {
path: `/blocks/{blockId}/extrinsics-raw`,
queryParams: [],
},
'/node/network': {
path: '/node/network',
queryParams: [],
Expand Down
4 changes: 4 additions & 0 deletions e2e-tests/latest/endpoints/westend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ export const westend: IConfig = {
path: '/blocks/head',
queryParams: [],
},
'/blocks/{blockId}/extrinsics-raw': {
path: `/blocks/{blockId}/extrinsics-raw`,
queryParams: [],
},
'/node/network': {
path: '/node/network',
queryParams: [],
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/acalaControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const acalaControllers: ControllerConfig = {
'AccountsValidate',
'Blocks',
'BlocksExtrinsics',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/assetHubKusamaControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const assetHubKusamaControllers: ControllerConfig = {
'AccountsValidate',
'Blocks',
'BlocksExtrinsics',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/assetHubPolkadotControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const assetHubPolkadotControllers: ControllerConfig = {
'AccountsValidate',
'Blocks',
'BlocksExtrinsics',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/assetHubWestendControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const assetHubWestendControllers: ControllerConfig = {
'AccountsValidate',
'Blocks',
'BlocksExtrinsics',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/astarControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const astarControllers: ControllerConfig = {
'Blocks',
'BlocksExtrinsics',
'BlocksTrace',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/bifrostControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const bifrostControllers: ControllerConfig = {
'AccountsValidate',
'Blocks',
'BlocksExtrinsics',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/bifrostPolkadotControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const bifrostPolkadotControllers: ControllerConfig = {
'AccountsValidate',
'Blocks',
'BlocksExtrinsics',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/calamariControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const calamariControllers: ControllerConfig = {
'AccountsVestingInfo',
'Blocks',
'BlocksExtrinsics',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/crustControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const crustControllers: ControllerConfig = {
'AccountsValidate',
'Blocks',
'BlocksExtrinsics',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/defaultControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const defaultControllers: ControllerConfig = {
'AccountsVestingInfo',
'Blocks',
'BlocksExtrinsics',
'BlocksRawExtrinsics',
'ContractsInk',
'NodeNetwork',
'NodeTransactionPool',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/dockMainnetControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const dockMainnetControllers: ControllerConfig = {
'AccountsValidate',
'Blocks',
'BlocksExtrinsics',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/dockPoSMainnetControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const dockPoSMainnetControllers: ControllerConfig = {
'AccountsValidate',
'Blocks',
'BlocksExtrinsics',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/dockPoSTestnetControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const dockTestnetControllers: ControllerConfig = {
'AccountsValidate',
'Blocks',
'BlocksExtrinsics',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/heikoControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const heikoControllers: ControllerConfig = {
'AccountsVestingInfo',
'Blocks',
'BlocksExtrinsics',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/karuraControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const karuraControllers: ControllerConfig = {
'AccountsValidate',
'Blocks',
'BlocksExtrinsics',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/kiltControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const kiltControllers: ControllerConfig = {
'AccountsValidate',
'Blocks',
'BlocksExtrinsics',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/kulupuControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const kulupuControllers: ControllerConfig = {
'AccountsValidate',
'Blocks',
'BlocksExtrinsics',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/kusamaControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const kusamaControllers: ControllerConfig = {
'Blocks',
'BlocksExtrinsics',
'BlocksTrace',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/mandalaControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const mandalaControllers: ControllerConfig = {
'AccountsVestingInfo',
'Blocks',
'BlocksExtrinsics',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/mantaControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export const mantaControllers: ControllerConfig = {
'AccountsVestingInfo',
'Blocks',
'BlocksExtrinsics',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/parallelControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const parallelControllers: ControllerConfig = {
'AccountsVestingInfo',
'Blocks',
'BlocksExtrinsics',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/polkadotControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const polkadotControllers: ControllerConfig = {
'Blocks',
'BlocksExtrinsics',
'BlocksTrace',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/polymeshControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export const polymeshControllers: ControllerConfig = {
'AccountsValidate',
'Blocks',
'BlocksExtrinsics',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/shidenControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const shidenControllers: ControllerConfig = {
'Blocks',
'BlocksExtrinsics',
'BlocksTrace',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/soraControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const soraControllers: ControllerConfig = {
'AccountsValidate',
'Blocks',
'BlocksExtrinsics',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/westendControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const westendControllers: ControllerConfig = {
'Blocks',
'BlocksExtrinsics',
'BlocksTrace',
'BlocksRawExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
Expand Down
60 changes: 60 additions & 0 deletions src/controllers/blocks/BlocksRawExtrinsicsController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// This file is part of Substrate API Sidecar.
//
// Substrate API Sidecar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { ApiPromise } from '@polkadot/api';
import { RequestHandler } from 'express';

import { BlocksService } from '../../services';
import { ControllerOptions } from '../../types/chains-config';
import { INumberParam } from '../../types/requests';
import AbstractController from '../AbstractController';

export default class BlocksRawExtrinsicsController extends AbstractController<BlocksService> {
constructor(api: ApiPromise, options: ControllerOptions) {
super(
api,
'/blocks/:blockId/extrinsics-raw',
new BlocksService(
api,
options.minCalcFeeRuntime,
options.blockStore,
options.hasQueryFeeApi
)
);
this.initRoutes();
}

protected initRoutes(): void {
this.safeMountAsyncGetHandlers([['', this.getBlockRawExtrinsics]]);
}

/**
*
* @param _req Express Request
* @param res Express Response
*/
private getBlockRawExtrinsics: RequestHandler<INumberParam> = async (
{ params: { blockId } },
res
): Promise<void> => {
const hash = await this.getHashForBlock(blockId);

BlocksRawExtrinsicsController.sanitizedSend(
res,
await this.service.fetchBlockRaw(hash)
);
};
}
1 change: 1 addition & 0 deletions src/controllers/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@

export { default as Blocks } from './BlocksController';
export { default as BlocksExtrinsics } from './BlocksExtrinsicsController';
export { default as BlocksRawExtrinsics } from './BlocksRawExtrinsicsController';
export { default as BlocksTrace } from './BlocksTraceController';
Loading

0 comments on commit f486aa9

Please sign in to comment.