UNPKG

982 BPlain TextView Raw
1import { Block } from './Block';
2import { InvalidScriptContainerTypeError } from './errors';
3import { ConsensusPayload } from './payload';
4import { Transaction } from './transaction';
5
6export enum ScriptContainerType {
7 Transaction = 0x00,
8 Block = 0x01,
9 Consensus = 0x02,
10}
11
12export type ScriptContainer =
13 | {
14 readonly type: ScriptContainerType.Transaction;
15 readonly value: Transaction;
16 }
17 | {
18 readonly type: ScriptContainerType.Block;
19 readonly value: Block;
20 }
21 | {
22 readonly type: ScriptContainerType.Consensus;
23 readonly value: ConsensusPayload;
24 };
25
26const isScriptContainerType = (value: number): value is ScriptContainerType =>
27 // tslint:disable-next-line strict-type-predicates
28 ScriptContainerType[value] !== undefined;
29
30export const assertScriptContainerType = (value: number): ScriptContainerType => {
31 if (isScriptContainerType(value)) {
32 return value;
33 }
34
35 throw new InvalidScriptContainerTypeError(value);
36};