Skip to content

Commit 58c6e06

Browse files
committed
WIP: Implement python interfaces for rust-lightning-bitcoinrpc
1 parent a45312d commit 58c6e06

File tree

3 files changed

+105
-2
lines changed

3 files changed

+105
-2
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ jobs:
2929

3030
- name: 'Build rust-lightning-bitcoinrpc'
3131
script:
32-
- docker run lnintegration bash -c "make update-rust-lightning bin/rust-lightning-bitcoinrpc"
32+
- docker run lnintegration bash -c "make update-rust-lightning bin/rust-lightning-bitcoinrpc && py.test -v test.py -k RustLightningBitcoinrpcNode"

rustln.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
from utils import TailableProc, BITCOIND_CONFIG
2+
3+
import logging
4+
import os
5+
import time
6+
7+
class RustLightningBitcoinrpc(TailableProc):
8+
9+
def __init__(self, lightning_dir, bitcoind, port):
10+
TailableProc.__init__(self, lightning_dir)
11+
self.lightning_dir = lightning_dir
12+
self.bitcoind = bitcoind
13+
self.port = port
14+
self.cmd_line = [
15+
'bin/rust-lightning-bitcoinrpc',
16+
'-chain=regtest',
17+
'-p2pport={}'.format(port),
18+
'-datadir={}'.format(lightning_dir),
19+
'-rpcauth={}:{}'.format(BITCOIND_CONFIG['rpcuser'], BITCOIND_CONFIG['rpcpassword']),
20+
'-rpc_host=127.0.0.1:{}'.format(self.bitcoind.rpcport),
21+
]
22+
self.prefix = 'rust-lightning-bitcoinrpc'
23+
24+
if not os.path.exists(lightning_dir):
25+
os.makedirs(lightning_dir)
26+
27+
def start(self):
28+
TailableProc.start(self)
29+
# self.wait_for_log("Started interactive shell! Commands:")
30+
time.sleep(5)
31+
logging.info("Success! Starting up...")
32+
33+
def stop(self):
34+
TailableProc.stop(self)
35+
logging.info("RustLightningBitcoinrpc stopped")
36+
37+
38+
class RustLightningBitcoinrpcNode(object):
39+
40+
displayName = 'rust-lightning-bitcoinrpc'
41+
42+
def __init__(self, lightning_dir, lightning_port, btc, executor=None, node_id=0):
43+
self.bitcoin = btc
44+
self.executor = executor
45+
self.daemon = RustLightningBitcoinrpc(lightning_dir, self.bitcoin, port=lightning_port)
46+
47+
# TODO rust-lightning-bitcoinrpc doesn't havean rpc interface, it just takes commands directly on the command line when running
48+
49+
def id(self):
50+
pass
51+
52+
def ping(self):
53+
pass
54+
55+
def peers(self):
56+
pass
57+
58+
def check_channel(self, remote):
59+
pass
60+
61+
def addfunds(self, bitcoind, satoshis):
62+
pass
63+
64+
def openchannel(self, node_id, host, port, satoshis):
65+
pass
66+
67+
def getchannels(self):
68+
pass
69+
70+
def getnodes(self):
71+
pass
72+
73+
def invoice(self, amount):
74+
pass
75+
76+
def send(self, bolt11):
77+
pass
78+
79+
def connect(self, host, port, node_id):
80+
pass
81+
82+
def info(self):
83+
pass
84+
85+
def block_sync(self, blockhash):
86+
print("Waiting for node to learn about", blockhash)
87+
self.daemon.wait_for_log('NTFN: New block: height=([0-9]+), sha={}'.format(blockhash))
88+
89+
def restart(self):
90+
self.daemon.stop()
91+
time.sleep(5)
92+
self.daemon.start()
93+
time.sleep(1)
94+
95+
def stop(self):
96+
self.daemon.stop()
97+
98+
def start(self):
99+
self.daemon.start()
100+
101+
def check_route(self, node_id, amount):
102+
pass

test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from lnaddr import lndecode
99
from lnd import LndNode
1010
from ptarmd import PtarmNode
11+
from rustln import RustLightningBitcoinrpcNode
1112
from concurrent import futures
1213
from utils import BitcoinD, BtcD
1314
from bech32 import bech32_decode
@@ -21,7 +22,7 @@
2122
import tempfile
2223
import time
2324

24-
impls = [EclairNode, LightningNode, LndNode, PtarmNode]
25+
impls = [EclairNode, LightningNode, LndNode, PtarmNode, RustLightningBitcoinrpcNode]
2526

2627
if TEST_DEBUG:
2728
logging.basicConfig(level=logging.DEBUG, stream=sys.stdout)

0 commit comments

Comments
 (0)