def message(self, msg): if msg['type'] == 'normal': try: req = json.loads(msg['body']) if req['TYPE'] == 'PAYMENT': try: p1, p2, p3, addr = req['DATA']['PATH'].split('/') frm, to = msg['from'].bare, self.boundjid.bare if Btclib.pubkey_to_address(Btclib.bip32_extract_key(Btclib.subkey_for_path(bppclient.mpkbtc, p1+'/'+p2+'/'+p3))) != addr: return if req['DATA']['TXIN'] in bppclient.pendpayhist: return if req['DATA']['TXIN'] in map(lambda x:x[0], bppclient.confpayhist): return invoke_gui(insertPendPay, (req['DATA']['TXIN'],req['DATA']['PATH'],frm,to,req['DATA']['REF'],req['DATA']['RETADDR'])) bppclient.pendpayhist[req['DATA']['TXIN']] = (req['DATA']['PATH'],frm,to,req['DATA']['REF'],req['DATA']['RETADDR']) bppclient.wallet.import_key_bip32(addr, p1+'/'+p2+'/'+p3, None) except: return except ValueError: return
def sendpay(): sendaddr = bppclient.ui.sendaddr.text().split('&') sendval = bppclient.ui.sendval.text() sendref = bppclient.ui.sendref.text() if len(sendaddr) == 2: check = '1'+sendaddr[1] else: check = '1'+sendaddr[0].split('@')[0] sendaddr = sendaddr[0] try: #Bitcoin Address if Btclib.get_version_byte(sendaddr) == 0: check = 'B' except AssertionError: pass if not '@' in sendaddr and check != 'B': QtGui.QMessageBox.warning(bppclient, 'Payment', "%s is not a BPP valid address." % sendaddr, QtGui.QMessageBox.Ok) return try: #BPP ID if check != 'B' and Btclib.get_version_byte(check) != 0: check = "" except AssertionError: check = "" if check == "": if QtGui.QMessageBox.Cancel == QtGui.QMessageBox.warning(bppclient, 'Payment', "There are not a valid security code entered. Do you want to send the payment without asserting the destination address ?", QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel): return try: result = json.loads(bppclient.bppcnx['xep_0054'].get_vcard(sendaddr)['vcard_temp']['NOTE']) if check != 'B' else None if check != "" and check != 'B' and Btclib.hex_to_b58check(Btclib.ecdsa_recover(str(result['BITCOIN_MPK']), str(result['BITCOIN_SIGN']))[2:32]) != check: QtGui.QMessageBox.critical(bppclient, 'Payment', "The security of the payment address is corrupted.", QtGui.QMessageBox.Ok) return try: amount = int(Decimal(sendval) * 100000000) if amount == 0: raise Exception except Exception: QtGui.QMessageBox.warning(bppclient, 'Payment', "Invalid Amount.", QtGui.QMessageBox.Ok) return if check != 'B': p1, p2, mpk = result['BITCOIN_MPK'].split('/') p3 = random.randrange(2**31-1) addr = Btclib.pubkey_to_address(Btclib.bip32_extract_key(Btclib.bip32_ckd(mpk, p3))) if check != 'B' else sendaddr try: tx = bppclient.wallet.mktx([(addr,amount)],None) except ValueError: QtGui.QMessageBox.warning(bppclient, 'Payment', "Not enough funds.", QtGui.QMessageBox.Ok) return txin = tx.inputs[0].get('prevout_hash') if check != 'B': paymsg = json.dumps({"TYPE" : "PAYMENT", "DATA" : {"PATH" : p1+'/'+p2+'/'+str(p3)+'/'+addr, "TXIN" : txin, "REF" : sendref, "RETADDR" : bppclient.ui.bppidsec.text()}}) bppclient.bppcnx.send_message(mto=sendaddr, mbody=paymsg) insertPendPay((txin,p1+'/'+p2+'/'+str(p3)+'/'+addr,bppclient.bppcnx.boundjid.bare,sendaddr,sendref,bppclient.ui.bppidsec.text()),) bppclient.pendpayhist[txin] = (p1+'/'+p2+'/'+str(p3)+'/'+addr,bppclient.bppcnx.boundjid.bare,sendaddr,sendref,bppclient.ui.bppidsec.text()) else: insertPendPay((txin,'',tx.inputs[0].get('address'),addr,sendref,''),) bppclient.pendpayhist[txin] = ('',tx.inputs[0].get('address'),addr,sendref,'') g, o = bppclient.wallet.sendtx(tx) if g: QtGui.QMessageBox.information(bppclient, 'Payment', "Your payment have been sent.", QtGui.QMessageBox.Ok) else: QtGui.QMessageBox.information(bppclient, 'Payment', o, QtGui.QMessageBox.Ok) except (sleekxmpp.exceptions.XMPPError, KeyError, TypeError): QtGui.QMessageBox.warning(bppclient, 'Payment', "%s is not a BPP valid address." % sendaddr, QtGui.QMessageBox.Ok) return