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

handle decode error #570

Merged
merged 2 commits into from
Nov 29, 2023
Merged
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
15 changes: 14 additions & 1 deletion packages/core/src/utils/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import { hexToU8a, u8aToHex } from '@polkadot/util'
import _ from 'lodash'

import { decodeWellKnownKey } from './well-known-keys.js'
import { defaultLogger } from '../logger.js'

const logger = defaultLogger.child({ module: 'decoder' })

const _CACHE: Record<string, LRUCache<HexString, StorageEntry>> = {}

Expand Down Expand Up @@ -78,12 +81,22 @@ export const decodeKeyValue = (
const { storage, decodedKey } = decodeKey(meta, block, key)

if (!storage || !decodedKey) {
logger.warn({ key, value }, 'Failed to decode storage key')
return undefined
}

const decodeValue = () => {
if (!value) return null
return meta.registry.createType(decodedKey.outputType, hexToU8a(value))[toHuman ? 'toHuman' : 'toJSON']()
try {
return meta.registry.createType(decodedKey.outputType, hexToU8a(value))[toHuman ? 'toHuman' : 'toJSON']()
} catch (error) {
logger.warn(error, 'Failed to decode storage value')
logger.warn(
{ key, value, section: storage.section, method: storage.method, args: decodedKey.args },
'Failed to decode storage value',
)
return undefined
}
}

return {
Expand Down