Skip to content

feat: add pallets/foreign-assets endpoint #1314

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 21 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e1aa255
feat: add pallets/foreign-assets endpoint
Imod7 Aug 15, 2023
e682fbd
fix: remove `asset-info` from endpoint & fix docs
Imod7 Aug 21, 2023
e9ca2e4
add name & symbol in human readable format
Imod7 Aug 21, 2023
eb9628e
Refactored the code that retrieves the metadata of the foreign asset
Imod7 Aug 28, 2023
0683642
test: added test & mock data
Imod7 Sep 5, 2023
07fddc4
Merge branch 'master' into domi-foreign-assets
Imod7 Sep 5, 2023
cc4b02b
Update src/services/pallets/PalletsForeignAssetsService.ts
Imod7 Sep 6, 2023
2c418c7
Update src/services/pallets/PalletsForeignAssetsService.ts
Imod7 Sep 6, 2023
c8b6d7e
Update src/services/pallets/PalletsForeignAssetsService.ts
Imod7 Sep 6, 2023
151396b
Update src/services/pallets/PalletsForeignAssetsService.ts
Imod7 Sep 6, 2023
e87cede
Update src/services/pallets/PalletsForeignAssetsService.ts
Imod7 Sep 6, 2023
34a04ec
replaced type anyjson with codec
Imod7 Sep 6, 2023
dae423e
changed types in assetInfo & assetMetadata & copyright
Imod7 Sep 6, 2023
1df530f
removed storageKeyMultilocation & changed storageKey
Imod7 Sep 6, 2023
8efc7f2
fix: changes to support a list of multiple foreign assets
Imod7 Sep 7, 2023
20f967e
Updated test to work with multiple foreign assets
Imod7 Sep 8, 2023
ffb3d54
Changes types of foreignAssetInfo and foreignAssetMetadata
Imod7 Sep 8, 2023
2d49b26
Merge branch 'master', resolved conflicts & rebuilt docs
Imod7 Sep 8, 2023
b4dd1f3
fix typing on queried values, and return values
TarikGul Sep 8, 2023
646083a
fix test
Imod7 Sep 8, 2023
1ecc91b
removed an unnecessary console.log
Imod7 Sep 8, 2023
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
2 changes: 1 addition & 1 deletion docs/dist/app.bundle.js

Large diffs are not rendered by default.

290 changes: 161 additions & 129 deletions docs/src/openapi-v1.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion e2e-tests/helpers/consts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/helpers/request.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/historical/endpoints/asset-hub-kusama/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/historical/endpoints/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/historical/endpoints/kusama/accounts/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/historical/endpoints/kusama/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/historical/endpoints/polkadot/runtime/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/historical/endpoints/westend/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
2 changes: 1 addition & 1 deletion e2e-tests/historical/historical.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
2 changes: 1 addition & 1 deletion scripts/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/assetHubKusamaControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const assetHubKusamaControllers: ControllerConfig = {
'PalletsConsts',
'PalletsErrors',
'PalletsEvents',
'PalletsForeignAssets',
'RuntimeCode',
'RuntimeMetadata',
'RuntimeSpec',
Expand Down
1 change: 1 addition & 0 deletions src/chains-config/assetHubPolkadotControllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const assetHubPolkadotControllers: ControllerConfig = {
'PalletsConsts',
'PalletsEvents',
'PalletsErrors',
'PalletsForeignAssets',
'RuntimeCode',
'RuntimeMetadata',
'RuntimeSpec',
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 @@ -40,6 +40,7 @@ export const defaultControllers: ControllerConfig = {
'PalletsConsts',
'PalletsErrors',
'PalletsEvents',
'PalletsForeignAssets',
'PalletsStakingProgress',
'PalletsStorage',
'Paras',
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/accounts/AccountsAssetsController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/blocks/BlocksController.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
2 changes: 2 additions & 0 deletions src/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
PalletsDispatchables,
PalletsErrors,
PalletsEvents,
PalletsForeignAssets,
PalletsNominationPools,
PalletsStakingProgress,
PalletsStakingValidators,
Expand Down Expand Up @@ -68,6 +69,7 @@ export const controllers = {
PalletsConsts,
PalletsErrors,
PalletsEvents,
PalletsForeignAssets,
PalletsNominationPools,
PalletsStakingProgress,
PalletsStakingValidators,
Expand Down
58 changes: 58 additions & 0 deletions src/controllers/pallets/PalletsForeignAssetsController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Copyright 2017-2023 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';
import { RequestHandler } from 'express';

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

/**
* GET asset information for all foreign assets.
*
* Query:
* - (Optional)`at`: Block at which to retrieve runtime version information at. Block
* identifier, as the block height or block hash. Defaults to most recent block.
*
* `/pallets/foreign-assets`
* Returns:
* - `at`: Block number and hash at which the call was made.
* - `items`: An array containing the `AssetDetails` and `AssetMetadata` of every foreign asset.
*
* Substrate References:
* - Foreign Assets Pallet Instance in Kusama Asset Hub: https://github.com/paritytech/cumulus/blob/master/parachains/runtimes/assets/asset-hub-kusama/src/lib.rs#L295
*/
export default class PalletsForeignAssetsController extends AbstractController<PalletsForeignAssetsService> {
constructor(api: ApiPromise) {
super(api, '/pallets/foreign-assets', new PalletsForeignAssetsService(api));
this.initRoutes();
}

protected initRoutes(): void {
this.safeMountAsyncGetHandlers([['', this.getForeignAssets]]);
}

private getForeignAssets: RequestHandler = async (
{ query: { at } },
res
): Promise<void> => {
const hash = await this.getHashFromAt(at);
PalletsForeignAssetsController.sanitizedSend(
res,
await this.service.fetchForeignAssets(hash)
);
};
}
1 change: 1 addition & 0 deletions src/controllers/pallets/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export { default as PalletsConsts } from './PalletsConstsController';
export { default as PalletsDispatchables } from './PalletsDispatchablesController';
export { default as PalletsErrors } from './PalletsErrorsController';
export { default as PalletsEvents } from './PalletsEventsController';
export { default as PalletsForeignAssets } from './PalletsForeignAssetsController';
export { default as PalletsNominationPools } from './PalletsNominationPoolsController';
export { default as PalletsStakingProgress } from './PalletsStakingProgressController';
export { default as PalletsStakingValidators } from './PalletsStakingValidatorsController';
Expand Down
2 changes: 1 addition & 1 deletion src/services/pallets/PalletsAssetsService.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
2 changes: 1 addition & 1 deletion src/services/pallets/PalletsAssetsService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
2 changes: 1 addition & 1 deletion src/services/pallets/PalletsDispatchablesService.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
4 changes: 2 additions & 2 deletions src/services/pallets/PalletsDispatchablesService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down Expand Up @@ -108,7 +108,7 @@ export class PalletsDispatchablesService extends AbstractPalletsService {
);
} else {
items = Object.entries(dispatchables).map(
(disaptchableItem) => disaptchableItem[1].meta
(dispatchableItem) => dispatchableItem[1].meta
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/services/pallets/PalletsErrorsService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2017-2022 Parity Technologies (UK) Ltd.
// Copyright 2017-2023 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
Expand Down
Loading