def key(name, password=None, display=True): print("Reading BCH private key from ORBIT wallet...") print(" Name: {}".format(name)) wpath = path(name) print(" File: {}".format(wpath)) wallet = access(wpath, password_handler(password)) key_hex = wallet.to_hex() key_bytes = wallet.to_bytes() key_der = wallet.to_der() key_pem = wallet.to_pem() key_int = wallet.to_int() key_wif = wallet.to_wif() if display: print() print(" Private BCH key (bytes): {}".format(key_bytes)) print(" Private BCH key (base58): {}".format(b58encode(key_bytes))) print(" Private BCH key (hex): {}".format(key_hex)) #print(" Private BCH key (hex base58): {}".format(b58encode(key_hex))) print(" Private BCH key (der): {}".format(key_der)) print(" Private BCH key (der base58): {}".format( b58encode(key_der))) print(" Private BCH key (der base64): {}".format( b64encode(key_der))) print(" Private BCH key (pem): {}".format(key_pem)) print(" Private BCH key (int): {}".format(key_int)) print(" Private BCH key (wif): {}".format(key_wif)) return (key_hex, key_bytes, key_der, key_pem, key_int)
def create(name=None, password=None): if name: print("Creating new ORBIT wallet file for BCH...") else: print("Generating new BCH key-pair...") if name: print(" Name: {}".format(name)) wpath = path(name) print(" File: {}".format(wpath)) else: wpath = None def show_address(address): print(" Public BCH address: {}".format(address)) def unencrypted_warning(): print("WARNING: You are about to save the private key without encryption! THIS IS NOT RECOMMENDED.") confirm = input(" Please type 'confirm' if you accept the risk and wish to continue: ") if confirm != 'confirm': raise ValueError('User abort') wallet = wcreate(wpath, None, password_handler(password, create=True), show_address, unencrypted_warning) if name is None: print(" Private BCH key (hex): {}".format(wallet.to_hex())) else: print() print("Wallet saved") return wallet
def rename(name, newname): print("Renaming ORBIT wallet file...") print(" Original name: {}".format(name)) wpath = path(name) print(" Original file: {}".format(wpath)) if not os.path.exists(wpath): raise ValueError("Wallet does not exist") print(" New name: {}".format(newname)) newwpath = path(newname) print(" New file: {}".format(newwpath)) if os.path.exists(newwpath): raise ValueError("A wallet already exists with the new name") os.rename(wpath, newwpath) print() print("Wallet renamed")
def address(name, password=None, display=True): print("Reading BCH address from ORBIT wallet file...") print(" Name: {}".format(name)) wpath = path(name) print(" File: {}".format(wpath)) wallet = access(wpath, password_handler(password)) if display: print() print(" Public BCH address: {}".format(wallet.address)) return wallet.address
def balance(name, password=None, display=True): print("Reading BCH address from ORBIT wallet file...") print(" Name: {}".format(name)) wpath = path(name) print(" File: {}".format(wpath)) wallet = access(wpath, password_handler(password)) balance = wallet.get_balance() if display: print() print(" Current balance : {} satoshi".format(balance)) return balance
def import_key(name, key=None, password=None): print("Importing private BCH key for new ORBIT wallet file...") print(" Name: {}".format(name)) wpath = path(name) print(" File: {}".format(wpath)) def get_key(): nonlocal key if not key: if stdin.isatty(): print() key = getpass("Enter private BCH key (hex): ") else: key = stdin.readline().rstrip() if not key: print() raise ValueError("Key may not be empty") return key def show_address(address): print(" Public BCH address: {}".format(address)) def unencrypted_warning(): print( "WARNING: You are about to save the private key without encryption! THIS IS NOT RECOMMENDED." ) confirm = input( " Please type 'confirm' if you accept the risk and wish to continue: " ) if confirm != 'confirm': raise ValueError('User abort') wallet = wcreate(wpath, get_key, password_handler(password, create=True), show_address, unencrypted_warning) print() print("Wallet saved") return wallet
def tokens(name, password=None): print("Opening wallet...") print(" Name: {}".format(name)) wpath = path(name) print(" File: {}".format(wpath)) wallet = access(wpath, password_handler(password)) print() print("Connecting to ORBIT node to retrieve token information...") host = get_orbit_host() port = get_orbit_port() print(" Host: {}".format(host)) print(" Port: {}".format(port)) client = Client(host=host, port=port) tokens = client.get_user_tokens(wallet.address)[Endpoints.USER_TOKENS] if tokens: for token in tokens: print() print(" Token @ {}".format(token['address'])) print(" Name: {}".format(token['name'])) print(" Symbol: {}".format(token['symbol'])) decimals = token['decimals'] print(" Decimals: {}".format(decimals)) print(" Balance") total = token['units'] print(" Total: {} ({} unit{})".format( Decimal(total).scaleb(-1 * decimals), total, "" if total == 1 else "s")) available = token['available'] print(" Available: {} ({} unit{})".format( Decimal(available).scaleb(-1 * decimals), available, "" if available == 1 else "s")) else: print() print(" No tokens")
def on_saveButton_clicked(self): self.error.setText("") name = self.name.text() try: wpath = path(name) def get_password(): return self.password.text() def warning(): if not Unencrypted(self).exec_(): raise ValueError("User abort") create(wpath, get_password=get_password, unencrypted_warning=warning) self.parent.reload_wallets(name) self.accept() except ValueError as e: self.error.setText("{}".format(e))
def on_wallets_currentIndexChanged(self, index): if self.wallet: self.wallet = None if index > 0: self.error.setText("") def password(): password = Password(self) if password.exec_(): return password.password.text() else: raise ValueError("User abort") try: wpath = path(self.wallets.currentText()) self.wallet = access(wpath, get_password=password) self.on_refreshCashButton_clicked() except ValueError as e: self.error.setText("{}".format(e)) self.wallets.setCurrentIndex(0) self.refresh()