-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add pallets/events endpoint (#1204)
* add events pallet events endpoint add unit tests add e2e test * update docs for pallet events endpoint * add statemint e2e tests for pallet events endpoint * update events references * remove duplicate IPalletEventsParam reference * lint * add events check to getPalletMetadataType add unhappy path check to fetchEventItem unit tests * merge master * update abstratpalletservice types refactored events items assignment * update error message to reflect more accurately when the pallet metadata has no items to query of a specific field type * debug historicApi pallets * update check for isValidPalletName to use the pallet meta data instead of the historicApi * update error log for when a pallet id is not recognized * yarn lint
- Loading branch information
Showing
32 changed files
with
919 additions
and
31 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 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 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 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 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 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 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 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 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 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 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,77 @@ | ||
// Copyright 2017-2022 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 { stringCamelCase } from '@polkadot/util'; | ||
import { RequestHandler } from 'express-serve-static-core'; | ||
import { IPalletsEventsParam } from 'src/types/requests'; | ||
|
||
import { PalletsEventsService } from '../../services'; | ||
import AbstractController from '../AbstractController'; | ||
|
||
export default class PalletsEventsController extends AbstractController<PalletsEventsService> { | ||
constructor(api: ApiPromise) { | ||
super(api, '/pallets/:palletId/events', new PalletsEventsService(api)); | ||
|
||
this.initRoutes(); | ||
} | ||
|
||
protected initRoutes(): void { | ||
this.safeMountAsyncGetHandlers([ | ||
['/:eventItemId', this.getEventById as RequestHandler], | ||
['/', this.getEvents], | ||
]); | ||
} | ||
|
||
private getEventById: RequestHandler<IPalletsEventsParam, unknown, unknown> = | ||
async ( | ||
{ query: { at, metadata }, params: { palletId, eventItemId } }, | ||
res | ||
): Promise<void> => { | ||
const metadataArg = metadata === 'true'; | ||
const hash = await this.getHashFromAt(at); | ||
const historicApi = await this.api.at(hash); | ||
|
||
PalletsEventsController.sanitizedSend( | ||
res, | ||
await this.service.fetchEventItem(historicApi, { | ||
hash, | ||
// stringCamelCase ensures we don't have snake case or kebab case | ||
palletId: stringCamelCase(palletId), | ||
eventItemId: stringCamelCase(eventItemId), | ||
metadata: metadataArg, | ||
}) | ||
); | ||
}; | ||
|
||
private getEvents: RequestHandler = async ( | ||
{ params: { palletId }, query: { at, onlyIds } }, | ||
res | ||
): Promise<void> => { | ||
const onlyIdsArg = onlyIds === 'true'; | ||
const hash = await this.getHashFromAt(at); | ||
const historicApi = await this.api.at(hash); | ||
|
||
PalletsEventsController.sanitizedSend( | ||
res, | ||
await this.service.fetchEvents(historicApi, { | ||
hash, | ||
palletId: stringCamelCase(palletId), | ||
onlyIds: onlyIdsArg, | ||
}) | ||
); | ||
}; | ||
} |
This file contains 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
Oops, something went wrong.