Add toU8a for EnumType (#362)

This commit is contained in:
Jaco Greeff
2018-10-29 14:51:07 +01:00
committed by GitHub
parent 4d920bbffa
commit 28fd04c9e9
2 changed files with 14 additions and 5 deletions
+4 -4
View File
@@ -46,10 +46,6 @@ export default class Enum extends Base<number> {
return this.raw;
}
toU8a (isBare?: boolean): Uint8Array {
return new Uint8Array([this.raw]);
}
toNumber (): number {
return this.raw;
}
@@ -57,4 +53,8 @@ export default class Enum extends Base<number> {
toString (): string {
return this._enum[this.raw] || `${this.raw}`;
}
toU8a (isBare?: boolean): Uint8Array {
return new Uint8Array([this.raw]);
}
}
+10 -1
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { isNumber, isObject, isU8a, isUndefined } from '@polkadot/util';
import { isNumber, isObject, isU8a, isUndefined, u8aConcat } from '@polkadot/util';
import Base from './Base';
import { Constructor } from '../types';
@@ -119,4 +119,13 @@ export default class EnumType<T> extends Base<Base<T>> {
toString (): string {
return this.type;
}
toU8a (isBare?: boolean): Uint8Array {
const index = this._indexes[this._index];
return u8aConcat(
new Uint8Array([index]),
this.raw.toU8a(isBare)
);
}
}