LndGrpcConnector::connect()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 9
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 15
ccs 0
cts 8
cp 0
crap 2
rs 9.9666
1
<?php declare(strict_types=1);
2
/**
3
 * This file is part of the ngutech/lnd-adapter project.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace NGUtech\Lnd\Connector;
10
11
use Daikon\Dbal\Connector\ConnectorInterface;
12
use Daikon\Dbal\Connector\ProvidesConnector;
13
use Grpc\ChannelCredentials;
14
15
final class LndGrpcConnector implements ConnectorInterface
16
{
17
    use ProvidesConnector;
18
19
    protected function connect(): LndGrpcClient
20
    {
21
        //@todo support node selection
22
        putenv('GRPC_SSL_CIPHER_SUITES=HIGH+ECDSA');
23
        $endpoint = sprintf('%s:%s', $this->settings['host'], $this->settings['port']);
24
        $sslCert = file_get_contents($this->settings['tlscertpath']);
25
        $macaroon = file_get_contents($this->settings['macaroonpath']);
26
        $metadataCallaback = function (array $metadata) use ($macaroon): array {
27
            return array_merge($metadata, ['macaroon' => [bin2hex($macaroon)]]);
28
        };
29
30
        /** @psalm-suppress UndefinedClass */
31
        return new LndGrpcClient($endpoint, [
32
            'credentials' => ChannelCredentials::createSsl($sslCert),
33
            'update_metadata' => $metadataCallaback
34
        ]);
35
    }
36
}
37