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