From 2f937f3331971fb57cfdad1b2047fe5452ee895c Mon Sep 17 00:00:00 2001 From: marshacb Date: Wed, 6 Dec 2023 14:01:32 -0500 Subject: [PATCH] add types to fix any lint errors --- src/services/blocks/XCMDecoder.ts | 28 +++++++++++-------- src/types/responses/SanitizedArgs.ts | 4 ++- .../responses/SanitizedBackedCandidate.ts | 27 ++++++++++++++++++ .../SanitizedBackedCandidateDescriptor.ts | 27 ++++++++++++++++++ .../SanitizedBackedCandidateValidityVotes.ts | 23 +++++++++++++++ .../SanitizedBackedCandidatesCommitments.ts | 24 ++++++++++++++++ src/types/responses/SanitizedBitfield.ts | 21 ++++++++++++++ src/types/responses/SanitizedCandidate.ts | 23 +++++++++++++++ .../responses/SanitizedHorizontalMessages.ts | 21 ++++++++++++++ .../SanitizedParachainInherentData.ts | 25 +++++++++++++++++ .../SanitizedParachainValidationData.ts | 22 +++++++++++++++ .../responses/SanitizedParentInherentData.ts | 27 ++++++++++++++++++ .../SanitizediDisputeStatementSet.ts | 21 ++++++++++++++ 13 files changed, 280 insertions(+), 13 deletions(-) create mode 100644 src/types/responses/SanitizedBackedCandidate.ts create mode 100644 src/types/responses/SanitizedBackedCandidateDescriptor.ts create mode 100644 src/types/responses/SanitizedBackedCandidateValidityVotes.ts create mode 100644 src/types/responses/SanitizedBackedCandidatesCommitments.ts create mode 100644 src/types/responses/SanitizedBitfield.ts create mode 100644 src/types/responses/SanitizedCandidate.ts create mode 100644 src/types/responses/SanitizedHorizontalMessages.ts create mode 100644 src/types/responses/SanitizedParachainInherentData.ts create mode 100644 src/types/responses/SanitizedParachainValidationData.ts create mode 100644 src/types/responses/SanitizedParentInherentData.ts create mode 100644 src/types/responses/SanitizediDisputeStatementSet.ts diff --git a/src/services/blocks/XCMDecoder.ts b/src/services/blocks/XCMDecoder.ts index 3542b56c8..c179b718d 100644 --- a/src/services/blocks/XCMDecoder.ts +++ b/src/services/blocks/XCMDecoder.ts @@ -18,6 +18,9 @@ import '@polkadot/api-augment'; import { ApiPromise } from '@polkadot/api'; import { Bytes } from '@polkadot/types'; +import { ISanitizedBackedCandidate } from 'src/types/responses/SanitizedBackedCandidate'; +import { ISanitizedParachainInherentData } from 'src/types/responses/SanitizedParachainInherentData'; +import { ISanitizedParentInherentData } from 'src/types/responses/SanitizedParentInherentData'; import { IDownwardMessage, @@ -59,10 +62,10 @@ export class XcmDecoder { extrinsics.forEach((extrinsic) => { const frame = extrinsic.method as IFrameMethod; if (frame.pallet === 'paraInherent' && frame.method === 'enter') { - const data: any = extrinsic.args.data; + const data = extrinsic.args.data as ISanitizedParentInherentData; const upwardMessage: IUpwardMessage[] = []; if (paraId !== undefined) { - data.backedCandidates.forEach((candidate: any) => { + data.backedCandidates.forEach((candidate) => { if (candidate.candidate.descriptor.paraId.toString() === paraId) { const msg_decoded = XcmDecoder.checkUpwardMsg(api, candidate); if (msg_decoded != undefined && Object.keys(msg_decoded).length > 0) { @@ -71,7 +74,7 @@ export class XcmDecoder { } }); } else { - data.backedCandidates.forEach((candidate: any) => { + data.backedCandidates.forEach((candidate) => { const msg_decoded = XcmDecoder.checkUpwardMsg(api, candidate); if (msg_decoded != undefined && Object.keys(msg_decoded).length > 0) { upwardMessage.push(msg_decoded); @@ -87,11 +90,12 @@ export class XcmDecoder { extrinsics.forEach((extrinsic) => { const frame: IFrameMethod = extrinsic.method as IFrameMethod; if (frame.pallet === 'parachainSystem' && frame.method === 'setValidationData') { - const data: any = extrinsic.args.data; - data.downwardMessages.forEach((msg: any) => { - if (msg.msg.length > 0) { + const data = extrinsic.args.data as ISanitizedParachainInherentData; + data.downwardMessages.forEach((msg) => { + const message = msg.data; + if (message.length > 0) { const downwardMessage: IDownwardMessage[] = []; - const xcmMessageDecoded = this.decodeMsg(api, msg.msg); + const xcmMessageDecoded = this.decodeMsg(api, message); downwardMessage.push({ sentAt: msg.sentAt, data: xcmMessageDecoded, @@ -101,8 +105,8 @@ export class XcmDecoder { }); } }); - data.horizontalMessages.forEach((msg: [], index: string) => { - msg.forEach((msg: any) => { + data.horizontalMessages.forEach((msgs, index) => { + msgs.forEach((msg) => { const horizontalMessage: IHorizontalMessage[] = []; const xcmMessageDecoded = this.decodeMsg(api, msg.data.slice(1)); horizontalMessage.push({ @@ -121,10 +125,10 @@ export class XcmDecoder { return xcmMessages; } - static checkUpwardMsg(api: ApiPromise, candidate: any): IUpwardMessage | undefined { + static checkUpwardMsg(api: ApiPromise, candidate: ISanitizedBackedCandidate): IUpwardMessage | undefined { if (candidate.candidate.commitments.upwardMessages.length > 0) { - const xcmMessage: string = candidate.candidate.commitments.upwardMessages; - const paraId: string = candidate.candidate.descriptor.paraId.toString(); + const xcmMessage = candidate.candidate.commitments.upwardMessages; + const paraId: string = candidate.candidate.descriptor.paraId; const xcmMessageDecoded: string = this.decodeMsg(api, xcmMessage[0]); const upwardMessage = { paraId: paraId, diff --git a/src/types/responses/SanitizedArgs.ts b/src/types/responses/SanitizedArgs.ts index c87e426ae..19b73335f 100644 --- a/src/types/responses/SanitizedArgs.ts +++ b/src/types/responses/SanitizedArgs.ts @@ -15,9 +15,11 @@ // along with this program. If not, see . import { ISanitizedCall } from '.'; +import { ISanitizedParachainInherentData } from './SanitizedParachainInherentData'; +import { ISanitizedParentInherentData } from './SanitizedParentInherentData'; export interface ISanitizedArgs { call?: ISanitizedCall; calls?: ISanitizedCall[]; - [key: string]: unknown; + data?: ISanitizedParentInherentData | ISanitizedParachainInherentData; } diff --git a/src/types/responses/SanitizedBackedCandidate.ts b/src/types/responses/SanitizedBackedCandidate.ts new file mode 100644 index 000000000..dc25b4007 --- /dev/null +++ b/src/types/responses/SanitizedBackedCandidate.ts @@ -0,0 +1,27 @@ +// 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 . + +import { + ISanitizedBackedCandidateExplicitValidityVote, + ISanitizedBackedCandidateImplicitValidityVote, +} from './SanitizedBackedCandidateValidityVotes'; +import { ISanitizedCandidate } from './SanitizedCandidate'; + +export interface ISanitizedBackedCandidate { + candidate: ISanitizedCandidate; + validityVotes: (ISanitizedBackedCandidateExplicitValidityVote | ISanitizedBackedCandidateImplicitValidityVote)[]; + validatorIndices: `0x${string}`; +} diff --git a/src/types/responses/SanitizedBackedCandidateDescriptor.ts b/src/types/responses/SanitizedBackedCandidateDescriptor.ts new file mode 100644 index 000000000..35d8db73d --- /dev/null +++ b/src/types/responses/SanitizedBackedCandidateDescriptor.ts @@ -0,0 +1,27 @@ +// 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 . + +export interface ISanitizedBackedCandidateDescriptor { + paraId: string; + relayParent: `0x${string}`; + collator: `0x${string}`; + persistedValidationDataHash: `0x${string}`; + povHash: `0x${string}`; + erasureRoot: `0x${string}`; + signature: `0x${string}`; + paraHead: `0x${string}`; + validationCodeHash: `0x${string}`; +} diff --git a/src/types/responses/SanitizedBackedCandidateValidityVotes.ts b/src/types/responses/SanitizedBackedCandidateValidityVotes.ts new file mode 100644 index 000000000..03e88d138 --- /dev/null +++ b/src/types/responses/SanitizedBackedCandidateValidityVotes.ts @@ -0,0 +1,23 @@ +// 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 . + +export interface ISanitizedBackedCandidateExplicitValidityVote { + explicit: `0x${string}`; +} + +export interface ISanitizedBackedCandidateImplicitValidityVote { + implicit: `0x${string}`; +} diff --git a/src/types/responses/SanitizedBackedCandidatesCommitments.ts b/src/types/responses/SanitizedBackedCandidatesCommitments.ts new file mode 100644 index 000000000..ab7e2e5e1 --- /dev/null +++ b/src/types/responses/SanitizedBackedCandidatesCommitments.ts @@ -0,0 +1,24 @@ +// 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 . + +export interface ISanitizedBackedCandidateCommitments { + upwardMessages: string[]; + horizontalMessages: string[]; + newValidationCode: string | undefined; + headData: `0x${string}`; + processedDownwardMessages: string; + hrmpWatermark: string; +} diff --git a/src/types/responses/SanitizedBitfield.ts b/src/types/responses/SanitizedBitfield.ts new file mode 100644 index 000000000..cd9e1280e --- /dev/null +++ b/src/types/responses/SanitizedBitfield.ts @@ -0,0 +1,21 @@ +// 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 . + +export interface ISanitizedBitfield { + payload: `0x${string}`; + validatorIndex: string; + signature: `0x${string}`; +} diff --git a/src/types/responses/SanitizedCandidate.ts b/src/types/responses/SanitizedCandidate.ts new file mode 100644 index 000000000..d836d7e8e --- /dev/null +++ b/src/types/responses/SanitizedCandidate.ts @@ -0,0 +1,23 @@ +// 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 . + +import { ISanitizedBackedCandidateDescriptor } from './SanitizedBackedCandidateDescriptor'; +import { ISanitizedBackedCandidateCommitments } from './SanitizedBackedCandidatesCommitments'; + +export interface ISanitizedCandidate { + descriptor: ISanitizedBackedCandidateDescriptor; + commitments: ISanitizedBackedCandidateCommitments; +} diff --git a/src/types/responses/SanitizedHorizontalMessages.ts b/src/types/responses/SanitizedHorizontalMessages.ts new file mode 100644 index 000000000..26c6f1c6c --- /dev/null +++ b/src/types/responses/SanitizedHorizontalMessages.ts @@ -0,0 +1,21 @@ +// 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 . + +import { IHorizontalMessage } from './BlockXCMMessages'; + +export interface ISanitizedHorizontalMessages { + [key: string]: IHorizontalMessage[]; +} diff --git a/src/types/responses/SanitizedParachainInherentData.ts b/src/types/responses/SanitizedParachainInherentData.ts new file mode 100644 index 000000000..4dc82e48c --- /dev/null +++ b/src/types/responses/SanitizedParachainInherentData.ts @@ -0,0 +1,25 @@ +// 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 . + +import { IDownwardMessage, IHorizontalMessage } from './BlockXCMMessages'; +import { ISanitizedParachainValidationData } from './SanitizedParachainValidationData'; + +export interface ISanitizedParachainInherentData { + validationData: ISanitizedParachainValidationData; + relayChainState: `0x${string}`[]; + downwardMessages: IDownwardMessage[]; + horizontalMessages: Map; +} diff --git a/src/types/responses/SanitizedParachainValidationData.ts b/src/types/responses/SanitizedParachainValidationData.ts new file mode 100644 index 000000000..aace26e0a --- /dev/null +++ b/src/types/responses/SanitizedParachainValidationData.ts @@ -0,0 +1,22 @@ +// 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 . + +export interface ISanitizedParachainValidationData { + parentHead: `0x${string}`; + relayParentNumber: string; + relayParentStorageRoot: `0x${string}`; + maxPovSize: string; +} diff --git a/src/types/responses/SanitizedParentInherentData.ts b/src/types/responses/SanitizedParentInherentData.ts new file mode 100644 index 000000000..1677ce536 --- /dev/null +++ b/src/types/responses/SanitizedParentInherentData.ts @@ -0,0 +1,27 @@ +// 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 . + +import { IBlockRaw } from './BlockRaw'; +import { ISanitizedBackedCandidate } from './SanitizedBackedCandidate'; +import { ISanitizedBitfield } from './SanitizedBitfield'; +import { ISanitizedDisputeStatementSet } from './SanitizediDisputeStatementSet'; + +export interface ISanitizedParentInherentData { + bitfields: ISanitizedBitfield[]; + backedCandidates: ISanitizedBackedCandidate[]; + disputes: ISanitizedDisputeStatementSet[]; + parentHeader: IBlockRaw; +} diff --git a/src/types/responses/SanitizediDisputeStatementSet.ts b/src/types/responses/SanitizediDisputeStatementSet.ts new file mode 100644 index 000000000..d47d3d250 --- /dev/null +++ b/src/types/responses/SanitizediDisputeStatementSet.ts @@ -0,0 +1,21 @@ +// 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 . + +export interface ISanitizedDisputeStatementSet { + candidateHash: `0x${string}`; + session: string; + statements: string[][]; +}