def update_layout(): global status_text if not network.is_connected(): text = "Not connected..." elif not wallet.up_to_date: text = "Synchronizing..." else: c, u, x = wallet.get_balance() text = "Balance:"+format_satoshis(c) if u: text += ' [' + format_satoshis(u,True).strip() + ']' if x: text += ' [' + format_satoshis(x,True).strip() + ']' # vibrate if status changed if text != status_text: if status_text and network.is_connected() and wallet.up_to_date: droid.vibrate() status_text = text droid.fullSetProperty("balanceTextView", "text", status_text) if wallet.up_to_date: set_history_layout(15)
def receive_loop(): global receive_addr, receive_amount, receive_message print "receive loop" receive_URI = util.create_URI(receive_addr, receive_amount, receive_message) make_bitmap(receive_URI) droid.fullShow(qr_layout(receive_addr, receive_amount, receive_message)) out = None while out is None: event = droid.eventWait().result if not event: continue elif event["name"]=="key": if event["data"]["key"] == '4': out = 'main' elif event["name"]=="clipboard": droid.setClipboard(receive_URI) modal_dialog('URI copied to clipboard', receive_URI) elif event["name"]=="amount": amount = modal_input('Amount', 'Amount you want to receive (in MUE). ', format_satoshis(receive_amount) if receive_amount else None, "numberDecimal") if amount is not None: receive_amount = int(COIN * Decimal(amount)) if amount else None out = 'receive' elif event["name"]=="message": message = modal_input('Message', 'Message in your request', receive_message) if message is not None: receive_message = unicode(message) out = 'receive' return out
def receive_loop(): global receive_addr, receive_amount, receive_message print "receive loop" receive_URI = util.create_URI(receive_addr, receive_amount, receive_message) make_bitmap(receive_URI) droid.fullShow(qr_layout(receive_addr, receive_amount, receive_message)) out = None while out is None: event = droid.eventWait().result if not event: continue elif event["name"]=="key": if event["data"]["key"] == '4': out = 'main' elif event["name"]=="clipboard": droid.setClipboard(receive_URI) modal_dialog('URI copied to clipboard', receive_URI) elif event["name"]=="amount": amount = modal_input('Amount', 'Amount you want to receive (in BTC). ', format_satoshis(receive_amount) if receive_amount else None, "numberDecimal") if amount is not None: receive_amount = int(COIN * Decimal(amount)) if amount else None out = 'receive' elif event["name"]=="message": message = modal_input('Message', 'Message in your request', receive_message) if message is not None: receive_message = unicode(message) out = 'receive' return out
def qr_layout(addr, amount, message): addr_view = ( """ <TextView android:id="@+id/addrTextView" android:layout_width="match_parent" android:layout_height="50" android:text="%s" android:textAppearance="?android:attr/textAppearanceLarge" android:gravity="center_vertical|center_horizontal|center"> </TextView>""" % addr ) if amount: amount_view = """ <TextView android:id="@+id/amountTextView" android:layout_width="match_parent" android:layout_height="50" android:text="Amount: %s" android:textAppearance="?android:attr/textAppearanceLarge" android:gravity="center_vertical|center_horizontal|center"> </TextView>""" % format_satoshis( amount ) else: amount_view = "" if message: message_view = ( """ <TextView android:id="@+id/messageTextView" android:layout_width="match_parent" android:layout_height="50" android:text="Message: %s" android:textAppearance="?android:attr/textAppearanceLarge" android:gravity="center_vertical|center_horizontal|center"> </TextView>""" % message ) else: message_view = "" return make_layout( """ %s %s %s <ImageView android:id="@+id/qrView" android:gravity="center" android:layout_width="match_parent" android:layout_height="350" android:antialias="false" android:src="file:///sdcard/sl4a/qrcode.bmp" /> """ % (addr_view, amount_view, message_view), True, )
def print_history(self): lines = self.wallet.get_tx_history() b = 0 i = 0 for i in range(20): if i < len(lines): line = lines[i] v = line['value'] b += v try: time_str = str( datetime.datetime.fromtimestamp( line['timestamp'])) except: print line['timestamp'] time_str = 'pending' label = line.get('label') if not label: label = line['tx_hash'] else: label = label + ' '*(64 - len(label) ) msg = time_str + " " + label + " " + format_satoshis(v)+ " "+ format_satoshis(b) else: msg = "" msg += " "*(WIDTH - len(msg)) self.stdscr.addstr( i+2, 1, msg[0:WIDTH])
def qr_layout(addr, amount, message): addr_view = """ <TextView android:id="@+id/addrTextView" android:layout_width="match_parent" android:layout_height="50" android:text="%s" android:textAppearance="?android:attr/textAppearanceLarge" android:gravity="center_vertical|center_horizontal|center"> </TextView>""" % addr if amount: amount_view = """ <TextView android:id="@+id/amountTextView" android:layout_width="match_parent" android:layout_height="50" android:text="Amount: %s" android:textAppearance="?android:attr/textAppearanceLarge" android:gravity="center_vertical|center_horizontal|center"> </TextView>""" % format_satoshis(amount) else: amount_view = "" if message: message_view = """ <TextView android:id="@+id/messageTextView" android:layout_width="match_parent" android:layout_height="50" android:text="Message: %s" android:textAppearance="?android:attr/textAppearanceLarge" android:gravity="center_vertical|center_horizontal|center"> </TextView>""" % message else: message_view = "" return make_layout( """ %s %s %s <ImageView android:id="@+id/qrView" android:gravity="center" android:layout_width="match_parent" android:layout_height="350" android:antialias="false" android:src="file:///sdcard/sl4a/qrcode.bmp" /> """ % (addr_view, amount_view, message_view), True)
def get_history_values(n): values = [] h = wallet.get_history() length = min(n, len(h)) for i in range(length): tx_hash, conf, value, timestamp, balance = h[-i-1] try: dt = datetime.datetime.fromtimestamp( timestamp ) if dt.date() == dt.today().date(): time_str = str( dt.time() ) else: time_str = str( dt.date() ) except Exception: time_str = 'pending' conf_str = 'v' if conf else 'o' label, is_default_label = wallet.get_label(tx_hash) label = label.replace('<','').replace('>','') values.append((conf_str, ' ' + time_str, ' ' + format_satoshis(value, True), ' ' + label)) return values
def get_history_values(n): values = [] h = wallet.get_history() length = min(n, len(h)) for i in range(length): tx_hash, conf, value, timestamp, balance = h[-i - 1] try: dt = datetime.datetime.fromtimestamp(timestamp) if dt.date() == dt.today().date(): time_str = str(dt.time()) else: time_str = str(dt.date()) except Exception: time_str = "pending" conf_str = "v" if conf else "o" label = wallet.get_label(tx_hash) label = label.replace("<", "").replace(">", "") values.append((conf_str, " " + time_str, " " + format_satoshis(value, True), " " + label)) return values
def get_history_values(n): values = [] h = wallet.get_tx_history() length = min(n, len(h)) for i in range(length): tx_hash, conf, is_mine, value, fee, balance, timestamp = h[-i-1] try: dt = datetime.datetime.fromtimestamp( timestamp ) if dt.date() == dt.today().date(): time_str = str( dt.time() ) else: time_str = str( dt.date() ) except: time_str = 'pending' conf_str = 'v' if conf else 'o' label, is_default_label = wallet.get_label(tx_hash) values.append((conf_str, ' ' + time_str, ' ' + format_satoshis(value,True), ' ' + label )) return values
def main(self): add_menu() welcome = "Use the menu to scan a transaction." droid.fullShow(qr_layout(welcome)) while True: event = droid.eventWait().result if not event: continue elif event["name"] == "key": if event["data"]["key"] == "4": if self.qr_data: self.show_qr(None) self.show_title(welcome) else: break elif event["name"] == "seed": password = self.get_password() if password is False: modal_dialog("Error", "incorrect password") continue seed = wallet.get_mnemonic(password) modal_dialog("Your seed is", seed) elif event["name"] == "password": self.change_password_dialog() elif event["name"] == "xpub": mpk = wallet.get_master_public_key() self.show_qr(mpk) self.show_title("master public key") elif event["name"] == "scan": r = droid.scanBarcode() r = r.result if not r: continue data = r["extras"]["SCAN_RESULT"] data = base_decode(data.encode("utf8"), None, base=43) data = "".join(chr(ord(b)) for b in data).encode("hex") tx = Transaction(data) # except: # modal_dialog('Error', 'Cannot parse transaction') # continue if not wallet.can_sign(tx): modal_dialog("Error", "Cannot sign this transaction") continue lines = map(lambda x: x[0] + u"\t\t" + format_satoshis(x[1]) if x[1] else x[0], tx.get_outputs()) if not modal_question("Sign?", "\n".join(lines)): continue password = self.get_password() if password is False: modal_dialog("Error", "incorrect password") continue droid.dialogCreateSpinnerProgress("Signing") droid.dialogShow() wallet.sign_transaction(tx, password) droid.dialogDismiss() data = base_encode(str(tx).decode("hex"), base=43) self.show_qr(data) self.show_title("Signed Transaction") droid.makeToast("Bye!")
def main(self): add_menu() welcome = 'Use the menu to scan a transaction.' droid.fullShow(qr_layout(welcome)) while True: event = droid.eventWait().result if not event: continue elif event["name"] == "key": if event["data"]["key"] == '4': if self.qr_data: self.show_qr(None) self.show_title(welcome) else: break elif event["name"] == "seed": password = self.get_password() if password is False: modal_dialog('Error', 'incorrect password') continue seed = wallet.get_mnemonic(password) modal_dialog('Your seed is', seed) elif event["name"] == "password": self.change_password_dialog() elif event["name"] == "xpub": mpk = wallet.get_master_public_key() self.show_qr(mpk) self.show_title('master public key') elif event["name"] == "scan": r = droid.scanBarcode() r = r.result if not r: continue data = r['extras']['SCAN_RESULT'] data = base_decode(data.encode('utf8'), None, base=43) data = ''.join(chr(ord(b)) for b in data).encode('hex') tx = Transaction(data) #except: # modal_dialog('Error', 'Cannot parse transaction') # continue if not wallet.can_sign(tx): modal_dialog('Error', 'Cannot sign this transaction') continue lines = map( lambda x: x[0] + u'\t\t' + format_satoshis(x[1]) if x[1] else x[0], tx.get_outputs()) if not modal_question('Sign?', '\n'.join(lines)): continue password = self.get_password() if password is False: modal_dialog('Error', 'incorrect password') continue droid.dialogCreateSpinnerProgress("Signing") droid.dialogShow() wallet.sign_transaction(tx, password) droid.dialogDismiss() data = base_encode(str(tx).decode('hex'), base=43) self.show_qr(data) self.show_title('Signed Transaction') droid.makeToast("Bye!")