1 | import { makeErrorWithCode } from '@neo-one/utils-esnext-esm';
|
2 |
|
3 | export enum InventoryType {
|
4 | Transaction = 0x01,
|
5 | Block = 0x02,
|
6 | Consensus = 0xe0,
|
7 | }
|
8 |
|
9 | export const InvalidInventoryTypeError = makeErrorWithCode(
|
10 | 'INVALID_INVENTORY_TYPE',
|
11 | (inventoryType: number) => `Expected inventory type, found: ${inventoryType}`,
|
12 | );
|
13 |
|
14 | const isInventoryType = (inventoryType: number): inventoryType is InventoryType =>
|
15 |
|
16 | InventoryType[inventoryType] !== undefined;
|
17 |
|
18 | export const assertInventoryType = (inventoryType: number): InventoryType => {
|
19 | if (isInventoryType(inventoryType)) {
|
20 | return inventoryType;
|
21 | }
|
22 |
|
23 | throw new InvalidInventoryTypeError(inventoryType);
|
24 | };
|