Merge branch 'main' into more-then-100-getCodes

This commit is contained in:
Milan Steiner 2022-03-15 19:27:46 +01:00 committed by GitHub
commit 0a93af06d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 89 additions and 6 deletions

View File

@ -44,8 +44,8 @@ and this project adheres to
dependencies. This should also reduce the bundle size as only the English
wordlist is shipped. ([#966])
- @cosmjs/cli: Rename binary `cosmwasm-cli` to `cosmjs-cli` ([#1033]).
- @cosmjs/stargate & @cosmjs/cosmwasm-stargate: Removed default types from AminoTypes. ([1079])
- @cosmjs/cosmwasm-stargate: getCodes() automatically loops through all pagination pages now. ([#1078])
- @cosmjs/stargate & @cosmjs/cosmwasm-stargate: Removed default types from AminoTypes. ([#1079])
- @cosmjs/cosmwasm-stargate: getCodes() automatically loops through all pagination pages now. ([#1077])
[#927]: https://github.com/cosmos/cosmjs/issues/927
[#955]: https://github.com/cosmos/cosmjs/issues/955
@ -57,6 +57,7 @@ and this project adheres to
[#1026]: https://github.com/cosmos/cosmjs/issues/1026
[#1033]: https://github.com/cosmos/cosmjs/issues/1033
[#1053]: https://github.com/cosmos/cosmjs/issues/1053
[#1077]: https://github.com/cosmos/cosmjs/issues/1077
[#1078]: https://github.com/cosmos/cosmjs/issues/1078
[#1079]: https://github.com/cosmos/cosmjs/issues/1079

View File

@ -96,6 +96,70 @@ We're happy to adjust this list according to users' needs as long as you don't
ask for Internet Explorer support. If your environment does not support Wasm, we
can work on a solution with swappable implementations.
## Webpack Configs
With WebPack 5, you have to be explicit about the usage of Node.js types and
modules that were simply replaced with re-implementations for browsers in
Webpack 4.
Configs for 0.28 and later:
```js
module.exports = [
{
...,
resolve: {
fallback: {
buffer: false,
crypto: false,
events: false,
path: false,
stream: false,
string_decoder: false,
},
},
},
];
```
Configs for CosmJS < 0.28
```js
module.exports = [
{
...,
resolve: {
fallback: {
buffer: false,
crypto: false,
events: false,
path: false,
stream: require.resolve("stream-browserify"),
string_decoder: false,
},
},
},
];
```
Also, in both cases you need the Buffer plugin:
```ts
module.exports = [
{
...,
plugins: [
...,
new webpack.ProvidePlugin({
Buffer: ["buffer", "Buffer"],
}),
],
...
},
];
```
## Roadmap
We maintain a [development board](https://github.com/orgs/cosmos/projects/6),

View File

@ -25,7 +25,11 @@ import {
} from "@cosmjs/stargate";
import { Tendermint34Client, toRfc3339WithNanoseconds } from "@cosmjs/tendermint-rpc";
import { assert, sleep } from "@cosmjs/utils";
import { CodeInfoResponse, QueryCodesResponse } 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 { JsonObject, setupWasmExtension, WasmExtension } from "./modules";
@ -350,10 +354,24 @@ export class CosmWasmClient {
return codeDetails;
}
/**
* getContracts() returns all contract instances for one code 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 getContracts(codeId: number): Promise<readonly string[]> {
// TODO: handle pagination - accept as arg or auto-loop
const { contracts } = await this.forceGetQueryClient().wasm.listContractsByCodeId(codeId);
return contracts;
const allContracts = [];
let startAtKey: Uint8Array | undefined = undefined;
do {
const { contracts, pagination }: QueryContractsByCodeResponse =
await this.forceGetQueryClient().wasm.listContractsByCodeId(codeId, startAtKey);
const loadedContracts = contracts || [];
allContracts.push(...loadedContracts);
startAtKey = pagination?.nextKey;
} while (startAtKey?.length !== 0 && startAtKey !== undefined);
return allContracts;
}
/**