1 | <?php |
||
16 | class OutputScriptFactory |
||
17 | { |
||
18 | /** |
||
19 | * @param AddressInterface $address |
||
20 | * @return ScriptInterface |
||
21 | */ |
||
22 | 16 | public function payToAddress(AddressInterface $address) |
|
23 | { |
||
24 | 16 | return $address instanceof ScriptHashAddress |
|
25 | 4 | ? ScriptFactory::sequence([Opcodes::OP_HASH160, $address->getHash(), Opcodes::OP_EQUAL]) |
|
26 | 16 | : ScriptFactory::sequence([Opcodes::OP_DUP, Opcodes::OP_HASH160, $address->getHash(), Opcodes::OP_EQUALVERIFY, Opcodes::OP_CHECKSIG]); |
|
27 | } |
||
28 | |||
29 | /** |
||
30 | * @param PublicKeyInterface $publicKey |
||
31 | * @return ScriptInterface |
||
32 | */ |
||
33 | 2 | public function p2pk(PublicKeyInterface $publicKey) |
|
37 | |||
38 | /** |
||
39 | * @param BufferInterface $pubKeyHash |
||
40 | * @return ScriptInterface |
||
41 | */ |
||
42 | 4 | public function p2pkh(BufferInterface $pubKeyHash) |
|
46 | |||
47 | /** |
||
48 | * @param BufferInterface $scriptHash |
||
49 | * @return ScriptInterface |
||
50 | */ |
||
51 | 24 | public function p2sh(BufferInterface $scriptHash) |
|
55 | |||
56 | /** |
||
57 | * @param BufferInterface $witnessScriptHash |
||
58 | * @return ScriptInterface |
||
59 | */ |
||
60 | 6 | public function p2wsh(BufferInterface $witnessScriptHash) |
|
64 | |||
65 | /** |
||
66 | * @param BufferInterface $witnessKeyHash |
||
67 | * @return ScriptInterface |
||
68 | */ |
||
69 | 2 | public function p2wkh(BufferInterface $witnessKeyHash) |
|
73 | /** |
||
74 | * Create a Pay to pubkey output |
||
75 | * |
||
76 | * @param PublicKeyInterface $publicKey |
||
77 | * @return ScriptInterface |
||
78 | */ |
||
79 | 14 | public function payToPubKey(PublicKeyInterface $publicKey) |
|
83 | |||
84 | /** |
||
85 | * Create a P2PKH output script |
||
86 | * |
||
87 | * @param BufferInterface $pubKeyHash |
||
88 | * @return ScriptInterface |
||
89 | */ |
||
90 | 48 | public function payToPubKeyHash(BufferInterface $pubKeyHash) |
|
98 | |||
99 | /** |
||
100 | /** |
||
101 | * Create a P2SH output script |
||
102 | * |
||
103 | * @param BufferInterface $scriptHash |
||
104 | * @return ScriptInterface |
||
105 | */ |
||
106 | 50 | public function payToScriptHash(BufferInterface $scriptHash) |
|
114 | |||
115 | /** |
||
116 | * @param int $m |
||
117 | * @param PublicKeyInterface[] $keys |
||
118 | * @param bool|true $sort |
||
119 | * @return ScriptInterface |
||
120 | */ |
||
121 | public function multisig($m, array $keys = [], $sort = true) |
||
127 | |||
128 | /** |
||
129 | * @param int $m |
||
130 | * @param BufferInterface[] $keys |
||
131 | * @param bool|true $sort |
||
132 | * @return ScriptInterface |
||
133 | */ |
||
134 | 32 | public function multisigKeyBuffers($m, array $keys = [], $sort = true) |
|
165 | |||
166 | /** |
||
167 | * @param BufferInterface $keyHash |
||
168 | * @return ScriptInterface |
||
169 | */ |
||
170 | 2 | public function witnessKeyHash(BufferInterface $keyHash) |
|
178 | |||
179 | /** |
||
180 | * @param BufferInterface $scriptHash |
||
181 | * @return ScriptInterface |
||
182 | */ |
||
183 | 8 | public function witnessScriptHash(BufferInterface $scriptHash) |
|
191 | |||
192 | /** |
||
193 | * @param BufferInterface $commitment |
||
194 | * @return ScriptInterface |
||
195 | */ |
||
196 | 6 | public function witnessCoinbaseCommitment(BufferInterface $commitment) |
|
207 | } |
||
208 |