Skip to content

Commit

Permalink
add types to fix any lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
marshacb committed Dec 6, 2023
1 parent 394e889 commit 2f937f3
Show file tree
Hide file tree
Showing 13 changed files with 280 additions and 13 deletions.
28 changes: 16 additions & 12 deletions src/services/blocks/XCMDecoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -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({
Expand All @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion src/types/responses/SanitizedArgs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

import { ISanitizedCall } from '.';
import { ISanitizedParachainInherentData } from './SanitizedParachainInherentData';
import { ISanitizedParentInherentData } from './SanitizedParentInherentData';

export interface ISanitizedArgs {
call?: ISanitizedCall;
calls?: ISanitizedCall[];
[key: string]: unknown;
data?: ISanitizedParentInherentData | ISanitizedParachainInherentData;
}
27 changes: 27 additions & 0 deletions src/types/responses/SanitizedBackedCandidate.ts
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

import {
ISanitizedBackedCandidateExplicitValidityVote,
ISanitizedBackedCandidateImplicitValidityVote,
} from './SanitizedBackedCandidateValidityVotes';
import { ISanitizedCandidate } from './SanitizedCandidate';

export interface ISanitizedBackedCandidate {
candidate: ISanitizedCandidate;
validityVotes: (ISanitizedBackedCandidateExplicitValidityVote | ISanitizedBackedCandidateImplicitValidityVote)[];
validatorIndices: `0x${string}`;
}
27 changes: 27 additions & 0 deletions src/types/responses/SanitizedBackedCandidateDescriptor.ts
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

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}`;
}
23 changes: 23 additions & 0 deletions src/types/responses/SanitizedBackedCandidateValidityVotes.ts
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

export interface ISanitizedBackedCandidateExplicitValidityVote {
explicit: `0x${string}`;
}

export interface ISanitizedBackedCandidateImplicitValidityVote {
implicit: `0x${string}`;
}
24 changes: 24 additions & 0 deletions src/types/responses/SanitizedBackedCandidatesCommitments.ts
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

export interface ISanitizedBackedCandidateCommitments {
upwardMessages: string[];
horizontalMessages: string[];
newValidationCode: string | undefined;
headData: `0x${string}`;
processedDownwardMessages: string;
hrmpWatermark: string;
}
21 changes: 21 additions & 0 deletions src/types/responses/SanitizedBitfield.ts
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

export interface ISanitizedBitfield {
payload: `0x${string}`;
validatorIndex: string;
signature: `0x${string}`;
}
23 changes: 23 additions & 0 deletions src/types/responses/SanitizedCandidate.ts
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

import { ISanitizedBackedCandidateDescriptor } from './SanitizedBackedCandidateDescriptor';
import { ISanitizedBackedCandidateCommitments } from './SanitizedBackedCandidatesCommitments';

export interface ISanitizedCandidate {
descriptor: ISanitizedBackedCandidateDescriptor;
commitments: ISanitizedBackedCandidateCommitments;
}
21 changes: 21 additions & 0 deletions src/types/responses/SanitizedHorizontalMessages.ts
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

import { IHorizontalMessage } from './BlockXCMMessages';

export interface ISanitizedHorizontalMessages {
[key: string]: IHorizontalMessage[];
}
25 changes: 25 additions & 0 deletions src/types/responses/SanitizedParachainInherentData.ts
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

import { IDownwardMessage, IHorizontalMessage } from './BlockXCMMessages';
import { ISanitizedParachainValidationData } from './SanitizedParachainValidationData';

export interface ISanitizedParachainInherentData {
validationData: ISanitizedParachainValidationData;
relayChainState: `0x${string}`[];
downwardMessages: IDownwardMessage[];
horizontalMessages: Map<string, IHorizontalMessage[]>;
}
22 changes: 22 additions & 0 deletions src/types/responses/SanitizedParachainValidationData.ts
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

export interface ISanitizedParachainValidationData {
parentHead: `0x${string}`;
relayParentNumber: string;
relayParentStorageRoot: `0x${string}`;
maxPovSize: string;
}
27 changes: 27 additions & 0 deletions src/types/responses/SanitizedParentInherentData.ts
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

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;
}
21 changes: 21 additions & 0 deletions src/types/responses/SanitizediDisputeStatementSet.ts
Original file line number Diff line number Diff line change
@@ -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 <http://www.gnu.org/licenses/>.

export interface ISanitizedDisputeStatementSet {
candidateHash: `0x${string}`;
session: string;
statements: string[][];
}

0 comments on commit 2f937f3

Please sign in to comment.