Update elerium_ordinals_daemon.py
This commit is contained in:
parent
275287bedc
commit
2501121f80
@ -10,17 +10,29 @@ import os
|
|||||||
|
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
BTCPAY_INSTANCE = "https://btcpay.kosmos.org"
|
|
||||||
STORE_ID = "BLt2tAvgDHaYL6eCpbcNTybaPEUS6cYBCoXZLMBw8APg"
|
|
||||||
API_KEY = "8daa71e669ca230acd5fb437fee6cfdd659c92f6"
|
|
||||||
DB_PATH = "elerium_orders.db"
|
|
||||||
CHECK_INTERVAL = 60 # in seconds
|
CHECK_INTERVAL = 60 # in seconds
|
||||||
# Maximum weight units for a safe transaction
|
# Maximum metadata size for a safe transaction is 95 KB, to be safe let's limit to 50 KB
|
||||||
MAX_INSCRIPTION_SIZE = 390000 # Maximum size in weight units
|
MAX_METADATA_SIZE_BYTES = 50 * 1024 # 50 kilobytes in bytes
|
||||||
|
|
||||||
|
# Load configuration from JSON file
|
||||||
|
with open('config.json', 'r') as config_file:
|
||||||
|
config = json.load(config_file)
|
||||||
|
|
||||||
|
BTCPAY_INSTANCE = config['btcpay']['instance']
|
||||||
|
STORE_ID = config['btcpay']['store_id']
|
||||||
|
API_KEY = config['btcpay']['api_key']
|
||||||
|
DB_PATH = config['database']['path']
|
||||||
|
LOG_FILE = config['database']['logging']
|
||||||
|
BITCOIN_CLI_PATH = config['bitcoin_cli']['path']
|
||||||
|
BITCOIN_CLI_DATADIR = config['bitcoin_cli']['data_dir']
|
||||||
|
BITCOIN_CLI_RPC_PORT = config['bitcoin_cli']['rpc_port']
|
||||||
|
ORD_COOKIE_FILE = config['ord_command']['cookie_file']
|
||||||
|
ORD_TESTNET = config['ord_command']['testnet']
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Set up logging
|
# Set up logging
|
||||||
logging.basicConfig(filename='elerium_daemon.log', level=logging.INFO,
|
logging.basicConfig(filename=LOG_FILE, level=logging.INFO,
|
||||||
format='%(asctime)s - %(levelname)s - %(message)s')
|
format='%(asctime)s - %(levelname)s - %(message)s')
|
||||||
|
|
||||||
# Database setup
|
# Database setup
|
||||||
@ -41,14 +53,12 @@ headers = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_fee_rate():
|
def get_fee_rate():
|
||||||
# Assuming bitcoin-cli is located in the same directory
|
|
||||||
command = [
|
command = [
|
||||||
"/media/n/backup/bitcoin-core/bitcoin-25.0/bin/bitcoin-cli",
|
BITCOIN_CLI_PATH,
|
||||||
"-datadir=/media/n/backup/bitcoin-core/bitcoin-25.0/data",
|
BITCOIN_CLI_DATADIR,
|
||||||
"-rpcport=18332",
|
BITCOIN_CLI_RPC_PORT,
|
||||||
"estimatesmartfee",
|
"estimatesmartfee",
|
||||||
"3", # conf_target for 3 blocks
|
"3", # conf_target for 3 blocks
|
||||||
"conservative" # estimate_mode
|
"conservative" # estimate_mode
|
||||||
@ -58,23 +68,30 @@ def get_fee_rate():
|
|||||||
result = subprocess.run(command, capture_output=True, text=True, check=True)
|
result = subprocess.run(command, capture_output=True, text=True, check=True)
|
||||||
output = result.stdout
|
output = result.stdout
|
||||||
data = json.loads(output)
|
data = json.loads(output)
|
||||||
|
print(data)
|
||||||
# Convert BTC/kvB to sat/B and round to nearest integer
|
# Convert BTC/kvB to sat/B and round to nearest integer
|
||||||
btc_per_kvB = data.get("feerate", 0)
|
btc_per_kvB = data.get("feerate", 0)
|
||||||
sat_per_B = int(btc_per_kvB * 100000000 / 1000)
|
|
||||||
|
btc_per_kvB = "{:.8f}".format(btc_per_kvB) # Convert to decimal with 8 decimal places
|
||||||
|
|
||||||
|
print(btc_per_kvB)
|
||||||
|
|
||||||
|
sat_per_B = int(float(btc_per_kvB) * 100000000 / 1000)
|
||||||
|
print(sat_per_B)
|
||||||
return sat_per_B
|
return sat_per_B
|
||||||
|
|
||||||
except subprocess.CalledProcessError as e:
|
except subprocess.CalledProcessError as e:
|
||||||
error_msg = e.stderr
|
error_msg = e.stderr
|
||||||
logging.error(f"Fee rate estimation failed: {error_msg}")
|
logging.error(f"Fee rate estimation failed: {error_msg}")
|
||||||
return 1 # Default fee rate or handle error accordingly
|
return 1 # Default fee rate
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def inscribe(metadata):
|
def inscribe(metadata):
|
||||||
metadata_size = len(json.dumps(metadata))
|
metadata_size_bytes = len(json.dumps(metadata).encode('utf-8'))
|
||||||
if metadata_size > MAX_INSCRIPTION_SIZE:
|
|
||||||
logging.error(f"Metadata size {metadata_size} exceeds maximum limit.")
|
if metadata_size_bytes > MAX_METADATA_SIZE_BYTES:
|
||||||
|
logging.error(f"Metadata size {metadata_size_bytes} bytes exceeds maximum limit of 50 KB.")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
fee_rate = get_fee_rate()
|
fee_rate = get_fee_rate()
|
||||||
@ -86,8 +103,8 @@ def inscribe(metadata):
|
|||||||
|
|
||||||
command = [
|
command = [
|
||||||
"ord",
|
"ord",
|
||||||
"--cookie-file=/media/n/backup/bitcoin-core/bitcoin-25.0/data/testnet3/.cookie",
|
#ORD_COOKIE_FILE,
|
||||||
"--testnet",
|
#ORD_TESTNET,
|
||||||
"wallet",
|
"wallet",
|
||||||
"inscribe",
|
"inscribe",
|
||||||
"--fee-rate",
|
"--fee-rate",
|
||||||
@ -96,14 +113,6 @@ def inscribe(metadata):
|
|||||||
temp_file_path
|
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:
|
try:
|
||||||
result = subprocess.run(command, capture_output=True, text=True, check=True)
|
result = subprocess.run(command, capture_output=True, text=True, check=True)
|
||||||
output = result.stdout
|
output = result.stdout
|
||||||
@ -133,7 +142,6 @@ def fetch_invoices():
|
|||||||
endpoint = f"{BTCPAY_INSTANCE}/api/v1/stores/{STORE_ID}/invoices"
|
endpoint = f"{BTCPAY_INSTANCE}/api/v1/stores/{STORE_ID}/invoices"
|
||||||
try:
|
try:
|
||||||
response = requests.get(endpoint, headers=headers)
|
response = requests.get(endpoint, headers=headers)
|
||||||
#print(response)
|
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response.json()
|
return response.json()
|
||||||
except RequestException as e:
|
except RequestException as e:
|
||||||
@ -161,7 +169,6 @@ def process_invoices(invoices):
|
|||||||
continue # Skip non-settled invoices
|
continue # Skip non-settled invoices
|
||||||
invoice_id = invoice['id']
|
invoice_id = invoice['id']
|
||||||
cursor.execute("SELECT status FROM orders WHERE invoice_id = ?", (invoice_id,))
|
cursor.execute("SELECT status FROM orders WHERE invoice_id = ?", (invoice_id,))
|
||||||
result = cursor.fetchone()
|
|
||||||
|
|
||||||
if not is_inscribed(invoice):
|
if not is_inscribed(invoice):
|
||||||
print("Found non-inscribed order: " + str(invoice))
|
print("Found non-inscribed order: " + str(invoice))
|
||||||
@ -193,10 +200,6 @@ def process_invoices(invoices):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main_loop():
|
def main_loop():
|
||||||
while True:
|
while True:
|
||||||
invoices = fetch_invoices()
|
invoices = fetch_invoices()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user