Skip to content

Commit

Permalink
feat: change codes after bump up wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
loin3 committed Feb 22, 2023
1 parent 694981d commit 8d1b804
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 11 deletions.
8 changes: 6 additions & 2 deletions packages/finschia/src/modules/wasm/aminomessages.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { fromBase64 } from "@cosmjs/encoding";
import { AminoTypes } from "@cosmjs/stargate";
import { MsgStoreCode } from "cosmjs-types/cosmwasm/wasm/v1/tx";
import { AccessType } from "cosmjs-types/cosmwasm/wasm/v1/types";
import { MsgStoreCode } from "lbmjs-types/cosmwasm/wasm/v1/tx";
import { AccessType } from "lbmjs-types/cosmwasm/wasm/v1/types";

import { AminoMsgStoreCode, createWasmAminoConverters } from "./aminomessages";

Expand Down Expand Up @@ -36,6 +36,7 @@ describe("AminoTypes", () => {
instantiatePermission: {
permission: AccessType.ACCESS_TYPE_ONLY_ADDRESS,
address: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
addresses: [],
},
};
const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({
Expand All @@ -50,6 +51,7 @@ describe("AminoTypes", () => {
instantiate_permission: {
permission: "OnlyAddress",
address: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
addresses: [],
},
},
};
Expand Down Expand Up @@ -87,6 +89,7 @@ describe("AminoTypes", () => {
instantiate_permission: {
permission: "OnlyAddress",
address: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
addresses: [],
},
},
};
Expand All @@ -97,6 +100,7 @@ describe("AminoTypes", () => {
instantiatePermission: {
permission: AccessType.ACCESS_TYPE_ONLY_ADDRESS,
address: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
addresses: [],
},
};
expect(msg).toEqual({
Expand Down
15 changes: 13 additions & 2 deletions packages/finschia/src/modules/wasm/aminomessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import { createWasmAminoConverters as createAminoConverters } from "@cosmjs/cosmwasm-stargate";
import { fromBase64, toBase64 } from "@cosmjs/encoding";
import { AminoConverters } from "@cosmjs/stargate";
import { MsgStoreCode } from "cosmjs-types/cosmwasm/wasm/v1/tx";
import { AccessType } from "cosmjs-types/cosmwasm/wasm/v1/types";
import { MsgStoreCode } from "lbmjs-types/cosmwasm/wasm/v1/tx";
import { AccessType } from "lbmjs-types/cosmwasm/wasm/v1/types";

export function accessTypeFromString(str: string): AccessType {
switch (str) {
Expand All @@ -15,6 +15,8 @@ export function accessTypeFromString(str: string): AccessType {
return AccessType.ACCESS_TYPE_ONLY_ADDRESS;
case "Everybody":
return AccessType.ACCESS_TYPE_EVERYBODY;
case "AnyOfAddresses":
return AccessType.ACCESS_TYPE_ANY_OF_ADDRESSES;
default:
return AccessType.UNRECOGNIZED;
}
Expand All @@ -30,6 +32,8 @@ export function accessTypeToString(object: any): string {
return "OnlyAddress";
case AccessType.ACCESS_TYPE_EVERYBODY:
return "Everybody";
case AccessType.ACCESS_TYPE_ANY_OF_ADDRESSES:
return "AnyOfAddresses";
case AccessType.UNRECOGNIZED:
default:
return "UNRECOGNIZED";
Expand All @@ -45,7 +49,12 @@ export interface AccessConfig {
* @see https://github.com/CosmWasm/wasmd/blob/v0.28.0/x/wasm/types/params.go#L54
*/
readonly permission: string;
/**
* Address
* Deprecated: replaced by addresses
*/
readonly address?: string;
readonly addresses: string[];
}

/**
Expand Down Expand Up @@ -80,6 +89,7 @@ export function createWasmAminoConverters(): AminoConverters {
? {
permission: accessTypeToString(instantiatePermission.permission),
address: instantiatePermission.address || undefined,
addresses: instantiatePermission.addresses,
}
: undefined,
}),
Expand All @@ -94,6 +104,7 @@ export function createWasmAminoConverters(): AminoConverters {
? {
permission: accessTypeFromString(instantiate_permission.permission),
address: instantiate_permission.address ?? "",
addresses: instantiate_permission.addresses,
}
: undefined,
}),
Expand Down
11 changes: 10 additions & 1 deletion packages/finschia/src/modules/wasm/messages.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GeneratedType } from "@cosmjs/proto-signing";
import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing";
import {
MsgClearAdmin,
MsgExecuteContract,
Expand All @@ -16,3 +16,12 @@ export const wasmTypes: ReadonlyArray<[string, GeneratedType]> = [
["/cosmwasm.wasm.v1.MsgInstantiateContract", MsgInstantiateContract],
["/cosmwasm.wasm.v1.MsgUpdateAdmin", MsgUpdateAdmin],
];

export interface MsgStoreCodeEncodeObject extends EncodeObject {
readonly typeUrl: "/cosmwasm.wasm.v1.MsgStoreCode";
readonly value: Partial<MsgStoreCode>;
}

export function isMsgStoreCodeEncodeObject(object: EncodeObject): object is MsgStoreCodeEncodeObject {
return (object as MsgStoreCodeEncodeObject).typeUrl === "/cosmwasm.wasm.v1.MsgStoreCode";
}
4 changes: 4 additions & 0 deletions packages/finschia/src/modules/wasmplus/aminomessages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe("AminoTypes", () => {
instantiatePermission: {
permission: AccessType.ACCESS_TYPE_ONLY_ADDRESS,
address: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
addresses: [],
},
admin: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
label: "sticky",
Expand All @@ -62,6 +63,7 @@ describe("AminoTypes", () => {
instantiate_permission: {
permission: "OnlyAddress",
address: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
addresses: [],
},
admin: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
label: "sticky",
Expand Down Expand Up @@ -112,6 +114,7 @@ describe("AminoTypes", () => {
instantiate_permission: {
permission: "OnlyAddress",
address: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
addresses: [],
},
admin: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
label: "sticky",
Expand All @@ -126,6 +129,7 @@ describe("AminoTypes", () => {
instantiatePermission: {
permission: AccessType.ACCESS_TYPE_ONLY_ADDRESS,
address: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
addresses: [],
},
admin: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6",
label: "sticky",
Expand Down
2 changes: 2 additions & 0 deletions packages/finschia/src/modules/wasmplus/aminomessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export function createWasmplusAminoConverters(): AminoConverters {
? {
permission: accessTypeToString(instantiatePermission.permission),
address: instantiatePermission.address || undefined,
addresses: instantiatePermission.addresses,
}
: undefined,
admin: admin || undefined,
Expand All @@ -66,6 +67,7 @@ export function createWasmplusAminoConverters(): AminoConverters {
? {
permission: accessTypeFromString(instantiate_permission.permission),
address: instantiate_permission.address ?? "",
addresses: instantiate_permission.addresses,
}
: undefined,
admin: admin ?? "",
Expand Down
10 changes: 7 additions & 3 deletions packages/finschia/src/signingfinschiaclient.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { addCoins, Secp256k1HdWallet } from "@cosmjs/amino";
import { MsgExecuteContractEncodeObject, MsgStoreCodeEncodeObject } from "@cosmjs/cosmwasm-stargate";
import { MsgExecuteContractEncodeObject } from "@cosmjs/cosmwasm-stargate";
import { sha256 } from "@cosmjs/crypto";
import { toHex, toUtf8 } from "@cosmjs/encoding";
import { decodeTxRaw, DirectSecp256k1HdWallet, Registry } from "@cosmjs/proto-signing";
Expand All @@ -21,11 +21,13 @@ import { DeepPartial, MsgSend } from "cosmjs-types/cosmos/bank/v1beta1/tx";
import { Coin } from "cosmjs-types/cosmos/base/v1beta1/coin";
import { MsgDelegate } from "cosmjs-types/cosmos/staking/v1beta1/tx";
import { AuthInfo, TxBody, TxRaw } from "cosmjs-types/cosmos/tx/v1beta1/tx";
import { MsgExecuteContract, MsgStoreCode } from "cosmjs-types/cosmwasm/wasm/v1/tx";
import { AccessConfig, AccessType } from "cosmjs-types/cosmwasm/wasm/v1/types";
import { MsgExecuteContract } from "cosmjs-types/cosmwasm/wasm/v1/tx";
import { MsgStoreCode } from "lbmjs-types/cosmwasm/wasm/v1/tx";
import { AccessConfig, AccessType } from "lbmjs-types/cosmwasm/wasm/v1/types";
import Long from "long";
import pako from "pako";
import protobuf from "protobufjs/minimal";
import { MsgStoreCodeEncodeObject } from "./modules/wasm/messages";

import { makeLinkPath } from "./paths";
import { SigningFinschiaClient } from "./signingfinschiaclient";
Expand Down Expand Up @@ -330,6 +332,7 @@ describe("SigningFinschiaClient", () => {
const accessConfig: AccessConfig = {
permission: AccessType.ACCESS_TYPE_EVERYBODY,
address: "",
addresses: [],
};
const { codeId, originalChecksum, originalSize, compressedChecksum, compressedSize } =
await client.upload(faucet.address0, wasm, defaultUploadFee, "test memo", accessConfig);
Expand Down Expand Up @@ -581,6 +584,7 @@ describe("SigningFinschiaClient", () => {
instantiatePermission: {
permission: AccessType.ACCESS_TYPE_ONLY_ADDRESS,
address: faucet.address0,
addresses: [],
},
admin: faucet.address0,
},
Expand Down
6 changes: 3 additions & 3 deletions packages/finschia/src/signingfinschiaclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
MsgExecuteContractEncodeObject,
MsgInstantiateContractEncodeObject,
MsgMigrateContractEncodeObject,
MsgStoreCodeEncodeObject,
MsgUpdateAdminEncodeObject,
} from "@cosmjs/cosmwasm-stargate";
import { sha256 } from "@cosmjs/crypto";
Expand Down Expand Up @@ -57,17 +56,18 @@ import {
MsgExecuteContract,
MsgInstantiateContract,
MsgMigrateContract,
MsgStoreCode,
MsgUpdateAdmin,
} from "cosmjs-types/cosmwasm/wasm/v1/tx";
import { AccessConfig } from "cosmjs-types/cosmwasm/wasm/v1/types";
import { MsgTransfer } from "cosmjs-types/ibc/applications/transfer/v1/tx";
import { Height } from "cosmjs-types/ibc/core/client/v1/client";
import { MsgStoreCode } from "lbmjs-types/cosmwasm/wasm/v1/tx";
import { AccessConfig } from "lbmjs-types/cosmwasm/wasm/v1/types";
import { MsgStoreCodeAndInstantiateContract } from "lbmjs-types/lbm/wasm/v1/tx";
import Long from "long";
import pako from "pako";

import { FinschiaClient } from "./finschiaclient";
import { MsgStoreCodeEncodeObject } from "./modules/wasm/messages";
import { createDefaultRegistry, createDefaultTypes } from "./types";

export interface UploadAndInstantiateOptions extends InstantiateOptions {
Expand Down

0 comments on commit 8d1b804

Please sign in to comment.