mirror of
https://github.com/cosmos/cosmjs.git
synced 2025-03-10 21:49:15 +00:00
cosmwasm: Separate CosmWasmClient.searchTx and .getTx
This commit is contained in:
parent
cb125800bd
commit
33c525ff75
@ -6,6 +6,8 @@
|
|||||||
@cosmjs/launchpad instead.
|
@cosmjs/launchpad instead.
|
||||||
- @cosmjs/cosmwasm: Export `JsonObject`, `ChangeAdminResult` and `WasmData`
|
- @cosmjs/cosmwasm: Export `JsonObject`, `ChangeAdminResult` and `WasmData`
|
||||||
types as well as `isValidBuilder` and `parseWasmData` functions.
|
types as well as `isValidBuilder` and `parseWasmData` functions.
|
||||||
|
- @cosmjs/cosmwasm: Add `CosmWasmClient.getTx` method for searching by ID and
|
||||||
|
remove such functionality from `CosmWasmClient.searchTx`.
|
||||||
- @cosmjs/cosmwasm-stargate: Add new package for CosmWasm Stargate support.
|
- @cosmjs/cosmwasm-stargate: Add new package for CosmWasm Stargate support.
|
||||||
- @cosmjs/launchpad: Add `Secp256k1Wallet` to manage a single raw secp256k1
|
- @cosmjs/launchpad: Add `Secp256k1Wallet` to manage a single raw secp256k1
|
||||||
keypair.
|
keypair.
|
||||||
|
@ -44,7 +44,7 @@ interface TestTxExecute {
|
|||||||
readonly tx: WrappedStdTx;
|
readonly tx: WrappedStdTx;
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("CosmWasmClient.searchTx", () => {
|
describe("CosmWasmClient.getTx and .searchTx", () => {
|
||||||
let sendSuccessful: TestTxSend | undefined;
|
let sendSuccessful: TestTxSend | undefined;
|
||||||
let sendSelfSuccessful: TestTxSend | undefined;
|
let sendSelfSuccessful: TestTxSend | undefined;
|
||||||
let sendUnsuccessful: TestTxSend | undefined;
|
let sendUnsuccessful: TestTxSend | undefined;
|
||||||
@ -147,15 +147,14 @@ describe("CosmWasmClient.searchTx", () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("with SearchByIdQuery", () => {
|
describe("getTx", () => {
|
||||||
it("can search successful tx by ID", async () => {
|
it("can get successful tx by ID", async () => {
|
||||||
pendingWithoutLaunchpad();
|
pendingWithoutLaunchpad();
|
||||||
pendingWithoutErc20();
|
pendingWithoutErc20();
|
||||||
assert(sendSuccessful, "value must be set in beforeAll()");
|
assert(sendSuccessful, "value must be set in beforeAll()");
|
||||||
const client = new CosmWasmClient(launchpad.endpoint);
|
const client = new CosmWasmClient(launchpad.endpoint);
|
||||||
const result = await client.searchTx({ id: sendSuccessful.hash });
|
const result = await client.getTx(sendSuccessful.hash);
|
||||||
expect(result.length).toEqual(1);
|
expect(result).toEqual(
|
||||||
expect(result[0]).toEqual(
|
|
||||||
jasmine.objectContaining({
|
jasmine.objectContaining({
|
||||||
height: sendSuccessful.height,
|
height: sendSuccessful.height,
|
||||||
hash: sendSuccessful.hash,
|
hash: sendSuccessful.hash,
|
||||||
@ -165,14 +164,13 @@ describe("CosmWasmClient.searchTx", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can search unsuccessful tx by ID", async () => {
|
it("can get unsuccessful tx by ID", async () => {
|
||||||
pendingWithoutLaunchpad();
|
pendingWithoutLaunchpad();
|
||||||
pendingWithoutErc20();
|
pendingWithoutErc20();
|
||||||
assert(sendUnsuccessful, "value must be set in beforeAll()");
|
assert(sendUnsuccessful, "value must be set in beforeAll()");
|
||||||
const client = new CosmWasmClient(launchpad.endpoint);
|
const client = new CosmWasmClient(launchpad.endpoint);
|
||||||
const result = await client.searchTx({ id: sendUnsuccessful.hash });
|
const result = await client.getTx(sendUnsuccessful.hash);
|
||||||
expect(result.length).toEqual(1);
|
expect(result).toEqual(
|
||||||
expect(result[0]).toEqual(
|
|
||||||
jasmine.objectContaining({
|
jasmine.objectContaining({
|
||||||
height: sendUnsuccessful.height,
|
height: sendUnsuccessful.height,
|
||||||
hash: sendUnsuccessful.hash,
|
hash: sendUnsuccessful.hash,
|
||||||
@ -182,41 +180,13 @@ describe("CosmWasmClient.searchTx", () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("can search by ID (non existent)", async () => {
|
it("can get by ID (non existent)", async () => {
|
||||||
pendingWithoutLaunchpad();
|
pendingWithoutLaunchpad();
|
||||||
pendingWithoutErc20();
|
pendingWithoutErc20();
|
||||||
const client = new CosmWasmClient(launchpad.endpoint);
|
const client = new CosmWasmClient(launchpad.endpoint);
|
||||||
const nonExistentId = "0000000000000000000000000000000000000000000000000000000000000000";
|
const nonExistentId = "0000000000000000000000000000000000000000000000000000000000000000";
|
||||||
const result = await client.searchTx({ id: nonExistentId });
|
const result = await client.getTx(nonExistentId);
|
||||||
expect(result.length).toEqual(0);
|
expect(result).toBeNull();
|
||||||
});
|
|
||||||
|
|
||||||
it("can search by ID and filter by minHeight", async () => {
|
|
||||||
pendingWithoutLaunchpad();
|
|
||||||
pendingWithoutErc20();
|
|
||||||
assert(sendSuccessful);
|
|
||||||
const client = new CosmWasmClient(launchpad.endpoint);
|
|
||||||
const query = { id: sendSuccessful.hash };
|
|
||||||
|
|
||||||
{
|
|
||||||
const result = await client.searchTx(query, { minHeight: 0 });
|
|
||||||
expect(result.length).toEqual(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const result = await client.searchTx(query, { minHeight: sendSuccessful.height - 1 });
|
|
||||||
expect(result.length).toEqual(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const result = await client.searchTx(query, { minHeight: sendSuccessful.height });
|
|
||||||
expect(result.length).toEqual(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
const result = await client.searchTx(query, { minHeight: sendSuccessful.height + 1 });
|
|
||||||
expect(result.length).toEqual(0);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -54,15 +54,7 @@ export interface SearchByTagsQuery {
|
|||||||
readonly tags: ReadonlyArray<{ readonly key: string; readonly value: string }>;
|
readonly tags: ReadonlyArray<{ readonly key: string; readonly value: string }>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type SearchTxQuery =
|
export type SearchTxQuery = SearchByHeightQuery | SearchBySentFromOrToQuery | SearchByTagsQuery;
|
||||||
| SearchByIdQuery
|
|
||||||
| SearchByHeightQuery
|
|
||||||
| SearchBySentFromOrToQuery
|
|
||||||
| SearchByTagsQuery;
|
|
||||||
|
|
||||||
function isSearchByIdQuery(query: SearchTxQuery): query is SearchByIdQuery {
|
|
||||||
return (query as SearchByIdQuery).id !== undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
function isSearchByHeightQuery(query: SearchTxQuery): query is SearchByHeightQuery {
|
function isSearchByHeightQuery(query: SearchTxQuery): query is SearchByHeightQuery {
|
||||||
return (query as SearchByHeightQuery).height !== undefined;
|
return (query as SearchByHeightQuery).height !== undefined;
|
||||||
@ -264,6 +256,11 @@ export class CosmWasmClient {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getTx(id: string): Promise<IndexedTx | null> {
|
||||||
|
const results = await this.txsQuery(`tx.hash=${id}`);
|
||||||
|
return results[0] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
public async searchTx(query: SearchTxQuery, filter: SearchTxFilter = {}): Promise<readonly IndexedTx[]> {
|
public async searchTx(query: SearchTxQuery, filter: SearchTxFilter = {}): Promise<readonly IndexedTx[]> {
|
||||||
const minHeight = filter.minHeight || 0;
|
const minHeight = filter.minHeight || 0;
|
||||||
const maxHeight = filter.maxHeight || Number.MAX_SAFE_INTEGER;
|
const maxHeight = filter.maxHeight || Number.MAX_SAFE_INTEGER;
|
||||||
@ -275,9 +272,7 @@ export class CosmWasmClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let txs: readonly IndexedTx[];
|
let txs: readonly IndexedTx[];
|
||||||
if (isSearchByIdQuery(query)) {
|
if (isSearchByHeightQuery(query)) {
|
||||||
txs = await this.txsQuery(`tx.hash=${query.id}`);
|
|
||||||
} else if (isSearchByHeightQuery(query)) {
|
|
||||||
// optional optimization to avoid network request
|
// optional optimization to avoid network request
|
||||||
if (query.height < minHeight || query.height > maxHeight) {
|
if (query.height < minHeight || query.height > maxHeight) {
|
||||||
txs = [];
|
txs = [];
|
||||||
|
@ -14,7 +14,6 @@ export {
|
|||||||
CosmWasmClient,
|
CosmWasmClient,
|
||||||
GetSequenceResult,
|
GetSequenceResult,
|
||||||
SearchByHeightQuery,
|
SearchByHeightQuery,
|
||||||
SearchByIdQuery,
|
|
||||||
SearchBySentFromOrToQuery,
|
SearchBySentFromOrToQuery,
|
||||||
SearchByTagsQuery,
|
SearchByTagsQuery,
|
||||||
SearchTxQuery,
|
SearchTxQuery,
|
||||||
|
7
packages/cosmwasm/types/cosmwasmclient.d.ts
vendored
7
packages/cosmwasm/types/cosmwasmclient.d.ts
vendored
@ -42,11 +42,7 @@ export interface SearchByTagsQuery {
|
|||||||
readonly value: string;
|
readonly value: string;
|
||||||
}>;
|
}>;
|
||||||
}
|
}
|
||||||
export declare type SearchTxQuery =
|
export declare type SearchTxQuery = SearchByHeightQuery | SearchBySentFromOrToQuery | SearchByTagsQuery;
|
||||||
| SearchByIdQuery
|
|
||||||
| SearchByHeightQuery
|
|
||||||
| SearchBySentFromOrToQuery
|
|
||||||
| SearchByTagsQuery;
|
|
||||||
export interface SearchTxFilter {
|
export interface SearchTxFilter {
|
||||||
readonly minHeight?: number;
|
readonly minHeight?: number;
|
||||||
readonly maxHeight?: number;
|
readonly maxHeight?: number;
|
||||||
@ -148,6 +144,7 @@ export declare class CosmWasmClient {
|
|||||||
* @param height The height of the block. If undefined, the latest height is used.
|
* @param height The height of the block. If undefined, the latest height is used.
|
||||||
*/
|
*/
|
||||||
getBlock(height?: number): Promise<Block>;
|
getBlock(height?: number): Promise<Block>;
|
||||||
|
getTx(id: string): Promise<IndexedTx | null>;
|
||||||
searchTx(query: SearchTxQuery, filter?: SearchTxFilter): Promise<readonly IndexedTx[]>;
|
searchTx(query: SearchTxQuery, filter?: SearchTxFilter): Promise<readonly IndexedTx[]>;
|
||||||
broadcastTx(tx: StdTx): Promise<BroadcastTxResult>;
|
broadcastTx(tx: StdTx): Promise<BroadcastTxResult>;
|
||||||
getCodes(): Promise<readonly Code[]>;
|
getCodes(): Promise<readonly Code[]>;
|
||||||
|
1
packages/cosmwasm/types/index.d.ts
vendored
1
packages/cosmwasm/types/index.d.ts
vendored
@ -13,7 +13,6 @@ export {
|
|||||||
CosmWasmClient,
|
CosmWasmClient,
|
||||||
GetSequenceResult,
|
GetSequenceResult,
|
||||||
SearchByHeightQuery,
|
SearchByHeightQuery,
|
||||||
SearchByIdQuery,
|
|
||||||
SearchBySentFromOrToQuery,
|
SearchBySentFromOrToQuery,
|
||||||
SearchByTagsQuery,
|
SearchByTagsQuery,
|
||||||
SearchTxQuery,
|
SearchTxQuery,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user