-
Notifications
You must be signed in to change notification settings - Fork 0
/
cosmwasm.go
38 lines (30 loc) · 865 Bytes
/
cosmwasm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package gosm
import (
"context"
"encoding/json"
"fmt"
wasm_types "github.com/CosmWasm/wasmd/x/wasm/types"
)
func (client *RPCClient) QuerySmartContractState(ctx context.Context, address string, query any) (*wasm_types.QuerySmartContractStateResponse, error) {
data, err := json.Marshal(query)
if err != nil {
return nil, err
}
queryMsg := &wasm_types.QuerySmartContractStateRequest{
Address: address,
QueryData: data,
}
result, err := client.ABCIQuery(ctx, "/cosmwasm.wasm.v1.Query/SmartContractState", queryMsg)
if err != nil {
return nil, err
}
if result.Response.Code != 0 {
return nil, fmt.Errorf("QuerySmartContractState failed: %s", result.Response.Log)
}
var response wasm_types.QuerySmartContractStateResponse
err = response.Unmarshal(result.Response.Value)
if err != nil {
return nil, err
}
return &response, nil
}