1 import curses, datetime
2 from decimal import Decimal
3 from util import format_satoshis, set_verbosity
9 def __init__(self, wallet, config, app=None):
12 self.stdscr = curses.initscr()
18 self.maxy, self.maxx = self.stdscr.getmaxyx()
21 def server_list_changed(self):
24 def restore_or_create(self):
27 def print_history(self):
30 for line in self.wallet.get_tx_history():
34 time_str = str( datetime.datetime.fromtimestamp( line['timestamp']))
36 print line['timestamp']
38 label = line.get('label')
39 if not label: label = line['tx_hash']
40 else: label = label + ' '*(64 - len(label) )
41 messages.append( time_str + " " + label + " " + format_satoshis(v)+ " "+ format_satoshis(b) )
43 self.print_list(messages, "%19s %64s %14s %10s"%("Date", "Description", "Amount", "Balance"))
46 def print_balance(self):
47 c, u = self.wallet.get_balance()
48 msg = "Balance: %f"%(Decimal( c ) / 100000000)
50 msg += " [%f unconfirmed]"%(Decimal( u ) / 100000000)
51 self.stdscr.addstr( self.maxy -3, 2, msg)
52 self.stdscr.addstr( self.maxy -1, 1, " History Send Receive Contacts Quit ")
54 def print_contacts(self):
55 messages = map(lambda addr: "%30s %30s "%(addr, self.wallet.labels.get(addr,"")), self.wallet.addressbook)
56 self.print_list(messages, "%19s %25s "%("Address", "Label"))
58 def print_receive(self):
59 messages = map(lambda addr: "%30s %30s "%(addr, self.wallet.labels.get(addr,"")), self.wallet.addresses)
60 self.print_list(messages, "%19s %25s "%("Address", "Label"))
62 def print_send_dialog(self):
64 self.stdscr.addstr( 3, 2, "Pay to")
65 self.stdscr.addstr( 5, 2, "Description")
66 self.stdscr.addstr( 7, 2, "Amount")
67 self.stdscr.addstr( 9, 2, "Fee")
71 s = self.stdscr.getstr(3, 15)
78 def print_list(self, list, firstline):
79 firstline += " "*(self.maxx -2 - len(firstline))
80 self.stdscr.addstr( 1, 1, firstline )
81 for i in range(self.maxy-6):
82 msg = list[i] if i < len(list) else ""
83 msg += " "*(self.maxx -2 - len(msg))
84 self.stdscr.addstr( i+2, 1, msg[0:self.maxx - 2])
95 c = self.stdscr.getch()
96 if c == ord('h'): self.print_history()
97 if c == ord('c'): self.print_contacts()
98 if c == ord('r'): self.print_receive()
99 if c == ord('s'): self.print_send_dialog()
100 elif c == ord('q'): break
101 elif c == curses.KEY_HOME: x = y = 0
105 self.stdscr.keypad(0);