Merge pull request #517 from cosmos/516-ibc-pagination

Add pagination params to IBC queries
This commit is contained in:
Will Clark 2020-11-05 14:07:27 +01:00 committed by GitHub
commit fa8f0c7d24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 24 deletions

View File

@ -26,9 +26,10 @@ export interface IbcExtension {
portId: string,
channelId: string,
) => Promise<ibc.core.channel.v1.IQueryChannelResponse>;
readonly channels: () => Promise<ibc.core.channel.v1.IQueryChannelsResponse>;
readonly channels: (paginationKey?: Uint8Array) => Promise<ibc.core.channel.v1.IQueryChannelsResponse>;
readonly connectionChannels: (
connection: string,
paginationKey?: Uint8Array,
) => Promise<ibc.core.channel.v1.IQueryConnectionChannelsResponse>;
readonly packetCommitment: (
portId: string,
@ -38,6 +39,7 @@ export interface IbcExtension {
readonly packetCommitments: (
portId: string,
channelId: string,
paginationKey?: Uint8Array,
) => Promise<ibc.core.channel.v1.IQueryPacketCommitmentsResponse>;
readonly packetAcknowledgement: (
portId: string,
@ -62,7 +64,9 @@ export interface IbcExtension {
// Queries for ibc.core.connection.v1
readonly connection: (connectionId: string) => Promise<ibc.core.connection.v1.IQueryConnectionResponse>;
readonly connections: () => Promise<ibc.core.connection.v1.IQueryConnectionsResponse>;
readonly connections: (
paginationKey?: Uint8Array,
) => Promise<ibc.core.connection.v1.IQueryConnectionsResponse>;
readonly clientConnections: (
clientId: string,
) => Promise<ibc.core.connection.v1.IQueryClientConnectionsResponse>;
@ -74,7 +78,7 @@ 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 = ChannelQuery.create((method: any, requestData, callback) => {
const channelQueryService = ChannelQuery.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.core.channel.v1.Query/${method.name}`;
base
@ -83,7 +87,7 @@ export function setupIbcExtension(base: QueryClient): IbcExtension {
.catch((error) => callback(error));
});
const connectionQuerySerice = ConnectionQuery.create((method: any, requestData, callback) => {
const connectionQueryService = ConnectionQuery.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.core.connection.v1.Query/${method.name}`;
base
@ -128,34 +132,43 @@ export function setupIbcExtension(base: QueryClient): IbcExtension {
unverified: {
// Queries for ibc.core.channel.v1
channel: async (portId: string, channelId: string) => {
const response = await channelQuerySerice.channel({ portId: portId, channelId: channelId });
const response = await channelQueryService.channel({ portId: portId, channelId: channelId });
return toObject(response);
},
channels: async () => {
const response = await channelQuerySerice.channels({});
channels: async (paginationKey?: Uint8Array) => {
const request = {
pagination: paginationKey ? { key: paginationKey } : undefined,
};
const response = await channelQueryService.channels(request);
return toObject(response);
},
connectionChannels: async (connection: string) => {
const response = await channelQuerySerice.connectionChannels({ connection: connection });
connectionChannels: async (connection: string, paginationKey?: Uint8Array) => {
const request = {
connection: connection,
pagination: paginationKey ? { key: paginationKey } : undefined,
};
const response = await channelQueryService.connectionChannels(request);
return toObject(response);
},
packetCommitment: async (portId: string, channelId: string, sequence: number) => {
const response = await channelQuerySerice.packetCommitment({
const response = await channelQueryService.packetCommitment({
portId: portId,
channelId: channelId,
sequence: Long.fromNumber(sequence),
});
return toObject(response);
},
packetCommitments: async (portId: string, channelId: string) => {
const response = await channelQuerySerice.packetCommitments({
portId: portId,
packetCommitments: async (portId: string, channelId: string, paginationKey?: Uint8Array) => {
const request = {
channelId: channelId,
});
portId: portId,
pagination: paginationKey ? { key: paginationKey } : undefined,
};
const response = await channelQueryService.packetCommitments(request);
return toObject(response);
},
packetAcknowledgement: async (portId: string, channelId: string, sequence: number) => {
const response = await channelQuerySerice.packetAcknowledgement({
const response = await channelQueryService.packetAcknowledgement({
portId: portId,
channelId: channelId,
sequence: Long.fromNumber(sequence),
@ -167,7 +180,7 @@ export function setupIbcExtension(base: QueryClient): IbcExtension {
channelId: string,
packetCommitmentSequences: readonly number[],
) => {
const response = await channelQuerySerice.unreceivedPackets({
const response = await channelQueryService.unreceivedPackets({
portId: portId,
channelId: channelId,
packetCommitmentSequences: packetCommitmentSequences.map((s) => Long.fromNumber(s)),
@ -175,7 +188,7 @@ export function setupIbcExtension(base: QueryClient): IbcExtension {
return toObject(response);
},
unreceivedAcks: async (portId: string, channelId: string, packetAckSequences: readonly number[]) => {
const response = await channelQuerySerice.unreceivedAcks({
const response = await channelQueryService.unreceivedAcks({
portId: portId,
channelId: channelId,
packetAckSequences: packetAckSequences.map((s) => Long.fromNumber(s)),
@ -183,7 +196,7 @@ export function setupIbcExtension(base: QueryClient): IbcExtension {
return toObject(response);
},
nextSequenceReceive: async (portId: string, channelId: string) => {
const response = await channelQuerySerice.nextSequenceReceive({
const response = await channelQueryService.nextSequenceReceive({
portId: portId,
channelId: channelId,
});
@ -193,15 +206,18 @@ export function setupIbcExtension(base: QueryClient): IbcExtension {
// Queries for ibc.core.connection.v1
connection: async (connectionId: string) => {
const response = await connectionQuerySerice.connection({ connectionId: connectionId });
const response = await connectionQueryService.connection({ connectionId: connectionId });
return toObject(response);
},
connections: async () => {
const response = await connectionQuerySerice.connections({});
connections: async (paginationKey?: Uint8Array) => {
const request = {
pagination: paginationKey ? { key: paginationKey } : undefined,
};
const response = await connectionQueryService.connections(request);
return toObject(response);
},
clientConnections: async (clientId: string) => {
const response = await connectionQuerySerice.clientConnections({ clientId: clientId });
const response = await connectionQueryService.clientConnections({ clientId: clientId });
return toObject(response);
},
},

View File

@ -15,9 +15,10 @@ export interface IbcExtension {
portId: string,
channelId: string,
) => Promise<ibc.core.channel.v1.IQueryChannelResponse>;
readonly channels: () => Promise<ibc.core.channel.v1.IQueryChannelsResponse>;
readonly channels: (paginationKey?: Uint8Array) => Promise<ibc.core.channel.v1.IQueryChannelsResponse>;
readonly connectionChannels: (
connection: string,
paginationKey?: Uint8Array,
) => Promise<ibc.core.channel.v1.IQueryConnectionChannelsResponse>;
readonly packetCommitment: (
portId: string,
@ -27,6 +28,7 @@ export interface IbcExtension {
readonly packetCommitments: (
portId: string,
channelId: string,
paginationKey?: Uint8Array,
) => Promise<ibc.core.channel.v1.IQueryPacketCommitmentsResponse>;
readonly packetAcknowledgement: (
portId: string,
@ -48,7 +50,9 @@ export interface IbcExtension {
channelId: string,
) => Promise<ibc.core.channel.v1.IQueryNextSequenceReceiveResponse>;
readonly connection: (connectionId: string) => Promise<ibc.core.connection.v1.IQueryConnectionResponse>;
readonly connections: () => Promise<ibc.core.connection.v1.IQueryConnectionsResponse>;
readonly connections: (
paginationKey?: Uint8Array,
) => Promise<ibc.core.connection.v1.IQueryConnectionsResponse>;
readonly clientConnections: (
clientId: string,
) => Promise<ibc.core.connection.v1.IQueryClientConnectionsResponse>;