mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-11 14:09:15 +00:00
stargate: Parse TxMsgData
This commit is contained in:
parent
84aeed43ef
commit
8f91640f43
@ -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());
|
||||
}
|
||||
|
||||
export 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 @@ export function accountFromProto(input: cosmos.auth.v1beta1.IBaseAccount): Accou
|
||||
};
|
||||
}
|
||||
|
||||
export 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,
|
||||
};
|
||||
}
|
||||
|
||||
|
12
packages/stargate/types/stargateclient.d.ts
vendored
12
packages/stargate/types/stargateclient.d.ts
vendored
@ -1,6 +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;
|
||||
@ -27,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;
|
||||
@ -44,8 +47,8 @@ export declare function isBroadcastTxSuccess(result: BroadcastTxResponse): resul
|
||||
export declare function assertIsBroadcastTxSuccess(
|
||||
result: BroadcastTxResponse,
|
||||
): asserts result is BroadcastTxSuccess;
|
||||
export declare function accountFromProto(input: cosmos.auth.v1beta1.IBaseAccount): Account;
|
||||
export declare function coinFromProto(input: cosmos.base.v1beta1.ICoin): Coin;
|
||||
export declare function accountFromProto(input: IBaseAccount): Account;
|
||||
export declare function coinFromProto(input: ICoin): Coin;
|
||||
/** Use for testing only */
|
||||
export interface PrivateStargateClient {
|
||||
readonly tmClient: TendermintClient;
|
||||
@ -74,3 +77,4 @@ export declare class StargateClient {
|
||||
broadcastTx(tx: Uint8Array): Promise<BroadcastTxResponse>;
|
||||
private txsQuery;
|
||||
}
|
||||
export {};
|
||||
|
Loading…
x
Reference in New Issue
Block a user