-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
imp(e2e): add contract query clients (#103)
* e2e: generated query clients * e2e: using query client now * fix: e2e * imp: regenerated query client
- Loading branch information
Showing
8 changed files
with
557 additions
and
179 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* Code generated by github.com/srdtrk/go-codegen, DO NOT EDIT. */ | ||
package callbackcounter | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types" | ||
grpc "google.golang.org/grpc" | ||
insecure "google.golang.org/grpc/credentials/insecure" | ||
) | ||
|
||
// QueryClient is the client API for Query service. | ||
// | ||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. | ||
type QueryClient interface { | ||
// GetCallbackCounter is the client API for the QueryMsg_GetCallbackCounter query message | ||
GetCallbackCounter(ctx context.Context, req *QueryMsg_GetCallbackCounter, opts ...grpc.CallOption) (*CallbackCounter, error) | ||
} | ||
|
||
type queryClient struct { | ||
cc *grpc.ClientConn | ||
address string | ||
} | ||
|
||
var _ QueryClient = (*queryClient)(nil) | ||
|
||
// NewQueryClient creates a new QueryClient | ||
func NewQueryClient(gRPCAddress, contractAddress string, opts ...grpc.DialOption) (QueryClient, error) { | ||
if len(opts) == 0 { | ||
opts = append(opts, grpc.WithTransportCredentials(insecure.NewCredentials())) | ||
} | ||
|
||
// Create a connection to the gRPC server | ||
grpcConn, err := grpc.Dial(gRPCAddress, opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return &queryClient{ | ||
address: contractAddress, | ||
cc: grpcConn, | ||
}, nil | ||
} | ||
|
||
// Close closes the gRPC connection to the server | ||
func (q *queryClient) Close() error { | ||
return q.cc.Close() | ||
} | ||
|
||
// queryContract is a helper function to query the contract with raw query data | ||
func (q *queryClient) queryContract(ctx context.Context, rawQueryData []byte, opts ...grpc.CallOption) ([]byte, error) { | ||
in := &wasmtypes.QuerySmartContractStateRequest{ | ||
Address: q.address, | ||
QueryData: rawQueryData, | ||
} | ||
out := new(wasmtypes.QuerySmartContractStateResponse) | ||
err := q.cc.Invoke(ctx, "/cosmwasm.wasm.v1.Query/SmartContractState", in, out, opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return out.Data, nil | ||
} | ||
|
||
func (q *queryClient) GetCallbackCounter(ctx context.Context, req *QueryMsg_GetCallbackCounter, opts ...grpc.CallOption) (*CallbackCounter, error) { | ||
rawQueryData, err := json.Marshal(&QueryMsg{GetCallbackCounter: req}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
rawResponseData, err := q.queryContract(ctx, rawQueryData, opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var response CallbackCounter | ||
if err := json.Unmarshal(rawResponseData, &response); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &response, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.