diff --git a/commands.py b/commands.py index 96d5d9a82a0954fa412e2204d10a0786a4331a9d..1517d21fa5ee805b0c33f018193f51bc075d0b0f 100644 --- a/commands.py +++ b/commands.py @@ -3,7 +3,7 @@ from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup from telegram.ext import CallbackContext from database import AppUser, AppState, AppWallet, AppWalletRequest, AppUserWallet -from util import generate_wallets +from util import generate_wallets, get_wallet_name def generate_message(state_id, extra_menu=None): @@ -83,14 +83,15 @@ def choose_wallet(update: Update, context: CallbackContext): user = AppUser.get(telegram_id=telegram_user.id, nickname=telegram_user.full_name) user_wallets = AppUserWallet.select().where(AppUserWallet.user_id == user) user.set_state(5) - menu = [[InlineKeyboardButton(uw.wallet_id.name, callback_data=uw.wallet_id.name)] for uw in user_wallets] + menu = [[InlineKeyboardButton(uw.wallet_id.name, callback_data=get_wallet_name(uw.wallet_id.id, uw.user_id.id))] for uw in user_wallets] reply_msg, reply_markup = generate_message(5, menu) update.effective_message.reply_text(reply_msg, reply_markup=reply_markup) pass def wallet_options(update: Update, context: CallbackContext, user: AppUser): - print("We are in the wallet options") + query = update.callback_query.data + print("We are in the wallet options: " + query) next_state = user.next_state() reply_msg, reply_markup = generate_message(next_state) update.effective_message.reply_text(reply_msg, reply_markup=reply_markup) diff --git a/util.py b/util.py index 782181a473adc177796b1cf702977b0a59de34ec..0fadef2a584976389c145ed9236ca61b696af74c 100644 --- a/util.py +++ b/util.py @@ -6,6 +6,9 @@ from bitcoinlib.wallets import Wallet import database +def get_wallet_name(wallet_id, user_id): + return "wallet_{}user_{}".format(wallet_id, user_id) + def generate_klist(hd_keys, private): return [hd_keys[x] if x == private else hd_keys[x].public_master_multisig() for x in range(len(hd_keys))] @@ -24,7 +27,7 @@ def generate_wallets(user_wallets): wallets = [] for i in range(count): uw = user_wallets[i] - wallet_name = "wallet_{}user_{}_{}".format(uw.wallet_id, uw.user_id,i) + wallet_name = get_wallet_name(uw.wallet_id.id,uw.user_id.id) wallet = Wallet.create(wallet_name, sigs_required=uw.wallet_id.min_co_signers, keys=generate_klist(hd_keys, i),