1 | import { makeErrorWithCode } from '@neo-one/utils-esnext-esm';
|
2 |
|
3 | export enum Command {
|
4 | addr = 'addr',
|
5 | block = 'block',
|
6 | consensus = 'consensus',
|
7 | filteradd = 'filteradd',
|
8 | filterclear = 'filterclear',
|
9 | filterload = 'filterload',
|
10 | getaddr = 'getaddr',
|
11 | getblocks = 'getblocks',
|
12 | getdata = 'getdata',
|
13 | getheaders = 'getheaders',
|
14 | headers = 'headers',
|
15 | inv = 'inv',
|
16 | mempool = 'mempool',
|
17 | tx = 'tx',
|
18 | verack = 'verack',
|
19 | version = 'version',
|
20 | alert = 'alert',
|
21 | merkleblock = 'merkleblock',
|
22 | notfound = 'notfound',
|
23 | ping = 'ping',
|
24 | pong = 'pong',
|
25 | reject = 'reject',
|
26 | }
|
27 |
|
28 | export const InvalidCommandError = makeErrorWithCode(
|
29 | 'INVALID_COMMAND',
|
30 | (command: string) => `Invalid Command. Found: ${command}`,
|
31 | );
|
32 |
|
33 | const isCommand = (command: string): command is Command =>
|
34 |
|
35 | Command[command as any] !== undefined;
|
36 |
|
37 | export const assertCommand = (command: string): Command => {
|
38 | if (isCommand(command)) {
|
39 | return command;
|
40 | }
|
41 |
|
42 | throw new InvalidCommandError(command);
|
43 | };
|