From cf0c939cf5fcfbad90f45d077aca86772b61f40d Mon Sep 17 00:00:00 2001 From: willclarktech Date: Thu, 26 Nov 2020 13:09:48 +0000 Subject: [PATCH] cosmwasm: Extract CosmosMsg types into separate file --- packages/cosmwasm/src/cosmosmsg.ts | 77 +++++++++++++++++++ packages/cosmwasm/src/cw3cosmwasmclient.ts | 2 +- packages/cosmwasm/src/index.ts | 6 +- packages/cosmwasm/src/msgs.ts | 72 ----------------- packages/cosmwasm/types/cosmosmsg.d.ts | 65 ++++++++++++++++ .../cosmwasm/types/cw3cosmwasmclient.d.ts | 2 +- packages/cosmwasm/types/index.d.ts | 6 +- packages/cosmwasm/types/msgs.d.ts | 61 --------------- 8 files changed, 146 insertions(+), 145 deletions(-) create mode 100644 packages/cosmwasm/src/cosmosmsg.ts create mode 100644 packages/cosmwasm/types/cosmosmsg.d.ts diff --git a/packages/cosmwasm/src/cosmosmsg.ts b/packages/cosmwasm/src/cosmosmsg.ts new file mode 100644 index 00000000..7cfc74c3 --- /dev/null +++ b/packages/cosmwasm/src/cosmosmsg.ts @@ -0,0 +1,77 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import { Coin } from "@cosmjs/launchpad"; + +interface BankSendMsg { + readonly send: { + readonly from_address: string; + readonly to_address: string; + readonly amount: readonly Coin[]; + }; +} + +export interface BankMsg { + readonly bank: BankSendMsg; +} + +export interface CustomMsg { + readonly custom: Record; +} + +interface StakingDelegateMsg { + readonly delegate: { + readonly validator: string; + readonly amount: Coin; + }; +} + +interface StakingRedelegateMsg { + readonly redelgate: { + readonly src_validator: string; + readonly dst_validator: string; + readonly amount: Coin; + }; +} + +interface StakingUndelegateMsg { + readonly undelegate: { + readonly validator: string; + readonly amount: Coin; + }; +} + +interface StakingWithdrawMsg { + readonly withdraw: { + readonly validator: string; + readonly recipient?: string; + }; +} + +export interface StakingMsg { + readonly staking: StakingDelegateMsg | StakingRedelegateMsg | StakingUndelegateMsg | StakingWithdrawMsg; +} + +interface WasmExecuteMsg { + readonly execute: { + readonly contract_address: string; + readonly msg: any; + readonly send: readonly Coin[]; + }; +} + +interface WasmInstantiateMsg { + readonly instantiate: { + readonly code_id: string; + readonly msg: any; + readonly send: readonly Coin[]; + readonly label?: string; + }; +} + +export interface WasmMsg { + readonly wasm: WasmExecuteMsg | WasmInstantiateMsg; +} + +/** These definitions are derived from CosmWasm: + * https://github.com/CosmWasm/cosmwasm/blob/v0.12.0/packages/std/src/results/cosmos_msg.rs#L10-L23 + */ +export type CosmosMsg = BankMsg | CustomMsg | StakingMsg | WasmMsg; diff --git a/packages/cosmwasm/src/cw3cosmwasmclient.ts b/packages/cosmwasm/src/cw3cosmwasmclient.ts index 9c043c5e..933c9574 100644 --- a/packages/cosmwasm/src/cw3cosmwasmclient.ts +++ b/packages/cosmwasm/src/cw3cosmwasmclient.ts @@ -1,8 +1,8 @@ /* eslint-disable @typescript-eslint/naming-convention */ import { BroadcastMode, GasLimits, GasPrice, OfflineSigner } from "@cosmjs/launchpad"; +import { CosmosMsg } from "./cosmosmsg"; import { Account } from "./cosmwasmclient"; -import { CosmosMsg } from "./msgs"; import { CosmWasmFeeTable, ExecuteResult, SigningCosmWasmClient } from "./signingcosmwasmclient"; export type Expiration = diff --git a/packages/cosmwasm/src/index.ts b/packages/cosmwasm/src/index.ts index 81d2c8be..b90bf610 100644 --- a/packages/cosmwasm/src/index.ts +++ b/packages/cosmwasm/src/index.ts @@ -1,4 +1,5 @@ export { setupWasmExtension, WasmExtension } from "./lcdapi/wasm"; +export { BankMsg, CosmosMsg, CustomMsg, StakingMsg, WasmMsg } from "./cosmosmsg"; export { Account, Block, @@ -39,11 +40,6 @@ export { UploadResult, } from "./signingcosmwasmclient"; export { - BankMsg, - CosmosMsg, - CustomMsg, - StakingMsg, - WasmMsg, isMsgClearAdmin, isMsgExecuteContract, isMsgInstantiateContract, diff --git a/packages/cosmwasm/src/msgs.ts b/packages/cosmwasm/src/msgs.ts index fabd9c9a..02d70e4a 100644 --- a/packages/cosmwasm/src/msgs.ts +++ b/packages/cosmwasm/src/msgs.ts @@ -144,75 +144,3 @@ export interface MsgMigrateContract extends Msg { export function isMsgMigrateContract(msg: Msg): msg is MsgMigrateContract { return (msg as MsgMigrateContract).type === "wasm/MsgMigrateContract"; } - -interface BankSendMsg { - readonly send: { - readonly from_address: string; - readonly to_address: string; - readonly amount: readonly Coin[]; - }; -} - -export interface BankMsg { - readonly bank: BankSendMsg; -} - -export interface CustomMsg { - readonly custom: Record; -} - -interface StakingDelegateMsg { - readonly delegate: { - readonly validator: string; - readonly amount: Coin; - }; -} - -interface StakingRedelegateMsg { - readonly redelgate: { - readonly src_validator: string; - readonly dst_validator: string; - readonly amount: Coin; - }; -} - -interface StakingUndelegateMsg { - readonly undelegate: { - readonly validator: string; - readonly amount: Coin; - }; -} - -interface StakingWithdrawMsg { - readonly withdraw: { - readonly validator: string; - readonly recipient?: string; - }; -} - -export interface StakingMsg { - readonly staking: StakingDelegateMsg | StakingRedelegateMsg | StakingUndelegateMsg | StakingWithdrawMsg; -} - -interface WasmExecuteMsg { - readonly execute: { - readonly contract_address: string; - readonly msg: any; - readonly send: readonly Coin[]; - }; -} - -interface WasmInstantiateMsg { - readonly instantiate: { - readonly code_id: string; - readonly msg: any; - readonly send: readonly Coin[]; - readonly label?: string; - }; -} - -export interface WasmMsg { - readonly wasm: WasmExecuteMsg | WasmInstantiateMsg; -} - -export type CosmosMsg = BankMsg | CustomMsg | StakingMsg | WasmMsg; diff --git a/packages/cosmwasm/types/cosmosmsg.d.ts b/packages/cosmwasm/types/cosmosmsg.d.ts new file mode 100644 index 00000000..82b225ba --- /dev/null +++ b/packages/cosmwasm/types/cosmosmsg.d.ts @@ -0,0 +1,65 @@ +import { Coin } from "@cosmjs/launchpad"; +interface BankSendMsg { + readonly send: { + readonly from_address: string; + readonly to_address: string; + readonly amount: readonly Coin[]; + }; +} +export interface BankMsg { + readonly bank: BankSendMsg; +} +export interface CustomMsg { + readonly custom: Record; +} +interface StakingDelegateMsg { + readonly delegate: { + readonly validator: string; + readonly amount: Coin; + }; +} +interface StakingRedelegateMsg { + readonly redelgate: { + readonly src_validator: string; + readonly dst_validator: string; + readonly amount: Coin; + }; +} +interface StakingUndelegateMsg { + readonly undelegate: { + readonly validator: string; + readonly amount: Coin; + }; +} +interface StakingWithdrawMsg { + readonly withdraw: { + readonly validator: string; + readonly recipient?: string; + }; +} +export interface StakingMsg { + readonly staking: StakingDelegateMsg | StakingRedelegateMsg | StakingUndelegateMsg | StakingWithdrawMsg; +} +interface WasmExecuteMsg { + readonly execute: { + readonly contract_address: string; + readonly msg: any; + readonly send: readonly Coin[]; + }; +} +interface WasmInstantiateMsg { + readonly instantiate: { + readonly code_id: string; + readonly msg: any; + readonly send: readonly Coin[]; + readonly label?: string; + }; +} +export interface WasmMsg { + readonly wasm: WasmExecuteMsg | WasmInstantiateMsg; +} +/** These definitions are derived from CosmWasm: + * https://github.com/CosmWasm/cosmwasm/blob/v0.12.0/packages/std/src/results/cosmos_msg.rs#L10-L23 + */ +export declare type CosmosMsg = BankMsg | CustomMsg | StakingMsg | WasmMsg; +export {}; diff --git a/packages/cosmwasm/types/cw3cosmwasmclient.d.ts b/packages/cosmwasm/types/cw3cosmwasmclient.d.ts index efbc17f3..80ff14fc 100644 --- a/packages/cosmwasm/types/cw3cosmwasmclient.d.ts +++ b/packages/cosmwasm/types/cw3cosmwasmclient.d.ts @@ -1,6 +1,6 @@ import { BroadcastMode, GasLimits, GasPrice, OfflineSigner } from "@cosmjs/launchpad"; +import { CosmosMsg } from "./cosmosmsg"; import { Account } from "./cosmwasmclient"; -import { CosmosMsg } from "./msgs"; import { CosmWasmFeeTable, ExecuteResult, SigningCosmWasmClient } from "./signingcosmwasmclient"; export declare type Expiration = | { diff --git a/packages/cosmwasm/types/index.d.ts b/packages/cosmwasm/types/index.d.ts index 81d2c8be..b90bf610 100644 --- a/packages/cosmwasm/types/index.d.ts +++ b/packages/cosmwasm/types/index.d.ts @@ -1,4 +1,5 @@ export { setupWasmExtension, WasmExtension } from "./lcdapi/wasm"; +export { BankMsg, CosmosMsg, CustomMsg, StakingMsg, WasmMsg } from "./cosmosmsg"; export { Account, Block, @@ -39,11 +40,6 @@ export { UploadResult, } from "./signingcosmwasmclient"; export { - BankMsg, - CosmosMsg, - CustomMsg, - StakingMsg, - WasmMsg, isMsgClearAdmin, isMsgExecuteContract, isMsgInstantiateContract, diff --git a/packages/cosmwasm/types/msgs.d.ts b/packages/cosmwasm/types/msgs.d.ts index 744b47fd..9b9c89c4 100644 --- a/packages/cosmwasm/types/msgs.d.ts +++ b/packages/cosmwasm/types/msgs.d.ts @@ -117,64 +117,3 @@ export interface MsgMigrateContract extends Msg { }; } export declare function isMsgMigrateContract(msg: Msg): msg is MsgMigrateContract; -interface BankSendMsg { - readonly send: { - readonly from_address: string; - readonly to_address: string; - readonly amount: readonly Coin[]; - }; -} -export interface BankMsg { - readonly bank: BankSendMsg; -} -export interface CustomMsg { - readonly custom: Record; -} -interface StakingDelegateMsg { - readonly delegate: { - readonly validator: string; - readonly amount: Coin; - }; -} -interface StakingRedelegateMsg { - readonly redelgate: { - readonly src_validator: string; - readonly dst_validator: string; - readonly amount: Coin; - }; -} -interface StakingUndelegateMsg { - readonly undelegate: { - readonly validator: string; - readonly amount: Coin; - }; -} -interface StakingWithdrawMsg { - readonly withdraw: { - readonly validator: string; - readonly recipient?: string; - }; -} -export interface StakingMsg { - readonly staking: StakingDelegateMsg | StakingRedelegateMsg | StakingUndelegateMsg | StakingWithdrawMsg; -} -interface WasmExecuteMsg { - readonly execute: { - readonly contract_address: string; - readonly msg: any; - readonly send: readonly Coin[]; - }; -} -interface WasmInstantiateMsg { - readonly instantiate: { - readonly code_id: string; - readonly msg: any; - readonly send: readonly Coin[]; - readonly label?: string; - }; -} -export interface WasmMsg { - readonly wasm: WasmExecuteMsg | WasmInstantiateMsg; -} -export declare type CosmosMsg = BankMsg | CustomMsg | StakingMsg | WasmMsg; -export {};