ref(clientactor): 优化 ExecuteContract 函数参数类型
- 将 ExecuteContract 函数的 arg 参数类型从 string 改为 any - 增加对 arg 参数的类型判断和处理,支持字符串和其他类型的数据 - 修改签名逻辑,确保兼容新的 arg 参数类型 - 更新单元测试,演示新的 ExecuteContract 调用方式
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user