From 684390a47960420af9d1018c85c82c04ea3e0126 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Fri, 29 Jun 2018 11:58:12 +0200 Subject: [PATCH] labels plugin: fix it. and extend to cli/daemon. --- lib/daemon.py | 2 ++ plugins/labels/__init__.py | 2 +- plugins/labels/cmdline.py | 11 +++++++++++ plugins/labels/labels.py | 5 +++-- 4 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 plugins/labels/cmdline.py diff --git a/lib/daemon.py b/lib/daemon.py index 99dfc1352..64a12e058 100644 --- a/lib/daemon.py +++ b/lib/daemon.py @@ -41,6 +41,7 @@ from .storage import WalletStorage from .commands import known_commands, Commands from .simple_config import SimpleConfig from .exchange_rate import FxThread +from .plugins import run_hook def get_lockfile(config): @@ -175,6 +176,7 @@ class Daemon(DaemonThread): wallet = self.load_wallet(path, config.get('password')) if wallet is not None: self.cmd_runner.wallet = wallet + run_hook('load_wallet', wallet, None) response = wallet is not None elif sub == 'close_wallet': path = config.get_wallet_path() diff --git a/plugins/labels/__init__.py b/plugins/labels/__init__.py index 759637355..4596bcae4 100644 --- a/plugins/labels/__init__.py +++ b/plugins/labels/__init__.py @@ -5,5 +5,5 @@ description = ' '.join([ _("Save your wallet labels on a remote server, and synchronize them across multiple devices where you use Electrum."), _("Labels, transactions IDs and addresses are encrypted before they are sent to the remote server.") ]) -available_for = ['qt', 'kivy'] +available_for = ['qt', 'kivy', 'cmdline'] diff --git a/plugins/labels/cmdline.py b/plugins/labels/cmdline.py new file mode 100644 index 000000000..bd2db0077 --- /dev/null +++ b/plugins/labels/cmdline.py @@ -0,0 +1,11 @@ +from .labels import LabelsPlugin +from electrum.plugins import hook + +class Plugin(LabelsPlugin): + + @hook + def load_wallet(self, wallet, window): + self.start_wallet(wallet) + + def on_pulled(self, wallet): + self.print_error('labels pulled from server') diff --git a/plugins/labels/labels.py b/plugins/labels/labels.py index 5176617ad..72c27c9b3 100644 --- a/plugins/labels/labels.py +++ b/plugins/labels/labels.py @@ -9,6 +9,7 @@ import base64 import electrum from electrum.plugins import BasePlugin, hook +from electrum.crypto import aes_encrypt_with_iv, aes_decrypt_with_iv from electrum.i18n import _ @@ -21,14 +22,14 @@ class LabelsPlugin(BasePlugin): def encode(self, wallet, msg): password, iv, wallet_id = self.wallets[wallet] - encrypted = electrum.bitcoin.aes_encrypt_with_iv(password, iv, + encrypted = aes_encrypt_with_iv(password, iv, msg.encode('utf8')) return base64.b64encode(encrypted).decode() def decode(self, wallet, message): password, iv, wallet_id = self.wallets[wallet] decoded = base64.b64decode(message) - decrypted = electrum.bitcoin.aes_decrypt_with_iv(password, iv, decoded) + decrypted = aes_decrypt_with_iv(password, iv, decoded) return decrypted.decode('utf8') def get_nonce(self, wallet):