Update elerium_ordinals_daemon.py
This commit is contained in:
parent
275287bedc
commit
2501121f80
@ -10,17 +10,29 @@ import os
|
||||
|
||||
|
||||
# Configuration
|
||||
BTCPAY_INSTANCE = "https://btcpay.kosmos.org"
|
||||
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
|
||||
# Maximum metadata size for a safe transaction is 95 KB, to be safe let's limit to 50 KB
|
||||
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
|
||||
logging.basicConfig(filename='elerium_daemon.log', level=logging.INFO,
|
||||
logging.basicConfig(filename=LOG_FILE, level=logging.INFO,
|
||||
format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
|
||||
# Database setup
|
||||
@ -41,14 +53,12 @@ headers = {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
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",
|
||||
BITCOIN_CLI_PATH,
|
||||
BITCOIN_CLI_DATADIR,
|
||||
BITCOIN_CLI_RPC_PORT,
|
||||
"estimatesmartfee",
|
||||
"3", # conf_target for 3 blocks
|
||||
"conservative" # estimate_mode
|
||||
@ -58,23 +68,30 @@ def get_fee_rate():
|
||||
result = subprocess.run(command, capture_output=True, text=True, check=True)
|
||||
output = result.stdout
|
||||
data = json.loads(output)
|
||||
|
||||
print(data)
|
||||
# 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)
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
return 1 # Default fee rate
|
||||
|
||||
|
||||
|
||||
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.")
|
||||
metadata_size_bytes = len(json.dumps(metadata).encode('utf-8'))
|
||||
|
||||
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
|
||||
|
||||
fee_rate = get_fee_rate()
|
||||
@ -86,8 +103,8 @@ def inscribe(metadata):
|
||||
|
||||
command = [
|
||||
"ord",
|
||||
"--cookie-file=/media/n/backup/bitcoin-core/bitcoin-25.0/data/testnet3/.cookie",
|
||||
"--testnet",
|
||||
#ORD_COOKIE_FILE,
|
||||
#ORD_TESTNET,
|
||||
"wallet",
|
||||
"inscribe",
|
||||
"--fee-rate",
|
||||
@ -96,14 +113,6 @@ def inscribe(metadata):
|
||||
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
|
||||
@ -133,7 +142,6 @@ def fetch_invoices():
|
||||
endpoint = f"{BTCPAY_INSTANCE}/api/v1/stores/{STORE_ID}/invoices"
|
||||
try:
|
||||
response = requests.get(endpoint, headers=headers)
|
||||
#print(response)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
except RequestException as e:
|
||||
@ -161,7 +169,6 @@ def process_invoices(invoices):
|
||||
continue # Skip non-settled invoices
|
||||
invoice_id = invoice['id']
|
||||
cursor.execute("SELECT status FROM orders WHERE invoice_id = ?", (invoice_id,))
|
||||
result = cursor.fetchone()
|
||||
|
||||
if not is_inscribed(invoice):
|
||||
print("Found non-inscribed order: " + str(invoice))
|
||||
@ -193,10 +200,6 @@ def process_invoices(invoices):
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
def main_loop():
|
||||
while True:
|
||||
invoices = fetch_invoices()
|
||||
|
Loading…
x
Reference in New Issue
Block a user