Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: export the public API of the package #225

Merged
merged 4 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
target

# tools ignores
tools/pylampo/pylampo_client/__pycache__
10 changes: 10 additions & 0 deletions tools/pylampo/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
CC=python3
FMT=black

default: fmt

fmt:
$(FMT) .

check:
pytest . --log-cli-level=DEBUG
148 changes: 148 additions & 0 deletions tools/pylampo/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tools/pylampo/pylampo_client/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__version__ = "0.1.0"

from .client import LampoClient
11 changes: 10 additions & 1 deletion tools/pylampo/pylampo_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ def call(self, method: str, params: dict = None) -> dict:
break
response += data.decode()

return json.loads(response)
# ad this point of the execution the response looks like
# the following one
# `{'result': {'node_id': '03f37129559621cbb4f8f4d4be5dff76ec21c220d7d274a6407683eafb996d97ae', 'peers': 0, 'channels': 0, 'chain': 'regtest', 'alias': '', 'blockheight': 101, 'lampo_dir': '/tmp/lnpt-lampo-2wi7vr28/lampo'}, 'error': None, 'id': 'pylampo-client/1', 'jsonrpc': '2.0'}`
response = json.loads(response)
if "result" in response:
return response["result"]
elif "error" in response:
raise Exception(f"{response['error']}")
else:
raise Exception("Invalid JSON RPC 2.0 response: `{response}`")
except Exception as e:
raise Exception(f"Error communicating with Lampo client: {e}")
3 changes: 2 additions & 1 deletion tools/pylampo/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ description = "A simple Lampo client that communicates via a Unix socket"
authors = ["Tarek <[email protected]>"]

[tool.poetry.dependencies]
python = "^3.7"
python = "^3.8"
black = "^24.4.2"


[build-system]
Expand Down
Loading