generated from okp4/template-oss
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
2,990 additions
and
3,401 deletions.
There are no files selected for viewing
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
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 schema | ||
|
||
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 { | ||
// Dataverse is the client API for the QueryMsg_Dataverse query message | ||
Dataverse(ctx context.Context, req *QueryMsg_Dataverse, opts ...grpc.CallOption) (*DataverseResponse, 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) Dataverse(ctx context.Context, req *QueryMsg_Dataverse, opts ...grpc.CallOption) (*DataverseResponse, error) { | ||
rawQueryData, err := json.Marshal(map[string]any{"dataverse": req}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
rawResponseData, err := q.queryContract(ctx, rawQueryData, opts...) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var response DataverseResponse | ||
if err := json.Unmarshal(rawResponseData, &response); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &response, nil | ||
} |
Oops, something went wrong.