Skip to content

Commit

Permalink
Update worker for new amqplib
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHash committed Aug 31, 2020
1 parent a3ddb2e commit 26f3bcb
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 61 deletions.
96 changes: 48 additions & 48 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 6 additions & 12 deletions src/Message/LightningdMessageWorker.php
Expand Up @@ -66,30 +66,24 @@ public function run(array $parameters = []): void

private function execute(AMQPMessage $amqpMessage): void
{
$deliveryInfo = $amqpMessage->delivery_info;
/** @var AMQPChannel $channel */
$channel = $deliveryInfo['channel'];
$deliveryTag = $deliveryInfo['delivery_tag'];
$routingKey = $deliveryInfo['routing_key'];

try {
$message = $this->createMessage($routingKey, $amqpMessage);
$message = $this->createMessage($amqpMessage);
if ($message instanceof LightningMessageInterface) {
$this->messageBus->publish($message, MessageBusProvisioner::EVENTS_CHANNEL);
}
$channel->basic_ack($deliveryTag);
$amqpMessage->ack();
} catch (RuntimeException $error) {
$this->logger->error(
"Error handling lightningd message '$routingKey'.",
"Error handling lightningd message '{$amqpMessage->getRoutingKey()}'.",
['exception' => $error->getTrace()]
);
$channel->basic_nack($deliveryTag, false, false);
$amqpMessage->nack();
}
}

private function createMessage(string $routingKey, AMQPMessage $amqpMessage): ?LightningMessageInterface
private function createMessage(AMQPMessage $amqpMessage): ?LightningMessageInterface
{
switch ($routingKey) {
switch ($amqpMessage->getRoutingKey()) {
case self::MESSAGE_INVOICE_PAYMENT:
$message = $this->createInvoicePaymentMessage($amqpMessage);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/Service/LightningdService.php
Expand Up @@ -238,7 +238,7 @@ protected function call(string $method, array $params = []): array

protected function convert(string $amount, string $currency = SatoshiCurrencies::MSAT): Bitcoin
{
return $this->moneyService->convert($this->moneyService->parse($amount ?? '0'.$currency), $currency);
return $this->moneyService->convert($this->moneyService->parse($amount), $currency);
}

protected function mapInvoiceState(string $state): InvoiceState
Expand Down

0 comments on commit 26f3bcb

Please sign in to comment.