-
Notifications
You must be signed in to change notification settings - Fork 340
/
Bool.ts
43 lines (33 loc) · 809 Bytes
/
Bool.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright 2017-2018 @polkadot/api-codec authors & contributors
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import Base from './codec/Base';
export default class Bool extends Base<boolean> {
constructor (value: Bool | boolean = false) {
super(
value instanceof Bool
? value.raw
: value
);
}
byteLength (): number {
return 1;
}
fromJSON (input: any): Bool {
this.raw = input === true;
return this;
}
fromU8a (input: Uint8Array): Bool {
this.raw = input[0] === 1;
return this;
}
toJSON (): any {
return this.raw;
}
toU8a (): Uint8Array {
return new Uint8Array([this.raw ? 1 : 0]);
}
toString (): string {
return `${this.raw}`;
}
}