Skip to content

Commit

Permalink
Add lighning call for cyphernode v0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomtibo committed Jun 10, 2020
1 parent bb7ef3c commit 8e9855c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ Command not working:

- Add more security for storing the configuration file data
- Fix not working things
- Make request more low level. Use socket not requests lib
- Add `CypherApp` for running code as a cypherapps using mqtt
- Add error handling
- Add logging
Expand Down
7 changes: 6 additions & 1 deletion autocomplete.bash
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ ln_connectfund
conf
newblock
executecallbacks
ots_backoffice""" cn cnt cnm cn-cli
ots_backoffice
ln_listpeers
ln_listfunds
ln_listpays
ln_delinvoice
ln_withdraw""" cn cnt cnm cn-cli
54 changes: 49 additions & 5 deletions libcn/libcn.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@ def __init__(self, \
'watchtxid', 'getactivewatches', 'get_txns_by_watchlabel',\
'get_unused_addresses_by_watchlabel', 'getbestblockhash', \
'getbestblockinfo', 'getblockinfo', 'gettransaction',\
'ln_getinfo', 'ln_create_invoice', 'ln_getconnectionstring', 'ln_decodebolt11']
'ln_getinfo', 'ln_create_invoice', 'ln_getconnectionstring', \
'ln_decodebolt11', 'ln_listpeers', 'ln_listfunds', 'ln_listpays']
self.spender_cmd = ['gettxnslist', 'getbalance', 'getbalances', \
'getbalancebyxpub', 'getbalancebyxpublabel', 'getnewaddress',\
'spend', 'bumpfee', 'addtobatch', 'batchspend', 'deriveindex', \
'derivexpubpath', 'ln_pay', 'ln_newaddr', 'ots_stamp',\
'ots_getfile', 'ln_getinvoice', 'ln_decodebolt11', 'ln_connectfund']
'ots_getfile', 'ln_getinvoice', 'ln_decodebolt11', 'ln_connectfund', \
'ln_delinvoice', 'ln_withdraw']
self.admin_cmd = ['conf', 'newblock', 'executecallbacks', 'ots_backoffice']
self.all_cmd = []
for itm in self.stats_cmd, self.watcher_cmd, self.spender_cmd: #, self.admin_cmd:
Expand Down Expand Up @@ -74,7 +76,7 @@ def __init__(self, \
elif self.cnid == '000':
for itm in self.stats_cmd:
self.auth.append(itm)
except ConnectionRefusedError:
except ConnectionError:
print('Authentification failed !')
return None
self.req = ['endpoint', 'headers=headers']
Expand Down Expand Up @@ -137,7 +139,7 @@ def get_data(self, call, endpoint):
else:
return None
else:
raise ConnectionRefusedError
raise ConnectionError
def post_data(self, call, endpoint, payload):
"""Post data request"""
if call in self.auth:
Expand All @@ -150,7 +152,7 @@ def post_data(self, call, endpoint, payload):
else:
return None
else:
raise ConnectionRefusedError
raise ConnectionError
# Get requests
def getblockchaininfo(self):
"""Get blockchain information"""
Expand Down Expand Up @@ -206,6 +208,24 @@ def ln_newaddr(self):
endpoint = "{}/{}".format(self.url, call)
response = self.get_data(call, endpoint)
return response
def ln_listpeers(self):
"""Get a list of lighning peers"""
call = 'ln_listpeers'
endpoint = "{}/{}".format(self.url, call)
response = self.get_data(call, endpoint)
return response
def ln_listfunds(self):
"""Get a list of funds"""
call = 'ln_listfunds'
endpoint = "{}/{}".format(self.url, call)
response = self.get_data(call, endpoint)
return response
def ln_listpays(self):
"""Get a list of payed invoice"""
call = 'ln_listpays'
endpoint = "{}/{}".format(self.url, call)
response = self.get_data(call, endpoint)
return response
def gettxnslist(self):################
"""Not working right now"""
call = 'gettxnslist'
Expand Down Expand Up @@ -246,6 +266,15 @@ def getnewaddress(self, *typeid):
endpoint = "{}/{}".format(self.url, call)
response = self.get_data(call, endpoint)
return response
def ln_getroute(self, nodeid, msatoshi, *risk):
"""Get lighning node route"""
call = 'ln_getroute'
if risk:
endpoint = "{}/{}/{}/{}/{}".format(self.url, call, nodeid, msatoshi, risk)
else:
endpoint = "{}/{}/{}/{}".format(self.url, call, nodeid, msatoshi)
response = self.get_data(call, endpoint)
return response
# Get request with argument(s)
def getblockhash(self):
"hashing"
Expand Down Expand Up @@ -337,6 +366,12 @@ def ln_getinvoice(self, label):
endpoint = "{}/{}/{}".format(self.url, call, label)
response = self.get_data(call, endpoint)
return response
def ln_delinvoice(self, label):
"label"
call = 'ln_delinvoice'
endpoint = "{}/{}/{}".format(self.url, call, label)
response = self.get_data(call, endpoint)
return response
# Post requests
def watch(self, address, cburl0=None, cburl1=None, emsg=None):
"""address [unconfirmedCallbackURL confirmedCallbackURL eventMessage]"""
Expand Down Expand Up @@ -416,6 +451,15 @@ def ln_pay(self, bolt11, expected_msatoshi, expected_description):
payload = json.dumps(payload)
response = self.post_data(call, endpoint, payload)
return response
def ln_withdraw(self, address, satoshi=None, feerate="normal", withdrawall="false"):
"""Withdraw lightning node to a bitcoin address"""
call = 'ln_withdraw'
endpoint = "{}/{}".format(self.url, call)
payload = {"destination":address, "satoshi":satoshi, \
"feerate":feerate, "all":withdrawall}
payload = json.dumps(payload)
response = self.post_data(call, endpoint, payload)
return response
def ln_connectfund(self, url, msatoshi, cburl=None):
"""peer msatoshi [callbackUrl]"""
call = 'ln_connectfund'
Expand Down

0 comments on commit 8e9855c

Please sign in to comment.