1 | <?php |
||
14 | class CheckSequenceVerify |
||
15 | { |
||
16 | /** |
||
17 | * @var int |
||
18 | */ |
||
19 | private $relativeTimeLock; |
||
20 | |||
21 | /** |
||
22 | * CheckLocktimeVerify constructor. |
||
23 | * @param int $relativeTimeLock |
||
24 | */ |
||
25 | public function __construct(int $relativeTimeLock) |
||
26 | { |
||
27 | if ($relativeTimeLock < 0) { |
||
28 | throw new \RuntimeException("relative locktime cannot be negative"); |
||
29 | } |
||
30 | |||
31 | if ($relativeTimeLock > Locktime::INT_MAX) { |
||
32 | throw new \RuntimeException("nLockTime exceeds maximum value"); |
||
33 | } |
||
34 | |||
35 | $this->relativeTimeLock = $relativeTimeLock; |
||
36 | } |
||
37 | |||
38 | /** |
||
39 | * @param Operation[] $chunks |
||
40 | * @param bool $fMinimal |
||
41 | * @return static |
||
42 | */ |
||
43 | 3 | public static function fromDecodedScript(array $chunks, $fMinimal = false): self |
|
44 | { |
||
45 | 3 | if (count($chunks) !== 3) { |
|
46 | 3 | throw new \RuntimeException("Invalid number of items for CSV"); |
|
47 | } |
||
48 | |||
49 | 2 | if (!$chunks[0]->isPush()) { |
|
50 | 2 | throw new \InvalidArgumentException('CSV script had invalid value for time'); |
|
51 | } |
||
52 | |||
53 | if ($chunks[1]->getOp() !== Opcodes::OP_CHECKSEQUENCEVERIFY) { |
||
54 | throw new \InvalidArgumentException('CSV script invalid opcode'); |
||
55 | } |
||
56 | |||
57 | if ($chunks[2]->getOp() !== Opcodes::OP_DROP) { |
||
58 | throw new \InvalidArgumentException('CSV script invalid opcode'); |
||
59 | } |
||
60 | |||
61 | $numLockTime = Number::buffer($chunks[0]->getData(), $fMinimal, 5); |
||
62 | |||
63 | return new static((int) $numLockTime->getInt()); |
||
64 | } |
||
65 | |||
66 | /** |
||
67 | * @param ScriptInterface $script |
||
68 | * @return CheckSequenceVerify |
||
69 | */ |
||
70 | public static function fromScript(ScriptInterface $script): self |
||
74 | |||
75 | /** |
||
76 | * @return int |
||
77 | */ |
||
78 | public function getRelativeLockTime(): int |
||
79 | { |
||
80 | return $this->relativeTimeLock; |
||
81 | } |
||
82 | |||
83 | /** |
||
84 | * @return bool |
||
85 | */ |
||
86 | public function isRelativeToBlock(): bool |
||
94 | |||
95 | /** |
||
96 | * @return bool |
||
97 | */ |
||
98 | public function isDisabled(): bool |
||
102 | } |
||
103 |