Merge branch 'main' of https://git.happytavern.co/oceanslim/elements.py
This commit is contained in:
commit
4485cc15a0
51
src/getWalletInfo.py
Normal file
51
src/getWalletInfo.py
Normal 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))
|
23
src/help.py
23
src/help.py
@ -1,15 +1,22 @@
|
|||||||
def help():
|
def help():
|
||||||
|
|
||||||
try:
|
|
||||||
print("\nAvailable Commands:")
|
print("\nAvailable Commands:")
|
||||||
print("createWallet - Create a Wallet on your Elements Node")
|
print("createWallet - Create a Wallet on your Elements Node")
|
||||||
print("getBlockchainInfo - Retrieve the current Blockchian Info")
|
print("getBlockchainInfo - Retrieve the current Blockchian Info")
|
||||||
print("getNewAddress - Prompts for wallet selection, then generates a new receiving address")
|
print(
|
||||||
print("listTransactions - Prompts for wallet selection, then lists all the transactions made in the selected wallet")
|
"getNewAddress - Prompts for wallet selection, then generates a new receiving address"
|
||||||
print("listUnspent - Prompts for wallet selection, then lists the selected wallet's asset balances")
|
)
|
||||||
|
print(
|
||||||
|
"getWalletInfo - prompts for wallet selection, then retrieves all information for the chosen wallet"
|
||||||
|
)
|
||||||
|
print(
|
||||||
|
"listTransactions - Prompts for wallet selection, then lists all the transactions made in the selected wallet"
|
||||||
|
)
|
||||||
|
print(
|
||||||
|
"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("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(
|
||||||
|
"sendToAddress - Create and sign a new transaction to send assets from the selected Wallet"
|
||||||
|
)
|
||||||
print("help - Display available commands")
|
print("help - Display available commands")
|
||||||
print("exit - Quit the program\n")
|
print("exit - Quit the program\n")
|
||||||
except Exception as e:
|
|
||||||
print("An error occurred:", str(e))
|
|
@ -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))
|
||||||
|
Loading…
Reference in New Issue
Block a user