-
Notifications
You must be signed in to change notification settings - Fork 1
/
inscriberauto.py
107 lines (97 loc) · 4.44 KB
/
inscriberauto.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import subprocess
import time
import json
import re
import os
from bitcoinrpc.authproxy import AuthServiceProxy, JSONRPCException
# Environment variables are used to securely store sensitive data such as RPC credentials.
rpc_user = os.getenv('RPC_USER', '<username>')
rpc_password = os.getenv('RPC_PASSWORD', '<password>')
rpc_host = os.getenv('RPC_HOST', 'localhost')
rpc_port = os.getenv('RPC_PORT', '22555') # Default Dogecoin RPC port
# Setting up the AuthServiceProxy client with the RPC server.
rpc_connection = AuthServiceProxy(f"http://{rpc_user}:{rpc_password}@{rpc_host}:{rpc_port}/")
def read_last_output(json_file_name):
if os.path.exists(json_file_name):
try:
with open(json_file_name, 'r') as file:
data = json.load(file)
return len(data) # Return the count of entries in the JSON file.
except json.JSONDecodeError as e:
print(f"JSON decode error in {json_file_name}: {e}")
return 0
def extract_details(file_name):
try:
with open(file_name, 'r', encoding='utf-8') as file:
return json.load(file).get('airDropList', [])
except Exception as e:
print(f"An error occurred while reading {file_name}: {e}")
return []
def update_json_file(image_path, txid, details):
json_file_name = "airDropOutput.json"
try:
data = {}
if os.path.exists(json_file_name):
with open(json_file_name, 'r') as file:
data = json.load(file)
key = os.path.basename(image_path)
data[key] = {"txid": txid, "address": details['dogecoin_address']}
with open(json_file_name, 'w') as file:
json.dump(data, file, indent=4)
except Exception as e:
print(f"Error updating {json_file_name}: {e}")
def process_mint_batch(start, end, directory, file_prefix, file_extension, details_list):
last_txid = ""
for i in range(start, end + 1):
if i > len(details_list):
break
details = details_list[i - 1]
file_number = str(i).zfill(5)
image_path = os.path.join(directory, f"{file_prefix}{file_number}.{file_extension}")
if not os.path.exists(image_path):
print(f"File not found: {image_path}")
continue
mint_command = f"node . mint {details['dogecoin_address']} {image_path}"
result_mint = subprocess.run(mint_command, shell=True, capture_output=True, text=True)
print("Output from mint command:")
print(result_mint.stdout)
if result_mint.stderr:
print("Error in mint command:")
print(result_mint.stderr)
txid_search = re.search("inscription txid: (\\w+)", result_mint.stdout)
if txid_search:
last_txid = txid_search.group(1)
print(f"Successful mint, TXID: {last_txid}")
update_json_file(image_path, last_txid, details)
return last_txid
def wait_for_tx_confirmation(txid):
while True:
try:
tx_info = rpc_connection.gettransaction(txid)
if tx_info and tx_info.get("confirmations", 0) >= 1:
print(f"Transaction {txid} is confirmed.")
break
except JSONRPCException as e:
print(f"Error fetching transaction {txid}: {e}")
time.sleep(10)
def continuous_minting_process(directory, file_prefix, file_extension):
last_count = read_last_output('airDropOutput.json')
details_list = extract_details('airDropList.json')
details_list = details_list[last_count:]
batch_size = 12
num_batches = (len(details_list) + batch_size - 1) // batch_size
for batch_index in range(num_batches):
start_index = batch_index * batch_size
end_index = start_index + batch_size
print(f"Processing batch from {start_index + 1} to {end_index}")
last_txid = process_mint_batch(start_index + 1, end_index, directory, file_prefix, file_extension, details_list)
if last_txid:
print(f"Waiting for confirmation of TXID: {last_txid}")
wait_for_tx_confirmation(last_txid)
else:
print("No valid transactions in this batch to wait for.")
# Initialize main variables and start process
directory = r'E:\newminternode\dogecoin-ordinals-drc-20-inscription\stones'
file_prefix = 'dpaystone'
file_extension = 'html'
continuous_minting_process(directory, file_prefix, file_extension)