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 decode null value #135

Merged
merged 2 commits into from
Jan 10, 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
2 changes: 1 addition & 1 deletion e2e/build-block.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { setupAll } from './helper'

describe.each([
{ chain: 'Polkadot', endpoint: 'wss://rpc.polkadot.io' },
{ chain: 'Kusama', endpoint: 'wss://kusama-rpc.polkadot.io' },
{ chain: 'Kusama', endpoint: 'wss://kusama-rpc.dwellir.com' },
{ chain: 'Acala', endpoint: 'wss://acala-rpc-1.aca-api.network' },
])('Latest $chain can build blocks', async ({ endpoint }) => {
const { setup, teardownAll } = await setupAll({ endpoint })
Expand Down
12 changes: 6 additions & 6 deletions src/utils/decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ export const decodeKeyValue = async (block: Block, key: HexString, value?: HexSt
return { [key]: value }
}

const decodedValue = meta.registry.createType(decodedKey.outputType, hexToU8a(value))
const decodedValue = value ? meta.registry.createType(decodedKey.outputType, hexToU8a(value)).toHuman() : null

switch (decodedKey.args.length) {
case 2: {
return {
[storage.section]: {
[storage.method]: {
[decodedKey.args[0].toString()]: {
[decodedKey.args[1].toString()]: decodedValue.toHuman(),
[decodedKey.args[1].toString()]: decodedValue,
},
},
},
Expand All @@ -71,15 +71,15 @@ export const decodeKeyValue = async (block: Block, key: HexString, value?: HexSt
return {
[storage.section]: {
[storage.method]: {
[decodedKey.args[0].toString()]: decodedValue.toHuman(),
[decodedKey.args[0].toString()]: decodedValue,
},
},
}
}
default:
return {
[storage.section]: {
[storage.method]: decodedValue.toHuman(),
[storage.method]: decodedValue,
},
}
}
Expand All @@ -92,8 +92,8 @@ export const decodeStorageDiff = async (block: Block, diff: [HexString, HexStrin
const oldState = {}
const newState = {}
for (const [key, value] of diff) {
_.merge(oldState, await decodeKeyValue(block, key as HexString, (await parent.get(key)) as any))
_.merge(newState, await decodeKeyValue(block, key as HexString, value))
_.merge(oldState, await decodeKeyValue(parent, key, (await parent.get(key)) as any))
_.merge(newState, await decodeKeyValue(block, key, value))
}
return [oldState, newState, diffPatcher.diff(oldState, newState)]
}