createwallet reverted to working script via cli

This commit is contained in:
0ceanSlim 2023-12-19 20:46:51 -05:00
parent b6b061b945
commit f7d46b6b41

View File

@ -1,35 +1,43 @@
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
from util.rpcHandler import read_rpc_config
from util.rpcHandler import read_rpc_config, create_rpc_connection
from mnemonic import Mnemonic
def create_wallet(wallet_name):
rpc_host, rpc_port, rpc_user, rpc_password = read_rpc_config()
# Read the RPC configuration from the configuration file
rpc_host, rpc_port, rpc_user, rpc_password = read_rpc_config()
try:
rpc_connection = AuthServiceProxy(
f"http://{rpc_user}:{rpc_password}@{rpc_host}:{rpc_port}"
)
# Prompt the user for the wallet name
wallet_name = input("Enter the wallet name to create: ")
wallet_info = rpc_connection.listwallets()
try:
rpc_connection = AuthServiceProxy(
f"http://{rpc_user}:{rpc_password}@{rpc_host}:{rpc_port}"
)
if wallet_name not in wallet_info:
rpc_connection.createwallet(wallet_name)
return f"Wallet '{wallet_name}' created successfully."
else:
return f"Wallet '{wallet_name}' already exists."
except JSONRPCException as json_exception:
return "A JSON RPC Exception occurred: " + str(json_exception)
except Exception as general_exception:
return "An Exception occurred: " + str(general_exception)
# Check if the wallet already exists
wallet_info = rpc_connection.listwallets()
def generate_seed(seed_length):
try:
if seed_length == '12' or seed_length == '24':
entropy_bits = 128 if seed_length == '12' else 256
# If the wallet doesn't exist, create it
if wallet_name not in wallet_info:
rpc_connection.createwallet(wallet_name)
print(f"Wallet '{wallet_name}' created successfully.")
# Prompt the user for seed phrase length preference
seed_length = input("Choose seed phrase length (12 or 24 words): ")
if seed_length == "12" or seed_length == "24":
entropy_bits = 128 if seed_length == "12" else 256
mnemonic = Mnemonic("english")
seed_words = mnemonic.generate(entropy_bits)
return seed_words
print("Write down these seed words:")
print(seed_words)
else:
return "Invalid choice. Please choose 12 or 24."
except Exception as e:
return "An error occurred while generating the seed phrase: " + str(e)
print("Invalid choice. Please choose 12 or 24.")
# You might want to save or display these seed words securely for the user
else:
print(f"Wallet '{wallet_name}' already exists.")
except JSONRPCException as json_exception:
print("A JSON RPC Exception occurred: " + str(json_exception))
except Exception as general_exception:
print("An Exception occurred: " + str(general_exception))