tkijewski / php-lnrpc
此包已被废弃,不再维护。作者建议使用https://github.com/lnpay/php-lnd-grpc包代替。
关于此包的最新版本(v0.16.4-beta)没有可用的许可证信息。
PHP LND RPC 实现
v0.16.4-beta
2023-08-16 19:59 UTC
Requires
- google/common-protos: ^1.1
- google/protobuf: ^3.8.0
- grpc/grpc: ^1.22.0
This package is auto-updated.
Last update: 2023-08-16 20:00:27 UTC
README
PHP 要求
$ sudo apt-get install php-dev php-pear zlib1g-dev zip unzip
$ pecl install grpc
$ sudo sh -c "echo 'extension=grpc.so' >> /etc/php/7.2/cli/php.ini" #depends on PHP version you are using. Add this line in the ini file
安装
安装此扩展的首选方法是使用composer
composer require lnpay/php-lnd-grpc
基本用法
然后可以这样使用
<?php
putenv('GRPC_SSL_CIPHER_SUITES=HIGH+ECDSA');
require __DIR__ . '/vendor/autoload.php';
$certPath = '../.lnd/tls.cert';
$macaroonPath = '../.lnd/data/chain/bitcoin/mainnet/admin.macaroon';
$cert = file_get_contents($certPath);
$macaroon = file_get_contents($macaroonPath);
$callback = function ($metadata) use ($macaroon) {
return ['macaroon' => [bin2hex($macaroon)]];
};
$credentials = \Grpc\ChannelCredentials::createSsl($cert);
$x = new \Lnrpc\LightningClient('127.0.0.1:10009',['credentials'=>$credentials,'update_metadata'=>$callback]);
$gir = new \Lnrpc\WalletBalanceRequest();
$result = $x->WalletBalance($gir);
echo "Balance:".$result->wait()[0]->getTotalBalance();
多个客户端示例
//EXAMPLE BY @MrHash
use Invoicesrpc\InvoicesClient;
use Lnrpc\LightningClient;
final class LndGrpcClient
{
/** @var LightningClient */
public $lnrpc;
/** @var InvoicesClient */
public $invoicesrpc;
public function __construct(string $endpoint, array $options)
{
$this->lnrpc = new LightningClient($endpoint, $options); //$options example seen in Basic Usage
$this->invoicesrpc = new InvoicesClient($endpoint, $options); //$options example seen in Basic Usage
}
}
更新 RPC 定义
$ bash regenerate_rpc.sh v0.11.1-beta
regenerate_rpc.sh
从https://raw.githubusercontent.com/lightningnetwork/lnd/master/v0.11.1-beta/XXX.proto 中获取,并根据此生成。
当前生成:rpc.proto invoices.proto router.proto walletkit.proto chainnotifier.proto signer.proto