Skip to content

Commit

Permalink
refactor(rpc): eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
homura committed Jul 23, 2024
1 parent a0cdddb commit a768a44
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
6 changes: 4 additions & 2 deletions packages/rpc/src/Base/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,11 +483,13 @@ export interface Base {
*/
getForkBlock(
blockHash: CKBComponents.Hash256,
verbosity?: 2n | "0x2"
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
verbosity?: 2 | 2n | "0x2"
): Promise<CKBComponents.BlockView | null>;
getForkBlock(
blockHash: CKBComponents.Hash256,
verbosity: 0n | "0x0"
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
verbosity: 0 | 0n | "0x0"
): Promise<CKBComponents.SerializedBlock | null>;

/**
Expand Down
4 changes: 3 additions & 1 deletion packages/rpc/src/exceptions/formatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ export class OutputsValidatorTypeException extends TypeError {
code = ErrorCode.ParameterInvalid;

constructor() {
super(`Expect outputs validator to be 'well_known_scripts_only' or 'passthrough'`);
super(
`Expect outputs validator to be 'well_known_scripts_only' or 'passthrough'`
);
}
}

Expand Down
14 changes: 9 additions & 5 deletions packages/rpc/src/resultFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable camelcase, @typescript-eslint/no-explicit-any */
import { CKBComponents } from "./types/api";
import { RPC } from "./types/rpc";

Expand Down Expand Up @@ -138,18 +137,24 @@ const toTip = (tip: RPC.Tip): CKBComponents.Tip => ({
blockNumber: tip.block_number,
});

function isBlockWithCycles(value: unknown): value is BlockWithCycles {
return (
!!value && typeof value === "object" && "block" in value && "cycles" in value
);
}

type BlockWithCycles = { block: RPC.Block | string; cycles: string[] };
function toBlock(block: string): string;
function toBlock(block: RPC.Block): CKBComponents.Block;
function toBlock<T extends BlockWithCycles>(block: T): T;
function toBlock(res: string | RPC.Block | BlockWithCycles): any {
function toBlock(res: string | RPC.Block | BlockWithCycles): unknown {
if (!res) return res;
if (typeof res === "string") return res;

if ("block" in res && "cycles" in res) {
if (isBlockWithCycles(res)) {
return {
cycles: res.cycles,
block: toBlock(res.block as any),
block: toBlock(res.block as RPC.Block),
};
}

Expand Down Expand Up @@ -881,4 +886,3 @@ export {
toDeploymentInfo,
toDeploymentsInfo,
};
/* eslint-enable camelcase */
5 changes: 4 additions & 1 deletion packages/rpc/src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ export namespace CKBComponents {
export type Nonce = string;
export type Cycles = string;
export type Size = string;
export type OutputsValidator = "well_known_scripts_only" | "passthrough" | undefined;
export type OutputsValidator =
| "well_known_scripts_only"
| "passthrough"
| undefined;
export type RationalU256 = Record<"denom" | "numer", string>;
export type ProposalWindow = Record<"closest" | "farthest", BlockNumber>;
export type EpochNumberWithFraction = string;
Expand Down

0 comments on commit a768a44

Please sign in to comment.