Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
a98d707e48 | ||
|
e575463bad | ||
|
93d969ce86 | ||
|
f46b1a08ee |
@ -280,7 +280,7 @@ func (c *Client) StartContractByYPK(isPrivate bool, path string, script string)
|
|||||||
func (c *Client) ExecuteContract(
|
func (c *Client) ExecuteContract(
|
||||||
contractID string,
|
contractID string,
|
||||||
operation string,
|
operation string,
|
||||||
arg string,
|
arg any,
|
||||||
withDynamicAnalysis bool,
|
withDynamicAnalysis bool,
|
||||||
withSignature bool,
|
withSignature bool,
|
||||||
) (*HttpResponse[ExecuteContractResponse[any]], error) {
|
) (*HttpResponse[ExecuteContractResponse[any]], error) {
|
||||||
@ -293,7 +293,18 @@ func (c *Client) ExecuteContract(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if withSignature {
|
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
|
body["pubkey"] = c.pubHex
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,14 +19,14 @@ func TestStruct(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func genClient() (*Client, error) {
|
func genClient() (*Client, error) {
|
||||||
url := "https://cpnode.demo.internetapi.cn/api/ctrlproxy/SCIDE"
|
url := "http://127.0.0.1:21030/SCIDE"
|
||||||
|
|
||||||
pub, err := sm2util.ParsePublicKey("04153ad2d70e67741e0fc33e0c92c702e2afba2480dbea73d23fd02a3ce3a1b69979a7006a8e045f8836ae4797a8fe426823d7ad3450817e794948c8e47b60b711")
|
pub, err := sm2util.ParsePublicKey("04180354fdb6507f8ab98ccfbe165ce11da74ba733f81af86ad6d32216b32cf4f797c559d50ceeefbf4c760c3483840471c67471b90acdffb388cd7d496d9a1610")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
priv, err := sm2util.ParsePrivateKey("31672b434458fdb6b854e64ededeb51305bc4d0bd258a5276ccb9bc86f7c03f6", pub)
|
priv, err := sm2util.ParsePrivateKey("1d4196947f59532db6f8f4055e58474a48db8f30b476ae3edc66406464521b3b", pub)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -70,7 +70,7 @@ func TestClient_StartContract(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.StartContract("contract TestContract {}")
|
resp, err := client.StartContract("contract TestContract")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Log(resp)
|
t.Log(resp)
|
||||||
@ -86,7 +86,7 @@ func TestClient_ExecuteContract(t *testing.T) {
|
|||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := client.ExecuteContract("ShanxiControlProxy", "listRepository", "", false, true)
|
resp, err := client.ExecuteContract("GlobalRouter", "listID", 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)
|
||||||
|
@ -8,14 +8,10 @@ type HttpResponse[D any] struct {
|
|||||||
|
|
||||||
// ClientResponse represents a generic response structure
|
// ClientResponse represents a generic response structure
|
||||||
type ClientResponse[T any] struct {
|
type ClientResponse[T any] struct {
|
||||||
NeedSeq bool `json:"needSeq,omitempty"`
|
NeedSeq bool `json:"needSeq,omitempty"`
|
||||||
Seq int `json:"seq,omitempty"`
|
Seq int `json:"seq,omitempty"`
|
||||||
Status string `json:"status,omitempty"`
|
Status string `json:"status,omitempty"`
|
||||||
Result struct {
|
Result T `json:"result,omitempty"`
|
||||||
Data T `json:"data,omitempty"`
|
|
||||||
Count int `json:"count,omitempty"`
|
|
||||||
Code int `json:"code,omitempty"`
|
|
||||||
} `json:"result,omitempty"`
|
|
||||||
IsInsnLimit bool `json:"isInsnLimit,omitempty"`
|
IsInsnLimit bool `json:"isInsnLimit,omitempty"`
|
||||||
TotalGas int `json:"totalGas,omitempty"`
|
TotalGas int `json:"totalGas,omitempty"`
|
||||||
ExecutionGas int `json:"executionGas,omitempty"`
|
ExecutionGas int `json:"executionGas,omitempty"`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user