contruct more advanced txs WIP
This commit is contained in:
parent
b25ffc1b41
commit
fc7c2cc439
@ -1,130 +1,112 @@
|
|||||||
|
## 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
|
||||||
|
|
||||||
# Read the RPC configuration from the configuration file
|
# Read the RPC configuration from the configuration file
|
||||||
rpc_host, rpc_port, rpc_user, rpc_password = read_rpc_config()
|
rpc_host, rpc_port, rpc_user, rpc_password = read_rpc_config()
|
||||||
|
|
||||||
|
try:
|
||||||
|
# Initial connection to list available wallets
|
||||||
|
rpc_connection_list_wallets = AuthServiceProxy(
|
||||||
|
f"http://{rpc_user}:{rpc_password}@{rpc_host}:{rpc_port}"
|
||||||
|
)
|
||||||
|
|
||||||
def send_to_address():
|
wallet_list = rpc_connection_list_wallets.listwallets()
|
||||||
try:
|
|
||||||
# Initial connection to list available wallets
|
|
||||||
rpc_connection_list_wallets = AuthServiceProxy(
|
|
||||||
f"http://{rpc_user}:{rpc_password}@{rpc_host}:{rpc_port}"
|
|
||||||
)
|
|
||||||
|
|
||||||
wallet_list = rpc_connection_list_wallets.listwallets()
|
if not wallet_list:
|
||||||
|
print("No wallets found.")
|
||||||
if not wallet_list:
|
else:
|
||||||
print("No wallets found.")
|
if len(wallet_list) == 1:
|
||||||
|
# If there's only one wallet, use it
|
||||||
|
wallet_name = wallet_list[0]
|
||||||
else:
|
else:
|
||||||
if len(wallet_list) == 1:
|
# If multiple wallets exist, prompt the user to select one
|
||||||
# If there's only one wallet, use it
|
print("Available wallets:")
|
||||||
wallet_name = wallet_list[0]
|
for i, wallet in enumerate(wallet_list):
|
||||||
|
print(f"{i + 1}. {wallet}")
|
||||||
|
|
||||||
|
wallet_index = (
|
||||||
|
int(input("Enter the number of the wallet to send from: ")) - 1
|
||||||
|
)
|
||||||
|
|
||||||
|
if 0 <= wallet_index < len(wallet_list):
|
||||||
|
wallet_name = wallet_list[wallet_index]
|
||||||
else:
|
else:
|
||||||
# If multiple wallets exist, prompt the user to select one
|
print("Invalid wallet selection. Exiting.")
|
||||||
print("Available wallets:")
|
exit()
|
||||||
for i, wallet in enumerate(wallet_list):
|
|
||||||
print(f"{i + 1}. {wallet}")
|
|
||||||
|
|
||||||
wallet_index = (
|
# Connection to the specific wallet
|
||||||
int(input("Enter the number of the wallet to send from: ")) - 1
|
rpc_connection = AuthServiceProxy(
|
||||||
)
|
f"http://{rpc_user}:{rpc_password}@{rpc_host}:{rpc_port}/wallet/{wallet_name}"
|
||||||
|
)
|
||||||
|
|
||||||
if 0 <= wallet_index < len(wallet_list):
|
# Prompt the user for the receiving address
|
||||||
wallet_name = wallet_list[wallet_index]
|
destination_address = input("Enter the receiving address: ")
|
||||||
else:
|
|
||||||
print("Invalid wallet selection. Exiting.")
|
|
||||||
exit()
|
|
||||||
|
|
||||||
# Connection to the specific wallet
|
if not rpc_connection.validateaddress(destination_address)["isvalid"]:
|
||||||
rpc_connection = AuthServiceProxy(
|
print("Invalid destination address. Exiting.")
|
||||||
f"http://{rpc_user}:{rpc_password}@{rpc_host}:{rpc_port}/wallet/{wallet_name}"
|
exit()
|
||||||
)
|
|
||||||
|
|
||||||
# Prompt the user for the receiving address
|
# Get the asset name you want to send
|
||||||
destination_address = input("Enter the receiving address: ")
|
asset_name = input("Enter the asset name (e.g., demoasset): ")
|
||||||
|
|
||||||
if not rpc_connection.validateaddress(destination_address)["isvalid"]:
|
# Get the amount to send
|
||||||
print("Invalid destination address. Exiting.")
|
amount = float(input(f"Enter the amount of {asset_name} to send: "))
|
||||||
exit()
|
|
||||||
|
|
||||||
# Get the asset name you want to send
|
# Additional options
|
||||||
asset_name = input("Enter the asset name (e.g., demoasset): ")
|
comment = input("Enter a comment for the transaction (optional): ")
|
||||||
|
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"
|
||||||
|
|
||||||
# Get the amount to send
|
# Build the transaction
|
||||||
amount = float(input(f"Enter the amount of {asset_name} to send: "))
|
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,
|
||||||
|
)
|
||||||
|
|
||||||
# Additional options
|
if verbose:
|
||||||
comment = input("Enter a comment for the transaction (optional): ")
|
print("Transaction Details:")
|
||||||
comment_to = input("Enter a comment for the recipient (optional): ")
|
print(tx_result)
|
||||||
subtract_fee_from_amount = (
|
else:
|
||||||
input("Subtract fee from amount? (true/false, optional): ").lower()
|
print(f"Transaction sent. Transaction ID: {tx_result}")
|
||||||
== "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
|
except JSONRPCException as json_exception:
|
||||||
tx_result = rpc_connection.sendtoaddress(
|
print("A JSON RPC Exception occurred: " + str(json_exception))
|
||||||
destination_address,
|
except Exception as general_exception:
|
||||||
amount,
|
print("An Exception occurred: " + str(general_exception))
|
||||||
comment,
|
|
||||||
comment_to,
|
|
||||||
subtract_fee_from_amount,
|
|
||||||
replaceable,
|
|
||||||
conf_target,
|
|
||||||
estimate_mode,
|
|
||||||
avoid_reuse,
|
|
||||||
asset_label,
|
|
||||||
ignore_blind_fail,
|
|
||||||
fee_rate,
|
|
||||||
verbose,
|
|
||||||
)
|
|
||||||
|
|
||||||
if verbose:
|
|
||||||
print("Transaction Details:")
|
|
||||||
print(tx_result)
|
|
||||||
else:
|
|
||||||
print(f"Transaction sent. Transaction ID: {tx_result}")
|
|
||||||
|
|
||||||
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))
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
# Retry the operation up to 3 times
|
|
||||||
for _ in range(3):
|
|
||||||
try:
|
|
||||||
send_to_address()
|
|
||||||
break # Break out of the loop if successful
|
|
||||||
except JSONRPCException as e:
|
|
||||||
print(f"Error: {e}. Retrying...")
|
|
||||||
except Exception as e:
|
|
||||||
print(f"An unexpected error occurred: {e}. Retrying...")
|
|
||||||
|
Loading…
Reference in New Issue
Block a user