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

feat: add nomination pools support #1095

Merged
merged 20 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from 18 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
122 changes: 122 additions & 0 deletions docs/src/openapi-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,60 @@ paths:
application/json:
marshacb marked this conversation as resolved.
Show resolved Hide resolved
schema:
$ref: '#/components/schemas/PalletsAssetsInfo'
/pallets/nominationPools/{poolId}:
get:
tags:
- pallets
summary: Get information and metadata associated with a nomination pool.
description: Returns information associated with a nomination pool which includes
the nomination pools' `bondedPool`, `rewardPool` and `metadata`.
operationId: getNominationPoolById
parameters:
- name: poolId
in: path
description: The unsignedInteger Id of a nomination pool.
required: true
schema:
type: string
format: unsignedInteger
- name: at
in: query
description: Block at which to retrieve the nomination pool.
required: false
schema:
type: string
description: Block identifier, as the block height or block hash.
format: unsignedInteger or $hex
responses:
"200":
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/PalletsNominationPool'
marshacb marked this conversation as resolved.
Show resolved Hide resolved
/pallets/nominationPools/info:
get:
tags:
- pallets
summary: Get information associated with nomination pools.
description: Returns information and metadata for nomination pools including pool counters and limits.
operationId: getNominationPoolInfo
parameters:
- name: at
in: query
description: Block at which to retrieve the nomination pool info.
required: false
schema:
type: string
description: Block identifier, as the block height or block hash.
format: unsignedInteger or $hex
responses:
"200":
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/PalletsNominationPoolsInfo'
marshacb marked this conversation as resolved.
Show resolved Hide resolved
/pallets/staking/progress:
get:
tags:
Expand Down Expand Up @@ -1869,6 +1923,26 @@ components:
type: array
items:
$ref: '#/components/schemas/Operation'
BondedPool:
type: object
properties:
points:
type: number
state:
type: string
memberCounter:
type: number
roles:
type: object
properties:
depositor:
type: string
root:
type: string
nominator:
type: string
stateToggler:
type: string
ChainType:
type: object
description: Type of the chain. It will return one of the following enum variants as a key. Live, Development, Local, or Custom. Each variant will have a value as null except when the ChainType is Custom, it will return a string.
Expand Down Expand Up @@ -2199,6 +2273,45 @@ components:
$ref: '#/components/schemas/AssetInfo'
assetMetadata:
$ref: '#/components/schemas/AssetMetadata'
PalletsNominationPool:
type: object
properties:
at:
$ref: '#/components/schemas/BlockIdentifiers'
bondedPool:
$ref: '#/components/schemas/BondedPool'
rewardPool:
$ref: '#/components/schemas/RewardPool'
PalletsNominationPoolsInfo:
type: object
properties:
at:
$ref: '#/components/schemas/BlockIdentifiers'
counterForBondedPools:
type: number
counterForMetadata:
type: number
counterForPoolMembers:
type: number
counterForReversePoolIdLookup:
type: number
counterForRewardPools:
type: number
counterForSubPoolsStorage:
type: number
lastPoolId:
type: number
maxPoolMembers:
type: number
maxPoolMembersPerPool:
type: number
nullable: true
maxPools:
type: number
minCreateBond:
type: number
minJoinBond:
type: number
PalletStorage:
type: object
properties:
Expand Down Expand Up @@ -2489,6 +2602,15 @@ components:
type: string
description: Height of the best block on the peer's canon chain.
format: unsignedInteger
RewardPool:
type: object
properties:
lastRecordedRewardCounter:
type: number
lastRecordedTotalPayouts:
type: number
totalRewardsClaimed:
type: number
RuntimeCode:
type: object
properties:
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 @@ -34,6 +34,7 @@ export const kusamaControllers: ControllerConfig = {
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
'PalletsNominationPools',
'PalletsStakingProgress',
'PalletsStorage',
'Paras',
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 @@ -34,6 +34,7 @@ export const polkadotControllers: ControllerConfig = {
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
'PalletsNominationPools',
'PalletsStakingProgress',
'PalletsStorage',
'Paras',
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 @@ -33,6 +33,7 @@ export const westendControllers: ControllerConfig = {
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
'PalletsNominationPools',
marshacb marked this conversation as resolved.
Show resolved Hide resolved
'PalletsStakingProgress',
'PalletsStorage',
'Paras',
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { Blocks, BlocksExtrinsics, BlocksTrace } from './blocks';
import { NodeNetwork, NodeTransactionPool, NodeVersion } from './node';
import {
PalletsAssets,
PalletsNominationPools,
PalletsStakingProgress,
PalletsStorage,
} from './pallets';
Expand Down Expand Up @@ -54,6 +55,7 @@ export const controllers = {
AccountsVestingInfo,
AccountsStakingPayouts,
PalletsAssets,
PalletsNominationPools,
PalletsStakingProgress,
PalletsStorage,
NodeNetwork,
Expand Down
74 changes: 74 additions & 0 deletions src/controllers/pallets/PalletsNominationPoolsController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// 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';
marshacb marked this conversation as resolved.
Show resolved Hide resolved
import { RequestHandler } from 'express';

import { PalletsNominationPoolService } from '../../services';
import AbstractController from '../AbstractController';

marshacb marked this conversation as resolved.
Show resolved Hide resolved
export default class PalletsNominationPoolController extends AbstractController<PalletsNominationPoolService> {
constructor(api: ApiPromise) {
super(
api,
'/pallets/nominationPools',
new PalletsNominationPoolService(api)
);
this.initRoutes();
}

protected initRoutes(): void {
this.safeMountAsyncGetHandlers([
['/info', this.getNominationPoolInfo],
['/:poolId', this.getNominationPoolById],
]);
}

private getNominationPoolById: RequestHandler = async (
{ params: { poolId }, query: { at, metadata } },
res
): Promise<void> => {
/**
* Verify our param `poolId` is an integer represented as a string, and return
* it as an integer
*/
const index = this.parseNumberOrThrow(
poolId,
'`poolId` path param is not a number'
);

const metadataArg = metadata === 'true';

const hash = await this.getHashFromAt(at);

PalletsNominationPoolController.sanitizedSend(
res,
await this.service.fetchNominationPoolById(index, hash, metadataArg)
);
};

private getNominationPoolInfo: RequestHandler = async (
{ query: { at } },
res
): Promise<void> => {
const hash = await this.getHashFromAt(at);

PalletsNominationPoolController.sanitizedSend(
res,
await this.service.fetchNominationPoolInfo(hash)
);
};
}
1 change: 1 addition & 0 deletions src/controllers/pallets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

export { default as PalletsAssets } from './PalletsAssetsController';
export { default as PalletsNominationPools } from './PalletsNominationPoolsController';
export { default as PalletsStakingProgress } from './PalletsStakingProgressController';
export { default as PalletsStorage } from './PalletsStorageController';
Loading