mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-20 18:44:20 +01:00
add http proxy option to wallet (#269)
This commit is contained in:
@@ -8,12 +8,12 @@ CASHU_DIR=~/.cashu
|
||||
MINT_HOST=127.0.0.1
|
||||
MINT_PORT=3338
|
||||
|
||||
# use builtin tor, this overrides SOCKS_HOST and SOCKS_PORT
|
||||
# use builtin tor, this overrides SOCKS_PROXY, HTTP_PROXY
|
||||
TOR=TRUE
|
||||
|
||||
# use custom tor proxy, this will only work with TOR=false
|
||||
#SOCKS_HOST=localhost
|
||||
#SOCKS_PORT=9050
|
||||
# use custom proxy, this will only work with TOR=false
|
||||
#SOCKS_PROXY=socks5://localhost:9050
|
||||
#HTTP_PROXY=http://localhost:8088
|
||||
|
||||
# NOSTR
|
||||
# nostr private key to which to receive tokens to
|
||||
|
||||
@@ -75,8 +75,10 @@ class MintInformation(CashuSettings):
|
||||
class WalletSettings(CashuSettings):
|
||||
lightning: bool = Field(default=True)
|
||||
tor: bool = Field(default=True)
|
||||
socks_host: str = Field(default=None)
|
||||
socks_port: int = Field(default=9050)
|
||||
socks_host: str = Field(default=None) # deprecated
|
||||
socks_port: int = Field(default=9050) # deprecated
|
||||
socks_proxy: str = Field(default=None)
|
||||
http_proxy: str = Field(default=None)
|
||||
mint_url: str = Field(default=None)
|
||||
mint_host: str = Field(default="8333.space")
|
||||
mint_port: int = Field(default=3338)
|
||||
@@ -128,5 +130,9 @@ def startup_settings_tasks():
|
||||
else:
|
||||
settings.mint_url = f"https://{settings.mint_host}:{settings.mint_port}"
|
||||
|
||||
# backwards compatibility: set socks_proxy from socks_host and socks_port
|
||||
if settings.socks_host and settings.socks_port:
|
||||
settings.socks_proxy = f"socks5://{settings.socks_host}:{settings.socks_port}"
|
||||
|
||||
|
||||
startup_settings_tasks()
|
||||
|
||||
@@ -405,10 +405,6 @@ async def info():
|
||||
else:
|
||||
nostr_public_key = None
|
||||
nostr_relays = []
|
||||
if settings.socks_host:
|
||||
socks_proxy = settings.socks_host + ":" + str(settings.socks_host)
|
||||
else:
|
||||
socks_proxy = None
|
||||
return InfoResponse(
|
||||
version=settings.version,
|
||||
wallet=wallet.name,
|
||||
@@ -419,5 +415,5 @@ async def info():
|
||||
tor=settings.tor,
|
||||
nostr_public_key=nostr_public_key,
|
||||
nostr_relays=nostr_relays,
|
||||
socks_proxy=socks_proxy,
|
||||
socks_proxy=settings.socks_proxy,
|
||||
)
|
||||
|
||||
@@ -642,8 +642,10 @@ async def info(ctx: Context, mint: bool):
|
||||
print(f"Nostr relays: {settings.nostr_relays}")
|
||||
except:
|
||||
print(f"Nostr: Error. Invalid key.")
|
||||
if settings.socks_host:
|
||||
print(f"Socks proxy: {settings.socks_host}:{settings.socks_port}")
|
||||
if settings.socks_proxy:
|
||||
print(f"Socks proxy: {settings.socks_proxy}")
|
||||
if settings.http_proxy:
|
||||
print(f"HTTP proxy: {settings.http_proxy}")
|
||||
print(f"Mint URL: {ctx.obj['HOST']}")
|
||||
if mint:
|
||||
wallet: Wallet = ctx.obj["WALLET"]
|
||||
|
||||
@@ -6,7 +6,7 @@ import secrets as scrts
|
||||
import time
|
||||
import uuid
|
||||
from itertools import groupby
|
||||
from typing import Dict, List, Optional, Tuple
|
||||
from typing import Dict, List, Optional, Tuple, Union
|
||||
|
||||
import requests
|
||||
from loguru import logger
|
||||
@@ -75,20 +75,21 @@ def async_set_requests(func):
|
||||
self.s.headers.update({"Client-version": settings.version})
|
||||
if settings.debug:
|
||||
self.s.verify = False
|
||||
socks_host, socks_port = None, None
|
||||
|
||||
# set proxy
|
||||
proxy_url: Union[str, None] = None
|
||||
if settings.tor and TorProxy().check_platform():
|
||||
self.tor = TorProxy(timeout=True)
|
||||
self.tor.run_daemon(verbose=True)
|
||||
socks_host, socks_port = "localhost", 9050
|
||||
else:
|
||||
socks_host, socks_port = settings.socks_host, settings.socks_port
|
||||
proxy_url = f"socks5://localhost:9050"
|
||||
elif settings.socks_proxy:
|
||||
proxy_url = f"socks5://{settings.socks_proxy}"
|
||||
elif settings.http_proxy:
|
||||
proxy_url = settings.http_proxy
|
||||
if proxy_url:
|
||||
self.s.proxies.update({"http": proxy_url})
|
||||
self.s.proxies.update({"https": proxy_url})
|
||||
|
||||
if socks_host and socks_port:
|
||||
proxies = {
|
||||
"http": f"socks5://{socks_host}:{socks_port}",
|
||||
"https": f"socks5://{socks_host}:{socks_port}",
|
||||
}
|
||||
self.s.proxies.update(proxies)
|
||||
self.s.headers.update({"User-Agent": scrts.token_urlsafe(8)})
|
||||
return await func(self, *args, **kwargs)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user