mirror of
https://github.com/yzernik/squeaknode.git
synced 2026-08-16 13:01:04 +02:00
Implement get info method of c-lightning client
This commit is contained in:
parent
ecf677f570
commit
95032fb7e1
6 changed files with 121 additions and 9 deletions
21
docker/config-clightning.ini
Normal file
21
docker/config-clightning.ini
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
[node]
|
||||
network=testnet
|
||||
|
||||
[clightning]
|
||||
enabled=true
|
||||
|
||||
[bitcoin]
|
||||
rpc_host=bitcoin-core
|
||||
rpc_port=18332
|
||||
rpc_user=devuser
|
||||
rpc_pass=devpass
|
||||
zeromq_hashblock_port=28334
|
||||
|
||||
[tor]
|
||||
proxy_ip=tor-node
|
||||
proxy_port=9050
|
||||
|
||||
[webadmin]
|
||||
enabled=true
|
||||
username=devuser
|
||||
password=devpass
|
||||
|
|
@ -26,7 +26,20 @@ services:
|
|||
- --bitcoin-rpcpassword=devpass
|
||||
- --network=testnet
|
||||
- --plugin-dir=/usr/libexec/c-lightning/plugins
|
||||
- --alias=mydockernode
|
||||
- --alias=myclientningclient
|
||||
- --log-level=debug
|
||||
- --rpc-file=/root/.lightning/lightning-rpc
|
||||
- --rpc-file-mode=0777
|
||||
- --proxy=tor-node:9050
|
||||
|
||||
clightning_server:
|
||||
command:
|
||||
- --bitcoin-rpcconnect=bitcoin-core
|
||||
- --bitcoin-rpcuser=devuser
|
||||
- --bitcoin-rpcpassword=devpass
|
||||
- --network=testnet
|
||||
- --plugin-dir=/usr/libexec/c-lightning/plugins
|
||||
- --alias=myclientningserver
|
||||
- --log-level=debug
|
||||
- --rpc-file=/root/.lightning/lightning-rpc
|
||||
- --rpc-file-mode=0777
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ services:
|
|||
|
||||
clightning_client:
|
||||
image: elementsproject/lightningd:v0.11.0.1
|
||||
container_name: clightning
|
||||
container_name: clightning_client
|
||||
expose:
|
||||
- "9735"
|
||||
- "19735"
|
||||
|
|
@ -78,6 +78,24 @@ services:
|
|||
sysctls:
|
||||
- net.ipv6.conf.all.disable_ipv6=0
|
||||
|
||||
clightning_server:
|
||||
image: elementsproject/lightningd:v0.11.0.1
|
||||
container_name: clightning_server
|
||||
expose:
|
||||
- "9735"
|
||||
- "19735"
|
||||
- "9835"
|
||||
- "10009"
|
||||
volumes:
|
||||
- clightning_server_dir:/root/.lightning
|
||||
- tor-dir:/var/lib/tor
|
||||
links:
|
||||
- "bitcoin-core:bitcoin-core"
|
||||
depends_on:
|
||||
- "tor-node"
|
||||
sysctls:
|
||||
- net.ipv6.conf.all.disable_ipv6=0
|
||||
|
||||
tor-node:
|
||||
image: osminogin/tor-simple
|
||||
container_name: tor-node
|
||||
|
|
@ -110,10 +128,36 @@ services:
|
|||
- net.ipv6.conf.all.disable_ipv6=0
|
||||
entrypoint: ["./entrypoint.sh"]
|
||||
|
||||
squeaknode_clightning:
|
||||
image: squeaknode
|
||||
container_name: squeaknode_clightning
|
||||
build:
|
||||
context: ../
|
||||
dockerfile: Dockerfile
|
||||
depends_on:
|
||||
- "lnd_server"
|
||||
volumes:
|
||||
- clightning_server_dir:/root/.lightning
|
||||
- squeaknode_clightning_dir:/root/.sqk
|
||||
- ./config-clightning.ini:/config.ini
|
||||
ports:
|
||||
- 18558:18555
|
||||
- 12996:12994
|
||||
links:
|
||||
- "bitcoin-core:bitcoin-core"
|
||||
- "lnd_server:lnd"
|
||||
sysctls:
|
||||
- net.ipv6.conf.all.disable_ipv6=0
|
||||
entrypoint: ["./entrypoint.sh"]
|
||||
|
||||
volumes:
|
||||
lnd_server_dir:
|
||||
driver: local
|
||||
clightning_server_dir:
|
||||
driver: local
|
||||
squeaknode_dir:
|
||||
driver: local
|
||||
squeaknode_clightning_dir:
|
||||
driver: local
|
||||
tor-dir:
|
||||
driver: local
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
alembic==1.7.1
|
||||
docutils==0.17.1
|
||||
Flask==2.0.1
|
||||
flask-cors==3.0.10
|
||||
flask-login==0.5.0
|
||||
|
|
@ -7,7 +8,7 @@ googleapis-common-protos==1.53.0
|
|||
importlib_resources==1.4.0
|
||||
mypy-protobuf==2.9
|
||||
protobuf==3.17.3
|
||||
pyln-client==0.10.2.post3
|
||||
pyln-client==0.10.1
|
||||
PySocks==1.7.1
|
||||
python-bitcoinlib==0.11.0
|
||||
pyzmq==22.3.0
|
||||
|
|
|
|||
|
|
@ -259,6 +259,7 @@ class SqueakCore:
|
|||
"""
|
||||
info = self.lightning_client.get_info()
|
||||
for uri in info.uris:
|
||||
logger.info('uri: {}'.format(uri))
|
||||
pubkey, address = uri.split("@")
|
||||
host, port_str = address.split(":")
|
||||
port = int(port_str)
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@
|
|||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
import logging
|
||||
import time
|
||||
import uuid
|
||||
|
||||
from pyln.client import LightningRpc
|
||||
|
||||
|
|
@ -64,6 +66,20 @@ class CLightningClient(LightningClient):
|
|||
)
|
||||
|
||||
def get_info(self) -> Info:
|
||||
info = self.lrpc.getinfo()
|
||||
pubkey = info['id']
|
||||
binding = info.get('binding')
|
||||
logger.info(binding)
|
||||
uris = []
|
||||
if binding:
|
||||
for b in binding:
|
||||
address = b['address']
|
||||
if ':' not in address: # TODO: Change type of uri to LightningAddress.
|
||||
port = b['port']
|
||||
uri = f"{pubkey}@{address}:{port}"
|
||||
logger.info(uri)
|
||||
uris.append(uri)
|
||||
|
||||
# get_info_request = lnd_pb2.GetInfoRequest()
|
||||
# get_info_response = self.stub.GetInfo(
|
||||
# get_info_request,
|
||||
|
|
@ -72,7 +88,7 @@ class CLightningClient(LightningClient):
|
|||
# uris=get_info_response.uris,
|
||||
# )
|
||||
return Info(
|
||||
uris=[],
|
||||
uris=uris,
|
||||
)
|
||||
|
||||
def decode_pay_req(self, payment_request: str) -> PayReq:
|
||||
|
|
@ -93,6 +109,16 @@ class CLightningClient(LightningClient):
|
|||
# return self.stub.LookupInvoice(payment_hash)
|
||||
|
||||
def create_invoice(self, preimage: bytes, amount_msat: int) -> Invoice:
|
||||
logger.info('preimage: {}'.format(preimage.hex()))
|
||||
logger.info('amount msat: {}'.format(amount_msat))
|
||||
created_invoice = self.lrpc.invoice(
|
||||
amount_msat,
|
||||
label=str(uuid.uuid4()),
|
||||
description="Squeaknode invoice",
|
||||
preimage=preimage.hex(),
|
||||
)
|
||||
logger.info('created invoice: {}'.format(created_invoice))
|
||||
|
||||
# add_invoice_response = self.add_invoice(preimage, amount_msat)
|
||||
# payment_hash = add_invoice_response.r_hash
|
||||
# lookup_invoice_response = self.lookup_invoice(
|
||||
|
|
@ -107,14 +133,20 @@ class CLightningClient(LightningClient):
|
|||
# creation_date=lookup_invoice_response.creation_date,
|
||||
# expiry=lookup_invoice_response.expiry,
|
||||
# )
|
||||
|
||||
creation_time = int(time.time())
|
||||
expiry = int(created_invoice['expires_at']) - creation_time
|
||||
logger.info('creation_time: {}'.format(creation_time))
|
||||
logger.info('expiry: {}'.format(expiry))
|
||||
|
||||
return Invoice(
|
||||
r_hash=b'',
|
||||
payment_request='',
|
||||
value_msat=0,
|
||||
r_hash=bytes.fromhex(created_invoice['payment_hash']),
|
||||
payment_request=created_invoice['bolt11'],
|
||||
value_msat=amount_msat,
|
||||
settled=False,
|
||||
settle_index=0,
|
||||
creation_date=0,
|
||||
expiry=0,
|
||||
creation_date=creation_time,
|
||||
expiry=expiry,
|
||||
)
|
||||
|
||||
def subscribe_invoices(self, settle_index: int) -> InvoiceStream:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue