Skip to content

Commit

Permalink
Merge pull request #1484 from cosmos/new-cosmjs-types
Browse files Browse the repository at this point in the history
Upgrade to new cosmjs-types (Telescope 1.0, big int 🔥)
  • Loading branch information
webmaster128 authored Oct 25, 2023
2 parents 3eba434 + a111327 commit 08200ae
Show file tree
Hide file tree
Showing 50 changed files with 328 additions and 303 deletions.
23 changes: 8 additions & 15 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions .yarn/cache/cosmjs-types-npm-0.8.0-4c175fd383-99714ec956.zip

This file was deleted.

3 changes: 3 additions & 0 deletions .yarn/cache/cosmjs-types-npm-0.9.0-e5d36a4ae5-9b00d169ec.zip
Git LFS file not shown
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to

### Changed

- all: Upgrade cosmjs-types to 0.9.0. This makes a few fields non-optional. It
changes all 64 bit int fields from type `long` to `bigint`. As part of the
upgrade, the types do not require the `long` and `protobufjs` anymore.
([#1484])
- Drop support for Node.js 14 and add support for Node.js 20. ([#1421])
- @cosmjs/tendermint-rpc: Remove `Adaptor` abstractions which are not needed
anymore by haing a dedicated client for each backend.
Expand All @@ -16,6 +20,7 @@ and this project adheres to
`connectComet` for auto-detecting the right client for a provided endpoint.

[#1421]: https://github.com/cosmos/cosmjs/issues/1421
[#1484]: https://github.com/cosmos/cosmjs/pull/1484

### Deprecated

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"axios": "^0.21.2",
"babylon": "^6.18.0",
"chalk": "^4",
"cosmjs-types": "^0.8.0",
"cosmjs-types": "^0.9.0",
"diff": "^4",
"recast": "^0.20",
"ts-node": "^8",
Expand Down
4 changes: 1 addition & 3 deletions packages/cosmwasm-stargate/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@
"@cosmjs/stargate": "workspace:^",
"@cosmjs/tendermint-rpc": "workspace:^",
"@cosmjs/utils": "workspace:^",
"cosmjs-types": "^0.8.0",
"long": "^4.0.0",
"cosmjs-types": "^0.9.0",
"pako": "^2.0.2"
},
"devDependencies": {
Expand Down Expand Up @@ -79,7 +78,6 @@
"karma-jasmine-html-reporter": "^1.5.4",
"nyc": "^15.1.0",
"prettier": "^2.8.1",
"protobufjs": "~6.11.4",
"readonly-date": "^1.0.0",
"ses": "^0.11.0",
"source-map-support": "^0.5.19",
Expand Down
8 changes: 4 additions & 4 deletions packages/cosmwasm-stargate/src/cosmwasmclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ export class CosmWasmClient {
return allCodes.map((entry: CodeInfoResponse): Code => {
assert(entry.creator && entry.codeId && entry.dataHash, "entry incomplete");
return {
id: entry.codeId.toNumber(),
id: Number(entry.codeId),
creator: entry.creator,
checksum: toHex(entry.dataHash),
};
Expand All @@ -356,7 +356,7 @@ export class CosmWasmClient {
"codeInfo missing or incomplete",
);
const codeDetails: CodeDetails = {
id: codeInfo.codeId.toNumber(),
id: Number(codeInfo.codeId),
creator: codeInfo.creator,
checksum: toHex(codeInfo.dataHash),
data: data,
Expand Down Expand Up @@ -413,7 +413,7 @@ export class CosmWasmClient {
assert(contractInfo.codeId && contractInfo.creator && contractInfo.label, "contractInfo incomplete");
return {
address: retrievedAddress,
codeId: contractInfo.codeId.toNumber(),
codeId: Number(contractInfo.codeId),
creator: contractInfo.creator,
admin: contractInfo.admin || undefined,
label: contractInfo.label,
Expand All @@ -436,7 +436,7 @@ export class CosmWasmClient {
assert(entry.operation && entry.codeId && entry.msg);
return {
operation: operations[entry.operation],
codeId: entry.codeId.toNumber(),
codeId: Number(entry.codeId),
msg: JSON.parse(fromUtf8(entry.msg)),
};
});
Expand Down
27 changes: 12 additions & 15 deletions packages/cosmwasm-stargate/src/modules/wasm/aminomessages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
MsgUpdateAdmin,
} from "cosmjs-types/cosmwasm/wasm/v1/tx";
import { AccessType } from "cosmjs-types/cosmwasm/wasm/v1/types";
import Long from "long";

import {
AminoMsgClearAdmin,
Expand All @@ -27,11 +26,10 @@ import {
describe("AminoTypes", () => {
describe("toAmino", () => {
it("works for MsgStoreCode", () => {
const msg: MsgStoreCode = {
const msg = MsgStoreCode.fromPartial({
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="),
instantiatePermission: undefined,
};
});
const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({
typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode",
value: msg,
Expand Down Expand Up @@ -81,7 +79,7 @@ describe("AminoTypes", () => {
{
const msg: MsgInstantiateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
codeId: Long.fromString("12345"),
codeId: BigInt("12345"),
label: "sticky",
msg: toUtf8(`{"foo":"bar"}`),
funds: coins(1234, "ucosm"),
Expand Down Expand Up @@ -109,7 +107,7 @@ describe("AminoTypes", () => {
{
const msg: MsgInstantiateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
codeId: Long.fromString("12345"),
codeId: BigInt("12345"),
label: "sticky",
msg: toUtf8(`{"foo":"bar"}`),
funds: coins(1234, "ucosm"),
Expand Down Expand Up @@ -139,7 +137,7 @@ describe("AminoTypes", () => {
{
const msg: MsgInstantiateContract2 = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
codeId: Long.fromString("12345"),
codeId: BigInt("12345"),
label: "sticky",
msg: toUtf8(`{"foo":"bar"}`),
funds: coins(1234, "ucosm"),
Expand Down Expand Up @@ -171,7 +169,7 @@ describe("AminoTypes", () => {
{
const msg: MsgInstantiateContract2 = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
codeId: Long.fromString("12345"),
codeId: BigInt("12345"),
label: "sticky",
msg: toUtf8(`{"foo":"bar"}`),
funds: coins(1234, "ucosm"),
Expand Down Expand Up @@ -267,7 +265,7 @@ describe("AminoTypes", () => {
const msg: MsgMigrateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
codeId: Long.fromString("98765"),
codeId: BigInt("98765"),
msg: toUtf8(`{"foo":"bar"}`),
};
const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({
Expand Down Expand Up @@ -297,11 +295,10 @@ describe("AminoTypes", () => {
},
};
const msg = new AminoTypes(createWasmAminoConverters()).fromAmino(aminoMsg);
const expectedValue: MsgStoreCode = {
const expectedValue = MsgStoreCode.fromPartial({
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
wasmByteCode: fromBase64("WUVMTE9XIFNVQk1BUklORQ=="),
instantiatePermission: undefined,
};
});
expect(msg).toEqual({
typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode",
value: expectedValue,
Expand Down Expand Up @@ -354,7 +351,7 @@ describe("AminoTypes", () => {
const msg = new AminoTypes(createWasmAminoConverters()).fromAmino(aminoMsg);
const expectedValue: MsgInstantiateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
codeId: Long.fromString("12345"),
codeId: BigInt("12345"),
label: "sticky",
msg: toUtf8(`{"foo":"bar"}`),
funds: coins(1234, "ucosm"),
Expand All @@ -381,7 +378,7 @@ describe("AminoTypes", () => {
const msg = new AminoTypes(createWasmAminoConverters()).fromAmino(aminoMsg);
const expectedValue: MsgInstantiateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
codeId: Long.fromString("12345"),
codeId: BigInt("12345"),
label: "sticky",
msg: toUtf8(`{"foo":"bar"}`),
funds: coins(1234, "ucosm"),
Expand Down Expand Up @@ -471,7 +468,7 @@ describe("AminoTypes", () => {
const expectedValue: MsgMigrateContract = {
sender: "cosmos1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
contract: "cosmos1xy4yqngt0nlkdcenxymg8tenrghmek4nmqm28k",
codeId: Long.fromString("98765"),
codeId: BigInt("98765"),
msg: toUtf8(`{"foo":"bar"}`),
};
expect(msg).toEqual({
Expand Down
17 changes: 8 additions & 9 deletions packages/cosmwasm-stargate/src/modules/wasm/aminomessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import {
MsgStoreCode,
MsgUpdateAdmin,
} from "cosmjs-types/cosmwasm/wasm/v1/tx";
import { AccessType } from "cosmjs-types/cosmwasm/wasm/v1/types";
import Long from "long";
import { AccessConfig, AccessType } from "cosmjs-types/cosmwasm/wasm/v1/types";

export function accessTypeFromString(str: string): AccessType {
switch (str) {
Expand Down Expand Up @@ -51,7 +50,7 @@ export function accessTypeToString(object: any): string {
/**
* @see https://github.com/CosmWasm/wasmd/blob/v0.18.0-rc1/proto/cosmwasm/wasm/v1/types.proto#L36-L41
*/
export interface AccessConfig {
export interface AminoAccessConfig {
/**
* Permission should be one kind of string 'Nobody', 'OnlyAddress', 'Everybody', 'AnyOfAddresses', 'Unspecified'
* @see https://github.com/CosmWasm/wasmd/blob/v0.31.0/x/wasm/types/params.go#L54
Expand All @@ -77,7 +76,7 @@ export interface AminoMsgStoreCode {
readonly sender: string;
/** Base64 encoded Wasm */
readonly wasm_byte_code: string;
readonly instantiate_permission?: AccessConfig;
readonly instantiate_permission?: AminoAccessConfig;
};
}

Expand Down Expand Up @@ -226,11 +225,11 @@ export function createWasmAminoConverters(): AminoConverters {
sender: sender,
wasmByteCode: fromBase64(wasm_byte_code),
instantiatePermission: instantiate_permission
? {
? AccessConfig.fromPartial({
permission: accessTypeFromString(instantiate_permission.permission),
address: instantiate_permission.address ?? "",
addresses: instantiate_permission.addresses ?? [],
}
})
: undefined,
}),
},
Expand Down Expand Up @@ -260,7 +259,7 @@ export function createWasmAminoConverters(): AminoConverters {
admin,
}: AminoMsgInstantiateContract["value"]): MsgInstantiateContract => ({
sender: sender,
codeId: Long.fromString(code_id),
codeId: BigInt(code_id),
label: label,
msg: toUtf8(JSON.stringify(msg)),
funds: [...funds],
Expand Down Expand Up @@ -299,7 +298,7 @@ export function createWasmAminoConverters(): AminoConverters {
fix_msg,
}: AminoMsgInstantiateContract2["value"]): MsgInstantiateContract2 => ({
sender: sender,
codeId: Long.fromString(code_id),
codeId: BigInt(code_id),
label: label,
msg: toUtf8(JSON.stringify(msg)),
funds: [...funds],
Expand Down Expand Up @@ -368,7 +367,7 @@ export function createWasmAminoConverters(): AminoConverters {
}: AminoMsgMigrateContract["value"]): MsgMigrateContract => ({
sender: sender,
contract: contract,
codeId: Long.fromString(code_id),
codeId: BigInt(code_id),
msg: toUtf8(JSON.stringify(msg)),
}),
},
Expand Down
Loading

0 comments on commit 08200ae

Please sign in to comment.