Skip to content

Commit

Permalink
Electrums upgrade (#393)
Browse files Browse the repository at this point in the history
* Electrums upgrade

* Upgrade packages
  • Loading branch information
MrNaif2018 authored Jan 10, 2024
1 parent cb1e636 commit 077f7be
Show file tree
Hide file tree
Showing 24 changed files with 1,578 additions and 1,532 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repos:
hooks:
- id: isort
- repo: https://github.com/pycqa/flake8
rev: 6.1.0
rev: 7.0.0
hooks:
- id: flake8
- repo: https://github.com/asottile/pyupgrade
Expand Down
4 changes: 4 additions & 0 deletions daemons/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,17 @@ def env(self, name, *, default, cast=noop_cast):

### Spec support ###

def set_dynamic_spec(self):
pass

def load_spec(self):
self.spec = load_spec(self.BASE_SPEC_FILE)
custom_spec_file = f"daemons/spec/{self.name.lower()}.json"
if custom_spec_file != self.BASE_SPEC_FILE:
custom_spec = load_spec(custom_spec_file, exit_on_error=False)
maybe_update_key(self.spec, custom_spec, "electrum_map")
maybe_update_key(self.spec, custom_spec, "exceptions")
self.set_dynamic_spec()

def get_error_code(self, error, fallback_code=-32603):
"""Get jsonrpc error code returned to client
Expand Down
36 changes: 25 additions & 11 deletions daemons/btc.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ def __init__(self):
# initialize not yet created network
self.loop = None
self.network = None
self.fx = None
self.daemon = None

def load_env(self):
Expand Down Expand Up @@ -112,6 +111,9 @@ def get_proxy_settings(self):
sys.exit(f"Invalid proxy URL. Original traceback:\n{traceback.format_exc()}")
return {"proxy": proxy}

def set_dynamic_spec(self):
self.spec["capabilities"] = {"lightning": self.LIGHTNING}

@property
@cached
def available_events(self):
Expand Down Expand Up @@ -161,13 +163,16 @@ async def on_startup(self, app):
self.network = self.daemon.network
callback_function = self._process_events if self.ASYNC_CLIENT else self._process_events_sync
self.register_callbacks(callback_function)
self.fx = self.daemon.fx

async def shutdown_daemon(self):
if self.daemon:
await self.daemon.stop()

async def on_shutdown(self, app):
coros = []
for wallet in list(self.wallets.keys()):
coros.append(self.close_wallet(wallet=wallet))
await asyncio.gather(*coros)
await self.shutdown_daemon()
await super().on_shutdown(app)

Expand All @@ -182,8 +187,8 @@ def load_cmd_wallet(self, cmd, wallet):
self.daemon.add_wallet(wallet)

def create_wallet(self, storage, config):
db = self.electrum.wallet_db.WalletDB(storage.read(), manual_upgrades=False)
return self.electrum.wallet.Wallet(db=db, storage=storage, config=config)
db = self.electrum.wallet_db.WalletDB(storage.read(), storage=storage, upgrade=True)
return self.electrum.wallet.Wallet(db=db, config=config)

def init_wallet(self, wallet):
if self.LIGHTNING:
Expand Down Expand Up @@ -362,7 +367,7 @@ def process_verified_tx(self, args):
return data, wallet

def get_status_str(self, status):
return self.electrum.invoices.pr_tooltips[status]
return self.electrum.invoices.pr_tooltips()[status]

def _get_request(self, wallet, address):
return wallet.get_request(address)
Expand Down Expand Up @@ -642,12 +647,21 @@ async def help(self, func=None, wallet=None):
else:
raise Exception("Procedure not found")

@rpc(requires_wallet=True, requires_network=True)
async def close_wallet(self, wallet):
method = self.wallets[wallet]["cmd"].close_wallet
await method() if self.ASYNC_CLIENT else method()
del self.wallets_updates[wallet]
del self.wallets[wallet]
@rpc(requires_network=True)
async def close_wallet(self, key=None, wallet=None):
key = wallet or key
if key not in self.wallets:
return False
if self.wallets[key]["wallet"].storage:
path = self.wallets[key]["wallet"].storage.path
if self.ASYNC_CLIENT:
await self.wallets[key]["cmd"].close_wallet(wallet_path=path)
else: # NOTE: we assume that non-async clients are BCH-based coins there
self.daemon.stop_wallet(path)
else:
await self.wallets[key]["wallet"].stop() if self.ASYNC_CLIENT else self.wallets[key]["wallet"].stop_threads()
del self.wallets_updates[key]
del self.wallets[key]
return True


Expand Down
2 changes: 1 addition & 1 deletion daemons/genericprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ class BlockProcessorDaemon(BaseDaemon, metaclass=ABCMeta):

SPEED_MULTIPLIERS = {"network": 1, "regular": 1.25, "fast": 1.5}

VERSION = "4.4.5" # version of electrum API with which we are "compatible"
VERSION = "4.5.0" # version of electrum API with which we are "compatible"

KEYSTORE_CLASS = KeyStore
WALLET_CLASS = Wallet
Expand Down
9 changes: 7 additions & 2 deletions daemons/spec/btc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "4.4.5",
"version": "4.5.0",
"electrum_map": {
"Procedure not found": -32601,
"wallet not loaded": -32000,
Expand All @@ -21,7 +21,8 @@
"No path found": -32010,
"Lightning not supported in this wallet type": -32011,
"Invoice not found": -32012,
"This version of Electrum is too old to open this wallet": -32013
"This version of Electrum is too old to open this wallet": -32013,
"No ConfigVar with key": -32014
},
"exceptions": {
"-32601": {
Expand Down Expand Up @@ -83,6 +84,10 @@
"-32013": {
"exc_name": "WalletVersionMismatchError",
"docstring": "Wallet file was opened in a newer electrum version than Bitcart is using. Delete the wallet file to fix this issue"
},
"-32014": {
"exc_name": "NoConfigKeyError",
"docstring": "No config key found"
}
}
}
2 changes: 1 addition & 1 deletion daemons/spec/eth.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "4.4.5",
"version": "4.5.0",
"electrum_map": {
"Procedure not found": -32601,
"wallet not loaded": -32000,
Expand Down
2 changes: 1 addition & 1 deletion requirements/daemons/bch.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
aiohttp<4.0
https://github.com/Electron-Cash/Electron-Cash/archive/397f43c848e270a7405795c4643a2805d872675f.zip
https://github.com/Electron-Cash/Electron-Cash/archive/cd4a0fe6cceb6ffc90dca5525c7e405387561506.zip
protobuf<4
2 changes: 1 addition & 1 deletion requirements/daemons/bsty.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
electrum-bsty[crypto] @ https://github.com/GlobalBoost/electrum/archive/87d0aea4317ea45a3e2a874905fed48cb02c450a.zip
electrum-bsty[crypto] @ https://github.com/GlobalBoost/electrum/archive/e5b267128464e7fa3298eb5615313ae7266dda7d.zip
protobuf<4
2 changes: 1 addition & 1 deletion requirements/daemons/btc.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
electrum[crypto] @ https://github.com/spesmilo/electrum/archive/13864f7abe103e0b290f97324d4d55b983a57b84.zip
electrum[crypto] @ https://github.com/spesmilo/electrum/archive/df1b9a223c77f4597a75df4e040754a58185151f.zip
protobuf<4
2 changes: 1 addition & 1 deletion requirements/daemons/grs.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
electrum-grs[crypto] @ https://github.com/Groestlcoin/electrum-grs/archive/c26925007deb2cdae1975fe4be84b28ab8a429e0.zip
electrum-grs[crypto] @ https://github.com/Groestlcoin/electrum-grs/archive/3bbebc766b0d0f12eb69b226de723e6a6431cd80.zip
protobuf<4
2 changes: 1 addition & 1 deletion requirements/daemons/ltc.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
electrum-ltc[crypto] @ https://github.com/bitcart/electrum-ltc/archive/7f42fc399dfc06b6245fcdfbb271ffa40df13daa.zip
electrum-ltc[crypto] @ https://github.com/bitcart/electrum-ltc/archive/b0c8bf8dd6c829ec5e93ff85627083f43b3db857.zip
protobuf<4
scrypt>=0.6.0
4 changes: 2 additions & 2 deletions requirements/deterministic/daemons/bch.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,8 @@ ecdsa==0.18.0 \
--hash=sha256:190348041559e21b22a1d65cee485282ca11a6f81d503fddb84d5017e9ed1e49 \
--hash=sha256:80600258e7ed2f16b9aa1d7c295bd70194109ad5a30fdee0eaeefef1d4c559dd
# via electron-cash
electron-cash @ https://github.com/Electron-Cash/Electron-Cash/archive/397f43c848e270a7405795c4643a2805d872675f.zip \
--hash=sha256:e3013b342fd4262c1f981ea85bc22b9bc13e6759a47774c957a582699028d4a1
electron-cash @ https://github.com/Electron-Cash/Electron-Cash/archive/cd4a0fe6cceb6ffc90dca5525c7e405387561506.zip \
--hash=sha256:38e368f56e7ad523b71e0845a5f7c9c7bcb2ac3bcaa9e5c57da1ee61c659c030
# via -r requirements/daemons/bch.txt
frozenlist==1.4.1 \
--hash=sha256:04ced3e6a46b4cfffe20f9ae482818e34eba9b5fb0ce4056e4cc9b6e212d09b7 \
Expand Down
Loading

0 comments on commit 077f7be

Please sign in to comment.