Use *PostTx* types and helpers from sdk38 in cosmwasm
This commit is contained in:
parent
31ca949a8c
commit
939b2b9964
@ -8,6 +8,8 @@
|
||||
- @cosmjs/cosmwasm: Add `SigningCosmWasmClient.signAndPost` as a mid-level
|
||||
abstraction between `SigningCosmWasmClient.upload`/`.instantiate`/`.execute`
|
||||
and `.postTx`.
|
||||
- @cosmjs/cosmwasm: Use `*PostTx*` types and helpers from @cosmjs/sdk38. Remove
|
||||
exported `PostTxResult`.
|
||||
- @cosmjs/sdk38: Rename `CosmosClient.getNonce` method to `.getSequence`.
|
||||
- @cosmjs/sdk38: Remove `RestClient` class in favour of new modular `LcdClient`
|
||||
class.
|
||||
|
||||
@ -42,7 +42,6 @@ export function main(originalArgs: readonly string[]): void {
|
||||
"ContractDetails",
|
||||
"CosmWasmClient",
|
||||
"GetSequenceResult",
|
||||
"PostTxResult",
|
||||
"SearchByHeightQuery",
|
||||
"SearchByIdQuery",
|
||||
"SearchBySentFromOrToQuery",
|
||||
@ -98,6 +97,7 @@ export function main(originalArgs: readonly string[]): void {
|
||||
"MsgSend",
|
||||
"LcdClient",
|
||||
"OfflineSigner",
|
||||
"PostTxResult",
|
||||
"PubKey",
|
||||
"pubkeyToAddress",
|
||||
"Secp256k1Wallet",
|
||||
|
||||
@ -4,6 +4,7 @@ import {
|
||||
coins,
|
||||
CosmosSdkTx,
|
||||
isMsgSend,
|
||||
isPostTxFailure,
|
||||
LcdClient,
|
||||
makeSignBytes,
|
||||
MsgSend,
|
||||
@ -11,7 +12,7 @@ import {
|
||||
} from "@cosmjs/sdk38";
|
||||
import { assert, sleep } from "@cosmjs/utils";
|
||||
|
||||
import { CosmWasmClient, isPostTxFailure } from "./cosmwasmclient";
|
||||
import { CosmWasmClient } from "./cosmwasmclient";
|
||||
import { isMsgExecuteContract, isMsgInstantiateContract } from "./msgs";
|
||||
import { SigningCosmWasmClient } from "./signingcosmwasmclient";
|
||||
import {
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { Sha256 } from "@cosmjs/crypto";
|
||||
import { Bech32, fromHex, fromUtf8, toAscii, toBase64 } from "@cosmjs/encoding";
|
||||
import { makeSignBytes, MsgSend, Secp256k1Wallet, StdFee } from "@cosmjs/sdk38";
|
||||
import { assertIsPostTxSuccess, makeSignBytes, MsgSend, Secp256k1Wallet, StdFee } from "@cosmjs/sdk38";
|
||||
import { assert, sleep } from "@cosmjs/utils";
|
||||
import { ReadonlyDate } from "readonly-date";
|
||||
|
||||
import { Code, CosmWasmClient, isPostTxFailure, PrivateCosmWasmClient } from "./cosmwasmclient";
|
||||
import { Code, CosmWasmClient, PrivateCosmWasmClient } from "./cosmwasmclient";
|
||||
import { findAttribute } from "./logs";
|
||||
import { SigningCosmWasmClient } from "./signingcosmwasmclient";
|
||||
import cosmoshub from "./testdata/cosmoshub.json";
|
||||
@ -243,7 +243,7 @@ describe("CosmWasmClient", () => {
|
||||
signatures: [signature],
|
||||
};
|
||||
const result = await client.postTx(signedTx);
|
||||
assert(!isPostTxFailure(result));
|
||||
assertIsPostTxSuccess(result);
|
||||
const { logs, transactionHash } = result;
|
||||
const amountAttr = findAttribute(logs, "transfer", "amount");
|
||||
expect(amountAttr.value).toEqual("1234567ucosm");
|
||||
|
||||
@ -9,13 +9,14 @@ import {
|
||||
decodeBech32Pubkey,
|
||||
IndexedTx,
|
||||
LcdClient,
|
||||
PostTxResult,
|
||||
PubKey,
|
||||
setupAuthExtension,
|
||||
StdTx,
|
||||
} from "@cosmjs/sdk38";
|
||||
|
||||
import { setupWasmExtension, WasmExtension } from "./lcdapi/wasm";
|
||||
import { Log, parseLogs } from "./logs";
|
||||
import { parseLogs } from "./logs";
|
||||
import { JsonObject } from "./types";
|
||||
|
||||
export interface GetSequenceResult {
|
||||
@ -32,28 +33,6 @@ export interface Account {
|
||||
readonly sequence: number;
|
||||
}
|
||||
|
||||
export interface PostTxFailure {
|
||||
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
|
||||
readonly transactionHash: string;
|
||||
readonly height: number;
|
||||
readonly code: number;
|
||||
readonly rawLog: string;
|
||||
}
|
||||
|
||||
export interface PostTxSuccess {
|
||||
readonly logs: readonly Log[];
|
||||
readonly rawLog: string;
|
||||
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
|
||||
readonly transactionHash: string;
|
||||
readonly data?: Uint8Array;
|
||||
}
|
||||
|
||||
export type PostTxResult = PostTxSuccess | PostTxFailure;
|
||||
|
||||
export function isPostTxFailure(postTxResult: PostTxResult): postTxResult is PostTxFailure {
|
||||
return !!(postTxResult as PostTxFailure).code;
|
||||
}
|
||||
|
||||
export interface SearchByIdQuery {
|
||||
readonly id: string;
|
||||
}
|
||||
|
||||
@ -12,7 +12,6 @@ export {
|
||||
ContractDetails,
|
||||
CosmWasmClient,
|
||||
GetSequenceResult,
|
||||
PostTxResult,
|
||||
SearchByHeightQuery,
|
||||
SearchByIdQuery,
|
||||
SearchBySentFromOrToQuery,
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
import { Sha256 } from "@cosmjs/crypto";
|
||||
import { toHex } from "@cosmjs/encoding";
|
||||
import {
|
||||
assertIsPostTxSuccess,
|
||||
AuthExtension,
|
||||
coin,
|
||||
coins,
|
||||
@ -12,7 +13,7 @@ import {
|
||||
} from "@cosmjs/sdk38";
|
||||
import { assert } from "@cosmjs/utils";
|
||||
|
||||
import { isPostTxFailure, PrivateCosmWasmClient } from "./cosmwasmclient";
|
||||
import { PrivateCosmWasmClient } from "./cosmwasmclient";
|
||||
import { setupWasmExtension, WasmExtension } from "./lcdapi/wasm";
|
||||
import { SigningCosmWasmClient, UploadMeta } from "./signingcosmwasmclient";
|
||||
import {
|
||||
@ -332,7 +333,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
|
||||
// send
|
||||
const result = await client.sendTokens(beneficiaryAddress, transferAmount, "for dinner");
|
||||
assert(!isPostTxFailure(result));
|
||||
assertIsPostTxSuccess(result);
|
||||
const [firstLog] = result.logs;
|
||||
expect(firstLog).toBeTruthy();
|
||||
|
||||
@ -362,7 +363,7 @@ describe("SigningCosmWasmClient", () => {
|
||||
gas: "120000", // 120k
|
||||
};
|
||||
const result = await client.signAndPost([msg], fee, "Use your power wisely");
|
||||
assert(!isPostTxFailure(result));
|
||||
assertIsPostTxSuccess(result);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -6,10 +6,13 @@ import {
|
||||
BroadcastMode,
|
||||
Coin,
|
||||
coins,
|
||||
isPostTxFailure,
|
||||
makeSignBytes,
|
||||
Msg,
|
||||
MsgSend,
|
||||
OfflineSigner,
|
||||
PostTxFailure,
|
||||
PostTxResult,
|
||||
StdFee,
|
||||
StdSignature,
|
||||
StdTx,
|
||||
@ -17,14 +20,7 @@ import {
|
||||
import pako from "pako";
|
||||
|
||||
import { isValidBuilder } from "./builder";
|
||||
import {
|
||||
Account,
|
||||
CosmWasmClient,
|
||||
GetSequenceResult,
|
||||
isPostTxFailure,
|
||||
PostTxFailure,
|
||||
PostTxResult,
|
||||
} from "./cosmwasmclient";
|
||||
import { Account, CosmWasmClient, GetSequenceResult } from "./cosmwasmclient";
|
||||
import { findAttribute, Log } from "./logs";
|
||||
import {
|
||||
MsgClearAdmin,
|
||||
|
||||
18
packages/cosmwasm/types/cosmwasmclient.d.ts
vendored
18
packages/cosmwasm/types/cosmwasmclient.d.ts
vendored
@ -5,11 +5,11 @@ import {
|
||||
CosmosSdkTx,
|
||||
IndexedTx,
|
||||
LcdClient,
|
||||
PostTxResult,
|
||||
PubKey,
|
||||
StdTx,
|
||||
} from "@cosmjs/sdk38";
|
||||
import { WasmExtension } from "./lcdapi/wasm";
|
||||
import { Log } from "./logs";
|
||||
import { JsonObject } from "./types";
|
||||
export interface GetSequenceResult {
|
||||
readonly accountNumber: number;
|
||||
@ -23,22 +23,6 @@ export interface Account {
|
||||
readonly accountNumber: number;
|
||||
readonly sequence: number;
|
||||
}
|
||||
export interface PostTxFailure {
|
||||
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
|
||||
readonly transactionHash: string;
|
||||
readonly height: number;
|
||||
readonly code: number;
|
||||
readonly rawLog: string;
|
||||
}
|
||||
export interface PostTxSuccess {
|
||||
readonly logs: readonly Log[];
|
||||
readonly rawLog: string;
|
||||
/** Transaction hash (might be used as transaction ID). Guaranteed to be non-empty upper-case hex */
|
||||
readonly transactionHash: string;
|
||||
readonly data?: Uint8Array;
|
||||
}
|
||||
export declare type PostTxResult = PostTxSuccess | PostTxFailure;
|
||||
export declare function isPostTxFailure(postTxResult: PostTxResult): postTxResult is PostTxFailure;
|
||||
export interface SearchByIdQuery {
|
||||
readonly id: string;
|
||||
}
|
||||
|
||||
1
packages/cosmwasm/types/index.d.ts
vendored
1
packages/cosmwasm/types/index.d.ts
vendored
@ -11,7 +11,6 @@ export {
|
||||
ContractDetails,
|
||||
CosmWasmClient,
|
||||
GetSequenceResult,
|
||||
PostTxResult,
|
||||
SearchByHeightQuery,
|
||||
SearchByIdQuery,
|
||||
SearchBySentFromOrToQuery,
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import { BroadcastMode, Coin, Msg, OfflineSigner, StdFee, StdSignature } from "@cosmjs/sdk38";
|
||||
import { Account, CosmWasmClient, GetSequenceResult, PostTxResult } from "./cosmwasmclient";
|
||||
import { BroadcastMode, Coin, Msg, OfflineSigner, PostTxResult, StdFee, StdSignature } from "@cosmjs/sdk38";
|
||||
import { Account, CosmWasmClient, GetSequenceResult } from "./cosmwasmclient";
|
||||
import { Log } from "./logs";
|
||||
export interface SigningCallback {
|
||||
(signBytes: Uint8Array): Promise<StdSignature>;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user