fix: use mint url for check

This commit is contained in:
callebtc
2022-12-26 21:00:30 +01:00
parent eabe19e675
commit 9d5dbc97d5
3 changed files with 16 additions and 13 deletions

View File

@@ -73,7 +73,7 @@ class NaturalOrderGroup(click.Group):
@click.pass_context @click.pass_context
def cli(ctx, host: str, walletname: str): def cli(ctx, host: str, walletname: str):
if TOR and not TorProxy().check_platform(): if TOR and not TorProxy().check_platform():
error_str = "Your settings say TOR=true but the built-in Tor bundle is not supported on your system. Please install Tor manually and set TOR=false and SOCKS_HOST=localhost and SOCKS_PORT=9050 in your Cashu config (recommended) or turn off Tor by setting TOR=false (not recommended). Cashu will not work until you edit your config file accordingly." error_str = "Your settings say TOR=true but the built-in Tor bundle is not supported on your system. You have two options: Either install Tor manually and set TOR=FALSE and SOCKS_HOST=localhost and SOCKS_PORT=9050 in your Cashu config (recommended). Or turn off Tor by setting TOR=false (not recommended). Cashu will not work until you edit your config file accordingly."
error_str += "\n\n" error_str += "\n\n"
if ENV_FILE: if ENV_FILE:
error_str += f"Edit your Cashu config file here: {ENV_FILE}" error_str += f"Edit your Cashu config file here: {ENV_FILE}"
@@ -83,7 +83,7 @@ def cli(ctx, host: str, walletname: str):
f"Ceate a new Cashu config file here: {os.path.join(CASHU_DIR, '.env')}" f"Ceate a new Cashu config file here: {os.path.join(CASHU_DIR, '.env')}"
) )
env_path = os.path.join(CASHU_DIR, ".env") env_path = os.path.join(CASHU_DIR, ".env")
error_str += f'\n\nYou can turn off Tor with this command: echo "TOR=false" >> {env_path}' error_str += f'\n\nYou can turn off Tor with this command: echo "TOR=FALSE" >> {env_path}'
raise Exception(error_str) raise Exception(error_str)
# configure logger # configure logger
@@ -203,13 +203,14 @@ async def balance(ctx, verbose):
print("") print("")
for k, v in keyset_balances.items(): for k, v in keyset_balances.items():
print( print(
f"Keyset: {k or 'undefined'} - Balance: {v['available']} sat (with pending: {v['balance']} sat)" f"Keyset: {k} - Balance: {v['available']} sat (pending: {v['balance']-v['available']} sat)"
) )
print("") print("")
# get balances per mint
mint_balances = await wallet.balance_per_minturl() mint_balances = await wallet.balance_per_minturl()
# if we have a balance on a non-default mint # if we have a balance on a non-default mint, we show its URL
show_mints = False show_mints = False
keysets = [k for k, v in wallet.balance_per_keyset().items()] keysets = [k for k, v in wallet.balance_per_keyset().items()]
for k in keysets: for k in keysets:
@@ -224,13 +225,13 @@ async def balance(ctx, verbose):
print("") print("")
for k, v in mint_balances.items(): for k, v in mint_balances.items():
print( print(
f"Mint: {k or 'undefined'} - Balance: {v['available']} sat (with pending: {v['balance']} sat)" f"Mint: {k} - Balance: {v['available']} sat (pending: {v['balance']-v['available']} sat)"
) )
print("") print("")
if verbose: if verbose:
print( print(
f"Balance: {wallet.balance} sat (available: {wallet.available_balance} sat in {len([p for p in wallet.proofs if not p.reserved])} tokens)" f"Balance: {wallet.available_balance} sat (pending: {wallet.balance-wallet.available_balance} sat) in {len([p for p in wallet.proofs if not p.reserved])} tokens"
) )
else: else:
print(f"Balance: {wallet.available_balance} sat") print(f"Balance: {wallet.available_balance} sat")

View File

@@ -15,7 +15,7 @@ async def verify_mints(ctx, dtoken):
keyset_wallet = Wallet( keyset_wallet = Wallet(
mint_url, os.path.join(CASHU_DIR, ctx.obj["WALLET_NAME"]) mint_url, os.path.join(CASHU_DIR, ctx.obj["WALLET_NAME"])
) )
# make sure that this mint indeed supports this keyset # make sure that this mint supports this keyset
mint_keysets = await keyset_wallet._get_keysets(mint_url) mint_keysets = await keyset_wallet._get_keysets(mint_url)
assert keyset in mint_keysets["keysets"], "mint does not have this keyset." assert keyset in mint_keysets["keysets"], "mint does not have this keyset."
@@ -23,19 +23,21 @@ async def verify_mints(ctx, dtoken):
mint_keyset = await keyset_wallet._get_keyset(mint_url, keyset) mint_keyset = await keyset_wallet._get_keyset(mint_url, keyset)
assert keyset == mint_keyset.id, Exception("keyset not valid.") assert keyset == mint_keyset.id, Exception("keyset not valid.")
# we check the db whether we know this keyset already and ask the user # we check the db whether we know this mint already and ask the user if not
mint_keysets = await get_keyset(id=keyset, db=keyset_wallet.db) mint_keysets = await get_keyset(mint_url=mint_url, db=keyset_wallet.db)
if mint_keysets is None: if mint_keysets is None:
# we encountered a new mint and ask for a user confirmation # we encountered a new mint and ask for a user confirmation
trust_token_mints = False trust_token_mints = False
print("") print("")
print("Warning: Tokens are from a mint or keyset you don't know yet.") print(
"Warning: Tokens are from a mint you don't know yet. Make sure that you know this mint."
)
print("\n") print("\n")
print(f"Mint URL: {mint_url}") print(f"Mint URL: {mint_url}")
print(f"Mint keyset: {keyset}") print(f"Mint keyset: {keyset}")
print("\n") print("\n")
click.confirm( click.confirm(
f"Do you want to trust this mint and receive the tokens?", f"Do you trust this mint and want to receive the tokens?",
abort=True, abort=True,
default=True, default=True,
) )

View File

@@ -66,8 +66,8 @@ class LedgerAPI:
def _set_requests(self): def _set_requests(self):
s = requests.Session() s = requests.Session()
s.headers.update({"Client-version": VERSION}) s.headers.update({"Client-version": VERSION})
if DEBUG: # if DEBUG:
s.verify = False # s.verify = False
socks_host, socks_port = None, None socks_host, socks_port = None, None
if TOR and TorProxy().check_platform(): if TOR and TorProxy().check_platform():
self.tor = TorProxy(timeout=True) self.tor = TorProxy(timeout=True)