refactor(client): 重构客户端方法并优化密钥处理

-将私钥和公钥的解析逻辑移至 NewClient 方法中- 优化 RequestWithSignature 方法,使其支持泛型返回值
- 移除不必要的 genHttpResponse 函数
- 更新客户端方法,使其使用新的 RequestWithSignature 实现
- 调整测试代码以适应新的客户端实现
This commit is contained in:
zhaoweijie
2025-06-03 15:56:02 +08:00
parent a98d707e48
commit a08ed7e35f
2 changed files with 118 additions and 187 deletions

View File

@@ -2,8 +2,6 @@ package client
import (
"testing"
"go.fusiongalaxy.cn/bdware/bdcontract-client/sm2util"
)
func TestStruct(t *testing.T) {
@@ -19,17 +17,11 @@ func TestStruct(t *testing.T) {
}
func genClient() (*Client, error) {
url := "http://127.0.0.1:21030/SCIDE"
url := "http://021.node.internetapi.cn:21030/SCIDE"
pub, err := sm2util.ParsePublicKey("04180354fdb6507f8ab98ccfbe165ce11da74ba733f81af86ad6d32216b32cf4f797c559d50ceeefbf4c760c3483840471c67471b90acdffb388cd7d496d9a1610")
if err != nil {
return nil, err
}
pub := "042731bc66608ba21a4301cd6522e3d6a6c7964f8dc3618cfe5d0aae493229a98623de23dfb35a5f9b7b4ac53e1f82ea79325ddf96d88a6bbcaf075df7e98acc5a"
priv, err := sm2util.ParsePrivateKey("1d4196947f59532db6f8f4055e58474a48db8f30b476ae3edc66406464521b3b", pub)
if err != nil {
return nil, err
}
priv := "481343eac82e0d18f8ea3a9f82a8f065543d720209e9f0d8d508f7e343883c45"
client, err := NewClient(url, priv, pub, HttpCOptions{})
if err != nil {
@@ -54,7 +46,7 @@ func TestClient_Ping(t *testing.T) {
t.Error(err)
}
resp, err := client.Ping()
resp, err := Ping(client)
if err != nil {
t.Log(resp.Status)
t.Error(err)
@@ -70,7 +62,7 @@ func TestClient_StartContract(t *testing.T) {
t.Error(err)
}
resp, err := client.StartContract("contract TestContract")
resp, err := StartContract(client, "contract TestContract")
if err != nil {
t.Log(resp)
@@ -86,7 +78,7 @@ func TestClient_ExecuteContract(t *testing.T) {
t.Error(err)
}
resp, err := client.ExecuteContract("GlobalRouter", "listID", map[string]any{"offset": 0, "count": 12, "queryByCreateTime": "true", "filter": "prefixId"}, false, true)
resp, err := ExecuteContract[any](client, "GlobalRouter", "listLRS", map[string]any{"offset": 0, "count": 12, "queryByCreateTime": "true", "filter": "prefixId"}, false, true)
if err != nil {
t.Log(resp)
@@ -102,7 +94,7 @@ func TestClient_LoadNodeConfig(t *testing.T) {
t.Error(err)
}
config, err := client.LoadNodeConfig()
config, err := LoadNodeConfig(client)
if err != nil {
t.Log(config)
t.Error(err)