From 8d1b804c196af71330a5d0405a5f2695a0555aaf Mon Sep 17 00:00:00 2001 From: "jinseong.cho" Date: Wed, 22 Feb 2023 20:33:15 +0900 Subject: [PATCH] feat: change codes after bump up wasm --- .../src/modules/wasm/aminomessages.spec.ts | 8 ++++++-- .../finschia/src/modules/wasm/aminomessages.ts | 15 +++++++++++++-- packages/finschia/src/modules/wasm/messages.ts | 11 ++++++++++- .../src/modules/wasmplus/aminomessages.spec.ts | 4 ++++ .../src/modules/wasmplus/aminomessages.ts | 2 ++ .../finschia/src/signingfinschiaclient.spec.ts | 10 +++++++--- packages/finschia/src/signingfinschiaclient.ts | 6 +++--- 7 files changed, 45 insertions(+), 11 deletions(-) diff --git a/packages/finschia/src/modules/wasm/aminomessages.spec.ts b/packages/finschia/src/modules/wasm/aminomessages.spec.ts index dbac014d..c5c3f7af 100644 --- a/packages/finschia/src/modules/wasm/aminomessages.spec.ts +++ b/packages/finschia/src/modules/wasm/aminomessages.spec.ts @@ -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"; @@ -36,6 +36,7 @@ describe("AminoTypes", () => { instantiatePermission: { permission: AccessType.ACCESS_TYPE_ONLY_ADDRESS, address: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", + addresses: [], }, }; const aminoMsg = new AminoTypes(createWasmAminoConverters()).toAmino({ @@ -50,6 +51,7 @@ describe("AminoTypes", () => { instantiate_permission: { permission: "OnlyAddress", address: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", + addresses: [], }, }, }; @@ -87,6 +89,7 @@ describe("AminoTypes", () => { instantiate_permission: { permission: "OnlyAddress", address: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", + addresses: [], }, }, }; @@ -97,6 +100,7 @@ describe("AminoTypes", () => { instantiatePermission: { permission: AccessType.ACCESS_TYPE_ONLY_ADDRESS, address: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", + addresses: [], }, }; expect(msg).toEqual({ diff --git a/packages/finschia/src/modules/wasm/aminomessages.ts b/packages/finschia/src/modules/wasm/aminomessages.ts index 6fa9b3b0..145fe1be 100644 --- a/packages/finschia/src/modules/wasm/aminomessages.ts +++ b/packages/finschia/src/modules/wasm/aminomessages.ts @@ -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) { @@ -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; } @@ -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"; @@ -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[]; } /** @@ -80,6 +89,7 @@ export function createWasmAminoConverters(): AminoConverters { ? { permission: accessTypeToString(instantiatePermission.permission), address: instantiatePermission.address || undefined, + addresses: instantiatePermission.addresses, } : undefined, }), @@ -94,6 +104,7 @@ export function createWasmAminoConverters(): AminoConverters { ? { permission: accessTypeFromString(instantiate_permission.permission), address: instantiate_permission.address ?? "", + addresses: instantiate_permission.addresses, } : undefined, }), diff --git a/packages/finschia/src/modules/wasm/messages.ts b/packages/finschia/src/modules/wasm/messages.ts index 0bef10b0..32297bd0 100644 --- a/packages/finschia/src/modules/wasm/messages.ts +++ b/packages/finschia/src/modules/wasm/messages.ts @@ -1,4 +1,4 @@ -import { GeneratedType } from "@cosmjs/proto-signing"; +import { EncodeObject, GeneratedType } from "@cosmjs/proto-signing"; import { MsgClearAdmin, MsgExecuteContract, @@ -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; +} + +export function isMsgStoreCodeEncodeObject(object: EncodeObject): object is MsgStoreCodeEncodeObject { + return (object as MsgStoreCodeEncodeObject).typeUrl === "/cosmwasm.wasm.v1.MsgStoreCode"; +} diff --git a/packages/finschia/src/modules/wasmplus/aminomessages.spec.ts b/packages/finschia/src/modules/wasmplus/aminomessages.spec.ts index 84923398..ecc0d2c7 100644 --- a/packages/finschia/src/modules/wasmplus/aminomessages.spec.ts +++ b/packages/finschia/src/modules/wasmplus/aminomessages.spec.ts @@ -44,6 +44,7 @@ describe("AminoTypes", () => { instantiatePermission: { permission: AccessType.ACCESS_TYPE_ONLY_ADDRESS, address: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", + addresses: [], }, admin: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", label: "sticky", @@ -62,6 +63,7 @@ describe("AminoTypes", () => { instantiate_permission: { permission: "OnlyAddress", address: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", + addresses: [], }, admin: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", label: "sticky", @@ -112,6 +114,7 @@ describe("AminoTypes", () => { instantiate_permission: { permission: "OnlyAddress", address: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", + addresses: [], }, admin: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", label: "sticky", @@ -126,6 +129,7 @@ describe("AminoTypes", () => { instantiatePermission: { permission: AccessType.ACCESS_TYPE_ONLY_ADDRESS, address: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", + addresses: [], }, admin: "link1pkptre7fdkl6gfrzlesjjvhxhlc3r4gmmk8rs6", label: "sticky", diff --git a/packages/finschia/src/modules/wasmplus/aminomessages.ts b/packages/finschia/src/modules/wasmplus/aminomessages.ts index 457aaccf..dfd6ccca 100644 --- a/packages/finschia/src/modules/wasmplus/aminomessages.ts +++ b/packages/finschia/src/modules/wasmplus/aminomessages.ts @@ -44,6 +44,7 @@ export function createWasmplusAminoConverters(): AminoConverters { ? { permission: accessTypeToString(instantiatePermission.permission), address: instantiatePermission.address || undefined, + addresses: instantiatePermission.addresses, } : undefined, admin: admin || undefined, @@ -66,6 +67,7 @@ export function createWasmplusAminoConverters(): AminoConverters { ? { permission: accessTypeFromString(instantiate_permission.permission), address: instantiate_permission.address ?? "", + addresses: instantiate_permission.addresses, } : undefined, admin: admin ?? "", diff --git a/packages/finschia/src/signingfinschiaclient.spec.ts b/packages/finschia/src/signingfinschiaclient.spec.ts index 651af64b..0f0d825d 100644 --- a/packages/finschia/src/signingfinschiaclient.spec.ts +++ b/packages/finschia/src/signingfinschiaclient.spec.ts @@ -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"; @@ -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"; @@ -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); @@ -581,6 +584,7 @@ describe("SigningFinschiaClient", () => { instantiatePermission: { permission: AccessType.ACCESS_TYPE_ONLY_ADDRESS, address: faucet.address0, + addresses: [], }, admin: faucet.address0, }, diff --git a/packages/finschia/src/signingfinschiaclient.ts b/packages/finschia/src/signingfinschiaclient.ts index d011771e..f0a5898e 100644 --- a/packages/finschia/src/signingfinschiaclient.ts +++ b/packages/finschia/src/signingfinschiaclient.ts @@ -13,7 +13,6 @@ import { MsgExecuteContractEncodeObject, MsgInstantiateContractEncodeObject, MsgMigrateContractEncodeObject, - MsgStoreCodeEncodeObject, MsgUpdateAdminEncodeObject, } from "@cosmjs/cosmwasm-stargate"; import { sha256 } from "@cosmjs/crypto"; @@ -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 {