Skip to content
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

fix: update errors endpoint to use latest error metadata for fetchErrorItem #1205

Merged
merged 1 commit into from
Jan 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 6 additions & 8 deletions src/services/AbstractPalletsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { ApiDecoration } from '@polkadot/api/types';
import { Option, Vec } from '@polkadot/types';
import {
ErrorMetadataLatest,
MetadataV13,
MetadataV14,
ModuleMetadataV13,
Expand Down Expand Up @@ -199,13 +200,10 @@ export abstract class AbstractPalletsService extends AbstractService {
palletMeta: PalletMetadataV14 | ModuleMetadataV13,
palletItemId: string,
metadataFieldType: string
):
| PalletErrorMetadataV14
| StorageEntryMetadataV13
| StorageEntryMetadataV14 {
): ErrorMetadataLatest | StorageEntryMetadataV13 | StorageEntryMetadataV14 {
let palletItemIdx = -1;
let palletItemMeta:
| PalletErrorMetadataV14
| ErrorMetadataLatest
| StorageEntryMetadataV13
| StorageEntryMetadataV14;

Expand Down Expand Up @@ -238,11 +236,11 @@ export abstract class AbstractPalletsService extends AbstractService {
palletMeta: PalletMetadataV14,
errorItemMetaIdx: number,
errorItemId: string
): [number, PalletErrorMetadataV14] {
): [number, ErrorMetadataLatest] {
const palletName = stringCamelCase(palletMeta.name);
const errors = historicApi.errors[palletName];

if ((palletMeta.errors as unknown as PalletErrorMetadataV14).isEmpty) {
if ((palletMeta.errors as unknown as ErrorMetadataLatest).isEmpty) {
throw new InternalServerError(
`No error items found in ${palletMeta.name.toString()}'s metadadta`
);
Expand All @@ -259,7 +257,7 @@ export abstract class AbstractPalletsService extends AbstractService {
errorItemMetaIdx,
Object.entries(errors)[
errorItemMetaIdx
] as unknown as PalletErrorMetadataV14,
] as unknown as ErrorMetadataLatest,
];
}

Expand Down
10 changes: 3 additions & 7 deletions src/services/pallets/PalletsErrorsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@

import { ApiDecoration } from '@polkadot/api/types';
import { Text } from '@polkadot/types';
import {
BlockHash,
ErrorMetadataLatest,
PalletErrorMetadataV14,
} from '@polkadot/types/interfaces';
import { BlockHash, ErrorMetadataLatest } from '@polkadot/types/interfaces';
import { IsError } from '@polkadot/types/metadata/decorate/types';
import { stringCamelCase } from '@polkadot/util';
import { IPalletErrors, IPalletErrorsItem } from 'src/types/responses';
Expand Down Expand Up @@ -59,7 +55,7 @@ export class PalletsErrorsService extends AbstractPalletsService {
palletMeta,
errorItemId,
metadataFieldType
) as PalletErrorMetadataV14;
) as ErrorMetadataLatest;

let palletErrorMetadata: ErrorMetadataLatest | undefined;
if (metadata) {
Expand Down Expand Up @@ -98,7 +94,7 @@ export class PalletsErrorsService extends AbstractPalletsService {
const errors = historicApi.errors[parsedPalletName];

let items: [] | ErrorMetadataLatest[] | Text[];
if ((palletMeta.errors as unknown as PalletErrorMetadataV14).isEmpty) {
if ((palletMeta.errors as unknown as ErrorMetadataLatest).isEmpty) {
items = [];
} else if (onlyIds) {
items = Object.entries(errors).map(
Expand Down