UNPKG

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