def balance(update, context): user = update.message.from_user id = user.id mydb = connectMeToDB() mycursor = mydb.cursor() mycursor.execute("SELECT * FROM wallets where user="******"" if len(myresult) == 0: message = "\U0001F6D1 Use command /wallet to create new address" else: data = myresult[0]; privateKey = data[3] myAddress = pw.Address(privateKey=privateKey) message = "\U0001F4B0 Balance is " + str(myAddress.balance()/(100000000)) + " WAVES" update.message.reply_text(message) mycursor.close() mydb.close()
def privatekey(update, context): user = update.message.from_user id = user.id mydb = connectMeToDB() mycursor = mydb.cursor() mycursor.execute("SELECT * FROM wallets where user="******"" if len(myresult) == 0: message = "\U0001F6D1 Use command /wallet to create new address" else: data = myresult[0]; message = "Your private key is \n\n" + data[3] + "\n\n\U0000203C Keep safe \U0000203C" update.message.reply_text(message) mycursor.close() mydb.close()
def send(update, context): user = update.message.from_user id = user.id mydb = connectMeToDB() mycursor = mydb.cursor() mycursor.execute("SELECT * FROM wallets where user="******"" if len(myresult) == 0: message = "\U0001F6D1 Use command /wallet to create new address" update.message.reply_text(message) return if len(context.args) != 2: message = "\U0001F6D1 For send WAVES use command \n/send <Address> <Amount>" update.message.reply_text(message) return address = context.args[0] amount = context.args[1] if not pw.validateAddress(address): message = "\U0001F6D1 Address is not valid. Please check!" update.message.reply_text(message) return amount_f = 0 try: amount_f = float(amount) except: message = "\U0001F6D1 Valid format for amount is 1 or 1.0" update.message.reply_text(message) return error_mess = "" real_amount = int(amount_f * (100000000)) #remove all past payments sql = "DELETE FROM payments WHERE user = "******"INSERT INTO payments(user, address, amount) VALUES(%s, %s, %s)" data = (str(id), address, real_amount) mycursor.execute(sql, data) mydb.commit() message = "\U0001F195 New transation\n\nRecepient\n\U0001F194 " + address + "\nAmount\n\U0001F4B8 " + str(amount_f) + " WAVES\n\nUse /confirm to send transaction to blockchain." update.message.reply_text(message) mycursor.close() mydb.close()
def confirm(update, context): user = update.message.from_user id = user.id mydb = connectMeToDB() mycursor = mydb.cursor() mycursor.execute("SELECT * FROM payments where user="******"" if len(myresult) == 0: message = "\U00002714 All payments was complete!" update.message.reply_text(message) return data = myresult[0]; address = data[2] amount = data[3] mycursor.execute("SELECT * FROM wallets where user="******"\U000023F3 Trying send WAVES..." update.message.reply_text(message) try: result = myAddress.sendWaves(recipient = pw.Address(address), amount = int(amount)) message = "\U00002714 Success!\nTX=" + result['id'] + "\ncompleted!" update.message.reply_text(message) success = 1 except Exception as e: update.message.reply_text(str(e)) #remove all past payments if success == 1: sql = "DELETE FROM payments WHERE user = " + str(id) mycursor.execute(sql) mydb.commit() mycursor.close() mydb.close()
def wallet(update, context): user = update.message.from_user id = user.id mydb = connectMeToDB() mycursor = mydb.cursor() mycursor.execute("SELECT * FROM wallets where user="******"" if len(myresult) == 0: message = "no wallet" seed = generatePhrase() myAddress = pw.Address(seed=seed) message = myAddress.address sql = "INSERT INTO wallets(user, address, privatkey) VALUES(%s, %s, %s)" data = (str(id), myAddress.address, myAddress.privateKey) mycursor.execute(sql, data) mydb.commit() message = "Congratulations!\nYou get new address\n\n\U0001F194 " + myAddress.address else: data = myresult[0]; message = "Your address \n\n\U0001F194 " + data[2] update.message.reply_text(message) mycursor.close() mydb.close()