From 02d881d34ecc23f8921a75c94e8af4b24439a727 Mon Sep 17 00:00:00 2001 From: homura Date: Mon, 25 Sep 2023 17:23:14 +0800 Subject: [PATCH 1/7] feat(rpc): added reason to txStatus --- packages/base/src/api.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/base/src/api.ts b/packages/base/src/api.ts index 3aee6e998..94cf2dc6b 100644 --- a/packages/base/src/api.ts +++ b/packages/base/src/api.ts @@ -84,9 +84,12 @@ export interface Transaction { witnesses: HexString[]; } +type Status = "pending" | "proposed" | "committed" | "unknown" | "rejected"; + export interface TxStatus { + status: Status; blockHash?: Hash; - status: string; + reason?: string; } export interface TransactionWithStatus { From 1e8389bd4bb41b05389bf0b6a648dba281c01281 Mon Sep 17 00:00:00 2001 From: homura Date: Mon, 25 Sep 2023 18:40:50 +0800 Subject: [PATCH 2/7] feat(rpc): support get_header with verbosity --- packages/rpc/src/Base/index.ts | 14 ++++++++------ packages/rpc/src/resultFormatter.ts | 11 +++++++++-- packages/rpc/src/types/api.ts | 2 +- 3 files changed, 18 insertions(+), 9 deletions(-) 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; From dea17ab7a829ad96af422a19a5fb6ce9ec3eef89 Mon Sep 17 00:00:00 2001 From: homura Date: Mon, 25 Sep 2023 20:47:56 +0800 Subject: [PATCH 3/7] feat(rpc): support withCycle for getBlock --- packages/rpc/src/Base/index.ts | 52 +++++++++++++++++++++++------ packages/rpc/src/resultFormatter.ts | 8 +++-- 2 files changed, 48 insertions(+), 12 deletions(-) diff --git a/packages/rpc/src/Base/index.ts b/packages/rpc/src/Base/index.ts index 2b85c2dc1..d04bad626 100644 --- a/packages/rpc/src/Base/index.ts +++ b/packages/rpc/src/Base/index.ts @@ -21,6 +21,22 @@ export const rpcProperties: RpcPropertes = { // skip subscription }; +/** + * - `0x0`: without verbosity, returns the raw serialized block bytes + * - `0x2`: with verbosity, returns the serialized block JSON object + * - `null`: default value, the same with `0x2` + */ +export type GetBlockVerbosityOptions = "0x0" | "0x2" | null; +export type GetBlockWithCycleOptions = boolean | null; +export type VerbosityBlock = + Verbosity extends "0x0" ? string : CKBComponents.BlockView; +export type BlockResponse< + Verbosity extends GetBlockVerbosityOptions, + WithCycle extends GetBlockWithCycleOptions +> = WithCycle extends true + ? { block: VerbosityBlock; cycles: CKBComponents.UInt64 } + : VerbosityBlock; + // prettier-ignore export interface GetTransaction { (hash: CKBComponents.Hash): Promise; @@ -86,10 +102,19 @@ export interface Base { * @method getBlock * @memberof DefaultRPC * @description rpc to get block by its hash - * @param {string} hash - the block hash of the target block - * @returns {Promise} block object + * @param {string} hash + * @param {string} verbosity + * @param {boolean} withCycle + * @return {Promise} */ - getBlock: (hash: CKBComponents.Hash) => Promise; + getBlock< + V extends GetBlockVerbosityOptions = null, + C extends GetBlockWithCycleOptions = null + >( + hash: CKBComponents.Hash, + verbosity?: V, + withCycle?: C + ): Promise | null>; /** * @method getHeader @@ -191,13 +216,20 @@ export interface Base { /** * @method getBlockByNumber * @memberof DefaultRPC - * @description rpc to get block by its number - * @param {string} number - the block number of the target block - * @returns {Promise} block object - */ - getBlockByNumber: ( - number: CKBComponents.BlockNumber | bigint - ) => Promise; + * @description rpc to get block by its hash + * @param {CKBComponents.BlockNumber | bigint} number + * @param {string} verbosity + * @param {boolean} withCycle + * @return {Promise} + */ + getBlockByNumber< + V extends GetBlockVerbosityOptions = null, + C extends GetBlockWithCycleOptions = null + >( + number: CKBComponents.BlockNumber | bigint, + verbosity?: V, + withCycle?: C + ): Promise | null>; /* Experimental */ diff --git a/packages/rpc/src/resultFormatter.ts b/packages/rpc/src/resultFormatter.ts index b38147647..20efed3e7 100644 --- a/packages/rpc/src/resultFormatter.ts +++ b/packages/rpc/src/resultFormatter.ts @@ -138,7 +138,10 @@ const toTip = (tip: RPC.Tip): CKBComponents.Tip => ({ blockNumber: tip.block_number, }); -const toBlock = (block: RPC.Block): CKBComponents.Block => { +function toBlock(block: string): string; +function toBlock(block: RPC.Block): CKBComponents.Block; +function toBlock(block: string | RPC.Block): CKBComponents.Block | string { + if (typeof block === "string") return block; if (!block) return block; const { header, uncles = [], transactions = [], ...rest } = block; return { @@ -147,7 +150,8 @@ const toBlock = (block: RPC.Block): CKBComponents.Block => { transactions: transactions.map(toTransaction), ...rest, }; -}; +} + const toAlertMessage = ( alertMessage: RPC.AlertMessage ): CKBComponents.AlertMessage => { From 624ef548b9e88c3f63b46b7f09c0640b2c5f1985 Mon Sep 17 00:00:00 2001 From: homura Date: Tue, 26 Sep 2023 13:00:17 +0800 Subject: [PATCH 4/7] fix(rpc): ts-node cannot run with complex type --- packages/rpc/src/Base/index.ts | 46 ++++++++--------------------- packages/rpc/src/resultFormatter.ts | 20 +++++++++---- packages/rpc/src/types/api.ts | 1 + packages/rpc/src/types/rpc.ts | 1 + 4 files changed, 29 insertions(+), 39 deletions(-) diff --git a/packages/rpc/src/Base/index.ts b/packages/rpc/src/Base/index.ts index d04bad626..5e6f3e7ae 100644 --- a/packages/rpc/src/Base/index.ts +++ b/packages/rpc/src/Base/index.ts @@ -21,21 +21,13 @@ export const rpcProperties: RpcPropertes = { // skip subscription }; -/** - * - `0x0`: without verbosity, returns the raw serialized block bytes - * - `0x2`: with verbosity, returns the serialized block JSON object - * - `null`: default value, the same with `0x2` - */ -export type GetBlockVerbosityOptions = "0x0" | "0x2" | null; -export type GetBlockWithCycleOptions = boolean | null; -export type VerbosityBlock = - Verbosity extends "0x0" ? string : CKBComponents.BlockView; -export type BlockResponse< - Verbosity extends GetBlockVerbosityOptions, - WithCycle extends GetBlockWithCycleOptions -> = WithCycle extends true - ? { block: VerbosityBlock; cycles: CKBComponents.UInt64 } - : VerbosityBlock; +// prettier-ignore +interface GetBlock { + (query:Q, verbosity?: '0x2', withCycle?: false): Promise; + (query:Q, verbosity: '0x0', withCycle?: false): Promise; + (query:Q, verbosity: '0x0', withCycle: true): Promise<{ block:string, cycles:CKBComponents.UInt64 }>; + (query:Q, verbosity: '0x2', withCycle: true): Promise<{ block: CKBComponents.BlockView; cycles: CKBComponents.UInt64 }>; +} // prettier-ignore export interface GetTransaction { @@ -105,16 +97,9 @@ export interface Base { * @param {string} hash * @param {string} verbosity * @param {boolean} withCycle - * @return {Promise} + * @return {Promise} */ - getBlock< - V extends GetBlockVerbosityOptions = null, - C extends GetBlockWithCycleOptions = null - >( - hash: CKBComponents.Hash, - verbosity?: V, - withCycle?: C - ): Promise | null>; + getBlock: GetBlock; /** * @method getHeader @@ -220,16 +205,9 @@ export interface Base { * @param {CKBComponents.BlockNumber | bigint} number * @param {string} verbosity * @param {boolean} withCycle - * @return {Promise} - */ - getBlockByNumber< - V extends GetBlockVerbosityOptions = null, - C extends GetBlockWithCycleOptions = null - >( - number: CKBComponents.BlockNumber | bigint, - verbosity?: V, - withCycle?: C - ): Promise | null>; + * @return {Promise} + */ + getBlockByNumber: GetBlock; /* Experimental */ diff --git a/packages/rpc/src/resultFormatter.ts b/packages/rpc/src/resultFormatter.ts index 20efed3e7..7aa189dd1 100644 --- a/packages/rpc/src/resultFormatter.ts +++ b/packages/rpc/src/resultFormatter.ts @@ -138,12 +138,22 @@ const toTip = (tip: RPC.Tip): CKBComponents.Tip => ({ blockNumber: tip.block_number, }); +type BlockWithCycles = { block: RPC.Block | string; cycles: string[] }; function toBlock(block: string): string; function toBlock(block: RPC.Block): CKBComponents.Block; -function toBlock(block: string | RPC.Block): CKBComponents.Block | string { - if (typeof block === "string") return block; - if (!block) return block; - const { header, uncles = [], transactions = [], ...rest } = block; +function toBlock(block: T): T; +function toBlock(res: string | RPC.Block | BlockWithCycles): any { + if (!res) return res; + if (typeof res === "string") return res; + + if ("block" in res && "cycles" in res) { + return { + cycles: res.cycles, + block: toBlock(res.block as any), + }; + } + + const { header, uncles = [], transactions = [], ...rest } = res; return { header: toHeader(header), uncles: uncles.map(toUncleBlock), @@ -151,7 +161,6 @@ function toBlock(block: string | RPC.Block): CKBComponents.Block | string { ...rest, }; } - const toAlertMessage = ( alertMessage: RPC.AlertMessage ): CKBComponents.AlertMessage => { @@ -747,6 +756,7 @@ const toForkBlockResult = ( uncles: result.uncles.map(toUncleBlock), transactions: result.transactions.map(toTransaction), proposals: result.proposals, + extension: result.extension, }; }; diff --git a/packages/rpc/src/types/api.ts b/packages/rpc/src/types/api.ts index f53c4e36c..60385c92f 100644 --- a/packages/rpc/src/types/api.ts +++ b/packages/rpc/src/types/api.ts @@ -303,6 +303,7 @@ export namespace CKBComponents { uncles: UncleBlock[]; transactions: TransactionView[]; proposals: ProposalShortId[]; + extension: Hash; } export type SerializedBlock = api.HexString; diff --git a/packages/rpc/src/types/rpc.ts b/packages/rpc/src/types/rpc.ts index f544f3ed3..3cb2a23f9 100644 --- a/packages/rpc/src/types/rpc.ts +++ b/packages/rpc/src/types/rpc.ts @@ -488,6 +488,7 @@ export namespace RPC { uncles: UncleBlockView[]; transactions: TransactionView[]; proposals: ProposalShortId[]; + extension: Hash256; } export type SerializedBlock = HexString; From e831f100fabb41628a0f27ce8437f33a8e36aa8b Mon Sep 17 00:00:00 2001 From: homura Date: Tue, 26 Sep 2023 17:11:48 +0800 Subject: [PATCH 5/7] chore(examples): support devnet transfer --- examples/pnpm-lock.yaml | 217 ++++++++++------------- examples/secp256k1-transfer/lib.ts | 8 +- examples/secp256k1-transfer/package.json | 6 +- 3 files changed, 107 insertions(+), 124 deletions(-) diff --git a/examples/pnpm-lock.yaml b/examples/pnpm-lock.yaml index ab8458098..6503420a3 100644 --- a/examples/pnpm-lock.yaml +++ b/examples/pnpm-lock.yaml @@ -1,4 +1,4 @@ -lockfileVersion: '6.1' +lockfileVersion: '6.0' settings: autoInstallPeers: true @@ -39,13 +39,13 @@ importers: ../packages/base: dependencies: '@ckb-lumos/bi': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../bi '@ckb-lumos/codec': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../codec '@ckb-lumos/toolkit': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../toolkit '@types/blake2b': specifier: ^2.1.0 @@ -76,19 +76,19 @@ importers: ../packages/ckb-indexer: dependencies: '@ckb-lumos/base': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../base '@ckb-lumos/bi': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../bi '@ckb-lumos/codec': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../codec '@ckb-lumos/rpc': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../rpc '@ckb-lumos/toolkit': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../toolkit cross-fetch: specifier: ^3.1.5 @@ -98,7 +98,7 @@ importers: version: 3.3.0 devDependencies: '@ckb-lumos/testkit': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../testkit '@types/lodash.uniqby': specifier: ^4.7.7 @@ -125,7 +125,7 @@ importers: ../packages/codec: dependencies: '@ckb-lumos/bi': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../bi devDependencies: escape-string-regexp: @@ -138,35 +138,35 @@ importers: ../packages/common-scripts: dependencies: '@ckb-lumos/base': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../base '@ckb-lumos/bi': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../bi '@ckb-lumos/codec': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../codec '@ckb-lumos/config-manager': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../config-manager '@ckb-lumos/helpers': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../helpers '@ckb-lumos/rpc': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../rpc '@ckb-lumos/toolkit': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../toolkit immutable: specifier: ^4.3.0 version: 4.3.0 devDependencies: '@ckb-lumos/debugger': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../debugger '@ckb-lumos/hd': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../hd '@types/keccak': specifier: ^3.0.1 @@ -178,13 +178,13 @@ importers: ../packages/config-manager: dependencies: '@ckb-lumos/base': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../base '@ckb-lumos/bi': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../bi '@ckb-lumos/codec': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../codec '@types/deep-freeze-strict': specifier: ^1.1.0 @@ -196,22 +196,22 @@ importers: ../packages/debugger: dependencies: '@ckb-lumos/base': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../base '@ckb-lumos/bi': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../bi '@ckb-lumos/codec': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../codec '@ckb-lumos/config-manager': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../config-manager '@ckb-lumos/helpers': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../helpers '@ckb-lumos/rpc': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../rpc '@types/download': specifier: ^8.0.1 @@ -233,55 +233,55 @@ importers: version: 3.0.0 devDependencies: '@ckb-lumos/common-scripts': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../common-scripts '@ckb-lumos/experiment-tx-assembler': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../experiment-tx-assembler '@ckb-lumos/hd': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../hd ../packages/e2e-test: dependencies: '@ckb-lumos/base': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../base '@ckb-lumos/bi': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../bi '@ckb-lumos/ckb-indexer': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../ckb-indexer '@ckb-lumos/codec': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../codec '@ckb-lumos/common-scripts': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../common-scripts '@ckb-lumos/config-manager': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../config-manager '@ckb-lumos/hd': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../hd '@ckb-lumos/helpers': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../helpers '@ckb-lumos/light-client': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../light-client '@ckb-lumos/rpc': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../rpc '@ckb-lumos/runner': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../runner '@ckb-lumos/toolkit': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../toolkit '@ckb-lumos/utils': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../utils '@types/kill-port': specifier: ^2.0.0 @@ -294,7 +294,7 @@ importers: version: 2.0.1 devDependencies: '@ckb-lumos/testkit': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../testkit '@types/request': specifier: ^2.48.8 @@ -315,28 +315,28 @@ importers: ../packages/experiment-tx-assembler: dependencies: '@ckb-lumos/base': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../base '@ckb-lumos/bi': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../bi '@ckb-lumos/config-manager': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../config-manager '@ckb-lumos/helpers': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../helpers '@ckb-lumos/toolkit': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../toolkit ../packages/hd: dependencies: '@ckb-lumos/base': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../base '@ckb-lumos/bi': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../bi bn.js: specifier: ^5.1.3 @@ -367,22 +367,22 @@ importers: ../packages/hd-cache: dependencies: '@ckb-lumos/base': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../base '@ckb-lumos/bi': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../bi '@ckb-lumos/ckb-indexer': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../ckb-indexer '@ckb-lumos/config-manager': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../config-manager '@ckb-lumos/hd': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../hd '@ckb-lumos/rpc': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../rpc immutable: specifier: ^4.3.0 @@ -398,19 +398,19 @@ importers: ../packages/helpers: dependencies: '@ckb-lumos/base': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../base '@ckb-lumos/bi': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../bi '@ckb-lumos/codec': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../codec '@ckb-lumos/config-manager': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../config-manager '@ckb-lumos/toolkit': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../toolkit bech32: specifier: ^2.0.0 @@ -422,13 +422,13 @@ importers: ../packages/light-client: dependencies: '@ckb-lumos/base': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../base '@ckb-lumos/ckb-indexer': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../ckb-indexer '@ckb-lumos/rpc': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../rpc cross-fetch: specifier: ^3.1.5 @@ -438,7 +438,7 @@ importers: version: 3.3.0 devDependencies: '@ckb-lumos/testkit': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../testkit '@types/request': specifier: ^2.48.8 @@ -453,31 +453,31 @@ importers: ../packages/lumos: dependencies: '@ckb-lumos/base': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../base '@ckb-lumos/bi': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../bi '@ckb-lumos/ckb-indexer': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../ckb-indexer '@ckb-lumos/common-scripts': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../common-scripts '@ckb-lumos/config-manager': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../config-manager '@ckb-lumos/hd': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../hd '@ckb-lumos/helpers': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../helpers '@ckb-lumos/rpc': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../rpc '@ckb-lumos/toolkit': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../toolkit devDependencies: buffer: @@ -505,10 +505,10 @@ importers: ../packages/molecule: dependencies: '@ckb-lumos/bi': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../bi '@ckb-lumos/codec': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../codec '@types/nearley': specifier: ^2.11.2 @@ -521,7 +521,7 @@ importers: version: 2.20.1 devDependencies: '@ckb-lumos/base': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../base jsbi: specifier: ^4.1.0 @@ -530,10 +530,10 @@ importers: ../packages/rpc: dependencies: '@ckb-lumos/base': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../base '@ckb-lumos/bi': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../bi '@vespaiach/axios-fetch-adapter': specifier: ^0.3.1 @@ -564,7 +564,7 @@ importers: ../packages/runner: dependencies: '@ckb-lumos/utils': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../utils '@ltd/j-toml': specifier: ^1.38.0 @@ -600,14 +600,17 @@ importers: ../packages/testkit: dependencies: '@ckb-lumos/base': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../base '@ckb-lumos/bi': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../bi '@ckb-lumos/codec': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../codec + '@ckb-lumos/rpc': + specifier: 0.21.0-next.0 + version: link:../rpc '@types/body-parser': specifier: ^1.19.1 version: 1.19.1 @@ -659,19 +662,19 @@ importers: ../packages/transaction-manager: dependencies: '@ckb-lumos/base': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../base '@ckb-lumos/ckb-indexer': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../ckb-indexer '@ckb-lumos/codec': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../codec '@ckb-lumos/rpc': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../rpc '@ckb-lumos/toolkit': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../toolkit immutable: specifier: ^4.3.0 @@ -794,31 +797,6 @@ importers: react-dom: specifier: 18.2.0 version: 18.2.0(react@18.2.0) - devDependencies: - buffer: - specifier: ^5.5.0 - version: 5.5.0 - crypto-browserify: - specifier: ^3.12.0 - version: 3.12.0 - events: - specifier: ^3.1.0 - version: 3.3.0 - parcel: - specifier: ^2.9.3 - version: 2.9.3 - path-browserify: - specifier: ^1.0.0 - version: 1.0.0 - process: - specifier: ^0.11.10 - version: 0.11.10 - stream-browserify: - specifier: ^3.0.0 - version: 3.0.0 - string_decoder: - specifier: ^1.3.0 - version: 1.3.0 omni-lock-secp256k1-blake160: dependencies: @@ -906,13 +884,13 @@ importers: secp256k1-transfer: dependencies: '@ckb-lumos/base': - specifier: 0.20.0 + specifier: canary version: link:../../packages/base '@ckb-lumos/codec': - specifier: 0.20.0 + specifier: canary version: link:../../packages/codec '@ckb-lumos/lumos': - specifier: 0.20.0 + specifier: canary version: link:../../packages/lumos '@types/react': specifier: ^18.0.25 @@ -6864,6 +6842,7 @@ packages: /node-gyp-build-optional-packages@5.0.7: resolution: {integrity: sha512-YlCCc6Wffkx0kHkmam79GKvDQ6x+QZkMjFGrIMxgFNILFvGSbCp2fCBC55pGTT9gVaz8Na5CLmxt/urtzRv36w==} hasBin: true + requiresBuild: true dev: true optional: true diff --git a/examples/secp256k1-transfer/lib.ts b/examples/secp256k1-transfer/lib.ts index 2fa6ee107..691ec9fd5 100644 --- a/examples/secp256k1-transfer/lib.ts +++ b/examples/secp256k1-transfer/lib.ts @@ -3,8 +3,9 @@ import { Indexer, helpers, Address, Script, RPC, hd, config, Cell, commons, Witn import { values, blockchain } from "@ckb-lumos/base"; const { ScriptValue } = values; -export const { AGGRON4 } = config.predefined; - +// export let { AGGRON4 } = config.predefined; +let AGGRON4: config.Config = config.predefined.AGGRON4; +// it can be changed to the devnet http://localhost:8114 const CKB_RPC_URL = "https://testnet.ckb.dev/rpc"; const rpc = new RPC(CKB_RPC_URL); const indexer = new Indexer(CKB_RPC_URL); @@ -52,6 +53,9 @@ interface Options { } export async function transfer(options: Options): Promise { + const block = await rpc.getBlockByNumber("0x0"); + AGGRON4 = { PREFIX: "ckt", SCRIPTS: config.generateGenesisScriptConfigs(block) }; + let txSkeleton = helpers.TransactionSkeleton({}); const fromScript = helpers.parseAddress(options.from, { config: AGGRON4 }); const toScript = helpers.parseAddress(options.to, { config: AGGRON4 }); diff --git a/examples/secp256k1-transfer/package.json b/examples/secp256k1-transfer/package.json index 203090c4b..99481d9a0 100644 --- a/examples/secp256k1-transfer/package.json +++ b/examples/secp256k1-transfer/package.json @@ -12,9 +12,9 @@ "author": "", "license": "MIT", "dependencies": { - "@ckb-lumos/base": "0.20.0", - "@ckb-lumos/codec": "0.20.0", - "@ckb-lumos/lumos": "0.20.0", + "@ckb-lumos/base": "canary", + "@ckb-lumos/codec": "canary", + "@ckb-lumos/lumos": "canary", "@types/react": "^18.0.25", "@types/react-dom": "^18.0.9", "react": "^18.2.0", From 3d5ff1e29774b9b7e6060238bd19cc0bde2d98b3 Mon Sep 17 00:00:00 2001 From: homura Date: Tue, 26 Sep 2023 17:19:58 +0800 Subject: [PATCH 6/7] chore: merged with develop --- lerna.json | 2 +- packages/testkit/package.json | 10 +++++----- .../chained-transfer-example/package.json | 18 +++++++++--------- pnpm-lock.yaml | 4 ++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lerna.json b/lerna.json index bd1eb6807..156ae74da 100644 --- a/lerna.json +++ b/lerna.json @@ -5,7 +5,7 @@ ], "npmClient": "pnpm", "useWorkspaces": true, - "version": "0.20.0", + "version": "0.21.0-next.0", "command": { "publish": { "access": "public" diff --git a/packages/testkit/package.json b/packages/testkit/package.json index 2f17b73db..14e39d461 100644 --- a/packages/testkit/package.json +++ b/packages/testkit/package.json @@ -1,6 +1,6 @@ { "name": "@ckb-lumos/testkit", - "version": "0.20.0", + "version": "0.21.0-next.0", "description": "Test toolkit for CKB", "homepage": "https://github.com/ckb-js/lumos#readme", "license": "MIT", @@ -18,10 +18,10 @@ "src" ], "dependencies": { - "@ckb-lumos/base": "0.20.0", - "@ckb-lumos/bi": "0.20.0", - "@ckb-lumos/codec": "0.20.0", - "@ckb-lumos/rpc": "0.20.0", + "@ckb-lumos/base": "0.21.0-next.0", + "@ckb-lumos/bi": "0.21.0-next.0", + "@ckb-lumos/codec": "0.21.0-next.0", + "@ckb-lumos/rpc": "0.21.0-next.0", "@types/body-parser": "^1.19.1", "@types/download": "^8.0.1", "@types/express": "^4.17.17", diff --git a/packages/transaction-manager/examples/chained-transfer-example/package.json b/packages/transaction-manager/examples/chained-transfer-example/package.json index fd3a8a66e..801535e49 100644 --- a/packages/transaction-manager/examples/chained-transfer-example/package.json +++ b/packages/transaction-manager/examples/chained-transfer-example/package.json @@ -15,14 +15,14 @@ "typescript": "^5.0.4" }, "dependencies": { - "@ckb-lumos/base": "0.20.0", - "@ckb-lumos/bi": "0.20.0", - "@ckb-lumos/ckb-indexer": "0.20.0", - "@ckb-lumos/codec": "0.20.0", - "@ckb-lumos/common-scripts": "0.20.0", - "@ckb-lumos/config-manager": "0.20.0", - "@ckb-lumos/hd": "0.20.0", - "@ckb-lumos/helpers": "0.20.0", - "@ckb-lumos/transaction-manager": "0.20.0" + "@ckb-lumos/base": "0.21.0-next.0", + "@ckb-lumos/bi": "0.21.0-next.0", + "@ckb-lumos/ckb-indexer": "0.21.0-next.0", + "@ckb-lumos/codec": "0.21.0-next.0", + "@ckb-lumos/common-scripts": "0.21.0-next.0", + "@ckb-lumos/config-manager": "0.21.0-next.0", + "@ckb-lumos/hd": "0.21.0-next.0", + "@ckb-lumos/helpers": "0.21.0-next.0", + "@ckb-lumos/transaction-manager": "0.21.0-next.0" } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0a303883d..f324315a4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -1,4 +1,4 @@ -lockfileVersion: '6.1' +lockfileVersion: '6.0' settings: autoInstallPeers: true @@ -684,7 +684,7 @@ importers: specifier: 0.21.0-next.0 version: link:../codec '@ckb-lumos/rpc': - specifier: 0.20.0 + specifier: 0.21.0-next.0 version: link:../rpc '@types/body-parser': specifier: ^1.19.1 From cd67b9999bb3ba1dd2a5a3fb446d5f624d8976c9 Mon Sep 17 00:00:00 2001 From: homura Date: Tue, 26 Sep 2023 17:20:57 +0800 Subject: [PATCH 7/7] test(rpc): add test cases about with_cycles --- .../__tests__/formatters/result.fixtures.json | 208 ++++++++++++++++++ 1 file changed, 208 insertions(+) diff --git a/packages/rpc/__tests__/formatters/result.fixtures.json b/packages/rpc/__tests__/formatters/result.fixtures.json index b70d37efc..6e447bf23 100644 --- a/packages/rpc/__tests__/formatters/result.fixtures.json +++ b/packages/rpc/__tests__/formatters/result.fixtures.json @@ -615,6 +615,214 @@ "transactions": [], "uncles": [] } + }, + { + "result": "0x0e02000018000000e8000000ec000000e6010000ea0100000000000000000120691e8ccb8a01000004000000000000000000000400e8030000fa775972159aba682a5bf6e1ad6aa2a989c1ad1af61f130da4a2639a6dbfd782b6ce096ba31efabe2c387cbad8b3a455f8f6d2ade3204bd215291c2df9c88500000000000000000000000000000000000000000000000000000000000000006fd0305920429076102ae14371a11a338c9f6d7b35d022bc3a4cea771d50190f14896308581fa12ed1f84c9bf2862300cbab61de3e0000000099f54b01fbfe06ed97c68a255c08adc3120210350aad1004000000fa00000008000000f20000000c0000006c000000600000001c000000200000002400000028000000580000005c0000000000000000000000000000000100000004000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffff040000000400000086000000080000007a0000007a0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce80114000000c8328aabcd9b9e8e64fbc566c4385c3bdeb219d7210000000000000020302e3131312e3020286161613531353820323032332d30392d3134290000000020000000880b0d848373b0b419e66835223d3bd423c6f0f40a7a3864e10912a7230cc417", + "expected": "0x0e02000018000000e8000000ec000000e6010000ea0100000000000000000120691e8ccb8a01000004000000000000000000000400e8030000fa775972159aba682a5bf6e1ad6aa2a989c1ad1af61f130da4a2639a6dbfd782b6ce096ba31efabe2c387cbad8b3a455f8f6d2ade3204bd215291c2df9c88500000000000000000000000000000000000000000000000000000000000000006fd0305920429076102ae14371a11a338c9f6d7b35d022bc3a4cea771d50190f14896308581fa12ed1f84c9bf2862300cbab61de3e0000000099f54b01fbfe06ed97c68a255c08adc3120210350aad1004000000fa00000008000000f20000000c0000006c000000600000001c000000200000002400000028000000580000005c0000000000000000000000000000000100000004000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffff040000000400000086000000080000007a0000007a0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce80114000000c8328aabcd9b9e8e64fbc566c4385c3bdeb219d7210000000000000020302e3131312e3020286161613531353820323032332d30392d3134290000000020000000880b0d848373b0b419e66835223d3bd423c6f0f40a7a3864e10912a7230cc417" + }, + { + "result": { + "block": { + "extension": "0x7dc094baf449662901d17c12a6b03af16181537d83aff41689d65ebd90131d7b", + "header": { + "compact_target": "0x20010000", + "dao": "0x5c490f74f540a12eb334c0d0f8862300cac44a092c07000000755322c8fbfe06", + "epoch": "0x3e80096000000", + "extra_hash": "0xf6e4abc7a5f61ec64060e2956b972e3d8f450102fa677cb23ee49373c55f14d1", + "hash": "0xbfba299e8942c89f96357b811a795343c0db0f42dd913e22c4fbd74843ef4c5a", + "nonce": "0xa238c12f207efedc2c388a0f2f78fcb", + "number": "0x96", + "parent_hash": "0x03bb5df51f01aafa4aa3010f86909aaa7a90dc0681c264bb3712e5c02ac1935e", + "proposals_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "timestamp": "0x18ad0b37f4e", + "transactions_root": "0x4dbf22caeebbc7cd35e631689b94e6abb4bd10bf2c175b40d187f997b7acd02f", + "version": "0x0" + }, + "proposals": [], + "transactions": [ + { + "cell_deps": [], + "hash": "0x4efec35228be483cdf3d58d73829b129e7b9dc6f85fc715e9267f5adeb2326b9", + "header_deps": [], + "inputs": [ + { + "previous_output": { + "index": "0xffffffff", + "tx_hash": "0x0000000000000000000000000000000000000000000000000000000000000000" + }, + "since": "0x96" + } + ], + "outputs": [ + { + "capacity": "0x2ecbd6b44c", + "lock": { + "args": "0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7", + "code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", + "hash_type": "type" + }, + "type": null + } + ], + "outputs_data": ["0x"], + "version": "0x0", + "witnesses": [ + "0x7a0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce80114000000c8328aabcd9b9e8e64fbc566c4385c3bdeb219d7210000000000000020302e3131312e3020286161613531353820323032332d30392d313429" + ] + }, + { + "cell_deps": [ + { + "dep_type": "dep_group", + "out_point": { + "index": "0x0", + "tx_hash": "0x5ee6d047719f30ba35065a99a13fbbd69dcf94b56273b23e77e8d0068e6e3984" + } + } + ], + "hash": "0x875371e951529d8b246736feea9033d09d3c5f1be4283644b2f49a43d5a5cdcd", + "header_deps": [], + "inputs": [ + { + "previous_output": { + "index": "0x7", + "tx_hash": "0x78420da5665c6bfa57abfcb58f3723223d79d55a3e1c771f6b433c72ac776ec9" + }, + "since": "0x0" + } + ], + "outputs": [ + { + "capacity": "0x174876e800", + "lock": { + "args": "0xed17669081a0a2d854d6cc30d2c1c1912680bbe3", + "code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", + "hash_type": "type" + }, + "type": null + }, + { + "capacity": "0x1bc16d50064f9160", + "lock": { + "args": "0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7", + "code_hash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", + "hash_type": "type" + }, + "type": null + } + ], + "outputs_data": ["0x", "0x"], + "version": "0x0", + "witnesses": [ + "0x5500000010000000550000005500000041000000b0e9ea8ed8a50a12d518c565d57cd9baaa9b5bd64e314b721c7c5140c3663fe25149aab99e63667fca71d96ba2c18c80bcbab2a33f40879e9c8ff47a8ca3894a00" + ] + } + ], + "uncles": [] + }, + "cycles": ["0x18d041"] + }, + "expected": { + "cycles": ["0x18d041"], + "block": { + "header": { + "compactTarget": "0x20010000", + "parentHash": "0x03bb5df51f01aafa4aa3010f86909aaa7a90dc0681c264bb3712e5c02ac1935e", + "transactionsRoot": "0x4dbf22caeebbc7cd35e631689b94e6abb4bd10bf2c175b40d187f997b7acd02f", + "proposalsHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "extraHash": "0xf6e4abc7a5f61ec64060e2956b972e3d8f450102fa677cb23ee49373c55f14d1", + "dao": "0x5c490f74f540a12eb334c0d0f8862300cac44a092c07000000755322c8fbfe06", + "epoch": "0x3e80096000000", + "hash": "0xbfba299e8942c89f96357b811a795343c0db0f42dd913e22c4fbd74843ef4c5a", + "nonce": "0xa238c12f207efedc2c388a0f2f78fcb", + "number": "0x96", + "timestamp": "0x18ad0b37f4e", + "version": "0x0" + }, + "uncles": [], + "transactions": [ + { + "cellDeps": [], + "inputs": [ + { + "previousOutput": { + "txHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "index": "0xffffffff" + }, + "since": "0x96" + } + ], + "outputs": [ + { + "lock": { + "codeHash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", + "hashType": "type", + "args": "0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7" + }, + "type": null, + "capacity": "0x2ecbd6b44c" + } + ], + "outputsData": ["0x"], + "headerDeps": [], + "hash": "0x4efec35228be483cdf3d58d73829b129e7b9dc6f85fc715e9267f5adeb2326b9", + "version": "0x0", + "witnesses": [ + "0x7a0000000c00000055000000490000001000000030000000310000009bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce80114000000c8328aabcd9b9e8e64fbc566c4385c3bdeb219d7210000000000000020302e3131312e3020286161613531353820323032332d30392d313429" + ] + }, + { + "cellDeps": [ + { + "outPoint": { + "txHash": "0x5ee6d047719f30ba35065a99a13fbbd69dcf94b56273b23e77e8d0068e6e3984", + "index": "0x0" + }, + "depType": "depGroup" + } + ], + "inputs": [ + { + "previousOutput": { + "txHash": "0x78420da5665c6bfa57abfcb58f3723223d79d55a3e1c771f6b433c72ac776ec9", + "index": "0x7" + }, + "since": "0x0" + } + ], + "outputs": [ + { + "lock": { + "codeHash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", + "hashType": "type", + "args": "0xed17669081a0a2d854d6cc30d2c1c1912680bbe3" + }, + "type": null, + "capacity": "0x174876e800" + }, + { + "lock": { + "codeHash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", + "hashType": "type", + "args": "0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7" + }, + "type": null, + "capacity": "0x1bc16d50064f9160" + } + ], + "outputsData": ["0x", "0x"], + "headerDeps": [], + "hash": "0x875371e951529d8b246736feea9033d09d3c5f1be4283644b2f49a43d5a5cdcd", + "version": "0x0", + "witnesses": [ + "0x5500000010000000550000005500000041000000b0e9ea8ed8a50a12d518c565d57cd9baaa9b5bd64e314b721c7c5140c3663fe25149aab99e63667fca71d96ba2c18c80bcbab2a33f40879e9c8ff47a8ca3894a00" + ] + } + ], + "extension": "0x7dc094baf449662901d17c12a6b03af16181537d83aff41689d65ebd90131d7b", + "proposals": [] + } + } } ], "toAlertMessage": [