1 | <?php |
||
21 | class AddressCreator extends BaseAddressCreator |
||
22 | { |
||
23 | /** |
||
24 | * @param string $strAddress |
||
25 | * @param NetworkInterface $network |
||
26 | * @return Base58Address|null |
||
27 | */ |
||
28 | 39 | protected function readBase58Address(string $strAddress, NetworkInterface $network) |
|
45 | |||
46 | /** |
||
47 | * @param string $strAddress |
||
48 | * @param NetworkInterface $network |
||
49 | * @return SegwitAddress|null |
||
50 | */ |
||
51 | 7 | protected function readSegwitAddress(string $strAddress, NetworkInterface $network) |
|
69 | |||
70 | /** |
||
71 | * @param ScriptInterface $outputScript |
||
72 | * @return Address |
||
73 | */ |
||
74 | 41 | public function fromOutputScript(ScriptInterface $outputScript): Address |
|
75 | { |
||
76 | 41 | if ($outputScript instanceof P2shScript || $outputScript instanceof WitnessScript) { |
|
77 | throw new \RuntimeException("P2shScript & WitnessScript's are not accepted by fromOutputScript"); |
||
78 | } |
||
79 | |||
80 | 41 | $wp = null; |
|
81 | 41 | if ($outputScript->isWitness($wp)) { |
|
82 | /** @var WitnessProgram $wp */ |
||
83 | 10 | return new SegwitAddress($wp); |
|
84 | } |
||
85 | |||
86 | 31 | $decode = (new OutputClassifier())->decode($outputScript); |
|
87 | 31 | switch ($decode->getType()) { |
|
88 | case ScriptType::P2PKH: |
||
89 | /** @var BufferInterface $solution */ |
||
90 | 20 | return new PayToPubKeyHashAddress($decode->getSolution()); |
|
91 | case ScriptType::P2SH: |
||
92 | /** @var BufferInterface $solution */ |
||
93 | 11 | return new ScriptHashAddress($decode->getSolution()); |
|
94 | default: |
||
95 | 1 | throw new \RuntimeException('Script type is not associated with an address'); |
|
96 | } |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * @param string $strAddress |
||
101 | * @param NetworkInterface|null $network |
||
102 | * @return Address |
||
103 | * @throws UnrecognizedAddressException |
||
104 | */ |
||
105 | 39 | public function fromString(string $strAddress, NetworkInterface $network = null): Address |
|
119 | } |
||
120 |