1 | <?php |
||
14 | class PayToPubkeyHash |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * @var BufferInterface |
||
19 | */ |
||
20 | private $hash; |
||
21 | |||
22 | /** |
||
23 | * @var bool |
||
24 | */ |
||
25 | private $verify; |
||
26 | |||
27 | /** |
||
28 | * PayToPubkeyHash constructor. |
||
29 | * @param int $opcode |
||
30 | * @param BufferInterface $hash160 |
||
31 | * @param bool $allowVerify |
||
32 | */ |
||
33 | 2 | public function __construct(int $opcode, BufferInterface $hash160, bool $allowVerify = false) |
|
51 | |||
52 | /** |
||
53 | * @param Operation[] $chunks |
||
54 | * @param bool $allowVerify |
||
55 | * @return static |
||
56 | */ |
||
57 | 4 | public static function fromDecodedScript(array $chunks, bool $allowVerify = false) |
|
58 | { |
||
59 | 4 | if (count($chunks) !== 5) { |
|
60 | 3 | throw new \RuntimeException('Malformed pay-to-pubkey-hash script'); |
|
61 | } |
||
62 | |||
63 | 2 | if ($chunks[0]->getOp() !== Opcodes::OP_DUP |
|
64 | 2 | || $chunks[1]->getOp() !== Opcodes::OP_HASH160 |
|
65 | 2 | || $chunks[3]->getOp() !== Opcodes::OP_EQUALVERIFY |
|
66 | ) { |
||
67 | throw new \RuntimeException('Malformed pay-to-pubkey-hash script'); |
||
68 | } |
||
69 | |||
70 | 2 | return new static($chunks[4]->getOp(), $chunks[2]->getData(), $allowVerify); |
|
71 | } |
||
72 | |||
73 | /** |
||
74 | * @param ScriptInterface $script |
||
75 | * @param bool $allowVerify |
||
76 | * @return PayToPubkeyHash |
||
77 | */ |
||
78 | 1 | public static function fromScript(ScriptInterface $script, bool $allowVerify = false) |
|
82 | |||
83 | /** |
||
84 | * @return string |
||
85 | */ |
||
86 | public function getType(): string |
||
87 | { |
||
88 | return ScriptType::P2PK; |
||
89 | } |
||
90 | |||
91 | /** |
||
92 | * @return int |
||
93 | */ |
||
94 | 2 | public function getRequiredSigCount(): int |
|
98 | |||
99 | /** |
||
100 | * @return int |
||
101 | */ |
||
102 | 1 | public function getKeyCount(): int |
|
106 | |||
107 | /** |
||
108 | * @return bool |
||
109 | */ |
||
110 | public function isChecksigVerify(): bool |
||
111 | { |
||
112 | return $this->verify; |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * @param PublicKeyInterface $publicKey |
||
117 | * @return bool |
||
118 | */ |
||
119 | 1 | public function checkInvolvesKey(PublicKeyInterface $publicKey): bool |
|
123 | |||
124 | /** |
||
125 | * @return BufferInterface |
||
126 | */ |
||
127 | 2 | public function getPubKeyHash(): BufferInterface |
|
131 | } |
||
132 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: