2023-11-08 03:08:49 +00:00
|
|
|
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
|
|
|
|
import json
|
|
|
|
|
2023-11-08 20:40:42 +00:00
|
|
|
# Read the RPC configuration from the configuration file
|
2023-11-08 03:08:49 +00:00
|
|
|
with open("rpc_config.json", "r") as config_file:
|
|
|
|
config = json.load(config_file)
|
|
|
|
|
|
|
|
rpc_host = config["rpc_host"]
|
|
|
|
rpc_port = config["rpc_port"]
|
|
|
|
rpc_user = config["rpc_user"]
|
|
|
|
rpc_password = config["rpc_password"]
|
|
|
|
|
|
|
|
try:
|
|
|
|
rpc_connection = AuthServiceProxy(
|
|
|
|
f"http://{rpc_user}:{rpc_password}@{rpc_host}:{rpc_port}"
|
|
|
|
)
|
|
|
|
|
|
|
|
# List available wallets
|
|
|
|
wallet_list = rpc_connection.listwallets()
|
|
|
|
|
|
|
|
if not wallet_list:
|
|
|
|
print("No wallets found.")
|
|
|
|
else:
|
2023-11-08 20:40:42 +00:00
|
|
|
print("Available wallets:")
|
|
|
|
for i, wallet in enumerate(wallet_list):
|
|
|
|
print(f"{i + 1}. {wallet}")
|
|
|
|
|
|
|
|
wallet_index = int(input("Enter the number of the wallet to get a new address for: ")) - 1
|
|
|
|
|
|
|
|
if 0 <= wallet_index < len(wallet_list):
|
|
|
|
wallet_name = wallet_list[wallet_index]
|
|
|
|
|
|
|
|
# Get a new address for the selected wallet
|
|
|
|
new_address = rpc_connection.getnewaddress(wallet_name)
|
|
|
|
print(f"New receiving address for wallet '{wallet_name}': {new_address}")
|
2023-11-08 03:08:49 +00:00
|
|
|
else:
|
2023-11-08 20:40:42 +00:00
|
|
|
print("Invalid wallet selection. Exiting.")
|
|
|
|
exit()
|
2023-11-08 03:08:49 +00:00
|
|
|
|
|
|
|
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))
|