From 36de0216caa3ee5a946ed651bc06aa86521f09f9 Mon Sep 17 00:00:00 2001 From: Dylan Janssen <dylan.janssen31@gmail.com> Date: Wed, 30 Mar 2022 11:43:01 +0200 Subject: [PATCH] Add: generalization for creating name of wallet --- commands.py | 7 ++++--- util.py | 5 ++++- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/commands.py b/commands.py index 96d5d9a..1517d21 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 782181a..0fadef2 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), -- GitLab