ref(clientactor): 优化 ExecuteContract 函数参数类型

- 将 ExecuteContract 函数的 arg 参数类型从 string 改为 any
- 增加对 arg 参数的类型判断和处理,支持字符串和其他类型的数据
- 修改签名逻辑,确保兼容新的 arg 参数类型
- 更新单元测试,演示新的 ExecuteContract 调用方式
This commit is contained in:
zhaoweijie
2025-03-08 11:43:49 +08:00
parent e575463bad
commit a98d707e48
2 changed files with 17 additions and 6 deletions

View File

@@ -280,7 +280,7 @@ func (c *Client) StartContractByYPK(isPrivate bool, path string, script string)
func (c *Client) ExecuteContract(
contractID string,
operation string,
arg string,
arg any,
withDynamicAnalysis bool,
withSignature bool,
) (*HttpResponse[ExecuteContractResponse[any]], error) {
@@ -293,7 +293,18 @@ func (c *Client) ExecuteContract(
}
if withSignature {
body["signature"] = c.Sign(contractID+"|"+operation+"|"+arg+"|"+c.pubHex, nil, nil)
argStr := ""
if v, ok := arg.(string); ok {
argStr = v
} else {
v, err := json.Marshal(arg)
if err != nil {
return nil, fmt.Errorf("arg %v marshal err", arg)
}
argStr = string(v)
}
body["signature"] = c.Sign(contractID+"|"+operation+"|"+argStr+"|"+c.pubHex, nil, nil)
body["pubkey"] = c.pubHex
}