Merge pull request #568 from cosmos/491-stargate-preparation
Prepare Stargate package for CosmWasm support
This commit is contained in:
commit
179b355536
@ -25,6 +25,7 @@ yarn pbjs \
|
||||
"$COSMOS_PROTO_DIR/bank/v1beta1/bank.proto" \
|
||||
"$COSMOS_PROTO_DIR/bank/v1beta1/query.proto" \
|
||||
"$COSMOS_PROTO_DIR/bank/v1beta1/tx.proto" \
|
||||
"$COSMOS_PROTO_DIR/base/abci/v1beta1/abci.proto" \
|
||||
"$COSMOS_PROTO_DIR/base/query/v1beta1/pagination.proto" \
|
||||
"$COSMOS_PROTO_DIR/base/v1beta1/coin.proto" \
|
||||
"$COSMOS_PROTO_DIR/crypto/multisig/v1beta1/multisig.proto" \
|
||||
@ -39,9 +40,11 @@ yarn pbjs \
|
||||
"$IBC_PROTO_DIR/core/commitment/v1/commitment.proto" \
|
||||
"$IBC_PROTO_DIR/core/connection/v1/connection.proto" \
|
||||
"$IBC_PROTO_DIR/core/connection/v1/query.proto" \
|
||||
"$TENDERMINT_PROTO_DIR/abci/types.proto" \
|
||||
"$TENDERMINT_PROTO_DIR/crypto/keys.proto" \
|
||||
"$TENDERMINT_PROTO_DIR/crypto/proof.proto" \
|
||||
"$TENDERMINT_PROTO_DIR/libs/bits/types.proto" \
|
||||
"$TENDERMINT_PROTO_DIR/types/params.proto" \
|
||||
"$TENDERMINT_PROTO_DIR/types/types.proto" \
|
||||
"$TENDERMINT_PROTO_DIR/types/validator.proto" \
|
||||
"$TENDERMINT_PROTO_DIR/version/types.proto"
|
||||
|
||||
4019
packages/stargate/src/codec/generated/codecimpl.d.ts
vendored
4019
packages/stargate/src/codec/generated/codecimpl.d.ts
vendored
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,6 @@
|
||||
export * as codec from "./codec";
|
||||
export { getMsgType, getMsgTypeUrl } from "./encoding";
|
||||
export { parseRawLog } from "./logs";
|
||||
export {
|
||||
AuthExtension,
|
||||
BankExtension,
|
||||
@ -8,5 +10,17 @@ export {
|
||||
setupBankExtension,
|
||||
setupIbcExtension,
|
||||
} from "./queries";
|
||||
export { assertIsBroadcastTxSuccess, StargateClient } from "./stargateclient";
|
||||
export {
|
||||
Account,
|
||||
accountFromProto,
|
||||
assertIsBroadcastTxSuccess,
|
||||
BroadcastTxFailure,
|
||||
BroadcastTxResponse,
|
||||
BroadcastTxSuccess,
|
||||
coinFromProto,
|
||||
IndexedTx,
|
||||
isBroadcastTxFailure,
|
||||
SequenceResponse,
|
||||
StargateClient,
|
||||
} from "./stargateclient";
|
||||
export { SigningStargateClient } from "./signingstargateclient";
|
||||
|
||||
11
packages/stargate/src/logs.ts
Normal file
11
packages/stargate/src/logs.ts
Normal file
@ -0,0 +1,11 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { logs } from "@cosmjs/launchpad";
|
||||
|
||||
export function parseRawLog(input = "[]"): readonly logs.Log[] {
|
||||
const logsToParse = JSON.parse(input).map(({ events }: { events: readonly unknown[] }, i: number) => ({
|
||||
msg_index: i,
|
||||
events,
|
||||
log: "",
|
||||
}));
|
||||
return logs.parseLogs(logsToParse);
|
||||
}
|
||||
@ -3,7 +3,7 @@ import { iavlSpec, ics23, tendermintSpec, verifyExistence, verifyNonExistence }
|
||||
import { toAscii, toHex } from "@cosmjs/encoding";
|
||||
import { firstEvent } from "@cosmjs/stream";
|
||||
import { Client as TendermintClient, Header, NewBlockHeaderEvent, ProofOp } from "@cosmjs/tendermint-rpc";
|
||||
import { arrayContentEquals, assert, isNonNullObject, sleep } from "@cosmjs/utils";
|
||||
import { arrayContentEquals, assert, assertDefined, isNonNullObject, sleep } from "@cosmjs/utils";
|
||||
import { Stream } from "xstream";
|
||||
|
||||
type QueryExtensionSetup<P> = (base: QueryClient) => P;
|
||||
@ -233,8 +233,8 @@ export class QueryClient {
|
||||
// this must return the header for height+1
|
||||
// throws an error if height is 0 or undefined
|
||||
private async getNextHeader(height?: number): Promise<Header> {
|
||||
assert(height);
|
||||
if (height == 0) {
|
||||
assertDefined(height);
|
||||
if (height === 0) {
|
||||
throw new Error("Query returned height 0, cannot prove it");
|
||||
}
|
||||
|
||||
|
||||
@ -25,6 +25,12 @@ import Long from "long";
|
||||
import { cosmos } from "./codec";
|
||||
import { AuthExtension, BankExtension, QueryClient, setupAuthExtension, setupBankExtension } from "./queries";
|
||||
|
||||
type IBaseAccount = cosmos.auth.v1beta1.IBaseAccount;
|
||||
type IMsgData = cosmos.base.abci.v1beta1.IMsgData;
|
||||
type ICoin = cosmos.base.v1beta1.ICoin;
|
||||
|
||||
const { TxMsgData } = cosmos.base.abci.v1beta1;
|
||||
|
||||
/** A transaction that is indexed as part of the transaction history */
|
||||
export interface IndexedTx {
|
||||
readonly height: number;
|
||||
@ -54,14 +60,14 @@ export interface BroadcastTxFailure {
|
||||
readonly code: number;
|
||||
readonly transactionHash: string;
|
||||
readonly rawLog?: string;
|
||||
readonly data?: Uint8Array;
|
||||
readonly data?: readonly IMsgData[];
|
||||
}
|
||||
|
||||
export interface BroadcastTxSuccess {
|
||||
readonly height: number;
|
||||
readonly transactionHash: string;
|
||||
readonly rawLog?: string;
|
||||
readonly data?: Uint8Array;
|
||||
readonly data?: readonly IMsgData[];
|
||||
}
|
||||
|
||||
export type BroadcastTxResponse = BroadcastTxSuccess | BroadcastTxFailure;
|
||||
@ -92,7 +98,7 @@ function uint64FromProto(input: number | Long | null | undefined): Uint64 {
|
||||
return Uint64.fromString(input.toString());
|
||||
}
|
||||
|
||||
function accountFromProto(input: cosmos.auth.v1beta1.IBaseAccount): Account {
|
||||
export function accountFromProto(input: IBaseAccount): Account {
|
||||
const { address, pubKey, accountNumber, sequence } = input;
|
||||
const pubkey = decodePubkey(pubKey);
|
||||
assert(address);
|
||||
@ -104,7 +110,7 @@ function accountFromProto(input: cosmos.auth.v1beta1.IBaseAccount): Account {
|
||||
};
|
||||
}
|
||||
|
||||
function coinFromProto(input: cosmos.base.v1beta1.ICoin): Coin {
|
||||
export function coinFromProto(input: ICoin): Coin {
|
||||
assertDefined(input.amount);
|
||||
assertDefined(input.denom);
|
||||
assert(input.amount !== null);
|
||||
@ -243,7 +249,7 @@ export class StargateClient {
|
||||
height: response.height,
|
||||
transactionHash: toHex(response.hash).toUpperCase(),
|
||||
rawLog: response.deliverTx?.log,
|
||||
data: response.deliverTx?.data,
|
||||
data: response.deliverTx?.data ? TxMsgData.decode(response.deliverTx?.data).data : undefined,
|
||||
};
|
||||
}
|
||||
return response.checkTx.code !== 0
|
||||
@ -252,14 +258,14 @@ export class StargateClient {
|
||||
code: response.checkTx.code,
|
||||
transactionHash: toHex(response.hash).toUpperCase(),
|
||||
rawLog: response.checkTx.log,
|
||||
data: response.checkTx.data,
|
||||
data: response.checkTx.data ? TxMsgData.decode(response.checkTx.data).data : undefined,
|
||||
}
|
||||
: {
|
||||
height: response.height,
|
||||
code: response.deliverTx?.code,
|
||||
transactionHash: toHex(response.hash).toUpperCase(),
|
||||
rawLog: response.deliverTx?.log,
|
||||
data: response.deliverTx?.data,
|
||||
data: response.deliverTx?.data ? TxMsgData.decode(response.deliverTx?.data).data : undefined,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
4019
packages/stargate/types/codec/generated/codecimpl.d.ts
vendored
4019
packages/stargate/types/codec/generated/codecimpl.d.ts
vendored
File diff suppressed because it is too large
Load Diff
16
packages/stargate/types/index.d.ts
vendored
16
packages/stargate/types/index.d.ts
vendored
@ -1,4 +1,6 @@
|
||||
export * as codec from "./codec";
|
||||
export { getMsgType, getMsgTypeUrl } from "./encoding";
|
||||
export { parseRawLog } from "./logs";
|
||||
export {
|
||||
AuthExtension,
|
||||
BankExtension,
|
||||
@ -8,5 +10,17 @@ export {
|
||||
setupBankExtension,
|
||||
setupIbcExtension,
|
||||
} from "./queries";
|
||||
export { assertIsBroadcastTxSuccess, StargateClient } from "./stargateclient";
|
||||
export {
|
||||
Account,
|
||||
accountFromProto,
|
||||
assertIsBroadcastTxSuccess,
|
||||
BroadcastTxFailure,
|
||||
BroadcastTxResponse,
|
||||
BroadcastTxSuccess,
|
||||
coinFromProto,
|
||||
IndexedTx,
|
||||
isBroadcastTxFailure,
|
||||
SequenceResponse,
|
||||
StargateClient,
|
||||
} from "./stargateclient";
|
||||
export { SigningStargateClient } from "./signingstargateclient";
|
||||
|
||||
2
packages/stargate/types/logs.d.ts
vendored
Normal file
2
packages/stargate/types/logs.d.ts
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import { logs } from "@cosmjs/launchpad";
|
||||
export declare function parseRawLog(input?: string): readonly logs.Log[];
|
||||
11
packages/stargate/types/stargateclient.d.ts
vendored
11
packages/stargate/types/stargateclient.d.ts
vendored
@ -1,5 +1,9 @@
|
||||
import { Block, Coin, PubKey, SearchTxFilter, SearchTxQuery } from "@cosmjs/launchpad";
|
||||
import { Client as TendermintClient } from "@cosmjs/tendermint-rpc";
|
||||
import { cosmos } from "./codec";
|
||||
declare type IBaseAccount = cosmos.auth.v1beta1.IBaseAccount;
|
||||
declare type IMsgData = cosmos.base.abci.v1beta1.IMsgData;
|
||||
declare type ICoin = cosmos.base.v1beta1.ICoin;
|
||||
/** A transaction that is indexed as part of the transaction history */
|
||||
export interface IndexedTx {
|
||||
readonly height: number;
|
||||
@ -26,13 +30,13 @@ export interface BroadcastTxFailure {
|
||||
readonly code: number;
|
||||
readonly transactionHash: string;
|
||||
readonly rawLog?: string;
|
||||
readonly data?: Uint8Array;
|
||||
readonly data?: readonly IMsgData[];
|
||||
}
|
||||
export interface BroadcastTxSuccess {
|
||||
readonly height: number;
|
||||
readonly transactionHash: string;
|
||||
readonly rawLog?: string;
|
||||
readonly data?: Uint8Array;
|
||||
readonly data?: readonly IMsgData[];
|
||||
}
|
||||
export declare type BroadcastTxResponse = BroadcastTxSuccess | BroadcastTxFailure;
|
||||
export declare function isBroadcastTxFailure(result: BroadcastTxResponse): result is BroadcastTxFailure;
|
||||
@ -43,6 +47,8 @@ export declare function isBroadcastTxSuccess(result: BroadcastTxResponse): resul
|
||||
export declare function assertIsBroadcastTxSuccess(
|
||||
result: BroadcastTxResponse,
|
||||
): asserts result is BroadcastTxSuccess;
|
||||
export declare function accountFromProto(input: IBaseAccount): Account;
|
||||
export declare function coinFromProto(input: ICoin): Coin;
|
||||
/** Use for testing only */
|
||||
export interface PrivateStargateClient {
|
||||
readonly tmClient: TendermintClient;
|
||||
@ -71,3 +77,4 @@ export declare class StargateClient {
|
||||
broadcastTx(tx: Uint8Array): Promise<BroadcastTxResponse>;
|
||||
private txsQuery;
|
||||
}
|
||||
export {};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user