From 5f3d740c7fe83040aa2fba81d5207198b404e1b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=97=B5=E5=AE=AA=E7=91=9E?= <9198107+min-xianrui@user.noreply.gitee.com> Date: Wed, 21 May 2025 15:00:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E4=B8=8A=E9=93=BEGET=E6=94=B9?= =?UTF-8?q?=E6=88=90POST?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 25ce4bb..c87b8a0 100644 --- a/main.go +++ b/main.go @@ -180,8 +180,10 @@ func getHandler(storage *SimpleStorage) http.HandlerFunc { // getByTxHashHandler 通过交易哈希查询存储在智能合约中的值 func getByTxHashHandler(client *ethclient.Client, storage *SimpleStorage) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { + // 记录请求开始 + log.Printf("收到请求: %s %s", r.Method, r.URL.String()) txHashStr := r.URL.Query().Get("txHash") - + log.Printf("请求参数 - txHash: %s", txHashStr) if txHashStr == "" { writeResponse(w, &Response{Msg: "error", Data: "缺少 txHash 参数"}) return @@ -189,8 +191,10 @@ func getByTxHashHandler(client *ethclient.Client, storage *SimpleStorage) http.H // 通过交易哈希获取键值 txHash := common.HexToHash(txHashStr) - + log.Printf("转换后的交易哈希: %s", txHash.Hex()) // 获取交易详情 + // 获取交易详情 + log.Println("正在获取交易详情...") tx, _, err := getTransactionDetails(client, txHash) if err != nil { writeResponse(w, &Response{Msg: "error", Data: fmt.Sprintf("无法获取交易详情: %v", err)}) @@ -198,20 +202,20 @@ func getByTxHashHandler(client *ethclient.Client, storage *SimpleStorage) http.H } // 解析交易输入 + log.Println("正在解析交易输入...") methodName, args, err := parseTransactionInput(string(abiJSON), tx.Data()) if err != nil { writeResponse(w, &Response{Msg: "error", Data: fmt.Sprintf("无法解析交易输入: %v", err)}) return } - - // 假设方法名为 "set",并且第一个参数是键 + log.Printf("解析结果 - 方法名: %s, 参数数量: %d", methodName, len(args)) + // 方法名为 "set",并且第一个参数是键 if methodName == "set" && len(args) > 0 { key, ok := args[0].(*big.Int) if !ok { writeResponse(w, &Response{Msg: "error", Data: "键值类型不匹配"}) return } - // 通过键值调用智能合约的 get 方法 callOpts := &bind.CallOpts{ Pending: false, @@ -222,7 +226,7 @@ func getByTxHashHandler(client *ethclient.Client, storage *SimpleStorage) http.H return } - // 假设结果只包含一个字符串值 + // 结果只包含一个字符串值 if len(result) > 0 { writeResponse(w, &Response{Msg: "ok", Data: result[0]}) } else {