Update elerium_ordinals_daemon.py
Added fee estimation via get_fee_rate function which calls bitcoin-cli estimatesmartfee with a conf_target of 3 blocks
This commit is contained in:
parent
676d349ca3
commit
275287bedc
@ -15,6 +15,9 @@ STORE_ID = "BLt2tAvgDHaYL6eCpbcNTybaPEUS6cYBCoXZLMBw8APg"
|
||||
API_KEY = "8daa71e669ca230acd5fb437fee6cfdd659c92f6"
|
||||
DB_PATH = "elerium_orders.db"
|
||||
CHECK_INTERVAL = 60 # in seconds
|
||||
# Maximum weight units for a safe transaction
|
||||
MAX_INSCRIPTION_SIZE = 390000 # Maximum size in weight units
|
||||
|
||||
|
||||
# Set up logging
|
||||
logging.basicConfig(filename='elerium_daemon.log', level=logging.INFO,
|
||||
@ -30,13 +33,6 @@ cursor.execute('''CREATE TABLE IF NOT EXISTS orders
|
||||
conn.commit()
|
||||
|
||||
|
||||
#Bitcoin node checks
|
||||
#check ord is able to run correctly. If ord can check transactions, that means bitcoind is running fine on the machine & ord is set up correctly
|
||||
|
||||
#ord --cookie-file=/media/n/backup/bitcoin-core/bitcoin-25.0/data/testnet3/.cookie --testnet wallet transactionse --testnet wallet transactions
|
||||
|
||||
#If that works, continue with program, else, throw error and shut down gracefully
|
||||
|
||||
|
||||
# Headers for BTCPay Server API requests
|
||||
headers = {
|
||||
@ -46,7 +42,43 @@ headers = {
|
||||
|
||||
|
||||
|
||||
def execute_inscription(metadata):
|
||||
|
||||
def get_fee_rate():
|
||||
# Assuming bitcoin-cli is located in the same directory
|
||||
command = [
|
||||
"/media/n/backup/bitcoin-core/bitcoin-25.0/bin/bitcoin-cli",
|
||||
"-datadir=/media/n/backup/bitcoin-core/bitcoin-25.0/data",
|
||||
"-rpcport=18332",
|
||||
"estimatesmartfee",
|
||||
"3", # conf_target for 3 blocks
|
||||
"conservative" # estimate_mode
|
||||
]
|
||||
|
||||
try:
|
||||
result = subprocess.run(command, capture_output=True, text=True, check=True)
|
||||
output = result.stdout
|
||||
data = json.loads(output)
|
||||
|
||||
# Convert BTC/kvB to sat/B and round to nearest integer
|
||||
btc_per_kvB = data.get("feerate", 0)
|
||||
sat_per_B = int(btc_per_kvB * 100000000 / 1000)
|
||||
return sat_per_B
|
||||
|
||||
except subprocess.CalledProcessError as e:
|
||||
error_msg = e.stderr
|
||||
logging.error(f"Fee rate estimation failed: {error_msg}")
|
||||
return 1 # Default fee rate or handle error accordingly
|
||||
|
||||
|
||||
|
||||
def inscribe(metadata):
|
||||
metadata_size = len(json.dumps(metadata))
|
||||
if metadata_size > MAX_INSCRIPTION_SIZE:
|
||||
logging.error(f"Metadata size {metadata_size} exceeds maximum limit.")
|
||||
return None
|
||||
|
||||
fee_rate = get_fee_rate()
|
||||
print("FEE RATE: "+ str(fee_rate))
|
||||
with tempfile.NamedTemporaryFile(mode='w+', delete=False, suffix='.json') as temp_file:
|
||||
# Write the metadata to the temporary file
|
||||
json.dump(metadata, temp_file)
|
||||
@ -54,16 +86,24 @@ def execute_inscription(metadata):
|
||||
|
||||
command = [
|
||||
"ord",
|
||||
#"--cookie-file=/media/n/backup/bitcoin-core/bitcoin-25.0/data/testnet3/.cookie",
|
||||
#"--testnet",
|
||||
"--cookie-file=/media/n/backup/bitcoin-core/bitcoin-25.0/data/testnet3/.cookie",
|
||||
"--testnet",
|
||||
"wallet",
|
||||
"inscribe",
|
||||
"--fee-rate",
|
||||
"1",
|
||||
str(fee_rate), # Use dynamic fee rate
|
||||
"--file",
|
||||
temp_file_path
|
||||
]
|
||||
|
||||
# Print the command
|
||||
print("Command to be executed:", ' '.join(command))
|
||||
# Ask user for confirmation
|
||||
user_input = input("Do you want to continue with the inscription? (Y/N): ")
|
||||
if user_input.lower() != 'y':
|
||||
print("Inscription cancelled.")
|
||||
exit()
|
||||
return None
|
||||
try:
|
||||
result = subprocess.run(command, capture_output=True, text=True, check=True)
|
||||
output = result.stdout
|
||||
@ -105,7 +145,9 @@ def is_inscribed(invoice):
|
||||
metadata = invoice.get('metadata', {})
|
||||
ordinals_id = metadata.get('ordinalsId', '')
|
||||
|
||||
is_inscribed = len(ordinals_id) > 1
|
||||
# Check if ordinals_id is not None and has a length greater than 1
|
||||
is_inscribed = ordinals_id is not None and len(ordinals_id) > 1
|
||||
|
||||
|
||||
# Debugging print statement
|
||||
print(f"Invoice ID: {invoice['id']}, Ordinals ID: {ordinals_id}, Is inscribed: {is_inscribed}")
|
||||
@ -125,7 +167,7 @@ def process_invoices(invoices):
|
||||
print("Found non-inscribed order: " + str(invoice))
|
||||
# 1. Inscribing the order
|
||||
metadata = invoice.get('metadata', {})
|
||||
ordinalsid = execute_inscription(metadata=metadata)
|
||||
ordinalsid = inscribe(metadata=metadata)
|
||||
|
||||
# 2. Prepare the invoice data for update
|
||||
update_data = invoice.copy()
|
||||
|
Loading…
x
Reference in New Issue
Block a user