diff --git a/packages/rpc/src/Base/index.ts b/packages/rpc/src/Base/index.ts index 542b6c51f..2b85c2dc1 100644 --- a/packages/rpc/src/Base/index.ts +++ b/packages/rpc/src/Base/index.ts @@ -29,6 +29,12 @@ export interface GetTransaction { (hash: CKBComponents.Hash, verbosity: "0x2", onlyCommitted?: boolean): Promise; } +// prettier-ignore +export interface GetHeader { + (query: Q, verbosity?: "0x1"): Promise; + (query: Q, verbosity: "0x0"): Promise; +} + export interface Base { /* Chain */ @@ -91,9 +97,7 @@ export interface Base { * @description Returns the information about a block header by hash. * @params {Promise} block hash */ - getHeader: ( - blockHash: CKBComponents.Hash - ) => Promise; + getHeader: GetHeader; /** * @method getHeaderByNumber @@ -101,9 +105,7 @@ export interface Base { * @description Returns the information about a block header by block number * @params {Promise} block number */ - getHeaderByNumber: ( - blockNumber: CKBComponents.BlockNumber | bigint - ) => Promise; + getHeaderByNumber: GetHeader; /** * @method getLiveCell diff --git a/packages/rpc/src/resultFormatter.ts b/packages/rpc/src/resultFormatter.ts index 4e8a8fa7c..b38147647 100644 --- a/packages/rpc/src/resultFormatter.ts +++ b/packages/rpc/src/resultFormatter.ts @@ -24,7 +24,13 @@ const toNullable = const toNumber = (number: RPC.BlockNumber): CKBComponents.BlockNumber => number.toString(); const toHash = (hash: RPC.Hash256): CKBComponents.Hash256 => hash; -const toHeader = (header: RPC.Header): CKBComponents.BlockHeader => { + +function toHeader(header: RPC.Header): CKBComponents.BlockHeader; +function toHeader(header: string): string; +function toHeader( + header: string | RPC.Header +): string | CKBComponents.BlockHeader { + if (typeof header === "string") return header; if (!header) return header; const { compact_target: compactTarget, @@ -42,7 +48,8 @@ const toHeader = (header: RPC.Header): CKBComponents.BlockHeader => { extraHash, ...rest, }; -}; +} + const toScript = (script: RPC.Script): CKBComponents.Script => { if (!script) return script; const { code_hash: codeHash, hash_type: hashType, ...rest } = script; diff --git a/packages/rpc/src/types/api.ts b/packages/rpc/src/types/api.ts index 843d606c9..f53c4e36c 100644 --- a/packages/rpc/src/types/api.ts +++ b/packages/rpc/src/types/api.ts @@ -74,7 +74,7 @@ export namespace CKBComponents { export type Transaction = Required; export type TransactionWithStatus = api.TransactionWithStatus; - export type BlockHeader = api.Header; + export type BlockHeader = T; export type Block = api.Block; export type UncleBlock = api.UncleBlock; export type LiveCell = api.LiveCell;