@@ -36,9 +36,9 @@ |
||
36 | 36 | */ |
37 | 37 | public function connect($host, $port) |
38 | 38 | { |
39 | - return $this->connector->create($host, $port)->then(function (Stream $stream) { |
|
39 | + return $this->connector->create($host, $port)->then(function(Stream $stream) { |
|
40 | 40 | return new Connection($stream, $this->requestFactory); |
41 | - }, function (\Exception $e) { |
|
41 | + }, function(\Exception $e) { |
|
42 | 42 | throw $e; |
43 | 43 | }); |
44 | 44 | } |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | /** |
32 | 32 | * @var Deferred[] |
33 | 33 | */ |
34 | - private $deferred = []; |
|
34 | + private $deferred = [ ]; |
|
35 | 35 | |
36 | 36 | /** |
37 | 37 | * @var string |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | { |
48 | 48 | $this->factory = $requestFactory; |
49 | 49 | $this->stream = $stream; |
50 | - $this->stream->on('data', [$this, 'onData']); |
|
50 | + $this->stream->on('data', [ $this, 'onData' ]); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | public function close() |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | public function sendRequest(Request $request) |
81 | 81 | { |
82 | 82 | $result = new Deferred(); |
83 | - $this->deferred[$request->getId()] = $result; |
|
83 | + $this->deferred[ $request->getId() ] = $result; |
|
84 | 84 | $this->sendData($request->write()); |
85 | 85 | return $result->promise(); |
86 | 86 | } |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | * @param array $params |
91 | 91 | * @return \React\Promise\Promise|\React\Promise\PromiseInterface |
92 | 92 | */ |
93 | - public function request($method, array $params = []) |
|
93 | + public function request($method, array $params = [ ]) |
|
94 | 94 | { |
95 | 95 | $request = $this->factory->create($method, $params); |
96 | 96 | return $this->sendRequest($request); |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public function onData($data) |
103 | 103 | { |
104 | - $buffer = $this->streamBuffer . $data; |
|
104 | + $buffer = $this->streamBuffer.$data; |
|
105 | 105 | |
106 | 106 | while (($nextPos = strpos($buffer, "\n"))) { |
107 | 107 | $msg = substr($buffer, 0, $nextPos); |
@@ -127,54 +127,54 @@ discard block |
||
127 | 127 | public function onMessage($data) |
128 | 128 | { |
129 | 129 | $response = $this->factory->response($data); |
130 | - if (isset($this->deferred[$response->getId()])) { |
|
131 | - $this->deferred[$response->getId()]->resolve($response); |
|
130 | + if (isset($this->deferred[ $response->getId() ])) { |
|
131 | + $this->deferred[ $response->getId() ]->resolve($response); |
|
132 | 132 | } else { |
133 | - $this->emit('message', [$response]); |
|
133 | + $this->emit('message', [ $response ]); |
|
134 | 134 | |
135 | 135 | if ($response instanceof Request) { |
136 | 136 | $params = $response->getParams(); |
137 | 137 | |
138 | 138 | switch ($response->getMethod()) { |
139 | 139 | case ElectrumClient::HEADERS_SUBSCRIBE: |
140 | - if (!isset($params[0])) { |
|
140 | + if (!isset($params[ 0 ])) { |
|
141 | 141 | throw new \RuntimeException('Headers notification missing body'); |
142 | 142 | } |
143 | 143 | |
144 | - $header = $params[0]; |
|
144 | + $header = $params[ 0 ]; |
|
145 | 145 | if (count($header) !== 8) { |
146 | 146 | throw new \RuntimeException('Headers notification missing parameter'); |
147 | 147 | } |
148 | 148 | |
149 | - $this->emit(ElectrumClient::HEADERS_SUBSCRIBE, [new HeadersNotification($header[0], $header[1], $header[2], $header[3], $header[4], $header[5], $header[6], $header[7])]); |
|
149 | + $this->emit(ElectrumClient::HEADERS_SUBSCRIBE, [ new HeadersNotification($header[ 0 ], $header[ 1 ], $header[ 2 ], $header[ 3 ], $header[ 4 ], $header[ 5 ], $header[ 6 ], $header[ 7 ]) ]); |
|
150 | 150 | break; |
151 | 151 | case ElectrumClient::ADDRESS_SUBSCRIBE: |
152 | - if (!isset($params[0]) || !isset($params[1])) { |
|
152 | + if (!isset($params[ 0 ]) || !isset($params[ 1 ])) { |
|
153 | 153 | throw new \RuntimeException('Address notification missing address/txid'); |
154 | 154 | } |
155 | 155 | |
156 | - $this->emit(ElectrumClient::ADDRESS_SUBSCRIBE, [new AddressNotification($params[0], $params[1])]); |
|
156 | + $this->emit(ElectrumClient::ADDRESS_SUBSCRIBE, [ new AddressNotification($params[ 0 ], $params[ 1 ]) ]); |
|
157 | 157 | break; |
158 | 158 | case ElectrumClient::NUMBLOCKS_SUBSCRIBE: |
159 | - if (!isset($params[0])) { |
|
159 | + if (!isset($params[ 0 ])) { |
|
160 | 160 | throw new \RuntimeException('Missing notification parameter: height'); |
161 | 161 | } |
162 | 162 | |
163 | - $this->emit(ElectrumClient::NUMBLOCKS_SUBSCRIBE, [new NumBlocksNotification($params[0])]); |
|
163 | + $this->emit(ElectrumClient::NUMBLOCKS_SUBSCRIBE, [ new NumBlocksNotification($params[ 0 ]) ]); |
|
164 | 164 | break; |
165 | 165 | case MiningClient::SET_DIFFICULTY: |
166 | - if (!isset($params[0])) { |
|
166 | + if (!isset($params[ 0 ])) { |
|
167 | 167 | throw new \RuntimeException('Missing mining difficulty notification parameter'); |
168 | 168 | } |
169 | 169 | |
170 | - $this->emit(MiningClient::SET_DIFFICULTY, [new SetDifficultyNotification($params[0])]); |
|
170 | + $this->emit(MiningClient::SET_DIFFICULTY, [ new SetDifficultyNotification($params[ 0 ]) ]); |
|
171 | 171 | break; |
172 | 172 | case MiningClient::NOTIFY: |
173 | 173 | if (count($params) !== 9) { |
174 | 174 | throw new \RuntimeException('Missing mining notification parameter'); |
175 | 175 | } |
176 | 176 | |
177 | - $this->emit(MiningClient::NOTIFY, [new MiningNotification($params[0], $params[1], $params[2], $params[3], $params[4], $params[5], $params[6], $params[7], $params[8])]); |
|
177 | + $this->emit(MiningClient::NOTIFY, [ new MiningNotification($params[ 0 ], $params[ 1 ], $params[ 2 ], $params[ 3 ], $params[ 4 ], $params[ 5 ], $params[ 6 ], $params[ 7 ], $params[ 8 ]) ]); |
|
178 | 178 | break; |
179 | 179 | } |
180 | 180 | } |