Browse Source

labels plugin: fix it. and extend to cli/daemon.

3.2.x
SomberNight 7 years ago
parent
commit
684390a479
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 2
      lib/daemon.py
  2. 2
      plugins/labels/__init__.py
  3. 11
      plugins/labels/cmdline.py
  4. 5
      plugins/labels/labels.py

2
lib/daemon.py

@ -41,6 +41,7 @@ from .storage import WalletStorage
from .commands import known_commands, Commands from .commands import known_commands, Commands
from .simple_config import SimpleConfig from .simple_config import SimpleConfig
from .exchange_rate import FxThread from .exchange_rate import FxThread
from .plugins import run_hook
def get_lockfile(config): def get_lockfile(config):
@ -175,6 +176,7 @@ class Daemon(DaemonThread):
wallet = self.load_wallet(path, config.get('password')) wallet = self.load_wallet(path, config.get('password'))
if wallet is not None: if wallet is not None:
self.cmd_runner.wallet = wallet self.cmd_runner.wallet = wallet
run_hook('load_wallet', wallet, None)
response = wallet is not None response = wallet is not None
elif sub == 'close_wallet': elif sub == 'close_wallet':
path = config.get_wallet_path() path = config.get_wallet_path()

2
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."), _("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.") _("Labels, transactions IDs and addresses are encrypted before they are sent to the remote server.")
]) ])
available_for = ['qt', 'kivy'] available_for = ['qt', 'kivy', 'cmdline']

11
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')

5
plugins/labels/labels.py

@ -9,6 +9,7 @@ import base64
import electrum import electrum
from electrum.plugins import BasePlugin, hook from electrum.plugins import BasePlugin, hook
from electrum.crypto import aes_encrypt_with_iv, aes_decrypt_with_iv
from electrum.i18n import _ from electrum.i18n import _
@ -21,14 +22,14 @@ class LabelsPlugin(BasePlugin):
def encode(self, wallet, msg): def encode(self, wallet, msg):
password, iv, wallet_id = self.wallets[wallet] 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')) msg.encode('utf8'))
return base64.b64encode(encrypted).decode() return base64.b64encode(encrypted).decode()
def decode(self, wallet, message): def decode(self, wallet, message):
password, iv, wallet_id = self.wallets[wallet] password, iv, wallet_id = self.wallets[wallet]
decoded = base64.b64decode(message) 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') return decrypted.decode('utf8')
def get_nonce(self, wallet): def get_nonce(self, wallet):

Loading…
Cancel
Save