private function initClient()
{
$this->client->on("connect", function () {
$this->logger->notice("Connected to websocket.");
$this->client->send('{"op":"unconfirmed_sub"}');
});
$this->client->on("message", function (WebSocketMessage $message) {
$data = json_decode($message->getData(), true);
$output = $data['x']['out'];
foreach ($output as $receiver) {
if (!isset($receiver['addr'])) {
//some outputs does not have address, dafuq?
continue;
}
$newAddresses = file_get_contents($this->newAddressesFile);
if ($newAddresses) {
$this->loadAddresses();
}
file_put_contents($this->lastReadFile, \Carbon\Carbon::now()->toAtomString());
$address = $receiver['addr'];
$amount = $receiver['value'] / 10000000;
// $this->logger->notice("$address, $amount");
if (isset($this->addresses[$address])) {
//todo: zjistit si, jestli není lepší mít to spíše jako hashset, aby to bylo rychlejší
$this->transactionReceived($address, $amount);
}
}
});
}