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: Experimental PLO endpoints #509

Merged
merged 38 commits into from
Apr 19, 2021
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1264b9a
Setup service and controller skeleton
emostov Mar 31, 2021
ec3d744
Update controller configs with paras and clean up type guards
emostov Mar 31, 2021
43735fd
Clean up with typeguards in blocks service
emostov Mar 31, 2021
99c83bb
Get ready to branch off
emostov Mar 31, 2021
470caf6
MVP /auctions/current
emostov Apr 1, 2021
ea4c761
Add winning
emostov Apr 1, 2021
1ccd287
Remove zeke specific code for better diffs in future
emostov Apr 2, 2021
d5b546a
feat: mvp crowdloan endpoints (#503)
TarikGul Apr 2, 2021
b898e3d
Add endpoints (#504)
emostov Apr 5, 2021
4f41b7e
Bump deps
emostov Apr 5, 2021
f4a0f23
Merge branch 'feat-experiment-plo-endpoints' of https://github.com/pa…
emostov Apr 5, 2021
567df74
Bumpt to polkadot-js/api 4.4.2-0
emostov Apr 7, 2021
9d7226e
Remove stray comment
emostov Apr 7, 2021
175bf98
feat: include lease set for each winning bid in auctions/current (#508)
emostov Apr 8, 2021
a9e000e
Try merge origin master
emostov Apr 8, 2021
722d756
docs: PLO endpoints (#507)
emostov Apr 9, 2021
aef7a54
fix: Query lease periods per slot; use exact int types (#513)
emostov Apr 12, 2021
a364fb2
Bump deps
emostov Apr 12, 2021
5eff845
feat: add testing for plo endpoints (#512)
TarikGul Apr 12, 2021
3dc425f
Try merge origin master
emostov Apr 12, 2021
3364c35
Merge branch 'feat-experiment-plo-endpoints' of https://github.com/pa…
emostov Apr 12, 2021
b05ef76
Lint
emostov Apr 12, 2021
86063fe
Apply suggestions from code review
emostov Apr 13, 2021
79e0431
Apply suggestions from code review
emostov Apr 13, 2021
97493f1
Polish openapi docs
emostov Apr 13, 2021
6cf49f3
Polish ParasControllers
emostov Apr 13, 2021
45bedde
fix(ParaService.spec): misc. fixes
emostov Apr 13, 2021
bf81c25
Revert "fix(ParaService.spec): misc. fixes"
emostov Apr 14, 2021
fa971f7
Revert "Revert "fix(ParaService.spec): misc. fixes""
emostov Apr 14, 2021
606b2ee
fix: refactor typeFactory, cleanup mockApi (#516)
TarikGul Apr 15, 2021
e43adc8
Apply suggestions from code review
emostov Apr 16, 2021
f59fc40
adress davids commebts
emostov Apr 19, 2021
e821610
Bump deps
emostov Apr 19, 2021
e0a457f
Correct `winning` doc comment
emostov Apr 19, 2021
78a296d
Create sample length fallback as a constant'
emostov Apr 19, 2021
5283f00
Try merge origin master
emostov Apr 19, 2021
a72a3aa
update yarn.lock
emostov Apr 19, 2021
39bf17a
update yarn.lock
emostov Apr 19, 2021
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
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"test": "jest --silent"
},
"dependencies": {
"@polkadot/api": "^4.4.1",
"@polkadot/api": "^4.4.2-0",
"@polkadot/apps-config": "^0.86.2",
"@polkadot/util-crypto": "^6.0.5",
"@substrate/calc": "^0.2.0",
Expand All @@ -47,15 +47,15 @@
"winston": "^3.3.3"
},
"devDependencies": {
"@substrate/dev": "^0.3.0",
"@substrate/dev": "^0.4.0",
"@types/express": "^4.17.11",
"@types/express-serve-static-core": "^4.17.18",
"@types/express-serve-static-core": "^4.17.19",
"@types/http-errors": "^1.6.3",
"@types/morgan": "^1.9.2",
"@types/triple-beam": "^1.3.2",
"rimraf": "^3.0.2",
"standard-version": "^9.1.1",
"ts-jest": "^26.5.3",
"ts-jest": "^26.5.4",
"tsc-watch": "^4.2.9",
"typescript": "4.2.3"
},
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 @@ -24,6 +24,7 @@ export const defaultControllers: ControllerConfig = {
TransactionSubmit: true,
PalletsStakingProgress: true,
PalletsStorage: true,
Paras: true,
},
options: {
finalizes: true,
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 @@ -23,6 +23,7 @@ export const dockMainnetControllers: ControllerConfig = {
TransactionSubmit: true,
PalletsStakingProgress: false,
PalletsStorage: true,
Paras: false,
},
options: {
finalizes: true,
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/dockTestnetControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const dockTestnetControllers: ControllerConfig = {
TransactionSubmit: true,
PalletsStakingProgress: false,
PalletsStorage: true,
Paras: false,
},
options: {
finalizes: true,
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 @@ -20,6 +20,7 @@ export const kulupuControllers: ControllerConfig = {
TransactionSubmit: true,
PalletsStakingProgress: false,
PalletsStorage: true,
Paras: false,
},
options: {
finalizes: false,
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 @@ -24,6 +24,7 @@ export const kusamaControllers: ControllerConfig = {
TransactionSubmit: true,
PalletsStakingProgress: true,
PalletsStorage: true,
Paras: true,
},
options: {
finalizes: true,
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 @@ -23,6 +23,7 @@ export const mandalaControllers: ControllerConfig = {
TransactionSubmit: true,
PalletsStakingProgress: true,
PalletsStorage: true,
Paras: true,
},
options: {
finalizes: true,
Expand Down
15 changes: 7 additions & 8 deletions src/chains-config/metadata-consts/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import {
BlockWeightStore,
ExtBaseWeightValue,
isExtBaseWeightValue,
isPerClassValue,
MetadataConsts,
PerClassValue,
} from '../../types/chains-config';
Expand Down Expand Up @@ -39,14 +41,11 @@ export function generateBlockWeightStore(
for (const version of runtimeVersions) {
blockWeightStore[version] = {};

if ((def as ExtBaseWeightValue).extrinsicBaseWeight) {
(blockWeightStore[
version
] as ExtBaseWeightValue).extrinsicBaseWeight = (def as ExtBaseWeightValue).extrinsicBaseWeight;
} else if ((def as PerClassValue).perClass) {
(blockWeightStore[
version
] as PerClassValue).perClass = (def as PerClassValue).perClass;
if (isExtBaseWeightValue(def)) {
(blockWeightStore[version] as ExtBaseWeightValue).extrinsicBaseWeight =
def.extrinsicBaseWeight;
} else if (isPerClassValue(def)) {
(blockWeightStore[version] as PerClassValue).perClass = def.perClass;
} else {
throw new Error(
'No Valid weight type found while generating block weight store'
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 @@ -24,6 +24,7 @@ export const polkadotControllers: ControllerConfig = {
TransactionSubmit: true,
PalletsStakingProgress: true,
PalletsStorage: true,
Paras: true,
},
options: {
finalizes: true,
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 @@ -24,6 +24,7 @@ export const westendControllers: ControllerConfig = {
TransactionSubmit: true,
PalletsStakingProgress: true,
PalletsStorage: true,
Paras: true,
dvdplm marked this conversation as resolved.
Show resolved Hide resolved
},
options: {
finalizes: true,
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/AbstractController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
IAddressNumberParams,
IAddressParam,
INumberParam,
IParaIdParam,
} from 'src/types/requests';

import { sanitizeNumbers } from '../sanitize';
Expand All @@ -19,6 +20,7 @@ type SidecarRequestHandler =
| RequestHandler<IAddressParam>
| RequestHandler<IAddressNumberParams>
| RequestHandler<INumberParam>
| RequestHandler<IParaIdParam>
| RequestHandler;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import { Blocks, BlocksExtrinsics } from './blocks';
import { NodeNetwork, NodeTransactionPool, NodeVersion } from './node';
import { PalletsStakingProgress, PalletsStorage } from './pallets';
import { Paras } from './paras';
import { RuntimeCode, RuntimeMetadata, RuntimeSpec } from './runtime';
import {
TransactionDryRun,
Expand Down Expand Up @@ -37,4 +38,5 @@ export const controllers = {
TransactionFeeEstimate,
TransactionMaterial,
TransactionSubmit,
Paras,
};
104 changes: 104 additions & 0 deletions src/controllers/paras/ParasController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import { ApiPromise } from '@polkadot/api';
import { RequestHandler } from 'express';
import { IParaIdParam } from 'src/types/requests';

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

export default class ParasController extends AbstractController<ParasService> {
constructor(api: ApiPromise) {
super(api, '/experimental/paras', new ParasService(api));
this.initRoutes();
}

protected initRoutes(): void {
this.safeMountAsyncGetHandlers([
['/', this.getParas],
['/crowdloans', this.getCrowdloans],
['/:paraId/crowdloan-info', this.getCrowdloanInfo],
['/:paraId/lease-info', this.getLeaseInfo],
['/leases/current', this.getLeasesCurrent],
['/auctions/current', this.getAuctionsCurrent],
]);
}

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

private getCrowdloanInfo: RequestHandler<IParaIdParam> = async (
{ params: { paraId }, query: { at } },
res
): Promise<void> => {
const hash = await this.getHashFromAt(at);
const paraIdArg = this.parseNumberOrThrow(
paraId,
'paraId must be an integer'
);

ParasController.sanitizedSend(
res,
await this.service.crowdloansInfo(hash, paraIdArg)
);
};

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

const includeFundInfo = fundInfo === 'true' ? true : false;

ParasController.sanitizedSend(
res,
await this.service.crowdloans(hash, includeFundInfo)
);
};

private getLeaseInfo: RequestHandler<IParaIdParam> = async (
{ params: { paraId }, query: { at } },
res
): Promise<void> => {
const hash = await this.getHashFromAt(at);
const paraIdArg = this.parseNumberOrThrow(
paraId,
'paraId must be an integer'
);

ParasController.sanitizedSend(
res,
await this.service.leaseInfo(hash, paraIdArg)
);
};

private getLeasesCurrent: RequestHandler = async (
{ query: { at, currentLeaseHolders } },
res
): Promise<void> => {
const hash = await this.getHashFromAt(at);
const includeCurrentLeaseHolders =
currentLeaseHolders === 'false' ? false : true;

ParasController.sanitizedSend(
res,
await this.service.leasesCurrent(hash, includeCurrentLeaseHolders)
);
};

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

ParasController.sanitizedSend(
res,
await this.service.auctionsCurrent(hash)
);
};
}
1 change: 1 addition & 0 deletions src/controllers/paras/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as Paras } from './ParasController';
25 changes: 9 additions & 16 deletions src/services/blocks/BlocksService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ import { BadRequest, InternalServerError } from 'http-errors';

import {
BlockWeightStore,
ExtBaseWeightValue,
IPerClass,
PerClassValue,
isExtBaseWeightValue,
isPerClassValue,
WeightValue,
} from '../../types/chains-config';
import {
Expand Down Expand Up @@ -261,21 +261,14 @@ export class BlocksService extends AbstractService {
* https://github.com/paritytech/substrate-api-sidecar/issues/393 .
* https://github.com/polkadot-js/api/issues/2365
*/
// This makes the compiler happy for below type guards
const weightStored = this.blockWeightStore[specVersion];
let extrinsicBaseWeight;
if (
// 0 is a falsy value so we need to check if undefined
(this.blockWeightStore[specVersion] as ExtBaseWeightValue)
.extrinsicBaseWeight !== undefined
) {
extrinsicBaseWeight = (this.blockWeightStore[
specVersion
] as ExtBaseWeightValue).extrinsicBaseWeight;
} else if (
(this.blockWeightStore[specVersion] as PerClassValue).perClass
) {
extrinsicBaseWeight = (this.blockWeightStore[
specVersion
] as PerClassValue)?.perClass[weightInfoClass]?.baseExtrinsic;
if (isExtBaseWeightValue(weightStored)) {
emostov marked this conversation as resolved.
Show resolved Hide resolved
extrinsicBaseWeight = weightStored.extrinsicBaseWeight;
} else if (isPerClassValue(weightStored)) {
extrinsicBaseWeight =
weightStored.perClass[weightInfoClass]?.baseExtrinsic;
}

if (!extrinsicBaseWeight) {
Expand Down
1 change: 1 addition & 0 deletions src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export * from './accounts';
export * from './blocks';
export * from './node';
export * from './pallets';
export * from './paras';
export * from './runtime';
export * from './transaction';
Loading