From 312596895ed9280098e23d02d051624db4d2ead8 Mon Sep 17 00:00:00 2001 From: Zichao Lin Date: Mon, 28 Jul 2025 19:22:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BF=9D=E5=AD=98=E5=B7=B2?= =?UTF-8?q?=E5=A4=84=E7=90=86=E4=BA=A4=E6=98=93=E5=93=88=E5=B8=8C=E7=9A=84?= =?UTF-8?q?=E9=80=BB=E8=BE=91=EF=BC=8C=E5=90=88=E5=B9=B6=E6=96=B0=E5=93=88?= =?UTF-8?q?=E5=B8=8C=E5=B9=B6=E6=9B=B4=E6=96=B0=E6=80=BB=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 205b7bb..5757fc2 100644 --- a/main.py +++ b/main.py @@ -136,7 +136,7 @@ def update_json_file(new_data): "成功更新%s,合并%d条记录,总计%d条记录", JSON_FILE, len(processed_data), - len(existing_data) + len(existing_data), ) except (FileNotFoundError, json.JSONDecodeError, IOError) as e: LOGGER.error("更新JSON文件时发生错误: %s,跳过本次更新", e) @@ -175,9 +175,26 @@ def load_processed_hashes(): def save_processed_hashes(): """Save processed transaction hashes to file.""" try: + # 读取现有数据 + try: + with open(HASH_FILE, "r", encoding="utf-8") as file: + existing_data = json.load(file) + except (FileNotFoundError, json.JSONDecodeError): + existing_data = [] + + # 合并新哈希 + updated_data = list(set(existing_data) | SEEN_TXHASHES) + + # 写回文件 with open(HASH_FILE, "w", encoding="utf-8") as file: - json.dump(list(SEEN_TXHASHES), file, indent=4, ensure_ascii=False) - LOGGER.info("成功保存已处理交易哈希到%s", HASH_FILE) + json.dump(updated_data, file, indent=4, ensure_ascii=False) + + LOGGER.info( + "成功更新%s,新增%d条哈希,总计%d条记录", + HASH_FILE, + len(SEEN_TXHASHES - set(existing_data)), + len(updated_data), + ) except IOError as e: LOGGER.error("保存已处理交易哈希时发生错误: %s", e)