-
Notifications
You must be signed in to change notification settings - Fork 162
feat: chainSpec based controller config; Types from apps-config #351
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
Merged
Merged
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 5d254dd
Update mock api to include derive getBlock - specs work
emostov 7072fdc
Update to reflect TS 4.1
emostov c682665
Clean up comments
emostov 4ab1b2d
Save
emostov cc9a962
Merge origin master
emostov ede1787
feat: Token query param for non-native token balance-info
emostov 39e1a1a
Revert package.json
emostov be66056
Initial reply david review
emostov e465092
Update src/main.ts
emostov 19a66e7
Remove kulupu controller
emostov 0ac5573
Merge branch 'types-package' of https://github.com/paritytech/substra…
emostov c5e9284
Add chain builder integration guide
emostov 0c57ecd
Patch CHAIN_INTEGRATION.md
emostov 6692e50
Apply suggestions from code review
emostov 4b4d9a2
Update CHAIN_INTEGRATION.md
emostov b81c0d1
Bump deps
emostov 46f067d
Merge remote-tracking branch 'origin' into types-package
emostov 92a8856
Use whole options object for controller creation
emostov 8451309
Apply suggestions from code review
emostov 87572a9
Respond to maciej feedback
emostov c38c105
Merge branch 'types-package' of https://github.com/paritytech/substra…
emostov a1a988a
Update chain integration guide
emostov 79f9eb8
Remove excessive nullish colescing operators
emostov cf84d63
Merge origin master
emostov b34cca2
Fix merge issue
emostov a16235a
Update CHAIN_INTEGRATION.md
emostov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
feat: chainSpec based controller config; Types from apps-config
Clean up
- Loading branch information
commit ae1de13620ff8a2d21f3a29b2db0173f62aa6b34
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { ControllerConfig } from '../types/chains-config'; | ||
|
|
||
| /** | ||
| * Controllers that Sidecar will always default to. This likely will always be | ||
| * the optimal controller selection for Polkadot and Kusama. | ||
| */ | ||
| export const defaultControllers: ControllerConfig = { | ||
| Blocks: true, | ||
| KulupuBlocks: 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, | ||
| PalletsStorageItem: true, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| import { ApiPromise } from '@polkadot/api'; | ||
| import AbstractController from 'src/controllers/AbstractController'; | ||
| import { AbstractService } from 'src/services/AbstractService'; | ||
|
|
||
| import { controllers } from '../controllers'; | ||
| import { ControllerConfig } from '../types/chains-config'; | ||
| import { defaultControllers } from './defaultControllers'; | ||
| import { kulupuControllers } from './kulupuControllers'; | ||
|
|
||
| /** | ||
| * | ||
| * @param api ApiPromise to inject into controllers | ||
| * @param implName | ||
| */ | ||
| export function getControllersForSpec( | ||
| api: ApiPromise, | ||
| specName: string | ||
| ): AbstractController<AbstractService>[] { | ||
| switch (specName) { | ||
| case 'kulupu': | ||
| return getControllersFromConfig(api, kulupuControllers); | ||
| default: | ||
| return getControllersFromConfig(api, defaultControllers); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Return an array of instantiated controller instances based off of a | ||
| * `ControllerConfig`. | ||
| * | ||
| * @param api ApiPromise to inject into controllers | ||
| * @param config controller mount configuration object | ||
| */ | ||
| function getControllersFromConfig(api: ApiPromise, config: ControllerConfig) { | ||
| // If we don't typecast here, tsc thinks its just [string, any][] | ||
| const controllersToInclude = Object.entries(config) as [ | ||
| keyof typeof controllers, | ||
| boolean | ||
| ][]; | ||
|
|
||
| return controllersToInclude.reduce((acc, [controllerName, shouldMount]) => { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One day JavaScript will get |
||
| if (shouldMount) { | ||
| return acc.concat(new controllers[controllerName](api)); | ||
| } | ||
|
|
||
| return acc; | ||
emostov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, [] as AbstractController<AbstractService>[]); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| 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, | ||
| PalletsStorageItem: true, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| import { ApiPromise } from '@polkadot/api'; | ||
| import { RequestHandler } from 'express'; | ||
|
|
||
| import { BlocksService } from '../../services'; | ||
| import { INumberParam } from '../../types/requests'; | ||
| import AbstractController from '../AbstractController'; | ||
|
|
||
| /** | ||
| * GET a block. | ||
| * | ||
| * N.B. this controller assumes the chain does not have a finality | ||
| * gadget (e.g. PoW in Kulupu)) | ||
| * | ||
| * Paths: | ||
| * - `kulupuBlocks\head`: Get the latest finalized block. | ||
| * - (Optional) `kulupuBlocks\number`: Block hash or height at which to query. If not provided, queries | ||
| * finalized head. | ||
| * | ||
| * Query: | ||
| * - (Optional) `eventDocs`: When set to `true`, every event will have an extra | ||
| * `docs` property with a string of the events documentation. | ||
| * - (Optional) `extrinsicDocs`: When set to `true`, every extrinsic will have an extra | ||
| * `docs` property with a string of the extrinsics documentation. | ||
| * | ||
| * | ||
| * Returns: | ||
| * - `number`: Block height. | ||
| * - `hash`: The block's hash. | ||
| * - `parentHash`: The hash of the parent block. | ||
| * - `stateRoot`: The state root after executing this block. | ||
| * - `extrinsicsRoot`: The Merkle root of the extrinsics. | ||
| * - `authorId`: The account ID of the block author (may be undefined for some chains). | ||
| * - `logs`: Array of `DigestItem`s associated with the block. | ||
| * - `onInitialize`: Object with an array of `SanitizedEvent`s that occurred during block | ||
| * initialization with the `method` and `data` for each. | ||
| * - `extrinsics`: Array of extrinsics (inherents and transactions) within the block. Each | ||
| * contains: | ||
| * - `method`: Extrinsic method. | ||
| * - `signature`: Object with `signature` and `signer`, or `null` if unsigned. | ||
| * - `nonce`: Account nonce, if applicable. | ||
| * - `args`: Array of arguments. | ||
| * - `tip`: Any tip added to the transaction. | ||
| * - `hash`: The transaction's hash. | ||
| * - `info`: `RuntimeDispatchInfo` for the transaction. Includes the `partialFee`. | ||
| * - `events`: An array of `SanitizedEvent`s that occurred during extrinsic execution. | ||
| * - `success`: Whether or not the extrinsic succeeded. | ||
| * - `paysFee`: Whether the extrinsic requires a fee. Careful! This field relates to whether or | ||
| * not the extrinsic requires a fee if called as a transaction. Block authors could insert | ||
| * the extrinsic as an inherent in the block and not pay a fee. Always check that `paysFee` | ||
| * is `true` and that the extrinsic is signed when reconciling old blocks. | ||
| * - `onFinalize`: Object with an array of `SanitizedEvent`s that occurred during block | ||
| * finalization with the `method` and `data` for each. | ||
| * | ||
| * | ||
| * Substrate Reference: | ||
| * - `DigestItem`: https://crates.parity.io/sp_runtime/enum.DigestItem.html | ||
| * - `RawEvent`: https://crates.parity.io/frame_system/enum.RawEvent.html | ||
| * - Extrinsics: https://substrate.dev/docs/en/knowledgebase/learn-substrate/extrinsics | ||
| * - `Extrinsic`: https://crates.parity.io/sp_runtime/traits/trait.Extrinsic.html | ||
| * - `OnInitialize`: https://crates.parity.io/frame_support/traits/trait.OnInitialize.html | ||
| * - `OnFinalize`: https://crates.parity.io/frame_support/traits/trait.OnFinalize.html | ||
| */ | ||
| export default class KulupuBlocksController extends AbstractController<BlocksService> { | ||
| constructor(api: ApiPromise) { | ||
| super(api, '/kulupuBlocks', new BlocksService(api)); | ||
| this.initRoutes(); | ||
| } | ||
|
|
||
| protected initRoutes(): void { | ||
| this.safeMountAsyncGetHandlers([ | ||
| ['/head', this.getLatestBlock], | ||
| ['/:number', this.getBlockById], | ||
| ]); | ||
| } | ||
|
|
||
| /** | ||
| * Get the latest block. | ||
| * | ||
| * @param _req Express Request | ||
| * @param res Express Response | ||
| */ | ||
| private getLatestBlock: RequestHandler = async ( | ||
| { query: { eventDocs, extrinsicDocs } }, | ||
| res | ||
| ) => { | ||
| const eventDocsArg = eventDocs === 'true'; | ||
| const extrsinsicDocsArg = extrinsicDocs === 'true'; | ||
|
|
||
| const hash = (await this.api.rpc.chain.getHeader()).hash; | ||
|
|
||
| KulupuBlocksController.sanitizedSend( | ||
| res, | ||
| await this.service.fetchBlock(hash, eventDocsArg, extrsinsicDocsArg) | ||
| ); | ||
| }; | ||
|
|
||
| /** | ||
| * Get a block by its hash or number identifier. | ||
| * | ||
| * @param req Express Request | ||
| * @param res Express Response | ||
| */ | ||
| private getBlockById: RequestHandler<INumberParam> = async ( | ||
| { params: { number }, query: { eventDocs, extrinsicDocs } }, | ||
| res | ||
| ): Promise<void> => { | ||
| const hash = await this.getHashForBlock(number); | ||
|
|
||
| const eventDocsArg = eventDocs === 'true'; | ||
| const extrinsinsicDocsArg = extrinsicDocs === 'true'; | ||
|
|
||
| KulupuBlocksController.sanitizedSend( | ||
| res, | ||
| await this.service.fetchBlock( | ||
| hash, | ||
| eventDocsArg, | ||
| extrinsinsicDocsArg | ||
| ) | ||
| ); | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| // Chain specific controllers. | ||
| // | ||
| // These endpoints may be reused for other chains as well, but for now naming them after the chain | ||
| // that originally neccesitated it for simplicity. | ||
|
|
||
| export { default as KulupuBlocks } from './KulupuBlocksController'; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.