Add IbcExtension
This commit is contained in:
parent
a08c8d7759
commit
7f13fd4f7b
117
packages/stargate/src/queries/ibc.spec.ts
Normal file
117
packages/stargate/src/queries/ibc.spec.ts
Normal file
@ -0,0 +1,117 @@
|
||||
import { Client as TendermintClient } from "@cosmjs/tendermint-rpc";
|
||||
|
||||
import { pendingWithoutSimapp, simapp } from "../testutils.spec";
|
||||
import { IbcExtension, setupIbcExtension } from "./ibc";
|
||||
import { QueryClient } from "./queryclient";
|
||||
|
||||
async function makeClientWithIbc(rpcUrl: string): Promise<[QueryClient & IbcExtension, TendermintClient]> {
|
||||
const tmClient = await TendermintClient.connect(rpcUrl);
|
||||
return [QueryClient.withExtensions(tmClient, setupIbcExtension), tmClient];
|
||||
}
|
||||
|
||||
describe("IbcExtension", () => {
|
||||
describe("unverified", () => {
|
||||
describe("channel", () => {
|
||||
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.channel("foo", "bar");
|
||||
expect(response).toBeTruthy(); // TODO: implement checks
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("channels", () => {
|
||||
it("can be called", async () => {
|
||||
pendingWithoutSimapp();
|
||||
const [client, tmClient] = await makeClientWithIbc(simapp.tendermintUrl);
|
||||
|
||||
const response = await client.ibc.unverified.channels();
|
||||
expect(response).toBeTruthy(); // TODO: implement checks
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("connectionChannels", () => {
|
||||
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.connectionChannels();
|
||||
expect(response).toBeTruthy(); // TODO: implement checks
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("packetCommitment", () => {
|
||||
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.packetCommitment();
|
||||
expect(response).toBeTruthy(); // TODO: implement checks
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("packetCommitments", () => {
|
||||
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.packetCommitments();
|
||||
expect(response).toBeTruthy(); // TODO: implement checks
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("packetAcknowledgement", () => {
|
||||
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.packetAcknowledgement();
|
||||
expect(response).toBeTruthy(); // TODO: implement checks
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("unrelayedPackets", () => {
|
||||
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.unrelayedPackets();
|
||||
expect(response).toBeTruthy(); // TODO: implement checks
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
|
||||
describe("nextSequenceReceive", () => {
|
||||
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.nextSequenceReceive();
|
||||
expect(response).toBeTruthy(); // TODO: implement checks
|
||||
|
||||
tmClient.disconnect();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
71
packages/stargate/src/queries/ibc.ts
Normal file
71
packages/stargate/src/queries/ibc.ts
Normal file
@ -0,0 +1,71 @@
|
||||
import { ibc } from "../codec";
|
||||
import { QueryClient } from "./queryclient";
|
||||
import { toObject } from "./utils";
|
||||
|
||||
export interface IbcExtension {
|
||||
readonly ibc: {
|
||||
readonly unverified: {
|
||||
readonly channel: (portId: string, channelId: string) => Promise<ibc.channel.IQueryChannelResponse>;
|
||||
readonly channels: () => Promise<ibc.channel.IQueryChannelsResponse>;
|
||||
readonly connectionChannels: () => Promise<ibc.channel.IQueryConnectionChannelsResponse>;
|
||||
readonly packetCommitment: () => Promise<ibc.channel.IQueryPacketCommitmentResponse>;
|
||||
readonly packetCommitments: () => Promise<ibc.channel.IQueryPacketCommitmentsResponse>;
|
||||
readonly packetAcknowledgement: () => Promise<ibc.channel.IQueryPacketAcknowledgementResponse>;
|
||||
readonly unrelayedPackets: () => Promise<ibc.channel.IQueryUnrelayedPacketsResponse>;
|
||||
readonly nextSequenceReceive: () => Promise<ibc.channel.IQueryNextSequenceReceiveResponse>;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export function setupIbcExtension(base: QueryClient): IbcExtension {
|
||||
// Use this service to get easy typed access to query methods
|
||||
// This cannot be used to for proof verification
|
||||
|
||||
const channelQuerySerice = ibc.channel.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.channel.Query/${method.name}`;
|
||||
base
|
||||
.queryUnverified(path, requestData)
|
||||
.then((response) => callback(null, response))
|
||||
.catch((error) => callback(error));
|
||||
});
|
||||
|
||||
return {
|
||||
ibc: {
|
||||
unverified: {
|
||||
channel: async (portId: string, channelId: string) => {
|
||||
const response = await channelQuerySerice.channel({ portId: portId, channelId: channelId });
|
||||
return toObject(response);
|
||||
},
|
||||
channels: async () => {
|
||||
const response = await channelQuerySerice.channels({});
|
||||
return toObject(response);
|
||||
},
|
||||
connectionChannels: async () => {
|
||||
const response = await channelQuerySerice.connectionChannels({});
|
||||
return toObject(response);
|
||||
},
|
||||
packetCommitment: async () => {
|
||||
const response = await channelQuerySerice.packetCommitment({});
|
||||
return toObject(response);
|
||||
},
|
||||
packetCommitments: async () => {
|
||||
const response = await channelQuerySerice.packetCommitments({});
|
||||
return toObject(response);
|
||||
},
|
||||
packetAcknowledgement: async () => {
|
||||
const response = await channelQuerySerice.packetAcknowledgement({});
|
||||
return toObject(response);
|
||||
},
|
||||
unrelayedPackets: async () => {
|
||||
const response = await channelQuerySerice.unrelayedPackets({});
|
||||
return toObject(response);
|
||||
},
|
||||
nextSequenceReceive: async () => {
|
||||
const response = await channelQuerySerice.nextSequenceReceive({});
|
||||
return toObject(response);
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
}
|
||||
@ -6,3 +6,4 @@ export { QueryClient } from "./queryclient";
|
||||
|
||||
export { AuthExtension, setupAuthExtension } from "./auth";
|
||||
export { BankExtension, setupBankExtension } from "./bank";
|
||||
export { IbcExtension, setupIbcExtension } from "./ibc";
|
||||
|
||||
17
packages/stargate/types/queries/ibc.d.ts
vendored
Normal file
17
packages/stargate/types/queries/ibc.d.ts
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
import { ibc } from "../codec";
|
||||
import { QueryClient } from "./queryclient";
|
||||
export interface IbcExtension {
|
||||
readonly ibc: {
|
||||
readonly unverified: {
|
||||
readonly channel: (portId: string, channelId: string) => Promise<ibc.channel.IQueryChannelResponse>;
|
||||
readonly channels: () => Promise<ibc.channel.IQueryChannelsResponse>;
|
||||
readonly connectionChannels: () => Promise<ibc.channel.IQueryConnectionChannelsResponse>;
|
||||
readonly packetCommitment: () => Promise<ibc.channel.IQueryPacketCommitmentResponse>;
|
||||
readonly packetCommitments: () => Promise<ibc.channel.IQueryPacketCommitmentsResponse>;
|
||||
readonly packetAcknowledgement: () => Promise<ibc.channel.IQueryPacketAcknowledgementResponse>;
|
||||
readonly unrelayedPackets: () => Promise<ibc.channel.IQueryUnrelayedPacketsResponse>;
|
||||
readonly nextSequenceReceive: () => Promise<ibc.channel.IQueryNextSequenceReceiveResponse>;
|
||||
};
|
||||
};
|
||||
}
|
||||
export declare function setupIbcExtension(base: QueryClient): IbcExtension;
|
||||
1
packages/stargate/types/queries/index.d.ts
vendored
1
packages/stargate/types/queries/index.d.ts
vendored
@ -1,3 +1,4 @@
|
||||
export { QueryClient } from "./queryclient";
|
||||
export { AuthExtension, setupAuthExtension } from "./auth";
|
||||
export { BankExtension, setupBankExtension } from "./bank";
|
||||
export { IbcExtension, setupIbcExtension } from "./ibc";
|
||||
|
||||
Loading…
Reference in New Issue
Block a user