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 108 109 110 111 112 113 114 115 116
| import requests import csv import time import base64 import os from Crypto.Cipher import AES from Crypto.Util.Padding import pad from proxy import get_proxy_config
def encrypt_with_aes256_cbc(plaintext): # 固定的密钥字符串 s = "yQmRxqD#c^DefKhxeuK,2V-M?}3om~eu"
# 将字符串转换为字节 key = s.encode("utf-8") # print("key:", key.hex())
# 生成随机的 16 字节 IV iv = os.urandom(16) # iv = bytes.fromhex("bcb5d322febaa005286401694c0e0dea")
# print("iv:", iv.hex())
# 创建 AES 加密器 cipher = AES.new(key, AES.MODE_CBC, iv)
# 使用 PKCS7 填充,并加密数据 plaintext_bytes = plaintext.encode("utf-8") encrypted_bytes = cipher.encrypt(pad(plaintext_bytes, AES.block_size))
# 将 IV 和加密数据编码为 Base64 后拼接 iv_base64 = base64.b64encode(iv).decode("utf-8") encrypted_base64 = base64.b64encode(encrypted_bytes).decode("utf-8")
return iv_base64 + encrypted_base64
def send_request(account,txHash, token,max_retries=3, retry_delay=3): headers = { 'accept': '*/*', 'accept-language': 'zh,zh-CN;q=0.9,en;q=0.8,und;q=0.7', 'authorization': f'Bearer {token}', 'content-type': 'application/json', 'origin': 'https://beratown.dapdap.net', 'priority': 'u=1, i', 'referer': 'https://beratown.dapdap.net/', 'sec-ch-ua': '"Google Chrome";v="131", "Chromium";v="131", "Not_A Brand";v="24"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '"macOS"', 'sec-fetch-dest': 'empty', 'sec-fetch-mode': 'cors', 'sec-fetch-site': 'cross-site', 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36', } for attempt in range(max_retries): try: json_data = { 'action_type': 'Lending', 'account_id': account, 'template': 'Dolomite', 'sub_type': 'Supply', 'action_switch': 0, 'action_status': 'Success', 'tx_id': txHash, 'action_network_id': 'Berachain bArtio', 'chain_id': 80084, 'action_title': 'Deposit 0.000 BERA on Dolomite', 'action_tokens': '["BERA"]', 'action_amount': '0.0001', 'ss': '', 'source': 'lending', 'wallet': 'OKX Wallet', }
t = f"template=Dolomite&action_type=Lending&tx_hash={txHash}&chain_id=80084&time={int(time.time())}" print("hashTx:" + txHash) # print("raw:" + t) encrypted_data = encrypt_with_aes256_cbc(t) json_data['ss'] = encrypted_data # print("encrypted:" + encrypted_data)
response = requests.post('https://testnet-api.beratown.app/api/action/add', headers=headers, json=json_data, proxies=get_proxy_config()) print(f"Response for address:{account} txHash {txHash}: {response.status_code}") print(response.json()) if response.status_code == 200: return response.status_code, response.json() else: print(f"Request failed with status code {response.status_code}. {response.text} Retrying...") except Exception as e: print(f"An error occurred: {e}. Retrying...")
time.sleep(retry_delay)
print(f"Failed to send request after {max_retries} attempts.") return None, None
if __name__ == "__main__": csv_file_path = '1_transaction_hashes.csv' # CSV文件路径
output_csv_file_path = '2_successful_hashes.csv' # 输出CSV文件路径
with open(csv_file_path, mode='r') as infile, open(output_csv_file_path, mode='a', newline='') as outfile: reader = csv.reader(infile) writer = csv.writer(outfile) for row in reader: if row: # 确保行不为空 address = row[0].strip() txHash = row[1].strip() token = row[2].strip() status_code, response = send_request(address, txHash,token) writer.writerow([address,txHash, token,status_code, response])
|