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
This commit is contained in:
Stefanie Doll
2019-06-12 16:45:45 +12:00
committed by Ian He
parent e16a4652e6
commit 1bf40ceeab
2 changed files with 4 additions and 11 deletions
+2 -9
View File
@@ -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
+2 -2
View File
@@ -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<number> | Uint8Array {
static decodeExtrinsic (value: ExtrinsicValue | AnyU8a | Method = new Uint8Array()): ExtrinsicValue | Array<number> | Uint8Array {
if (Array.isArray(value) || isHex(value)) {
// Instead of the block below, it should simply be:
// return Extrinsic.decodeExtrinsic(hexToU8a(value as string));