|
| 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 |
0 commit comments