Add toU8a for EnumType (#362)
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user