Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ae1de13
feat: chainSpec based controller config; Types from apps-config
emostov Nov 24, 2020
5d254dd
Update mock api to include derive getBlock - specs work
emostov Nov 24, 2020
7072fdc
Update to reflect TS 4.1
emostov Nov 24, 2020
c682665
Clean up comments
emostov Nov 24, 2020
4ab1b2d
Save
emostov Dec 2, 2020
cc9a962
Merge origin master
emostov Dec 2, 2020
ede1787
feat: Token query param for non-native token balance-info
emostov Dec 2, 2020
39e1a1a
Revert package.json
emostov Dec 2, 2020
be66056
Initial reply david review
emostov Dec 2, 2020
e465092
Update src/main.ts
emostov Dec 2, 2020
19a66e7
Remove kulupu controller
emostov Dec 2, 2020
0ac5573
Merge branch 'types-package' of https://github.com/paritytech/substra…
emostov Dec 2, 2020
c5e9284
Add chain builder integration guide
emostov Dec 3, 2020
0c57ecd
Patch CHAIN_INTEGRATION.md
emostov Dec 3, 2020
6692e50
Apply suggestions from code review
emostov Dec 4, 2020
4b4d9a2
Update CHAIN_INTEGRATION.md
emostov Dec 4, 2020
b81c0d1
Bump deps
emostov Dec 8, 2020
46f067d
Merge remote-tracking branch 'origin' into types-package
emostov Dec 8, 2020
92a8856
Use whole options object for controller creation
emostov Dec 8, 2020
8451309
Apply suggestions from code review
emostov Dec 9, 2020
87572a9
Respond to maciej feedback
emostov Dec 9, 2020
c38c105
Merge branch 'types-package' of https://github.com/paritytech/substra…
emostov Dec 9, 2020
a1a988a
Update chain integration guide
emostov Dec 9, 2020
79f9eb8
Remove excessive nullish colescing operators
emostov Dec 9, 2020
cf84d63
Merge origin master
emostov Dec 9, 2020
b34cca2
Fix merge issue
emostov Dec 9, 2020
a16235a
Update CHAIN_INTEGRATION.md
emostov Dec 9, 2020
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
Prev Previous commit
Next Next commit
Remove kulupu controller
  • Loading branch information
emostov committed Dec 2, 2020
commit 19a66e73b3594d2173e76c56e13887e22feac609
40 changes: 22 additions & 18 deletions src/chains-config/defaultControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@ import { ControllerConfig } from '../types/chains-config';
* the optimal controller selection for Polkadot and Kusama.
*/
export const defaultControllers: ControllerConfig = {
Blocks: true,
KulupuBlocks: false,
AccountsStakingPayouts: true,
AccountsBalanceInfo: true,
AccountsStakingInfo: true,
AccountsVestingInfo: true,
NodeNetwork: true,
NodeVersion: true,
NodeTransactionPool: true,
RuntimeCode: true,
RuntimeSpec: true,
RuntimeMetadata: true,
TransactionDryRun: true,
TransactionMaterial: true,
TransactionFeeEstimate: true,
TransactionSubmit: true,
PalletsStakingProgress: true,
PalletsStorage: true,
controllers: {
Blocks: true,
AccountsStakingPayouts: true,
AccountsBalanceInfo: true,
AccountsStakingInfo: true,
AccountsVestingInfo: true,
NodeNetwork: true,
NodeVersion: true,
NodeTransactionPool: true,
RuntimeCode: true,
RuntimeSpec: true,
RuntimeMetadata: true,
TransactionDryRun: true,
TransactionMaterial: true,
TransactionFeeEstimate: true,
TransactionSubmit: true,
PalletsStakingProgress: true,
PalletsStorage: true,
},
options: {
finalizes: true,
},
};
24 changes: 15 additions & 9 deletions src/chains-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { defaultControllers } from './defaultControllers';
import { kulupuControllers } from './kulupuControllers';
import { mandalaControllers } from './mandalaControllers';

const specToControllerMap = {
kulupu: kulupuControllers,
mandala: mandalaControllers,
};

/**
* Return an array of instantiated controller instances based off of a `specName`.
*
Expand All @@ -18,14 +23,13 @@ export function getControllersForSpec(
api: ApiPromise,
specName: string
): AbstractController<AbstractService>[] {
switch (specName) {
case 'kulupu':
return getControllersFromConfig(api, kulupuControllers);
case 'mandala':
return getControllersFromConfig(api, mandalaControllers);
default:
return getControllersFromConfig(api, defaultControllers);
if (specToControllerMap[specName]) {
return getControllersFromConfig(api, specToControllerMap[specName]);
}

// If we don't have the specName in the specToControllerMap we use the default
// contoller config
return getControllersFromConfig(api, defaultControllers);
}

/**
Expand All @@ -37,14 +41,16 @@ export function getControllersForSpec(
*/
function getControllersFromConfig(api: ApiPromise, config: ControllerConfig) {
// If we don't typecast here, tsc thinks its just [string, any][]
const controllersToInclude = Object.entries(config) as [
const controllersToInclude = Object.entries(config.controllers) as [
keyof typeof controllers,
boolean
][];

return controllersToInclude.reduce((acc, [controllerName, shouldMount]) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One day JavaScript will get filterMap on arrays, one day... :)

if (shouldMount) {
acc.push(new controllers[controllerName](api));
acc.push(
new controllers[controllerName](api, config.options.finalizes)
);
}

return acc;
Expand Down
40 changes: 22 additions & 18 deletions src/chains-config/kulupuControllers.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import { ControllerConfig } from '../types/chains-config';

export const kulupuControllers: ControllerConfig = {
Blocks: false,
KulupuBlocks: true,
AccountsStakingPayouts: false,
AccountsBalanceInfo: true,
AccountsStakingInfo: false,
AccountsVestingInfo: false,
NodeNetwork: true,
NodeVersion: true,
NodeTransactionPool: true,
RuntimeCode: true,
RuntimeSpec: true,
RuntimeMetadata: true,
TransactionDryRun: true,
TransactionMaterial: true,
TransactionFeeEstimate: true,
TransactionSubmit: true,
PalletsStakingProgress: false,
PalletsStorage: true,
controllers: {
Blocks: true,
AccountsStakingPayouts: false,
AccountsBalanceInfo: true,
AccountsStakingInfo: false,
AccountsVestingInfo: false,
NodeNetwork: true,
NodeVersion: true,
NodeTransactionPool: true,
RuntimeCode: true,
RuntimeSpec: true,
RuntimeMetadata: true,
TransactionDryRun: true,
TransactionMaterial: true,
TransactionFeeEstimate: true,
TransactionSubmit: true,
PalletsStakingProgress: false,
PalletsStorage: true,
},
options: {
finalizes: false,
},
};
40 changes: 22 additions & 18 deletions src/chains-config/mandalaControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,26 @@ import { ControllerConfig } from '../types/chains-config';
* Controllers for mandala, acala's test network.
*/
export const mandalaControllers: ControllerConfig = {
Blocks: true,
KulupuBlocks: false,
AccountsStakingPayouts: true,
AccountsBalanceInfo: true,
AccountsStakingInfo: true,
AccountsVestingInfo: true,
NodeNetwork: true,
NodeVersion: true,
NodeTransactionPool: true,
RuntimeCode: true,
RuntimeSpec: true,
RuntimeMetadata: true,
TransactionDryRun: true,
TransactionMaterial: true,
TransactionFeeEstimate: true,
TransactionSubmit: true,
PalletsStakingProgress: true,
PalletsStorage: true,
controllers: {
Blocks: true,
AccountsStakingPayouts: true,
AccountsBalanceInfo: true,
AccountsStakingInfo: true,
AccountsVestingInfo: true,
NodeNetwork: true,
NodeVersion: true,
NodeTransactionPool: true,
RuntimeCode: true,
RuntimeSpec: true,
RuntimeMetadata: true,
TransactionDryRun: true,
TransactionMaterial: true,
TransactionFeeEstimate: true,
TransactionSubmit: true,
PalletsStakingProgress: true,
PalletsStorage: true,
},
options: {
finalizes: true,
},
};
4 changes: 2 additions & 2 deletions src/controllers/blocks/BlocksController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import AbstractController from '../AbstractController';
* - `OnFinalize`: https://crates.parity.io/frame_support/traits/trait.OnFinalize.html
*/
export default class BlocksController extends AbstractController<BlocksService> {
constructor(api: ApiPromise) {
constructor(api: ApiPromise, private finalizes = true) {
super(api, '/blocks', new BlocksService(api));
this.initRoutes();
}
Expand All @@ -91,7 +91,7 @@ export default class BlocksController extends AbstractController<BlocksService>
const extrsinsicDocsArg = extrinsicDocs === 'true';

const hash =
finalized === 'false'
finalized === 'false' || !this.finalizes
? (await this.api.rpc.chain.getHeader()).hash
: await this.api.rpc.chain.getFinalizedHead();

Expand Down
121 changes: 0 additions & 121 deletions src/controllers/chains/KulupuBlocksController.ts

This file was deleted.

6 changes: 0 additions & 6 deletions src/controllers/chains/index.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
AccountsVestingInfo,
} from './accounts';
import { Blocks } from './blocks';
import { KulupuBlocks } from './chains';
import { NodeNetwork, NodeTransactionPool, NodeVersion } from './node';
import { PalletsStakingProgress, PalletsStorage } from './pallets';
import { RuntimeCode, RuntimeMetadata, RuntimeSpec } from './runtime';
Expand All @@ -25,7 +24,6 @@ export const controllers = {
AccountsStakingInfo,
AccountsVestingInfo,
AccountsStakingPayouts,
KulupuBlocks,
PalletsStakingProgress,
PalletsStorage,
NodeNetwork,
Expand Down
15 changes: 14 additions & 1 deletion src/types/chains-config/ControllerConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,18 @@ import { controllers } from '../../controllers';
* Controller mounting configuration as an object where the keys are the
* controller class names and the values are booleans indicating whether or not
* to include the controller.
*
* There is an additional `finalizes` field that is used to indicate wether or
* not a chain has finalized blocks. Practically, this only affects if
* `BlocksController` defaults to getFinalizedHead (in the case it finalizes) or
* getHeader (in the case it does not finalize)
*/
export type ControllerConfig = Record<keyof typeof controllers, boolean>;
export interface ControllerConfig {
controllers: Record<keyof typeof controllers, boolean>;
/**
* Wether or not the chain finalizes blocks
*/
options: {
finalizes: boolean;
};
}