Skip to content

Commit

Permalink
feat: support ckb-light-client v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PainterPuppets committed Nov 10, 2023
1 parent 71a9a1b commit c24bd32
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
14 changes: 8 additions & 6 deletions packages/e2e-test/tests/light-client-rpc.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,10 @@ test.serial("test setScripts", async (t) => {
t.deepEqual(listeningBob, false);

// partial case
await lightClientRPC.setScripts([
{ script: bob.lockScript, scriptType: "lock", blockNumber: "0x0" },
], 'partial');
await lightClientRPC.setScripts(
[{ script: bob.lockScript, scriptType: "lock", blockNumber: "0x0" }],
"partial"
);

const afterScripts = await lightClientRPC.getScripts();

Expand All @@ -268,9 +269,10 @@ test.serial("test setScripts", async (t) => {
t.deepEqual(afterListeningBob, true);

// delete case
await lightClientRPC.setScripts([
{ script: bob.lockScript, scriptType: "lock", blockNumber: "0x0" },
], 'delete');
await lightClientRPC.setScripts(
[{ script: bob.lockScript, scriptType: "lock", blockNumber: "0x0" }],
"delete"
);

const deletedAfterScripts = await lightClientRPC.getScripts();

Expand Down
15 changes: 13 additions & 2 deletions packages/light-client/src/rpc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { HexString, utils, Header, Block, RemoteNode, LocalNode, TransactionWithStatus } from "@ckb-lumos/base";
import {
HexString,
utils,
Header,
Block,
RemoteNode,
LocalNode,
TransactionWithStatus,
} from "@ckb-lumos/base";
import { CKBComponents } from "@ckb-lumos/rpc/lib/types/api";
import { ParamsFormatter } from "@ckb-lumos/rpc";

Expand Down Expand Up @@ -77,7 +85,10 @@ export class LightClientRPC {
return utils.deepCamel(await request(this.uri, "get_scripts"));
}

async setScripts(scripts: Array<LightClientScript>, command?: SetScriptCommand): Promise<void> {
async setScripts(
scripts: Array<LightClientScript>,
command?: SetScriptCommand
): Promise<void> {
const params = [
scripts.map(({ script, scriptType, blockNumber }) => ({
script: toScript(script),
Expand Down
10 changes: 8 additions & 2 deletions packages/light-client/src/type.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
export type ScriptType = "type" | "lock";

import { HexNumber, Script, Transaction, Header, TransactionWithStatus } from "@ckb-lumos/base";
import {
HexNumber,
Script,
Transaction,
Header,
TransactionWithStatus,
} from "@ckb-lumos/base";

export enum FetchFlag {
Fetched = "fetched",
Expand Down Expand Up @@ -49,7 +55,7 @@ export type GroupedLightClientTransaction = {
cells: Array<[IOType, HexNum]>;
};

export type SetScriptCommand = "all" | "partial" | "delete"
export type SetScriptCommand = "all" | "partial" | "delete";

export type LightClientScript = {
script: Script;
Expand Down

0 comments on commit c24bd32

Please sign in to comment.