forked from cdecker/lightning-integration
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lnd: Initial commit for lnd nodes and rpc
Unfortunately GRPC pulls in a lot of dependencies. Adding them to the repo so we don't have to jump through hoops to get them working.
- Loading branch information
Showing
8 changed files
with
6,825 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! | ||
import grpc | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT! | ||
import grpc | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
from utils import TailableProc | ||
import rpc_pb2_grpc as lnrpc_grpc | ||
import rpc_pb2 as lnrpc | ||
|
||
|
||
import grpc | ||
import logging | ||
import os | ||
import time | ||
|
||
|
||
class LndD(TailableProc): | ||
def __init__(self, lightning_dir, bitcoin_dir, port): | ||
TailableProc.__init__(self, lightning_dir) | ||
self.lightning_dir = lightning_dir | ||
self.bitcoin_dir = bitcoin_dir | ||
self.port = port | ||
self.rpc_port = str(10000 + port) | ||
self.prefix = 'lnd' | ||
|
||
self.cmd_line = [ | ||
'lnd/lnd', | ||
'--peerport={}'.format(self.port), | ||
'--rpcport={}'.format(self.rpc_port), | ||
'--bitcoin.active', | ||
'--datadir={}'.format(lightning_dir), | ||
'--debuglevel=trace', | ||
'--bitcoin.rpcuser=rpcuser', | ||
'--bitcoin.rpcpass=rpcpass', | ||
'--configfile={}'.format(os.path.join(lightning_dir, 'lnd.conf')), | ||
'--bitcoin.regtest', | ||
] | ||
|
||
if not os.path.exists(lightning_dir): | ||
os.makedirs(lightning_dir) | ||
with open(os.path.join(lightning_dir, "lnd.conf"), "w") as f: | ||
f.write("""[Application Options]\n""") | ||
|
||
def start(self): | ||
TailableProc.start(self) | ||
self.wait_for_log("Opened wallet") | ||
time.sleep(30) | ||
logging.info("LND started (pid: {})".format(self.proc.pid)) | ||
|
||
|
||
class LndNode(object): | ||
|
||
def __init__(self, lightning_dir, lightning_port, btc, executor=None, | ||
node_id=0): | ||
self.bitcoin = btc | ||
self.executor = executor | ||
self.daemon = LndD(lightning_dir, btc.bitcoin_dir, port=lightning_port) | ||
self.rpc = LndRpc(lightning_port) | ||
|
||
@property | ||
def id(self): | ||
while True: | ||
try: | ||
print(self.rpc.stub.GetInfo(lnrpc.GetInfoRequest())) | ||
except: | ||
time.sleep(1) | ||
pass | ||
|
||
class LndRpc(object): | ||
def __init__(self, rpc_port): | ||
print('localhost:{}'.format(rpc_port)) | ||
channel = grpc.insecure_channel('localhost:{}'.format(rpc_port)) | ||
self.stub = lnrpc_grpc.LightningStub(channel) | ||
|
||
def connect(self, host, port, node_id): | ||
logging.debug(self.stub.GetInfo(lnrpc.GetInfoRequest())) | ||
|
||
|
Oops, something went wrong.