1 | <?php |
||
17 | class AddressFactory |
||
18 | { |
||
19 | /** |
||
20 | * Returns a pay-to-pubkey-hash address for the given public key |
||
21 | * |
||
22 | * @param KeyInterface $key |
||
23 | 44 | * @return PayToPubKeyHashAddress |
|
24 | */ |
||
25 | 44 | public static function fromKey(KeyInterface $key) |
|
29 | |||
30 | /** |
||
31 | * Takes the $p2shScript and generates the scriptHash address. |
||
32 | * |
||
33 | * @param ScriptInterface $p2shScript |
||
34 | 12 | * @return ScriptHashAddress |
|
35 | */ |
||
36 | 12 | public static function fromScript(ScriptInterface $p2shScript) |
|
40 | |||
41 | /** |
||
42 | * @param WitnessProgram $wp |
||
43 | 8 | * @return SegwitAddress |
|
44 | */ |
||
45 | 8 | public static function fromWitnessProgram(WitnessProgram $wp) |
|
49 | 4 | ||
50 | 6 | /** |
|
51 | * @param ScriptInterface $outputScript |
||
52 | 2 | * @return AddressInterface |
|
53 | */ |
||
54 | 4 | public static function fromOutputScript(ScriptInterface $outputScript) |
|
73 | 32 | ||
74 | /** |
||
75 | 2 | * @param string $address |
|
76 | * @param NetworkInterface $network |
||
77 | * @return AddressInterface |
||
78 | * @throws \BitWasp\Bitcoin\Exceptions\Base58ChecksumFailure |
||
79 | */ |
||
80 | public static function fromString($address, NetworkInterface $network = null) |
||
105 | 4 | ||
106 | /** |
||
107 | 4 | * @param string $address |
|
108 | 4 | * @param NetworkInterface $network |
|
109 | 4 | * @return bool |
|
110 | 2 | * @throws \BitWasp\Bitcoin\Exceptions\Base58ChecksumFailure |
|
111 | */ |
||
112 | 4 | public static function isValidAddress($address, NetworkInterface $network = null) |
|
123 | |||
124 | /** |
||
125 | * Following a loose definition of 'associated', returns |
||
126 | * the current script types, and a PayToPubKeyHash address for P2PK. |
||
127 | * |
||
128 | * @param ScriptInterface $script |
||
129 | * @return AddressInterface |
||
130 | * @throws \RuntimeException |
||
131 | */ |
||
132 | public static function getAssociatedAddress(ScriptInterface $script) |
||
142 | } |
||
143 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: