Merge pull request #928 from adrienemery/python-docs

docs: encode macaroon in python grpc example
This commit is contained in:
Olaoluwa Osuntokun 2018-03-29 15:36:30 -07:00 committed by GitHub
commit 117441b7d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -138,11 +138,13 @@ This example will send a payment of 100 satoshis every 2 seconds.
To authenticate using macaroons you need to include the macaroon in the metadata of the request. To authenticate using macaroons you need to include the macaroon in the metadata of the request.
```python ```python
import codecs
# Lnd admin macaroon is at ~/.lnd/admin.macaroon on Linux and # Lnd admin macaroon is at ~/.lnd/admin.macaroon on Linux and
# ~/Library/Application Support/Lnd/admin.macaroon on Mac # ~/Library/Application Support/Lnd/admin.macaroon on Mac
with open('~/.lnd/admin.macaroon', 'rb') as f: with open(os.path.expanduser('~/.lnd/admin.macaroon'), 'rb') as f:
macaroon_bytes = f.read() macaroon_bytes = f.read()
macaroon = codecs.decode(macaroon_bytes, 'hex') macaroon = codecs.encode(macaroon_bytes, 'hex')
``` ```
The simplest approach to use the macaroon is to include the metadata in each request as shown below. The simplest approach to use the macaroon is to include the metadata in each request as shown below.
@ -156,7 +158,7 @@ However, this can get tiresome to do for each request, so to avoid explicitly in
```python ```python
def metadata_callback(context, callback): def metadata_callback(context, callback):
# for more info see grpc docs # for more info see grpc docs
callback([('macaroon', self.macaroon)], None) callback([('macaroon', macaroon)], None)
# build ssl credentials using the cert the same as before # build ssl credentials using the cert the same as before