diff --git a/.changeset/great-buses-talk.md b/.changeset/great-buses-talk.md new file mode 100644 index 000000000..cd84cc5e4 --- /dev/null +++ b/.changeset/great-buses-talk.md @@ -0,0 +1,5 @@ +--- +"@ckb-lumos/rpc": minor +--- + +feat: add rpc `test_tx_pool_accept` https://github.com/nervosnetwork/ckb/pull/4433 diff --git a/.changeset/lemon-jobs-walk.md b/.changeset/lemon-jobs-walk.md new file mode 100644 index 000000000..ccfc681f1 --- /dev/null +++ b/.changeset/lemon-jobs-walk.md @@ -0,0 +1,6 @@ +--- +"@ckb-lumos/base": minor +"@ckb-lumos/rpc": minor +--- + +feat: added the `conflicted` field to `get_raw_tx_pool` https://github.com/nervosnetwork/ckb/pull/4339 diff --git a/.changeset/small-cups-divide.md b/.changeset/small-cups-divide.md new file mode 100644 index 000000000..fdc5452ae --- /dev/null +++ b/.changeset/small-cups-divide.md @@ -0,0 +1,5 @@ +--- +"@ckb-lumos/rpc": minor +--- + +fix: added `well_known_scripts_only` to `OutputValidator` diff --git a/packages/base/src/api.ts b/packages/base/src/api.ts index a350afdec..8e90b07bd 100644 --- a/packages/base/src/api.ts +++ b/packages/base/src/api.ts @@ -349,6 +349,7 @@ export interface TxPoolVerbosity { proposed: { [key: string]: TxVerbosity; }; + conflicted: Hash[]; } export type RawTxPool = TxPoolIds | TxPoolVerbosity; diff --git a/packages/rpc/__tests__/ckb-rpc-helpers.js b/packages/rpc/__tests__/ckb-rpc-helpers.js index 85607d63e..78797b8a5 100644 --- a/packages/rpc/__tests__/ckb-rpc-helpers.js +++ b/packages/rpc/__tests__/ckb-rpc-helpers.js @@ -33,7 +33,7 @@ describe('ckb-rpc settings and helpers', () => { }) it('has 47 basic rpc', () => { - expect(Object.values(rpc)).toHaveLength(47) + expect(Object.values(rpc)).toHaveLength(48) }) it('set node url to http://test.localhost:8114', () => { diff --git a/packages/rpc/__tests__/exceptions/fixtures.json b/packages/rpc/__tests__/exceptions/fixtures.json index 75fd2bbc8..72ff53248 100644 --- a/packages/rpc/__tests__/exceptions/fixtures.json +++ b/packages/rpc/__tests__/exceptions/fixtures.json @@ -31,7 +31,7 @@ "params": [], "expected": { "code": 101, - "message": "Expect outputs validator to be 'default' or 'passthrough'" + "message": "Expect outputs validator to be 'well_known_scripts_only' or 'passthrough'" } }, "BigintOrHexStringTypeException": { diff --git a/packages/rpc/__tests__/formatters/params.fixtures.json b/packages/rpc/__tests__/formatters/params.fixtures.json index 09e14a554..bb340a883 100644 --- a/packages/rpc/__tests__/formatters/params.fixtures.json +++ b/packages/rpc/__tests__/formatters/params.fixtures.json @@ -322,8 +322,8 @@ "expected": "undefined" }, { - "param": "default", - "expected": "default" + "param": "well_known_scripts_only", + "expected": "well_known_scripts_only" }, { "param": "passthrough", @@ -335,7 +335,7 @@ }, { "param": "unknown", - "exception": "Expect outputs validator to be 'default' or 'passthrough'" + "exception": "Expect outputs validator to be 'well_known_scripts_only' or 'passthrough'" } ], "toBoolean": [ diff --git a/packages/rpc/src/Base/index.ts b/packages/rpc/src/Base/index.ts index 00283c51e..b5ca6bcab 100644 --- a/packages/rpc/src/Base/index.ts +++ b/packages/rpc/src/Base/index.ts @@ -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; getForkBlock( blockHash: CKBComponents.Hash256, - verbosity: 0n | "0x0" + // eslint-disable-next-line @typescript-eslint/no-magic-numbers + verbosity: 0 | 0n | "0x0" ): Promise; /** @@ -534,6 +536,11 @@ export interface Base { ) => Promise; getDeploymentsInfo: () => Promise; + + testTxPoolAccept: ( + tx: CKBComponents.RawTransaction, + outputsValidator?: CKBComponents.OutputsValidator + ) => Promise; } export class Base { diff --git a/packages/rpc/src/Base/pool.ts b/packages/rpc/src/Base/pool.ts index a5d9a3364..caa8e2f14 100644 --- a/packages/rpc/src/Base/pool.ts +++ b/packages/rpc/src/Base/pool.ts @@ -27,4 +27,12 @@ export default { paramsFormatters: [], resultFormatters: resultFmts.toRawTxPool, }, + + testTxPoolAccept: { + method: "test_tx_pool_accept", + paramsFormatters: [ + paramsFmts.toRawTransaction, + paramsFmts.toOutputsValidator, + ], + }, }; diff --git a/packages/rpc/src/exceptions/formatter.ts b/packages/rpc/src/exceptions/formatter.ts index 35d1499a6..d7bfc42b3 100644 --- a/packages/rpc/src/exceptions/formatter.ts +++ b/packages/rpc/src/exceptions/formatter.ts @@ -25,7 +25,9 @@ export class OutputsValidatorTypeException extends TypeError { code = ErrorCode.ParameterInvalid; constructor() { - super(`Expect outputs validator to be 'default' or 'passthrough'`); + super( + `Expect outputs validator to be 'well_known_scripts_only' or 'passthrough'` + ); } } diff --git a/packages/rpc/src/paramsFormatter.ts b/packages/rpc/src/paramsFormatter.ts index 7fb71111a..8fab50cf3 100644 --- a/packages/rpc/src/paramsFormatter.ts +++ b/packages/rpc/src/paramsFormatter.ts @@ -140,7 +140,7 @@ export const formatter = { toReverseOrder: (reverse = false) => !!reverse, toOutputsValidator: (outputsValidator: CKBComponents.OutputsValidator) => { if (!outputsValidator) return undefined; - const VALIDATORS = ["default", "passthrough"]; + const VALIDATORS = ["well_known_scripts_only", "passthrough"]; if (VALIDATORS.indexOf(outputsValidator) > -1) { return outputsValidator; } diff --git a/packages/rpc/src/resultFormatter.ts b/packages/rpc/src/resultFormatter.ts index 141be2d26..d89c583c6 100644 --- a/packages/rpc/src/resultFormatter.ts +++ b/packages/rpc/src/resultFormatter.ts @@ -1,4 +1,3 @@ -/* eslint-disable camelcase, @typescript-eslint/no-explicit-any */ import { CKBComponents } from "./types/api"; import { RPC } from "./types/rpc"; @@ -138,18 +137,27 @@ 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(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), }; } @@ -643,7 +651,7 @@ const toRawTxPool = (rawTxPool: RPC.RawTxPool): CKBComponents.RawTxPool => { pending[hash] = toTxVerbosity(rawTxPool.pending[hash]); }); - return { proposed, pending }; + return { proposed, pending, conflicted: rawTxPool.conflicted }; }; const toIndexerCell = ( @@ -881,4 +889,3 @@ export { toDeploymentInfo, toDeploymentsInfo, }; -/* eslint-enable camelcase */ diff --git a/packages/rpc/src/types/api.ts b/packages/rpc/src/types/api.ts index 169a8eab8..1e066e14f 100644 --- a/packages/rpc/src/types/api.ts +++ b/packages/rpc/src/types/api.ts @@ -25,7 +25,10 @@ export namespace CKBComponents { export type Nonce = string; export type Cycles = string; export type Size = string; - export type OutputsValidator = "default" | "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; @@ -35,7 +38,7 @@ export namespace CKBComponents { Proposed = "proposed", Committed = "committed", } - + export type Cycle = string; export type ScriptHashType = api.HashType; export type DepType = "code" | "depGroup"; @@ -316,6 +319,12 @@ export namespace CKBComponents { } export type DeploymentPos = api.DeploymentPos; + + export interface EntryCompleted { + cycles: Cycle; + /// Cached tx fee + fee: Capacity; + } export type DeploymentState = api.DeploymentState; export type DeploymentInfo = api.DeploymentInfo; export type DeploymentsInfo = api.DeploymentsInfo; diff --git a/packages/rpc/src/types/rpc.ts b/packages/rpc/src/types/rpc.ts index a940aa54c..2074af2a3 100644 --- a/packages/rpc/src/types/rpc.ts +++ b/packages/rpc/src/types/rpc.ts @@ -330,10 +330,15 @@ export namespace RPC { ancestors_count: Count; } - export type TxPoolVerbosity = Record< - "pending" | "proposed", - Record - >; + export interface TxPoolVerbosity { + pending: { + [key: string]: TxVerbosity; + }; + proposed: { + [key: string]: TxVerbosity; + }; + conflicted: Hash[]; + } export type RawTxPool = TxPoolIds | TxPoolVerbosity; @@ -544,4 +549,9 @@ export namespace RPC { is_initial_block_download: boolean; alerts: Vec; } + + export interface EntryCompleted { + cycles: Cycles; + fee: Capacity; + } }