refactor(client): 重构客户端方法并优化密钥处理
-将私钥和公钥的解析逻辑移至 NewClient 方法中- 优化 RequestWithSignature 方法,使其支持泛型返回值 - 移除不必要的 genHttpResponse 函数 - 更新客户端方法,使其使用新的 RequestWithSignature 实现 - 调整测试代码以适应新的客户端实现
This commit is contained in:
parent
a98d707e48
commit
a08ed7e35f
283
client/client.go
283
client/client.go
@ -36,10 +36,20 @@ type Client struct {
|
|||||||
|
|
||||||
func NewClient(
|
func NewClient(
|
||||||
baseUrl string,
|
baseUrl string,
|
||||||
priv *sm2.PrivateKey,
|
privStr string,
|
||||||
pub *sm2.PublicKey,
|
pubStr string,
|
||||||
opt HttpCOptions,
|
opt HttpCOptions,
|
||||||
) (*Client, error) {
|
) (*Client, error) {
|
||||||
|
pub, err := sm2util.ParsePublicKey(pubStr)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
priv, err := sm2util.ParsePrivateKey(privStr, pub)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
pubHex, err := sm2util.CheckSm2KeyPair(priv, pub)
|
pubHex, err := sm2util.CheckSm2KeyPair(priv, pub)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -61,27 +71,27 @@ func NewClient(
|
|||||||
|
|
||||||
// RequestWithSignature
|
// RequestWithSignature
|
||||||
// @Description 发送带有签名的请求
|
// @Description 发送带有签名的请求
|
||||||
|
// @Param c 客户端
|
||||||
// @Param path 请求路径
|
// @Param path 请求路径
|
||||||
// @Param http 请求方法(GET | POST)
|
// @Param http 请求方法(GET | POST)
|
||||||
// @Param result 接收请求返回结果的结构体指针
|
// @Param result 接收请求返回结果的结构体指针
|
||||||
// @Param body 请求体(尽在method为POST时使用)
|
// @Param body 请求体(尽在method为POST时使用)
|
||||||
// @Param priv 请求私钥
|
// @Param priv 请求私钥
|
||||||
// @Param pub 请求公钥
|
// @Param pub 请求公钥
|
||||||
func (c *Client) RequestWithSignature(
|
func RequestWithSignature[T any](
|
||||||
|
c *Client,
|
||||||
path string,
|
path string,
|
||||||
method string,
|
method string,
|
||||||
result any,
|
|
||||||
body map[string]interface{},
|
body map[string]interface{},
|
||||||
priv *sm2.PrivateKey,
|
priv *sm2.PrivateKey,
|
||||||
pub *sm2.PublicKey,
|
pub *sm2.PublicKey,
|
||||||
) (response HttpResponse[any], err error) {
|
) (response *HttpResponse[T], err error) {
|
||||||
response = HttpResponse[any]{
|
response = &HttpResponse[T]{
|
||||||
Status: 0,
|
Status: 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
var pubHex string
|
var pubHex string
|
||||||
if priv != nil {
|
if priv != nil {
|
||||||
var err error
|
|
||||||
pubHex, err = sm2util.CheckSm2KeyPair(priv, pub)
|
pubHex, err = sm2util.CheckSm2KeyPair(priv, pub)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return response, err
|
return response, err
|
||||||
@ -151,13 +161,15 @@ func (c *Client) RequestWithSignature(
|
|||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
err = json.Unmarshal(bodyBytes, result)
|
var result T
|
||||||
|
err = json.Unmarshal(bodyBytes, &result)
|
||||||
// 如果bodyBytes解析失败直接将信息保存到ErrData
|
// 如果bodyBytes解析失败直接将信息保存到ErrData
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.ErrData = string(bodyBytes)
|
response.ErrData = string(bodyBytes)
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
response.Data = result
|
||||||
response.Status = resp.StatusCode
|
response.Status = resp.StatusCode
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
@ -195,60 +207,45 @@ func retry[T any](fn func() (T, error)) (T, error) {
|
|||||||
return zero, lastErr
|
return zero, lastErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func genHttpResponse[D any](data D, response *HttpResponse[any], err error) (*HttpResponse[D], error) {
|
|
||||||
return &HttpResponse[D]{
|
|
||||||
Data: data,
|
|
||||||
Status: response.Status,
|
|
||||||
ErrData: response.ErrData,
|
|
||||||
}, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Ping https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id15
|
// Ping https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id15
|
||||||
func (c *Client) Ping() (*HttpResponse[PingResponse], error) {
|
func Ping(c *Client) (*HttpResponse[PingResponse], error) {
|
||||||
return retry(func() (*HttpResponse[PingResponse], error) {
|
return retry(func() (*HttpResponse[PingResponse], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[PingResponse](
|
||||||
|
c,
|
||||||
resp, err := c.RequestWithSignature(
|
|
||||||
"/SCManager?action=ping",
|
"/SCManager?action=ping",
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[PingResponse](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartContract TODO 未跑通
|
// StartContract TODO 未跑通
|
||||||
// StartContract 启动合约
|
// StartContract 启动合约
|
||||||
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id60
|
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id60
|
||||||
func (c *Client) StartContract(code string) (*HttpResponse[any], error) {
|
func StartContract(c *Client, code string) (*HttpResponse[any], error) {
|
||||||
params := url.Values{
|
params := url.Values{
|
||||||
"action": {"startContract"},
|
"action": {"startContract"},
|
||||||
"script": {code},
|
"script": {code},
|
||||||
}
|
}
|
||||||
path := fmt.Sprintf("/SCManager?%s", params.Encode())
|
path := fmt.Sprintf("/SCManager?%s", params.Encode())
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
path,
|
path,
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartContractByYPK TODO 待测试
|
// StartContractByYPK TODO 待测试
|
||||||
// StartContractByYPK 启动合约
|
// StartContractByYPK 启动合约
|
||||||
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id13
|
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id13
|
||||||
func (c *Client) StartContractByYPK(isPrivate bool, path string, script string) (*HttpResponse[any], error) {
|
func StartContractByYPK(c *Client, isPrivate bool, path string, script string) (*HttpResponse[any], error) {
|
||||||
params := url.Values{
|
params := url.Values{
|
||||||
"action": []string{"startContractByYPK"},
|
"action": []string{"startContractByYPK"},
|
||||||
"script": []string{script},
|
"script": []string{script},
|
||||||
@ -261,29 +258,27 @@ func (c *Client) StartContractByYPK(isPrivate bool, path string, script string)
|
|||||||
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
httpPath,
|
httpPath,
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ExecuteContract 调用合约
|
// ExecuteContract 调用合约
|
||||||
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id69
|
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id69
|
||||||
func (c *Client) ExecuteContract(
|
func ExecuteContract[T any](
|
||||||
|
c *Client,
|
||||||
contractID string,
|
contractID string,
|
||||||
operation string,
|
operation string,
|
||||||
arg any,
|
arg any,
|
||||||
withDynamicAnalysis bool,
|
withDynamicAnalysis bool,
|
||||||
withSignature bool,
|
withSignature bool,
|
||||||
) (*HttpResponse[ExecuteContractResponse[any]], error) {
|
) (*HttpResponse[ExecuteContractResponse[T]], error) {
|
||||||
body := map[string]any{
|
body := map[string]any{
|
||||||
"action": "executeContract",
|
"action": "executeContract",
|
||||||
"contractID": contractID,
|
"contractID": contractID,
|
||||||
@ -308,25 +303,23 @@ func (c *Client) ExecuteContract(
|
|||||||
body["pubkey"] = c.pubHex
|
body["pubkey"] = c.pubHex
|
||||||
}
|
}
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[ExecuteContractResponse[any]], error) {
|
return retry(func() (*HttpResponse[ExecuteContractResponse[T]], error) {
|
||||||
result := ExecuteContractResponse[any]{}
|
return RequestWithSignature[ExecuteContractResponse[T]](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
"/SCManager",
|
"/SCManager",
|
||||||
"POST",
|
"POST",
|
||||||
&result,
|
|
||||||
body,
|
body,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[ExecuteContractResponse[any]](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// KillContractProcess TODO 待测试
|
// KillContractProcess TODO 待测试
|
||||||
// KillContractProcess 停止合约
|
// KillContractProcess 停止合约
|
||||||
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id122
|
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id122
|
||||||
func (c *Client) KillContractProcess(contractID string, requestID string) (*HttpResponse[any], error) {
|
func KillContractProcess(c *Client, contractID string, requestID string) (*HttpResponse[any], error) {
|
||||||
params := url.Values{
|
params := url.Values{
|
||||||
"action": []string{"killContractProcess"},
|
"action": []string{"killContractProcess"},
|
||||||
"id": []string{contractID},
|
"id": []string{contractID},
|
||||||
@ -339,24 +332,22 @@ func (c *Client) KillContractProcess(contractID string, requestID string) (*Http
|
|||||||
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
httpPath,
|
httpPath,
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// KillAllContract TODO 待测试
|
// KillAllContract TODO 待测试
|
||||||
// KillAllContract 停止所有合约
|
// KillAllContract 停止所有合约
|
||||||
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id131
|
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id131
|
||||||
func (c *Client) KillAllContract() (*HttpResponse[any], error) {
|
func KillAllContract(c *Client) (*HttpResponse[any], error) {
|
||||||
params := url.Values{
|
params := url.Values{
|
||||||
"action": []string{"killAllContract"},
|
"action": []string{"killAllContract"},
|
||||||
}
|
}
|
||||||
@ -364,24 +355,22 @@ func (c *Client) KillAllContract() (*HttpResponse[any], error) {
|
|||||||
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
httpPath,
|
httpPath,
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyNodeRole TODO 待测试
|
// ApplyNodeRole TODO 待测试
|
||||||
// ApplyNodeRole 申请角色
|
// ApplyNodeRole 申请角色
|
||||||
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html
|
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html
|
||||||
func (c *Client) ApplyNodeRole(role string) (*HttpResponse[any], error) {
|
func ApplyNodeRole(c *Client, role string) (*HttpResponse[any], error) {
|
||||||
params := url.Values{
|
params := url.Values{
|
||||||
"action": []string{"applyNodeRole"},
|
"action": []string{"applyNodeRole"},
|
||||||
"role": []string{role},
|
"role": []string{role},
|
||||||
@ -390,24 +379,23 @@ func (c *Client) ApplyNodeRole(role string) (*HttpResponse[any], error) {
|
|||||||
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
httpPath,
|
httpPath,
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuthNodeRole TODO 待测试
|
// AuthNodeRole TODO 待测试
|
||||||
// AuthNodeRole 授权角色
|
// AuthNodeRole 授权角色
|
||||||
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html
|
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html
|
||||||
func (c *Client) AuthNodeRole(
|
func AuthNodeRole(
|
||||||
|
c *Client,
|
||||||
isAccept bool,
|
isAccept bool,
|
||||||
authorizedPubKey string,
|
authorizedPubKey string,
|
||||||
priv *sm2.PrivateKey,
|
priv *sm2.PrivateKey,
|
||||||
@ -422,24 +410,21 @@ func (c *Client) AuthNodeRole(
|
|||||||
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
httpPath,
|
httpPath,
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
priv,
|
priv,
|
||||||
pub,
|
pub,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// DistributeContract TODO 待测试, 用sse获取问题未解决!!!
|
// DistributeContract TODO 待测试, 用sse获取问题未解决!!!
|
||||||
// 分发合约项目
|
// 分发合约项目
|
||||||
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html
|
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html
|
||||||
//func (c *Client) DistributeContract(
|
//func DistributeContract(
|
||||||
// nodeIDs string,
|
// nodeIDs string,
|
||||||
// projectName string,
|
// projectName string,
|
||||||
// isPrivate bool,
|
// isPrivate bool,
|
||||||
@ -455,7 +440,7 @@ func (c *Client) AuthNodeRole(
|
|||||||
//
|
//
|
||||||
// return retry(func() (*HttpResponse[any], error) {
|
// return retry(func() (*HttpResponse[any], error) {
|
||||||
// result := PingResponse{}
|
// result := PingResponse{}
|
||||||
// resp, err := c.RequestWithSignature(
|
// return RequestWithSignature(
|
||||||
// httpPath,
|
// httpPath,
|
||||||
// "GET",
|
// "GET",
|
||||||
// &result,
|
// &result,
|
||||||
@ -469,7 +454,8 @@ func (c *Client) AuthNodeRole(
|
|||||||
//}
|
//}
|
||||||
|
|
||||||
// SaveFile TODO 待测试
|
// SaveFile TODO 待测试
|
||||||
func (c *Client) SaveFile(
|
func SaveFile(
|
||||||
|
c *Client,
|
||||||
content string,
|
content string,
|
||||||
isAppend bool,
|
isAppend bool,
|
||||||
isPrivate bool,
|
isPrivate bool,
|
||||||
@ -486,22 +472,21 @@ func (c *Client) SaveFile(
|
|||||||
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
httpPath,
|
httpPath,
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListProjectPermission TODO 待测试
|
// ListProjectPermission TODO 待测试
|
||||||
func (c *Client) ListProjectPermission(
|
func ListProjectPermission(
|
||||||
|
c *Client,
|
||||||
isPrivate bool,
|
isPrivate bool,
|
||||||
path string,
|
path string,
|
||||||
) (*HttpResponse[any], error) {
|
) (*HttpResponse[any], error) {
|
||||||
@ -514,22 +499,20 @@ func (c *Client) ListProjectPermission(
|
|||||||
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
httpPath,
|
httpPath,
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// StartContractMultiPoint TODO 待测试
|
// StartContractMultiPoint TODO 待测试
|
||||||
func (c *Client) StartContractMultiPoint(
|
func StartContractMultiPoint(
|
||||||
|
c *Client,
|
||||||
peersID string,
|
peersID string,
|
||||||
contractType int,
|
contractType int,
|
||||||
selectUnitNum int,
|
selectUnitNum int,
|
||||||
@ -550,24 +533,21 @@ func (c *Client) StartContractMultiPoint(
|
|||||||
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
httpPath,
|
httpPath,
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadNodeConfig TODO 待测试
|
// LoadNodeConfig TODO 待测试
|
||||||
// 获取节点配置信息
|
// 获取节点配置信息
|
||||||
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id497
|
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id497
|
||||||
func (c *Client) LoadNodeConfig() (*HttpResponse[any], error) {
|
func LoadNodeConfig(c *Client) (*HttpResponse[any], error) {
|
||||||
params := url.Values{
|
params := url.Values{
|
||||||
"action": []string{"loadNodeConfig"},
|
"action": []string{"loadNodeConfig"},
|
||||||
}
|
}
|
||||||
@ -575,17 +555,14 @@ func (c *Client) LoadNodeConfig() (*HttpResponse[any], error) {
|
|||||||
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
httpPath,
|
httpPath,
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -593,7 +570,7 @@ func (c *Client) LoadNodeConfig() (*HttpResponse[any], error) {
|
|||||||
// 修改节点配置
|
// 修改节点配置
|
||||||
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id504
|
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id504
|
||||||
// @Param key {licence,projectDir,yjsPath,dataChain,doipConfig,nodeCenter,nodeName,masterAddress,resetNodeCenterWS}
|
// @Param key {licence,projectDir,yjsPath,dataChain,doipConfig,nodeCenter,nodeName,masterAddress,resetNodeCenterWS}
|
||||||
func (c *Client) UpdateConfig(key string, val string) (*HttpResponse[any], error) {
|
func UpdateConfig(c *Client, key string, val string) (*HttpResponse[any], error) {
|
||||||
params := url.Values{
|
params := url.Values{
|
||||||
"action": []string{"updateConfig"},
|
"action": []string{"updateConfig"},
|
||||||
"key": []string{key},
|
"key": []string{key},
|
||||||
@ -603,23 +580,20 @@ func (c *Client) UpdateConfig(key string, val string) (*HttpResponse[any], error
|
|||||||
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
httpPath,
|
httpPath,
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ResetNodeManager TODO 待测试
|
// ResetNodeManager TODO 待测试
|
||||||
// 设置pubkey为node manager
|
// 设置pubkey为node manager
|
||||||
func (c *Client) ResetNodeManager() (*HttpResponse[any], error) {
|
func ResetNodeManager(c *Client) (*HttpResponse[any], error) {
|
||||||
params := url.Values{
|
params := url.Values{
|
||||||
"action": []string{"resetNodeManager"},
|
"action": []string{"resetNodeManager"},
|
||||||
}
|
}
|
||||||
@ -627,23 +601,20 @@ func (c *Client) ResetNodeManager() (*HttpResponse[any], error) {
|
|||||||
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
httpPath,
|
httpPath,
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// LockEdit TODO 待测试
|
// LockEdit TODO 待测试
|
||||||
// 锁定某个用户的的私有目录编辑功能
|
// 锁定某个用户的的私有目录编辑功能
|
||||||
func (c *Client) LockEdit() (*HttpResponse[any], error) {
|
func LockEdit(c *Client) (*HttpResponse[any], error) {
|
||||||
params := url.Values{
|
params := url.Values{
|
||||||
"action": []string{"lockEdit"},
|
"action": []string{"lockEdit"},
|
||||||
}
|
}
|
||||||
@ -651,23 +622,20 @@ func (c *Client) LockEdit() (*HttpResponse[any], error) {
|
|||||||
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
httpPath,
|
httpPath,
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// UnlockEdit TODO 待测试
|
// UnlockEdit TODO 待测试
|
||||||
// 解锁某个用户的的私有目录编辑功能
|
// 解锁某个用户的的私有目录编辑功能
|
||||||
func (c *Client) UnlockEdit() (*HttpResponse[any], error) {
|
func UnlockEdit(c *Client) (*HttpResponse[any], error) {
|
||||||
params := url.Values{
|
params := url.Values{
|
||||||
"action": []string{"unlockEdit"},
|
"action": []string{"unlockEdit"},
|
||||||
}
|
}
|
||||||
@ -675,22 +643,19 @@ func (c *Client) UnlockEdit() (*HttpResponse[any], error) {
|
|||||||
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
httpPath,
|
httpPath,
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddNode TODO 待测试
|
// AddNode TODO 待测试
|
||||||
func (c *Client) AddNode(nodePubKey string) (*HttpResponse[any], error) {
|
func AddNode(c *Client, nodePubKey string) (*HttpResponse[any], error) {
|
||||||
params := url.Values{
|
params := url.Values{
|
||||||
"action": []string{"addNode"},
|
"action": []string{"addNode"},
|
||||||
"nodePubKey": []string{nodePubKey},
|
"nodePubKey": []string{nodePubKey},
|
||||||
@ -699,23 +664,20 @@ func (c *Client) AddNode(nodePubKey string) (*HttpResponse[any], error) {
|
|||||||
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
httpPath,
|
httpPath,
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ApplyRole TODO 待测试
|
// ApplyRole TODO 待测试
|
||||||
// 申请角色
|
// 申请角色
|
||||||
func (c *Client) ApplyRole(role string) (*HttpResponse[any], error) {
|
func ApplyRole(c *Client, role string) (*HttpResponse[any], error) {
|
||||||
params := url.Values{
|
params := url.Values{
|
||||||
"action": []string{"applyRole"},
|
"action": []string{"applyRole"},
|
||||||
"role": []string{role},
|
"role": []string{role},
|
||||||
@ -724,22 +686,19 @@ func (c *Client) ApplyRole(role string) (*HttpResponse[any], error) {
|
|||||||
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
httpPath,
|
httpPath,
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuthNodeManager TODO 待测试
|
// AuthNodeManager TODO 待测试
|
||||||
func (c *Client) AuthNodeManager(isAccept bool, authorizedPubKey string) (*HttpResponse[any], error) {
|
func AuthNodeManager(c *Client, isAccept bool, authorizedPubKey string) (*HttpResponse[any], error) {
|
||||||
params := url.Values{
|
params := url.Values{
|
||||||
"action": []string{"authNodeManager"},
|
"action": []string{"authNodeManager"},
|
||||||
"isAccept": []string{strconv.FormatBool(isAccept)},
|
"isAccept": []string{strconv.FormatBool(isAccept)},
|
||||||
@ -749,22 +708,19 @@ func (c *Client) AuthNodeManager(isAccept bool, authorizedPubKey string) (*HttpR
|
|||||||
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
httpPath,
|
httpPath,
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListAllUsers TODO 待测试
|
// ListAllUsers TODO 待测试
|
||||||
func (c *Client) ListAllUsers() (*HttpResponse[any], error) {
|
func ListAllUsers(c *Client) (*HttpResponse[any], error) {
|
||||||
params := url.Values{
|
params := url.Values{
|
||||||
"action": []string{"listAllUsers"},
|
"action": []string{"listAllUsers"},
|
||||||
}
|
}
|
||||||
@ -772,22 +728,19 @@ func (c *Client) ListAllUsers() (*HttpResponse[any], error) {
|
|||||||
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
httpPath,
|
httpPath,
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListNodes TODO 待测试
|
// ListNodes TODO 待测试
|
||||||
func (c *Client) ListNodes() (*HttpResponse[any], error) {
|
func ListNodes(c *Client) (*HttpResponse[any], error) {
|
||||||
params := url.Values{
|
params := url.Values{
|
||||||
"action": []string{"listNodes"},
|
"action": []string{"listNodes"},
|
||||||
}
|
}
|
||||||
@ -795,24 +748,22 @@ func (c *Client) ListNodes() (*HttpResponse[any], error) {
|
|||||||
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
httpPath,
|
httpPath,
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateTrustUnit TODO 待测试
|
// CreateTrustUnit TODO 待测试
|
||||||
// 建立可信执行集群
|
// 建立可信执行集群
|
||||||
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id664
|
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id664
|
||||||
func (c *Client) CreateTrustUnit(
|
func CreateTrustUnit(
|
||||||
|
c *Client,
|
||||||
data []struct {
|
data []struct {
|
||||||
nodeName string
|
nodeName string
|
||||||
pubkey string
|
pubkey string
|
||||||
@ -829,24 +780,21 @@ func (c *Client) CreateTrustUnit(
|
|||||||
}
|
}
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
"/SCManager",
|
"/SCManager",
|
||||||
"POST",
|
"POST",
|
||||||
&result,
|
|
||||||
body,
|
body,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListTrustUnits TODO 待测试
|
// ListTrustUnits TODO 待测试
|
||||||
// 查看可信执行集群列表
|
// 查看可信执行集群列表
|
||||||
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id657
|
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id657
|
||||||
func (c *Client) ListTrustUnits() (*HttpResponse[any], error) {
|
func ListTrustUnits(c *Client) (*HttpResponse[any], error) {
|
||||||
params := url.Values{
|
params := url.Values{
|
||||||
"action": []string{"listTrustUnits"},
|
"action": []string{"listTrustUnits"},
|
||||||
}
|
}
|
||||||
@ -854,24 +802,21 @@ func (c *Client) ListTrustUnits() (*HttpResponse[any], error) {
|
|||||||
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
httpPath,
|
httpPath,
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// ListContractProcess TODO 待测试
|
// ListContractProcess TODO 待测试
|
||||||
// 查询合约进程
|
// 查询合约进程
|
||||||
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id444
|
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id444
|
||||||
func (c *Client) ListContractProcess() (*HttpResponse[any], error) {
|
func ListContractProcess(c *Client) (*HttpResponse[any], error) {
|
||||||
params := url.Values{
|
params := url.Values{
|
||||||
"action": []string{"listContractProcess"},
|
"action": []string{"listContractProcess"},
|
||||||
}
|
}
|
||||||
@ -879,24 +824,21 @@ func (c *Client) ListContractProcess() (*HttpResponse[any], error) {
|
|||||||
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
httpPath,
|
httpPath,
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// DownloadContract TODO 待测试
|
// DownloadContract TODO 待测试
|
||||||
// 下载合约项目
|
// 下载合约项目
|
||||||
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id25
|
// https://public.internetapi.cn/docs/bdcontract/doc/ContractAPI.html#id25
|
||||||
func (c *Client) DownloadContract(projectName string, isPrivate bool, timestamp int) (*HttpResponse[any], error) {
|
func DownloadContract(c *Client, projectName string, isPrivate bool, timestamp int) (*HttpResponse[any], error) {
|
||||||
params := url.Values{
|
params := url.Values{
|
||||||
"action": []string{"downloadContract"},
|
"action": []string{"downloadContract"},
|
||||||
"projectName": []string{projectName},
|
"projectName": []string{projectName},
|
||||||
@ -907,17 +849,14 @@ func (c *Client) DownloadContract(projectName string, isPrivate bool, timestamp
|
|||||||
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
httpPath := fmt.Sprintf("/SCManager?%s", params.Encode())
|
||||||
|
|
||||||
return retry(func() (*HttpResponse[any], error) {
|
return retry(func() (*HttpResponse[any], error) {
|
||||||
result := PingResponse{}
|
return RequestWithSignature[any](
|
||||||
resp, err := c.RequestWithSignature(
|
c,
|
||||||
httpPath,
|
httpPath,
|
||||||
"GET",
|
"GET",
|
||||||
&result,
|
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
nil,
|
nil,
|
||||||
)
|
)
|
||||||
|
|
||||||
return genHttpResponse[any](result, &resp, err)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -931,8 +870,8 @@ func (c *Client) DownloadContract(projectName string, isPrivate bool, timestamp
|
|||||||
// // 配置中心节点时使用
|
// // 配置中心节点时使用
|
||||||
// LHSProxyAddress string
|
// LHSProxyAddress string
|
||||||
// }
|
// }
|
||||||
func (c *Client) ConfigNode(arg map[string]string) bool {
|
func ConfigNode(c *Client, arg map[string]string) bool {
|
||||||
res, err := c.ResetNodeManager()
|
res, err := ResetNodeManager(c)
|
||||||
|
|
||||||
if err != nil || res.Status == 0 {
|
if err != nil || res.Status == 0 {
|
||||||
return false
|
return false
|
||||||
@ -941,7 +880,7 @@ func (c *Client) ConfigNode(arg map[string]string) bool {
|
|||||||
eg := errgroup.Group{}
|
eg := errgroup.Group{}
|
||||||
for key, value := range arg {
|
for key, value := range arg {
|
||||||
eg.Go(func() error {
|
eg.Go(func() error {
|
||||||
res, err = c.UpdateConfig(key, value)
|
res, err = UpdateConfig(c, key, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -956,7 +895,7 @@ func (c *Client) ConfigNode(arg map[string]string) bool {
|
|||||||
|
|
||||||
for _, value := range []string{"ContractProvider", "ContractUser", "ContractInstanceManager"} {
|
for _, value := range []string{"ContractProvider", "ContractUser", "ContractInstanceManager"} {
|
||||||
eg.Go(func() error {
|
eg.Go(func() error {
|
||||||
res, err = c.ApplyNodeRole(value)
|
res, err = ApplyNodeRole(c, value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -970,7 +909,7 @@ func (c *Client) ConfigNode(arg map[string]string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
eg.Go(func() error {
|
eg.Go(func() error {
|
||||||
res, err = c.AuthNodeRole(true, c.pubHex, nil, nil)
|
res, err = AuthNodeRole(c, true, c.pubHex, nil, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -987,7 +926,7 @@ func (c *Client) ConfigNode(arg map[string]string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
res, err = c.LoadNodeConfig()
|
res, err = LoadNodeConfig(c)
|
||||||
if err != nil || res.Status == 0 {
|
if err != nil || res.Status == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
@ -2,8 +2,6 @@ package client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"go.fusiongalaxy.cn/bdware/bdcontract-client/sm2util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestStruct(t *testing.T) {
|
func TestStruct(t *testing.T) {
|
||||||
@ -19,17 +17,11 @@ func TestStruct(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func genClient() (*Client, error) {
|
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")
|
pub := "042731bc66608ba21a4301cd6522e3d6a6c7964f8dc3618cfe5d0aae493229a98623de23dfb35a5f9b7b4ac53e1f82ea79325ddf96d88a6bbcaf075df7e98acc5a"
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
priv, err := sm2util.ParsePrivateKey("1d4196947f59532db6f8f4055e58474a48db8f30b476ae3edc66406464521b3b", pub)
|
priv := "481343eac82e0d18f8ea3a9f82a8f065543d720209e9f0d8d508f7e343883c45"
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
client, err := NewClient(url, priv, pub, HttpCOptions{})
|
client, err := NewClient(url, priv, pub, HttpCOptions{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -54,7 +46,7 @@ func TestClient_Ping(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.Ping()
|
resp, err := Ping(client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Log(resp.Status)
|
t.Log(resp.Status)
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
@ -70,7 +62,7 @@ func TestClient_StartContract(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.StartContract("contract TestContract")
|
resp, err := StartContract(client, "contract TestContract")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Log(resp)
|
t.Log(resp)
|
||||||
@ -86,7 +78,7 @@ func TestClient_ExecuteContract(t *testing.T) {
|
|||||||
t.Error(err)
|
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 {
|
if err != nil {
|
||||||
t.Log(resp)
|
t.Log(resp)
|
||||||
@ -102,7 +94,7 @@ func TestClient_LoadNodeConfig(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
config, err := client.LoadNodeConfig()
|
config, err := LoadNodeConfig(client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Log(config)
|
t.Log(config)
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user