From b57b03450d95f8885e1a346ad286535bd9c0534b Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Sun, 12 Aug 2018 00:47:23 +0200 Subject: [PATCH] null/undefined check for value decoding --- packages/type-params/src/decode/value/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/type-params/src/decode/value/index.ts b/packages/type-params/src/decode/value/index.ts index 5c75b65721..c29bba68c8 100644 --- a/packages/type-params/src/decode/value/index.ts +++ b/packages/type-params/src/decode/value/index.ts @@ -7,6 +7,8 @@ import { Decoder } from '../types'; import sizes from '@polkadot/primitives/sizes'; import toU8a from '@polkadot/util/u8a/toU8a'; +import isNull from '@polkadot/util/is/null'; +import isUndefined from '@polkadot/util/is/undefined'; import accountId from './accountId'; import bool from './bool'; @@ -24,8 +26,10 @@ import string from './string'; import time from './time'; import u8a from './u8a'; -export default function decodeValue (decode: Decoder, type: Param$Type, _input: Uint8Array | string | null, version: EncodingVersions, isStorage: boolean): Param$Decoded { - const input: Uint8Array | null = toU8a(_input); +export default function decodeValue (decode: Decoder, type: Param$Type, _input: Uint8Array | string | null | undefined, version: EncodingVersions, isStorage: boolean): Param$Decoded { + const input: Uint8Array | null = isUndefined(_input) || isNull(_input) + ? null + : toU8a(_input); try { switch (type) {