def get_peers(): config = SimpleConfig() peers = {} # 1. get connected interfaces server = config.get('server') interfaces = get_interfaces([server]) if not interfaces: print("No connection to", server) return [] # 2. get list of peers interface = interfaces[server] interface.queue_request('server.peers.subscribe', [], 0) responses = wait_on_interfaces(interfaces).get(server) if responses: response = responses[0][1] # One response, (req, response) tuple peers = parse_servers(response.get('result')) return peers
class SignApp(object): def __init__(self, **kwargs): '''Get app settings from options''' self.make_commit = kwargs.pop('make_commit') self.password = kwargs.pop('password') self.signing_key = kwargs.pop('signing_key') self.testnet = kwargs.pop('testnet') self.wallet_path = kwargs.pop('wallet') script_config = read_config() if script_config: self.make_commit = (self.make_commit or script_config.get('make_commit', False)) self.signing_key = (self.signing_key or script_config.get('signing_key', False)) self.testnet = (self.testnet or script_config.get('testnet', False)) self.wallet_path = (self.wallet_path or script_config.get('wallet', False)) if self.wallet_path: self.wallet_path = os.path.expanduser(self.wallet_path) self.config_options = {'cwd': os.getcwd()} self.config_options['password'] = self.password self.config_options['testnet'] = self.testnet self.config_options['wallet_path'] = self.wallet_path self.config = SimpleConfig(self.config_options) if self.config.get('testnet'): constants.set_testnet() self.storage = WalletStorage(self.config.get_wallet_path()) def load_wallet(self, storage): print('Lodaing wallet: %s' % self.config.get_wallet_path()) password = None if storage.is_encrypted(): if storage.is_encrypted_with_hw_device(): plugins = Plugins(self.config, 'cmdline') password = get_passwd_for_hw_device_encrypted_storage(plugins) storage.decrypt(password) else: password = get_password(storage.decrypt) db = WalletDB(self.storage.read(), manual_upgrades=True) if db.requires_upgrade(): print('Error: Wallet db need to be upgraded.' ' Do it with the wallet app') sys.exit(1) self.wallet = Wallet(db, self.storage, config=self.config) if self.wallet.has_password() and not password: password = get_password(self.wallet.check_password) self.config_options['password'] = password def commit_latest_version(self): commit_msg = COMMIT_MSG_TEMPLATE.format(fname=LATEST_VER_FNAME, version=ELECTRUM_VERSION) print('commiting: %s' % commit_msg) os.system('git add ./%s' % LATEST_VER_FNAME) os.system('git commit -m "%s"' % commit_msg) def run(self): self.load_wallet(self.storage) if self.signing_key: address = self.signing_key else: address = SIGNING_KEYS[0] message = ELECTRUM_VERSION password = self.config_options.get('password') print('Signing version: %s' % message) print('with address: %s' % address) sig = self.wallet.sign_message(address, message, password) sig = base64.b64encode(sig).decode('ascii') content = { 'version': ELECTRUM_VERSION, 'signatures': { address: sig } } content_json = json.dumps(content, indent=4) print(content_json) with open('./%s' % LATEST_VER_FNAME, 'w') as fd: fd.write('%s\n' % content_json) if self.make_commit: self.commit_latest_version()