From ed02a75354aa06f50d1c5cf62851d543b5dcfe9f Mon Sep 17 00:00:00 2001 From: Simon Warta Date: Tue, 18 Aug 2020 12:37:39 +0200 Subject: [PATCH] Add ibc.connection queries --- packages/stargate/src/queries/ibc.spec.ts | 40 +++++++++++++++++++++++ packages/stargate/src/queries/ibc.ts | 34 +++++++++++++++++++ packages/stargate/types/queries/ibc.d.ts | 3 ++ 3 files changed, 77 insertions(+) diff --git a/packages/stargate/src/queries/ibc.spec.ts b/packages/stargate/src/queries/ibc.spec.ts index 8f397b13..3cbb128a 100644 --- a/packages/stargate/src/queries/ibc.spec.ts +++ b/packages/stargate/src/queries/ibc.spec.ts @@ -113,5 +113,45 @@ describe("IbcExtension", () => { tmClient.disconnect(); }); }); + + // Queries for ibc.connection + + describe("connection", () => { + it("can be called", async () => { + pending("Fails with 'Query failed with (1): internal'. Make it work."); + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.connection("foo"); + expect(response).toBeTruthy(); // TODO: implement checks + + tmClient.disconnect(); + }); + }); + + describe("connections", () => { + it("can be called", async () => { + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.connections(); + expect(response).toBeTruthy(); // TODO: implement checks + + tmClient.disconnect(); + }); + }); + + describe("clientConnections", () => { + it("can be called", async () => { + pending("Fails with 'Query failed with (1): internal'. Make it work."); + pendingWithoutSimapp(); + const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl); + + const response = await client.ibc.unverified.clientConnections(); + expect(response).toBeTruthy(); // TODO: implement checks + + tmClient.disconnect(); + }); + }); }); }); diff --git a/packages/stargate/src/queries/ibc.ts b/packages/stargate/src/queries/ibc.ts index 98378b94..06e1ecbb 100644 --- a/packages/stargate/src/queries/ibc.ts +++ b/packages/stargate/src/queries/ibc.ts @@ -5,6 +5,8 @@ import { toObject } from "./utils"; export interface IbcExtension { readonly ibc: { readonly unverified: { + // Queries for ibc.channel + readonly channel: (portId: string, channelId: string) => Promise; readonly channels: () => Promise; readonly connectionChannels: () => Promise; @@ -13,6 +15,12 @@ export interface IbcExtension { readonly packetAcknowledgement: () => Promise; readonly unrelayedPackets: () => Promise; readonly nextSequenceReceive: () => Promise; + + // Queries for ibc.connection + + readonly connection: (connectionId: string) => Promise; + readonly connections: () => Promise; + readonly clientConnections: () => Promise; }; }; } @@ -30,9 +38,20 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { .catch((error) => callback(error)); }); + const connectionQuerySerice = ibc.connection.Query.create((method: any, requestData, callback) => { + // Parts of the path are unavailable, so we hardcode them here. See https://github.com/protobufjs/protobuf.js/issues/1229 + const path = `/ibc.connection.Query/${method.name}`; + base + .queryUnverified(path, requestData) + .then((response) => callback(null, response)) + .catch((error) => callback(error)); + }); + return { ibc: { unverified: { + // Queries for ibc.channel + channel: async (portId: string, channelId: string) => { const response = await channelQuerySerice.channel({ portId: portId, channelId: channelId }); return toObject(response); @@ -65,6 +84,21 @@ export function setupIbcExtension(base: QueryClient): IbcExtension { const response = await channelQuerySerice.nextSequenceReceive({}); return toObject(response); }, + + // Queries for ibc.connection + + connection: async (connectionId: string) => { + const response = await connectionQuerySerice.connection({ connectionId: connectionId }); + return toObject(response); + }, + connections: async () => { + const response = await connectionQuerySerice.connections({}); + return toObject(response); + }, + clientConnections: async () => { + const response = await connectionQuerySerice.clientConnections({}); + return toObject(response); + }, }, }, }; diff --git a/packages/stargate/types/queries/ibc.d.ts b/packages/stargate/types/queries/ibc.d.ts index 59d1c666..e9ba331f 100644 --- a/packages/stargate/types/queries/ibc.d.ts +++ b/packages/stargate/types/queries/ibc.d.ts @@ -11,6 +11,9 @@ export interface IbcExtension { readonly packetAcknowledgement: () => Promise; readonly unrelayedPackets: () => Promise; readonly nextSequenceReceive: () => Promise; + readonly connection: (connectionId: string) => Promise; + readonly connections: () => Promise; + readonly clientConnections: () => Promise; }; }; }