From 32c7a0c9867141e08f09ef53070ed3c30f642383 Mon Sep 17 00:00:00 2001 From: Keith Date: Wed, 15 Jul 2020 15:46:00 +0800 Subject: [PATCH] feat(core): remove experimental rpc 1. remove computeTransactionHash RPC; 2. remove computeScriptHash RPC; BREAKING CHANGE: computeTransactionHash and computeScriptHash are removed from the rpc list --- packages/ckb-sdk-core/__tests__/fixtures.json | 10 ------ packages/ckb-sdk-core/__tests__/index.test.js | 18 ---------- packages/ckb-sdk-core/src/index.ts | 34 +++---------------- 3 files changed, 4 insertions(+), 58 deletions(-) diff --git a/packages/ckb-sdk-core/__tests__/fixtures.json b/packages/ckb-sdk-core/__tests__/fixtures.json index 59ec8545..0b5c689d 100644 --- a/packages/ckb-sdk-core/__tests__/fixtures.json +++ b/packages/ckb-sdk-core/__tests__/fixtures.json @@ -361,16 +361,6 @@ "exception": "Witnesses is required" } }, - "computeScriptHash": { - "baisc": { - "script": { - "codeHash": "0xb35557e7e9854206f7bc13e3c3a7fa4cf8892c84a09237fb0aab40aab3771eee", - "hashType": "data", - "args": "0x" - }, - "expected": "0x9e9e450fa32ef75e7063023574f1fd3647e8eb35ff5ce9e3c04fb3056c8e37d6" - } - }, "generateRawTransaction": { "testnet": { "params": { diff --git a/packages/ckb-sdk-core/__tests__/index.test.js b/packages/ckb-sdk-core/__tests__/index.test.js index 7aa5a327..b964eca3 100644 --- a/packages/ckb-sdk-core/__tests__/index.test.js +++ b/packages/ckb-sdk-core/__tests__/index.test.js @@ -90,24 +90,6 @@ describe('ckb', () => { }) }) - describe('compute script hash', () => { - const fixtureTable = Object.entries(fixtures.computeScriptHash).map(([title, { script, expected, exception }]) => [ - title, - script, - expected, - exception, - ]) - test.each(fixtureTable)('%s', async (_title, script, expected, exception) => { - if (undefined !== exception) { - const computedHash = await ckb.rpc.computeScriptHash(script) - expect(computedHash).toBe(expected) - } - if (undefined !== exception) { - expect(ckb.rpc.computeScriptHash(script)).reject.toThrowError(exception) - } - }) - }) - describe('sign transaction', () => { const fixtureTable = Object.entries(fixtures.signTransaction).map(([title, { params, expected, exception }]) => [ title, diff --git a/packages/ckb-sdk-core/src/index.ts b/packages/ckb-sdk-core/src/index.ts index 1900e9ab..489790e8 100644 --- a/packages/ckb-sdk-core/src/index.ts +++ b/packages/ckb-sdk-core/src/index.ts @@ -50,32 +50,6 @@ class CKB { url: nodeUrl, } this.rpc = new RPC(nodeUrl) - - const computeTransactionHashMethod = { - name: 'computeTransactionHash', - method: '_compute_transaction_hash', - paramsFormatters: [this.rpc.paramsFormatter.toRawTransaction], - } - - /** - * @method computeTransactionHash - * @description this RPC is used to calculate the hash of a raw transaction - * @deprecated this RPC method has been marked as deprecated in Nervos CKB Project - */ - this.rpc.addMethod(computeTransactionHashMethod) - - const computeScriptHashMethod = { - name: 'computeScriptHash', - method: '_compute_script_hash', - paramsFormatters: [this.rpc.paramsFormatter.toScript], - } - - /** - * @method computeScriptHash - * @description this RPC is used to calculate the hash of lock/type script - * @deprecated this RPC method has been marked as deprecated in Nervos CKB Project - */ - this.rpc.addMethod(computeScriptHashMethod) } public setNode(node: URL | CKBComponents.Node): CKBComponents.Node { @@ -96,15 +70,15 @@ class CKB { public generateLockHash = ( publicKeyHash: PublicKeyHash, - deps: Omit | undefined = this.config.secp256k1Dep, + dep: Omit | undefined = this.config.secp256k1Dep, ) => { - if (!deps) { + if (!dep) { throw new ParameterRequiredException('deps') } return this.utils.scriptToHash({ - hashType: deps.hashType, - codeHash: deps.codeHash, + hashType: dep.hashType, + codeHash: dep.codeHash, args: publicKeyHash, }) }