contruct more advanced txs WIP

This commit is contained in:
0ceanSlim 2023-11-11 12:16:48 -05:00
parent b25ffc1b41
commit fc7c2cc439

View File

@ -1,12 +1,13 @@
## 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:
def send_to_address():
try:
# Initial connection to list available wallets # Initial connection to list available wallets
rpc_connection_list_wallets = AuthServiceProxy( rpc_connection_list_wallets = AuthServiceProxy(
f"http://{rpc_user}:{rpc_password}@{rpc_host}:{rpc_port}" f"http://{rpc_user}:{rpc_password}@{rpc_host}:{rpc_port}"
@ -58,24 +59,18 @@ def send_to_address():
comment = input("Enter a comment for the transaction (optional): ") comment = input("Enter a comment for the transaction (optional): ")
comment_to = input("Enter a comment for the recipient (optional): ") comment_to = input("Enter a comment for the recipient (optional): ")
subtract_fee_from_amount = ( subtract_fee_from_amount = (
input("Subtract fee from amount? (true/false, optional): ").lower() input("Subtract fee from amount? (true/false, optional): ").lower() == "true"
== "true"
) )
replaceable = ( replaceable = (
input("Enable BIP125 replaceable? (true/false, optional): ").lower() input("Enable BIP125 replaceable? (true/false, optional): ").lower() == "true"
== "true"
)
conf_target = int(
input("Enter confirmation target in blocks (optional): ") or 0
) )
conf_target = int(input("Enter confirmation target in blocks (optional): ") or 0)
estimate_mode = ( estimate_mode = (
input("Enter fee estimate mode (unset/economical/conservative, optional): ") input("Enter fee estimate mode (unset/economical/conservative, optional): ")
or "unset" or "unset"
) )
avoid_reuse = ( avoid_reuse = (
input( input("Avoid spending from dirty addresses? (true/false, optional): ").lower()
"Avoid spending from dirty addresses? (true/false, optional): "
).lower()
== "true" == "true"
) )
asset_label = ( asset_label = (
@ -85,14 +80,13 @@ def send_to_address():
input("Ignore blinding failure? (true/false, optional): ").lower() == "true" input("Ignore blinding failure? (true/false, optional): ").lower() == "true"
) )
fee_rate = float(input("Enter fee rate in sat/vB (optional): ") or 0) fee_rate = float(input("Enter fee rate in sat/vB (optional): ") or 0)
verbose = ( verbose = input("Enable verbose mode? (true/false, optional): ").lower() == "true"
input("Enable verbose mode? (true/false, optional): ").lower() == "true"
)
# Build the transaction # Build the transaction
tx_result = rpc_connection.sendtoaddress( tx_result = rpc_connection.sendtoaddress(
destination_address, destination_address,
amount, amount,
asset_name,
comment, comment,
comment_to, comment_to,
subtract_fee_from_amount, subtract_fee_from_amount,
@ -112,19 +106,7 @@ def send_to_address():
else: else:
print(f"Transaction sent. Transaction ID: {tx_result}") 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))
except Exception as general_exception: except Exception as general_exception:
print("An Exception occurred: " + str(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...")