mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-20 02:24:20 +01:00
works
This commit is contained in:
@@ -106,7 +106,7 @@ cashu info
|
|||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
```bash
|
```bash
|
||||||
Version: 0.4.3
|
Version: 0.5.0
|
||||||
Debug: False
|
Debug: False
|
||||||
Cashu dir: /home/user/.cashu
|
Cashu dir: /home/user/.cashu
|
||||||
Wallet: wallet
|
Wallet: wallet
|
||||||
|
|||||||
@@ -53,4 +53,4 @@ LNBITS_ENDPOINT = env.str("LNBITS_ENDPOINT", default=None)
|
|||||||
LNBITS_KEY = env.str("LNBITS_KEY", default=None)
|
LNBITS_KEY = env.str("LNBITS_KEY", default=None)
|
||||||
|
|
||||||
MAX_ORDER = 64
|
MAX_ORDER = 64
|
||||||
VERSION = "0.4.3"
|
VERSION = "0.5.0"
|
||||||
|
|||||||
@@ -91,15 +91,21 @@ class TorProxy:
|
|||||||
# current attached process running
|
# current attached process running
|
||||||
return self.tor_proc and self.tor_proc.poll() is None
|
return self.tor_proc and self.tor_proc.poll() is None
|
||||||
|
|
||||||
def wait_until_startup(self):
|
def wait_until_startup(self, verbose=False):
|
||||||
if self.is_port_open():
|
if self.is_port_open():
|
||||||
return
|
return
|
||||||
if self.tor_proc is None:
|
if self.tor_proc is None:
|
||||||
raise Exception("Tor proxy not attached.")
|
raise Exception("Tor proxy not attached.")
|
||||||
if not self.tor_proc.stdout:
|
if not self.tor_proc.stdout:
|
||||||
raise Exception("could not get tor stdout.")
|
raise Exception("could not get tor stdout.")
|
||||||
|
if verbose:
|
||||||
|
print("Starting Tor...", end="", flush=True)
|
||||||
for line in self.tor_proc.stdout:
|
for line in self.tor_proc.stdout:
|
||||||
|
if verbose:
|
||||||
|
print(".", end="", flush=True)
|
||||||
if "Bootstrapped 100%: Done" in str(line):
|
if "Bootstrapped 100%: Done" in str(line):
|
||||||
|
if verbose:
|
||||||
|
print("done.", flush=True)
|
||||||
break
|
break
|
||||||
# tor is ready
|
# tor is ready
|
||||||
self.startup_finished = True
|
self.startup_finished = True
|
||||||
|
|||||||
@@ -58,14 +58,13 @@ class LedgerAPI:
|
|||||||
|
|
||||||
def __init__(self, url):
|
def __init__(self, url):
|
||||||
self.url = url
|
self.url = url
|
||||||
self.s = self._set_requests()
|
|
||||||
self.s.headers.update({"Client-version": VERSION})
|
|
||||||
|
|
||||||
def _set_requests(self):
|
def _set_requests(self):
|
||||||
s = requests.Session()
|
s = requests.Session()
|
||||||
|
s.headers.update({"Client-version": VERSION})
|
||||||
if TOR:
|
if TOR:
|
||||||
tor = TorProxy(keep_alive=True)
|
tor = TorProxy(keep_alive=True)
|
||||||
tor.wait_until_startup()
|
tor.wait_until_startup(verbose=True)
|
||||||
socks_host, socks_port = "localhost", 9050
|
socks_host, socks_port = "localhost", 9050
|
||||||
else:
|
else:
|
||||||
socks_host, socks_port = SOCKS_HOST, SOCKS_PORT
|
socks_host, socks_port = SOCKS_HOST, SOCKS_PORT
|
||||||
@@ -77,7 +76,6 @@ class LedgerAPI:
|
|||||||
}
|
}
|
||||||
s.proxies.update(proxies)
|
s.proxies.update(proxies)
|
||||||
s.headers.update({"User-Agent": scrts.token_urlsafe(8)})
|
s.headers.update({"User-Agent": scrts.token_urlsafe(8)})
|
||||||
|
|
||||||
return s
|
return s
|
||||||
|
|
||||||
def _construct_proofs(
|
def _construct_proofs(
|
||||||
@@ -174,6 +172,7 @@ class LedgerAPI:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
async def _get_keys(self, url):
|
async def _get_keys(self, url):
|
||||||
|
self.s = self._set_requests()
|
||||||
resp = self.s.get(
|
resp = self.s.get(
|
||||||
url + "/keys",
|
url + "/keys",
|
||||||
)
|
)
|
||||||
@@ -188,6 +187,7 @@ class LedgerAPI:
|
|||||||
return keyset
|
return keyset
|
||||||
|
|
||||||
async def _get_keysets(self, url):
|
async def _get_keysets(self, url):
|
||||||
|
self.s = self._set_requests()
|
||||||
resp = self.s.get(
|
resp = self.s.get(
|
||||||
url + "/keysets",
|
url + "/keysets",
|
||||||
)
|
)
|
||||||
@@ -198,6 +198,7 @@ class LedgerAPI:
|
|||||||
|
|
||||||
def request_mint(self, amount):
|
def request_mint(self, amount):
|
||||||
"""Requests a mint from the server and returns Lightning invoice."""
|
"""Requests a mint from the server and returns Lightning invoice."""
|
||||||
|
self.s = self._set_requests()
|
||||||
resp = self.s.get(self.url + "/mint", params={"amount": amount})
|
resp = self.s.get(self.url + "/mint", params={"amount": amount})
|
||||||
resp.raise_for_status()
|
resp.raise_for_status()
|
||||||
return_dict = resp.json()
|
return_dict = resp.json()
|
||||||
@@ -209,7 +210,7 @@ class LedgerAPI:
|
|||||||
secrets = [self._generate_secret() for s in range(len(amounts))]
|
secrets = [self._generate_secret() for s in range(len(amounts))]
|
||||||
await self._check_used_secrets(secrets)
|
await self._check_used_secrets(secrets)
|
||||||
payloads, rs = self._construct_outputs(amounts, secrets)
|
payloads, rs = self._construct_outputs(amounts, secrets)
|
||||||
|
self.s = self._set_requests()
|
||||||
resp = self.s.post(
|
resp = self.s.post(
|
||||||
self.url + "/mint",
|
self.url + "/mint",
|
||||||
json=payloads.dict(),
|
json=payloads.dict(),
|
||||||
@@ -265,6 +266,7 @@ class LedgerAPI:
|
|||||||
"proofs": {i: proofs_include for i in range(len(proofs))},
|
"proofs": {i: proofs_include for i in range(len(proofs))},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.s = self._set_requests()
|
||||||
resp = self.s.post(
|
resp = self.s.post(
|
||||||
self.url + "/split",
|
self.url + "/split",
|
||||||
json=split_payload.dict(include=_splitrequest_include_fields(proofs)),
|
json=split_payload.dict(include=_splitrequest_include_fields(proofs)),
|
||||||
@@ -297,6 +299,7 @@ class LedgerAPI:
|
|||||||
"proofs": {i: {"secret"} for i in range(len(proofs))},
|
"proofs": {i: {"secret"} for i in range(len(proofs))},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.s = self._set_requests()
|
||||||
resp = self.s.post(
|
resp = self.s.post(
|
||||||
self.url + "/check",
|
self.url + "/check",
|
||||||
json=payload.dict(include=_check_spendable_include_fields(proofs)),
|
json=payload.dict(include=_check_spendable_include_fields(proofs)),
|
||||||
@@ -309,6 +312,7 @@ class LedgerAPI:
|
|||||||
async def check_fees(self, payment_request: str):
|
async def check_fees(self, payment_request: str):
|
||||||
"""Checks whether the Lightning payment is internal."""
|
"""Checks whether the Lightning payment is internal."""
|
||||||
payload = CheckFeesRequest(pr=payment_request)
|
payload = CheckFeesRequest(pr=payment_request)
|
||||||
|
self.s = self._set_requests()
|
||||||
resp = self.s.post(
|
resp = self.s.post(
|
||||||
self.url + "/checkfees",
|
self.url + "/checkfees",
|
||||||
json=payload.dict(),
|
json=payload.dict(),
|
||||||
@@ -333,6 +337,7 @@ class LedgerAPI:
|
|||||||
"proofs": {i: proofs_include for i in range(len(proofs))},
|
"proofs": {i: proofs_include for i in range(len(proofs))},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
self.s = self._set_requests()
|
||||||
resp = self.s.post(
|
resp = self.s.post(
|
||||||
self.url + "/melt",
|
self.url + "/melt",
|
||||||
json=payload.dict(include=_meltequest_include_fields(proofs)),
|
json=payload.dict(include=_meltequest_include_fields(proofs)),
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "cashu"
|
name = "cashu"
|
||||||
version = "0.4.3"
|
version = "0.5.0"
|
||||||
description = "Ecash wallet and mint."
|
description = "Ecash wallet and mint."
|
||||||
authors = ["calle <callebtc@protonmail.com>"]
|
authors = ["calle <callebtc@protonmail.com>"]
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
|||||||
2
setup.py
2
setup.py
@@ -13,7 +13,7 @@ entry_points = {"console_scripts": ["cashu = cashu.wallet.cli:cli"]}
|
|||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="cashu",
|
name="cashu",
|
||||||
version="0.4.3",
|
version="0.5.0",
|
||||||
description="Ecash wallet and mint with Bitcoin Lightning support",
|
description="Ecash wallet and mint with Bitcoin Lightning support",
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
|
|||||||
Reference in New Issue
Block a user