Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ndeet/php-ln-lnd-rest
A Lightning Network Daemon (LND) package for LND's REST endpoints. PHP classes are generated by the Swagger Codegen project.
https://github.com/ndeet/php-ln-lnd-rest
bitcoin lightning-network lnd php rest-api swagger-codegen
Last synced: about 1 month ago
JSON representation
A Lightning Network Daemon (LND) package for LND's REST endpoints. PHP classes are generated by the Swagger Codegen project.
- Host: GitHub
- URL: https://github.com/ndeet/php-ln-lnd-rest
- Owner: ndeet
- Created: 2018-01-10T10:10:41.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-10-15T07:16:44.000Z (about 3 years ago)
- Last Synced: 2024-09-30T09:22:47.109Z (about 2 months ago)
- Topics: bitcoin, lightning-network, lnd, php, rest-api, swagger-codegen
- Language: PHP
- Homepage:
- Size: 467 KB
- Stars: 8
- Watchers: 3
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# LndRest
A [Lightning Network Daemon (LND)](https://github.com/lightningnetwork/lnd) package for LND's REST endpoints. PHP classes are generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project using LND's [rpc.swagger.json](https://github.com/lightningnetwork/lnd/blob/master/lnrpc/rpc.swagger.json)
- Based on LND version: 0.13.3-beta
- This package version: 0.13.3## Requirements
PHP 7.1 and later
## Installation & Usage
### ComposerTo install the bindings via [Composer](http://getcomposer.org/), use the following command:
```
composer require ndeet/ln-lnd-rest
```## Tests
To run the unit tests:
```
composer install
./vendor/bin/phpunit
```## Getting Started
Note:
- The examples in the generated classes docs are not working out of the box. You will need to pass the port, use SSL and also
use macaroons of your properly secured LND installation.
- Generated classes with lnd-0.13.3-beta are not tested yet by me due to lack of time currently. Fingers crossed everything works.```php
setHost('https://localhost:8001');// First we need to unlock the encrypted wallet. This needs only run once.
$walletInstance = new Lnd\Rest\Api\WalletUnlockerApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client([
'debug' => TRUE,
'verify' => $tlsPath,
'headers' => [
'Grpc-Metadata-macaroon' => $macaroon
]
]),
$apiConfig
);$unlockRequest = new \Lnd\Rest\Model\LnrpcUnlockWalletRequest([
'walletPassword' => base64_encode('YOUR_WALLET_PASS')
]);try {
$unlocked = $walletInstance->unlockWallet($unlockRequest);
// gives 408 timeout but unlock successful, afterwards 404 not found
} catch (Exception $e) {
echo 'Exception when calling WalletUnlockerApi->unlockWallet(): ', $e->getMessage(), PHP_EOL;
}// We can now use the getInfo endpoint:
$apiInstance = new Lnd\Rest\Api\LightningApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
new GuzzleHttp\Client([
'debug' => TRUE,
'verify' => $tlsPath,
'headers' => [
'Grpc-Metadata-macaroon' => bin2hex(file_get_contents($macaroonPath))
]
]),
$apiConfig
);try {
$result = $apiInstance->getInfo();
var_dump($result);
} catch (Exception $e) {
echo 'Exception when calling LightningApi->getInfo: ', $e->getMessage(), PHP_EOL;
}// Let's generate an lightning invoice.
$invoice = new \Lnd\Rest\Model\LnrpcInvoice([
'memo' => 'testinvoice memo',
'value' => 1001,
'expiry' => 3600
]);try {
$invoiceResult = $apiInstance->addInvoice($invoice);
var_dump($invoiceResult);
} catch (Exception $e) {
echo 'Exception when calling LightningApi->addInvoice: ', $e->getMessage(), PHP_EOL;
}?>
```## How to generate the code yourself
You can use swagger-codegen to create this whole package out of the rpc.swagger.json of LND. To do this you need swagger-codegen and (for this package as example) this `lnrest-config.json`:
```
{
"variableNamingConvention": "camelCase",
"invokerPackage": "Lnd\\Rest",
"packagePath": "LndRest",
"srcBasePath": "src",
"composerVendorName": "ndeet",
"gitUserId": "ndeet",
"composerProjectName": "ln-lnd-rest",
"gitRepoId": "php-ln-lnd-rest",
"artifactVersion": "0.13.3",
"license": "MIT"
}
```You can generate the code by having the official [lightningnetwork/lnd](https://github.com/lightningnetwork/lnd) repo checked out to the tag you need and then use that rpc.swagger.json for the code genration like this.
```
swagger-codegen generate -c lnrest-config.json -l php -o php-ln-lnd-rest -i /path/to/lightningnetwork/lnd/lnrpc/rpc.swagger.json
```## Notice regarding to `subscribeInvoices` endpoint
The REST endpoints are generated from the same gRPC `rpc.proto` file and it seems the streaming does not work on REST services according to LND's lead developer [@roasbeef](https://github.com/roasbeef). But they plan to provide Websockets in a future release. So you may need to do some custom long polling using [**lookupInvoice**](docs/Api/LightningApi.md#lookupinvoice) endpoint.This are some autogenerated docs pointing to classes docs:
## Documentation for API endpoints
[Lightning API Endpoints](docs/Api/LightningApi.md)
[Wallet Unlocker API](docs/Api/WalletUnlockerApi.md)## Documentation for authorization
All endpoints do not require authorization. Make sure that those endpoints provided
by this package are not publicly accessible. If you set a wallet password you need
to unlock your wallet first, see documentation and example above.## Author
Andreas Tasch