From 1bf40ceeab6cb6d10d0766ee9b54f152df841448 Mon Sep 17 00:00:00 2001 From: Stefanie Doll Date: Thu, 16 May 2019 15:11:22 +0200 Subject: [PATCH] Extrinsic bug with undefined value (#914) * Extrinsic contructor to fix * Switch from Unit8Array to U8a * new line * Move Unit8Array to end of decode function * move unit8array up as default * only create empty Unit8Array for undefined values * default value for string * remove empty ExtrinsicValue in decode function call * Throw error instead of console.error * Travis --- packages/types/src/primitive/Method.ts | 11 ++--------- packages/types/src/type/Extrinsic.ts | 4 ++-- 2 files changed, 4 insertions(+), 11 deletions(-) diff --git a/packages/types/src/primitive/Method.ts b/packages/types/src/primitive/Method.ts index 04e0a817e1..82c73ce094 100644 --- a/packages/types/src/primitive/Method.ts +++ b/packages/types/src/primitive/Method.ts @@ -86,7 +86,7 @@ export default class Method extends Struct implements IMethod { * @param _meta - Metadata to use, so that `injectMethods` lookup is not * necessary. */ - private static decodeMethod (value: DecodedMethod | Uint8Array | string, _meta?: FunctionMetadataV4): DecodedMethod { + private static decodeMethod (value: DecodedMethod | Uint8Array | string = new Uint8Array(), _meta?: FunctionMetadataV4): DecodedMethod { if (isHex(value)) { return Method.decodeMethod(hexToU8a(value), _meta); } else if (isU8a(value)) { @@ -122,14 +122,7 @@ export default class Method extends Struct implements IMethod { }; } - console.error(`Method: cannot decode value '${value}' of type ${typeof value}`); - - return { - args: new Uint8Array(), - argsDef: {}, - meta: new FunctionMetadataV4(), - callIndex: new Uint8Array([255, 255]) - }; + throw new Error(`Method: Cannot decode value '${value}' of type ${typeof value}`); } // If the extrinsic function has an argument of type `Origin`, we ignore it diff --git a/packages/types/src/type/Extrinsic.ts b/packages/types/src/type/Extrinsic.ts index fe0b960e67..e35d1a4f82 100644 --- a/packages/types/src/type/Extrinsic.ts +++ b/packages/types/src/type/Extrinsic.ts @@ -38,10 +38,10 @@ export default class Extrinsic extends Struct implements IExtrinsic { super({ signature: ExtrinsicSignature, method: Method - }, Extrinsic.decodeExtrinsic(value || {})); + }, Extrinsic.decodeExtrinsic(value)); } - static decodeExtrinsic (value: ExtrinsicValue | AnyU8a | Method): ExtrinsicValue | Array | Uint8Array { + static decodeExtrinsic (value: ExtrinsicValue | AnyU8a | Method = new Uint8Array()): ExtrinsicValue | Array | Uint8Array { if (Array.isArray(value) || isHex(value)) { // Instead of the block below, it should simply be: // return Extrinsic.decodeExtrinsic(hexToU8a(value as string));