Skip to content

Commit

Permalink
fix type conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
Officeyutong committed Dec 3, 2024
1 parent fe09648 commit 9e4169c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion light-client-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"light-client-db-worker": "file:../light-client-db-worker",
"light-client-wasm": "file:../light-client-wasm",
"stream-browserify": "^3.0.0",
"@ckb-ccc/core": "https://gitpkg.vercel.app/Officeyutong/ccc/packages/core?a1b8a02"
"@ckb-ccc/core": "0.1.0-alpha.6"
},
"scripts": {
"build-debug": "webpack --mode=development --stats-children",
Expand Down
12 changes: 6 additions & 6 deletions light-client-js/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ClientFindCellsResponse, ClientFindTransactionsGroupedResponse, ClientFindTransactionsResponse, ClientIndexerSearchKeyLike, ClientIndexerSearchKeyTransactionLike, ClientTransactionResponse } from "@ckb-ccc/core/client";
import { FetchResponse, JsonRpcLocalNode, JsonRpcRemoteNode, JsonRpcScriptStatus, LocalNode, localNodeTo, NetworkFlag, RemoteNode, remoteNodeTo, ScriptStatus, scriptStatusFrom, scriptStatusTo, LightClientWasmSetScriptsCommand, transformFetchResponse, LightClientWasmOrder } from "./types";
import { ClientFindCellsResponse, ClientFindTransactionsGroupedResponse, ClientFindTransactionsResponse, ClientIndexerSearchKeyLike, ClientIndexerSearchKeyTransactionLike, ClientTransactionResponse } from "@ckb-ccc/core";
import { FetchResponse, JsonRpcLocalNode, JsonRpcRemoteNode, JsonRpcScriptStatus, LocalNode, localNodeTo, NetworkFlag, RemoteNode, remoteNodeTo, ScriptStatus, scriptStatusFrom, scriptStatusTo, LightClientWasmSetScriptsCommand, transformFetchResponse, cccOrderToLightClientWasmOrder } from "./types";
import { ClientBlock, ClientBlockHeader, Hex, hexFrom, HexLike, Num, numFrom, NumLike, numToHex, TransactionLike } from "@ckb-ccc/core/barrel";
import { JsonRpcBlockHeader, JsonRpcTransformers } from "@ckb-ccc/core/advancedBarrel";
const DEFAULT_BUFFER_SIZE = 50 * (1 << 20);
Expand Down Expand Up @@ -143,13 +143,13 @@ class LightClient {
*/
async getCells(
searchKey: ClientIndexerSearchKeyLike,
order?: LightClientWasmOrder,
order?: "asc" | "desc",
limit?: NumLike,
afterCursor?: string
): Promise<ClientFindCellsResponse> {
return JsonRpcTransformers.findCellsResponseTo(await this.invokeLightClientCommand("get_cells", [
JsonRpcTransformers.indexerSearchKeyFrom(searchKey),
order ?? LightClientWasmOrder.Asc,
cccOrderToLightClientWasmOrder(order ?? "asc"),
Number(numFrom(numToHex(limit ?? 10))),
afterCursor
]));
Expand All @@ -164,7 +164,7 @@ class LightClient {
*/
async getTransactions(
searchKey: ClientIndexerSearchKeyTransactionLike,
order?: LightClientWasmOrder,
order?: "asc" | "desc",
limit?: NumLike,
afterCursor?: string
): Promise<ClientFindTransactionsResponse | ClientFindTransactionsGroupedResponse> {
Expand All @@ -173,7 +173,7 @@ class LightClient {
"get_transactions",
[
JsonRpcTransformers.indexerSearchKeyTransactionFrom(searchKey),
order ?? LightClientWasmOrder.Asc,
cccOrderToLightClientWasmOrder(order ?? "asc"),
Number(numFrom(numToHex(limit ?? 10))),
afterCursor
]
Expand Down
6 changes: 6 additions & 0 deletions light-client-js/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ export enum LightClientWasmOrder {
Desc = 0,
Asc = 1,
}

export function cccOrderToLightClientWasmOrder(input: "asc" | "desc"): LightClientWasmOrder {
if (input === "asc") return LightClientWasmOrder.Asc;
else return LightClientWasmOrder.Desc;
}

export type {
LightClientFunctionCall,
WorkerInitializeOptions,
Expand Down

0 comments on commit 9e4169c

Please sign in to comment.