Exemplo n.º 1
0
def draw_exporttx_window(state, window, rpc_queue):
	color = curses.color_pair(1)
	if g.testnet:
		color = curses.color_pair(2)

	UI = getstr.UserInput(window, "export transactions to csv file")

	# check for csv data in state
	if 'csv_data' in state['wallet']:
		if len(state['wallet']['csv_data']) > 0:
			UI.addline("Please enter destination file name (existing file will be overwritten):", curses.A_BOLD)
			try:
				backup = str(UI.getstr(254)).strip()
			except ValueError:
				backup = ""
			if backup != '':
				backup = backup.replace('~', os.path.expanduser('~'))
				state['wallet']['y'] = UI._y + 1
				UI.addmessageline("Saving " + str(len(state['wallet']['csv_data'])) + " tx...", color + curses.A_BOLD)
				_csv = readhashmap.get(os.path.dirname(os.path.abspath(inspect.getframeinfo(inspect.currentframe()).filename)) + \
					os.path.sep + 'csv_export_de.tpl')	# template hard coded here!!!
				try:
					with open(backup, 'w') as f:
						csv.register_dialect('coindDialect', quoting=csv.QUOTE_ALL, skipinitialspace=True)
						writer = csv.writer(f, dialect='coindDialect')
						writer.writerow([_csv['Confirmed'], _csv['Date'], _csv['Type'], _csv['Label'], _csv['Address'], _csv['Amount'] + ' (' + g.coin_unit + ')', _csv['ID']])
						for tx in state['wallet']['csv_data']:
							writer.writerow([tx['Confirmed'].encode('utf-8'), tx['Date'].encode('utf-8'), _csv[tx['Type']], tx['Label'].encode('utf-8'), tx['Address'].encode('utf-8'), str(tx['Amount']).encode('utf-8'), tx['ID'].encode('utf-8')])
					f.close()
					UI.addmessageline("File '" + backup + "' sucessfully written.", color + curses.A_BOLD)
				except:
					UI.addmessageline("An error occured on saving the file...", color + curses.A_BOLD)
			else:
				UI.addmessageline("Invalid file or directory name. Aborting.", color + curses.A_BOLD)
		else:
			UI.addmessageline("There are no transactions to save...", color + curses.A_BOLD)
	else:
		UI.addmessageline("No wallet data loaded yet...", color + curses.A_BOLD)
		
	# return to tx view
	state['wallet']['mode'] = 'tx'
	rpc_queue.put('getwalletinfo')
	rpc_queue.put('listsinceblock')
	UI.clear()
Exemplo n.º 2
0
def draw_backup_wallet_window(state, window, rpc_queue):
	color = curses.color_pair(1)
	if g.testnet:
		color = curses.color_pair(2)

	UI = getstr.UserInput(window, "backup wallet.dat mode")

	UI.addline("Please enter destination file or directory name:", curses.A_BOLD)
	try:
		backup = str(UI.getstr(254)).strip()
	except ValueError:
		backup = ""
	
	state['wallet']['y'] = UI._y + 1
	if backup != "":
		backup = backup.replace('~', os.path.expanduser('~'))
		rpc_queue.put({'backupwallet': backup })
		UI.addmessageline("Backing up wallet.dat to file '" + backup + "'...", color + curses.A_BOLD)
	else:
		UI.addmessageline("Invalid file or directory name. Aborting.", color + curses.A_BOLD)
		state['wallet']['mode'] = 'tx'
		rpc_queue.put('getwalletinfo')
		rpc_queue.put('listsinceblock')
		UI.clear()
Exemplo n.º 3
0
def draw_fee_input_window(state, window, rpc_queue):
	color = curses.color_pair(1)
	unit = g.coin_unit
	if g.testnet:
		color = curses.color_pair(2)
		unit = g.coin_unit_test

	UI = getstr.UserInput(window, "fee input mode")
	if 'walletinfo' in state:
		if 'paytxfee' in state['walletinfo']:
			fee_string = "Current transaction fee: " + "%0.8f" % state['walletinfo']['paytxfee'] + " " + unit + " per kB"
			UI.addline(fee_string)

	if 'estimatefee' in state and len(state['estimatefee']):
		string = "Estimatefee: "
		for item in state['estimatefee']:
			if item['value'] >= 0:
				string += "{:0.8f}".format(item['value']) + " " + unit + " per kB (" + str(item['blocks']) + (" blocks) " if int(item['blocks']) > 1 else " block) ")
		UI.addline(string, curses.A_NORMAL)

	UI.addline("Please enter new transaction fee in " + unit + " per kB:", curses.A_BOLD)
	
	try:
		new_fee = float(UI.getstr(64))
	except ValueError:
		new_fee = -1
	
	if new_fee >= 0:
		s = {'settxfee': "{:0.8f}".format(new_fee)}
		UI.addmessageline("Setting transaction fee value to " + "{:0.8f}".format(new_fee) + " " + unit + " per kB...", color + curses.A_BOLD)
		rpc_queue.put(s)
	else:
		UI.addmessageline("No valid fee amount entered. Aborting.", color + curses.A_BOLD)
		UI.clear()
		state['wallet']['mode'] = 'addresses'
		rpc_queue.put('listsinceblock')
Exemplo n.º 4
0
def draw_send_coins_window(state, window, rpc_queue):
	color = curses.color_pair(1)
	unit = g.coin_unit
	if g.testnet:
		color = curses.color_pair(2)
		unit = g.coin_unit_test

	UI = getstr.UserInput(window, "send " + unit + " mode")

	if 'balance' in state and g.y >= 14:
		display_string = "Current balance: " + "%0.8f" % state['balance'] + " " + unit
		if 'unconfirmedbalance' in state:
			if state['unconfirmedbalance'] != 0:
				display_string += " (+" + "%0.8f" % state['unconfirmedbalance'] + " unconf)"
		if 'unconfirmed_balance' in state:
			if state['unconfirmed_balance'] != 0:
				display_string += " (+" + "%0.8f" % state['unconfirmed_balance'] + " unconf)"
		UI.addline(display_string)

	if 'walletinfo' in state:
		if 'paytxfee' in state['walletinfo'] and g.y >= 15:
			display_string = "Current transaction fee: " + "%0.8f" % state['walletinfo']['paytxfee'] + " " + unit + " per kB"
			UI.addline(display_string, curses.A_NORMAL)

	if 'estimatefee' in state and g.y >= 17:
		display_string = "Estimatefee: "
		for item in state['estimatefee']:
			if item['value'] > 0:
				display_string += "{:0.8f}".format(item['value']) + " " + unit + " per kB (" + str(item['blocks']) + (" blocks) " if int(item['blocks']) > 1 else " block) ")
		UI.addline(display_string, curses.A_NORMAL)

	err_msg = ""
	abort = False

	UI.addline("Please enter amount of " + unit + " so send:", curses.A_BOLD)
	try:
		amount = float(UI.getstr(32))
	except ValueError:
		amount = -1
	
	if amount > 0:

		state['newtransaction']['amount'] = "%0.8f" % amount

		UI.addline("Please enter receiving address:", curses.A_BOLD)
		try:
			address = UI.getstr(54).strip()
		except:
			abort = True

		if check_address(address) and not abort:

			state['newtransaction']['address'] = address
			
			UI.addline("Please enter a comment on the transaction (optional):", curses.A_BOLD)
			try:
				comment = UI.getstr(128).strip()
			except:
				abort = True

			if not abort:

				state['newtransaction']['comment'] = comment
				
				UI.addline("Please enter a comment on the recipient (optional):", curses.A_BOLD)
				try:
					comment_to = UI.getstr(128).strip()
				except:
					abort = True

				if not abort:

					state['newtransaction']['comment_to'] = comment_to
				
					if g.y >= 19:
						UI.addline()
					if g.y >= 16:
						UI.addline("You will send " + "{:0.8f}".format(amount) + " " + unit + " (+ fee) to the address '" + address + "'")
					if g.y >= 18:
						UI.addline()

					encrypted = False
					if 'walletinfo' in state:
						if 'unlocked_until' in state['walletinfo']:
							encrypted = True

					if encrypted:
						UI.addline("Please confirm this transaction by providing your wallet's passphrase:", curses.A_BOLD)
						try:
							password = getstr.getstr(128, UI._y, 1, "*")
							pass
						except:
							abort = True
					else:
						abort = not UI.continue_yesno(False)
						UI._y -= 1

					if not abort:

						if encrypted:
							if g.y >= 18:
								UI.addline()
							s = {'walletpassphrase': password}
							rpc_queue.put(s)
							UI.addmessageline("Unlocking wallet and sending transaction...", color + curses.A_BOLD)
						else:
							if g.y >= 17:
								UI.addline()
							s = {'sendtoaddress': {'address': address, 'amount': str(amount), 'comment': comment, 'comment_to': comment_to}}
							rpc_queue.put(s)
							UI.addmessageline("Sending transaction...", color + curses.A_BOLD)
						state['wallet']['y'] = UI._y

		else:
			err_msg = "Invalid receiving address."
			abort = True

	else:
		err_msg = "Invalid amount."
		abort = True

	if abort:
		UI.addmessageline(err_msg + " Aborting.", color + curses.A_BOLD)
		UI.clear()
		state['wallet']['mode'] = 'addresses'
		rpc_queue.put('listsinceblock')
Exemplo n.º 5
0
def draw_new_address_window(state, window, rpc_queue):
	color = curses.color_pair(1)
	if g.testnet:
		color = curses.color_pair(2)

	UI = getstr.UserInput(window, "new receiving address mode")

	abort = False
	error_string = ""
	UI.addline("Please enter an address label (optional):", curses.A_BOLD)
	try:
		new_account = str(UI.getstr(128)).strip()
	except:
		abort = True
	
	if not abort:
		UI.addline("Do you want to add a [r]eceiving or a [w]atch-only address? [r/w]", curses.A_BOLD)
		try:
			new_type = str(UI.getstr(1))
		except:
			error_string = "Invalid address type entered. "
			abort = True

		if new_type == 'r':
			state['wallet']['y'] = UI._y + 2
			state['wallet']['newlabel'] = new_account
			rpc_queue.put({'getnewaddress': new_account})
			UI.addmessageline("Creating new receiving address" + (" for account " + "'{}'".format(new_account) if len(new_account) else "") + "...", 
								color + curses.A_BOLD)
		elif new_type == 'w':
			UI.addline("Please enter watch-only address:", curses.A_BOLD)
			new_address = ""
			try:
				new_address = UI.getstr(35).strip()
			except:
				abort = True
			if not check_address(new_address):
				error_string = "Invalid address entered. "
				abort = True
			if not abort:
				UI.addline("Do you want to rescan the entire blockchain for matching transactions? [y/N]", curses.A_BOLD)
				try:
					new_rescan = str(UI.getstr(1))
				except:
					abort = True
				if new_rescan in ['y', 'Y']:
					new_rescan = True
				elif new_rescan in ['n', 'N']:
					new_rescan = False
				else:
					abort = True

				if not abort:
					state['wallet']['newlabel'] = new_account
					state['wallet']['newaddress'] = new_address
					s = {'importaddress': {'account': new_account, 'address': new_address, 'rescan': bool(new_rescan)}}
					rpc_queue.put(s)
					UI.addmessageline("Importing watch-only address" + (" for account " + "'{}'".format(new_account) if len(new_account) else "") + "...", 
										color + curses.A_BOLD)
		else:
			abort = True

	if abort:
		UI.addmessageline(error_string + "Aborting.", color + curses.A_BOLD)
		state['wallet']['mode'] = 'addresses'
		rpc_queue.put('listreceivedbyaddress')
		UI.clear()
		footer.draw_window(state, rpc_queue, True)