docs: State example gRPC assumptions, add TLS grpc instructions
This commit is contained in:
parent
96a5fdd3ec
commit
9cd1168ebe
@ -17,18 +17,16 @@
|
|||||||
|
|
||||||
At this point, you should set your `$GOPATH` environment variable, which
|
At this point, you should set your `$GOPATH` environment variable, which
|
||||||
represents the path to your workspace. By default, `$GOPATH` is set to
|
represents the path to your workspace. By default, `$GOPATH` is set to
|
||||||
`~/go`. Be sure to set your `$GOPATH` every time you open a new terminal
|
`~/go`. You wll also need to add `$GOPATH/bin` to your `PATH`. This ensures
|
||||||
window.
|
that your shell will be able to detect the binaries you install.
|
||||||
```
|
|
||||||
export GOPATH=~/projects/lightning
|
|
||||||
```
|
|
||||||
It is recommended to add `$GOPATH/bin` to your `PATH` at this point, like
|
|
||||||
so:
|
|
||||||
```bash
|
```bash
|
||||||
|
export GOPATH=~/projects/lightning
|
||||||
export PATH=$PATH:$GOPATH/bin
|
export PATH=$PATH:$GOPATH/bin
|
||||||
```
|
```
|
||||||
This will ensure that your shell will be able to detect the binaries that
|
We recommend placing the above in your .bashrc or in a setup
|
||||||
were just installed.
|
script so that you can avoid typing this every time you open a new terminal
|
||||||
|
window.
|
||||||
|
|
||||||
* **Glide:** This project uses `Glide` to manage dependencies as well
|
* **Glide:** This project uses `Glide` to manage dependencies as well
|
||||||
as to provide *reproducible builds*. To install `Glide`, execute the
|
as to provide *reproducible builds*. To install `Glide`, execute the
|
||||||
@ -131,7 +129,7 @@ If you are doing local development, such as for the tutorial, you'll want to
|
|||||||
start both `btcd` and `lnd` in the `simnet` mode. Simnet is similar to regtest
|
start both `btcd` and `lnd` in the `simnet` mode. Simnet is similar to regtest
|
||||||
in that you'll be able to instantly mine blocks as needed to test `lnd`
|
in that you'll be able to instantly mine blocks as needed to test `lnd`
|
||||||
locally. In order to start either daemon in the `simnet` mode use `simnet`
|
locally. In order to start either daemon in the `simnet` mode use `simnet`
|
||||||
instead of `testnet`, such as adding the `--bitcoin.simnet` flag instead of the
|
instead of `testnet`, adding the `--bitcoin.simnet` flag instead of the
|
||||||
`--bitcoin.testnet` flag.
|
`--bitcoin.testnet` flag.
|
||||||
|
|
||||||
Another relevant command line flag for local testing of new `lnd` developments
|
Another relevant command line flag for local testing of new `lnd` developments
|
||||||
@ -144,7 +142,9 @@ of your `sendpayment` commands.
|
|||||||
### Running LND
|
### Running LND
|
||||||
|
|
||||||
If you are on testnet, run this command after `btcd` has finished syncing.
|
If you are on testnet, run this command after `btcd` has finished syncing.
|
||||||
Otherwise, replace `--bitcoin.testnet` with `--bitcoin.simnet`
|
Otherwise, replace `--bitcoin.testnet` with `--bitcoin.simnet`. If you
|
||||||
|
installing `lnd` in preparation for the
|
||||||
|
[tutorial](//dev.lightning.community/tutorial), you may skip this step.
|
||||||
```
|
```
|
||||||
lnd --bitcoin.active --bitcoin.testnet --debuglevel=debug --bitcoin.rpcuser=kek --bitcoin.rpcpass=kek --externalip=X.X.X.X
|
lnd --bitcoin.active --bitcoin.testnet --debuglevel=debug --bitcoin.rpcuser=kek --bitcoin.rpcpass=kek --externalip=X.X.X.X
|
||||||
```
|
```
|
||||||
|
@ -18,8 +18,8 @@ at least somewhere reachable by your Javascript code).
|
|||||||
The `rpc.proto` file is [located in the `lnrpc` directory of the `lnd`
|
The `rpc.proto` file is [located in the `lnrpc` directory of the `lnd`
|
||||||
sources](https://github.com/lightningnetwork/lnd/blob/master/lnrpc/rpc.proto).
|
sources](https://github.com/lightningnetwork/lnd/blob/master/lnrpc/rpc.proto).
|
||||||
|
|
||||||
In order to allow the auto code generated to compile the protos successfully,
|
In order for the auto-generated code to compile successfully, you'll need to
|
||||||
you'll need to comment out the following line:
|
comment out the following line:
|
||||||
```
|
```
|
||||||
//import "google/api/annotations.proto";
|
//import "google/api/annotations.proto";
|
||||||
```
|
```
|
||||||
@ -31,14 +31,23 @@ Every time you work with Javascript gRPC, you will have to import `grpc`, load
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
var grpc = require('grpc');
|
var grpc = require('grpc');
|
||||||
|
var fs = require("fs");
|
||||||
|
|
||||||
|
// Lnd cert is at ~/.lnd/tls.cert on Linux and
|
||||||
|
// ~/Library/Application Support/Lnd/tls.cert on Mac
|
||||||
|
var lndCert = fs.readFileSync("~/.lnd/tls.cert");
|
||||||
|
var credentials = grpc.credentials.createSsl(lndCert);
|
||||||
var lnrpcDescriptor = grpc.load("rpc.proto");
|
var lnrpcDescriptor = grpc.load("rpc.proto");
|
||||||
var lnrpc = lnrpcDescriptor.lnrpc;
|
var lnrpc = lnrpcDescriptor.lnrpc;
|
||||||
var lightning = new lnrpc.Lightning('localhost:10009', grpc.credentials.createInsecure());
|
var lightning = new lnrpc.Lightning('localhost:10009', credentials);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
Let's walk through some examples of Javascript gRPC clients.
|
Let's walk through some examples of Javascript gRPC clients. These examples
|
||||||
|
assume that you have at least two `lnd` nodes running, the RPC location of one
|
||||||
|
of which is at the default `localhost:10009`, with an open channel between the
|
||||||
|
two nodes.
|
||||||
|
|
||||||
#### Simple RPC
|
#### Simple RPC
|
||||||
|
|
||||||
@ -78,8 +87,18 @@ call.on('data', function(invoice) {
|
|||||||
console.log("Current status" + status);
|
console.log("Current status" + status);
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
Now, create an invoice for your node at `localhost:10009` and send a payment to
|
|
||||||
it. Your Javascript console should display the details of the recently satisfied
|
Now, create an invoice for your node at `localhost:10009`and send a payment to
|
||||||
|
it from another node.
|
||||||
|
```bash
|
||||||
|
$ lncli addinvoice --value=100
|
||||||
|
{
|
||||||
|
"r_hash": <RHASH>,
|
||||||
|
"pay_req": <PAYMENT_REQUEST>
|
||||||
|
}
|
||||||
|
$ lncli sendpayment --pay_req=<PAYMENT_REQUEST>
|
||||||
|
```
|
||||||
|
Your Javascript console should now display the details of the recently satisfied
|
||||||
invoice.
|
invoice.
|
||||||
|
|
||||||
#### Bidirectional-streaming RPC
|
#### Bidirectional-streaming RPC
|
||||||
|
@ -44,7 +44,7 @@ Python gRPC.
|
|||||||
|
|
||||||
#### Imports and Client
|
#### Imports and Client
|
||||||
|
|
||||||
Everytime you use Python gRPC, you will have to import the generated rpc modeuls
|
Everytime you use Python gRPC, you will have to import the generated rpc modules
|
||||||
and set up a channel and stub to your connect to your `lnd` node:
|
and set up a channel and stub to your connect to your `lnd` node:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
@ -52,13 +52,19 @@ import rpc_pb2 as ln
|
|||||||
import rpc_pb2_grpc as lnrpc
|
import rpc_pb2_grpc as lnrpc
|
||||||
import grpc
|
import grpc
|
||||||
|
|
||||||
channel = grpc.insecure_channel('localhost:10009')
|
# Lnd cert is at ~/.lnd/tls.cert on Linux and
|
||||||
|
# ~/Library/Application Support/Lnd/tls.cert on Mac
|
||||||
|
cert = open('~/.lnd/tls.cert').read()
|
||||||
|
creds = grpc.ssl_channel_credentials(cert)
|
||||||
|
channel = grpc.secure_channel('localhost:10009', creds)
|
||||||
stub = lnrpc.LightningStub(channel)
|
stub = lnrpc.LightningStub(channel)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Examples
|
### Examples
|
||||||
|
|
||||||
Let's walk through some examples of Python gRPC clients.
|
Let's walk through some examples of Python gRPC clients. These examples assume
|
||||||
|
that you have at least two `lnd` nodes running, the RPC location of one of which
|
||||||
|
is at the default `localhost:10009`, with an open channel between the two nodes.
|
||||||
|
|
||||||
#### Simple RPC
|
#### Simple RPC
|
||||||
|
|
||||||
@ -75,8 +81,19 @@ request = ln.InvoiceSubscription()
|
|||||||
for invoice in stub.SubscribeInvoices(request);
|
for invoice in stub.SubscribeInvoices(request);
|
||||||
print invoice
|
print invoice
|
||||||
```
|
```
|
||||||
Now, create an invoice for your node at `localhost:10009` and send a payment to
|
|
||||||
it. Your Python console should display the details of the recently satisfied
|
Now, create an invoice for your node at `localhost:10009`and send a payment to
|
||||||
|
it from another node.
|
||||||
|
```bash
|
||||||
|
$ lncli addinvoice --value=100
|
||||||
|
{
|
||||||
|
"r_hash": <R_HASH>,
|
||||||
|
"pay_req": <PAY_REQ>
|
||||||
|
}
|
||||||
|
$ lncli sendpayment --pay_req=<PAY_REQ>
|
||||||
|
```
|
||||||
|
|
||||||
|
Your Python console should now display the details of the recently satisfied
|
||||||
invoice.
|
invoice.
|
||||||
|
|
||||||
#### Bidirectional-streaming RPC
|
#### Bidirectional-streaming RPC
|
||||||
|
Loading…
Reference in New Issue
Block a user