Sort some types between sdk38 and cosmwasm

This commit is contained in:
Simon Warta 2020-06-02 13:45:19 +02:00
parent dd54e7f5af
commit efb90d1f65
19 changed files with 260 additions and 443 deletions

View File

@ -1,8 +1,9 @@
/* eslint-disable @typescript-eslint/camelcase */
import { Coin, Secp256k1Pen, makeSignBytes } from "@cosmwasm/sdk38";
import { Coin, makeSignBytes, Secp256k1Pen } from "@cosmwasm/sdk38";
import { assert, sleep } from "@iov/utils";
import { CosmWasmClient } from "./cosmwasmclient";
import { isMsgExecuteContract, isMsgInstantiateContract, isMsgSend, MsgSend } from "./msgs";
import { RestClient } from "./restclient";
import { SigningCosmWasmClient } from "./signingcosmwasmclient";
import {
@ -14,7 +15,7 @@ import {
wasmd,
wasmdEnabled,
} from "./testutils.spec";
import { CosmosSdkTx, isMsgExecuteContract, isMsgInstantiateContract, isMsgSend, MsgSend } from "./types";
import { CosmosSdkTx } from "./types";
describe("CosmWasmClient.searchTx", () => {
let sendSuccessful:

View File

@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/camelcase */
import { Secp256k1Pen, makeSignBytes } from "@cosmwasm/sdk38";
import { makeSignBytes, Secp256k1Pen } from "@cosmwasm/sdk38";
import { Sha256 } from "@iov/crypto";
import { Bech32, Encoding } from "@iov/encoding";
import { assert, sleep } from "@iov/utils";
@ -7,6 +7,7 @@ import { ReadonlyDate } from "readonly-date";
import { Code, CosmWasmClient, PrivateCosmWasmClient } from "./cosmwasmclient";
import { findAttribute } from "./logs";
import { MsgSend } from "./msgs";
import { SigningCosmWasmClient } from "./signingcosmwasmclient";
import cosmoshub from "./testdata/cosmoshub.json";
import {
@ -20,7 +21,7 @@ import {
wasmd,
wasmdEnabled,
} from "./testutils.spec";
import { MsgSend, StdFee } from "./types";
import { StdFee } from "./types";
const { fromHex, fromUtf8, toAscii, toBase64 } = Encoding;

View File

@ -1,9 +1,8 @@
import { Coin } from "@cosmwasm/sdk38";
import { Coin, decodeBech32Pubkey, IndexedTx } from "@cosmwasm/sdk38";
import { Sha256 } from "@iov/crypto";
import { Encoding } from "@iov/encoding";
import { Log, parseLogs } from "./logs";
import { decodeBech32Pubkey } from "./pubkey";
import { BroadcastMode, RestClient } from "./restclient";
import { CosmosSdkTx, JsonObject, PubKey, StdTx } from "./types";
@ -103,24 +102,6 @@ export interface ContractDetails extends Contract {
readonly initMsg: object;
}
/** A transaction that is indexed as part of the transaction history */
export interface IndexedTx {
readonly height: number;
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly hash: string;
/** Transaction execution error code. 0 on success. */
readonly code: number;
readonly rawLog: string;
readonly logs: readonly Log[];
readonly tx: CosmosSdkTx;
/** The gas limit as set by the user */
readonly gasWanted?: number;
/** The gas used by the execution */
readonly gasUsed?: number;
/** An RFC 3339 time string like e.g. '2020-02-15T10:39:10.4696305Z' */
readonly timestamp: string;
}
export interface BlockHeader {
readonly version: {
readonly block: string;

View File

@ -1,6 +1,5 @@
import * as logs from "./logs";
import * as types from "./types";
export { logs, types };
export { logs };
export { BroadcastMode, RestClient, TxsResponse } from "./restclient";
export {
@ -13,7 +12,6 @@ export {
ContractDetails,
CosmWasmClient,
GetNonceResult,
IndexedTx,
PostTxResult,
SearchByHeightQuery,
SearchByIdQuery,
@ -22,7 +20,6 @@ export {
SearchTxQuery,
SearchTxFilter,
} from "./cosmwasmclient";
export { decodeBech32Pubkey, encodeBech32Pubkey, encodeSecp256k1Pubkey } from "./pubkey";
export {
ExecuteResult,
FeeTable,
@ -32,3 +29,11 @@ export {
UploadMeta,
UploadResult,
} from "./signingcosmwasmclient";
export {
isMsgExecuteContract,
isMsgInstantiateContract,
isMsgStoreCode,
MsgStoreCode,
MsgExecuteContract,
MsgInstantiateContract,
} from "./msgs";

View File

@ -0,0 +1,93 @@
import { Coin } from "@cosmwasm/sdk38";
interface MsgTemplate {
readonly type: string;
readonly value: any;
}
/** A Cosmos SDK token transfer message */
export interface MsgSend extends MsgTemplate {
readonly type: "cosmos-sdk/MsgSend";
readonly value: {
/** Bech32 account address */
readonly from_address: string;
/** Bech32 account address */
readonly to_address: string;
readonly amount: ReadonlyArray<Coin>;
};
}
/**
* Uploads Wam code to the chain
*
* @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L17
*/
export interface MsgStoreCode extends MsgTemplate {
readonly type: "wasm/store-code";
readonly value: {
/** Bech32 account address */
readonly sender: string;
/** Base64 encoded Wasm */
readonly wasm_byte_code: string;
/** A valid URI reference to the contract's source code. Can be empty. */
readonly source: string;
/** A docker tag. Can be empty. */
readonly builder: string;
};
}
/**
* Creates an instance of contract that was uploaded before.
*
* @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L73
*/
export interface MsgInstantiateContract extends MsgTemplate {
readonly type: "wasm/instantiate";
readonly value: {
/** Bech32 account address */
readonly sender: string;
/** ID of the Wasm code that was uploaded before */
readonly code_id: string;
/** Human-readable label for this contract */
readonly label: string;
/** Init message as JavaScript object */
readonly init_msg: any;
readonly init_funds: ReadonlyArray<Coin>;
};
}
/**
* Creates an instance of contract that was uploaded before.
*
* @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L103
*/
export interface MsgExecuteContract extends MsgTemplate {
readonly type: "wasm/execute";
readonly value: {
/** Bech32 account address */
readonly sender: string;
/** Bech32 account address */
readonly contract: string;
/** Handle message as JavaScript object */
readonly msg: any;
readonly sent_funds: ReadonlyArray<Coin>;
};
}
export type Msg = MsgSend | MsgStoreCode | MsgInstantiateContract | MsgExecuteContract | 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 function isMsgInstantiateContract(msg: Msg): msg is MsgInstantiateContract {
return (msg as MsgInstantiateContract).type === "wasm/instantiate";
}
export function isMsgExecuteContract(msg: Msg): msg is MsgExecuteContract {
return (msg as MsgExecuteContract).type === "wasm/execute";
}

View File

@ -1,57 +0,0 @@
import { Encoding } from "@iov/encoding";
import { decodeBech32Pubkey, encodeBech32Pubkey, encodeSecp256k1Pubkey } from "./pubkey";
import { PubKey } from "./types";
const { fromBase64 } = Encoding;
describe("pubkey", () => {
describe("encodeSecp256k1Pubkey", () => {
it("encodes a compresed pubkey", () => {
const pubkey = fromBase64("AtQaCqFnshaZQp6rIkvAPyzThvCvXSDO+9AzbxVErqJP");
expect(encodeSecp256k1Pubkey(pubkey)).toEqual({
type: "tendermint/PubKeySecp256k1",
value: "AtQaCqFnshaZQp6rIkvAPyzThvCvXSDO+9AzbxVErqJP",
});
});
it("throws for uncompressed public keys", () => {
const pubkey = fromBase64(
"BE8EGB7ro1ORuFhjOnZcSgwYlpe0DSFjVNUIkNNQxwKQE7WHpoHoNswYeoFkuYpYSKK4mzFzMV/dB0DVAy4lnNU=",
);
expect(() => encodeSecp256k1Pubkey(pubkey)).toThrowError(/public key must be compressed secp256k1/i);
});
});
describe("decodeBech32Pubkey", () => {
it("works", () => {
expect(
decodeBech32Pubkey("cosmospub1addwnpepqd8sgxq7aw348ydctp3n5ajufgxp395hksxjzc6565yfp56scupfqhlgyg5"),
).toEqual({
type: "tendermint/PubKeySecp256k1",
value: "A08EGB7ro1ORuFhjOnZcSgwYlpe0DSFjVNUIkNNQxwKQ",
});
});
it("works for enigma pubkey", () => {
expect(
decodeBech32Pubkey("enigmapub1addwnpepqw5k9p439nw0zpg2aundx4umwx4nw233z5prpjqjv5anl5grmnchzp2xwvv"),
).toEqual({
type: "tendermint/PubKeySecp256k1",
value: "A6lihrEs3PEFCu8m01ebcas3KjEVAjDIEmU7P9ED3PFx",
});
});
});
describe("encodeBech32Pubkey", () => {
it("works for secp256k1", () => {
const pubkey: PubKey = {
type: "tendermint/PubKeySecp256k1",
value: "A08EGB7ro1ORuFhjOnZcSgwYlpe0DSFjVNUIkNNQxwKQ",
};
expect(encodeBech32Pubkey(pubkey, "cosmospub")).toEqual(
"cosmospub1addwnpepqd8sgxq7aw348ydctp3n5ajufgxp395hksxjzc6565yfp56scupfqhlgyg5",
);
});
});
});

View File

@ -1,71 +0,0 @@
import { Bech32, Encoding } from "@iov/encoding";
import equal from "fast-deep-equal";
import { PubKey, pubkeyType } from "./types";
export function encodeSecp256k1Pubkey(pubkey: Uint8Array): PubKey {
if (pubkey.length !== 33 || (pubkey[0] !== 0x02 && pubkey[0] !== 0x03)) {
throw new Error("Public key must be compressed secp256k1, i.e. 33 bytes starting with 0x02 or 0x03");
}
return {
type: pubkeyType.secp256k1,
value: Encoding.toBase64(pubkey),
};
}
// As discussed in https://github.com/binance-chain/javascript-sdk/issues/163
// Prefixes listed here: https://github.com/tendermint/tendermint/blob/d419fffe18531317c28c29a292ad7d253f6cafdf/docs/spec/blockchain/encoding.md#public-key-cryptography
// Last bytes is varint-encoded length prefix
const pubkeyAminoPrefixSecp256k1 = Encoding.fromHex("eb5ae98721");
const pubkeyAminoPrefixEd25519 = Encoding.fromHex("1624de6420");
const pubkeyAminoPrefixSr25519 = Encoding.fromHex("0dfb1005");
const pubkeyAminoPrefixLength = pubkeyAminoPrefixSecp256k1.length;
export function decodeBech32Pubkey(bechEncoded: string): PubKey {
const { data } = Bech32.decode(bechEncoded);
const aminoPrefix = data.slice(0, pubkeyAminoPrefixLength);
const rest = data.slice(pubkeyAminoPrefixLength);
if (equal(aminoPrefix, pubkeyAminoPrefixSecp256k1)) {
if (rest.length !== 33) {
throw new Error("Invalid rest data length. Expected 33 bytes (compressed secp256k1 pubkey).");
}
return {
type: pubkeyType.secp256k1,
value: Encoding.toBase64(rest),
};
} else if (equal(aminoPrefix, pubkeyAminoPrefixEd25519)) {
if (rest.length !== 32) {
throw new Error("Invalid rest data length. Expected 32 bytes (Ed25519 pubkey).");
}
return {
type: pubkeyType.ed25519,
value: Encoding.toBase64(rest),
};
} else if (equal(aminoPrefix, pubkeyAminoPrefixSr25519)) {
if (rest.length !== 32) {
throw new Error("Invalid rest data length. Expected 32 bytes (Sr25519 pubkey).");
}
return {
type: pubkeyType.sr25519,
value: Encoding.toBase64(rest),
};
} else {
throw new Error("Unsupported Pubkey type. Amino prefix: " + Encoding.toHex(aminoPrefix));
}
}
export function encodeBech32Pubkey(pubkey: PubKey, prefix: string): string {
let aminoPrefix: Uint8Array;
switch (pubkey.type) {
// Note: please don't add cases here without writing additional unit tests
case pubkeyType.secp256k1:
aminoPrefix = pubkeyAminoPrefixSecp256k1;
break;
default:
throw new Error("Unsupported pubkey type");
}
const data = new Uint8Array([...aminoPrefix, ...Encoding.fromBase64(pubkey.value)]);
return Bech32.encode(prefix, data);
}

View File

@ -1,12 +1,28 @@
/* eslint-disable @typescript-eslint/camelcase */
import { Coin, makeCosmoshubPath, Pen, rawSecp256k1PubkeyToAddress, Secp256k1Pen, makeSignBytes } from "@cosmwasm/sdk38";
import {
Coin,
encodeBech32Pubkey,
makeCosmoshubPath,
makeSignBytes,
Pen,
rawSecp256k1PubkeyToAddress,
Secp256k1Pen,
} from "@cosmwasm/sdk38";
import { Sha256 } from "@iov/crypto";
import { Encoding } from "@iov/encoding";
import { assert, sleep } from "@iov/utils";
import { ReadonlyDate } from "readonly-date";
import { findAttribute, parseLogs } from "./logs";
import { encodeBech32Pubkey } from "./pubkey";
import {
isMsgInstantiateContract,
isMsgStoreCode,
Msg,
MsgExecuteContract,
MsgInstantiateContract,
MsgSend,
MsgStoreCode,
} from "./msgs";
import { PostTxsResponse, RestClient, TxsResponse } from "./restclient";
import { SigningCosmWasmClient } from "./signingcosmwasmclient";
import cosmoshub from "./testdata/cosmoshub.json";
@ -28,18 +44,7 @@ import {
wasmd,
wasmdEnabled,
} from "./testutils.spec";
import {
isMsgInstantiateContract,
isMsgStoreCode,
Msg,
MsgExecuteContract,
MsgInstantiateContract,
MsgSend,
MsgStoreCode,
StdFee,
StdSignature,
StdTx,
} from "./types";
import { StdFee, StdSignature, StdTx } from "./types";
const { fromAscii, fromBase64, fromHex, toAscii, toBase64, toHex } = Encoding;

View File

@ -6,15 +6,9 @@ import pako from "pako";
import { isValidBuilder } from "./builder";
import { Account, CosmWasmClient, GetNonceResult, PostTxResult } from "./cosmwasmclient";
import { findAttribute, Log } from "./logs";
import { MsgExecuteContract, MsgInstantiateContract, MsgSend, MsgStoreCode } from "./msgs";
import { BroadcastMode } from "./restclient";
import {
MsgExecuteContract,
MsgInstantiateContract,
MsgSend,
MsgStoreCode,
StdFee,
StdSignature,
} from "./types";
import { StdFee, StdSignature } from "./types";
export interface SigningCallback {
(signBytes: Uint8Array): Promise<StdSignature>;

View File

@ -1,6 +1,8 @@
import { Coin } from "@cosmwasm/sdk38";
import { Encoding } from "@iov/encoding";
import { Msg } from "./msgs";
const { fromBase64, fromHex } = Encoding;
/** An Amino/Cosmos SDK StdTx */
@ -23,98 +25,6 @@ export interface CosmosSdkTx {
readonly value: StdTx;
}
interface MsgTemplate {
readonly type: string;
readonly value: any;
}
/** A Cosmos SDK token transfer message */
export interface MsgSend extends MsgTemplate {
readonly type: "cosmos-sdk/MsgSend";
readonly value: {
/** Bech32 account address */
readonly from_address: string;
/** Bech32 account address */
readonly to_address: string;
readonly amount: ReadonlyArray<Coin>;
};
}
/**
* Uploads Wam code to the chain
*
* @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L17
*/
export interface MsgStoreCode extends MsgTemplate {
readonly type: "wasm/store-code";
readonly value: {
/** Bech32 account address */
readonly sender: string;
/** Base64 encoded Wasm */
readonly wasm_byte_code: string;
/** A valid URI reference to the contract's source code. Can be empty. */
readonly source: string;
/** A docker tag. Can be empty. */
readonly builder: string;
};
}
/**
* Creates an instance of contract that was uploaded before.
*
* @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L73
*/
export interface MsgInstantiateContract extends MsgTemplate {
readonly type: "wasm/instantiate";
readonly value: {
/** Bech32 account address */
readonly sender: string;
/** ID of the Wasm code that was uploaded before */
readonly code_id: string;
/** Human-readable label for this contract */
readonly label: string;
/** Init message as JavaScript object */
readonly init_msg: any;
readonly init_funds: ReadonlyArray<Coin>;
};
}
/**
* Creates an instance of contract that was uploaded before.
*
* @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L103
*/
export interface MsgExecuteContract extends MsgTemplate {
readonly type: "wasm/execute";
readonly value: {
/** Bech32 account address */
readonly sender: string;
/** Bech32 account address */
readonly contract: string;
/** Handle message as JavaScript object */
readonly msg: any;
readonly sent_funds: ReadonlyArray<Coin>;
};
}
export type Msg = MsgSend | MsgStoreCode | MsgInstantiateContract | MsgExecuteContract | 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 function isMsgInstantiateContract(msg: Msg): msg is MsgInstantiateContract {
return (msg as MsgInstantiateContract).type === "wasm/instantiate";
}
export function isMsgExecuteContract(msg: Msg): msg is MsgExecuteContract {
return (msg as MsgExecuteContract).type === "wasm/execute";
}
export interface StdFee {
readonly amount: ReadonlyArray<Coin>;
readonly gas: string;

View File

@ -1,4 +1,4 @@
import { Coin } from "@cosmwasm/sdk38";
import { Coin, IndexedTx } from "@cosmwasm/sdk38";
import { Log } from "./logs";
import { BroadcastMode, RestClient } from "./restclient";
import { CosmosSdkTx, JsonObject, PubKey, StdTx } from "./types";
@ -72,23 +72,6 @@ export interface ContractDetails extends Contract {
/** Argument passed on initialization of the contract */
readonly initMsg: object;
}
/** A transaction that is indexed as part of the transaction history */
export interface IndexedTx {
readonly height: number;
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly hash: string;
/** Transaction execution error code. 0 on success. */
readonly code: number;
readonly rawLog: string;
readonly logs: readonly Log[];
readonly tx: CosmosSdkTx;
/** The gas limit as set by the user */
readonly gasWanted?: number;
/** The gas used by the execution */
readonly gasUsed?: number;
/** An RFC 3339 time string like e.g. '2020-02-15T10:39:10.4696305Z' */
readonly timestamp: string;
}
export interface BlockHeader {
readonly version: {
readonly block: string;

View File

@ -1,6 +1,5 @@
import * as logs from "./logs";
import * as types from "./types";
export { logs, types };
export { logs };
export { BroadcastMode, RestClient, TxsResponse } from "./restclient";
export {
Account,
@ -12,7 +11,6 @@ export {
ContractDetails,
CosmWasmClient,
GetNonceResult,
IndexedTx,
PostTxResult,
SearchByHeightQuery,
SearchByIdQuery,
@ -21,7 +19,6 @@ export {
SearchTxQuery,
SearchTxFilter,
} from "./cosmwasmclient";
export { decodeBech32Pubkey, encodeBech32Pubkey, encodeSecp256k1Pubkey } from "./pubkey";
export {
ExecuteResult,
FeeTable,
@ -31,3 +28,11 @@ export {
UploadMeta,
UploadResult,
} from "./signingcosmwasmclient";
export {
isMsgExecuteContract,
isMsgInstantiateContract,
isMsgStoreCode,
MsgStoreCode,
MsgExecuteContract,
MsgInstantiateContract,
} from "./msgs";

76
packages/cosmwasm/types/msgs.d.ts vendored Normal file
View File

@ -0,0 +1,76 @@
import { Coin } from "@cosmwasm/sdk38";
interface MsgTemplate {
readonly type: string;
readonly value: any;
}
/** A Cosmos SDK token transfer message */
export interface MsgSend extends MsgTemplate {
readonly type: "cosmos-sdk/MsgSend";
readonly value: {
/** Bech32 account address */
readonly from_address: string;
/** Bech32 account address */
readonly to_address: string;
readonly amount: ReadonlyArray<Coin>;
};
}
/**
* Uploads Wam code to the chain
*
* @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L17
*/
export interface MsgStoreCode extends MsgTemplate {
readonly type: "wasm/store-code";
readonly value: {
/** Bech32 account address */
readonly sender: string;
/** Base64 encoded Wasm */
readonly wasm_byte_code: string;
/** A valid URI reference to the contract's source code. Can be empty. */
readonly source: string;
/** A docker tag. Can be empty. */
readonly builder: string;
};
}
/**
* Creates an instance of contract that was uploaded before.
*
* @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L73
*/
export interface MsgInstantiateContract extends MsgTemplate {
readonly type: "wasm/instantiate";
readonly value: {
/** Bech32 account address */
readonly sender: string;
/** ID of the Wasm code that was uploaded before */
readonly code_id: string;
/** Human-readable label for this contract */
readonly label: string;
/** Init message as JavaScript object */
readonly init_msg: any;
readonly init_funds: ReadonlyArray<Coin>;
};
}
/**
* Creates an instance of contract that was uploaded before.
*
* @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L103
*/
export interface MsgExecuteContract extends MsgTemplate {
readonly type: "wasm/execute";
readonly value: {
/** Bech32 account address */
readonly sender: string;
/** Bech32 account address */
readonly contract: string;
/** Handle message as JavaScript object */
readonly msg: any;
readonly sent_funds: ReadonlyArray<Coin>;
};
}
export declare type Msg = MsgSend | MsgStoreCode | MsgInstantiateContract | MsgExecuteContract | MsgTemplate;
export declare function isMsgSend(msg: Msg): msg is MsgSend;
export declare function isMsgStoreCode(msg: Msg): msg is MsgStoreCode;
export declare function isMsgInstantiateContract(msg: Msg): msg is MsgInstantiateContract;
export declare function isMsgExecuteContract(msg: Msg): msg is MsgExecuteContract;
export {};

View File

@ -1,4 +0,0 @@
import { PubKey } from "./types";
export declare function encodeSecp256k1Pubkey(pubkey: Uint8Array): PubKey;
export declare function decodeBech32Pubkey(bechEncoded: string): PubKey;
export declare function encodeBech32Pubkey(pubkey: PubKey, prefix: string): string;

View File

@ -1,4 +1,5 @@
import { Coin } from "@cosmwasm/sdk38";
import { Msg } from "./msgs";
/** An Amino/Cosmos SDK StdTx */
export interface StdTx {
readonly msg: ReadonlyArray<Msg>;
@ -11,80 +12,6 @@ export interface CosmosSdkTx {
readonly type: string;
readonly value: StdTx;
}
interface MsgTemplate {
readonly type: string;
readonly value: any;
}
/** A Cosmos SDK token transfer message */
export interface MsgSend extends MsgTemplate {
readonly type: "cosmos-sdk/MsgSend";
readonly value: {
/** Bech32 account address */
readonly from_address: string;
/** Bech32 account address */
readonly to_address: string;
readonly amount: ReadonlyArray<Coin>;
};
}
/**
* Uploads Wam code to the chain
*
* @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L17
*/
export interface MsgStoreCode extends MsgTemplate {
readonly type: "wasm/store-code";
readonly value: {
/** Bech32 account address */
readonly sender: string;
/** Base64 encoded Wasm */
readonly wasm_byte_code: string;
/** A valid URI reference to the contract's source code. Can be empty. */
readonly source: string;
/** A docker tag. Can be empty. */
readonly builder: string;
};
}
/**
* Creates an instance of contract that was uploaded before.
*
* @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L73
*/
export interface MsgInstantiateContract extends MsgTemplate {
readonly type: "wasm/instantiate";
readonly value: {
/** Bech32 account address */
readonly sender: string;
/** ID of the Wasm code that was uploaded before */
readonly code_id: string;
/** Human-readable label for this contract */
readonly label: string;
/** Init message as JavaScript object */
readonly init_msg: any;
readonly init_funds: ReadonlyArray<Coin>;
};
}
/**
* Creates an instance of contract that was uploaded before.
*
* @see https://github.com/cosmwasm/wasmd/blob/9842678d89/x/wasm/internal/types/msg.go#L103
*/
export interface MsgExecuteContract extends MsgTemplate {
readonly type: "wasm/execute";
readonly value: {
/** Bech32 account address */
readonly sender: string;
/** Bech32 account address */
readonly contract: string;
/** Handle message as JavaScript object */
readonly msg: any;
readonly sent_funds: ReadonlyArray<Coin>;
};
}
export declare type Msg = MsgSend | MsgStoreCode | MsgInstantiateContract | MsgExecuteContract | MsgTemplate;
export declare function isMsgSend(msg: Msg): msg is MsgSend;
export declare function isMsgStoreCode(msg: Msg): msg is MsgStoreCode;
export declare function isMsgInstantiateContract(msg: Msg): msg is MsgInstantiateContract;
export declare function isMsgExecuteContract(msg: Msg): msg is MsgExecuteContract;
export interface StdFee {
readonly amount: ReadonlyArray<Coin>;
readonly gas: string;
@ -120,4 +47,3 @@ export declare function parseWasmData({ key, val }: WasmData): Model;
* This doen't privide any type safety over `any` but expresses intent in the code.
*/
export declare type JsonObject = any;
export {};

View File

@ -4,6 +4,26 @@ export { logs, types };
export { pubkeyToAddress, rawSecp256k1PubkeyToAddress } from "./address";
export { Coin, coin, coins } from "./coins";
export {
Account,
Block,
BlockHeader,
Code,
CodeDetails,
Contract,
ContractDetails,
CosmosClient,
GetNonceResult,
IndexedTx,
PostTxResult,
SearchByHeightQuery,
SearchByIdQuery,
SearchBySentFromOrToQuery,
SearchByTagsQuery,
SearchTxQuery,
SearchTxFilter,
} from "./cosmosclient";
export { unmarshalTx } from "./decoding";
export { makeSignBytes, marshalTx } from "./encoding";
export { BroadcastMode, RestClient, TxsResponse } from "./restclient";
@ -11,3 +31,4 @@ export { Pen, Secp256k1Pen, makeCosmoshubPath } from "./pen";
export { decodeBech32Pubkey, encodeBech32Pubkey, encodeSecp256k1Pubkey } from "./pubkey";
export { findSequenceForSignedTx } from "./sequence";
export { encodeSecp256k1Signature, decodeSignature } from "./signature";
export { FeeTable, SigningCallback, SigningCosmosClient } from "./signingcosmosclient";

View File

@ -1,7 +1,6 @@
import { Coin, coins } from "./coins";
import { Account, CosmosClient, GetNonceResult, PostTxResult } from "./cosmosclient";
import { makeSignBytes } from "./encoding";
import { Log } from "./logs";
import { BroadcastMode } from "./restclient";
import { MsgSend, StdFee, StdSignature } from "./types";
@ -35,43 +34,6 @@ const defaultFees: FeeTable = {
},
};
export interface UploadMeta {
/** The source URL */
readonly source?: string;
/** The builder tag */
readonly builder?: string;
}
export interface UploadResult {
/** Size of the original wasm code in bytes */
readonly originalSize: number;
/** A hex encoded sha256 checksum of the original wasm code (that is stored on chain) */
readonly originalChecksum: string;
/** Size of the compressed wasm code in bytes */
readonly compressedSize: number;
/** A hex encoded sha256 checksum of the compressed wasm code (that stored in the transaction) */
readonly compressedChecksum: string;
/** The ID of the code asigned by the chain */
readonly codeId: number;
readonly logs: readonly Log[];
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly transactionHash: string;
}
export interface InstantiateResult {
/** The address of the newly instantiated contract */
readonly contractAddress: string;
readonly logs: readonly Log[];
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly transactionHash: string;
}
export interface ExecuteResult {
readonly logs: readonly Log[];
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly transactionHash: string;
}
export class SigningCosmosClient extends CosmosClient {
public readonly senderAddress: string;

View File

@ -3,6 +3,25 @@ import * as types from "./types";
export { logs, types };
export { pubkeyToAddress, rawSecp256k1PubkeyToAddress } from "./address";
export { Coin, coin, coins } from "./coins";
export {
Account,
Block,
BlockHeader,
Code,
CodeDetails,
Contract,
ContractDetails,
CosmosClient,
GetNonceResult,
IndexedTx,
PostTxResult,
SearchByHeightQuery,
SearchByIdQuery,
SearchBySentFromOrToQuery,
SearchByTagsQuery,
SearchTxQuery,
SearchTxFilter,
} from "./cosmosclient";
export { unmarshalTx } from "./decoding";
export { makeSignBytes, marshalTx } from "./encoding";
export { BroadcastMode, RestClient, TxsResponse } from "./restclient";
@ -10,3 +29,4 @@ export { Pen, Secp256k1Pen, makeCosmoshubPath } from "./pen";
export { decodeBech32Pubkey, encodeBech32Pubkey, encodeSecp256k1Pubkey } from "./pubkey";
export { findSequenceForSignedTx } from "./sequence";
export { encodeSecp256k1Signature, decodeSignature } from "./signature";
export { FeeTable, SigningCallback, SigningCosmosClient } from "./signingcosmosclient";

View File

@ -1,6 +1,5 @@
import { Coin } from "./coins";
import { Account, CosmosClient, GetNonceResult, PostTxResult } from "./cosmosclient";
import { Log } from "./logs";
import { BroadcastMode } from "./restclient";
import { StdFee, StdSignature } from "./types";
export interface SigningCallback {
@ -12,39 +11,6 @@ export interface FeeTable {
readonly exec: StdFee;
readonly send: StdFee;
}
export interface UploadMeta {
/** The source URL */
readonly source?: string;
/** The builder tag */
readonly builder?: string;
}
export interface UploadResult {
/** Size of the original wasm code in bytes */
readonly originalSize: number;
/** A hex encoded sha256 checksum of the original wasm code (that is stored on chain) */
readonly originalChecksum: string;
/** Size of the compressed wasm code in bytes */
readonly compressedSize: number;
/** A hex encoded sha256 checksum of the compressed wasm code (that stored in the transaction) */
readonly compressedChecksum: string;
/** The ID of the code asigned by the chain */
readonly codeId: number;
readonly logs: readonly Log[];
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly transactionHash: string;
}
export interface InstantiateResult {
/** The address of the newly instantiated contract */
readonly contractAddress: string;
readonly logs: readonly Log[];
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly transactionHash: string;
}
export interface ExecuteResult {
readonly logs: readonly Log[];
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
readonly transactionHash: string;
}
export declare class SigningCosmosClient extends CosmosClient {
readonly senderAddress: string;
private readonly signCallback;