1 | <?php |
||
9 | class WitnessProgram |
||
10 | { |
||
11 | const V0 = 0; |
||
12 | |||
13 | /** |
||
14 | * @var int |
||
15 | */ |
||
16 | private $version; |
||
17 | |||
18 | /** |
||
19 | * @var BufferInterface |
||
20 | */ |
||
21 | private $program; |
||
22 | |||
23 | /** |
||
24 | * @var |
||
25 | */ |
||
26 | private $outputScript; |
||
27 | |||
28 | /** |
||
29 | * WitnessProgram constructor. |
||
30 | * @param int $version |
||
31 | * @param BufferInterface $program |
||
32 | */ |
||
33 | 312 | public function __construct(int $version, BufferInterface $program) |
|
46 | |||
47 | /** |
||
48 | * @param BufferInterface $program |
||
49 | * @return WitnessProgram |
||
50 | */ |
||
51 | 25 | public static function v0(BufferInterface $program): WitnessProgram |
|
52 | { |
||
53 | 25 | if ($program->getSize() === 20) { |
|
54 | 1 | return new self(self::V0, $program); |
|
55 | 24 | } else if ($program->getSize() === 32) { |
|
56 | 24 | return new self(self::V0, $program); |
|
57 | } else { |
||
58 | throw new \RuntimeException('Invalid size for V0 witness program - must be 20 or 32 bytes'); |
||
59 | } |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * @return int |
||
64 | */ |
||
65 | 279 | public function getVersion(): int |
|
69 | |||
70 | /** |
||
71 | * @return BufferInterface |
||
72 | */ |
||
73 | 275 | public function getProgram(): BufferInterface |
|
77 | |||
78 | /** |
||
79 | * @return ScriptInterface |
||
80 | */ |
||
81 | 29 | public function getScript(): ScriptInterface |
|
89 | } |
||
90 |