Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflection example #97

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/osmojs/scripts/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ telescope({
'cosmos.app.v1beta1',
'cosmos.autocli.v1',
'cosmos.base.kv.v1beta1',
'cosmos.base.reflection.v1beta1',
// 'cosmos.base.reflection.v1beta1',
'cosmos.base.snapshots.v1beta1',
'cosmos.base.store.v1beta1',
'cosmos.base.tendermint.v1beta1',
Expand Down Expand Up @@ -106,6 +106,7 @@ telescope({
},
rpcClients: {
enabled: true,
enabledServices: ['Service', 'Msg', 'Query', 'ReflectionService'],
camelCase: true,
useConnectComet: true
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//@ts-nocheck
import { LCDClient } from "@cosmology/lcd";
import { ListAllInterfacesRequest, ListAllInterfacesResponseSDKType, ListImplementationsRequest, ListImplementationsResponseSDKType } from "./reflection";
export class LCDQueryClient {
req: LCDClient;
constructor({
requestClient
}: {
requestClient: LCDClient;
}) {
this.req = requestClient;
this.listAllInterfaces = this.listAllInterfaces.bind(this);
this.listImplementations = this.listImplementations.bind(this);
}
/* ListAllInterfaces lists all the interfaces registered in the interface
registry. */
async listAllInterfaces(_params: ListAllInterfacesRequest = {}): Promise<ListAllInterfacesResponseSDKType> {
const endpoint = `cosmos/base/reflection/v1beta1/interfaces`;
return await this.req.get<ListAllInterfacesResponseSDKType>(endpoint);
}
/* ListImplementations list all the concrete types that implement a given
interface. */
async listImplementations(params: ListImplementationsRequest): Promise<ListImplementationsResponseSDKType> {
const endpoint = `cosmos/base/reflection/v1beta1/interfaces/${params.interfaceName}/implementations`;
return await this.req.get<ListImplementationsResponseSDKType>(endpoint);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//@ts-nocheck
import { Rpc } from "../../../../helpers";
import { BinaryReader } from "../../../../binary";
import { QueryClient, createProtobufRpcClient } from "@cosmjs/stargate";
import { ListAllInterfacesRequest, ListAllInterfacesResponse, ListImplementationsRequest, ListImplementationsResponse } from "./reflection";
/** ReflectionService defines a service for interface reflection. */
export interface ReflectionService {
/**
* ListAllInterfaces lists all the interfaces registered in the interface
* registry.
*/
listAllInterfaces(request?: ListAllInterfacesRequest): Promise<ListAllInterfacesResponse>;
/**
* ListImplementations list all the concrete types that implement a given
* interface.
*/
listImplementations(request: ListImplementationsRequest): Promise<ListImplementationsResponse>;
}
export class ReflectionServiceClientImpl implements ReflectionService {
private readonly rpc: Rpc;
constructor(rpc: Rpc) {
this.rpc = rpc;
this.listAllInterfaces = this.listAllInterfaces.bind(this);
this.listImplementations = this.listImplementations.bind(this);
}
listAllInterfaces(request: ListAllInterfacesRequest = {}): Promise<ListAllInterfacesResponse> {
const data = ListAllInterfacesRequest.encode(request).finish();
const promise = this.rpc.request("cosmos.base.reflection.v1beta1.ReflectionService", "ListAllInterfaces", data);
return promise.then(data => ListAllInterfacesResponse.decode(new BinaryReader(data)));
}
listImplementations(request: ListImplementationsRequest): Promise<ListImplementationsResponse> {
const data = ListImplementationsRequest.encode(request).finish();
const promise = this.rpc.request("cosmos.base.reflection.v1beta1.ReflectionService", "ListImplementations", data);
return promise.then(data => ListImplementationsResponse.decode(new BinaryReader(data)));
}
}
export const createRpcQueryExtension = (base: QueryClient) => {
const rpc = createProtobufRpcClient(base);
const queryService = new ReflectionServiceClientImpl(rpc);
return {
listAllInterfaces(request?: ListAllInterfacesRequest): Promise<ListAllInterfacesResponse> {
return queryService.listAllInterfaces(request);
},
listImplementations(request: ListImplementationsRequest): Promise<ListImplementationsResponse> {
return queryService.listImplementations(request);
}
};
};
Loading
Loading