Improve and fix Msg types
This commit is contained in:
parent
cd66935dce
commit
44182e96b7
@ -73,13 +73,10 @@ export function decodeAmount(tokens: TokenInfos, coin: types.Coin): Amount {
|
||||
}
|
||||
|
||||
export function parseMsg(msg: types.Msg, chainId: ChainId, tokens: TokenInfos): SendTransaction {
|
||||
if (msg.type !== "cosmos-sdk/MsgSend") {
|
||||
if (!types.isMsgSend(msg)) {
|
||||
throw new Error("Unknown message type in transaction");
|
||||
}
|
||||
if (!(msg.value as types.MsgSend).from_address) {
|
||||
throw new Error("Only MsgSend is supported");
|
||||
}
|
||||
const msgValue = msg.value as types.MsgSend;
|
||||
const msgValue = msg.value;
|
||||
if (msgValue.amount.length !== 1) {
|
||||
throw new Error("Only MsgSend with one amount is supported");
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ import { encodeSecp256k1Signature, marshalTx, sortJson } from "./encoding";
|
||||
import { RestClient } from "./restclient";
|
||||
import contract from "./testdata/contract.json";
|
||||
import data from "./testdata/cosmoshub.json";
|
||||
import { MsgStoreCodeWrapped, StdTx } from "./types";
|
||||
import { MsgStoreCode, StdTx } from "./types";
|
||||
|
||||
const { fromBase64, toUtf8 } = Encoding;
|
||||
|
||||
@ -66,7 +66,7 @@ describe("RestClient", () => {
|
||||
const signer = await wallet.createIdentity("abc" as ChainId, faucetPath);
|
||||
|
||||
const memo = "My first contract on chain";
|
||||
const theMsg: MsgStoreCodeWrapped = {
|
||||
const theMsg: MsgStoreCode = {
|
||||
type: "wasm/store-code",
|
||||
value: {
|
||||
sender: faucetAddress,
|
||||
|
||||
@ -22,12 +22,12 @@ export function isAminoStdTx(txValue: unknown): txValue is StdTx {
|
||||
);
|
||||
}
|
||||
|
||||
interface MsgUnknownWrapped {
|
||||
interface MsgTemplate {
|
||||
readonly type: string;
|
||||
readonly value: object;
|
||||
}
|
||||
|
||||
export interface MsgSend {
|
||||
export interface ValueSend {
|
||||
/** Bech32 account address */
|
||||
readonly from_address: string;
|
||||
/** Bech32 account address */
|
||||
@ -35,12 +35,12 @@ export interface MsgSend {
|
||||
readonly amount: ReadonlyArray<Coin>;
|
||||
}
|
||||
|
||||
export interface MsgSendWrapped extends MsgUnknownWrapped {
|
||||
readonly type: "cosmos-sdk/StdTx";
|
||||
readonly value: MsgSend;
|
||||
export interface MsgSend extends MsgTemplate {
|
||||
readonly type: "cosmos-sdk/MsgSend";
|
||||
readonly value: ValueSend;
|
||||
}
|
||||
|
||||
export interface MsgStoreCode {
|
||||
export interface ValueStoreCode {
|
||||
/** Bech32 account address */
|
||||
readonly sender: string;
|
||||
/** Base64 encoded Wasm */
|
||||
@ -51,12 +51,20 @@ export interface MsgStoreCode {
|
||||
readonly builder?: string;
|
||||
}
|
||||
|
||||
export interface MsgStoreCodeWrapped extends MsgUnknownWrapped {
|
||||
export interface MsgStoreCode extends MsgTemplate {
|
||||
readonly type: "wasm/store-code";
|
||||
readonly value: MsgStoreCode;
|
||||
readonly value: ValueStoreCode;
|
||||
}
|
||||
|
||||
export type Msg = MsgSendWrapped | MsgStoreCodeWrapped | MsgUnknownWrapped;
|
||||
export type Msg = MsgSend | MsgStoreCode | MsgTemplate;
|
||||
|
||||
export function isMsgSend(msg: Msg): msg is MsgSend {
|
||||
return (msg as MsgSend).type === "cosmos-sdk/MsgSend";
|
||||
}
|
||||
|
||||
export function isMsgStoreCode(msg: Msg): msg is MsgStoreCode {
|
||||
return (msg as MsgStoreCode).type === "wasm/store-code";
|
||||
}
|
||||
|
||||
export interface StdFee {
|
||||
readonly amount: ReadonlyArray<Coin>;
|
||||
|
||||
20
packages/sdk/types/types.d.ts
vendored
20
packages/sdk/types/types.d.ts
vendored
@ -12,22 +12,22 @@ export declare type AminoTx = Tx & {
|
||||
readonly value: StdTx;
|
||||
};
|
||||
export declare function isAminoStdTx(txValue: unknown): txValue is StdTx;
|
||||
interface MsgUnknownWrapped {
|
||||
interface MsgTemplate {
|
||||
readonly type: string;
|
||||
readonly value: object;
|
||||
}
|
||||
export interface MsgSend {
|
||||
export interface ValueSend {
|
||||
/** Bech32 account address */
|
||||
readonly from_address: string;
|
||||
/** Bech32 account address */
|
||||
readonly to_address: string;
|
||||
readonly amount: ReadonlyArray<Coin>;
|
||||
}
|
||||
export interface MsgSendWrapped extends MsgUnknownWrapped {
|
||||
readonly type: "cosmos-sdk/StdTx";
|
||||
readonly value: MsgSend;
|
||||
export interface MsgSend extends MsgTemplate {
|
||||
readonly type: "cosmos-sdk/MsgSend";
|
||||
readonly value: ValueSend;
|
||||
}
|
||||
export interface MsgStoreCode {
|
||||
export interface ValueStoreCode {
|
||||
/** Bech32 account address */
|
||||
readonly sender: string;
|
||||
/** Base64 encoded Wasm */
|
||||
@ -37,11 +37,13 @@ export interface MsgStoreCode {
|
||||
/** A docker tag, optional */
|
||||
readonly builder?: string;
|
||||
}
|
||||
export interface MsgStoreCodeWrapped extends MsgUnknownWrapped {
|
||||
export interface MsgStoreCode extends MsgTemplate {
|
||||
readonly type: "wasm/store-code";
|
||||
readonly value: MsgStoreCode;
|
||||
readonly value: ValueStoreCode;
|
||||
}
|
||||
export declare type Msg = MsgSendWrapped | MsgStoreCodeWrapped | MsgUnknownWrapped;
|
||||
export declare type Msg = MsgSend | MsgStoreCode | MsgTemplate;
|
||||
export declare function isMsgSend(msg: Msg): msg is MsgSend;
|
||||
export declare function isMsgStoreCode(msg: Msg): msg is MsgStoreCode;
|
||||
export interface StdFee {
|
||||
readonly amount: ReadonlyArray<Coin>;
|
||||
readonly gas: string;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user