fix: no logs
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import subprocess
|
import subprocess
|
||||||
from collections.abc import AsyncGenerator
|
from collections.abc import AsyncGenerator
|
||||||
@@ -44,13 +45,23 @@ class LightsparkSparkWallet(Wallet):
|
|||||||
self._status = "Initializing"
|
self._status = "Initializing"
|
||||||
self._sidecar_path = Path(settings.lnbits_data_folder, "light_spark")
|
self._sidecar_path = Path(settings.lnbits_data_folder, "light_spark")
|
||||||
self.pending_invoices: list[str] = []
|
self.pending_invoices: list[str] = []
|
||||||
|
|
||||||
self.endpoint = normalize_endpoint(cast(str, settings.spark_l2_endpoint))
|
self.endpoint = normalize_endpoint(cast(str, settings.spark_l2_endpoint))
|
||||||
|
self.network = "MAINNET"
|
||||||
|
self.pay_wait_ms = 20000
|
||||||
|
self.mnemonic = (
|
||||||
|
"garage soldier inch broccoli"
|
||||||
|
" prize owner build dignity slam embark mouse drill"
|
||||||
|
)
|
||||||
|
|
||||||
api_key = settings.spark_l2_api_key
|
api_key = settings.spark_l2_api_key
|
||||||
headers = {"User-Agent": settings.user_agent}
|
headers = {"User-Agent": settings.user_agent}
|
||||||
if api_key:
|
if api_key:
|
||||||
headers["X-Api-Key"] = api_key
|
headers["X-Api-Key"] = api_key
|
||||||
|
|
||||||
self.sidecar_task = asyncio.create_task(self._start_sidecar())
|
self.sidecar_task = asyncio.create_task(self._start_sidecar())
|
||||||
|
print("###" \
|
||||||
|
" after side car start")
|
||||||
|
|
||||||
self.client = httpx.AsyncClient(
|
self.client = httpx.AsyncClient(
|
||||||
base_url=self.endpoint,
|
base_url=self.endpoint,
|
||||||
@@ -60,11 +71,11 @@ class LightsparkSparkWallet(Wallet):
|
|||||||
|
|
||||||
async def _start_sidecar(self):
|
async def _start_sidecar(self):
|
||||||
logger.info("Starting Spark sidecar")
|
logger.info("Starting Spark sidecar")
|
||||||
npm_path = shutil.which("npm")
|
node_path = shutil.which("node")
|
||||||
if not npm_path:
|
if not node_path:
|
||||||
logger.error("npm not found in PATH, cannot start Spark sidecar")
|
logger.error("Node.js not found in PATH, cannot start Spark sidecar")
|
||||||
return
|
return
|
||||||
logger.info(f"npm found: {npm_path}")
|
logger.info(f"Node.js found: {node_path}")
|
||||||
|
|
||||||
repo, branch = "spark_sidecar", "main"
|
repo, branch = "spark_sidecar", "main"
|
||||||
|
|
||||||
@@ -87,45 +98,64 @@ class LightsparkSparkWallet(Wallet):
|
|||||||
else:
|
else:
|
||||||
logger.info("Spark sidecar already downloaded.")
|
logger.info("Spark sidecar already downloaded.")
|
||||||
|
|
||||||
|
print("### Checking Spark sidecar npm dependencies", Path(self._sidecar_path, node_modules_path, "node_modules"))
|
||||||
if not Path(self._sidecar_path, node_modules_path, "node_modules").is_dir():
|
if not Path(self._sidecar_path, node_modules_path, "node_modules").is_dir():
|
||||||
|
logger.debug("Installing Spark sidecar npm dependencies")
|
||||||
|
npm_path = shutil.which("npm")
|
||||||
|
if not npm_path:
|
||||||
|
logger.error("npm not found in PATH, cannot start Spark sidecar")
|
||||||
|
return
|
||||||
|
logger.info(f"npm found: {npm_path}")
|
||||||
|
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
["npm", "install"],
|
[npm_path, "install"],
|
||||||
cwd=str(node_modules_path),
|
cwd=str(node_modules_path),
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
text=True,
|
text=True,
|
||||||
check=True, # raises an exception if npm fails
|
check=True, # raises an exception if npm fails
|
||||||
)
|
)
|
||||||
|
logger.debug("Spark sidecar npm dependencies installed")
|
||||||
print("### npm install output:")
|
print("### npm install output:")
|
||||||
print(result.stdout)
|
print(result.stdout)
|
||||||
print(result.stderr)
|
print(result.stderr)
|
||||||
|
|
||||||
print("### Starting Spark sidecar node server")
|
print("### Starting Spark sidecar node server")
|
||||||
|
|
||||||
|
# env = os.environ.copy()
|
||||||
|
env = {}
|
||||||
|
env["SPARK_NETWORK"] = self.network
|
||||||
|
env["SPARK_PAY_WAIT_MS"] = str(self.pay_wait_ms)
|
||||||
|
env["SPARK_MNEMONIC"] = self.mnemonic
|
||||||
|
|
||||||
# result = subprocess.run(
|
# result = subprocess.run(
|
||||||
# ["node", "server.mjs"],
|
# ["node", "server.mjs"],
|
||||||
# cwd=str(node_modules_path),
|
# cwd=str(node_modules_path),
|
||||||
# capture_output=True,
|
# # capture_output=True,
|
||||||
# text=True,
|
# text=True,
|
||||||
# # check=True, # raises an exception if node fails
|
# check=True, # raises an exception if node fails
|
||||||
|
# env=env,
|
||||||
# )
|
# )
|
||||||
|
|
||||||
# print("### Spark sidecar output:")
|
print("### Spark sidecar output:")
|
||||||
# print(result.stdout)
|
# print(result.stdout)
|
||||||
# print(result.stderr)
|
# print(result.stderr)
|
||||||
|
|
||||||
process = subprocess.Popen(
|
process = subprocess.Popen(
|
||||||
["node", "server.mjs"],
|
[node_path, "server.mjs"],
|
||||||
|
env=env,
|
||||||
cwd=str(node_modules_path),
|
cwd=str(node_modules_path),
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
text=True
|
text=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
if process.stdout:
|
print("### Spark sidecar DONE")
|
||||||
for line in process.stdout:
|
|
||||||
logger.info(f"Spark: {line}", end="")
|
# if process.stdout:
|
||||||
else:
|
# for line in process.stdout:
|
||||||
logger.warning(" No output captured for Spark sidecar.")
|
# logger.info(f"Spark: {line}", end="")
|
||||||
|
# else:
|
||||||
|
# logger.warning(" No output captured for Spark sidecar.")
|
||||||
|
|
||||||
async def cleanup(self):
|
async def cleanup(self):
|
||||||
try:
|
try:
|
||||||
|
|||||||
Reference in New Issue
Block a user