This commit is contained in:
0ceanSlim 2023-11-13 07:49:59 -05:00
commit 4485cc15a0
4 changed files with 123 additions and 18 deletions

BIN
cli.exe

Binary file not shown.

51
src/getWalletInfo.py Normal file
View File

@ -0,0 +1,51 @@
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
from util.rpcHandler import read_rpc_config, create_rpc_connection
# 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}"
)
# List available wallets
wallet_list = rpc_connection.listwallets()
if not wallet_list:
print("No wallets found.")
else:
if len(wallet_list) == 1:
# If there's only one wallet, use it
wallet_name = wallet_list[0]
else:
# If multiple wallets exist, prompt the user to select one
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 check balances for: ")) - 1
)
if 0 <= wallet_index < len(wallet_list):
wallet_name = wallet_list[wallet_index]
else:
print("Invalid wallet selection. Exiting.")
exit()
# Connect to the selected wallet by specifying the wallet file name
rpc_wallet_connection = AuthServiceProxy(
f"http://{rpc_user}:{rpc_password}@{rpc_host}:{rpc_port}/wallet/{wallet_name}"
)
# Get wallet information using getwalletinfo
wallet_info = rpc_wallet_connection.getwalletinfo()
print(f"Wallet Info for '{wallet_name}':")
print(wallet_info)
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))

View File

@ -1,15 +1,22 @@
def help(): def help():
print("\nAvailable Commands:")
try: print("createWallet - Create a Wallet on your Elements Node")
print("\nAvailable Commands:") print("getBlockchainInfo - Retrieve the current Blockchian Info")
print("createWallet - Create a Wallet on your Elements Node") print(
print("getBlockchainInfo - Retrieve the current Blockchian Info") "getNewAddress - Prompts for wallet selection, then generates a new receiving address"
print("getNewAddress - Prompts for wallet selection, then generates a new receiving address") )
print("listTransactions - Prompts for wallet selection, then lists all the transactions made in the selected wallet") print(
print("listUnspent - Prompts for wallet selection, then lists the selected wallet's asset balances") "getWalletInfo - prompts for wallet selection, then retrieves all information for the chosen wallet"
print("listWallets - Lists all the Wallets that exist on your Elements Node") )
print("sendToAddress - Create and sign a new transaction to send assets from the selected Wallet") print(
print("help - Display available commands") "listTransactions - Prompts for wallet selection, then lists all the transactions made in the selected wallet"
print("exit - Quit the program\n") )
except Exception as e: print(
print("An error occurred:", str(e)) "listUnspent - Prompts for wallet selection, then lists the selected wallet's asset balances"
)
print("listWallets - Lists all the Wallets that exist on your Elements Node")
print(
"sendToAddress - Create and sign a new transaction to send assets from the selected Wallet"
)
print("help - Display available commands")
print("exit - Quit the program\n")

View File

@ -1,3 +1,6 @@
## Last working script version
## https://git.happytavern.co/OceanSlim/elements.py/src/commit/3eb6d6022418a349152a5c51464a0ac11d31fa9e/src/sendToAddress.py
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
from util.rpcHandler import read_rpc_config, create_rpc_connection from util.rpcHandler import read_rpc_config, create_rpc_connection
@ -52,12 +55,56 @@ try:
# Get the amount to send # Get the amount to send
amount = float(input(f"Enter the amount of {asset_name} to send: ")) amount = float(input(f"Enter the amount of {asset_name} to send: "))
# Send the asset to the destination address # Additional options
txid = rpc_connection.sendtoaddress( comment = input("Enter a comment for the transaction (optional): ")
destination_address, amount, asset_name, "", False, True, 1 comment_to = input("Enter a comment for the recipient (optional): ")
subtract_fee_from_amount = (
input("Subtract fee from amount? (true/false, optional): ").lower() == "true"
)
replaceable = (
input("Enable BIP125 replaceable? (true/false, optional): ").lower() == "true"
)
conf_target = int(input("Enter confirmation target in blocks (optional): ") or 0)
estimate_mode = (
input("Enter fee estimate mode (unset/economical/conservative, optional): ")
or "unset"
)
avoid_reuse = (
input("Avoid spending from dirty addresses? (true/false, optional): ").lower()
== "true"
)
asset_label = (
input("Enter hex asset id or asset label for balance (optional): ") or None
)
ignore_blind_fail = (
input("Ignore blinding failure? (true/false, optional): ").lower() == "true"
)
fee_rate = float(input("Enter fee rate in sat/vB (optional): ") or 0)
verbose = input("Enable verbose mode? (true/false, optional): ").lower() == "true"
# Build the transaction
tx_result = rpc_connection.sendtoaddress(
destination_address,
amount,
asset_name,
comment,
comment_to,
subtract_fee_from_amount,
replaceable,
conf_target,
estimate_mode,
avoid_reuse,
asset_label,
ignore_blind_fail,
fee_rate,
verbose,
) )
print(f"Asset sent. Transaction ID: {txid}") if verbose:
print("Transaction Details:")
print(tx_result)
else:
print(f"Transaction sent. Transaction ID: {tx_result}")
except JSONRPCException as json_exception: except JSONRPCException as json_exception:
print("A JSON RPC Exception occurred: " + str(json_exception)) print("A JSON RPC Exception occurred: " + str(json_exception))