mirror of
https://github.com/aljazceru/nutshell.git
synced 2025-12-21 02:54:20 +01:00
chore: run pyupgrade (#623)
- use `{...}` instead of `set([...])`
- do not use `class Foo(object):`, just use `class Foo:`
- do not specify default flags (`"r"`) for `open()`
This commit is contained in:
@@ -839,7 +839,7 @@ class TokenV3(Token):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def keysets(self) -> List[str]:
|
def keysets(self) -> List[str]:
|
||||||
return list(set([p.id for p in self.proofs]))
|
return list({p.id for p in self.proofs})
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def mint(self) -> str:
|
def mint(self) -> str:
|
||||||
@@ -847,7 +847,7 @@ class TokenV3(Token):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def mints(self) -> List[str]:
|
def mints(self) -> List[str]:
|
||||||
return list(set([t.mint for t in self.token if t.mint]))
|
return list({t.mint for t in self.token if t.mint})
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def memo(self) -> Optional[str]:
|
def memo(self) -> Optional[str]:
|
||||||
@@ -1037,7 +1037,7 @@ class TokenV4(Token):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def keysets(self) -> List[str]:
|
def keysets(self) -> List[str]:
|
||||||
return list(set([p.i.hex() for p in self.t]))
|
return list({p.i.hex() for p in self.t})
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_tokenv3(cls, tokenv3: TokenV3):
|
def from_tokenv3(cls, tokenv3: TokenV3):
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ from ..core.settings import settings
|
|||||||
def amount_summary(proofs: List[Proof], unit: Unit) -> str:
|
def amount_summary(proofs: List[Proof], unit: Unit) -> str:
|
||||||
amounts_we_have = [
|
amounts_we_have = [
|
||||||
(amount, len([p for p in proofs if p.amount == amount]))
|
(amount, len([p for p in proofs if p.amount == amount]))
|
||||||
for amount in set([p.amount for p in proofs])
|
for amount in {p.amount for p in proofs}
|
||||||
]
|
]
|
||||||
amounts_we_have.sort(key=lambda x: x[0])
|
amounts_we_have.sort(key=lambda x: x[0])
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class BlinkWallet(LightningBackend):
|
|||||||
}
|
}
|
||||||
payment_statuses = {"SUCCESS": True, "PENDING": None, "FAILURE": False}
|
payment_statuses = {"SUCCESS": True, "PENDING": None, "FAILURE": False}
|
||||||
|
|
||||||
supported_units = set([Unit.sat, Unit.msat])
|
supported_units = {Unit.sat, Unit.msat}
|
||||||
supports_description: bool = True
|
supports_description: bool = True
|
||||||
unit = Unit.sat
|
unit = Unit.sat
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ from .base import (
|
|||||||
|
|
||||||
|
|
||||||
class CLNRestWallet(LightningBackend):
|
class CLNRestWallet(LightningBackend):
|
||||||
supported_units = set([Unit.sat, Unit.msat])
|
supported_units = {Unit.sat, Unit.msat}
|
||||||
unit = Unit.sat
|
unit = Unit.sat
|
||||||
supports_mpp = settings.mint_clnrest_enable_mpp
|
supports_mpp = settings.mint_clnrest_enable_mpp
|
||||||
supports_incoming_payment_stream: bool = True
|
supports_incoming_payment_stream: bool = True
|
||||||
@@ -41,7 +41,7 @@ class CLNRestWallet(LightningBackend):
|
|||||||
raise Exception("missing rune for clnrest")
|
raise Exception("missing rune for clnrest")
|
||||||
# load from file or use as is
|
# load from file or use as is
|
||||||
if os.path.exists(rune_settings):
|
if os.path.exists(rune_settings):
|
||||||
with open(rune_settings, "r") as f:
|
with open(rune_settings) as f:
|
||||||
rune = f.read()
|
rune = f.read()
|
||||||
rune = rune.strip()
|
rune = rune.strip()
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ from .macaroon import load_macaroon
|
|||||||
|
|
||||||
|
|
||||||
class CoreLightningRestWallet(LightningBackend):
|
class CoreLightningRestWallet(LightningBackend):
|
||||||
supported_units = set([Unit.sat, Unit.msat])
|
supported_units = {Unit.sat, Unit.msat}
|
||||||
unit = Unit.sat
|
unit = Unit.sat
|
||||||
supports_incoming_payment_stream: bool = True
|
supports_incoming_payment_stream: bool = True
|
||||||
supports_description: bool = True
|
supports_description: bool = True
|
||||||
|
|||||||
@@ -39,12 +39,12 @@ class FakeWallet(LightningBackend):
|
|||||||
privkey: str = hashlib.pbkdf2_hmac(
|
privkey: str = hashlib.pbkdf2_hmac(
|
||||||
"sha256",
|
"sha256",
|
||||||
secret.encode(),
|
secret.encode(),
|
||||||
("FakeWallet").encode(),
|
b"FakeWallet",
|
||||||
2048,
|
2048,
|
||||||
32,
|
32,
|
||||||
).hex()
|
).hex()
|
||||||
|
|
||||||
supported_units = set([Unit.sat, Unit.msat, Unit.usd, Unit.eur])
|
supported_units = {Unit.sat, Unit.msat, Unit.usd, Unit.eur}
|
||||||
unit = Unit.sat
|
unit = Unit.sat
|
||||||
|
|
||||||
supports_incoming_payment_stream: bool = True
|
supports_incoming_payment_stream: bool = True
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ from .base import (
|
|||||||
class LNbitsWallet(LightningBackend):
|
class LNbitsWallet(LightningBackend):
|
||||||
"""https://github.com/lnbits/lnbits"""
|
"""https://github.com/lnbits/lnbits"""
|
||||||
|
|
||||||
supported_units = set([Unit.sat])
|
supported_units = {Unit.sat}
|
||||||
unit = Unit.sat
|
unit = Unit.sat
|
||||||
supports_incoming_payment_stream: bool = True
|
supports_incoming_payment_stream: bool = True
|
||||||
supports_description: bool = True
|
supports_description: bool = True
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ INVOICE_STATUSES = {
|
|||||||
class LndRPCWallet(LightningBackend):
|
class LndRPCWallet(LightningBackend):
|
||||||
supports_mpp = settings.mint_lnd_enable_mpp
|
supports_mpp = settings.mint_lnd_enable_mpp
|
||||||
supports_incoming_payment_stream = True
|
supports_incoming_payment_stream = True
|
||||||
supported_units = set([Unit.sat, Unit.msat])
|
supported_units = {Unit.sat, Unit.msat}
|
||||||
supports_description: bool = True
|
supports_description: bool = True
|
||||||
|
|
||||||
unit = Unit.sat
|
unit = Unit.sat
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ class LndRestWallet(LightningBackend):
|
|||||||
|
|
||||||
supports_mpp = settings.mint_lnd_enable_mpp
|
supports_mpp = settings.mint_lnd_enable_mpp
|
||||||
supports_incoming_payment_stream = True
|
supports_incoming_payment_stream = True
|
||||||
supported_units = set([Unit.sat, Unit.msat])
|
supported_units = {Unit.sat, Unit.msat}
|
||||||
supports_description: bool = True
|
supports_description: bool = True
|
||||||
unit = Unit.sat
|
unit = Unit.sat
|
||||||
|
|
||||||
|
|||||||
@@ -274,7 +274,7 @@ class LedgerSpendingConditions:
|
|||||||
|
|
||||||
# all pubkeys and n_sigs must be the same
|
# all pubkeys and n_sigs must be the same
|
||||||
assert (
|
assert (
|
||||||
len(set([tuple(pubs_output) for pubs_output in pubkeys_per_proof])) == 1
|
len({tuple(pubs_output) for pubs_output in pubkeys_per_proof}) == 1
|
||||||
), "pubkeys in all proofs must match."
|
), "pubkeys in all proofs must match."
|
||||||
assert len(set(n_sigs_per_proof)) == 1, "n_sigs in all proofs must match."
|
assert len(set(n_sigs_per_proof)) == 1, "n_sigs in all proofs must match."
|
||||||
|
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ class LedgerVerification(
|
|||||||
return units_proofs[0]
|
return units_proofs[0]
|
||||||
|
|
||||||
def get_fees_for_proofs(self, proofs: List[Proof]) -> int:
|
def get_fees_for_proofs(self, proofs: List[Proof]) -> int:
|
||||||
if not len(set([self.keysets[p.id].unit for p in proofs])) == 1:
|
if not len({self.keysets[p.id].unit for p in proofs}) == 1:
|
||||||
raise TransactionUnitError("inputs have different units.")
|
raise TransactionUnitError("inputs have different units.")
|
||||||
fee = (sum([self.keysets[p.id].input_fee_ppk for p in proofs]) + 999) // 1000
|
fee = (sum([self.keysets[p.id].input_fee_ppk for p in proofs]) + 999) // 1000
|
||||||
return fee
|
return fee
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ key = bytes.fromhex("3aa925cb69eb613e2928f8a18279c78b1dca04541dfd064df2eda66b598
|
|||||||
BLOCK_SIZE = 16
|
BLOCK_SIZE = 16
|
||||||
|
|
||||||
|
|
||||||
class AESCipher(object):
|
class AESCipher:
|
||||||
"""This class is compatible with crypto.createCipheriv('aes-256-cbc')"""
|
"""This class is compatible with crypto.createCipheriv('aes-256-cbc')"""
|
||||||
|
|
||||||
def __init__(self, key=None):
|
def __init__(self, key=None):
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ class Filter:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
if self.tags:
|
if self.tags:
|
||||||
e_tag_identifiers = set([e_tag[0] for e_tag in event.tags])
|
e_tag_identifiers = {e_tag[0] for e_tag in event.tags}
|
||||||
for f_tag, f_tag_values in self.tags.items():
|
for f_tag, f_tag_values in self.tags.items():
|
||||||
# Omit any NIP-01 or NIP-12 "#" chars on single-letter tags
|
# Omit any NIP-01 or NIP-12 "#" chars on single-letter tags
|
||||||
f_tag = f_tag.replace("#", "")
|
f_tag = f_tag.replace("#", "")
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ class TorProxy:
|
|||||||
def read_pid(self):
|
def read_pid(self):
|
||||||
if not os.path.isfile(self.pid_file):
|
if not os.path.isfile(self.pid_file):
|
||||||
return None
|
return None
|
||||||
with open(self.pid_file, "r") as f:
|
with open(self.pid_file) as f:
|
||||||
pid = f.readlines()
|
pid = f.readlines()
|
||||||
# check if pid is valid
|
# check if pid is valid
|
||||||
if len(pid) == 0 or not int(pid[0]) > 0:
|
if len(pid) == 0 or not int(pid[0]) > 0:
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class WalletProofs(SupportsDb, SupportsKeysets):
|
|||||||
self, proofs: List[Proof], unit: Optional[Unit] = None
|
self, proofs: List[Proof], unit: Optional[Unit] = None
|
||||||
) -> Dict[str, List[Proof]]:
|
) -> Dict[str, List[Proof]]:
|
||||||
ret: Dict[str, List[Proof]] = {}
|
ret: Dict[str, List[Proof]] = {}
|
||||||
keyset_ids = set([p.id for p in proofs])
|
keyset_ids = {p.id for p in proofs}
|
||||||
for id in keyset_ids:
|
for id in keyset_ids:
|
||||||
if id is None:
|
if id is None:
|
||||||
continue
|
continue
|
||||||
@@ -178,7 +178,7 @@ class WalletProofs(SupportsDb, SupportsKeysets):
|
|||||||
if not keysets:
|
if not keysets:
|
||||||
raise ValueError("No keysets found for proofs")
|
raise ValueError("No keysets found for proofs")
|
||||||
assert (
|
assert (
|
||||||
len(set([k.unit for k in keysets.values()])) == 1
|
len({k.unit for k in keysets.values()}) == 1
|
||||||
), "All keysets must have the same unit"
|
), "All keysets must have the same unit"
|
||||||
unit = keysets[list(keysets.keys())[0]].unit
|
unit = keysets[list(keysets.keys())[0]].unit
|
||||||
|
|
||||||
@@ -216,14 +216,14 @@ class WalletProofs(SupportsDb, SupportsKeysets):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
raise ValueError("Keysets of proofs are not loaded in wallet")
|
raise ValueError("Keysets of proofs are not loaded in wallet")
|
||||||
# we make sure that all proofs are from keysets of the same mint
|
# we make sure that all proofs are from keysets of the same mint
|
||||||
if len(set([k.mint_url for k in keysets])) > 1:
|
if len({k.mint_url for k in keysets}) > 1:
|
||||||
raise ValueError("TokenV4 can only contain proofs from a single mint URL")
|
raise ValueError("TokenV4 can only contain proofs from a single mint URL")
|
||||||
mint_url = keysets[0].mint_url
|
mint_url = keysets[0].mint_url
|
||||||
if not mint_url:
|
if not mint_url:
|
||||||
raise ValueError("No mint URL found for keyset")
|
raise ValueError("No mint URL found for keyset")
|
||||||
|
|
||||||
# we make sure that all keysets have the same unit
|
# we make sure that all keysets have the same unit
|
||||||
if len(set([k.unit for k in keysets])) > 1:
|
if len({k.unit for k in keysets}) > 1:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"TokenV4 can only contain proofs from keysets with the same unit"
|
"TokenV4 can only contain proofs from keysets with the same unit"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ def async_ensure_mint_loaded(func):
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
class LedgerAPI(LedgerAPIDeprecated, object):
|
class LedgerAPI(LedgerAPIDeprecated):
|
||||||
tor: TorProxy
|
tor: TorProxy
|
||||||
db: Database # we need the db for melt_deprecated
|
db: Database # we need the db for melt_deprecated
|
||||||
httpx: httpx.AsyncClient
|
httpx: httpx.AsyncClient
|
||||||
|
|||||||
Reference in New Issue
Block a user