Use stronger types for Msg

This commit is contained in:
Simon Warta 2020-02-04 11:41:24 +01:00
parent 28a4518edf
commit 4e9c009809
3 changed files with 28 additions and 8 deletions

View File

@ -3,13 +3,12 @@ import { ChainId, PrehashType, SignableBytes } from "@iov/bcp";
import { Secp256k1 } from "@iov/crypto";
import { Encoding } from "@iov/encoding";
import { HdPaths, Secp256k1HdWallet } from "@iov/keycontrol";
import { types } from "src";
import { marshalTx, sortJson } from "./encoding";
import { RestClient } from "./restclient";
import contract from "./testdata/contract.json";
import data from "./testdata/cosmoshub.json";
import { StdSignature, StdTx } from "./types";
import { MsgStoreCodeWrapped, StdSignature, StdTx } from "./types";
const { fromBase64, toBase64, toUtf8 } = Encoding;
@ -68,7 +67,7 @@ describe("RestClient", () => {
const signer = await wallet.createIdentity("abc" as ChainId, faucetPath);
const memo = "My first contract on chain";
const theMsg: types.Msg = {
const theMsg: MsgStoreCodeWrapped = {
type: "wasm/store-code",
value: {
sender: faucetAddress,

View File

@ -22,10 +22,9 @@ export function isAminoStdTx(txValue: unknown): txValue is StdTx {
);
}
export interface Msg {
interface MsgUnknownWrapped {
readonly type: string;
// TODO: make better union type
readonly value: MsgSend | MsgStoreCode | unknown;
readonly value: object;
}
export interface MsgSend {
@ -36,6 +35,11 @@ export interface MsgSend {
readonly amount: ReadonlyArray<Coin>;
}
export interface MsgSendWrapped extends MsgUnknownWrapped {
readonly type: "cosmos-sdk/StdTx";
readonly value: MsgSend;
}
export interface MsgStoreCode {
/** Bech32 account address */
readonly sender: string;
@ -47,6 +51,13 @@ export interface MsgStoreCode {
readonly builder?: string;
}
export interface MsgStoreCodeWrapped extends MsgUnknownWrapped {
readonly type: "wasm/store-code";
readonly value: MsgStoreCode;
}
export type Msg = MsgSendWrapped | MsgStoreCodeWrapped | MsgUnknownWrapped;
export interface StdFee {
readonly amount: ReadonlyArray<Coin>;
readonly gas: string;

View File

@ -12,9 +12,9 @@ export declare type AminoTx = Tx & {
readonly value: StdTx;
};
export declare function isAminoStdTx(txValue: unknown): txValue is StdTx;
export interface Msg {
interface MsgUnknownWrapped {
readonly type: string;
readonly value: MsgSend | MsgStoreCode | unknown;
readonly value: object;
}
export interface MsgSend {
/** Bech32 account address */
@ -23,6 +23,10 @@ export interface MsgSend {
readonly to_address: string;
readonly amount: ReadonlyArray<Coin>;
}
export interface MsgSendWrapped extends MsgUnknownWrapped {
readonly type: "cosmos-sdk/StdTx";
readonly value: MsgSend;
}
export interface MsgStoreCode {
/** Bech32 account address */
readonly sender: string;
@ -33,6 +37,11 @@ export interface MsgStoreCode {
/** A docker tag, optional */
readonly builder?: string;
}
export interface MsgStoreCodeWrapped extends MsgUnknownWrapped {
readonly type: "wasm/store-code";
readonly value: MsgStoreCode;
}
export declare type Msg = MsgSendWrapped | MsgStoreCodeWrapped | MsgUnknownWrapped;
export interface StdFee {
readonly amount: ReadonlyArray<Coin>;
readonly gas: string;
@ -58,3 +67,4 @@ export interface BaseAccount {
readonly account_number: number;
readonly sequence: number;
}
export {};