Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rpc): new rpc get_raw_tx_pool #732

Merged
merged 5 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/great-buses-talk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ckb-lumos/rpc": minor
---

feat: add rpc `test_tx_pool_accept` https://github.com/nervosnetwork/ckb/pull/4433
6 changes: 6 additions & 0 deletions .changeset/lemon-jobs-walk.md
Original file line number Diff line number Diff line change
@@ -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
5 changes: 5 additions & 0 deletions .changeset/small-cups-divide.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@ckb-lumos/rpc": minor
---

fix: added `well_known_scripts_only` to `OutputValidator`
1 change: 1 addition & 0 deletions packages/base/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ export interface TxPoolVerbosity {
proposed: {
[key: string]: TxVerbosity;
};
conflicted: Hash[];
}

export type RawTxPool = TxPoolIds | TxPoolVerbosity;
Expand Down
2 changes: 1 addition & 1 deletion packages/rpc/__tests__/ckb-rpc-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/rpc/__tests__/exceptions/fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
6 changes: 3 additions & 3 deletions packages/rpc/__tests__/formatters/params.fixtures.json
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@
"expected": "undefined"
},
{
"param": "default",
"expected": "default"
"param": "well_known_scripts_only",
"expected": "well_known_scripts_only"
},
{
"param": "passthrough",
Expand All @@ -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": [
Expand Down
11 changes: 9 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 Expand Up @@ -534,6 +536,11 @@ export interface Base {
) => Promise<CKBComponents.FeeRateStatistics>;

getDeploymentsInfo: () => Promise<CKBComponents.DeploymentsInfo>;

testTxPoolAccept: (
tx: CKBComponents.RawTransaction,
outputsValidator?: CKBComponents.OutputsValidator
) => Promise<CKBComponents.EntryCompleted>;
}

export class Base {
Expand Down
8 changes: 8 additions & 0 deletions packages/rpc/src/Base/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,12 @@ export default {
paramsFormatters: [],
resultFormatters: resultFmts.toRawTxPool,
},

testTxPoolAccept: {
method: "test_tx_pool_accept",
paramsFormatters: [
paramsFmts.toRawTransaction,
paramsFmts.toOutputsValidator,
],
},
};
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 'default' or 'passthrough'`);
super(
`Expect outputs validator to be 'well_known_scripts_only' or 'passthrough'`
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/rpc/src/paramsFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
19 changes: 13 additions & 6 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,27 @@
blockNumber: tip.block_number,
});

function isBlockWithCycles(value: unknown): value is BlockWithCycles {
return (
!!value &&

Check warning on line 142 in packages/rpc/src/resultFormatter.ts

View check run for this annotation

Codecov / codecov/patch

packages/rpc/src/resultFormatter.ts#L140-L142

Added lines #L140 - L142 were not covered by tests
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 {

Check warning on line 153 in packages/rpc/src/resultFormatter.ts

View check run for this annotation

Codecov / codecov/patch

packages/rpc/src/resultFormatter.ts#L153

Added line #L153 was not covered by tests
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 @@ -643,7 +651,7 @@
pending[hash] = toTxVerbosity(rawTxPool.pending[hash]);
});

return { proposed, pending };
return { proposed, pending, conflicted: rawTxPool.conflicted };
};

const toIndexerCell = (
Expand Down Expand Up @@ -881,4 +889,3 @@
toDeploymentInfo,
toDeploymentsInfo,
};
/* eslint-enable camelcase */
13 changes: 11 additions & 2 deletions 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 = "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;
Expand All @@ -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";
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 14 additions & 4 deletions packages/rpc/src/types/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,15 @@ export namespace RPC {
ancestors_count: Count;
}

export type TxPoolVerbosity = Record<
"pending" | "proposed",
Record<Hash256, TxVerbosity>
>;
export interface TxPoolVerbosity {
pending: {
[key: string]: TxVerbosity;
};
proposed: {
[key: string]: TxVerbosity;
};
conflicted: Hash[];
}

export type RawTxPool = TxPoolIds | TxPoolVerbosity;

Expand Down Expand Up @@ -544,4 +549,9 @@ export namespace RPC {
is_initial_block_download: boolean;
alerts: Vec<AlertMessage>;
}

export interface EntryCompleted {
cycles: Cycles;
fee: Capacity;
}
}
Loading