mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-11 14:09:15 +00:00
Merge pull request #1085 from cosmos/more-then-100-getCodes
getCodes(): Support more than 100 code IDs
This commit is contained in:
commit
2539a2da62
@ -58,6 +58,7 @@ and this project adheres to
|
|||||||
[#1033]: https://github.com/cosmos/cosmjs/issues/1033
|
[#1033]: https://github.com/cosmos/cosmjs/issues/1033
|
||||||
[#1053]: https://github.com/cosmos/cosmjs/issues/1053
|
[#1053]: https://github.com/cosmos/cosmjs/issues/1053
|
||||||
[#1077]: https://github.com/cosmos/cosmjs/issues/1077
|
[#1077]: https://github.com/cosmos/cosmjs/issues/1077
|
||||||
|
[#1078]: https://github.com/cosmos/cosmjs/issues/1078
|
||||||
[#1079]: https://github.com/cosmos/cosmjs/issues/1079
|
[#1079]: https://github.com/cosmos/cosmjs/issues/1079
|
||||||
|
|
||||||
### Removed
|
### Removed
|
||||||
|
@ -25,7 +25,11 @@ import {
|
|||||||
} from "@cosmjs/stargate";
|
} from "@cosmjs/stargate";
|
||||||
import { Tendermint34Client, toRfc3339WithNanoseconds } from "@cosmjs/tendermint-rpc";
|
import { Tendermint34Client, toRfc3339WithNanoseconds } from "@cosmjs/tendermint-rpc";
|
||||||
import { assert, sleep } from "@cosmjs/utils";
|
import { assert, sleep } from "@cosmjs/utils";
|
||||||
import { CodeInfoResponse, QueryContractsByCodeResponse } from "cosmjs-types/cosmwasm/wasm/v1/query";
|
import {
|
||||||
|
CodeInfoResponse,
|
||||||
|
QueryCodesResponse,
|
||||||
|
QueryContractsByCodeResponse,
|
||||||
|
} from "cosmjs-types/cosmwasm/wasm/v1/query";
|
||||||
import { ContractCodeHistoryOperationType } from "cosmjs-types/cosmwasm/wasm/v1/types";
|
import { ContractCodeHistoryOperationType } from "cosmjs-types/cosmwasm/wasm/v1/types";
|
||||||
|
|
||||||
import { JsonObject, setupWasmExtension, WasmExtension } from "./modules";
|
import { JsonObject, setupWasmExtension, WasmExtension } from "./modules";
|
||||||
@ -303,9 +307,25 @@ export class CosmWasmClient {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getCodes() returns all codes and is just looping through all pagination pages.
|
||||||
|
*
|
||||||
|
* This is potentially inefficient and advanced apps should consider creating
|
||||||
|
* their own query client to handle pagination together with the app's screens.
|
||||||
|
*/
|
||||||
public async getCodes(): Promise<readonly Code[]> {
|
public async getCodes(): Promise<readonly Code[]> {
|
||||||
const { codeInfos } = await this.forceGetQueryClient().wasm.listCodeInfo();
|
const allCodes = [];
|
||||||
return (codeInfos || []).map((entry: CodeInfoResponse): Code => {
|
|
||||||
|
let startAtKey: Uint8Array | undefined = undefined;
|
||||||
|
do {
|
||||||
|
const { codeInfos, pagination }: QueryCodesResponse =
|
||||||
|
await this.forceGetQueryClient().wasm.listCodeInfo(startAtKey);
|
||||||
|
const loadedCodes = codeInfos || [];
|
||||||
|
allCodes.push(...loadedCodes);
|
||||||
|
startAtKey = pagination?.nextKey;
|
||||||
|
} while (startAtKey?.length !== 0);
|
||||||
|
|
||||||
|
return allCodes.map((entry: CodeInfoResponse): Code => {
|
||||||
assert(entry.creator && entry.codeId && entry.dataHash, "entry incomplete");
|
assert(entry.creator && entry.codeId && entry.dataHash, "entry incomplete");
|
||||||
return {
|
return {
|
||||||
id: entry.codeId.toNumber(),
|
id: entry.codeId.toNumber(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user