1 | import { Block } from './Block';
|
2 | import { InvalidScriptContainerTypeError } from './errors';
|
3 | import { ConsensusPayload } from './payload';
|
4 | import { Transaction } from './transaction';
|
5 |
|
6 | export enum ScriptContainerType {
|
7 | Transaction = 0x00,
|
8 | Block = 0x01,
|
9 | Consensus = 0x02,
|
10 | }
|
11 |
|
12 | export 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 |
|
26 | const isScriptContainerType = (value: number): value is ScriptContainerType =>
|
27 |
|
28 | ScriptContainerType[value] !== undefined;
|
29 |
|
30 | export const assertScriptContainerType = (value: number): ScriptContainerType => {
|
31 | if (isScriptContainerType(value)) {
|
32 | return value;
|
33 | }
|
34 |
|
35 | throw new InvalidScriptContainerTypeError(value);
|
36 | };
|