diff --git a/packages/type-params/src/decode/index.ts b/packages/type-params/src/decode/index.ts index f9a887e7e5..d3dc6b68f2 100644 --- a/packages/type-params/src/decode/index.ts +++ b/packages/type-params/src/decode/index.ts @@ -11,7 +11,7 @@ import isUndefined from '@polkadot/util/is/undefined'; import decodeValue from './value'; -function decodeTuple (type: Param$Type$Array, input: Uint8Array | null, version: EncodingVersions, isStorage: boolean): Param$Decoded { +function decodeTuple (type: Param$Type$Array, input: Uint8Array | null | undefined, version: EncodingVersions, isStorage: boolean): Param$Decoded { if (!input) { return { length: 0, @@ -36,7 +36,7 @@ function decodeTuple (type: Param$Type$Array, input: Uint8Array | null, version: }; } -function decodeArray ([ type ]: Param$Type$Array, input: Uint8Array | null, version: EncodingVersions, isStorage: boolean): Param$Decoded { +function decodeArray ([ type ]: Param$Type$Array, input: Uint8Array | null | undefined, version: EncodingVersions, isStorage: boolean): Param$Decoded { if (!input) { return { length: 0, @@ -63,8 +63,8 @@ function decodeArray ([ type ]: Param$Type$Array, input: Uint8Array | null, vers } export default function decode (type: Param$Types, _input: Uint8Array | string | null | undefined, version: EncodingVersions, isStorage: boolean = false): Param$Decoded { - const input: Uint8Array | null = isUndefined(_input) || isNull(_input) - ? null + const input: Uint8Array | null | undefined = isUndefined(_input) || isNull(_input) + ? _input : toU8a(_input); if (Array.isArray(type)) { diff --git a/packages/type-params/src/decode/value/accountId.ts b/packages/type-params/src/decode/value/accountId.ts index aeba69477e..5ced50c501 100644 --- a/packages/type-params/src/decode/value/accountId.ts +++ b/packages/type-params/src/decode/value/accountId.ts @@ -8,10 +8,11 @@ import encodeAddress from '@polkadot/util-keyring/address/encode'; import u8a from './u8a'; -export default function accountId (input: Uint8Array | null, version: EncodingVersions, isStorage: boolean): Param$Decoded { - if (input === null) { +export default function accountId (input: Uint8Array | null | undefined, version: EncodingVersions, isStorage: boolean): Param$Decoded { + if (!input) { return { - length: 0 + length: 0, + value: input } as Param$Decoded; } diff --git a/packages/type-params/src/decode/value/bn.ts b/packages/type-params/src/decode/value/bn.ts index 7c221e3695..22ad99e0ec 100644 --- a/packages/type-params/src/decode/value/bn.ts +++ b/packages/type-params/src/decode/value/bn.ts @@ -7,8 +7,8 @@ import { Param$Decoded } from '../../types'; import BN from 'bn.js'; import u8aToBn from '@polkadot/util/u8a/toBn'; -export default function bn (input: Uint8Array | null, bitLength: 32 | 64 | 128): Param$Decoded { - if (input === null) { +export default function bn (input: Uint8Array | null | undefined, bitLength: 32 | 64 | 128): Param$Decoded { + if (!input) { return { length: 0, value: new BN(0) diff --git a/packages/type-params/src/decode/value/bool.ts b/packages/type-params/src/decode/value/bool.ts index 53f940dfe7..f000832368 100644 --- a/packages/type-params/src/decode/value/bool.ts +++ b/packages/type-params/src/decode/value/bool.ts @@ -4,8 +4,8 @@ import { Param$Decoded } from '../../types'; -export default function bool (input: Uint8Array | null): Param$Decoded { - if (input === null) { +export default function bool (input: Uint8Array | null | undefined): Param$Decoded { + if (!input) { return { length: 0, value: false diff --git a/packages/type-params/src/decode/value/byte.ts b/packages/type-params/src/decode/value/byte.ts index c4ffc2edef..40d50972e9 100644 --- a/packages/type-params/src/decode/value/byte.ts +++ b/packages/type-params/src/decode/value/byte.ts @@ -4,8 +4,8 @@ import { Param$Decoded } from '../../types'; -export default function byte (input: Uint8Array | null): Param$Decoded { - if (input === null) { +export default function byte (input: Uint8Array | null | undefined): Param$Decoded { + if (!input) { return { length: 0, value: 0 diff --git a/packages/type-params/src/decode/value/bytes.ts b/packages/type-params/src/decode/value/bytes.ts index 314be1fb7e..b4a5e42d45 100644 --- a/packages/type-params/src/decode/value/bytes.ts +++ b/packages/type-params/src/decode/value/bytes.ts @@ -6,10 +6,11 @@ import { Param$Decoded } from '../../types'; import u8aToBn from '@polkadot/util/u8a/toBn'; -export default function bytes (input: Uint8Array | null): Param$Decoded { - if (input === null) { +export default function bytes (input: Uint8Array | null | undefined): Param$Decoded { + if (!input) { return { - length: 0 + length: 0, + value: input } as Param$Decoded; } diff --git a/packages/type-params/src/decode/value/code.ts b/packages/type-params/src/decode/value/code.ts index 049272f7bb..120c9ee79e 100644 --- a/packages/type-params/src/decode/value/code.ts +++ b/packages/type-params/src/decode/value/code.ts @@ -6,10 +6,11 @@ import { Param$Decoded } from '../../types'; import u8aToBn from '@polkadot/util/u8a/toBn'; -export default function code (input: Uint8Array | null): Param$Decoded { - if (input === null) { +export default function code (input: Uint8Array | null | undefined): Param$Decoded { + if (!input) { return { - length: 0 + length: 0, + value: input } as Param$Decoded; } diff --git a/packages/type-params/src/decode/value/digest.ts b/packages/type-params/src/decode/value/digest.ts index 0692218930..7f5101f279 100644 --- a/packages/type-params/src/decode/value/digest.ts +++ b/packages/type-params/src/decode/value/digest.ts @@ -9,10 +9,11 @@ import u8aToBn from '@polkadot/util/u8a/toBn'; import bytes from './bytes'; -export default function digest (input: Uint8Array | null): Param$Decoded { - if (input === null) { +export default function digest (input: Uint8Array | null | undefined): Param$Decoded { + if (!input) { return { - length: 0 + length: 0, + value: input } as Param$Decoded; } diff --git a/packages/type-params/src/decode/value/header.ts b/packages/type-params/src/decode/value/header.ts index e9d812f0fa..2c35cc1aea 100644 --- a/packages/type-params/src/decode/value/header.ts +++ b/packages/type-params/src/decode/value/header.ts @@ -6,10 +6,11 @@ import { Param$Decoded } from '../../types'; import decodeHeader from '@polkadot/primitives/codec/header/decode'; -export default function header (input: Uint8Array | null): Param$Decoded { - if (input === null) { +export default function header (input: Uint8Array | null | undefined): Param$Decoded { + if (!input) { return { - length: 0 + length: 0, + value: input } as Param$Decoded; } diff --git a/packages/type-params/src/decode/value/index.ts b/packages/type-params/src/decode/value/index.ts index c29bba68c8..afff3eed25 100644 --- a/packages/type-params/src/decode/value/index.ts +++ b/packages/type-params/src/decode/value/index.ts @@ -27,8 +27,8 @@ import time from './time'; import u8a from './u8a'; 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 + const input: Uint8Array | null | undefined = isUndefined(_input) || isNull(_input) + ? _input : toU8a(_input); try { diff --git a/packages/type-params/src/decode/value/keyValue.ts b/packages/type-params/src/decode/value/keyValue.ts index cb81a73070..7fee34286b 100644 --- a/packages/type-params/src/decode/value/keyValue.ts +++ b/packages/type-params/src/decode/value/keyValue.ts @@ -6,10 +6,11 @@ import { Param$Decoded } from '../../types'; import u8aToBn from '@polkadot/util/u8a/toBn'; -export default function bytes (input: Uint8Array | null): Param$Decoded { +export default function bytes (input: Uint8Array | null | undefined): Param$Decoded { if (!input) { return { - length: 0 + length: 0, + value: input } as Param$Decoded; } diff --git a/packages/type-params/src/decode/value/method.ts b/packages/type-params/src/decode/value/method.ts index 08aee7b02c..e9d6063055 100644 --- a/packages/type-params/src/decode/value/method.ts +++ b/packages/type-params/src/decode/value/method.ts @@ -16,10 +16,11 @@ type Result = { value: ExtrinsicDecoded }; -export default function call (decode: Decoder, input: Uint8Array | null, isPublic: boolean, version: EncodingVersions, isStorage: boolean): Param$Decoded { - if (input === null) { +export default function call (decode: Decoder, input: Uint8Array | null | undefined, isPublic: boolean, version: EncodingVersions, isStorage: boolean): Param$Decoded { + if (!input) { return { - length: 0 + length: 0, + value: input } as Param$Decoded; } diff --git a/packages/type-params/src/decode/value/misbehavior.ts b/packages/type-params/src/decode/value/misbehavior.ts index 4470430ceb..d4491dd3e5 100644 --- a/packages/type-params/src/decode/value/misbehavior.ts +++ b/packages/type-params/src/decode/value/misbehavior.ts @@ -18,8 +18,8 @@ const B_SIG = B_HASH + 32; const length = B_SIG + 64; -export default function misbehavior (input: Uint8Array | null): Param$Decoded { - if (input === null) { +export default function misbehavior (input: Uint8Array | null | undefined): Param$Decoded { + if (!input) { return { length: 0 } as Param$Decoded; diff --git a/packages/type-params/src/decode/value/passThrough.ts b/packages/type-params/src/decode/value/passThrough.ts index 6e46067663..f3e4332836 100644 --- a/packages/type-params/src/decode/value/passThrough.ts +++ b/packages/type-params/src/decode/value/passThrough.ts @@ -4,10 +4,11 @@ import { Param$Decoded } from '../../types'; -export default function passThrough (input: Uint8Array | null): Param$Decoded { - if (input === null) { +export default function passThrough (input: Uint8Array | null | undefined): Param$Decoded { + if (!input) { return { - length: 0 + length: 0, + value: input } as Param$Decoded; } diff --git a/packages/type-params/src/decode/value/string.ts b/packages/type-params/src/decode/value/string.ts index 23b1d73d6c..f622179f46 100644 --- a/packages/type-params/src/decode/value/string.ts +++ b/packages/type-params/src/decode/value/string.ts @@ -6,11 +6,14 @@ import { Param$Decoded } from '../../types'; import u8aToBn from '@polkadot/util/u8a/toBn'; import u8aToUtf8 from '@polkadot/util/u8a/toUtf8'; +import isNull from '@polkadot/util/is/null'; +import isUndefined from '@polkadot/util/is/undefined'; -export default function string (input: Uint8Array | null): Param$Decoded { - if (input === null) { +export default function string (input: Uint8Array | null | undefined): Param$Decoded { + if (isUndefined(input) || isNull(input)) { return { - length: 0 + length: 0, + value: input } as Param$Decoded; } diff --git a/packages/type-params/src/decode/value/time.ts b/packages/type-params/src/decode/value/time.ts index 579e87ea2b..1860ea7acf 100644 --- a/packages/type-params/src/decode/value/time.ts +++ b/packages/type-params/src/decode/value/time.ts @@ -6,12 +6,12 @@ import { Param$Decoded } from '../../types'; import u8aToBn from '@polkadot/util/u8a/toBn'; -export default function time (input: Uint8Array | null): Param$Decoded { - if (input === null) { +export default function time (input: Uint8Array | null | undefined): Param$Decoded { + if (!input) { return { length: 0, - value: new Date(0) - }; + value: input + } as Param$Decoded; } return { diff --git a/packages/type-params/src/decode/value/u8a.ts b/packages/type-params/src/decode/value/u8a.ts index 7ea561dd35..847b3e1af3 100644 --- a/packages/type-params/src/decode/value/u8a.ts +++ b/packages/type-params/src/decode/value/u8a.ts @@ -4,10 +4,11 @@ import { Param$Decoded } from '../../types'; -export default function u8a (input: Uint8Array | null, bitLength: 256 | 512, offset: number): Param$Decoded { - if (input === null) { +export default function u8a (input: Uint8Array | null | undefined, bitLength: 256 | 512, offset: number): Param$Decoded { + if (!input) { return { - length: 0 + length: 0, + value: input } as Param$Decoded; } diff --git a/packages/type-params/src/types.d.ts b/packages/type-params/src/types.d.ts index 92ebc2e76d..48c6ae6ea5 100644 --- a/packages/type-params/src/types.d.ts +++ b/packages/type-params/src/types.d.ts @@ -30,7 +30,7 @@ export type KeyValue = { value: Uint8Array } -export type Param$Value = Digest | Header | KeyValue | MisbehaviorReport | ExtrinsicDecoded | BN | Date | Uint8Array | boolean | number | string; +export type Param$Value = Digest | Header | KeyValue | MisbehaviorReport | ExtrinsicDecoded | BN | Date | Uint8Array | boolean | number | string | null; export type Param$Value$Array = Array>>;