def prompt_auth(self, msg): import getpass print_msg(msg) response = getpass.getpass('') if len(response) == 0: return None return response
def runCommand(self): command = self.getCommand() self.addToHistory(command) command = self.getConstruct(command) if command: tmp_stdout = sys.stdout class stdoutProxy(): def __init__(self, write_func): self.write_func = write_func self.skip = False def flush(self): pass def write(self, text): if not self.skip: stripped_text = text.rstrip('\n') self.write_func(stripped_text) QtCore.QCoreApplication.processEvents() self.skip = not self.skip if type(self.namespace.get(command)) == type(lambda: None): self.appendPlainText( "'{}' is a function. Type '{}()' to use it in the Python console." .format(command, command)) self.newPrompt() return sys.stdout = stdoutProxy(self.appendPlainText) try: try: # eval is generally considered bad practice. use it wisely! result = eval(command, self.namespace, self.namespace) if result != None: if self.is_json: util.print_msg(util.json_encode(result)) else: self.appendPlainText(repr(result)) except SyntaxError: # exec is generally considered bad practice. use it wisely! exec(command, self.namespace, self.namespace) except SystemExit: self.close() except (Exception, BaseException): # Catch errors in the network layer as well, as long as it uses BaseException. traceback_lines = traceback.format_exc().split('\n') # Remove traceback mentioning this file, and a linebreak for i in (3, 2, 1, -1): traceback_lines.pop(i) self.appendPlainText('\n'.join(traceback_lines)) sys.stdout = tmp_stdout self.newPrompt() self.set_json(False)
def _send(self, parent, blob): def sender_thread(): with self._audio_interface() as interface: src = BytesIO(blob) dst = interface.player() amodem.main.send(config=self.modem_config, src=src, dst=dst) print_msg('Sending:', repr(blob)) blob = zlib.compress(blob.encode('ascii')) kbps = self.modem_config.modem_bps / 1e3 msg = 'Sending to Audio MODEM ({0:.1f} kbps)...'.format(kbps) WaitingDialog(parent, msg, sender_thread)
def genContractWallet(self, nickname=None): path = os.path.join(self.topDir, 'wallets') if not os.path.isdir(path): os.mkdir(path) if nickname: for i, c in enumerate(self.contracts): if c["nickname"] == nickname: print_msg("{} contract exists.".format(nickname)) return self.getContractWallet(i), c #print(type(self.contracts)) #this next loop generates a wallet name that isn't in use yet. if self.contracts == []: walletFile = os.path.join(self.topDir, 'wallets', 'contract0.wallet') else: walletNames = [] for c in self.contracts: #print(c) walletNames.append(c['walletFile']) for i in range(len(walletNames) + 1): walletFile = os.path.join(self.topDir, 'wallets', 'contract' + str(i) + '.wallet') if walletFile not in walletNames: break storage = WalletStorage(walletFile) seed_type = 'standard' seed = Mnemonic('en').make_seed(seed_type) k = keystore.from_seed(seed, '', False) storage.put('keystore', k.dump()) storage.put('wallet_type', 'standard') wallet = Wallet(storage) wallet.set_schnorr_enabled(False) wallet.update_password(None, '', True) wallet.synchronize() print_msg("Your wallet generation seed is:\n\"%s\"" % seed) print_msg( "Please keep it in a safe place; if you lose it, you will not be able to restore your wallet." ) wallet.storage.write() print_msg("Wallet saved in '%s'" % wallet.storage.path) my_addr = wallet.get_unused_address() my_addr_index = wallet.receiving_addresses.index(my_addr) #my_addr_index is always going to be 0 if the wallet is unused, so maybe previous line unnecessary my_pubkey = wallet.derive_pubkeys(False, my_addr_index) my_x_pubkey = self.get_x_pubkey(my_addr_index, wallet) self.contracts.append({ 'walletFile': wallet.storage.path, "my_addr": my_addr.to_ui_string(), "my_pubkey": my_pubkey, "my_x_pubkey": my_x_pubkey, "nickname": nickname, "label": "" }) #print(self.contracts) self.updateContracts() self.multiWallets.append(None) return wallet, self.contracts[-1]
def create_multisig_addr(self, idx, partner_x_pubkey, generated_by_me=True): wallet = self.getContractWallet(idx) c = commands.Commands(None, wallet, None) contract = self.contracts[idx] if 'address' in contract: print_msg( "Cash Rip**********************************Overwriting old contract. It will be saved in contracts-bkp.txt" ) backupContract(contract) (partner_pubkey, partner_address) = keystore.xpubkey_to_address(partner_x_pubkey) if generated_by_me: multiaddress = c.createmultisig( 2, [contract["my_pubkey"], partner_pubkey]) else: multiaddress = c.createmultisig( 2, [partner_pubkey, contract["my_pubkey"]]) multiaddress["address"] = Address.from_string( multiaddress["address"]).to_ui_string() partner_address = partner_address.to_ui_string() contract.update(multiaddress) contract["partner_addr"] = partner_address contract["partner_x_pubkey"] = partner_x_pubkey contract["partner_pubkey"] = partner_pubkey contract["gen_by_me"] = generated_by_me addrWalletFile = contract["walletFile"][:-7] + "-address.wallet" #print("addrWalletFile: {}".format(addrWalletFile)) storage = WalletStorage(addrWalletFile) if storage.file_exists(): os.remove(addrWalletFile) storage = WalletStorage(addrWalletFile) #wal = ImportedAddressWallet.from_text(storage, contract["address"].to_ui_string()) wal = ImportedAddressWallet.from_text(storage, contract["address"]) wal.synchronize() wal.storage.write() print_msg("Wallet saved in '%s'" % wal.storage.path) contract["addrWalletFile"] = addrWalletFile #print_msg("contracts now: %s" % contracts) self.updateContracts() self.multiWallets[idx] = wal return contract
def get_pin(self, msg): t = { "a": "7", "b": "8", "c": "9", "d": "4", "e": "5", "f": "6", "g": "1", "h": "2", "i": "3", } print_msg(msg) print_msg("a b c\nd e f\ng h i\n-----") o = raw_input() return ''.join(map(lambda x: t[x], o))
def get_pin(self, msg): t = { 'a': '7', 'b': '8', 'c': '9', 'd': '4', 'e': '5', 'f': '6', 'g': '1', 'h': '2', 'i': '3' } print_msg(msg) print_msg("a b c\nd e f\ng h i\n-----") o = raw_input() return ''.join(map(lambda x: t[x], o))
def show_message(self, msg): print_msg(msg)
def get_passphrase(self, msg, confirm): import getpass print_msg(msg) return getpass.getpass('')
def on_finished(blob): if blob: blob = zlib.decompress(blob).decode('ascii') print_msg('Received:', repr(blob)) parent.setText(blob)
def debug_msg(*args): if DEBUG: print_msg(*args)
def test3(self): network = Network(None) network.start() to_addr = "bitcoincash:qqj4pf98k326u53ns75ap7lm4xp7a9upyc9nwcxrun" tx = self.maketx_from_multisig(0, to_addr, network) print_msg("Are we broadcasting tx?: {}".format(tx))
def show_message(self, msg, on_cancel=None): print_msg(msg)
def yes_no_question(self, msg): print_msg(msg) return raw_input() in 'yY'
'auto_connect': True, 'verbose': False, 'wallet_password': os.getenv("WALLET_PASSPHRASE"), "noonion": True, } if __name__ == '__main__': set_verbosity(config_options.get('verbose')) if config_options.get('testnet'): networks.set_testnet() config = SimpleConfig(config_options) storage = WalletStorage(config.get_wallet_path()) if not storage.file_exists(): print_msg("Wallet doesn't exist, creating...") data = create_new_wallet(path=storage.path, config=config, password=config_options['wallet_password'], encrypt_file=True) storage = WalletStorage(storage.path) if storage.is_encrypted() is False: print_msg("Error: Wallet is unencrypted") sys.exit(1) fd, server = daemon.get_fd_or_server(config) if fd is not None: plugins = init_plugins(config, 'cmdline') d = daemon.Daemon(config, fd, False, plugins)