Skip to content

Commit

Permalink
feat: Support Dock's multiplier & add Dock controller config (#365)
Browse files Browse the repository at this point in the history
* Support Dock's Multiplier

Signed-off-by: lovesh <lovesh.bond@gmail.com>

* Link package for local testing; Bump deps

* Add controllers for Dock

Signed-off-by: lovesh <lovesh.bond@gmail.com>

* Revert to calc NPM package

Co-authored-by: emostov <32168567+emostov@users.noreply.github.com>
  • Loading branch information
lovesh and emostov committed Dec 18, 2020
1 parent 8cbafea commit fb5df84
Show file tree
Hide file tree
Showing 13 changed files with 445 additions and 371 deletions.
2 changes: 1 addition & 1 deletion calc/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion calc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "calc"
version = "0.1.2"
version = "0.1.3"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
license = "Apache-2.0"
Expand Down
34 changes: 34 additions & 0 deletions calc/pkg/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<br /><br />

<div align="center">
<h1 align="center">@substrate/calc</h1>
<h4 align="center">Off-chain calculations for @substrate/api-sidecar.</h4>

<p align="center">
<a href="https://www.npmjs.com/package/@substrate/api-sidecar">
<img alt="npm" src="https://img.shields.io/npm/v/@substrate/calc" />
</a>
<a href="https://github.com/paritytech/substrate-api-sidecar/actions">
<img alt="Github Actions" src="https://github.com/paritytech/substrate-api-sidecar/workflows/pr/badge.svg" />
</a>
<a href="https://opensource.org/licenses/Apache-2.0">
<img alt="apache-2.0" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg" />
</a>
</p>
</div>

<br /><br />

## About

This package is generated from the [`calc`](https://github.com/paritytech/substrate-api-sidecar/tree/master/calc) Rust crate using `wasm-bindgen` and was initially developed
solely to use as a dependency for `substrate-api-sidecar`. We are now offering this package as a
standalone through the npm registry.

## Usage

Example usage for the package can be found in Sidecar's [staking payout service](https://github.com/paritytech/substrate-api-sidecar/blob/master/src/services/accounts/AccountsStakingPayoutsService.ts) and Sidecar's [block service](https://github.com/paritytech/substrate-api-sidecar/blob/master/src/services/blocks/BlocksService.ts).

## Contributing

We welcome [contributions for documentation and code](https://github.com/paritytech/substrate-api-sidecar/pulls). If you have any questions you can reach the maintainers by [filing an issue on github.](https://github.com/paritytech/substrate-api-sidecar/issues)
Binary file modified calc/pkg/calc_bg.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion calc/pkg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Parity Technologies <admin@parity.io>"
],
"description": "Off-chain calculations for @substrate/api-sidecar.",
"version": "0.1.2",
"version": "0.1.3",
"license": "Apache-2.0",
"repository": {
"type": "git",
Expand Down
3 changes: 3 additions & 0 deletions calc/src/calc_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ impl Multiplier {
("westend", v) if 10 < v && v < 31 => V1((new_i128(inner), false)),
("westend", v) if 31 <= v => V2(new_u128(inner)),

("dock-main-runtime", _) => V2(new_u128(inner)),
("dock-testnet", _) => V2(new_u128(inner)),

_ => {
info!("Unsupported runtime: {}#{}", spec_name, spec_version);
return None;
Expand Down
20 changes: 10 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@
"test": "jest --silent"
},
"dependencies": {
"@polkadot/api": "^2.10.1",
"@polkadot/apps-config": "^0.70.1",
"@polkadot/util-crypto": "^4.2.1",
"@polkadot/api": "^3.0.1",
"@polkadot/apps-config": "^0.71.2",
"@polkadot/util-crypto": "^5.0.1",
"@substrate/calc": "^0.1.2",
"confmgr": "^1.0.6",
"express": "^4.17.1",
Expand All @@ -48,24 +48,24 @@
},
"devDependencies": {
"@types/express": "^4.17.9",
"@types/express-serve-static-core": "^4.17.14",
"@types/express-serve-static-core": "^4.17.17",
"@types/http-errors": "^1.6.3",
"@types/jest": "^26.0.16",
"@types/jest": "^26.0.19",
"@types/morgan": "^1.9.2",
"@types/triple-beam": "^1.3.2",
"@typescript-eslint/eslint-plugin": "4.9.1",
"@typescript-eslint/parser": "4.9.1",
"@typescript-eslint/eslint-plugin": "4.10.0",
"@typescript-eslint/parser": "4.10.0",
"eslint": "^7.15.0",
"eslint-config-prettier": "^7.0.0",
"eslint-plugin-prettier": "^3.2.0",
"eslint-plugin-simple-import-sort": "^6.0.1",
"eslint-plugin-prettier": "^3.3.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"jest": "^26.6.3",
"prettier": "^2.2.1",
"rimraf": "^3.0.2",
"standard-version": "^9.0.0",
"ts-jest": "^26.4.4",
"tsc-watch": "^4.2.9",
"typescript": "^4.1.2"
"typescript": "^4.1.3"
},
"resolutions": {
"node-forge": ">=0.10.0",
Expand Down
29 changes: 29 additions & 0 deletions src/chains-config/dockMainnetControllers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ControllerConfig } from '../types/chains-config';

/**
* Controllers for Dock's mainnet.
*/
export const dockMainnetControllers: ControllerConfig = {
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: true,
},
};
29 changes: 29 additions & 0 deletions src/chains-config/dockTestnetControllers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { ControllerConfig } from '../types/chains-config';

/**
* Controllers for Dock's test network.
*/
export const dockTestnetControllers: ControllerConfig = {
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: true,
},
};
4 changes: 4 additions & 0 deletions src/chains-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ import { AbstractService } from 'src/services/AbstractService';
import { controllers } from '../controllers';
import { ControllerConfig } from '../types/chains-config';
import { defaultControllers } from './defaultControllers';
import { dockMainnetControllers } from './dockMainnetControllers';
import { dockTestnetControllers } from './dockTestnetControllers';
import { kulupuControllers } from './kulupuControllers';
import { mandalaControllers } from './mandalaControllers';

const specToControllerMap = {
kulupu: kulupuControllers,
mandala: mandalaControllers,
'dock-testnet': dockTestnetControllers,
'dock-main-runtime': dockMainnetControllers,
};

/**
Expand Down
8 changes: 1 addition & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { ApiPromise } from '@polkadot/api';
import {
typesBundle,
typesChain,
typesRpc,
typesSpec,
} from '@polkadot/apps-config/api';
import { typesBundle, typesChain, typesSpec } from '@polkadot/apps-config/api';
import { WsProvider } from '@polkadot/rpc-provider';
import { json } from 'express';

Expand All @@ -42,7 +37,6 @@ async function main() {
// Instantiate a web socket connection to the node for basic polkadot-js use
const api = await ApiPromise.create({
provider: new WsProvider(config.SUBSTRATE.WS_URL),
rpc: typesRpc,
typesBundle,
typesChain,
typesSpec,
Expand Down
2 changes: 1 addition & 1 deletion src/services/blocks/BlocksService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export class BlocksService extends AbstractService {
typeof api.query.transactionPayment?.nextFeeMultiplier?.at !==
'function'
) {
// We do not have the neccesary materials to build calcFee, so we just give a dummy function
// We do not have the necessary materials to build calcFee, so we just give a dummy function
// that aligns with the expected API of calcFee.
calcFee = { calc_fee: () => null };

Expand Down
Loading

0 comments on commit fb5df84

Please sign in to comment.