From 31eb97eed23ff2feb1a0d8fb48edf5f8bac9885a Mon Sep 17 00:00:00 2001 From: Keith Date: Mon, 23 Sep 2019 10:23:08 +0800 Subject: [PATCH 01/19] feat(type): update the result of getCellsByLockHash method add a field of blockHash in the result of the getCellsByLockHash method and update the type of CellIncludingOutPoint BREAKING CHANGE: update the result of getCellsByLockHash method --- .../ckb-sdk-rpc/__tests__/formatters/result.fixtures.json | 4 ++++ packages/ckb-sdk-rpc/src/resultFormatter.ts | 3 ++- packages/ckb-sdk-rpc/types/CKB_RPC/index.d.ts | 1 + packages/ckb-types/index.d.ts | 1 + 4 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json b/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json index 9bcd8661..ccddaf6a 100644 --- a/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json +++ b/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json @@ -770,6 +770,7 @@ }, { "result": { + "block_hash": "0x03935a4b5e3c03a9c1deb93a39183a9a116c16cff3dc9ab129e847487da0e2b8", "lock": { "code_hash": "0x9e3b3557f11b2b3532ce352bfe8017e9fd11d154c4c7f9b7aaaa1e621b539a08", "args": ["0x7f52f0fccdd1d11391c441adfb174f87bca612b0"], @@ -783,6 +784,7 @@ } }, "expected": { + "blockHash": "0x03935a4b5e3c03a9c1deb93a39183a9a116c16cff3dc9ab129e847487da0e2b8", "lock": { "codeHash": "0x9e3b3557f11b2b3532ce352bfe8017e9fd11d154c4c7f9b7aaaa1e621b539a08", "args": ["0x7f52f0fccdd1d11391c441adfb174f87bca612b0"], @@ -837,6 +839,7 @@ { "result": [ { + "block_hash": "0x03935a4b5e3c03a9c1deb93a39183a9a116c16cff3dc9ab129e847487da0e2b8", "lock": { "codeHash": "0x9e3b3557f11b2b3532ce352bfe8017e9fd11d154c4c7f9b7aaaa1e621b539a08", "args": ["0x7f52f0fccdd1d11391c441adfb174f87bca612b0"], @@ -852,6 +855,7 @@ ], "expected": [ { + "blockHash": "0x03935a4b5e3c03a9c1deb93a39183a9a116c16cff3dc9ab129e847487da0e2b8", "lock": { "codeHash": "0x9e3b3557f11b2b3532ce352bfe8017e9fd11d154c4c7f9b7aaaa1e621b539a08", "args": ["0x7f52f0fccdd1d11391c441adfb174f87bca612b0"], diff --git a/packages/ckb-sdk-rpc/src/resultFormatter.ts b/packages/ckb-sdk-rpc/src/resultFormatter.ts index 87c4b4ad..d9370d62 100644 --- a/packages/ckb-sdk-rpc/src/resultFormatter.ts +++ b/packages/ckb-sdk-rpc/src/resultFormatter.ts @@ -198,8 +198,9 @@ const formatter = { }, toCellIncludingOutPoint: (cell: CKB_RPC.CellIncludingOutPoint) => { if (!cell) return cell - const { lock, out_point, ...rest } = cell + const { lock, block_hash: blockHash, out_point, ...rest } = cell return { + blockHash, lock: formatter.toScript(lock), outPoint: formatter.toOutPoint(out_point), ...rest, diff --git a/packages/ckb-sdk-rpc/types/CKB_RPC/index.d.ts b/packages/ckb-sdk-rpc/types/CKB_RPC/index.d.ts index b39c8e1a..5cff2b44 100644 --- a/packages/ckb-sdk-rpc/types/CKB_RPC/index.d.ts +++ b/packages/ckb-sdk-rpc/types/CKB_RPC/index.d.ts @@ -66,6 +66,7 @@ declare module CKB_RPC { } export interface CellIncludingOutPoint { + block_hash: Hash256 capacity: Capacity lock: Script out_point: OutPoint | null diff --git a/packages/ckb-types/index.d.ts b/packages/ckb-types/index.d.ts index 3ebab294..e975f63d 100644 --- a/packages/ckb-types/index.d.ts +++ b/packages/ckb-types/index.d.ts @@ -265,6 +265,7 @@ declare namespace CKBComponents { */ export interface CellIncludingOutPoint { + blockHash: Hash256 capacity: Capacity lock: Script outPoint: OutPoint | null From 201901d3133d1b7ee60b24a99aadc394dd769ed5 Mon Sep 17 00:00:00 2001 From: Keith Date: Mon, 23 Sep 2019 14:23:41 +0800 Subject: [PATCH 02/19] feat(rpc): update rpc signatures allow user to use the number type in rpc method --- packages/ckb-sdk-rpc/src/defaultRPC.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/ckb-sdk-rpc/src/defaultRPC.ts b/packages/ckb-sdk-rpc/src/defaultRPC.ts index 63bb84e7..08fbf14e 100644 --- a/packages/ckb-sdk-rpc/src/defaultRPC.ts +++ b/packages/ckb-sdk-rpc/src/defaultRPC.ts @@ -172,7 +172,7 @@ export class DefaultRPC { * @param {string} number - the block number of the target block * @returns {Promise} block object */ - public getBlockByNumber!: (number: CKBComponents.BlockNumber) => Promise + public getBlockByNumber!: (number: CKBComponents.BlockNumber | number) => Promise /** * @method getBlockByNumber @@ -199,7 +199,7 @@ export class DefaultRPC { * @param {string} hash - block hash * @return {Promise} block hash */ - public getBlockHash!: (number: CKBComponents.BlockNumber) => Promise + public getBlockHash!: (number: CKBComponents.BlockNumber | number) => Promise /** * @method getTipHeader @@ -221,8 +221,8 @@ export class DefaultRPC { */ public getCellsByLockHash!: ( hash: CKBComponents.Hash256, - from: CKBComponents.BlockNumber, - to: CKBComponents.BlockNumber + from: CKBComponents.BlockNumber | number, + to: CKBComponents.BlockNumber | number ) => Promise /** @@ -317,7 +317,7 @@ export class DefaultRPC { * @description rpc to get the epoch info by its number * @return {Promise} epoch info */ - public getEpochByNumber!: (epoch: string) => Promise + public getEpochByNumber!: (epoch: string | number) => Promise /** * @method dryRunTransaction @@ -352,8 +352,8 @@ export class DefaultRPC { */ public getLiveCellsByLockHash!: ( lockHash: CKBComponents.Hash256, - pageNumber: string, - pageSize: string, + pageNumber: string | number, + pageSize: string | number, reverseOrder?: boolean ) => Promise @@ -378,8 +378,8 @@ export class DefaultRPC { */ public getTransactionsByLockHash!: ( lockHash: CKBComponents.Hash256, - pageNumber: string, - pageSize: string, + pageNumber: string | number, + pageSize: string | number, reverseOrder?: boolean ) => Promise @@ -438,7 +438,7 @@ export class DefaultRPC { * @description Returns the information about a block header by block number * @params {string} block number */ - public getHeaderByNumber!: (blockNumber: CKBComponents.BlockNumber) => Promise + public getHeaderByNumber!: (blockNumber: CKBComponents.BlockNumber | number) => Promise /** * @method getCellbaseOutputCapacityDetails From 18d10d350dbaf4897d19490129b960d8526f7802 Mon Sep 17 00:00:00 2001 From: Keith Date: Mon, 23 Sep 2019 20:08:00 +0800 Subject: [PATCH 03/19] chore: update ts libs --- packages/ckb-sdk-core/tsconfig.json | 1 + tsconfig.json | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/ckb-sdk-core/tsconfig.json b/packages/ckb-sdk-core/tsconfig.json index 637d3154..f1d7d4b5 100644 --- a/packages/ckb-sdk-core/tsconfig.json +++ b/packages/ckb-sdk-core/tsconfig.json @@ -2,6 +2,7 @@ "extends": "../../tsconfig.json", "compilerOptions": { "outDir": "./lib", + "lib": ["es6", "esnext.array"], "types": ["@nervosnetwork/ckb-types", "@nervosnetwork/ckb-sdk-utils"] }, "include": ["./src"] diff --git a/tsconfig.json b/tsconfig.json index 18a53202..c4860156 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,7 +2,7 @@ "extends": "./node_modules/@cryptape/sdk-ts-config/tsconfig.json", "compilerOptions": { "target": "es6", - "lib": ["es6", "dom"], + "lib": ["es6"], "esModuleInterop": true, "moduleResolution": "node", "sourceMap": true From d884efa2c7b766899da766813278df761a656756 Mon Sep 17 00:00:00 2001 From: Keith Date: Mon, 23 Sep 2019 20:10:31 +0800 Subject: [PATCH 04/19] refactor(rpc): update result type of get live cell method --- packages/ckb-sdk-rpc/src/resultFormatter.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/ckb-sdk-rpc/src/resultFormatter.ts b/packages/ckb-sdk-rpc/src/resultFormatter.ts index d9370d62..de340acb 100644 --- a/packages/ckb-sdk-rpc/src/resultFormatter.ts +++ b/packages/ckb-sdk-rpc/src/resultFormatter.ts @@ -184,7 +184,10 @@ const formatter = { ...rest, } }, - toLiveCellWithStatus: (cellWithStatus: { cell: CKB_RPC.LiveCell; status: string }) => { + toLiveCellWithStatus: (cellWithStatus: { + cell: CKB_RPC.LiveCell + status: string + }): { cell: CKBComponents.LiveCell; status: string } => { if (!cellWithStatus) return cellWithStatus const { cell, ...rest } = cellWithStatus return { From 2e5803c331ee1f35e59960d75dc1eea6e940544c Mon Sep 17 00:00:00 2001 From: Keith Date: Mon, 23 Sep 2019 20:28:13 +0800 Subject: [PATCH 05/19] feat(address): enable address to load cells and generate signed transactions --- packages/ckb-sdk-address/package.json | 5 +- packages/ckb-sdk-address/src/index.ts | 218 +++++++++++++++++- packages/ckb-sdk-address/src/loadCells.ts | 74 ++++++ packages/ckb-sdk-address/src/signWitnesses.ts | 28 +++ packages/ckb-sdk-core/src/index.ts | 60 +---- 5 files changed, 330 insertions(+), 55 deletions(-) create mode 100644 packages/ckb-sdk-address/src/loadCells.ts create mode 100644 packages/ckb-sdk-address/src/signWitnesses.ts diff --git a/packages/ckb-sdk-address/package.json b/packages/ckb-sdk-address/package.json index 015ee5f9..05753456 100644 --- a/packages/ckb-sdk-address/package.json +++ b/packages/ckb-sdk-address/package.json @@ -33,7 +33,10 @@ "url": "https://github.com/nervosnetwork/ckb-sdk-js/issues" }, "dependencies": { - "@nervosnetwork/ckb-sdk-utils": "0.21.1", + "@nervosnetwork/ckb-sdk-utils": "0.21.1" + }, + "devDependencies": { + "@nervosnetwork/ckb-sdk-rpc": "0.21.1", "@nervosnetwork/ckb-types": "0.21.1" }, "gitHead": "41659647a9b5376daec6a0b839ad3f3d4bbd4ff2" diff --git a/packages/ckb-sdk-address/src/index.ts b/packages/ckb-sdk-address/src/index.ts index 1081a1f3..4ad117fb 100644 --- a/packages/ckb-sdk-address/src/index.ts +++ b/packages/ckb-sdk-address/src/index.ts @@ -1,14 +1,38 @@ import ECPair from '@nervosnetwork/ckb-sdk-utils/lib/ecpair' -import * as utils from '@nervosnetwork/ckb-sdk-utils' +import RPC from '@nervosnetwork/ckb-sdk-rpc' import { AddressOptions } from '@nervosnetwork/ckb-sdk-utils/lib/address' -const { pubkeyToAddress, blake160, AddressPrefix, AddressType } = utils +import { + blake160, + rawTransactionToHash, + scriptToHash, + pubkeyToAddress, + AddressPrefix, + AddressType, +} from '@nervosnetwork/ckb-sdk-utils' + +import loadCells, { Cell } from './loadCells' +import signWitnesses from './signWitnesses' + +interface Deps { + hashType: CKBComponents.ScriptHashType + codeHash: CKBComponents.Hash256 + outPoint: CKBComponents.OutPoint +} + +const EMPTY_DATA_HASH = '0x0000000000000000000000000000000000000000000000000000000000000000' class Address extends ECPair { + public rpc: RPC | undefined = undefined + + public cells: Cell[] = [] + public value = '' public publicKeyHash = '' + public deps: Deps | undefined = undefined + public constructor( sk: Uint8Array | string, { @@ -25,7 +49,9 @@ class Address extends ECPair { prefix: AddressPrefix.Testnet, type: AddressType.HashIdx, codeHashIndex: '0x00', - } + }, + rpc?: RPC, + deps?: Deps ) { super(sk) this.value = addressAlgorithm(this.publicKey, { @@ -34,6 +60,192 @@ class Address extends ECPair { codeHashIndex, }) this.publicKeyHash = `0x${blake160(this.publicKey as string, 'hex')}` + if (rpc) { + this.rpc = rpc + } + if (deps) { + this.deps = deps + } + } + + public loadCells = async ( + { + start = 0, + end, + STEP = 100, + save = true, + }: { + start?: string | number + end?: string | number + STEP?: number + save?: boolean + } = { + start: 0, + STEP: 100, + save: true, + } + ) => { + if (!this.rpc) { + throw new Error('The rpc is not initialized') + } + + if (!this.deps) { + throw new Error('The deps is not loaded') + } + + const lockScript: CKBComponents.Script = { + codeHash: this.deps.codeHash, + hashType: this.deps.hashType, + args: [this.publicKeyHash], + } + const lockHash = scriptToHash(lockScript) + const cells = await loadCells({ lockHash, start, end, STEP, rpc: this.rpc }) + + if (save) { + this.cells = cells + } + return cells + } + + public generateRawTransaction = async ({ + toPublicKeyHash, + capacity = '600000', + safeMode = true, + cells: unspentCells = this.cells, + }: { + fromPublicKeyHash: string + toPublicKeyHash: string + capacity: bigint | string + safeMode: boolean + cells: Cell[] + }) => { + if (!this.deps) { + throw new Error('The deps is not loaded') + } + const targetCapacity = typeof capacity !== 'bigint' ? BigInt(capacity) : capacity + + const lockScript = { + codeHash: this.deps.codeHash, + hashType: this.deps.hashType, + args: [this.publicKeyHash], + } + + /** + * the new cell for next owner + */ + const toOutput = { + capacity: targetCapacity, + lock: { + hashType: this.deps.hashType, + codeHash: this.deps.codeHash, + args: [toPublicKeyHash], + }, + } + + /** + * the new cell as a change + */ + const changeOutput = { + capacity: BigInt(0), + lock: lockScript, + } + + if (!unspentCells.length) { + await this.loadCells() + } + if (!unspentCells.length) { + throw new Error('No available cells found in the cell map, please make sure the loadCells method is called') + } + const inputs = [] + let inputCapacity = BigInt(0) + /** + * pick inputs + */ + for (let i = 0; i < unspentCells.length; i++) { + const unspentCell = unspentCells[i] + if (!safeMode || unspentCell.dataHash === EMPTY_DATA_HASH) { + inputs.push({ + previousOutput: unspentCell.outPoint, + since: '0x0', + }) + inputCapacity += BigInt(unspentCells[i].capacity) + if (inputCapacity >= targetCapacity) { + break + } + } + } + if (inputCapacity < targetCapacity) { + throw new Error('Input capacity is not enough') + } + if (inputCapacity > targetCapacity) { + changeOutput.capacity = inputCapacity - targetCapacity + } + + /** + * compose the raw transaction which has an empty witnesses + */ + + const outputs = [{ ...toOutput, capacity: `0x${toOutput.capacity.toString(16)}` }] + + if (changeOutput.capacity > BigInt(0)) { + outputs.push({ ...changeOutput, capacity: `0x${changeOutput.capacity.toString(16)}` }) + } + + const outputsData = outputs.map(() => '0x') + + const tx = { + version: '0x0', + cellDeps: [ + { + outPoint: this.deps.outPoint, + depType: 'depGroup', + }, + ], + headerDeps: [], + inputs, + outputs, + witnesses: [ + { + data: [], + }, + ], + outputsData, + } + return tx + } + + public signWitnesses = ({ + transactionHash, + witnesses = [], + }: { + transactionHash: string + witnesses: CKBComponents.Witness[] + }) => { + if (!transactionHash) throw new Error('Transaction hash is required') + const signedWitnesses = signWitnesses({ + transactionHash, + witnesses, + signRecoverable: this.signRecoverable, + }) + return signedWitnesses + } + + public signTransaction = (transaction: CKBComponents.RawTransaction) => { + if (!transaction) throw new Error('Transaction is required') + if (!transaction.witnesses) throw new Error('Witnesses is required') + if (transaction.witnesses.length < transaction.inputs.length) throw new Error('Invalid count of witnesses') + if (!transaction.outputsData) throw new Error('OutputsData is required') + if (transaction.outputsData.length < transaction.outputs.length) throw new Error('Invalid count of outputsData') + + const transactionHash = rawTransactionToHash(transaction) + const signedWitnesses = this.signWitnesses({ + transactionHash, + witnesses: transaction.witnesses, + }) + return { + ...transaction, + witnesses: signedWitnesses, + } } } diff --git a/packages/ckb-sdk-address/src/loadCells.ts b/packages/ckb-sdk-address/src/loadCells.ts new file mode 100644 index 00000000..23988948 --- /dev/null +++ b/packages/ckb-sdk-address/src/loadCells.ts @@ -0,0 +1,74 @@ +import RPC from '@nervosnetwork/ckb-sdk-rpc' + +export interface Cell extends CKBComponents.CellIncludingOutPoint { + status: string + dataHash: string +} + +const loadCells = async ({ + lockHash, + start = 0, + end, + STEP = 100, + rpc, +}: { + lockHash: string + start?: string | number + end?: string | number + STEP?: number + rpc: RPC +}) => { + if (!lockHash) { + throw new Error('lockHash is required to load cells') + } + if (!rpc) { + throw new Error('RPC module is required to load cells') + } + const from = +start + if (!Number.isInteger(from)) { + throw new Error(`${start} cannot be converted into a integer`) + } + const tipBlockNumber = await rpc.getTipBlockNumber() + + let to = end === undefined ? +tipBlockNumber : Math.min(+end, +tipBlockNumber) + + if (!Number.isInteger(to)) { + throw new Error(`${end} cannot be converted into a integer`) + } + + to = Math.min(to, +tipBlockNumber) + + if (to < from) { + throw new Error(`${start} should not be less than ${end}`) + } + + const groups = Array.from( + { + length: Math.ceil((to - from) / STEP), + }, + (_, idx) => [from + idx * STEP + (idx ? 1 : 0), Math.min(from + (idx + 1) * STEP, to)] + ) + + const cells: Cell[] = [] + + /* eslint-disable no-await-in-loop */ + for (let i = 0; i < groups.length; i++) { + const cellDigestsInRange = await rpc.getCellsByLockHash(lockHash, groups[i][0], groups[i][1]) + const cellDetailInRange = await Promise.all( + cellDigestsInRange.map(cellDigest => rpc!.getLiveCell(cellDigest.outPoint!, true)) + ) + cells.push( + ...cellDigestsInRange + .map((digest, idx) => ({ + ...digest, + dataHash: cellDetailInRange[idx].cell.data!.hash, + status: cellDetailInRange[idx].status, + })) + .filter(cell => cell.status === 'live') + ) + } + /* eslint-enable no-await-in-loop */ + + return cells +} +export default loadCells diff --git a/packages/ckb-sdk-address/src/signWitnesses.ts b/packages/ckb-sdk-address/src/signWitnesses.ts new file mode 100644 index 00000000..9d166668 --- /dev/null +++ b/packages/ckb-sdk-address/src/signWitnesses.ts @@ -0,0 +1,28 @@ +import { blake2b, PERSONAL, hexToBytes } from '@nervosnetwork/ckb-sdk-utils' + +const signWitnesses = ({ + transactionHash, + witnesses = [], + signRecoverable, +}: { + transactionHash: string + witnesses: CKBComponents.Witness[] + signRecoverable: Function +}) => { + const signedWitnesses = witnesses.map(witness => { + const oldData = witness.data || [] + const s = blake2b(32, null, null, PERSONAL) + s.update(hexToBytes(transactionHash)) + oldData.forEach(datum => { + s.update(hexToBytes(datum)) + }) + const message = `0x${s.digest('hex')}` + const data = [signRecoverable(message), ...oldData] + return { + data, + } + }) + return signedWitnesses +} + +export default signWitnesses diff --git a/packages/ckb-sdk-core/src/index.ts b/packages/ckb-sdk-core/src/index.ts index 2ae469cb..4af22f43 100644 --- a/packages/ckb-sdk-core/src/index.ts +++ b/packages/ckb-sdk-core/src/index.ts @@ -75,11 +75,15 @@ class Core { codeHashIndex: '0x00', } ) => - new Address(privateKey, { - prefix, - type, - codeHashIndex, - }) + new Address( + privateKey, + { + prefix, + type, + codeHashIndex, + }, + this.rpc + ) public loadSecp256k1Dep = async () => { /** @@ -115,52 +119,6 @@ class Core { } return this.config.secp256k1Dep } - - public signWitnesses = (key: string | Address) => ({ - transactionHash, - witnesses = [], - }: { - transactionHash: string - witnesses: CKBComponents.Witness[] - }) => { - if (!key) throw new Error('Private key or address object is required') - if (!transactionHash) throw new Error('Transaction hash is required') - - const addrObj = typeof key === 'string' ? this.generateAddress(key) : key - const signedWitnesses = witnesses.map(witness => { - const oldData = witness.data || [] - const s = this.utils.blake2b(32, null, null, this.utils.PERSONAL) - s.update(this.utils.hexToBytes(transactionHash)) - oldData.forEach(datum => { - s.update(this.utils.hexToBytes(datum)) - }) - const message = `0x${s.digest('hex')}` - const data = [addrObj.signRecoverable(message), ...oldData] - return { - data, - } - }) - return signedWitnesses - } - - public signTransaction = (key: string | Address) => (transaction: CKBComponents.RawTransaction) => { - if (!key) throw new Error('Private key or address object is required') - if (!transaction) throw new Error('Transaction is required') - if (!transaction.witnesses) throw new Error('Witnesses is required') - if (transaction.witnesses.length < transaction.inputs.length) throw new Error('Invalid count of witnesses') - if (!transaction.outputsData) throw new Error('OutputsData is required') - if (transaction.outputsData.length < transaction.outputs.length) throw new Error('Invalid count of outputsData') - - const transactionHash = this.utils.rawTransactionToHash(transaction) - const signedWitnesses = this.signWitnesses(key)({ - transactionHash, - witnesses: transaction.witnesses, - }) - return { - ...transaction, - witnesses: signedWitnesses, - } - } } export default Core From 2befcffd38240bf126b8920090ad19d4631c470b Mon Sep 17 00:00:00 2001 From: Keith Date: Tue, 24 Sep 2019 14:09:42 +0800 Subject: [PATCH 06/19] feat(cli): deprive this repo of the ckb-cli --- packages/ckb-cli/CHANGELOG.md | 178 ------------------------ packages/ckb-cli/README.md | 70 ---------- packages/ckb-cli/package.json | 48 ------- packages/ckb-cli/src/dashboard/index.ts | 169 ---------------------- packages/ckb-cli/src/index.ts | 89 ------------ packages/ckb-cli/src/rpc/index.ts | 32 ----- packages/ckb-cli/tsconfig.json | 7 - 7 files changed, 593 deletions(-) delete mode 100644 packages/ckb-cli/CHANGELOG.md delete mode 100644 packages/ckb-cli/README.md delete mode 100644 packages/ckb-cli/package.json delete mode 100644 packages/ckb-cli/src/dashboard/index.ts delete mode 100644 packages/ckb-cli/src/index.ts delete mode 100644 packages/ckb-cli/src/rpc/index.ts delete mode 100644 packages/ckb-cli/tsconfig.json diff --git a/packages/ckb-cli/CHANGELOG.md b/packages/ckb-cli/CHANGELOG.md deleted file mode 100644 index ff4a8732..00000000 --- a/packages/ckb-cli/CHANGELOG.md +++ /dev/null @@ -1,178 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.21.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.21.0...v0.21.1) (2019-09-24) - -**Note:** Version bump only for package @nervosnetwork/ckb-cli - - - - - -# [0.21.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.20.0...v0.21.0) (2019-09-21) - -**Note:** Version bump only for package @nervosnetwork/ckb-cli - - - - - -# [0.20.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.19.1...v0.20.0) (2019-09-07) - -**Note:** Version bump only for package @nervosnetwork/ckb-cli - - - - - -## [0.19.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.19.0...v0.19.1) (2019-08-28) - -**Note:** Version bump only for package @nervosnetwork/ckb-cli - - - - - -# [0.19.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.18.0...v0.19.0) (2019-08-27) - - -### Features - -* **type:** block header structure changes ([ce48faf](https://github.com/nervosnetwork/ckb-sdk-js/commit/ce48faf)) -* **type:** Input structure changes ([ba16d1b](https://github.com/nervosnetwork/ckb-sdk-js/commit/ba16d1b)) -* **type:** Transaction structure changes ([df65152](https://github.com/nervosnetwork/ckb-sdk-js/commit/df65152)) - - -### BREAKING CHANGES - -* **type:** block header structure changes -* **type:** Transaction structure changes -* **type:** Input structure chagnes - - - - - -# [0.18.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.17.1...v0.18.0) (2019-08-10) - -**Note:** Version bump only for package @nervosnetwork/ckb-cli - - - - - -## [0.17.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.17.0...v0.17.1) (2019-07-29) - -**Note:** Version bump only for package @nervosnetwork/ckb-cli - - - - - -# [0.17.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.16.0...v0.17.0) (2019-07-27) - -**Note:** Version bump only for package @nervosnetwork/ckb-cli - - - - - -# [0.16.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.15.1...v0.16.0) (2019-07-13) - -**Note:** Version bump only for package @nervosnetwork/ckb-cli - - - - - -## [0.15.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.15.0...v0.15.1) (2019-07-12) - -**Note:** Version bump only for package @nervosnetwork/ckb-cli - - - - - -# [0.15.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.14.0...v0.15.0) (2019-06-29) - - -### Features - -* **cli:** add dashboard mode of ckb-cli ([9accdeb](https://github.com/nervosnetwork/ckb-sdk-js/commit/9accdeb)) - - - - - -# [0.14.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.13.0...v0.14.0) (2019-06-15) - -**Note:** Version bump only for package @nervosnetwork/ckb-cli - - - - - -# [0.13.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.12.0...v0.13.0) (2019-06-01) - -**Note:** Version bump only for package @nervosnetwork/ckb-cli - - - - - -# [0.12.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.11.0...v0.12.0) (2019-05-18) - -**Note:** Version bump only for package @nervosnetwork/ckb-cli - - - - - -# [0.11.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.10.0...v0.11.0) (2019-05-14) - -**Note:** Version bump only for package @nervosnetwork/ckb-cli - - - - - -# [0.10.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.9.0...v0.10.0) (2019-05-06) - -**Note:** Version bump only for package @nervosnetwork/ckb-cli - - - - - -## [0.9.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.9.0...v0.9.1) (2019-04-24) - -**Note:** Version bump only for package @nervosnetwork/ckb-cli - - - - - -# [0.9.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.8.0...v0.9.0) (2019-04-22) - - -### Features - -* **type:** update types of script, cell input, cell output ([ee405bb](https://github.com/nervosnetwork/ckb-sdk-js/commit/ee405bb)) - - -### BREAKING CHANGES - -* **type:** script model updated - - - - - -# [0.8.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.7.0...v0.8.0) (2019-04-08) - - -# [0.7.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.0.1-alpha.3...v0.7.0) (2019-03-25) - -**Note:** Version bump only for package @nervosnetwork/ckb-cli diff --git a/packages/ckb-cli/README.md b/packages/ckb-cli/README.md deleted file mode 100644 index 17975ccc..00000000 --- a/packages/ckb-cli/README.md +++ /dev/null @@ -1,70 +0,0 @@ -# `ckb-cli` - -`@nervosnetwork/ckb-cli` is a command line package based on `@nervosnetwork/ckb-sdk-core`, used to start a Node.js runtime, which has an object named `core` injected. The `core` is the instance of `@nervosnetwork/ckb-sdk-core`. - -This project is still under very rapid development, all contributions are welcome. - -## Installation - -Install the package with [yarn](https://yarnpkg.com/): - -```sh -$ yarn global add @nervosnetwork/ckb-cli -``` - -Or install the package with [npm](https://npmjs.com): - -```sh -$ npm install -g @nervosnetwork/ckb-cli -``` - -## Usage - -### REPL - -```sh -$ ckb-cli i -ckb => connected to -ckb => await core.rpc.getTipBlockNumber() -'6905' -ckb => await core.rpc.getBlockHash('6905') -'0x89de946313839a8a77749b6218d4d7ab3513910c5ed86040e5f38efd41e566d7' -ckb => await core.rpc.getBlock('0x89de946313839a8a77749b6218d4d7ab3513910c5ed86040e5f38efd41e566d7') -{ header: - { parentHash: - '0xc5e11f1e5bcf589a99b94d9eaeffdccb51e3fbdc3c39561dfc49e6d42740f400', - transactionsRoot: - '0x993b28a820cea9297da82654c18e99e6469e08c1a14425724e71ed271d0aac0e', - proposalsHash: - '0x0000000000000000000000000000000000000000000000000000000000000000', - witnessesRoot: - '0x0000000000000000000000000000000000000000000000000000000000000000', - unclesHash: - '0x0000000000000000000000000000000000000000000000000000000000000000', - unclesCount: 0, - difficulty: '0x1000', - epoch: '4', - hash: - '0x89de946313839a8a77749b6218d4d7ab3513910c5ed86040e5f38efd41e566d7', - number: 6905, - nonce: '17168453808346374945', - timestamp: '1557653980138', - version: 0 }, - uncles: [], - transactions: - [ { cellDeps: [], - inputs: [Array], - outputs: [Array], - hash: - '0x993b28a820cea9297da82654c18e99e6469e08c1a14425724e71ed271d0aac0e', - version: 0, - witnesses: [] } ], - proposals: [] } -ckb => -``` - -### Dashboard - -```sh -$ ckb-cli d -``` diff --git a/packages/ckb-cli/package.json b/packages/ckb-cli/package.json deleted file mode 100644 index 6b0d8ff9..00000000 --- a/packages/ckb-cli/package.json +++ /dev/null @@ -1,48 +0,0 @@ -{ - "name": "@nervosnetwork/ckb-cli", - "version": "0.21.1", - "description": "Command line package based on @nervosnetwork/ckb-sdk-core", - "author": "Nervos ", - "homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme", - "license": "MIT", - "main": "lib/index.js", - "preferGlobal": true, - "bin": { - "ckb-cli": "./lib/index.js" - }, - "directories": { - "lib": "lib", - "test": "__tests__" - }, - "files": [ - "lib" - ], - "publishConfig": { - "registry": "http://registry.npmjs.org/", - "access": "public" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/nervosnetwork/ckb-sdk-js.git" - }, - "scripts": { - "tsc": "tsc", - "tsc:watch": "tsc --watch", - "test": "echo \"Error: run tests from root\" && exit 1" - }, - "bugs": { - "url": "https://github.com/nervosnetwork/ckb-sdk-js/issues" - }, - "dependencies": { - "@nervosnetwork/ckb-sdk-core": "0.21.1", - "blessed": "0.1.81", - "blessed-contrib": "4.8.16", - "commander": "2.20.0", - "inquirer": "6.5.2" - }, - "devDependencies": { - "@types/blessed": "0.1.12", - "@types/inquirer": "6.5.0" - }, - "gitHead": "41659647a9b5376daec6a0b839ad3f3d4bbd4ff2" -} diff --git a/packages/ckb-cli/src/dashboard/index.ts b/packages/ckb-cli/src/dashboard/index.ts deleted file mode 100644 index e61bb3ed..00000000 --- a/packages/ckb-cli/src/dashboard/index.ts +++ /dev/null @@ -1,169 +0,0 @@ -import Core from '@nervosnetwork/ckb-sdk-core' -import * as contrib from 'blessed-contrib' -import { screen } from 'blessed' - -const { grid: Grid, table } = contrib - -const MAX_BLOCKS = 50 -const MAX_TRANSACTIONS = 50 -let listener: any - -interface ChainInfo { - url: string - version: string - tipNumber: string -} -type Block = [string, string, number] // [number, hash, tx count] -type Transaction = [string, string, string] // [hash, inputs, outputs] -interface RenderedData { - chainInfo: ChainInfo - blocks: Block[] - transactions: Transaction[] -} - -const data: RenderedData = { - chainInfo: { - url: '', - version: '', - tipNumber: '', - }, - blocks: [], - transactions: [], -} - -const dashboard = (core: Core) => { - const MainScreen = screen({ - smartCSR: true, - cursor: { - artificial: true, - shape: 'underline', - blink: false, - color: 'white', - }, - }) - - MainScreen.key(['escape', 'C-c'], () => process.exit(0)) - - const Layout = new Grid({ - rows: 12, - cols: 12, - screen: MainScreen, - }) - - const chainInfo = Layout.set(0, 0, 2, 12, table, { - label: 'Chain Infomation', - fg: 'white', - columnSpacing: 10, - columnWidth: [30, 60, 30], - interactive: false, - data: { - headers: [], - data: [], - }, - }) - - const updateChainInfo = (info: ChainInfo) => { - chainInfo.setData({ - headers: Object.keys(info).map(() => ''), - data: Object.entries(info), - }) - MainScreen.render() - } - - const blocks = Layout.set(2, 0, 3, 12, table, { - label: 'Block List', - fg: 'white', - columnSpacing: 10, - columnWidth: [15, 66, 10], - interactive: false, - scrollable: true, - data: { - headers: [], - data: [], - }, - }) - - const updateBlocks = (info: Block[]) => { - blocks.setData({ - headers: ['block number', 'hash', 'tx count'], - data: info, - }) - MainScreen.render() - } - - const transactions = Layout.set(5, 0, 7, 12, table, { - label: 'Transaction List', - fg: 'white', - columnSpacing: 10, - columnWidth: [66, 30, 60], - interactive: false, - scrollable: true, - data: { - headers: [], - data: [], - }, - }) - - const updateTransactions = (info: Transaction[]) => { - transactions.setData({ - headers: ['hash', 'inputs', 'outputs'], - data: info, - }) - MainScreen.render() - } - - const fetchAndUpdateChainInfo = async () => { - const [nodeInfo, tipNumber] = await Promise.all([core.rpc.localNodeInfo(), core.rpc.getTipBlockNumber()]) - data.chainInfo = { - url: core.node.url, - version: nodeInfo.version, - tipNumber, - } - updateChainInfo(data.chainInfo) - } - - const fetchAndUpdateBlock = async () => { - const block = await core.rpc.getBlockByNumber(data.chainInfo.tipNumber) - data.blocks = [ - [block.header.number, block.header.hash, block.transactions.length], - ...data.blocks.slice(0, MAX_BLOCKS - 1), - ] - const { transactions: txs } = block - if (txs.length) { - const newTxs: Transaction[] = txs.map((tx): [string, string, string] => [ - tx.hash, - JSON.stringify(tx.inputs.map(input => input.previousOutput)), - JSON.stringify(tx.outputs.map(output => `${output.lock.args[0]}-${output.capacity}`)), - ]) - data.transactions = [...newTxs, ...data.transactions].slice(0, MAX_TRANSACTIONS) - } - updateBlocks(data.blocks) - updateTransactions(data.transactions) - } - - const stop = () => { - clearInterval(listener) - MainScreen.destroy() - } - - const start = () => { - listener = setInterval(async () => { - try { - const currentTipNumber = data.chainInfo.tipNumber - await fetchAndUpdateChainInfo() - if (+data.chainInfo.tipNumber > +currentTipNumber) { - fetchAndUpdateBlock() - } - } catch (err) { - stop() - console.error(err.message) - } - }, 500) - } - return { - start, - stop, - } -} - -export default dashboard diff --git a/packages/ckb-cli/src/index.ts b/packages/ckb-cli/src/index.ts deleted file mode 100644 index bd6e6edb..00000000 --- a/packages/ckb-cli/src/index.ts +++ /dev/null @@ -1,89 +0,0 @@ -#!/usr/bin/env node --experimental-repl-await - -import repl from 'repl' -import Core from '@nervosnetwork/ckb-sdk-core' -import commander from 'commander' -import { prompt } from 'inquirer' -import dashboard from './dashboard' - -const RPC_URL = 'http://localhost:8114' - -commander.version('0.0.1').description('Cli of CKB') -commander.command('') - -commander.version('0.0.1', '-v, --version') - -commander - .command('link [remote]') // No need of specifying arguments here - .alias('l') - .description('Start a link to the remote address') - .action(async (remote = RPC_URL) => { - const core = new Core(remote) - console.info(`connected to ${remote}`) - const { action } = await prompt({ - type: 'rawlist', - name: 'action', - choices: ['rpc', 'watch'], - }) - console.info(action) - if (action === 'rpc') { - const { rpcMethod } = await prompt({ - type: 'rawlist', - name: 'rpcMethod', - message: 'which kind of rpc to send', - choices: [ - 'getBlock', - 'getTransaction', - 'getBlockHash', - 'getTipHeader', - 'getCellsByLockHash', - 'getCurrentCell', - 'getTipBlockNumber', - 'sendTransaction', - ], - }) - console.info(rpcMethod) - /* eslint-disable indent */ - switch (rpcMethod) { - case 'getTipHeader': - case 'getTipBlockNumber': { - return (core.rpc as any)[rpcMethod]().then(console.info) - } - default: { - return null - } - } - /* eslint-enable indent */ - } - return null - }) - -commander - .command('interact [remote]') - .alias('i') - .description('user interaface') - .action(async (remote = RPC_URL) => { - const replServer = repl.start({ - prompt: 'ckb => ', - }) - console.info(`connected to ${remote}`) - const core = new Core(remote) - replServer.context.core = core - replServer.context.rpc = {} - replServer.context.dashboard = () => dashboard(core) - Object.keys(core.rpc).forEach(key => { - replServer.context.rpc[key] = (core.rpc as any)[key] - }) - }) - -commander - .command('dashboard [remote]') - .alias('d') - .description('dashboard') - .action(async (remote = RPC_URL) => { - console.info('boosting the dashboard') - const core = new Core(remote) - dashboard(core).start() - }) - -commander.parse(process.argv) diff --git a/packages/ckb-cli/src/rpc/index.ts b/packages/ckb-cli/src/rpc/index.ts deleted file mode 100644 index 74922cd4..00000000 --- a/packages/ckb-cli/src/rpc/index.ts +++ /dev/null @@ -1,32 +0,0 @@ -interface Question { - type: string - name: string - message: string - choices?: string[] -} - -export enum RPCMethods { - GetBlock = 'getBlock', - GetTransaction = 'getTransaction', - GetBlockHash = 'getBlockHash', - GetTipHeader = 'getTipHeader', - GetCellsByLockHash = 'getCellsByLockHash', - GetCurrentCell = 'getCurrentCell', - GetTipBlockNumber = 'getTipBlockNumber', - SendTransaction = 'sendTransaction', -} - -const choices = Object.keys(RPCMethods) - .filter(k => typeof RPCMethods[k as keyof typeof RPCMethods] === 'number') - .map(k => RPCMethods[k as keyof typeof RPCMethods]) - -const questions: Question[] = [ - { - type: 'rawlist', - name: 'rpcMethod', - message: 'What kind of rpc to send', - choices, - }, -] - -export default questions diff --git a/packages/ckb-cli/tsconfig.json b/packages/ckb-cli/tsconfig.json deleted file mode 100644 index da67782f..00000000 --- a/packages/ckb-cli/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "outDir": "./lib" - }, - "include": ["./src"] -} From 10dd017587ed8f747c701ec4cf5a989b20dc5a28 Mon Sep 17 00:00:00 2001 From: Keith Date: Tue, 24 Sep 2019 20:52:49 +0800 Subject: [PATCH 07/19] feat(core): move the address module into the core module 1. move the address module into the core module, 2. add loadCells and generateRawTransaction method in the core module BREAKING CHANGE: move the address module into the core module --- README.md | 19 - packages/ckb-sdk-address/CHANGELOG.md | 142 ----- packages/ckb-sdk-address/README.md | 69 --- packages/ckb-sdk-address/package.json | 43 -- packages/ckb-sdk-address/src/index.ts | 252 --------- packages/ckb-sdk-address/src/signWitnesses.ts | 28 - packages/ckb-sdk-address/tsconfig.json | 8 - .../ckb-sdk-core/__mocks__/data/cell.json | 13 + .../__mocks__/data/genesisBlock.json | 202 +++++++ .../ckb-sdk-core/__mocks__/data/liveCell.json | 24 + packages/ckb-sdk-core/__mocks__/rpc.js | 17 + .../__tests__/address}/fixtures.json | 0 .../__tests__/address}/index.test.js | 6 +- packages/ckb-sdk-core/__tests__/fixtures.json | 252 +++++++++ .../generateRawTransaction/fixtures.json | 500 ++++++++++++++++++ .../generateRawTransaction/index.test.js | 26 + packages/ckb-sdk-core/__tests__/index.test.js | 124 ++++- .../__tests__/loadCells/fixtures.json | 123 +++++ .../__tests__/loadCells/index.test.js | 42 ++ packages/ckb-sdk-core/package.json | 1 - packages/ckb-sdk-core/src/address.ts | 38 ++ .../src/generateRawTransaction.ts | 117 ++++ packages/ckb-sdk-core/src/index.ts | 160 +++++- .../src/loadCells.ts | 40 +- packages/ckb-sdk-core/tsconfig.json | 2 +- packages/ckb-sdk-core/types/global.d.ts | 10 + packages/ckb-sdk-utils/src/address/index.ts | 4 + 27 files changed, 1639 insertions(+), 623 deletions(-) delete mode 100644 packages/ckb-sdk-address/CHANGELOG.md delete mode 100644 packages/ckb-sdk-address/README.md delete mode 100644 packages/ckb-sdk-address/package.json delete mode 100644 packages/ckb-sdk-address/src/index.ts delete mode 100644 packages/ckb-sdk-address/src/signWitnesses.ts delete mode 100644 packages/ckb-sdk-address/tsconfig.json create mode 100644 packages/ckb-sdk-core/__mocks__/data/cell.json create mode 100644 packages/ckb-sdk-core/__mocks__/data/genesisBlock.json create mode 100644 packages/ckb-sdk-core/__mocks__/data/liveCell.json create mode 100644 packages/ckb-sdk-core/__mocks__/rpc.js rename packages/{ckb-sdk-address/__tests__ => ckb-sdk-core/__tests__/address}/fixtures.json (100%) rename packages/{ckb-sdk-address/__tests__ => ckb-sdk-core/__tests__/address}/index.test.js (81%) create mode 100644 packages/ckb-sdk-core/__tests__/generateRawTransaction/fixtures.json create mode 100644 packages/ckb-sdk-core/__tests__/generateRawTransaction/index.test.js create mode 100644 packages/ckb-sdk-core/__tests__/loadCells/fixtures.json create mode 100644 packages/ckb-sdk-core/__tests__/loadCells/index.test.js create mode 100644 packages/ckb-sdk-core/src/address.ts create mode 100644 packages/ckb-sdk-core/src/generateRawTransaction.ts rename packages/{ckb-sdk-address => ckb-sdk-core}/src/loadCells.ts (58%) create mode 100644 packages/ckb-sdk-core/types/global.d.ts diff --git a/README.md b/README.md index c021d9a8..e3b97825 100644 --- a/README.md +++ b/README.md @@ -75,25 +75,6 @@ $ yarn add @nervosnetwork/ckb-sdk-core # install the SDK into your project This SDK includes several modules: -
- - Address Code - -
- -Used to create an address object, whose value is the address we are going to use. - -Default `address algorithm` is the `pubkeyToAddress` in utils module, which generates address in bech32 format. - -Default rule to generate the address from a public key is: - -- Blake160(public key): blake2b(public key) then trauncate it for fist 20 bytes. -- Specify options used: Address Type, Address Bin Index, Prefix. The options will be explained in an RFC. -- Bech32 the blake160ed public key with specified options: bech32Address(blake160Pubkey, {prefix, type, binIndex}) - -
-
-
RPC Code diff --git a/packages/ckb-sdk-address/CHANGELOG.md b/packages/ckb-sdk-address/CHANGELOG.md deleted file mode 100644 index db5079e9..00000000 --- a/packages/ckb-sdk-address/CHANGELOG.md +++ /dev/null @@ -1,142 +0,0 @@ -# Changelog - -All notable changes to this project will be documented in this file. -See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. - -## [0.21.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.21.0...v0.21.1) (2019-09-24) - -**Note:** Version bump only for package @nervosnetwork/ckb-sdk-address - - - - - -# [0.21.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.20.0...v0.21.0) (2019-09-21) - - -### Code Refactoring - -* **address** rename public key identifier to publicKeyHash ([b33c096](https://github.com/nervosnetwork/ckb-sdk-js/commit/b33c096)) - - -### BREAKING CHANGES - -* **address** rename public key identifier to publicKeyHash - - - - - -# [0.20.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.19.1...v0.20.0) (2019-09-07) - -**Note:** Version bump only for package @nervosnetwork/ckb-sdk-address - - - - - -## [0.19.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.19.0...v0.19.1) (2019-08-28) - -**Note:** Version bump only for package @nervosnetwork/ckb-sdk-address - - - - - -# [0.19.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.18.0...v0.19.0) (2019-08-27) - -**Note:** Version bump only for package @nervosnetwork/ckb-sdk-address - - - - - -# [0.18.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.17.1...v0.18.0) (2019-08-10) - -**Note:** Version bump only for package @nervosnetwork/ckb-sdk-address - - - - - -## [0.17.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.17.0...v0.17.1) (2019-07-29) - -**Note:** Version bump only for package @nervosnetwork/ckb-sdk-address - - - - - -# [0.17.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.16.0...v0.17.0) (2019-07-27) - - -### Features - -* **utils:** update the address format ([74a5ad8](https://github.com/nervosnetwork/ckb-sdk-js/commit/74a5ad8)) - - -### BREAKING CHANGES - -* **utils:** update the address format - - - - - -# [0.16.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.15.1...v0.16.0) (2019-07-13) - -**Note:** Version bump only for package @nervosnetwork/ckb-sdk-address - - - - - -## [0.15.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.15.0...v0.15.1) (2019-07-12) - -**Note:** Version bump only for package @nervosnetwork/ckb-sdk-address - - - - - -# [0.15.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.14.0...v0.15.0) (2019-06-29) - -**Note:** Version bump only for package @nervosnetwork/ckb-sdk-address - - - - - -# [0.14.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.13.0...v0.14.0) (2019-06-15) - -**Note:** Version bump only for package @nervosnetwork/ckb-sdk-address - - - - - -# [0.13.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.12.0...v0.13.0) (2019-06-01) - - -### Features - -* **address:** add blake160-ed public key as address identifier ([b7bee1c](https://github.com/nervosnetwork/ckb-sdk-js/commit/b7bee1c)) - - - - - -# [0.12.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.11.0...v0.12.0) (2019-05-18) - -**Note:** Version bump only for package @nervosnetwork/ckb-sdk-address - - - - - -# [0.11.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.10.0...v0.11.0) (2019-05-14) - - -### Features - -* **feat:** add address module ([c5b532](https://github.com/nervosnetwork/ckb-sdk-js/commit/c5b532)) diff --git a/packages/ckb-sdk-address/README.md b/packages/ckb-sdk-address/README.md deleted file mode 100644 index b57b0709..00000000 --- a/packages/ckb-sdk-address/README.md +++ /dev/null @@ -1,69 +0,0 @@ -# `ckb-sdk-address` - -`@nervosnetwork/ckb-sdk-address` is the address module of `@nervosnetwork/ckb-sdk-core`. - -Its current responsibility is just to generate an address object, the algorithm will be introduced in an RFC in the near future. - -In a nutshell, the address format is similar to [BIP-0173](https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki) - -1. this module takes a private key and then calculates the corresponding public key with secp256k1 algorithm; -2. use blake160 algorithm to hash the public key and get a blake160-ed string; -3. bech32 the blake160-ed string with three options(prefix, type, binIndex) to get a bech32-formatted address. - -Detailed methods could be found in `@nervosnetwork/ckb-sdk-utils` - -## Address configuration - -> The meanings of the configuration will be explained in the RFC. - -1. Prefix - - - 'ckb' for the mainnet - - 'ckt' for the testnet - -2. type - - - '0x00' for wallet build-in binary_hash ref id - - '0x01' for binary_hash - -3. binIndex - - - 'P2PH' - -## Address Value - -The `address.value` is the address string generated by the private key and address configuration you passed to the constructor. - -## Address identifier - -The `address.identifier` represents the identity of the address object. It derives from the public key, and used to generate the human readable address value. - -`address.identifier` is calculated by `blake160(publicKey)`, which picks the first 20 bytes of `blake2b(publicKey)`. - -And `address.identifier` is used to generate `address.value` in `bech32(address.identifier, ...AddressConfiguration)`. - -## Installation - -Install the package with [yarn](https://yarnpkg.com/): - -```sh -$ yarn add @nervosnetwork/ckb-sdk-address -``` - -Or install the package with [npm](https://npmjs.com): - -```sh -$ npm install --save @nervosnetwork/ckb-sdk-address -``` - -## Usage - -```javascript -const Address = require('@nervosnetwork/ckb-sdk-address').default - -const privateKey = 'your private key' - -const address = new Address(privateKey, { prefix: 'ckt' }) -console.log(address.value) -console.log(address.identifier) -``` diff --git a/packages/ckb-sdk-address/package.json b/packages/ckb-sdk-address/package.json deleted file mode 100644 index 05753456..00000000 --- a/packages/ckb-sdk-address/package.json +++ /dev/null @@ -1,43 +0,0 @@ -{ - "name": "@nervosnetwork/ckb-sdk-address", - "version": "0.21.1", - "description": "Address module of @nervosnetwork/ckb-sdk-core", - "keywords": [ - "CKB", - "address" - ], - "author": "Nervos ", - "homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme", - "license": "MIT", - "main": "lib/index.js", - "directories": { - "lib": "lib", - "test": "__tests__" - }, - "files": [ - "lib" - ], - "publishConfig": { - "registry": "http://registry.npmjs.org/", - "access": "public" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/nervosnetwork/ckb-sdk-js.git" - }, - "scripts": { - "tsc": "tsc", - "test": "../../node_modules/.bin/jest" - }, - "bugs": { - "url": "https://github.com/nervosnetwork/ckb-sdk-js/issues" - }, - "dependencies": { - "@nervosnetwork/ckb-sdk-utils": "0.21.1" - }, - "devDependencies": { - "@nervosnetwork/ckb-sdk-rpc": "0.21.1", - "@nervosnetwork/ckb-types": "0.21.1" - }, - "gitHead": "41659647a9b5376daec6a0b839ad3f3d4bbd4ff2" -} diff --git a/packages/ckb-sdk-address/src/index.ts b/packages/ckb-sdk-address/src/index.ts deleted file mode 100644 index 4ad117fb..00000000 --- a/packages/ckb-sdk-address/src/index.ts +++ /dev/null @@ -1,252 +0,0 @@ -import ECPair from '@nervosnetwork/ckb-sdk-utils/lib/ecpair' -import RPC from '@nervosnetwork/ckb-sdk-rpc' -import { AddressOptions } from '@nervosnetwork/ckb-sdk-utils/lib/address' - -import { - blake160, - rawTransactionToHash, - scriptToHash, - pubkeyToAddress, - AddressPrefix, - AddressType, -} from '@nervosnetwork/ckb-sdk-utils' - -import loadCells, { Cell } from './loadCells' -import signWitnesses from './signWitnesses' - -interface Deps { - hashType: CKBComponents.ScriptHashType - codeHash: CKBComponents.Hash256 - outPoint: CKBComponents.OutPoint -} - -const EMPTY_DATA_HASH = '0x0000000000000000000000000000000000000000000000000000000000000000' - -class Address extends ECPair { - public rpc: RPC | undefined = undefined - - public cells: Cell[] = [] - - public value = '' - - public publicKeyHash = '' - - public deps: Deps | undefined = undefined - - public constructor( - sk: Uint8Array | string, - { - addressAlgorithm = pubkeyToAddress, - prefix = AddressPrefix.Testnet, - type = AddressType.HashIdx, - codeHashIndex = '0x00', - }: Partial< - { - addressAlgorithm: Function - } & AddressOptions - > = { - addressAlgorithm: pubkeyToAddress, - prefix: AddressPrefix.Testnet, - type: AddressType.HashIdx, - codeHashIndex: '0x00', - }, - rpc?: RPC, - deps?: Deps - ) { - super(sk) - this.value = addressAlgorithm(this.publicKey, { - prefix, - type, - codeHashIndex, - }) - this.publicKeyHash = `0x${blake160(this.publicKey as string, 'hex')}` - if (rpc) { - this.rpc = rpc - } - if (deps) { - this.deps = deps - } - } - - public loadCells = async ( - { - start = 0, - end, - STEP = 100, - save = true, - }: { - start?: string | number - end?: string | number - STEP?: number - save?: boolean - } = { - start: 0, - STEP: 100, - save: true, - } - ) => { - if (!this.rpc) { - throw new Error('The rpc is not initialized') - } - - if (!this.deps) { - throw new Error('The deps is not loaded') - } - - const lockScript: CKBComponents.Script = { - codeHash: this.deps.codeHash, - hashType: this.deps.hashType, - args: [this.publicKeyHash], - } - const lockHash = scriptToHash(lockScript) - const cells = await loadCells({ lockHash, start, end, STEP, rpc: this.rpc }) - - if (save) { - this.cells = cells - } - return cells - } - - public generateRawTransaction = async ({ - toPublicKeyHash, - capacity = '600000', - safeMode = true, - cells: unspentCells = this.cells, - }: { - fromPublicKeyHash: string - toPublicKeyHash: string - capacity: bigint | string - safeMode: boolean - cells: Cell[] - }) => { - if (!this.deps) { - throw new Error('The deps is not loaded') - } - const targetCapacity = typeof capacity !== 'bigint' ? BigInt(capacity) : capacity - - const lockScript = { - codeHash: this.deps.codeHash, - hashType: this.deps.hashType, - args: [this.publicKeyHash], - } - - /** - * the new cell for next owner - */ - const toOutput = { - capacity: targetCapacity, - lock: { - hashType: this.deps.hashType, - codeHash: this.deps.codeHash, - args: [toPublicKeyHash], - }, - } - - /** - * the new cell as a change - */ - const changeOutput = { - capacity: BigInt(0), - lock: lockScript, - } - - if (!unspentCells.length) { - await this.loadCells() - } - if (!unspentCells.length) { - throw new Error('No available cells found in the cell map, please make sure the loadCells method is called') - } - const inputs = [] - let inputCapacity = BigInt(0) - /** - * pick inputs - */ - for (let i = 0; i < unspentCells.length; i++) { - const unspentCell = unspentCells[i] - if (!safeMode || unspentCell.dataHash === EMPTY_DATA_HASH) { - inputs.push({ - previousOutput: unspentCell.outPoint, - since: '0x0', - }) - inputCapacity += BigInt(unspentCells[i].capacity) - if (inputCapacity >= targetCapacity) { - break - } - } - } - if (inputCapacity < targetCapacity) { - throw new Error('Input capacity is not enough') - } - if (inputCapacity > targetCapacity) { - changeOutput.capacity = inputCapacity - targetCapacity - } - - /** - * compose the raw transaction which has an empty witnesses - */ - - const outputs = [{ ...toOutput, capacity: `0x${toOutput.capacity.toString(16)}` }] - - if (changeOutput.capacity > BigInt(0)) { - outputs.push({ ...changeOutput, capacity: `0x${changeOutput.capacity.toString(16)}` }) - } - - const outputsData = outputs.map(() => '0x') - - const tx = { - version: '0x0', - cellDeps: [ - { - outPoint: this.deps.outPoint, - depType: 'depGroup', - }, - ], - headerDeps: [], - inputs, - outputs, - witnesses: [ - { - data: [], - }, - ], - outputsData, - } - return tx - } - - public signWitnesses = ({ - transactionHash, - witnesses = [], - }: { - transactionHash: string - witnesses: CKBComponents.Witness[] - }) => { - if (!transactionHash) throw new Error('Transaction hash is required') - const signedWitnesses = signWitnesses({ - transactionHash, - witnesses, - signRecoverable: this.signRecoverable, - }) - return signedWitnesses - } - - public signTransaction = (transaction: CKBComponents.RawTransaction) => { - if (!transaction) throw new Error('Transaction is required') - if (!transaction.witnesses) throw new Error('Witnesses is required') - if (transaction.witnesses.length < transaction.inputs.length) throw new Error('Invalid count of witnesses') - if (!transaction.outputsData) throw new Error('OutputsData is required') - if (transaction.outputsData.length < transaction.outputs.length) throw new Error('Invalid count of outputsData') - - const transactionHash = rawTransactionToHash(transaction) - const signedWitnesses = this.signWitnesses({ - transactionHash, - witnesses: transaction.witnesses, - }) - return { - ...transaction, - witnesses: signedWitnesses, - } - } -} - -export default Address diff --git a/packages/ckb-sdk-address/src/signWitnesses.ts b/packages/ckb-sdk-address/src/signWitnesses.ts deleted file mode 100644 index 9d166668..00000000 --- a/packages/ckb-sdk-address/src/signWitnesses.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { blake2b, PERSONAL, hexToBytes } from '@nervosnetwork/ckb-sdk-utils' - -const signWitnesses = ({ - transactionHash, - witnesses = [], - signRecoverable, -}: { - transactionHash: string - witnesses: CKBComponents.Witness[] - signRecoverable: Function -}) => { - const signedWitnesses = witnesses.map(witness => { - const oldData = witness.data || [] - const s = blake2b(32, null, null, PERSONAL) - s.update(hexToBytes(transactionHash)) - oldData.forEach(datum => { - s.update(hexToBytes(datum)) - }) - const message = `0x${s.digest('hex')}` - const data = [signRecoverable(message), ...oldData] - return { - data, - } - }) - return signedWitnesses -} - -export default signWitnesses diff --git a/packages/ckb-sdk-address/tsconfig.json b/packages/ckb-sdk-address/tsconfig.json deleted file mode 100644 index 637d3154..00000000 --- a/packages/ckb-sdk-address/tsconfig.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "outDir": "./lib", - "types": ["@nervosnetwork/ckb-types", "@nervosnetwork/ckb-sdk-utils"] - }, - "include": ["./src"] -} diff --git a/packages/ckb-sdk-core/__mocks__/data/cell.json b/packages/ckb-sdk-core/__mocks__/data/cell.json new file mode 100644 index 00000000..3e5b348e --- /dev/null +++ b/packages/ckb-sdk-core/__mocks__/data/cell.json @@ -0,0 +1,13 @@ +{ + "blockHash": "0x28011ef2c3b99a38b45809e52a3904666782bda571f2fc6b1c90eb829fc81363", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x8f67802f18390f0072b718cbde1805563d2d8b057383bf586b5ebf976d56ca5a", + "index": "0x0" + }, + "capacity": "0x1fd59fe3ae" +} diff --git a/packages/ckb-sdk-core/__mocks__/data/genesisBlock.json b/packages/ckb-sdk-core/__mocks__/data/genesisBlock.json new file mode 100644 index 00000000..dcc9f382 --- /dev/null +++ b/packages/ckb-sdk-core/__mocks__/data/genesisBlock.json @@ -0,0 +1,202 @@ +{ + "header": { + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "transactionsRoot": "0x4d4d325247a64014ae5725dd562df408299687fc4dbd16e7ebb1d0a884b3b8ea", + "proposalsHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "witnessesRoot": "0xfd973862f00e91dc5d54a05ef167ea92ff30a7010f98bed36d321e47a86f6b9c", + "unclesHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "unclesCount": "0x0", + "chain_root": "0x0000000000000000000000000000000000000000000000000000000000000000", + "dao": "0x01000000000000000000c16ff2862300009145139e840700008b54d27c7a0100", + "difficulty": "0x100", + "epoch": "0x0", + "hash": "0x18be8d57863c8f548c5772ed07912aaf731f367e048765f1c3c0a6f76c55c54c", + "nonce": "0x0", + "number": "0x0", + "timestamp": "0x0", + "version": "0x0" + }, + "uncles": [], + "transactions": [ + { + "cellDeps": [], + "inputs": [ + { + "previousOutput": { + "txHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "index": "0xffffffff" + }, + "since": "0x0" + } + ], + "outputs": [ + { + "lock": { + "codeHash": "0xb35557e7e9854206f7bc13e3c3a7fa4cf8892c84a09237fb0aab40aab3771eee", + "hashType": "data", + "args": [] + }, + "type": null, + "capacity": "0x11e1a3000" + }, + { + "lock": { + "codeHash": "0xb35557e7e9854206f7bc13e3c3a7fa4cf8892c84a09237fb0aab40aab3771eee", + "hashType": "data", + "args": [] + }, + "type": { + "codeHash": "0x00000000000000000000000000000000000000000000000000545950455f4944", + "hashType": "type", + "args": ["0x8536c9d5d908bd89fc70099e4284870708b6632356aad98734fcf43f6f71c304"] + }, + "capacity": "0x478d409d200" + }, + { + "lock": { + "codeHash": "0xb35557e7e9854206f7bc13e3c3a7fa4cf8892c84a09237fb0aab40aab3771eee", + "hashType": "data", + "args": [] + }, + "type": { + "codeHash": "0x00000000000000000000000000000000000000000000000000545950455f4944", + "hashType": "type", + "args": ["0xb2a8500929d6a1294bf9bf1bf565f549fa4a5f1316a3306ad3d4783e64bcf626"] + }, + "capacity": "0xa513b17200" + }, + { + "lock": { + "codeHash": "0xb35557e7e9854206f7bc13e3c3a7fa4cf8892c84a09237fb0aab40aab3771eee", + "hashType": "data", + "args": [] + }, + "type": null, + "capacity": "0x5f5f04610900" + }, + { + "lock": { + "codeHash": "0xb35557e7e9854206f7bc13e3c3a7fa4cf8892c84a09237fb0aab40aab3771eee", + "hashType": "data", + "args": [] + }, + "type": { + "codeHash": "0x00000000000000000000000000000000000000000000000000545950455f4944", + "hashType": "type", + "args": ["0xd813c1b15bd79c8321ad7f5819e5d9f659a1042b72e64659a2c092be68ea9758"] + }, + "capacity": "0x51d4cc26a00" + }, + { + "lock": { + "codeHash": "0xa656f172b6b45c245307aeb5a7a37a176f002f6f22e92582c58bf7ba362e4176", + "hashType": "data", + "args": ["0xb73961e46d9eb118d3de1d1e8f30b3af7bbf3160"] + }, + "type": null, + "capacity": "0xba43b7400" + }, + { + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7"] + }, + "type": null, + "capacity": "0x38d7ea4c68000" + }, + { + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0x470dcdc5e44064909650113a274b3b36aecb6dc7"] + }, + "type": null, + "capacity": "0x1c6bf52634000" + }, + { + "lock": { + "codeHash": "0x9cc3121726ed40c0ece7b43f7f28af712c7f13101f78699c5668341a52ddf280", + "hashType": "type", + "args": ["0x62e907b15cbf27d5425399ebf6f0fb50ebb88f18"] + }, + "type": null, + "capacity": "0x1c6bf52634000" + } + ], + "headerDeps": [], + "hash": "0x6ad2e9bddef6b99665f2cf69368a5aeb5f4d9f26615cf91b4637254980d32b0f", + "version": "0x0", + "witnesses": [ + { + "data": [ + "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df201", + "0xb2e61ff569acf041b3c2c17724e2379c581eeac3" + ] + } + ] + }, + { + "cellDeps": [ + { + "outPoint": { + "txHash": "0x6ad2e9bddef6b99665f2cf69368a5aeb5f4d9f26615cf91b4637254980d32b0f", + "index": "0x3" + }, + "depType": "code" + }, + { + "outPoint": { + "txHash": "0x6ad2e9bddef6b99665f2cf69368a5aeb5f4d9f26615cf91b4637254980d32b0f", + "index": "0x1" + }, + "depType": "code" + } + ], + "inputs": [ + { + "previousOutput": { + "txHash": "0x6ad2e9bddef6b99665f2cf69368a5aeb5f4d9f26615cf91b4637254980d32b0f", + "index": "0x5" + }, + "since": "0x0" + } + ], + "outputs": [ + { + "lock": { + "codeHash": "0xb35557e7e9854206f7bc13e3c3a7fa4cf8892c84a09237fb0aab40aab3771eee", + "hashType": "data", + "args": [] + }, + "type": null, + "capacity": "0x2b95fd500" + }, + { + "lock": { + "codeHash": "0xb35557e7e9854206f7bc13e3c3a7fa4cf8892c84a09237fb0aab40aab3771eee", + "hashType": "data", + "args": [] + }, + "type": null, + "capacity": "0x2b95fd500" + } + ], + "outputsData": [ + "0x020000006ad2e9bddef6b99665f2cf69368a5aeb5f4d9f26615cf91b4637254980d32b0f030000006ad2e9bddef6b99665f2cf69368a5aeb5f4d9f26615cf91b4637254980d32b0f01000000", + "0x020000006ad2e9bddef6b99665f2cf69368a5aeb5f4d9f26615cf91b4637254980d32b0f030000006ad2e9bddef6b99665f2cf69368a5aeb5f4d9f26615cf91b4637254980d32b0f04000000" + ], + "headerDeps": [], + "hash": "0x6347ee7ce5fc6828133590558b867097b895149a66e51cf353c361f7128e2091", + "version": "0x0", + "witnesses": [ + { + "data": [ + "0xd3e22911399a15898967cd64fabcae132046e359e1dc151bbb9e5199bfe166e056936c051cef17d6ac2d5bb1d61148d9879d5b84a1f479332e021038e6feea2c01" + ] + } + ] + } + ], + "proposals": [] +} diff --git a/packages/ckb-sdk-core/__mocks__/data/liveCell.json b/packages/ckb-sdk-core/__mocks__/data/liveCell.json new file mode 100644 index 00000000..97f4326e --- /dev/null +++ b/packages/ckb-sdk-core/__mocks__/data/liveCell.json @@ -0,0 +1,24 @@ +{ + "cell": { + "data": { + "content": "0x", + "hash": "0x0000000000000000000000000000000000000000000000000000000000000000" + }, + "output": { + "lock": [ + { + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "type": null, + "capacity": "0x1fd9e09516" + } + ], + "type": null, + "capacity": "0x1fd9e09516" + } + }, + "status": "live" +} diff --git a/packages/ckb-sdk-core/__mocks__/rpc.js b/packages/ckb-sdk-core/__mocks__/rpc.js new file mode 100644 index 00000000..5d73af13 --- /dev/null +++ b/packages/ckb-sdk-core/__mocks__/rpc.js @@ -0,0 +1,17 @@ +const genesisBlock = require('./data/genesisBlock.json') +const liveCell = require('./data/liveCell') +const cell = require('./data/cell.json') + +module.exports = { + getBlockByNumber: jest.fn().mockResolvedValue(genesisBlock), + getTipBlockNumber: jest.fn().mockResolvedValue('0x1000'), + getCellsByLockHash: jest.fn().mockResolvedValue( + Array.from( + { + length: 100, + }, + () => cell + ) + ), + getLiveCell: jest.fn().mockResolvedValue(liveCell), +} diff --git a/packages/ckb-sdk-address/__tests__/fixtures.json b/packages/ckb-sdk-core/__tests__/address/fixtures.json similarity index 100% rename from packages/ckb-sdk-address/__tests__/fixtures.json rename to packages/ckb-sdk-core/__tests__/address/fixtures.json diff --git a/packages/ckb-sdk-address/__tests__/index.test.js b/packages/ckb-sdk-core/__tests__/address/index.test.js similarity index 81% rename from packages/ckb-sdk-address/__tests__/index.test.js rename to packages/ckb-sdk-core/__tests__/address/index.test.js index 2b5eaa79..ddbc340f 100644 --- a/packages/ckb-sdk-address/__tests__/index.test.js +++ b/packages/ckb-sdk-core/__tests__/address/index.test.js @@ -1,7 +1,7 @@ -const { default: Address } = require('../lib') +const { default: Address } = require('../../lib/address') const { generateAddress: generateAddressFixtures } = require('./fixtures.json') -describe('ckb-sdk-address', () => { +describe('address', () => { describe('generate address', () => { const fixtureTable = Object.entries(generateAddressFixtures).map( ([title, { privateKey, expected, exception, ...config }]) => [title, privateKey, config, expected, exception] @@ -15,7 +15,7 @@ describe('ckb-sdk-address', () => { expect(address.value).toBe(expected.address) } if (undefined !== exception) { - expect(() => new Address(privateKey, option)).toThrow(new Error(exception)) + expect(() => new Address(privateKey, option)).toThrowError(exception) } }) }) diff --git a/packages/ckb-sdk-core/__tests__/fixtures.json b/packages/ckb-sdk-core/__tests__/fixtures.json index 684ee460..ab8e0754 100644 --- a/packages/ckb-sdk-core/__tests__/fixtures.json +++ b/packages/ckb-sdk-core/__tests__/fixtures.json @@ -252,5 +252,257 @@ }, "expected": "0x9e9e450fa32ef75e7063023574f1fd3647e8eb35ff5ce9e3c04fb3056c8e37d6" } + }, + "generateRawTransaction": { + "testnet": { + "params": { + "fromAddress": "ckt1qyqw975zuu9svtyxgjuq44lv7mspte0n2tmqa703cd", + "toAddress": "ckt1qyqdm0tlp845spzscxc76tyxjcjgm6gudqpq4h77wx", + "capacity": 783602013670, + "safeMode": true, + "isMainnet": false, + "cells": [ + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x0" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x1" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x2" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x3" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x4" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x5" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x6" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x7" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x8" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x9" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + } + ], + "deps": { + "hashType": "type", + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "outPoint": { + "txHash": "0x6347ee7ce5fc6828133590558b867097b895149a66e51cf353c361f7128e2091", + "index": "0x0" + } + } + }, + "expected": { + "cellDeps": [ + { + "depType": "depGroup", + "outPoint": { + "index": "0x0", + "txHash": "0x6347ee7ce5fc6828133590558b867097b895149a66e51cf353c361f7128e2091" + } + } + ], + "headerDeps": [], + "inputs": [ + { + "previousOutput": { + "index": "0x1", + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2" + }, + "since": "0x0" + }, + { + "previousOutput": { + "index": "0x2", + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2" + }, + "since": "0x0" + }, + { + "previousOutput": { + "index": "0x3", + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2" + }, + "since": "0x0" + }, + { + "previousOutput": { + "index": "0x4", + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2" + }, + "since": "0x0" + }, + { + "previousOutput": { + "index": "0x5", + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2" + }, + "since": "0x0" + }, + { + "previousOutput": { + "index": "0x6", + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2" + }, + "since": "0x0" + } + ], + "outputs": [ + { + "capacity": "0xb67251d5e6", + "lock": { + "args": ["0xddbd7f09eb480450c1b1ed2c8696248de91c6802"], + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type" + } + }, + { + "capacity": "0x88cb4e12e", + "lock": { + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"], + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type" + } + } + ], + "outputsData": ["0x", "0x"], + "version": "0x0", + "witnesses": [ + { + "data": [] + } + ] + } + } } } diff --git a/packages/ckb-sdk-core/__tests__/generateRawTransaction/fixtures.json b/packages/ckb-sdk-core/__tests__/generateRawTransaction/fixtures.json new file mode 100644 index 00000000..007d9a06 --- /dev/null +++ b/packages/ckb-sdk-core/__tests__/generateRawTransaction/fixtures.json @@ -0,0 +1,500 @@ +{ + "basic": { + "params": { + "fromPublicKeyHash": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", + "toPublicKeyHash": "0xddbd7f09eb480450c1b1ed2c8696248de91c6802", + "capacity": 783602013670, + "safeMode": true, + "cells": [ + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x0" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x1" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x2" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x3" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x4" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x5" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x6" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x7" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x8" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x9" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + } + ], + "deps": { + "hashType": "type", + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "outPoint": { + "txHash": "0x6347ee7ce5fc6828133590558b867097b895149a66e51cf353c361f7128e2091", + "index": "0x0" + } + } + }, + "expected": { + "cellDeps": [ + { + "depType": "depGroup", + "outPoint": { + "index": "0x0", + "txHash": "0x6347ee7ce5fc6828133590558b867097b895149a66e51cf353c361f7128e2091" + } + } + ], + "headerDeps": [], + "inputs": [ + { + "previousOutput": { + "index": "0x1", + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2" + }, + "since": "0x0" + }, + { + "previousOutput": { + "index": "0x2", + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2" + }, + "since": "0x0" + }, + { + "previousOutput": { + "index": "0x3", + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2" + }, + "since": "0x0" + }, + { + "previousOutput": { + "index": "0x4", + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2" + }, + "since": "0x0" + }, + { + "previousOutput": { + "index": "0x5", + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2" + }, + "since": "0x0" + }, + { + "previousOutput": { + "index": "0x6", + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2" + }, + "since": "0x0" + } + ], + "outputs": [ + { + "capacity": "0xb67251d5e6", + "lock": { + "args": ["0xddbd7f09eb480450c1b1ed2c8696248de91c6802"], + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type" + } + }, + { + "capacity": "0x88cb4e12e", + "lock": { + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"], + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type" + } + } + ], + "outputsData": ["0x", "0x"], + "version": "0x0", + "witnesses": [ + { + "data": [] + } + ] + } + }, + "unsafe transaction": { + "params": { + "fromPublicKeyHash": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", + "toPublicKeyHash": "0xddbd7f09eb480450c1b1ed2c8696248de91c6802", + "capacity": 783602013670, + "safeMode": false, + "cells": [ + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x0" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x1" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x2" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x3" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x4" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x5" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x6" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x7" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x8" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + }, + { + "blockHash": "0x355cd43b6b517be40ce69278b7c6d2017546e2d46557d59e31adff20646c845e", + "lock": { + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type", + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + }, + "outPoint": { + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", + "index": "0x9" + }, + "capacity": "0x1fd52bc92e", + "dataHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "status": "live" + } + ], + "deps": { + "hashType": "type", + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "outPoint": { + "txHash": "0x6347ee7ce5fc6828133590558b867097b895149a66e51cf353c361f7128e2091", + "index": "0x0" + } + } + }, + "expected": { + "cellDeps": [ + { + "depType": "depGroup", + "outPoint": { + "index": "0x0", + "txHash": "0x6347ee7ce5fc6828133590558b867097b895149a66e51cf353c361f7128e2091" + } + } + ], + "headerDeps": [], + "inputs": [ + { + "previousOutput": { + "index": "0x0", + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2" + }, + "since": "0x0" + }, + { + "previousOutput": { + "index": "0x1", + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2" + }, + "since": "0x0" + }, + { + "previousOutput": { + "index": "0x2", + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2" + }, + "since": "0x0" + }, + { + "previousOutput": { + "index": "0x3", + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2" + }, + "since": "0x0" + }, + { + "previousOutput": { + "index": "0x4", + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2" + }, + "since": "0x0" + }, + { + "previousOutput": { + "index": "0x5", + "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2" + }, + "since": "0x0" + } + ], + "outputs": [ + { + "capacity": "0xb67251d5e6", + "lock": { + "args": ["0xddbd7f09eb480450c1b1ed2c8696248de91c6802"], + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type" + } + }, + { + "capacity": "0x88cb4e12e", + "lock": { + "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"], + "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "hashType": "type" + } + } + ], + "outputsData": ["0x", "0x"], + "version": "0x0", + "witnesses": [ + { + "data": [] + } + ] + } + } +} diff --git a/packages/ckb-sdk-core/__tests__/generateRawTransaction/index.test.js b/packages/ckb-sdk-core/__tests__/generateRawTransaction/index.test.js new file mode 100644 index 00000000..2c8edec6 --- /dev/null +++ b/packages/ckb-sdk-core/__tests__/generateRawTransaction/index.test.js @@ -0,0 +1,26 @@ +const { default: generateRawTransaction } = require('../../lib/generateRawTransaction') +const { default: Core } = require('../../lib') +const rpc = require('../../__mocks__/rpc') + +const fixtures = require('./fixtures.json') + +describe('generate raw transaction', () => { + const core = new Core('http://localhost:8114') + core.rpc = rpc + + const fixtureTable = Object.entries(fixtures).map(([title, { params, expected, exception }]) => [ + title, + params, + expected, + exception, + ]) + + test.each(fixtureTable)('%s', async (title, params, expected, exception) => { + if (undefined === exception) { + const rawTransaction = await generateRawTransaction(params) + expect(rawTransaction).toEqual(expected) + } else { + expect(generateRawTransaction(params)).rejects.toThrowError(exception) + } + }) +}) diff --git a/packages/ckb-sdk-core/__tests__/index.test.js b/packages/ckb-sdk-core/__tests__/index.test.js index 12e465ea..db4b31ea 100644 --- a/packages/ckb-sdk-core/__tests__/index.test.js +++ b/packages/ckb-sdk-core/__tests__/index.test.js @@ -1,35 +1,76 @@ const fixtures = require('./fixtures.json') +const rpc = require('../__mocks__/rpc') const { default: Core } = require('../lib') -const url = 'http://localhost:8114' -const core = new Core(url) - describe('ckb-core', () => { - it('load the secp256k1 dep', async () => { - jest.setTimeout(50000) - const fixture = fixtures.loadSecp256k1Dep - expect(core.config.loadSecp256k1Dep).toEqual(undefined) + const url = 'http://localhost:8114' + let core + beforeEach(() => { + core = new Core(url) + }) - const secp256k1Dep = await core.loadSecp256k1Dep() - expect(secp256k1Dep).toEqual(fixture.target) + describe('load data', () => { + it('load the secp256k1 dep', async () => { + core.rpc = rpc + jest.setTimeout(50000) + const fixture = fixtures.loadSecp256k1Dep + expect(core.config.loadSecp256k1Dep).toEqual(undefined) + + const secp256k1Dep = await core.loadSecp256k1Dep() + expect(secp256k1Dep).toEqual(fixture.target) + }) + + it('load cells', async () => { + core.rpc = rpc + const lockHash = '0xe831b2179a00307607d254b6fae904047b1fb7f2c76968f305ec27841201739a' + const cells = await core.loadCells({ + lockHash, + end: 100, + step: 100, + save: true, + }) + expect(cells).toHaveLength(100) + expect(core.cells.size).toBe(1) + expect(core.cells.get(lockHash)).toHaveLength(100) + }) }) - describe('sign witnesses', () => { - const fixtureTable = Object.entries(fixtures.signWitnesses).map( - ([title, { privateKey, message, expected, exception }]) => [title, privateKey, message, expected, exception] - ) - test.each(fixtureTable)('%s', (_title, privateKey, message, expected, exception) => { - if (undefined !== expected) { - const signedWitnessesByPrivateKey = core.signWitnesses(privateKey)(message) - expect(signedWitnessesByPrivateKey).toEqual(expected) + describe('set node', () => { + const newURL = 'http://localhost:8080' + it('has url set by instantication', () => { + expect(core.node.url).toBe(url) + expect(core.rpc.node.url).toBe(url) + }) + it('set node with url', () => { + core.setNode(newURL) + expect(core.node.url).toBe(newURL) + expect(core.rpc.node.url).toBe(newURL) + }) + it('set node with node object', () => { + core.setNode({ + url, + }) + expect(core.node.url).toBe(url) + expect(core.node.url).toBe(url) + }) + }) - const signedWitnessesByAddressObject = core.signWitnesses(core.generateAddress(privateKey))(message) - expect(signedWitnessesByAddressObject).toEqual(expected) - } - if (undefined !== exception) { - expect(() => core.signWitnesses(privateKey)(message)).toThrowError(exception) - } + describe('generate lockHash', () => { + const params = { + publicKeyHash: '0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6', + deps: { + hashType: 'type', + codeHash: '0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2', + }, + } + it('generate lock hash', () => { + const lockHash = core.generateLockHash(params.publicKeyHash, params.deps) + expect(lockHash).toBe('0xe831b2179a00307607d254b6fae904047b1fb7f2c76968f305ec27841201739a') + }) + + it('lack fo deps should throw an error', () => { + expect(() => core.generateLockHash(params.publicKeyHash)).toThrowError('deps is required') }) }) @@ -46,7 +87,25 @@ describe('ckb-core', () => { expect(computedHash).toBe(expected) } if (undefined !== exception) { - expect(core.rpc.computeScriptHash(script)).reject.toBe(new Error(exception)) + expect(core.rpc.computeScriptHash(script)).reject.toThrowError(exception) + } + }) + }) + + describe('sign witnesses', () => { + const fixtureTable = Object.entries(fixtures.signWitnesses).map( + ([title, { privateKey, message, expected, exception }]) => [title, privateKey, message, expected, exception] + ) + test.each(fixtureTable)('%s', (_title, privateKey, message, expected, exception) => { + if (undefined !== expected) { + const signedWitnessesByPrivateKey = core.signWitnesses(privateKey)(message) + expect(signedWitnessesByPrivateKey).toEqual(expected) + + const signedWitnessesByAddressObject = core.signWitnesses(core.generateAddress(privateKey))(message) + expect(signedWitnessesByAddressObject).toEqual(expected) + } + if (undefined !== exception) { + expect(() => core.signWitnesses(privateKey)(message)).toThrowError(exception) } }) }) @@ -69,7 +128,22 @@ describe('ckb-core', () => { expect(signedTransactionWithAddressObj).toEqual(expected) } if (undefined !== exception) { - expect(() => core.signTransaction(privateKey)(transaction)).toThrow(new Error(exception)) + expect(() => core.signTransaction(privateKey)(transaction)).toThrowError(exception) + } + }) + }) + + describe('generate raw transactin', () => { + const fixtureTable = Object.entries(fixtures.generateRawTransaction).map( + ([title, { params, expected, exception }]) => [title, params, expected, exception] + ) + + test.each(fixtureTable)('%s', async (_title, params, expected, exception) => { + if (undefined === exception) { + const rawTransaction = await core.generateRawTransaction(params) + expect(rawTransaction).toEqual(expected) + } else { + expect(core.generateRawTransaction(params)).rejects.toThrowError(exception) } }) }) diff --git a/packages/ckb-sdk-core/__tests__/loadCells/fixtures.json b/packages/ckb-sdk-core/__tests__/loadCells/fixtures.json new file mode 100644 index 00000000..bb299c88 --- /dev/null +++ b/packages/ckb-sdk-core/__tests__/loadCells/fixtures.json @@ -0,0 +1,123 @@ +{ + "basic": { + "params": { + "lockHash": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", + "start": 1, + "end": 300, + "STEP": 100 + }, + "expectedCells": 300, + "expectedCalls": [ + ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", 1, 101], + ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", 102, 201], + ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", 202, 300] + ] + }, + "hex string": { + "params": { + "lockHash": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", + "start": "0x1", + "end": "0x12c", + "STEP": 100 + }, + "expectedCells": 300, + "expectedCalls": [ + ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", 1, 101], + ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", 102, 201], + ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", 202, 300] + ] + }, + "default params": { + "params": { + "lockHash": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", + "end": 300 + }, + "expectedCells": 300, + "expectedCalls": [ + ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", 0, 100], + ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", 101, 200], + ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", 201, 300] + ] + }, + "STEP = 30": { + "params": { + "lockHash": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", + "end": 285, + "STEP": 30 + }, + "expectedCells": 1000, + "expectedCalls": [ + ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", 0, 30], + ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", 31, 60], + ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", 61, 90], + ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", 91, 120], + ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", 121, 150], + ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", 151, 180], + ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", 181, 210], + ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", 211, 240], + ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", 241, 270], + ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", 271, 285] + ] + }, + "start === end": { + "params": { + "lockHash": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", + "start": 300, + "end": 300 + }, + "expectedCells": 100, + "expectedCalls": [["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", 300, 300]] + }, + "parameters without lockHash should throw an error": { + "params": { + "end": 300, + "STEP": 30 + }, + "exception": "lockHash is required" + }, + "parameters including invalid hex-string of start should throw an error": { + "params": { + "lockHash": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", + "start": "1", + "end": "0x12c", + "STEP": 100 + }, + "exception": "Hex string 1 should start with 0x" + }, + "parameters including invalid hex-string of end should throw an error": { + "params": { + "lockHash": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", + "start": "0x1", + "end": "12c", + "STEP": 100 + }, + "exception": "Hex string 12c should start with 0x" + }, + "parameters including invalid integer of start should throw an error": { + "params": { + "lockHash": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", + "start": 1.1, + "end": "0x12c", + "STEP": 100 + }, + "exception": "1.1 cannot be converted into an integer" + }, + "parameters including invalid integer of end should throw an error": { + "params": { + "lockHash": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", + "start": "0x1", + "end": 1.1, + "STEP": 100 + }, + "exception": "1.1 cannot be converted into an integer" + }, + "end less than start should throw an error": { + "params": { + "lockHash": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", + "start": 300, + "end": 299, + "STEP": 100 + }, + "exception": "start(300) should not be less than end(299)" + } +} diff --git a/packages/ckb-sdk-core/__tests__/loadCells/index.test.js b/packages/ckb-sdk-core/__tests__/loadCells/index.test.js new file mode 100644 index 00000000..2bddb13c --- /dev/null +++ b/packages/ckb-sdk-core/__tests__/loadCells/index.test.js @@ -0,0 +1,42 @@ +const { default: loadCells } = require('../../lib/loadCells') +const rpc = require('../../__mocks__/rpc') +const fixtures = require('./fixtures.json') + +describe('load cells', () => { + const fixtureTable = Object.entries(fixtures).map(([title, { params, expectedCells, expectedCalls, exception }]) => [ + title, + params, + expectedCells, + expectedCalls, + exception, + ]) + test.each(fixtureTable)('%s case: %j', async (_title, params, expectedCells, expectedCalls, exception) => { + rpc.getCellsByLockHash.mockClear() + if (undefined === exception) { + const cells = await loadCells({ + ...params, + rpc, + }) + expect(cells).toHaveLength(expectedCells) + expect(rpc.getCellsByLockHash.mock.calls).toEqual(expectedCalls) + } else { + expect( + loadCells({ + ...params, + rpc, + }) + ).rejects.toThrowError(exception) + } + }) + + it('parameters without rpc should throw an error', () => { + expect( + loadCells({ + lockHash: '0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6', + start: '0x1', + end: '0x12c', + STEP: 100, + }) + ).rejects.toThrowError('RPC object is required') + }) +}) diff --git a/packages/ckb-sdk-core/package.json b/packages/ckb-sdk-core/package.json index ffa60c9c..bead533f 100644 --- a/packages/ckb-sdk-core/package.json +++ b/packages/ckb-sdk-core/package.json @@ -30,7 +30,6 @@ "url": "https://github.com/nervosnetwork/ckb-sdk-js/issues" }, "dependencies": { - "@nervosnetwork/ckb-sdk-address": "0.21.1", "@nervosnetwork/ckb-sdk-rpc": "0.21.1", "@nervosnetwork/ckb-sdk-utils": "0.21.1", "@nervosnetwork/ckb-types": "0.21.1" diff --git a/packages/ckb-sdk-core/src/address.ts b/packages/ckb-sdk-core/src/address.ts new file mode 100644 index 00000000..2ca16345 --- /dev/null +++ b/packages/ckb-sdk-core/src/address.ts @@ -0,0 +1,38 @@ +import ECPair from '@nervosnetwork/ckb-sdk-utils/lib/ecpair' +import { pubkeyToAddress, blake160, AddressPrefix, AddressType } from '@nervosnetwork/ckb-sdk-utils' +import { AddressOptions } from '@nervosnetwork/ckb-sdk-utils/lib/address' + +class Address extends ECPair { + public value = '' + + public publicKeyHash = '' + + public constructor( + sk: Uint8Array | string, + { + addressAlgorithm = pubkeyToAddress, + prefix = AddressPrefix.Testnet, + type = AddressType.HashIdx, + codeHashIndex = '0x00', + }: Partial< + { + addressAlgorithm: Function + } & AddressOptions + > = { + addressAlgorithm: pubkeyToAddress, + prefix: AddressPrefix.Testnet, + type: AddressType.HashIdx, + codeHashIndex: '0x00', + } + ) { + super(sk) + this.value = addressAlgorithm(this.publicKey, { + prefix, + type, + codeHashIndex, + }) + this.publicKeyHash = `0x${blake160(this.publicKey as string, 'hex')}` + } +} + +export default Address diff --git a/packages/ckb-sdk-core/src/generateRawTransaction.ts b/packages/ckb-sdk-core/src/generateRawTransaction.ts new file mode 100644 index 00000000..2ea2c3a9 --- /dev/null +++ b/packages/ckb-sdk-core/src/generateRawTransaction.ts @@ -0,0 +1,117 @@ +import { HexStringShouldStartWith0x } from '@nervosnetwork/ckb-sdk-utils/lib/exceptions' + +const EMPTY_DATA_HASH = '0x0000000000000000000000000000000000000000000000000000000000000000' + +const generateRawTransaction = async ({ + fromPublicKeyHash, + toPublicKeyHash, + capacity, + safeMode = true, + cells: unspentCells = [], + deps, +}: { + fromPublicKeyHash: string + toPublicKeyHash: string + capacity: bigint | string | number + safeMode: boolean + cells: CachedCell[] + deps: DepCellInfo +}) => { + if (!deps) { + throw new Error('The deps is not loaded') + } + + if (typeof capacity === 'string' && !capacity.startsWith('0x')) { + throw new HexStringShouldStartWith0x(capacity) + } + + const targetCapacity = typeof capacity !== 'bigint' ? BigInt(capacity) : capacity + + const lockScript = { + codeHash: deps.codeHash, + hashType: deps.hashType, + args: [fromPublicKeyHash], + } + + /** + * the new cell for next owner + */ + const toOutput = { + capacity: targetCapacity, + lock: { + hashType: deps.hashType, + codeHash: deps.codeHash, + args: [toPublicKeyHash], + }, + } + + /** + * the new cell as a change + */ + const changeOutput = { + capacity: BigInt(0), + lock: lockScript, + } + + if (!unspentCells.length) { + throw new Error('No available cells found in the cell map, please make sure the loadCells method is called') + } + const inputs = [] + let inputCapacity = BigInt(0) + /** + * pick inputs + */ + for (let i = 0; i < unspentCells.length; i++) { + const unspentCell = unspentCells[i] + if (!safeMode || unspentCell.dataHash === EMPTY_DATA_HASH) { + inputs.push({ + previousOutput: unspentCell.outPoint, + since: '0x0', + }) + inputCapacity += BigInt(unspentCells[i].capacity) + if (inputCapacity >= targetCapacity) { + break + } + } + } + if (inputCapacity < targetCapacity) { + throw new Error('Input capacity is not enough') + } + if (inputCapacity > targetCapacity) { + changeOutput.capacity = inputCapacity - targetCapacity + } + + /** + * compose the raw transaction which has an empty witnesses + */ + + const outputs = [{ ...toOutput, capacity: `0x${toOutput.capacity.toString(16)}` }] + + if (changeOutput.capacity > BigInt(0)) { + outputs.push({ ...changeOutput, capacity: `0x${changeOutput.capacity.toString(16)}` }) + } + + const outputsData = outputs.map(() => '0x') + + const tx = { + version: '0x0', + cellDeps: [ + { + outPoint: deps.outPoint, + depType: 'depGroup', + }, + ], + headerDeps: [], + inputs, + outputs, + witnesses: [ + { + data: [], + }, + ], + outputsData, + } + return tx +} + +export default generateRawTransaction diff --git a/packages/ckb-sdk-core/src/index.ts b/packages/ckb-sdk-core/src/index.ts index 4af22f43..909aee55 100644 --- a/packages/ckb-sdk-core/src/index.ts +++ b/packages/ckb-sdk-core/src/index.ts @@ -1,13 +1,17 @@ import RPC from '@nervosnetwork/ckb-sdk-rpc' -import Address from '@nervosnetwork/ckb-sdk-address' +import { ArgumentRequired } from '@nervosnetwork/ckb-sdk-utils/lib/exceptions' import * as utils from '@nervosnetwork/ckb-sdk-utils' -interface DepCellInfo { - hashType: CKBComponents.ScriptHashType - codeHash: CKBComponents.Hash256 - outPoint: CKBComponents.OutPoint -} +import generateRawTransaction from './generateRawTransaction' + +import Address from './address' +import loadCells from './loadCells' + +const hrpSize = 6 + class Core { + public cells: Map = new Map() + public rpc: RPC public utils = utils @@ -75,15 +79,26 @@ class Core { codeHashIndex: '0x00', } ) => - new Address( - privateKey, - { - prefix, - type, - codeHashIndex, - }, - this.rpc - ) + new Address(privateKey, { + prefix, + type, + codeHashIndex, + }) + + public generateLockHash = ( + publicKeyHash: string, + deps: Omit | undefined = this.config.secp256k1Dep + ) => { + if (!deps) { + throw new ArgumentRequired('deps') + } + + return this.utils.scriptToHash({ + hashType: deps.hashType, + codeHash: deps.codeHash, + args: [publicKeyHash], + }) + } public loadSecp256k1Dep = async () => { /** @@ -119,6 +134,121 @@ class Core { } return this.config.secp256k1Dep } + + public loadCells = async ({ + lockHash, + start = 0, + end, + STEP = 100, + save = false, + }: { + lockHash: string + start?: string | number + end?: string | number + STEP?: number + save?: boolean + }) => { + const cells = await loadCells({ lockHash, start, end, STEP, rpc: this.rpc }) + if (save) { + this.cells.set(lockHash, cells) + } + return cells + } + + public signWitnesses = (key: string | Address) => ({ + transactionHash, + witnesses = [], + }: { + transactionHash: string + witnesses: CKBComponents.Witness[] + }) => { + if (!key) throw new ArgumentRequired('Private key or address object') + if (!transactionHash) throw new ArgumentRequired('Transaction hash') + + const addrObj = typeof key === 'string' ? this.generateAddress(key) : key + const signedWitnesses = witnesses.map(witness => { + const oldData = witness.data || [] + const s = this.utils.blake2b(32, null, null, this.utils.PERSONAL) + s.update(this.utils.hexToBytes(transactionHash)) + oldData.forEach(datum => { + s.update(this.utils.hexToBytes(datum)) + }) + const message = `0x${s.digest('hex')}` + const data = [addrObj.signRecoverable(message), ...oldData] + return { + data, + } + }) + return signedWitnesses + } + + public signTransaction = (key: string | Address) => (transaction: CKBComponents.RawTransaction) => { + if (!key) throw new ArgumentRequired('Private key or address object') + if (!transaction) throw new ArgumentRequired('Transaction') + if (!transaction.witnesses) throw new ArgumentRequired('Witnesses') + if (transaction.witnesses.length < transaction.inputs.length) throw new Error('Invalid count of witnesses') + if (!transaction.outputsData) throw new ArgumentRequired('OutputsData') + if (transaction.outputsData.length < transaction.outputs.length) throw new Error('Invalid count of outputsData') + + const transactionHash = this.utils.rawTransactionToHash(transaction) + const signedWitnesses = this.signWitnesses(key)({ + transactionHash, + witnesses: transaction.witnesses, + }) + return { + ...transaction, + witnesses: signedWitnesses, + } + } + + public generateRawTransaction = async ({ + fromAddress, + toAddress, + capacity, + safeMode = true, + cells = [], + deps = this.config.secp256k1Dep!, + isMainnet = false, + }: { + fromAddress: string + toAddress: string + capacity: string | bigint + safeMode: boolean + cells: CachedCell[] + deps: DepCellInfo + isMainnet: boolean + }) => { + const prefix = isMainnet ? this.utils.AddressPrefix.Mainnet : this.utils.AddressPrefix.Testnet + const [fromPublicKeyHash, toPublicKeyHash] = [fromAddress, toAddress].map((addr: string) => { + const addressPayload = this.utils.parseAddress(addr, prefix, 'hex') + return `0x${addressPayload.slice(hrpSize)}` + }) + + let availableCells = cells + if (!availableCells.length && deps) { + const lockHash = this.utils.scriptToHash({ + codeHash: deps.codeHash, + hashType: deps.hashType, + args: [fromPublicKeyHash], + }) + const cachedCells = this.cells.get(lockHash) + if (cachedCells && cachedCells.length) { + availableCells = cachedCells + } else { + const fetchedCells = await this.loadCells({ lockHash, save: true }) + availableCells = fetchedCells + } + } + + return generateRawTransaction({ + fromPublicKeyHash, + toPublicKeyHash, + capacity, + safeMode, + cells: availableCells, + deps, + }) + } } export default Core diff --git a/packages/ckb-sdk-address/src/loadCells.ts b/packages/ckb-sdk-core/src/loadCells.ts similarity index 58% rename from packages/ckb-sdk-address/src/loadCells.ts rename to packages/ckb-sdk-core/src/loadCells.ts index 23988948..0b6103d7 100644 --- a/packages/ckb-sdk-address/src/loadCells.ts +++ b/packages/ckb-sdk-core/src/loadCells.ts @@ -1,9 +1,5 @@ import RPC from '@nervosnetwork/ckb-sdk-rpc' - -export interface Cell extends CKBComponents.CellIncludingOutPoint { - status: string - dataHash: string -} +import { HexStringShouldStartWith0x, ArgumentRequired } from '@nervosnetwork/ckb-sdk-utils/lib/exceptions' const loadCells = async ({ lockHash, @@ -19,37 +15,47 @@ const loadCells = async ({ rpc: RPC }) => { if (!lockHash) { - throw new Error('lockHash is required to load cells') + throw new ArgumentRequired('lockHash') } if (!rpc) { - throw new Error('RPC module is required to load cells') + throw new ArgumentRequired('RPC object') } + if (typeof start === 'string' && !start.startsWith('0x')) { + throw new HexStringShouldStartWith0x(start) + } + + if (typeof end === 'string' && !end.startsWith('0x')) { + throw new HexStringShouldStartWith0x(end) + } + const from = +start if (!Number.isInteger(from)) { - throw new Error(`${start} cannot be converted into a integer`) + throw new Error(`${start} cannot be converted into an integer`) } const tipBlockNumber = await rpc.getTipBlockNumber() let to = end === undefined ? +tipBlockNumber : Math.min(+end, +tipBlockNumber) if (!Number.isInteger(to)) { - throw new Error(`${end} cannot be converted into a integer`) + throw new Error(`${end} cannot be converted into an integer`) } to = Math.min(to, +tipBlockNumber) if (to < from) { - throw new Error(`${start} should not be less than ${end}`) + throw new Error(`start(${start}) should not be less than end(${end})`) } - const groups = Array.from( - { - length: Math.ceil((to - from) / STEP), - }, - (_, idx) => [from + idx * STEP + (idx ? 1 : 0), Math.min(from + (idx + 1) * STEP, to)] - ) + const range = to - from + + const groups = range + ? Array.from({ length: Math.ceil(range / STEP) }, (_, idx) => [ + from + idx * STEP + (idx ? 1 : 0), + Math.min(from + (idx + 1) * STEP, to), + ]) + : [[from, to]] - const cells: Cell[] = [] + const cells: CachedCell[] = [] /* eslint-disable no-await-in-loop */ for (let i = 0; i < groups.length; i++) { diff --git a/packages/ckb-sdk-core/tsconfig.json b/packages/ckb-sdk-core/tsconfig.json index f1d7d4b5..c1cd949b 100644 --- a/packages/ckb-sdk-core/tsconfig.json +++ b/packages/ckb-sdk-core/tsconfig.json @@ -3,7 +3,7 @@ "compilerOptions": { "outDir": "./lib", "lib": ["es6", "esnext.array"], - "types": ["@nervosnetwork/ckb-types", "@nervosnetwork/ckb-sdk-utils"] + "types": ["@nervosnetwork/ckb-types", "@nervosnetwork/ckb-sdk-utils", "./types/global"] }, "include": ["./src"] } diff --git a/packages/ckb-sdk-core/types/global.d.ts b/packages/ckb-sdk-core/types/global.d.ts new file mode 100644 index 00000000..43371ec7 --- /dev/null +++ b/packages/ckb-sdk-core/types/global.d.ts @@ -0,0 +1,10 @@ +interface DepCellInfo { + hashType: CKBComponents.ScriptHashType + codeHash: CKBComponents.Hash256 + outPoint: CKBComponents.OutPoint +} + +interface CachedCell extends CKBComponents.CellIncludingOutPoint { + status: string + dataHash: string +} diff --git a/packages/ckb-sdk-utils/src/address/index.ts b/packages/ckb-sdk-utils/src/address/index.ts index 053bc0fd..0ae7d043 100644 --- a/packages/ckb-sdk-utils/src/address/index.ts +++ b/packages/ckb-sdk-utils/src/address/index.ts @@ -75,6 +75,10 @@ export declare interface ParseAddress { (address: string, prefix: AddressPrefix, encode: 'hex'): string (address: string, prefix: AddressPrefix, encode: 'binary' | 'hex'): Uint8Array | string } +/** + * @return addressPayload, consists of type | params | publicKeyHash + * e.g. 0x | 01 | 00 | e2fa82e70b062c8644b80ad7ecf6e015e5f352f6 + */ export const parseAddress: ParseAddress = ( address: string, prefix: AddressPrefix = AddressPrefix.Testnet, From 25af44142424a95f27af115e622db11e3acc81eb Mon Sep 17 00:00:00 2001 From: Keith Date: Tue, 24 Sep 2019 21:05:32 +0800 Subject: [PATCH 08/19] chore(core): update the example of sending transactions --- .../ckb-sdk-core/examples/sendTransaction.js | 170 ++---------------- 1 file changed, 17 insertions(+), 153 deletions(-) diff --git a/packages/ckb-sdk-core/examples/sendTransaction.js b/packages/ckb-sdk-core/examples/sendTransaction.js index 30786d7a..308520a8 100644 --- a/packages/ckb-sdk-core/examples/sendTransaction.js +++ b/packages/ckb-sdk-core/examples/sendTransaction.js @@ -49,166 +49,30 @@ const bootstrap = async () => { // console.log(lockHash) // method to fetch all unspent cells by lock hash - const STEP = 100 - const cellsGroup = [] - const getUnspentCells = (_lockHash, from, to, cb) => - new Promise((resolve, reject) => { - if (from + STEP < to) { - return core.rpc - .getCellsByLockHash(_lockHash, from, from + STEP) - .then(cells => { - if (cells.length) { - console.log(`Fetched from ${from} to ${from + STEP} with ${cells.length} cells`) - } - cellsGroup.push(cells) - return getUnspentCells(_lockHash, from + STEP + 1, to, cb) - }) - .catch(reject) - } - return core.rpc - .getCellsByLockHash(_lockHash, from, to) - .then(cells => { - if (cells.length) { - console.log(`Fetched from ${from} to ${to} with ${cells.length} cells`) - } - cellsGroup.push(cells) - resolve(cellsGroup) - }) - .catch(reject) - }) - .then(group => group.flat()) - .then(cells => { - /** - * too see the cells - */ - // console.log(cells) - if (cb) cb(cells) - }) - - // load the unspent cells in Promise method, just an optimiztion of code. - const loadCells = () => - new Promise((resolve, reject) => { - core.rpc - .getTipBlockNumber() - .then(tipNumber => - getUnspentCells(lockHash, 0, tipNumber, resolve) - ) - .catch(reject) - }) + const unspentCells = await core.loadCells({ + lockHash + }) /** * to see the unspent cells */ - // core.rpc - // .getTipBlockNumber() - // .then(tipNumber => loadCells(lockHash, 0, tipNumber)) - // .then(console.log) - - /** - * @notice fill the blaked160ed public key as the publicKeyHash of the target address in the output's args, - * which is used to specify the next owner of the output, namely the fresh cell. - * @notice use bigint or big number to handle the capacity for safety - */ - const generateTransaction = async (targetPublicKeyHash, capacity) => { - const targetCapacity = BigInt(capacity) - - /** - * the new cell for next owner - */ - const targetOutput = { - capacity: targetCapacity, - lock: { - hashType: secp256k1Dep.hashType, - codeHash: secp256k1Dep.codeHash, - args: [targetPublicKeyHash], - }, - } - - /** - * the new cell as a change - */ - const changeOutput = { - capacity: 0n, - lock: { - hashType: secp256k1Dep.hashType, - codeHash: secp256k1Dep.codeHash, - args: [myAddressObj.publicKeyHash], - }, - } - - const unspentCells = await loadCells() - const inputs = [] - let inputCapacity = 0n - /** - * pick inputs - */ - for (let i = 0; i < unspentCells.length; i++) { - const unspentCell = unspentCells[i] - inputs.push({ - previousOutput: unspentCell.outPoint, - since: '0x0', - }) - inputCapacity += BigInt(unspentCells[i].capacity) - if (inputCapacity >= targetCapacity) { - break - } - } - if (inputCapacity < targetCapacity) { - throw new Error('inputCapacity is not enough') - } - if (inputCapacity > targetCapacity) { - changeOutput.capacity = inputCapacity - targetCapacity - } - - /** - * compose the raw transaction which has an empty witnesses - */ - - const outputs = - changeOutput.capacity > 0n ? [{ - ...targetOutput, - capacity: `0x${targetOutput.capacity.toString(16)}`, - }, - { - ...changeOutput, - capacity: `0x${changeOutput.capacity.toString(16)}`, - }, - ] : [{ - ...targetOutput, - capacity: `0x${targetOutput.capacity.toString(16)}`, - }, ] - - const outputsData = outputs.map(output => "0x") - - const tx = { - version: '0x0', - cellDeps: [{ - outPoint: secp256k1Dep.outPoint, - depType: "depGroup", - }, ], - headerDeps: [], - inputs, - outputs, - witnesses: [{ - data: [], - }, ], - outputsData, - } - return tx - } - - /** - * to see the generated transaction - */ - // generateTransaction(blake160edPublicKey, 1000000000000).then(tx => { - // console.log(JSON.stringify(tx, null, 2)) - // }) + // console.log(unspentCells) /** * send transaction */ - const tx = await generateTransaction(myAddressObj.publicKeyHash, 60000000000) // generate the raw transaction with empty witnesses - const signedTx = await core.signTransaction(myAddressObj)(tx) + const toAddress = core.generateAddress("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff").value + const rawTransaction = await core.generateRawTransaction({ + fromAddress: myAddressObj.value, + toAddress, + capacity: 60000000000, + safeMode: true, + cells: unspentCells, + deps: core.config.secp256k1Dep, + isMainnet: false + }) + + const signedTx = core.signTransaction(myAddressObj)(rawTransaction) /** * to see the signed transaction */ @@ -218,7 +82,7 @@ const bootstrap = async () => { /** * to see the real transaction hash */ - // console.log(`The real transaction hash is: ${realTxHash}`) + console.log(`The real transaction hash is: ${realTxHash}`) } bootstrap() From ce1f3a4c8eec02af1dfa18bc0eec0cd635d5eb69 Mon Sep 17 00:00:00 2001 From: Keith Date: Wed, 25 Sep 2019 10:38:42 +0800 Subject: [PATCH 09/19] chore(core): update the mock data update the mock data of genesis block to ckb@v0.21.1 --- .../__mocks__/data/genesisBlock.json | 25 ++++++++----------- packages/ckb-sdk-core/__tests__/fixtures.json | 2 +- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/packages/ckb-sdk-core/__mocks__/data/genesisBlock.json b/packages/ckb-sdk-core/__mocks__/data/genesisBlock.json index dcc9f382..434e7d42 100644 --- a/packages/ckb-sdk-core/__mocks__/data/genesisBlock.json +++ b/packages/ckb-sdk-core/__mocks__/data/genesisBlock.json @@ -1,16 +1,15 @@ { "header": { "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "transactionsRoot": "0x4d4d325247a64014ae5725dd562df408299687fc4dbd16e7ebb1d0a884b3b8ea", + "transactionsRoot": "0x38b4c90bde0edb55596ec9e5cff789ecc5fadcfa1ebd62b80d1c0e0a6e4379f1", "proposalsHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "witnessesRoot": "0xfd973862f00e91dc5d54a05ef167ea92ff30a7010f98bed36d321e47a86f6b9c", + "witnessesRoot": "0x507d20cfc103c97a4a5494291dbed6379396097e42348446709a8ac6ea796cb4", "unclesHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "unclesCount": "0x0", - "chain_root": "0x0000000000000000000000000000000000000000000000000000000000000000", "dao": "0x01000000000000000000c16ff2862300009145139e840700008b54d27c7a0100", "difficulty": "0x100", "epoch": "0x0", - "hash": "0x18be8d57863c8f548c5772ed07912aaf731f367e048765f1c3c0a6f76c55c54c", + "hash": "0x7e08e99706bc47864c506f3425fadd51a7f708c45ecc6c4e2a49722ed255607c", "nonce": "0x0", "number": "0x0", "timestamp": "0x0", @@ -124,8 +123,9 @@ "capacity": "0x1c6bf52634000" } ], + "outputsData": [], "headerDeps": [], - "hash": "0x6ad2e9bddef6b99665f2cf69368a5aeb5f4d9f26615cf91b4637254980d32b0f", + "hash": "0x234abf25a6f2117021f90c165897c19890ae056ea559ebb609fbf1bfbbe3f76a", "version": "0x0", "witnesses": [ { @@ -140,14 +140,14 @@ "cellDeps": [ { "outPoint": { - "txHash": "0x6ad2e9bddef6b99665f2cf69368a5aeb5f4d9f26615cf91b4637254980d32b0f", + "txHash": "0x234abf25a6f2117021f90c165897c19890ae056ea559ebb609fbf1bfbbe3f76a", "index": "0x3" }, "depType": "code" }, { "outPoint": { - "txHash": "0x6ad2e9bddef6b99665f2cf69368a5aeb5f4d9f26615cf91b4637254980d32b0f", + "txHash": "0x234abf25a6f2117021f90c165897c19890ae056ea559ebb609fbf1bfbbe3f76a", "index": "0x1" }, "depType": "code" @@ -156,7 +156,7 @@ "inputs": [ { "previousOutput": { - "txHash": "0x6ad2e9bddef6b99665f2cf69368a5aeb5f4d9f26615cf91b4637254980d32b0f", + "txHash": "0x234abf25a6f2117021f90c165897c19890ae056ea559ebb609fbf1bfbbe3f76a", "index": "0x5" }, "since": "0x0" @@ -182,17 +182,14 @@ "capacity": "0x2b95fd500" } ], - "outputsData": [ - "0x020000006ad2e9bddef6b99665f2cf69368a5aeb5f4d9f26615cf91b4637254980d32b0f030000006ad2e9bddef6b99665f2cf69368a5aeb5f4d9f26615cf91b4637254980d32b0f01000000", - "0x020000006ad2e9bddef6b99665f2cf69368a5aeb5f4d9f26615cf91b4637254980d32b0f030000006ad2e9bddef6b99665f2cf69368a5aeb5f4d9f26615cf91b4637254980d32b0f04000000" - ], + "outputsData": [], "headerDeps": [], - "hash": "0x6347ee7ce5fc6828133590558b867097b895149a66e51cf353c361f7128e2091", + "hash": "0x5b88ad98883ba700e5f6b50bf66ca39fcea1e001efdefec691c52c91ad98bf54", "version": "0x0", "witnesses": [ { "data": [ - "0xd3e22911399a15898967cd64fabcae132046e359e1dc151bbb9e5199bfe166e056936c051cef17d6ac2d5bb1d61148d9879d5b84a1f479332e021038e6feea2c01" + "0x32ee5f643edafd72e1f8944eabf046e92ec952d1f56aaafde27f6d261e8464014590d4d906f3145133194f294d0e96b6ce36f90e19ffc0a7036d57dbb539162300" ] } ] diff --git a/packages/ckb-sdk-core/__tests__/fixtures.json b/packages/ckb-sdk-core/__tests__/fixtures.json index ab8e0754..1cea27d8 100644 --- a/packages/ckb-sdk-core/__tests__/fixtures.json +++ b/packages/ckb-sdk-core/__tests__/fixtures.json @@ -4,7 +4,7 @@ "hashType": "type", "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "outPoint": { - "txHash": "0x6347ee7ce5fc6828133590558b867097b895149a66e51cf353c361f7128e2091", + "txHash": "0x5b88ad98883ba700e5f6b50bf66ca39fcea1e001efdefec691c52c91ad98bf54", "index": "0x0" } } From 90feb9152b976218a810275af4d8c3905e608ee9 Mon Sep 17 00:00:00 2001 From: Keith Date: Wed, 25 Sep 2019 11:20:13 +0800 Subject: [PATCH 10/19] feat(utils): update the interface of utils.parseAddress remove the prefix from the parameter list BREAKING CHANGE: remove the prefix from the parameter list of utils.parseAddress --- .../ckb-sdk-core/examples/sendTransaction.js | 1 - packages/ckb-sdk-core/src/index.ts | 5 +---- .../__tests__/utils/index.test.js | 18 ++++-------------- packages/ckb-sdk-utils/src/address/index.ts | 16 ++++------------ 4 files changed, 9 insertions(+), 31 deletions(-) diff --git a/packages/ckb-sdk-core/examples/sendTransaction.js b/packages/ckb-sdk-core/examples/sendTransaction.js index 308520a8..0dd2565c 100644 --- a/packages/ckb-sdk-core/examples/sendTransaction.js +++ b/packages/ckb-sdk-core/examples/sendTransaction.js @@ -69,7 +69,6 @@ const bootstrap = async () => { safeMode: true, cells: unspentCells, deps: core.config.secp256k1Dep, - isMainnet: false }) const signedTx = core.signTransaction(myAddressObj)(rawTransaction) diff --git a/packages/ckb-sdk-core/src/index.ts b/packages/ckb-sdk-core/src/index.ts index 909aee55..d3755e56 100644 --- a/packages/ckb-sdk-core/src/index.ts +++ b/packages/ckb-sdk-core/src/index.ts @@ -208,7 +208,6 @@ class Core { safeMode = true, cells = [], deps = this.config.secp256k1Dep!, - isMainnet = false, }: { fromAddress: string toAddress: string @@ -216,11 +215,9 @@ class Core { safeMode: boolean cells: CachedCell[] deps: DepCellInfo - isMainnet: boolean }) => { - const prefix = isMainnet ? this.utils.AddressPrefix.Mainnet : this.utils.AddressPrefix.Testnet const [fromPublicKeyHash, toPublicKeyHash] = [fromAddress, toAddress].map((addr: string) => { - const addressPayload = this.utils.parseAddress(addr, prefix, 'hex') + const addressPayload = this.utils.parseAddress(addr, 'hex') return `0x${addressPayload.slice(hrpSize)}` }) diff --git a/packages/ckb-sdk-utils/__tests__/utils/index.test.js b/packages/ckb-sdk-utils/__tests__/utils/index.test.js index 1a25a281..0cb77098 100644 --- a/packages/ckb-sdk-utils/__tests__/utils/index.test.js +++ b/packages/ckb-sdk-utils/__tests__/utils/index.test.js @@ -279,34 +279,24 @@ describe('address', () => { it('parse address', () => { const fixture = { addr: 'ckt1qyqrdsefa43s6m882pcj53m4gdnj4k440axqswmu83', - prefix: 'ckt', hrp: '0100', blake160Pubkey: '36c329ed630d6ce750712a477543672adab57f4c', } - const parsedHex = parseAddress(fixture.addr, fixture.prefix, 'hex') + const parsedHex = parseAddress(fixture.addr, 'hex') expect(parsedHex).toBe(`0x${fixture.hrp}${fixture.blake160Pubkey}`) - const parsedBytes = parseAddress(fixture.addr, fixture.prefix) + const parsedBytes = parseAddress(fixture.addr, 'binary') expect(bytesToHex(parsedBytes)).toBe(`0x${fixture.hrp}${fixture.blake160Pubkey}`) }) - it('parse address with default options prefix: ckt, encode: binary', () => { + it('parse address with default options encode: binary', () => { const fixture = { addr: 'ckt1qyqrdsefa43s6m882pcj53m4gdnj4k440axqswmu83', - prefix: 'ckt', hrp: '0100', blake160Pubkey: '36c329ed630d6ce750712a477543672adab57f4c', } const parsedHex = bytesToHex(parseAddress(fixture.addr)) expect(parsedHex).toBe(`0x${fixture.hrp}${fixture.blake160Pubkey}`) - const parsedBytes = parseAddress(fixture.addr, fixture.prefix) + const parsedBytes = parseAddress(fixture.addr) expect(bytesToHex(parsedBytes)).toBe(`0x${fixture.hrp}${fixture.blake160Pubkey}`) }) - - it('parser incorrect address', () => { - const fixture = { - addr: 'ckt1qyqrdsefa43s6m882pcj53m4gdnj4k440axqswmu83', - incorrectPrefix: 'ckb', - } - expect(() => parseAddress(fixture.addr, fixture.incorrectPrefix)).toThrow('Prefix not matched') - }) }) diff --git a/packages/ckb-sdk-utils/src/address/index.ts b/packages/ckb-sdk-utils/src/address/index.ts index 0ae7d043..cf02271b 100644 --- a/packages/ckb-sdk-utils/src/address/index.ts +++ b/packages/ckb-sdk-utils/src/address/index.ts @@ -70,24 +70,16 @@ export const pubkeyToAddress = ( export declare interface ParseAddress { (address: string): Uint8Array - (address: string, prefix: AddressPrefix): Uint8Array - (address: string, prefix: AddressPrefix, encode: 'binary'): Uint8Array - (address: string, prefix: AddressPrefix, encode: 'hex'): string - (address: string, prefix: AddressPrefix, encode: 'binary' | 'hex'): Uint8Array | string + (address: string, encode: 'binary'): Uint8Array + (address: string, encode: 'hex'): string + (address: string, encode: 'binary' | 'hex'): Uint8Array | string } /** * @return addressPayload, consists of type | params | publicKeyHash * e.g. 0x | 01 | 00 | e2fa82e70b062c8644b80ad7ecf6e015e5f352f6 */ -export const parseAddress: ParseAddress = ( - address: string, - prefix: AddressPrefix = AddressPrefix.Testnet, - encode: 'binary' | 'hex' = 'binary' -): any => { +export const parseAddress: ParseAddress = (address: string, encode: 'binary' | 'hex' = 'binary'): any => { const decoded = bech32.decode(address) - if (decoded.prefix !== prefix) { - throw new Error('Prefix not matched') - } const data = bech32.fromWords(new Uint8Array(decoded.words)) return encode === 'binary' ? data : bytesToHex(data) } From c8d994bd39520bf46bc6e84e009129641354144e Mon Sep 17 00:00:00 2001 From: Keith Date: Thu, 26 Sep 2019 14:15:26 +0800 Subject: [PATCH 11/19] feat(rpc): use bigint instead of number in the interfaces of rpc methods allow bigit and forbid number type BREAKING CHANGE: use bigint instead of number in the interfaces of rpc methods --- .../__tests__/formatters/params.fixtures.json | 28 +++++++++---------- .../__tests__/formatters/params.test.js | 6 ++-- packages/ckb-sdk-rpc/src/paramsFormatter.ts | 19 +++++++------ 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/packages/ckb-sdk-rpc/__tests__/formatters/params.fixtures.json b/packages/ckb-sdk-rpc/__tests__/formatters/params.fixtures.json index d2ef010e..d66e50e7 100644 --- a/packages/ckb-sdk-rpc/__tests__/formatters/params.fixtures.json +++ b/packages/ckb-sdk-rpc/__tests__/formatters/params.fixtures.json @@ -6,15 +6,15 @@ }, { "param": 20, - "expected": "0x14" + "exception": "The number 20 should be a bigint or a hex string" }, { "param": null, - "exception": "The number null should be a number or a hex string" + "exception": "The number null should be a bigint or a hex string" }, { "param": "1", - "exception": "If the number 1 is a hex string, please prefix it with 0x" + "exception": "Hex string 1 should start with 0x" } ], "toHash": [ @@ -120,7 +120,7 @@ { "param": { "previousOutput": null, - "since": 0 + "since": "0x0" }, "expected": { "previous_output": null, @@ -297,10 +297,6 @@ "param": "0x12", "expected": "0x12" }, - { - "param": 12, - "expected": "0xc" - }, { "expected": "0x1" } @@ -311,18 +307,22 @@ "expected": "0x12" }, { - "param": 12, - "expected": "0xc" + "expected": "0x32" + }, + { + "param": 0, + "expected": "0x0" }, { - "expected": "0x32" + "param": -1, + "exception": "Page size is expected to be non-negative" }, { - "param": "-1", - "exception": "Page size is expected to be positive" + "param": 50, + "expected": "0x32" }, { - "param": "51", + "param": 51, "exception": "Page size is up to 50" } ], diff --git a/packages/ckb-sdk-rpc/__tests__/formatters/params.test.js b/packages/ckb-sdk-rpc/__tests__/formatters/params.test.js index 4681c3c8..a9f89cb9 100644 --- a/packages/ckb-sdk-rpc/__tests__/formatters/params.test.js +++ b/packages/ckb-sdk-rpc/__tests__/formatters/params.test.js @@ -21,7 +21,7 @@ describe('params formatter', () => { describe('toOptional', () => { it('toOptional with other format should return the formatted value', () => { - expect(paramsFmt.toOptional(paramsFmt.toNumber)(20)).toBe('0x14') + expect(paramsFmt.toOptional(paramsFmt.toNumber)(BigInt(20))).toBe('0x14') }) it("toOptional with other format should return the raw value if it's undefined or null", () => { @@ -34,9 +34,7 @@ describe('params formatter', () => { }) it('toOptional should throw errors which are thrown from other format', () => { - expect(() => paramsFmt.toOptional(paramsFmt.toNumber)('20')).toThrow( - 'If the number 20 is a hex string, please prefix it with 0x' - ) + expect(() => paramsFmt.toOptional(paramsFmt.toNumber)('20')).toThrow('Hex string 20 should start with 0x') }) }) }) diff --git a/packages/ckb-sdk-rpc/src/paramsFormatter.ts b/packages/ckb-sdk-rpc/src/paramsFormatter.ts index bc83230d..d0726f22 100644 --- a/packages/ckb-sdk-rpc/src/paramsFormatter.ts +++ b/packages/ckb-sdk-rpc/src/paramsFormatter.ts @@ -1,3 +1,4 @@ +import { HexStringShouldStartWith0x } from '@nervosnetwork/ckb-sdk-utils/lib/exceptions' /* eslint-disable camelcase */ const formatter = { toOptional: (format?: Function) => (arg: any) => { @@ -12,15 +13,15 @@ const formatter = { } return hash.startsWith('0x') ? hash : `0x${hash}` }, - toNumber: (number: CKBComponents.Number | number): CKB_RPC.Number => { - if (typeof number === 'number') { + toNumber: (number: CKBComponents.Number | bigint): CKB_RPC.Number => { + if (typeof number === 'bigint') { return `0x${number.toString(16)}` } if (typeof number !== 'string') { - throw new TypeError(`The number ${number} should be a number or a hex string`) + throw new TypeError(`The number ${number} should be a bigint or a hex string`) } if (!number.startsWith('0x')) { - throw new Error(`If the number ${number} is a hex string, please prefix it with 0x`) + throw new HexStringShouldStartWith0x(number) } return number }, @@ -100,11 +101,11 @@ const formatter = { } return tx }, - toPageNumber: (pageNo: string | number = '0x1') => formatter.toNumber(pageNo), - toPageSize: (pageSize: string | number = 50) => { - const size = +pageSize || 50 - if (size > 50) throw new Error('Page size is up to 50') - if (size < 0) throw new Error('Page size is expected to be positive') + toPageNumber: (pageNo: string | bigint = '0x1') => formatter.toNumber(pageNo), + toPageSize: (pageSize: string | bigint = '0x32') => { + const size = BigInt(pageSize) + if (size > BigInt(50)) throw new Error('Page size is up to 50') + if (size < BigInt(0)) throw new Error('Page size is expected to be non-negative') return formatter.toNumber(size) }, toReverseOrder: (reverse: boolean = false) => !!reverse, From 71f53b0a55fecaf9a84b79091c5072b6c1eedb7d Mon Sep 17 00:00:00 2001 From: Keith Date: Fri, 27 Sep 2019 11:48:21 +0800 Subject: [PATCH 12/19] feat(type): update the type of witness change the type of witness from { data: string[] } to string BREAKING CHANGE: change the type of witnes from { data: string[] } to string --- packages/ckb-sdk-core/__tests__/fixtures.json | 40 ++++--------------- .../generateRawTransaction/fixtures.json | 12 +----- .../src/generateRawTransaction.ts | 6 +-- packages/ckb-sdk-core/src/index.ts | 12 ++---- .../serialization/transaction/fixtures.json | 6 +-- .../utils/rawTransactionToHash.fixtures.json | 6 +-- packages/ckb-types/index.d.ts | 4 +- 7 files changed, 18 insertions(+), 68 deletions(-) diff --git a/packages/ckb-sdk-core/__tests__/fixtures.json b/packages/ckb-sdk-core/__tests__/fixtures.json index 1cea27d8..fb9ed7eb 100644 --- a/packages/ckb-sdk-core/__tests__/fixtures.json +++ b/packages/ckb-sdk-core/__tests__/fixtures.json @@ -14,29 +14,17 @@ "privateKey": "0xe79f3207ea4980b7fed79956d5934249ceac4751a4fae01a0f7c4a96884bc4e3", "message": { "transactionHash": "0xac1bb95455cdfb89b6e977568744e09b6b80e08cab9477936a09c4ca07f5b8ab", - "witnesses": [ - { - "data": [] - } - ] + "witnesses": ["0x"] }, "expected": [ - { - "data": [ - "0x2c643579e47045be050d3842ed9270151af8885e33954bddad0e53e81d1c2dbe2dc637877a8302110846ebc6a16d9148c106e25f945063ad1c4d4db2b695240800" - ] - } + "0x2c643579e47045be050d3842ed9270151af8885e33954bddad0e53e81d1c2dbe2dc637877a8302110846ebc6a16d9148c106e25f945063ad1c4d4db2b695240800" ] }, "without private key should throw an error": { "privateKey": null, "message": { "transactionHash": "0xac1bb95455cdfb89b6e977568744e09b6b80e08cab9477936a09c4ca07f5b8ab", - "witnesses": [ - { - "data": [] - } - ] + "witnesses": ["0x"] }, "exception": "Private key or address object is required" }, @@ -44,11 +32,7 @@ "privateKey": "0xe79f3207ea4980b7fed79956d5934249ceac4751a4fae01a0f7c4a96884bc4e3", "message": { "transactionHash": null, - "witnesses": [ - { - "data": [] - } - ] + "witnesses": ["0x"] }, "exception": "Transaction hash is required" } @@ -81,7 +65,7 @@ ], "outputsData": ["0x"], "version": "0x0", - "witnesses": [{ "data": [] }] + "witnesses": ["0x"] }, "expected": { "cellDeps": [], @@ -109,11 +93,7 @@ "outputsData": ["0x"], "version": "0x0", "witnesses": [ - { - "data": [ - "0x9f626950d515cb7829467646a5cab7c66c873c542a4ad4c6420fde4ea9eda14d23404d26a114a7e989bf6ca7e11d6ec8777fa4410fa88c55ace33ed7ba45f5c800" - ] - } + "0x9f626950d515cb7829467646a5cab7c66c873c542a4ad4c6420fde4ea9eda14d23404d26a114a7e989bf6ca7e11d6ec8777fa4410fa88c55ace33ed7ba45f5c800" ] } }, @@ -153,7 +133,7 @@ } ], "version": "0x0", - "witnesses": [{ "data": [] }] + "witnesses": ["0x"] }, "exception": "Private key or address object is required" }, @@ -497,11 +477,7 @@ ], "outputsData": ["0x", "0x"], "version": "0x0", - "witnesses": [ - { - "data": [] - } - ] + "witnesses": [] } } } diff --git a/packages/ckb-sdk-core/__tests__/generateRawTransaction/fixtures.json b/packages/ckb-sdk-core/__tests__/generateRawTransaction/fixtures.json index 007d9a06..73e14faa 100644 --- a/packages/ckb-sdk-core/__tests__/generateRawTransaction/fixtures.json +++ b/packages/ckb-sdk-core/__tests__/generateRawTransaction/fixtures.json @@ -241,11 +241,7 @@ ], "outputsData": ["0x", "0x"], "version": "0x0", - "witnesses": [ - { - "data": [] - } - ] + "witnesses": [] } }, "unsafe transaction": { @@ -490,11 +486,7 @@ ], "outputsData": ["0x", "0x"], "version": "0x0", - "witnesses": [ - { - "data": [] - } - ] + "witnesses": [] } } } diff --git a/packages/ckb-sdk-core/src/generateRawTransaction.ts b/packages/ckb-sdk-core/src/generateRawTransaction.ts index 2ea2c3a9..e7af4e7b 100644 --- a/packages/ckb-sdk-core/src/generateRawTransaction.ts +++ b/packages/ckb-sdk-core/src/generateRawTransaction.ts @@ -104,11 +104,7 @@ const generateRawTransaction = async ({ headerDeps: [], inputs, outputs, - witnesses: [ - { - data: [], - }, - ], + witnesses: [], outputsData, } return tx diff --git a/packages/ckb-sdk-core/src/index.ts b/packages/ckb-sdk-core/src/index.ts index d3755e56..4c8814d9 100644 --- a/packages/ckb-sdk-core/src/index.ts +++ b/packages/ckb-sdk-core/src/index.ts @@ -167,17 +167,13 @@ class Core { const addrObj = typeof key === 'string' ? this.generateAddress(key) : key const signedWitnesses = witnesses.map(witness => { - const oldData = witness.data || [] const s = this.utils.blake2b(32, null, null, this.utils.PERSONAL) + const witnessBytes = this.utils.hexToBytes(witness) s.update(this.utils.hexToBytes(transactionHash)) - oldData.forEach(datum => { - s.update(this.utils.hexToBytes(datum)) - }) + s.update(witnessBytes) const message = `0x${s.digest('hex')}` - const data = [addrObj.signRecoverable(message), ...oldData] - return { - data, - } + const data = [...this.utils.hexToBytes(addrObj.signRecoverable(message)), ...witnessBytes] + return this.utils.bytesToHex(new Uint8Array(data)) }) return signedWitnesses } diff --git a/packages/ckb-sdk-utils/__tests__/serialization/transaction/fixtures.json b/packages/ckb-sdk-utils/__tests__/serialization/transaction/fixtures.json index 85b439f8..0ca0c8ca 100644 --- a/packages/ckb-sdk-utils/__tests__/serialization/transaction/fixtures.json +++ b/packages/ckb-sdk-utils/__tests__/serialization/transaction/fixtures.json @@ -220,11 +220,7 @@ ], "outputsData": ["0x", "0x"], "witnesses": [ - { - "data": [ - "0x82df73581bcd08cb9aa270128d15e79996229ce8ea9e4f985b49fbf36762c5c37936caf3ea3784ee326f60b8992924fcf496f9503c907982525a3436f01ab32900" - ] - } + "0x82df73581bcd08cb9aa270128d15e79996229ce8ea9e4f985b49fbf36762c5c37936caf3ea3784ee326f60b8992924fcf496f9503c907982525a3436f01ab32900" ], "hash": "0x9d1bf801b235ce62812844f01381a070c0cc72876364861e00492eac1d8b54e7" }, diff --git a/packages/ckb-sdk-utils/__tests__/utils/rawTransactionToHash.fixtures.json b/packages/ckb-sdk-utils/__tests__/utils/rawTransactionToHash.fixtures.json index b2676c24..682b5e45 100644 --- a/packages/ckb-sdk-utils/__tests__/utils/rawTransactionToHash.fixtures.json +++ b/packages/ckb-sdk-utils/__tests__/utils/rawTransactionToHash.fixtures.json @@ -55,11 +55,7 @@ ], "outputsData": ["0x", "0x"], "witnesses": [ - { - "data": [ - "0x82df73581bcd08cb9aa270128d15e79996229ce8ea9e4f985b49fbf36762c5c37936caf3ea3784ee326f60b8992924fcf496f9503c907982525a3436f01ab32900" - ] - } + "0x82df73581bcd08cb9aa270128d15e79996229ce8ea9e4f985b49fbf36762c5c37936caf3ea3784ee326f60b8992924fcf496f9503c907982525a3436f01ab32900" ], "hash": "0x9d1bf801b235ce62812844f01381a070c0cc72876364861e00492eac1d8b54e7" }, diff --git a/packages/ckb-types/index.d.ts b/packages/ckb-types/index.d.ts index 7fb13c74..eff88c09 100644 --- a/packages/ckb-types/index.d.ts +++ b/packages/ckb-types/index.d.ts @@ -110,9 +110,7 @@ declare namespace CKBComponents { depType: DepType } - export interface Witness { - data: Hash[] - } + export type Witness = Bytes /** * @typedef RawTransaction, raw transaction object From 09d649ab6186f01dc4ef9a99fac2e70de160abb5 Mon Sep 17 00:00:00 2001 From: Keith Date: Fri, 27 Sep 2019 13:34:39 +0800 Subject: [PATCH 13/19] feat(type): update the type of args change the type of args from string[] to string BREAKING CHANGE: change the type of args from string[] to string --- .../ckb-sdk-core/__mocks__/data/cell.json | 2 +- .../__mocks__/data/genesisBlock.json | 87 +++++++++---------- .../ckb-sdk-core/__mocks__/data/liveCell.json | 2 +- packages/ckb-sdk-core/__tests__/fixtures.json | 42 ++++----- .../generateRawTransaction/fixtures.json | 48 +++++----- packages/ckb-sdk-core/__tests__/index.test.js | 2 +- .../src/generateRawTransaction.ts | 4 +- packages/ckb-sdk-core/src/index.ts | 4 +- .../__tests__/formatters/params.fixtures.json | 12 +-- .../__tests__/formatters/result.fixtures.json | 64 +++++++------- packages/ckb-sdk-rpc/types/CKB_RPC/index.d.ts | 2 +- .../serialization/script/fixtures.json | 22 ++--- .../serialization/transaction/fixtures.json | 39 ++++++--- .../__tests__/utils/index.test.js | 6 +- .../utils/rawTransactionToHash.fixtures.json | 8 +- .../ckb-sdk-utils/src/serialization/script.ts | 6 +- packages/ckb-types/index.d.ts | 11 ++- 17 files changed, 185 insertions(+), 176 deletions(-) diff --git a/packages/ckb-sdk-core/__mocks__/data/cell.json b/packages/ckb-sdk-core/__mocks__/data/cell.json index 3e5b348e..d4ac69b8 100644 --- a/packages/ckb-sdk-core/__mocks__/data/cell.json +++ b/packages/ckb-sdk-core/__mocks__/data/cell.json @@ -3,7 +3,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x8f67802f18390f0072b718cbde1805563d2d8b057383bf586b5ebf976d56ca5a", diff --git a/packages/ckb-sdk-core/__mocks__/data/genesisBlock.json b/packages/ckb-sdk-core/__mocks__/data/genesisBlock.json index 434e7d42..85ef27d8 100644 --- a/packages/ckb-sdk-core/__mocks__/data/genesisBlock.json +++ b/packages/ckb-sdk-core/__mocks__/data/genesisBlock.json @@ -1,15 +1,15 @@ { "header": { "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "transactionsRoot": "0x38b4c90bde0edb55596ec9e5cff789ecc5fadcfa1ebd62b80d1c0e0a6e4379f1", + "transactionsRoot": "0xd7ced5301ba283ee505e1b282e32c6fd8741f99a65560b7c6722daa8231b7d40", "proposalsHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "witnessesRoot": "0x507d20cfc103c97a4a5494291dbed6379396097e42348446709a8ac6ea796cb4", + "witnessesRoot": "0xbed05f9c5fc7f698bd067e3837b09673d43a86beb36fb1173586f6a9c73c5878", "unclesHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "unclesCount": "0x0", - "dao": "0x01000000000000000000c16ff2862300009145139e840700008b54d27c7a0100", + "dao": "0x28ef3c7ff38607000000c16ff2862300fcf149e38e00000000e3bad4847a0100", "difficulty": "0x100", "epoch": "0x0", - "hash": "0x7e08e99706bc47864c506f3425fadd51a7f708c45ecc6c4e2a49722ed255607c", + "hash": "0xe10b8035540bf0976aa991dbcc1dfb2237a81706e6848596aca8773a69efb85c", "nonce": "0x0", "number": "0x0", "timestamp": "0x0", @@ -31,93 +31,93 @@ "outputs": [ { "lock": { - "codeHash": "0xb35557e7e9854206f7bc13e3c3a7fa4cf8892c84a09237fb0aab40aab3771eee", + "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "hashType": "data", - "args": [] + "args": "0x" }, "type": null, "capacity": "0x11e1a3000" }, { "lock": { - "codeHash": "0xb35557e7e9854206f7bc13e3c3a7fa4cf8892c84a09237fb0aab40aab3771eee", + "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "hashType": "data", - "args": [] + "args": "0x" }, "type": { "codeHash": "0x00000000000000000000000000000000000000000000000000545950455f4944", "hashType": "type", - "args": ["0x8536c9d5d908bd89fc70099e4284870708b6632356aad98734fcf43f6f71c304"] + "args": "0x8536c9d5d908bd89fc70099e4284870708b6632356aad98734fcf43f6f71c304" }, - "capacity": "0x478d409d200" + "capacity": "0x47ab0e02200" }, { "lock": { - "codeHash": "0xb35557e7e9854206f7bc13e3c3a7fa4cf8892c84a09237fb0aab40aab3771eee", + "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "hashType": "data", - "args": [] + "args": "0x" }, "type": { "codeHash": "0x00000000000000000000000000000000000000000000000000545950455f4944", "hashType": "type", - "args": ["0xb2a8500929d6a1294bf9bf1bf565f549fa4a5f1316a3306ad3d4783e64bcf626"] + "args": "0xb2a8500929d6a1294bf9bf1bf565f549fa4a5f1316a3306ad3d4783e64bcf626" }, - "capacity": "0xa513b17200" + "capacity": "0xa95c6b2a00" }, { "lock": { - "codeHash": "0xb35557e7e9854206f7bc13e3c3a7fa4cf8892c84a09237fb0aab40aab3771eee", + "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "hashType": "data", - "args": [] + "args": "0x" }, "type": null, "capacity": "0x5f5f04610900" }, { "lock": { - "codeHash": "0xb35557e7e9854206f7bc13e3c3a7fa4cf8892c84a09237fb0aab40aab3771eee", + "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "hashType": "data", - "args": [] + "args": "0x" }, "type": { "codeHash": "0x00000000000000000000000000000000000000000000000000545950455f4944", "hashType": "type", - "args": ["0xd813c1b15bd79c8321ad7f5819e5d9f659a1042b72e64659a2c092be68ea9758"] + "args": "0xd813c1b15bd79c8321ad7f5819e5d9f659a1042b72e64659a2c092be68ea9758" }, - "capacity": "0x51d4cc26a00" + "capacity": "0x51f2998ba00" }, { "lock": { - "codeHash": "0xa656f172b6b45c245307aeb5a7a37a176f002f6f22e92582c58bf7ba362e4176", + "codeHash": "0xc8b0772347016713ee8039d6b1d2f4b02803abdc4ea4e95677b0c5e8ff52ea3b", "hashType": "data", - "args": ["0xb73961e46d9eb118d3de1d1e8f30b3af7bbf3160"] + "args": "0xb73961e46d9eb118d3de1d1e8f30b3af7bbf3160" }, "type": null, "capacity": "0xba43b7400" }, { "lock": { - "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "codeHash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", "hashType": "type", - "args": ["0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7"] + "args": "0xc8328aabcd9b9e8e64fbc566c4385c3bdeb219d7" }, "type": null, "capacity": "0x38d7ea4c68000" }, { "lock": { - "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "codeHash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", "hashType": "type", - "args": ["0x470dcdc5e44064909650113a274b3b36aecb6dc7"] + "args": "0x470dcdc5e44064909650113a274b3b36aecb6dc7" }, "type": null, "capacity": "0x1c6bf52634000" }, { "lock": { - "codeHash": "0x9cc3121726ed40c0ece7b43f7f28af712c7f13101f78699c5668341a52ddf280", + "codeHash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", "hashType": "type", - "args": ["0x62e907b15cbf27d5425399ebf6f0fb50ebb88f18"] + "args": "0x62e907b15cbf27d5425399ebf6f0fb50ebb88f18" }, "type": null, "capacity": "0x1c6bf52634000" @@ -125,29 +125,24 @@ ], "outputsData": [], "headerDeps": [], - "hash": "0x234abf25a6f2117021f90c165897c19890ae056ea559ebb609fbf1bfbbe3f76a", + "hash": "0x50b9240d466800a6d0b2d07e10151b3a48f44c801a0f7f22e4e033419bd69b8e", "version": "0x0", "witnesses": [ - { - "data": [ - "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df201", - "0xb2e61ff569acf041b3c2c17724e2379c581eeac3" - ] - } + "0x3500000010000000300000003100000000000000000000000000000000000000000000000000000000000000000000000100000000" ] }, { "cellDeps": [ { "outPoint": { - "txHash": "0x234abf25a6f2117021f90c165897c19890ae056ea559ebb609fbf1bfbbe3f76a", + "txHash": "0x50b9240d466800a6d0b2d07e10151b3a48f44c801a0f7f22e4e033419bd69b8e", "index": "0x3" }, "depType": "code" }, { "outPoint": { - "txHash": "0x234abf25a6f2117021f90c165897c19890ae056ea559ebb609fbf1bfbbe3f76a", + "txHash": "0x50b9240d466800a6d0b2d07e10151b3a48f44c801a0f7f22e4e033419bd69b8e", "index": "0x1" }, "depType": "code" @@ -156,7 +151,7 @@ "inputs": [ { "previousOutput": { - "txHash": "0x234abf25a6f2117021f90c165897c19890ae056ea559ebb609fbf1bfbbe3f76a", + "txHash": "0x50b9240d466800a6d0b2d07e10151b3a48f44c801a0f7f22e4e033419bd69b8e", "index": "0x5" }, "since": "0x0" @@ -165,18 +160,18 @@ "outputs": [ { "lock": { - "codeHash": "0xb35557e7e9854206f7bc13e3c3a7fa4cf8892c84a09237fb0aab40aab3771eee", + "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "hashType": "data", - "args": [] + "args": "0x" }, "type": null, "capacity": "0x2b95fd500" }, { "lock": { - "codeHash": "0xb35557e7e9854206f7bc13e3c3a7fa4cf8892c84a09237fb0aab40aab3771eee", + "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "hashType": "data", - "args": [] + "args": "0x" }, "type": null, "capacity": "0x2b95fd500" @@ -184,14 +179,10 @@ ], "outputsData": [], "headerDeps": [], - "hash": "0x5b88ad98883ba700e5f6b50bf66ca39fcea1e001efdefec691c52c91ad98bf54", + "hash": "0xe7d5ddd093bcc5909a6f441882e58906062eaf66a6ac1bcf7d7411931bc9ab72", "version": "0x0", "witnesses": [ - { - "data": [ - "0x32ee5f643edafd72e1f8944eabf046e92ec952d1f56aaafde27f6d261e8464014590d4d906f3145133194f294d0e96b6ce36f90e19ffc0a7036d57dbb539162300" - ] - } + "0x7d80ac60a3ba28cab68b20b996c5cf53338cffe58e12d1c581f6948fbd7944e16a248aa1d8b669c27d46928762305d8f742cf389a1df74dadbae718ec7de148500" ] } ], diff --git a/packages/ckb-sdk-core/__mocks__/data/liveCell.json b/packages/ckb-sdk-core/__mocks__/data/liveCell.json index 97f4326e..c2c73034 100644 --- a/packages/ckb-sdk-core/__mocks__/data/liveCell.json +++ b/packages/ckb-sdk-core/__mocks__/data/liveCell.json @@ -10,7 +10,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "type": null, "capacity": "0x1fd9e09516" diff --git a/packages/ckb-sdk-core/__tests__/fixtures.json b/packages/ckb-sdk-core/__tests__/fixtures.json index fb9ed7eb..4f113382 100644 --- a/packages/ckb-sdk-core/__tests__/fixtures.json +++ b/packages/ckb-sdk-core/__tests__/fixtures.json @@ -2,9 +2,9 @@ "loadSecp256k1Dep": { "target": { "hashType": "type", - "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", + "codeHash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", "outPoint": { - "txHash": "0x5b88ad98883ba700e5f6b50bf66ca39fcea1e001efdefec691c52c91ad98bf54", + "txHash": "0xe7d5ddd093bcc5909a6f441882e58906062eaf66a6ac1bcf7d7411931bc9ab72", "index": "0x0" } } @@ -56,7 +56,7 @@ { "capacity": "0x48c27395000", "lock": { - "args": [], + "args": "0x", "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hashType": "data" }, @@ -83,7 +83,7 @@ { "capacity": "0x48c27395000", "lock": { - "args": [], + "args": "0x", "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hashType": "data" }, @@ -93,7 +93,7 @@ "outputsData": ["0x"], "version": "0x0", "witnesses": [ - "0x9f626950d515cb7829467646a5cab7c66c873c542a4ad4c6420fde4ea9eda14d23404d26a114a7e989bf6ca7e11d6ec8777fa4410fa88c55ace33ed7ba45f5c800" + "0x993ab9cc92ea4936354155ed891a5d85a669872b9048b97c8eb05e155ddb1b4942aa3d9defffb8eb929956b2ec9eaf499d03fcf89957f1246a7ecc51b0eb002e00" ] } }, @@ -126,7 +126,7 @@ "capacity": "0x48c27395000", "data": "0x", "lock": { - "args": [], + "args": "0x", "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001" }, "type": null @@ -171,7 +171,7 @@ "capacity": "0x48c27395000", "data": "0x", "lock": { - "args": [], + "args": "0x", "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001" }, "type": null @@ -211,7 +211,7 @@ "capacity": "0x48c27395000", "data": "0x", "lock": { - "args": [], + "args": "0x", "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001" }, "type": null @@ -228,7 +228,7 @@ "script": { "codeHash": "0xb35557e7e9854206f7bc13e3c3a7fa4cf8892c84a09237fb0aab40aab3771eee", "hashType": "data", - "args": [] + "args": "0x" }, "expected": "0x9e9e450fa32ef75e7063023574f1fd3647e8eb35ff5ce9e3c04fb3056c8e37d6" } @@ -247,7 +247,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -262,7 +262,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -277,7 +277,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -292,7 +292,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -307,7 +307,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -322,7 +322,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -337,7 +337,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -352,7 +352,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -367,7 +367,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -382,7 +382,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -461,7 +461,7 @@ { "capacity": "0xb67251d5e6", "lock": { - "args": ["0xddbd7f09eb480450c1b1ed2c8696248de91c6802"], + "args": "0xddbd7f09eb480450c1b1ed2c8696248de91c6802", "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type" } @@ -469,7 +469,7 @@ { "capacity": "0x88cb4e12e", "lock": { - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"], + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type" } diff --git a/packages/ckb-sdk-core/__tests__/generateRawTransaction/fixtures.json b/packages/ckb-sdk-core/__tests__/generateRawTransaction/fixtures.json index 73e14faa..4fe9198f 100644 --- a/packages/ckb-sdk-core/__tests__/generateRawTransaction/fixtures.json +++ b/packages/ckb-sdk-core/__tests__/generateRawTransaction/fixtures.json @@ -11,7 +11,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -26,7 +26,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -41,7 +41,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -56,7 +56,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -71,7 +71,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -86,7 +86,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -101,7 +101,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -116,7 +116,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -131,7 +131,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -146,7 +146,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -225,7 +225,7 @@ { "capacity": "0xb67251d5e6", "lock": { - "args": ["0xddbd7f09eb480450c1b1ed2c8696248de91c6802"], + "args": "0xddbd7f09eb480450c1b1ed2c8696248de91c6802", "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type" } @@ -233,7 +233,7 @@ { "capacity": "0x88cb4e12e", "lock": { - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"], + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type" } @@ -256,7 +256,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -271,7 +271,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -286,7 +286,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -301,7 +301,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -316,7 +316,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -331,7 +331,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -346,7 +346,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -361,7 +361,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -376,7 +376,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -391,7 +391,7 @@ "lock": { "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type", - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"] + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6" }, "outPoint": { "txHash": "0x9160bef8b6a9e388a99184bfd8bea0e7795b487c77fe784120fb2bc3fb25d1b2", @@ -470,7 +470,7 @@ { "capacity": "0xb67251d5e6", "lock": { - "args": ["0xddbd7f09eb480450c1b1ed2c8696248de91c6802"], + "args": "0xddbd7f09eb480450c1b1ed2c8696248de91c6802", "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type" } @@ -478,7 +478,7 @@ { "capacity": "0x88cb4e12e", "lock": { - "args": ["0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6"], + "args": "0xe2fa82e70b062c8644b80ad7ecf6e015e5f352f6", "codeHash": "0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2", "hashType": "type" } diff --git a/packages/ckb-sdk-core/__tests__/index.test.js b/packages/ckb-sdk-core/__tests__/index.test.js index db4b31ea..d408ef9d 100644 --- a/packages/ckb-sdk-core/__tests__/index.test.js +++ b/packages/ckb-sdk-core/__tests__/index.test.js @@ -66,7 +66,7 @@ describe('ckb-core', () => { } it('generate lock hash', () => { const lockHash = core.generateLockHash(params.publicKeyHash, params.deps) - expect(lockHash).toBe('0xe831b2179a00307607d254b6fae904047b1fb7f2c76968f305ec27841201739a') + expect(lockHash).toBe('0x0fec94c611533c9588c8ddfed557b9024f4431a65ace4b1e7106388ddd5dd87b') }) it('lack fo deps should throw an error', () => { diff --git a/packages/ckb-sdk-core/src/generateRawTransaction.ts b/packages/ckb-sdk-core/src/generateRawTransaction.ts index e7af4e7b..c275fbdf 100644 --- a/packages/ckb-sdk-core/src/generateRawTransaction.ts +++ b/packages/ckb-sdk-core/src/generateRawTransaction.ts @@ -30,7 +30,7 @@ const generateRawTransaction = async ({ const lockScript = { codeHash: deps.codeHash, hashType: deps.hashType, - args: [fromPublicKeyHash], + args: fromPublicKeyHash, } /** @@ -41,7 +41,7 @@ const generateRawTransaction = async ({ lock: { hashType: deps.hashType, codeHash: deps.codeHash, - args: [toPublicKeyHash], + args: toPublicKeyHash, }, } diff --git a/packages/ckb-sdk-core/src/index.ts b/packages/ckb-sdk-core/src/index.ts index 4c8814d9..2dedfa4e 100644 --- a/packages/ckb-sdk-core/src/index.ts +++ b/packages/ckb-sdk-core/src/index.ts @@ -96,7 +96,7 @@ class Core { return this.utils.scriptToHash({ hashType: deps.hashType, codeHash: deps.codeHash, - args: [publicKeyHash], + args: publicKeyHash, }) } @@ -222,7 +222,7 @@ class Core { const lockHash = this.utils.scriptToHash({ codeHash: deps.codeHash, hashType: deps.hashType, - args: [fromPublicKeyHash], + args: fromPublicKeyHash, }) const cachedCells = this.cells.get(lockHash) if (cachedCells && cachedCells.length) { diff --git a/packages/ckb-sdk-rpc/__tests__/formatters/params.fixtures.json b/packages/ckb-sdk-rpc/__tests__/formatters/params.fixtures.json index d2ef010e..6ea09a49 100644 --- a/packages/ckb-sdk-rpc/__tests__/formatters/params.fixtures.json +++ b/packages/ckb-sdk-rpc/__tests__/formatters/params.fixtures.json @@ -154,7 +154,7 @@ "capacity": "0x48c27395000", "data": "0x", "lock": { - "args": [], + "args": "0x", "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hashType": "data" }, @@ -164,7 +164,7 @@ "capacity": "0x48c27395000", "data": "0x", "lock": { - "args": [], + "args": "0x", "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hash_type": "data" }, @@ -176,7 +176,7 @@ "capacity": "0x48c27395000", "data": "0x", "lock": { - "args": [], + "args": "0x", "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hashType": "data" } @@ -185,7 +185,7 @@ "capacity": "0x48c27395000", "data": "0x", "lock": { - "args": [], + "args": "0x", "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hash_type": "data" }, @@ -240,7 +240,7 @@ { "capacity": "0x48c27395000", "lock": { - "args": [], + "args": "0x", "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hashType": "data" }, @@ -279,7 +279,7 @@ { "capacity": "0x48c27395000", "lock": { - "args": [], + "args": "0x", "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hash_type": "data" }, diff --git a/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json b/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json index ccddaf6a..9ed78b76 100644 --- a/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json +++ b/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json @@ -18,12 +18,12 @@ }, { "result": { - "args": [], + "args": "0x", "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hash_type": "data" }, "expected": { - "args": [], + "args": "0x", "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hashType": "data" } @@ -60,12 +60,12 @@ "result": { "capacity": "5000000000000", "lock": { - "args": [], + "args": "0x", "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hash_type": "data" }, "type": { - "args": [], + "args": "0x", "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hash_type": "type" } @@ -73,12 +73,12 @@ "expected": { "capacity": "5000000000000", "lock": { - "args": [], + "args": "0x", "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hashType": "data" }, "type": { - "args": [], + "args": "0x", "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hashType": "type" } @@ -88,7 +88,7 @@ "result": { "capacity": "5000000000000", "lock": { - "args": [], + "args": "0x", "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hash_type": "data" }, @@ -97,7 +97,7 @@ "expected": { "capacity": "5000000000000", "lock": { - "args": [], + "args": "0x", "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hashType": "data" }, @@ -194,7 +194,7 @@ { "capacity": "5000000000000", "lock": { - "args": [], + "args": "0x", "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hash_type": "data" }, @@ -223,7 +223,7 @@ "capacity": "5000000000000", "lock": { - "args": [], + "args": "0x", "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hashType": "data" }, @@ -342,7 +342,7 @@ "capacity": "5000000000000", "lock": { - "args": [], + "args": "0x", "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hash_type": "data" }, @@ -393,7 +393,7 @@ "capacity": "5000000000000", "lock": { - "args": [], + "args": "0x", "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hashType": "data" }, @@ -656,12 +656,12 @@ "result": { "capacity": "5000000000000", "lock": { - "args": [], + "args": "0x", "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hash_type": "data" }, "type": { - "args": [], + "args": "0x", "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hash_type": "type" } @@ -669,12 +669,12 @@ "expected": { "capacity": "5000000000000", "lock": { - "args": [], + "args": "0x", "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hashType": "data" }, "type": { - "args": [], + "args": "0x", "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hashType": "type" } @@ -695,7 +695,7 @@ "output": { "capacity": "0x802665800", "lock": { - "args": [], + "args": "0x", "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "hash_type": "data" }, @@ -710,7 +710,7 @@ "output": { "capacity": "0x802665800", "lock": { - "args": [], + "args": "0x", "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "hashType": "data" }, @@ -734,7 +734,7 @@ "output": { "capacity": "0x802665800", "lock": { - "args": [], + "args": "0x", "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", "hash_type": "data" }, @@ -752,7 +752,7 @@ "output": { "capacity": "0x802665800", "lock": { - "args": [], + "args": "0x", "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000000", "hashType": "data" }, @@ -773,7 +773,7 @@ "block_hash": "0x03935a4b5e3c03a9c1deb93a39183a9a116c16cff3dc9ab129e847487da0e2b8", "lock": { "code_hash": "0x9e3b3557f11b2b3532ce352bfe8017e9fd11d154c4c7f9b7aaaa1e621b539a08", - "args": ["0x7f52f0fccdd1d11391c441adfb174f87bca612b0"], + "args": "0x7f52f0fccdd1d11391c441adfb174f87bca612b0", "hash_type": "data" }, "type": null, @@ -787,7 +787,7 @@ "blockHash": "0x03935a4b5e3c03a9c1deb93a39183a9a116c16cff3dc9ab129e847487da0e2b8", "lock": { "codeHash": "0x9e3b3557f11b2b3532ce352bfe8017e9fd11d154c4c7f9b7aaaa1e621b539a08", - "args": ["0x7f52f0fccdd1d11391c441adfb174f87bca612b0"], + "args": "0x7f52f0fccdd1d11391c441adfb174f87bca612b0", "hashType": "data" }, "type": null, @@ -810,7 +810,7 @@ "capacity": "5000000000000", "lock": { - "args": [], + "args": "0x", "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hash_type": "data" }, @@ -822,7 +822,7 @@ "capacity": "5000000000000", "lock": { - "args": [], + "args": "0x", "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hashType": "data" }, @@ -842,7 +842,7 @@ "block_hash": "0x03935a4b5e3c03a9c1deb93a39183a9a116c16cff3dc9ab129e847487da0e2b8", "lock": { "codeHash": "0x9e3b3557f11b2b3532ce352bfe8017e9fd11d154c4c7f9b7aaaa1e621b539a08", - "args": ["0x7f52f0fccdd1d11391c441adfb174f87bca612b0"], + "args": "0x7f52f0fccdd1d11391c441adfb174f87bca612b0", "hashType": "data" }, "type": null, @@ -858,7 +858,7 @@ "blockHash": "0x03935a4b5e3c03a9c1deb93a39183a9a116c16cff3dc9ab129e847487da0e2b8", "lock": { "codeHash": "0x9e3b3557f11b2b3532ce352bfe8017e9fd11d154c4c7f9b7aaaa1e621b539a08", - "args": ["0x7f52f0fccdd1d11391c441adfb174f87bca612b0"], + "args": "0x7f52f0fccdd1d11391c441adfb174f87bca612b0", "hashType": "data" }, "type": null, @@ -935,7 +935,7 @@ { "capacity": "5000000000000", "lock": { - "args": [], + "args": "0x", "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hash_type": "data" }, @@ -969,7 +969,7 @@ { "capacity": "5000000000000", "lock": { - "args": [], + "args": "0x", "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001", "hashType": "data" }, @@ -1080,7 +1080,7 @@ "cell_output": { "capacity": "50000000000000", "lock": { - "args": [], + "args": "0x", "code_hash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5" }, "type": null @@ -1095,7 +1095,7 @@ "cell_output": { "capacity": "50000000000000", "lock": { - "args": [], + "args": "0x", "code_hash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5" }, "type": null @@ -1112,7 +1112,7 @@ "cellOutput": { "capacity": "50000000000000", "lock": { - "args": [], + "args": "0x", "codeHash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5" }, "type": null @@ -1128,7 +1128,7 @@ "capacity": "50000000000000", "lock": { - "args": [], + "args": "0x", "codeHash": "0x28e83a1277d48add8e72fadaa9248559e1b632bab2bd60b27955ebc4c03800a5" }, "type": null diff --git a/packages/ckb-sdk-rpc/types/CKB_RPC/index.d.ts b/packages/ckb-sdk-rpc/types/CKB_RPC/index.d.ts index 5cff2b44..4eac08ca 100644 --- a/packages/ckb-sdk-rpc/types/CKB_RPC/index.d.ts +++ b/packages/ckb-sdk-rpc/types/CKB_RPC/index.d.ts @@ -29,7 +29,7 @@ declare module CKB_RPC { export type DepType = 'code' | 'dep_group' export interface Script { - args: Bytes[] + args: Bytes code_hash: Hash256 hash_type: ScriptHashType } diff --git a/packages/ckb-sdk-utils/__tests__/serialization/script/fixtures.json b/packages/ckb-sdk-utils/__tests__/serialization/script/fixtures.json index 30761728..12d4cede 100644 --- a/packages/ckb-sdk-utils/__tests__/serialization/script/fixtures.json +++ b/packages/ckb-sdk-utils/__tests__/serialization/script/fixtures.json @@ -1,16 +1,16 @@ { "serializeArgs": { "empty args": { - "args": [], - "expected": "0x04000000" + "args": "", + "expected": "0x00000000" }, - "args has multiple items": { - "args": ["0x10", "0x01"], - "expected": "0x160000000c0000001100000001000000100100000001" + "basic args": { + "args": "0x8536c9d5d908bd89fc70099e4284870708b6632356aad98734fcf43f6f71c304", + "expected": "0x200000008536c9d5d908bd89fc70099e4284870708b6632356aad98734fcf43f6f71c304" }, - "args has one item": { - "args": ["0x3954acece65096bfa81258983ddb83915fc56bd8"], - "expected": "0x2000000008000000140000003954acece65096bfa81258983ddb83915fc56bd8" + "args without 0x": { + "args": "8536c9d5d908bd89fc70099e4284870708b6632356aad98734fcf43f6f71c304", + "exception": "Hex string 8536c9d5d908bd89fc70099e4284870708b6632356aad98734fcf43f6f71c304 should start with 0x" } }, "serializeCodeHash": { @@ -37,17 +37,17 @@ "basic script": { "script": { "codeHash": "0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88", - "args": ["0x3954acece65096bfa81258983ddb83915fc56bd8"], + "args": "0x3954acece65096bfa81258983ddb83915fc56bd8", "hashType": "type" }, - "expected": "0x5100000010000000300000003100000068d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88012000000008000000140000003954acece65096bfa81258983ddb83915fc56bd8" + "expected": "0x4900000010000000300000003100000068d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e8801140000003954acece65096bfa81258983ddb83915fc56bd8" }, "default args should be an empty arary": { "script": { "codeHash": "0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88", "hashType": "type" }, - "expected": "0x3500000010000000300000003100000068d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e880104000000" + "expected": "0x3500000010000000300000003100000068d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e880100000000" }, "undefined script should throw an error": { "script": null, diff --git a/packages/ckb-sdk-utils/__tests__/serialization/transaction/fixtures.json b/packages/ckb-sdk-utils/__tests__/serialization/transaction/fixtures.json index 0ca0c8ca..bd16c555 100644 --- a/packages/ckb-sdk-utils/__tests__/serialization/transaction/fixtures.json +++ b/packages/ckb-sdk-utils/__tests__/serialization/transaction/fixtures.json @@ -1,4 +1,18 @@ { + "serializeArgs": { + "empty args": { + "args": "0x", + "expected": "0x" + }, + "basic args": { + "args": "0x2000000008000000140000003954acece65096bfa81258983ddb83915fc56bd8", + "expected": "0x2000000008000000140000003954acece65096bfa81258983ddb83915fc56bd8" + }, + "args without 0x": { + "args": "2000000008000000140000003954acece65096bfa81258983ddb83915fc56bd8", + "expected": "0x2000000008000000140000003954acece65096bfa81258983ddb83915fc56bd8" + } + }, "serializeVersion": { "0x0": { "version": "0x0", @@ -117,16 +131,16 @@ "capacity": "0x174876e800", "lock": { "codeHash": "0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88", - "args": ["0x59a27ef3ba84f061517d13f42cf44ed020610061"], + "args": "0x59a27ef3ba84f061517d13f42cf44ed020610061", "hashType": "type" }, "type": { "codeHash": "0xece45e0979030e2f8909f76258631c42333b1e906fd9701ec3600a464a90b8f6", - "args": [], + "args": "0x", "hashType": "data" } }, - "expected": "0x9e00000010000000180000006900000000e87648170000005100000010000000300000003100000068d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e880120000000080000001400000059a27ef3ba84f061517d13f42cf44ed02061006135000000100000003000000031000000ece45e0979030e2f8909f76258631c42333b1e906fd9701ec3600a464a90b8f60004000000" + "expected": "0x9600000010000000180000006100000000e87648170000004900000010000000300000003100000068d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88011400000059a27ef3ba84f061517d13f42cf44ed02061006135000000100000003000000031000000ece45e0979030e2f8909f76258631c42333b1e906fd9701ec3600a464a90b8f60000000000" } }, "serializeOutputs": { @@ -136,12 +150,12 @@ "capacity": "0x174876e800", "lock": { "codeHash": "0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88", - "args": ["0x59a27ef3ba84f061517d13f42cf44ed020610061"], + "args": "0x59a27ef3ba84f061517d13f42cf44ed020610061", "hashType": "type" }, "type": { "codeHash": "0xece45e0979030e2f8909f76258631c42333b1e906fd9701ec3600a464a90b8f6", - "args": [], + "args": "0x", "hashType": "data" } }, @@ -149,13 +163,13 @@ "capacity": "0x59e1416a5000", "lock": { "codeHash": "0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88", - "args": ["0x59a27ef3ba84f061517d13f42cf44ed020610061"], + "args": "0x59a27ef3ba84f061517d13f42cf44ed020610061", "hashType": "type" }, "type": null } ], - "expected": "0x130100000c000000aa0000009e00000010000000180000006900000000e87648170000005100000010000000300000003100000068d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e880120000000080000001400000059a27ef3ba84f061517d13f42cf44ed02061006135000000100000003000000031000000ece45e0979030e2f8909f76258631c42333b1e906fd9701ec3600a464a90b8f600040000006900000010000000180000006900000000506a41e15900005100000010000000300000003100000068d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e880120000000080000001400000059a27ef3ba84f061517d13f42cf44ed020610061" + "expected": "0x030100000c000000a20000009600000010000000180000006100000000e87648170000004900000010000000300000003100000068d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88011400000059a27ef3ba84f061517d13f42cf44ed02061006135000000100000003000000031000000ece45e0979030e2f8909f76258631c42333b1e906fd9701ec3600a464a90b8f600000000006100000010000000180000006100000000506a41e15900004900000010000000300000003100000068d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88011400000059a27ef3ba84f061517d13f42cf44ed020610061" } }, "serializeOutputsData": { @@ -199,12 +213,12 @@ "capacity": "0x174876e800", "lock": { "codeHash": "0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88", - "args": ["0x59a27ef3ba84f061517d13f42cf44ed020610061"], + "args": "0x59a27ef3ba84f061517d13f42cf44ed020610061", "hashType": "type" }, "type": { "codeHash": "0xece45e0979030e2f8909f76258631c42333b1e906fd9701ec3600a464a90b8f6", - "args": [], + "args": "0x", "hashType": "data" } }, @@ -212,7 +226,7 @@ "capacity": "0x59e1416a5000", "lock": { "codeHash": "0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88", - "args": ["0x59a27ef3ba84f061517d13f42cf44ed020610061"], + "args": "0x59a27ef3ba84f061517d13f42cf44ed020610061", "hashType": "type" }, "type": null @@ -221,10 +235,9 @@ "outputsData": ["0x", "0x"], "witnesses": [ "0x82df73581bcd08cb9aa270128d15e79996229ce8ea9e4f985b49fbf36762c5c37936caf3ea3784ee326f60b8992924fcf496f9503c907982525a3436f01ab32900" - ], - "hash": "0x9d1bf801b235ce62812844f01381a070c0cc72876364861e00492eac1d8b54e7" + ] }, - "expected": "0xc90100001c000000200000006e00000072000000a2000000b50100000000000002000000c12386705b5cbb312b693874f3edf45c43a274482e27b8df0fd80c8d3f5feb8b00000000010fb4945d52baf91e0dee2a686cdd9d84cad95b566a1d7409b970ee0a0f364f6002000000000000000001000000000000000000000031f695263423a4b05045dd25ce6692bb55d7bba2965d8be16b036e138e72cc6501000000130100000c000000aa0000009e00000010000000180000006900000000e87648170000005100000010000000300000003100000068d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e880120000000080000001400000059a27ef3ba84f061517d13f42cf44ed02061006135000000100000003000000031000000ece45e0979030e2f8909f76258631c42333b1e906fd9701ec3600a464a90b8f600040000006900000010000000180000006900000000506a41e15900005100000010000000300000003100000068d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e880120000000080000001400000059a27ef3ba84f061517d13f42cf44ed020610061140000000c000000100000000000000000000000" + "expected": "0xb90100001c000000200000006e00000072000000a2000000a50100000000000002000000c12386705b5cbb312b693874f3edf45c43a274482e27b8df0fd80c8d3f5feb8b00000000010fb4945d52baf91e0dee2a686cdd9d84cad95b566a1d7409b970ee0a0f364f6002000000000000000001000000000000000000000031f695263423a4b05045dd25ce6692bb55d7bba2965d8be16b036e138e72cc6501000000030100000c000000a20000009600000010000000180000006100000000e87648170000004900000010000000300000003100000068d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88011400000059a27ef3ba84f061517d13f42cf44ed02061006135000000100000003000000031000000ece45e0979030e2f8909f76258631c42333b1e906fd9701ec3600a464a90b8f600000000006100000010000000180000006100000000506a41e15900004900000010000000300000003100000068d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88011400000059a27ef3ba84f061517d13f42cf44ed020610061140000000c000000100000000000000000000000" } } } diff --git a/packages/ckb-sdk-utils/__tests__/utils/index.test.js b/packages/ckb-sdk-utils/__tests__/utils/index.test.js index 0cb77098..d712ccaa 100644 --- a/packages/ckb-sdk-utils/__tests__/utils/index.test.js +++ b/packages/ckb-sdk-utils/__tests__/utils/index.test.js @@ -150,7 +150,7 @@ describe('scriptToHash', () => { args: [], hashType: 'data', }, - scriptHash: '0xbd7e6000ffb8e983a6023809037e0c4cedbc983637c46d74621fd28e5f15fe4f', + scriptHash: '0x77c93b0632b5b6c3ef922c5b7cea208fb0a7c427a13d50e13d3fefad17e0c590', }, 'Script with hash type of data': { script: { @@ -158,7 +158,7 @@ describe('scriptToHash', () => { args: ['0x01'], hashType: 'data', }, - scriptHash: '0x5a2b913dfb1b79136fc72a575fd8e93ae080b504463c0066fea086482bfc3a94', + scriptHash: '0x67951b34bce20cb71b7e235c1f8cda259628d99d94825bffe549c23b4dd2930f', }, 'Script with hash type of type': { script: { @@ -166,7 +166,7 @@ describe('scriptToHash', () => { args: ['0x01'], hashType: 'type', }, - scriptHash: '0x3d7e565f3831955f0f5cfecdadddeef7e0d106af84ceb0c2f4dbb6ddff88c9bc', + scriptHash: '0xd39f84d4702f53cf8625da4411be1640b961715cb36816501798fedb70b6e0fb', }, } test.each(Object.keys(fixtures))('%s', fixtureName => { diff --git a/packages/ckb-sdk-utils/__tests__/utils/rawTransactionToHash.fixtures.json b/packages/ckb-sdk-utils/__tests__/utils/rawTransactionToHash.fixtures.json index 682b5e45..ce73d139 100644 --- a/packages/ckb-sdk-utils/__tests__/utils/rawTransactionToHash.fixtures.json +++ b/packages/ckb-sdk-utils/__tests__/utils/rawTransactionToHash.fixtures.json @@ -34,12 +34,12 @@ "capacity": "0x174876e800", "lock": { "codeHash": "0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88", - "args": ["0x59a27ef3ba84f061517d13f42cf44ed020610061"], + "args": "0x59a27ef3ba84f061517d13f42cf44ed020610061", "hashType": "type" }, "type": { "codeHash": "0xece45e0979030e2f8909f76258631c42333b1e906fd9701ec3600a464a90b8f6", - "args": [], + "args": "0x", "hashType": "data" } }, @@ -47,7 +47,7 @@ "capacity": "0x59e1416a5000", "lock": { "codeHash": "0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88", - "args": ["0x59a27ef3ba84f061517d13f42cf44ed020610061"], + "args": "0x59a27ef3ba84f061517d13f42cf44ed020610061", "hashType": "type" }, "type": null @@ -59,7 +59,7 @@ ], "hash": "0x9d1bf801b235ce62812844f01381a070c0cc72876364861e00492eac1d8b54e7" }, - "expected": "0x09ce2223304a5f48d5ce2b6ee2777d96503591279671460fa39ae894ea9e2b87" + "expected": "0xe765f9912b06c72552dae11779f6371309236e968aa045ae3b8f426d8ec8ca05" } ] } diff --git a/packages/ckb-sdk-utils/src/serialization/script.ts b/packages/ckb-sdk-utils/src/serialization/script.ts index b09cf04c..4a6119d0 100644 --- a/packages/ckb-sdk-utils/src/serialization/script.ts +++ b/packages/ckb-sdk-utils/src/serialization/script.ts @@ -1,4 +1,4 @@ -import { serializeDynVec, serializeArray, serializeTable, serializeFixVec } from '.' +import { serializeArray, serializeTable, serializeFixVec } from '.' import { ArgumentRequired } from '../exceptions' export const serializeCodeHash = (codeHash: CKBComponents.Hash256) => serializeArray(codeHash) @@ -9,11 +9,11 @@ export const serializeHashType = (hashType: CKBComponents.ScriptHashType) => { throw new TypeError("Hash type must be either of 'data' or 'type'") } -export const serializeArgs = (args: string[]) => serializeDynVec(args.map(arg => serializeFixVec(arg))) +export const serializeArgs = (args: string) => serializeFixVec(args) export const serializeScript = (script: CKBComponents.Script) => { if (!script) throw new ArgumentRequired('Script') - const { codeHash = '', hashType, args = [] } = script + const { codeHash = '', hashType, args = '' } = script const serializedCodeHash = serializeCodeHash(codeHash) const serializedHashType = serializeHashType(hashType) const serializedArgs = serializeArgs(args) diff --git a/packages/ckb-types/index.d.ts b/packages/ckb-types/index.d.ts index eff88c09..4c300a67 100644 --- a/packages/ckb-types/index.d.ts +++ b/packages/ckb-types/index.d.ts @@ -55,14 +55,19 @@ declare namespace CKBComponents { /* eslint-disable max-len */ /** * @typedef Script, lock or type script - * @description Script, the script model in CKB. CKB scripts use UNIX standard execution environment. Each script binary should contain a main function with the following signature `int main(int argc, char* argv[]);`. CKB will concat `signed_args` and `args`, then use the concatenated array to fill `argc/argv` part, then start the script execution. Upon termination, the executed `main` function here will provide a return code, `0` means the script execution succeeds, other values mean the execution fails. + * @description Script, the script model in CKB. CKB scripts use UNIX standard execution environment. + * Each script binary should contain a main function with the following signature `int main(int argc, char* argv[]);`. + * CKB will concat `args`, then use the concatenated array to fill `argc/argv` part, then start the script execution. + * Upon termination, the executed `main` function here will provide a return code, + * `0` means the script execution succeeds, other values mean the execution fails. * @property args, arguments. - * @property codeHash, point to its dependency, if the referred dependency is listed in the deps field in a transaction, the codeHash means the hash of the referred cell's data. + * @property codeHash, point to its dependency, if the referred dependency is listed in the deps field in a transaction, + * the codeHash means the hash of the referred cell's data. * @property hashType, a enumerate indicates the type of the code which is referened by the code hash */ /* eslint-enable max-len */ export interface Script { - args: Bytes[] + args: Bytes codeHash: Hash256 hashType: ScriptHashType } From ea3f6c51d193027db043f7916f9da9284bd5b322 Mon Sep 17 00:00:00 2001 From: Keith Date: Fri, 27 Sep 2019 13:55:17 +0800 Subject: [PATCH 14/19] test(rpc): add more tests of optional fields in formatters --- .../__tests__/formatters/params.fixtures.json | 30 +++++++++++ .../__tests__/formatters/result.fixtures.json | 54 ++++++++++++++++--- 2 files changed, 76 insertions(+), 8 deletions(-) diff --git a/packages/ckb-sdk-rpc/__tests__/formatters/params.fixtures.json b/packages/ckb-sdk-rpc/__tests__/formatters/params.fixtures.json index 6ea09a49..6c254232 100644 --- a/packages/ckb-sdk-rpc/__tests__/formatters/params.fixtures.json +++ b/packages/ckb-sdk-rpc/__tests__/formatters/params.fixtures.json @@ -191,6 +191,36 @@ }, "type": null } + }, + { + "param": { + "capacity": "0x48c27395000", + "data": "0x", + "lock": { + "args": "0x", + "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001", + "hashType": "data" + }, + "type": { + "args": "0x", + "codeHash": "0x0000000000000000000000000000000000000000000000000000000000000001", + "hashType": "data" + } + }, + "expected": { + "capacity": "0x48c27395000", + "data": "0x", + "lock": { + "args": "0x", + "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001", + "hash_type": "data" + }, + "type": { + "args": "0x", + "code_hash": "0x0000000000000000000000000000000000000000000000000000000000000001", + "hash_type": "data" + } + } } ], "toRawTransaction": [ diff --git a/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json b/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json index 9ed78b76..1a870483 100644 --- a/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json +++ b/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json @@ -34,6 +34,16 @@ "result": null, "expected": null }, + { + "result": { + "previous_output": null, + "since": "0" + }, + "expected": { + "previousOutput": null, + "since": "0" + } + }, { "result": { "previous_output": { @@ -1035,16 +1045,16 @@ { "consumed_by": null, "created_by": { - "block_number": "1", - "index": "0", + "block_number": "0x1", + "index": "0x0", "tx_hash": "0x41524669872de0ce874f926a9799b6944198571094fe94dc7ffa623a97c4f19f" } }, { "consumed_by": null, "created_by": { - "block_number": "2", - "index": "0", + "block_number": "0x2", + "index": "0x0", "tx_hash": "0x46ab01ddbbabef1af701f0843e11c7cfc0ce53f9aa9b554af74cadf8e3257d89" } } @@ -1053,20 +1063,48 @@ { "consumedBy": null, "createdBy": { - "blockNumber": "1", - "index": "0", + "blockNumber": "0x1", + "index": "0x0", "txHash": "0x41524669872de0ce874f926a9799b6944198571094fe94dc7ffa623a97c4f19f" } }, { "consumedBy": null, "createdBy": { - "blockNumber": "2", - "index": "0", + "blockNumber": "0x2", + "index": "0x0", "txHash": "0x46ab01ddbbabef1af701f0843e11c7cfc0ce53f9aa9b554af74cadf8e3257d89" } } ] + }, + { + "result": [ + { + "consumed_by": { + "block_number": "0x1", + "tx_hash": "0x41524669872de0ce874f926a9799b6944198571094fe94dc7ffa623a97c4f19f" + }, + "created_by": { + "block_number": "0x1", + "index": "0x0", + "tx_hash": "0x41524669872de0ce874f926a9799b6944198571094fe94dc7ffa623a97c4f19f" + } + } + ], + "expected": [ + { + "consumedBy": { + "blockNumber": "0x1", + "txHash": "0x41524669872de0ce874f926a9799b6944198571094fe94dc7ffa623a97c4f19f" + }, + "createdBy": { + "blockNumber": "0x1", + "index": "0x0", + "txHash": "0x41524669872de0ce874f926a9799b6944198571094fe94dc7ffa623a97c4f19f" + } + } + ] } ], "toLiveCellsByLockHash": [ From 55de626849ca31ed9e6026ef53ab2c4e9217b206 Mon Sep 17 00:00:00 2001 From: Keith Date: Sun, 29 Sep 2019 10:15:27 +0800 Subject: [PATCH 15/19] feat(type): update the fields of BlockHeader 1. remove unclesCount 2. merge witnessesRoot and transactionRoot 3. replace difficulty with compactTarget BREAKING CHANGE: 1. remove unclesCount 2. merge witnessesRoot and transactionRoot 3. replace difficulty with compactTarget --- .../__mocks__/data/genesisBlock.json | 20 +++-- packages/ckb-sdk-core/__tests__/fixtures.json | 2 +- .../__tests__/formatters/result.fixtures.json | 80 ++++++++----------- packages/ckb-sdk-rpc/src/resultFormatter.ts | 13 +-- packages/ckb-sdk-rpc/types/CKB_RPC/index.d.ts | 4 +- packages/ckb-types/index.d.ts | 8 +- 6 files changed, 47 insertions(+), 80 deletions(-) diff --git a/packages/ckb-sdk-core/__mocks__/data/genesisBlock.json b/packages/ckb-sdk-core/__mocks__/data/genesisBlock.json index 85ef27d8..52b1fcfe 100644 --- a/packages/ckb-sdk-core/__mocks__/data/genesisBlock.json +++ b/packages/ckb-sdk-core/__mocks__/data/genesisBlock.json @@ -1,15 +1,13 @@ { "header": { + "compactTarget": "0x20010000", "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "transactionsRoot": "0xd7ced5301ba283ee505e1b282e32c6fd8741f99a65560b7c6722daa8231b7d40", + "transactionsRoot": "0xec2e1c678b12fc41d312fe1e73ebe924947790cad552d0775e7657dd4d04248c", "proposalsHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "witnessesRoot": "0xbed05f9c5fc7f698bd067e3837b09673d43a86beb36fb1173586f6a9c73c5878", "unclesHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "unclesCount": "0x0", "dao": "0x28ef3c7ff38607000000c16ff2862300fcf149e38e00000000e3bad4847a0100", - "difficulty": "0x100", "epoch": "0x0", - "hash": "0xe10b8035540bf0976aa991dbcc1dfb2237a81706e6848596aca8773a69efb85c", + "hash": "0x70396940ae2e81bd2627a8e0e75f3d277585bb1afd78839cfd8f2c54e8697bbc", "nonce": "0x0", "number": "0x0", "timestamp": "0x0", @@ -125,7 +123,7 @@ ], "outputsData": [], "headerDeps": [], - "hash": "0x50b9240d466800a6d0b2d07e10151b3a48f44c801a0f7f22e4e033419bd69b8e", + "hash": "0xe8290457a1f23d4c99257150bcbc3f03efc696db6e87cc37489a3850c4b2bc52", "version": "0x0", "witnesses": [ "0x3500000010000000300000003100000000000000000000000000000000000000000000000000000000000000000000000100000000" @@ -135,14 +133,14 @@ "cellDeps": [ { "outPoint": { - "txHash": "0x50b9240d466800a6d0b2d07e10151b3a48f44c801a0f7f22e4e033419bd69b8e", + "txHash": "0xe8290457a1f23d4c99257150bcbc3f03efc696db6e87cc37489a3850c4b2bc52", "index": "0x3" }, "depType": "code" }, { "outPoint": { - "txHash": "0x50b9240d466800a6d0b2d07e10151b3a48f44c801a0f7f22e4e033419bd69b8e", + "txHash": "0xe8290457a1f23d4c99257150bcbc3f03efc696db6e87cc37489a3850c4b2bc52", "index": "0x1" }, "depType": "code" @@ -151,7 +149,7 @@ "inputs": [ { "previousOutput": { - "txHash": "0x50b9240d466800a6d0b2d07e10151b3a48f44c801a0f7f22e4e033419bd69b8e", + "txHash": "0xe8290457a1f23d4c99257150bcbc3f03efc696db6e87cc37489a3850c4b2bc52", "index": "0x5" }, "since": "0x0" @@ -179,10 +177,10 @@ ], "outputsData": [], "headerDeps": [], - "hash": "0xe7d5ddd093bcc5909a6f441882e58906062eaf66a6ac1bcf7d7411931bc9ab72", + "hash": "0xd4bad47e0b4775c4a6866424a3e3cb58c3a2a266cec407fba508541e85f18a8c", "version": "0x0", "witnesses": [ - "0x7d80ac60a3ba28cab68b20b996c5cf53338cffe58e12d1c581f6948fbd7944e16a248aa1d8b669c27d46928762305d8f742cf389a1df74dadbae718ec7de148500" + "0xc4355b739f76a74975580c36beea92009e0f0ddf0bf1309ddb7878f91cbb5b77192bce1adc6165494e3fcbc9ee3496e72c1e44336ad7b0b698847d80cab352bc01" ] } ], diff --git a/packages/ckb-sdk-core/__tests__/fixtures.json b/packages/ckb-sdk-core/__tests__/fixtures.json index 4f113382..334a0fee 100644 --- a/packages/ckb-sdk-core/__tests__/fixtures.json +++ b/packages/ckb-sdk-core/__tests__/fixtures.json @@ -4,7 +4,7 @@ "hashType": "type", "codeHash": "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8", "outPoint": { - "txHash": "0xe7d5ddd093bcc5909a6f441882e58906062eaf66a6ac1bcf7d7411931bc9ab72", + "txHash": "0xd4bad47e0b4775c4a6866424a3e3cb58c3a2a266cec407fba508541e85f18a8c", "index": "0x0" } } diff --git a/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json b/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json index 1a870483..ce3180e8 100644 --- a/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json +++ b/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json @@ -271,8 +271,8 @@ { "result": { "header": { + "compact_target": "0x1e083126", "dao": "0x010000000000000063ae2493990ab00000f0c890408900000061eb7ada030000", - "difficulty": "0x3e8", "epoch": "0", "hash": "0x0a663a245ae0b3545a24e4ec06066b9e9f0bd32e5fdbb9038ec15af59ef2593d", "number": "1024", @@ -281,17 +281,15 @@ "nonce": "0", "timestamp": "1557311767", "transactions_root": "0x64a872caca3c7b671b64897230e88dec8800b594347d192661908a87f7fbcb9b", - "uncles_count": "0", "uncles_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "version": "0", - "witnesses_root": "0x688c1ff7df5b9b454bd76a031d40e13b4e462aeee5f8497d0f9f6f1dbd5d8111" + "version": "0" }, "proposals": [] }, "expected": { "header": { + "compactTarget": "0x1e083126", "dao": "0x010000000000000063ae2493990ab00000f0c890408900000061eb7ada030000", - "difficulty": "0x3e8", "epoch": "0", "hash": "0x0a663a245ae0b3545a24e4ec06066b9e9f0bd32e5fdbb9038ec15af59ef2593d", "number": "1024", @@ -300,10 +298,8 @@ "nonce": "0", "timestamp": "1557311767", "transactionsRoot": "0x64a872caca3c7b671b64897230e88dec8800b594347d192661908a87f7fbcb9b", - "unclesCount": "0", "unclesHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "version": "0", - "witnessesRoot": "0x688c1ff7df5b9b454bd76a031d40e13b4e462aeee5f8497d0f9f6f1dbd5d8111" + "version": "0" }, "proposals": [] } @@ -317,8 +313,8 @@ { "result": { "header": { + "compact_target": "0x1e083126", "dao": "0x010000000000000063ae2493990ab00000f0c890408900000061eb7ada030000", - "difficulty": "0x3e8", "epoch": "0", "hash": "0x0a663a245ae0b3545a24e4ec06066b9e9f0bd32e5fdbb9038ec15af59ef2593d", "number": "1024", @@ -327,10 +323,8 @@ "nonce": "0", "timestamp": "1557311767", "transactions_root": "0x64a872caca3c7b671b64897230e88dec8800b594347d192661908a87f7fbcb9b", - "uncles_count": "0", "uncles_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "version": "0", - "witnesses_root": "0x688c1ff7df5b9b454bd76a031d40e13b4e462aeee5f8497d0f9f6f1dbd5d8111" + "version": "0" }, "proposals": [], "transactions": [ @@ -368,8 +362,8 @@ }, "expected": { "header": { + "compactTarget": "0x1e083126", "dao": "0x010000000000000063ae2493990ab00000f0c890408900000061eb7ada030000", - "difficulty": "0x3e8", "epoch": "0", "hash": "0x0a663a245ae0b3545a24e4ec06066b9e9f0bd32e5fdbb9038ec15af59ef2593d", "number": "1024", @@ -378,10 +372,8 @@ "nonce": "0", "timestamp": "1557311767", "transactionsRoot": "0x64a872caca3c7b671b64897230e88dec8800b594347d192661908a87f7fbcb9b", - "unclesCount": "0", "unclesHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "version": "0", - "witnessesRoot": "0x688c1ff7df5b9b454bd76a031d40e13b4e462aeee5f8497d0f9f6f1dbd5d8111" + "version": "0" }, "proposals": [], "transactions": [ @@ -421,8 +413,8 @@ { "result": { "header": { + "compact_target": "0x1e083126", "dao": "0x010000000000000063ae2493990ab00000f0c890408900000061eb7ada030000", - "difficulty": "0x3e8", "epoch": "0", "hash": "0x0a663a245ae0b3545a24e4ec06066b9e9f0bd32e5fdbb9038ec15af59ef2593d", "number": "1024", @@ -431,17 +423,15 @@ "nonce": "0", "timestamp": "1557311767", "transactions_root": "0x64a872caca3c7b671b64897230e88dec8800b594347d192661908a87f7fbcb9b", - "uncles_count": "0", "uncles_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "version": "0", - "witnesses_root": "0x688c1ff7df5b9b454bd76a031d40e13b4e462aeee5f8497d0f9f6f1dbd5d8111" + "version": "0" }, "proposals": [] }, "expected": { "header": { + "compactTarget": "0x1e083126", "dao": "0x010000000000000063ae2493990ab00000f0c890408900000061eb7ada030000", - "difficulty": "0x3e8", "epoch": "0", "hash": "0x0a663a245ae0b3545a24e4ec06066b9e9f0bd32e5fdbb9038ec15af59ef2593d", "number": "1024", @@ -450,10 +440,8 @@ "nonce": "0", "timestamp": "1557311767", "transactionsRoot": "0x64a872caca3c7b671b64897230e88dec8800b594347d192661908a87f7fbcb9b", - "unclesCount": "0", "unclesHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "version": "0", - "witnessesRoot": "0x688c1ff7df5b9b454bd76a031d40e13b4e462aeee5f8497d0f9f6f1dbd5d8111" + "version": "0" }, "proposals": [], "transactions": [], @@ -888,36 +876,32 @@ }, { "result": { - "dao": "0x01000000000000000000c16ff286230000203d88792d0000000961f400000000", - "difficulty": "0x3e8", - "epoch": "0", - "hash": "0xba0d878d2c3711d38b5ddc2bc917312ca3898cad98457cc7960e28ec31f26e7f", - "number": "1024", - "parent_hash": "0x3533d5f0882a60d3b25b7dd57002a5d9eb591e89a98231e8abc5bf48f7ee0592", + "compact_target": "0x1e083126", + "dao": "0xd040e08b93e8000039585fc1261dd700f6e18bdea63700000061eb7ada030000", + "epoch": "0x7080018000001", + "hash": "0x806b570b61df8196346faeb570fdb33fbdf833613c9a9c519f06b7f6ebed2953", + "nonce": "0x0", + "number": "0x400", + "parent_hash": "0xa607d253daae7c7c1292da49faa12fa02da44051eeaa4892286bf6fe8c6c4dd8", "proposals_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "nonce": "0", - "timestamp": "1557311767", - "transactions_root": "0x81389ffabda2d1658c75a81e390a82b335d4cb849b2269d134b042fea9cb9513", - "uncles_count": "0", + "timestamp": "0x5cd2b117", + "transactions_root": "0x7fe9a50693f3e0a7418c7a99e9a298f8d0806b149bed700bb09c1f35a63100ce", "uncles_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "version": "0", - "witnesses_root": "0xb36423f72fd5cdbf6297c189b9d74e970bf0b971a537f41b8334088afe27900a" + "version": "0x0" }, "expected": { - "dao": "0x01000000000000000000c16ff286230000203d88792d0000000961f400000000", - "difficulty": "0x3e8", - "epoch": "0", - "hash": "0xba0d878d2c3711d38b5ddc2bc917312ca3898cad98457cc7960e28ec31f26e7f", - "number": "1024", - "parentHash": "0x3533d5f0882a60d3b25b7dd57002a5d9eb591e89a98231e8abc5bf48f7ee0592", + "compactTarget": "0x1e083126", + "dao": "0xd040e08b93e8000039585fc1261dd700f6e18bdea63700000061eb7ada030000", + "epoch": "0x7080018000001", + "hash": "0x806b570b61df8196346faeb570fdb33fbdf833613c9a9c519f06b7f6ebed2953", + "nonce": "0x0", + "number": "0x400", + "parentHash": "0xa607d253daae7c7c1292da49faa12fa02da44051eeaa4892286bf6fe8c6c4dd8", "proposalsHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "nonce": "0", - "timestamp": "1557311767", - "transactionsRoot": "0x81389ffabda2d1658c75a81e390a82b335d4cb849b2269d134b042fea9cb9513", - "unclesCount": "0", + "timestamp": "0x5cd2b117", + "transactionsRoot": "0x7fe9a50693f3e0a7418c7a99e9a298f8d0806b149bed700bb09c1f35a63100ce", "unclesHash": "0x0000000000000000000000000000000000000000000000000000000000000000", - "version": "0", - "witnessesRoot": "0xb36423f72fd5cdbf6297c189b9d74e970bf0b971a537f41b8334088afe27900a" + "version": "0x0" } } ], diff --git a/packages/ckb-sdk-rpc/src/resultFormatter.ts b/packages/ckb-sdk-rpc/src/resultFormatter.ts index de340acb..57cbf49b 100644 --- a/packages/ckb-sdk-rpc/src/resultFormatter.ts +++ b/packages/ckb-sdk-rpc/src/resultFormatter.ts @@ -4,22 +4,13 @@ const formatter = { toHash: (hash: CKB_RPC.Hash256): CKBComponents.Hash256 => hash, toHeader: (header: CKB_RPC.Header): CKBComponents.BlockHeader => { if (!header) return header - const { - transactions_root, - proposals_hash, - witnesses_root, - uncles_hash, - uncles_count, - parent_hash, - ...rest - } = header + const { compact_target, transactions_root, proposals_hash, uncles_hash, parent_hash, ...rest } = header return { + compactTarget: compact_target, parentHash: parent_hash, transactionsRoot: transactions_root, proposalsHash: proposals_hash, - witnessesRoot: witnesses_root, unclesHash: uncles_hash, - unclesCount: uncles_count, ...rest, } }, diff --git a/packages/ckb-sdk-rpc/types/CKB_RPC/index.d.ts b/packages/ckb-sdk-rpc/types/CKB_RPC/index.d.ts index 4eac08ca..8c590cca 100644 --- a/packages/ckb-sdk-rpc/types/CKB_RPC/index.d.ts +++ b/packages/ckb-sdk-rpc/types/CKB_RPC/index.d.ts @@ -113,8 +113,8 @@ declare module CKB_RPC { export type LiveCellsByLockHash = LiveCellByLockHash[] export interface Header { + compact_target: Hash dao: DAO - difficulty: Difficulty epoch: EpochInHeader hash: Hash256 number: BlockNumber @@ -123,9 +123,7 @@ declare module CKB_RPC { nonce: CKBComponents.Nonce timestamp: Timestamp transactions_root: Hash256 - uncles_count: Count uncles_hash: Hash256 - witnesses_root: Hash256 version: Version } diff --git a/packages/ckb-types/index.d.ts b/packages/ckb-types/index.d.ts index 4c300a67..1a28af11 100644 --- a/packages/ckb-types/index.d.ts +++ b/packages/ckb-types/index.d.ts @@ -180,8 +180,8 @@ declare namespace CKBComponents { /** * @typedef BlockHeader, header of a block + * @property compactTarget * @property dao - * @property difficulty * @property epoch * @property hash * @property number @@ -190,14 +190,12 @@ declare namespace CKBComponents { * @property nonce * @property timestamp * @property transactionsRoot - * @property unclesCount * @property unclesHash - * @property witnessesRoot * @property version */ export interface BlockHeader { + compactTarget: Hash dao: DAO - difficulty: Difficulty epoch: EpochInHeader hash: Hash256 number: BlockNumber @@ -206,9 +204,7 @@ declare namespace CKBComponents { nonce: Nonce timestamp: Timestamp transactionsRoot: Hash256 - unclesCount: Count unclesHash: Hash256 - witnessesRoot: Hash256 version: Version } From 76770f4546c5c76eb0bebafb31206af188851c08 Mon Sep 17 00:00:00 2001 From: Keith Date: Sun, 29 Sep 2019 11:06:38 +0800 Subject: [PATCH 16/19] feat(type): update the structure of Epoch replace difficulty with compactTarget BREAKING CHANGE: replace difficulty with compactTarget in Epoch --- .../ckb-sdk-rpc/__tests__/formatters/result.fixtures.json | 4 ++-- packages/ckb-sdk-rpc/src/resultFormatter.ts | 3 ++- packages/ckb-sdk-rpc/types/CKB_RPC/index.d.ts | 2 +- packages/ckb-types/index.d.ts | 2 +- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json b/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json index ce3180e8..72e44217 100644 --- a/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json +++ b/packages/ckb-sdk-rpc/__tests__/formatters/result.fixtures.json @@ -988,13 +988,13 @@ }, { "result": { - "difficulty": "0x100", + "compact_target": "0x100", "length": "1000", "number": "0", "start_number": "0" }, "expected": { - "difficulty": "0x100", + "compactTarget": "0x100", "length": "1000", "number": "0", "startNumber": "0" diff --git a/packages/ckb-sdk-rpc/src/resultFormatter.ts b/packages/ckb-sdk-rpc/src/resultFormatter.ts index 57cbf49b..3ccd1454 100644 --- a/packages/ckb-sdk-rpc/src/resultFormatter.ts +++ b/packages/ckb-sdk-rpc/src/resultFormatter.ts @@ -222,8 +222,9 @@ const formatter = { }, toEpoch: (epoch: CKB_RPC.Epoch): CKBComponents.Epoch => { if (!epoch) return epoch - const { start_number: startNumber, ...rest } = epoch + const { start_number: startNumber, compact_target: compactTarget, ...rest } = epoch return { + compactTarget, startNumber, ...rest, } diff --git a/packages/ckb-sdk-rpc/types/CKB_RPC/index.d.ts b/packages/ckb-sdk-rpc/types/CKB_RPC/index.d.ts index 8c590cca..961e6caa 100644 --- a/packages/ckb-sdk-rpc/types/CKB_RPC/index.d.ts +++ b/packages/ckb-sdk-rpc/types/CKB_RPC/index.d.ts @@ -178,7 +178,7 @@ declare module CKB_RPC { } export interface Epoch { - difficulty: string + compact_target: Hash length: string number: string start_number: string diff --git a/packages/ckb-types/index.d.ts b/packages/ckb-types/index.d.ts index 1a28af11..ec253998 100644 --- a/packages/ckb-types/index.d.ts +++ b/packages/ckb-types/index.d.ts @@ -326,7 +326,7 @@ declare namespace CKBComponents { } export interface Epoch { - difficulty: String + compactTarget: Hash length: String number: String startNumber: String From 5924749cdc66abd63ce1d60440d665bafaf3a64b Mon Sep 17 00:00:00 2001 From: Keith Date: Mon, 30 Sep 2019 09:55:56 +0800 Subject: [PATCH 17/19] chore: update package versions and changelogs --- CHANGELOG.md | 35 +++++++++++++++++++++++++++++ lerna.json | 2 +- packages/ckb-sdk-core/CHANGELOG.md | 27 ++++++++++++++++++++++ packages/ckb-sdk-core/package.json | 8 +++---- packages/ckb-sdk-rpc/CHANGELOG.md | 27 ++++++++++++++++++++++ packages/ckb-sdk-rpc/package.json | 6 ++--- packages/ckb-sdk-utils/CHANGELOG.md | 22 ++++++++++++++++++ packages/ckb-sdk-utils/package.json | 4 ++-- packages/ckb-types/CHANGELOG.md | 26 +++++++++++++++++++++ packages/ckb-types/package.json | 2 +- 10 files changed, 148 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5311fd3..e7b062e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,41 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [0.22.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.21.1...v0.22.0) (2019-10-05) + + +### Features + +* **address:** enable address to load cells and generate signed transactions ([2e5803c](https://github.com/nervosnetwork/ckb-sdk-js/commit/2e5803c)) +* **cli:** deprive this repo of the ckb-cli ([2befcff](https://github.com/nervosnetwork/ckb-sdk-js/commit/2befcff)) +* **core:** move the address module into the core module ([10dd017](https://github.com/nervosnetwork/ckb-sdk-js/commit/10dd017)) +* **rpc:** update rpc signatures ([201901d](https://github.com/nervosnetwork/ckb-sdk-js/commit/201901d)) +* **rpc:** use bigint instead of number in the interfaces of rpc methods ([c8d994b](https://github.com/nervosnetwork/ckb-sdk-js/commit/c8d994b)) +* **type:** update the fields of BlockHeader ([55de626](https://github.com/nervosnetwork/ckb-sdk-js/commit/55de626)) +* **type:** update the result of getCellsByLockHash method ([31eb97e](https://github.com/nervosnetwork/ckb-sdk-js/commit/31eb97e)) +* **type:** update the structure of Epoch ([76770f4](https://github.com/nervosnetwork/ckb-sdk-js/commit/76770f4)) +* **type:** update the type of args ([09d649a](https://github.com/nervosnetwork/ckb-sdk-js/commit/09d649a)) +* **type:** update the type of witness ([71f53b0](https://github.com/nervosnetwork/ckb-sdk-js/commit/71f53b0)) +* **utils:** update the interface of utils.parseAddress ([90feb91](https://github.com/nervosnetwork/ckb-sdk-js/commit/90feb91)) + + +### BREAKING CHANGES + +* **type:** replace difficulty with compactTarget in Epoch +* **type:** 1. remove unclesCount +2. merge witnessesRoot and transactionRoot +3. replace difficulty with compactTarget +* **type:** change the type of args from string[] to string +* **type:** change the type of witnes from { data: string[] } to string +* **rpc:** use bigint instead of number in the interfaces of rpc methods +* **utils:** remove the prefix from the parameter list of utils.parseAddress +* **core:** move the address module into the core module +* **type:** update the result of getCellsByLockHash method + + + + + ## [0.21.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.21.0...v0.21.1) (2019-09-24) diff --git a/lerna.json b/lerna.json index 83a96a33..c79555af 100644 --- a/lerna.json +++ b/lerna.json @@ -2,5 +2,5 @@ "packages": [ "packages/*" ], - "version": "0.21.1" + "version": "0.22.0" } diff --git a/packages/ckb-sdk-core/CHANGELOG.md b/packages/ckb-sdk-core/CHANGELOG.md index 7790ead7..221efd49 100644 --- a/packages/ckb-sdk-core/CHANGELOG.md +++ b/packages/ckb-sdk-core/CHANGELOG.md @@ -3,6 +3,33 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [0.22.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.21.1...v0.22.0) (2019-10-05) + + +### Features + +* **address:** enable address to load cells and generate signed transactions ([2e5803c](https://github.com/nervosnetwork/ckb-sdk-js/commit/2e5803c)) +* **core:** move the address module into the core module ([10dd017](https://github.com/nervosnetwork/ckb-sdk-js/commit/10dd017)) +* **type:** update the fields of BlockHeader ([55de626](https://github.com/nervosnetwork/ckb-sdk-js/commit/55de626)) +* **type:** update the type of args ([09d649a](https://github.com/nervosnetwork/ckb-sdk-js/commit/09d649a)) +* **type:** update the type of witness ([71f53b0](https://github.com/nervosnetwork/ckb-sdk-js/commit/71f53b0)) +* **utils:** update the interface of utils.parseAddress ([90feb91](https://github.com/nervosnetwork/ckb-sdk-js/commit/90feb91)) + + +### BREAKING CHANGES + +* **type:** 1. remove unclesCount +2. merge witnessesRoot and transactionRoot +3. replace difficulty with compactTarget +* **type:** change the type of args from string[] to string +* **type:** change the type of witnes from { data: string[] } to string +* **utils:** remove the prefix from the parameter list of utils.parseAddress +* **core:** move the address module into the core module + + + + + ## [0.21.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.21.0...v0.21.1) (2019-09-24) **Note:** Version bump only for package @nervosnetwork/ckb-sdk-core diff --git a/packages/ckb-sdk-core/package.json b/packages/ckb-sdk-core/package.json index bead533f..76257e97 100644 --- a/packages/ckb-sdk-core/package.json +++ b/packages/ckb-sdk-core/package.json @@ -1,6 +1,6 @@ { "name": "@nervosnetwork/ckb-sdk-core", - "version": "0.21.1", + "version": "0.22.0", "description": "JavaScript SDK for Nervos Network CKB Project", "author": "Nervos ", "homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme", @@ -30,9 +30,9 @@ "url": "https://github.com/nervosnetwork/ckb-sdk-js/issues" }, "dependencies": { - "@nervosnetwork/ckb-sdk-rpc": "0.21.1", - "@nervosnetwork/ckb-sdk-utils": "0.21.1", - "@nervosnetwork/ckb-types": "0.21.1" + "@nervosnetwork/ckb-sdk-rpc": "0.22.0", + "@nervosnetwork/ckb-sdk-utils": "0.22.0", + "@nervosnetwork/ckb-types": "0.22.0" }, "gitHead": "41659647a9b5376daec6a0b839ad3f3d4bbd4ff2" } diff --git a/packages/ckb-sdk-rpc/CHANGELOG.md b/packages/ckb-sdk-rpc/CHANGELOG.md index 37a3b4b6..6b97d8c0 100644 --- a/packages/ckb-sdk-rpc/CHANGELOG.md +++ b/packages/ckb-sdk-rpc/CHANGELOG.md @@ -3,6 +3,33 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [0.22.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.21.1...v0.22.0) (2019-10-05) + + +### Features + +* **rpc:** update rpc signatures ([201901d](https://github.com/nervosnetwork/ckb-sdk-js/commit/201901d)) +* **rpc:** use bigint instead of number in the interfaces of rpc methods ([c8d994b](https://github.com/nervosnetwork/ckb-sdk-js/commit/c8d994b)) +* **type:** update the fields of BlockHeader ([55de626](https://github.com/nervosnetwork/ckb-sdk-js/commit/55de626)) +* **type:** update the result of getCellsByLockHash method ([31eb97e](https://github.com/nervosnetwork/ckb-sdk-js/commit/31eb97e)) +* **type:** update the structure of Epoch ([76770f4](https://github.com/nervosnetwork/ckb-sdk-js/commit/76770f4)) +* **type:** update the type of args ([09d649a](https://github.com/nervosnetwork/ckb-sdk-js/commit/09d649a)) + + +### BREAKING CHANGES + +* **type:** replace difficulty with compactTarget in Epoch +* **type:** 1. remove unclesCount +2. merge witnessesRoot and transactionRoot +3. replace difficulty with compactTarget +* **type:** change the type of args from string[] to string +* **rpc:** use bigint instead of number in the interfaces of rpc methods +* **type:** update the result of getCellsByLockHash method + + + + + ## [0.21.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.21.0...v0.21.1) (2019-09-24) diff --git a/packages/ckb-sdk-rpc/package.json b/packages/ckb-sdk-rpc/package.json index fe915bc3..040bad0c 100644 --- a/packages/ckb-sdk-rpc/package.json +++ b/packages/ckb-sdk-rpc/package.json @@ -1,6 +1,6 @@ { "name": "@nervosnetwork/ckb-sdk-rpc", - "version": "0.21.1", + "version": "0.22.0", "description": "RPC module of @nervosnetwork/ckb-sdk-core", "author": "Nervos ", "homepage": "https://github.com/nervosnetwork/ckb-sdk-js/packages/ckb-rpc#readme", @@ -32,11 +32,11 @@ "url": "https://github.com/nervosnetwork/ckb-sdk-js/issues" }, "dependencies": { - "@nervosnetwork/ckb-sdk-utils": "0.21.1", + "@nervosnetwork/ckb-sdk-utils": "0.22.0", "axios": "0.19.0" }, "devDependencies": { - "@nervosnetwork/ckb-types": "0.21.1", + "@nervosnetwork/ckb-types": "0.22.0", "dotenv": "8.1.0" }, "gitHead": "41659647a9b5376daec6a0b839ad3f3d4bbd4ff2" diff --git a/packages/ckb-sdk-utils/CHANGELOG.md b/packages/ckb-sdk-utils/CHANGELOG.md index b95554a8..1bfc14b5 100644 --- a/packages/ckb-sdk-utils/CHANGELOG.md +++ b/packages/ckb-sdk-utils/CHANGELOG.md @@ -3,6 +3,28 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [0.22.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.21.1...v0.22.0) (2019-10-05) + + +### Features + +* **core:** move the address module into the core module ([10dd017](https://github.com/nervosnetwork/ckb-sdk-js/commit/10dd017)) +* **type:** update the type of args ([09d649a](https://github.com/nervosnetwork/ckb-sdk-js/commit/09d649a)) +* **type:** update the type of witness ([71f53b0](https://github.com/nervosnetwork/ckb-sdk-js/commit/71f53b0)) +* **utils:** update the interface of utils.parseAddress ([90feb91](https://github.com/nervosnetwork/ckb-sdk-js/commit/90feb91)) + + +### BREAKING CHANGES + +* **type:** change the type of args from string[] to string +* **type:** change the type of witnes from { data: string[] } to string +* **utils:** remove the prefix from the parameter list of utils.parseAddress +* **core:** move the address module into the core module + + + + + ## [0.21.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.21.0...v0.21.1) (2019-09-24) **Note:** Version bump only for package @nervosnetwork/ckb-sdk-utils diff --git a/packages/ckb-sdk-utils/package.json b/packages/ckb-sdk-utils/package.json index f6dc3db9..c479f2d8 100644 --- a/packages/ckb-sdk-utils/package.json +++ b/packages/ckb-sdk-utils/package.json @@ -1,6 +1,6 @@ { "name": "@nervosnetwork/ckb-sdk-utils", - "version": "0.21.1", + "version": "0.22.0", "description": "Utils module of @nervosnetwork/ckb-sdk-core", "author": "Nervos ", "homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme", @@ -30,7 +30,7 @@ "url": "https://github.com/nervosnetwork/ckb-sdk-js/issues" }, "dependencies": { - "@nervosnetwork/ckb-types": "0.21.1", + "@nervosnetwork/ckb-types": "0.22.0", "blake2b-wasm": "1.1.7", "elliptic": "6.5.1" }, diff --git a/packages/ckb-types/CHANGELOG.md b/packages/ckb-types/CHANGELOG.md index 4a154fa8..346b24ad 100644 --- a/packages/ckb-types/CHANGELOG.md +++ b/packages/ckb-types/CHANGELOG.md @@ -3,6 +3,32 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [0.22.0](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.21.1...v0.22.0) (2019-10-05) + + +### Features + +* **type:** update the fields of BlockHeader ([55de626](https://github.com/nervosnetwork/ckb-sdk-js/commit/55de626)) +* **type:** update the result of getCellsByLockHash method ([31eb97e](https://github.com/nervosnetwork/ckb-sdk-js/commit/31eb97e)) +* **type:** update the structure of Epoch ([76770f4](https://github.com/nervosnetwork/ckb-sdk-js/commit/76770f4)) +* **type:** update the type of args ([09d649a](https://github.com/nervosnetwork/ckb-sdk-js/commit/09d649a)) +* **type:** update the type of witness ([71f53b0](https://github.com/nervosnetwork/ckb-sdk-js/commit/71f53b0)) + + +### BREAKING CHANGES + +* **type:** replace difficulty with compactTarget in Epoch +* **type:** 1. remove unclesCount +2. merge witnessesRoot and transactionRoot +3. replace difficulty with compactTarget +* **type:** change the type of args from string[] to string +* **type:** change the type of witnes from { data: string[] } to string +* **type:** update the result of getCellsByLockHash method + + + + + ## [0.21.1](https://github.com/nervosnetwork/ckb-sdk-js/compare/v0.21.0...v0.21.1) (2019-09-24) diff --git a/packages/ckb-types/package.json b/packages/ckb-types/package.json index db4e6d13..cc503202 100644 --- a/packages/ckb-types/package.json +++ b/packages/ckb-types/package.json @@ -1,6 +1,6 @@ { "name": "@nervosnetwork/ckb-types", - "version": "0.21.1", + "version": "0.22.0", "description": "Type module of @nervosnetwork/ckb-sdk-core", "author": "Nervos ", "homepage": "https://github.com/nervosnetwork/ckb-sdk-js#readme", From 360e95437fad0599a10d270f1192f5bdb94887eb Mon Sep 17 00:00:00 2001 From: Keith Date: Sat, 5 Oct 2019 13:50:19 +0800 Subject: [PATCH 18/19] docs: adjust the typesettings of changelogs[skip ci] --- CHANGELOG.md | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7b062e3..3273a840 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,9 +24,10 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline ### BREAKING CHANGES * **type:** replace difficulty with compactTarget in Epoch -* **type:** 1. remove unclesCount -2. merge witnessesRoot and transactionRoot -3. replace difficulty with compactTarget +* **type:** + 1. remove unclesCount + 2. merge witnessesRoot and transactionRoot + 3. replace difficulty with compactTarget * **type:** change the type of args from string[] to string * **type:** change the type of witnes from { data: string[] } to string * **rpc:** use bigint instead of number in the interfaces of rpc methods From ad78116d9220940e251fc8d7bb16d6984b60393e Mon Sep 17 00:00:00 2001 From: Keith Date: Sat, 5 Oct 2019 14:58:49 +0800 Subject: [PATCH 19/19] chore: update lerna hashes[skip ci] --- packages/ckb-sdk-core/package.json | 2 +- packages/ckb-sdk-rpc/package.json | 2 +- packages/ckb-sdk-utils/package.json | 2 +- packages/ckb-types/package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/ckb-sdk-core/package.json b/packages/ckb-sdk-core/package.json index 76257e97..a7509641 100644 --- a/packages/ckb-sdk-core/package.json +++ b/packages/ckb-sdk-core/package.json @@ -34,5 +34,5 @@ "@nervosnetwork/ckb-sdk-utils": "0.22.0", "@nervosnetwork/ckb-types": "0.22.0" }, - "gitHead": "41659647a9b5376daec6a0b839ad3f3d4bbd4ff2" + "gitHead": "360e95437fad0599a10d270f1192f5bdb94887eb" } diff --git a/packages/ckb-sdk-rpc/package.json b/packages/ckb-sdk-rpc/package.json index 040bad0c..bebeb285 100644 --- a/packages/ckb-sdk-rpc/package.json +++ b/packages/ckb-sdk-rpc/package.json @@ -39,5 +39,5 @@ "@nervosnetwork/ckb-types": "0.22.0", "dotenv": "8.1.0" }, - "gitHead": "41659647a9b5376daec6a0b839ad3f3d4bbd4ff2" + "gitHead": "360e95437fad0599a10d270f1192f5bdb94887eb" } diff --git a/packages/ckb-sdk-utils/package.json b/packages/ckb-sdk-utils/package.json index c479f2d8..6a7b41aa 100644 --- a/packages/ckb-sdk-utils/package.json +++ b/packages/ckb-sdk-utils/package.json @@ -39,5 +39,5 @@ "@types/elliptic": "6.4.8", "@types/utf8": "2.1.6" }, - "gitHead": "41659647a9b5376daec6a0b839ad3f3d4bbd4ff2" + "gitHead": "360e95437fad0599a10d270f1192f5bdb94887eb" } diff --git a/packages/ckb-types/package.json b/packages/ckb-types/package.json index cc503202..7493ba06 100644 --- a/packages/ckb-types/package.json +++ b/packages/ckb-types/package.json @@ -23,5 +23,5 @@ "scripts": { "doc": "../../node_modules/.bin/typedoc --out docs ./index.d.ts --mode modules --includeDeclarations --excludeExternals --ignoreCompilerErrors --theme default --readme README.md" }, - "gitHead": "41659647a9b5376daec6a0b839ad3f3d4bbd4ff2" + "gitHead": "360e95437fad0599a10d270f1192f5bdb94887eb" }