Skip to content

Commit

Permalink
feat(core): add the RPC of computeScriptHash
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY committed Aug 21, 2019
1 parent 578eb43 commit 705f51e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/ckb-sdk-core/__tests__/ckb-core.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ describe('ckb-core', () => {
expect(signedWitnessesByAddressObject).toEqual(fixture.target)
})

it('compute script hash', async () => {
const fixture = {
script: {
codeHash: '0xb35557e7e9854206f7bc13e3c3a7fa4cf8892c84a09237fb0aab40aab3771eee',
hashType: 'Data',
args: [],
},
scriptHash: '0xeb69f265382eb9d5139be8c918e51f2ab65027c975db60f90130735776b4751e',
}
const camputedHash = await core.rpc.computeScriptHash(fixture.script)
expect(camputedHash).toBe(fixture.scriptHash)
})

it('sign transaction', async () => {
const fixture = successFixtures.signTransaction
const signedTransactionWithPrivateKey = await core.signTransaction(fixture.privateKey)(fixture.transaction)
Expand Down
13 changes: 13 additions & 0 deletions packages/ckb-sdk-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ class Core {
* @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: string | CKBComponents.Node): CKBComponents.Node {
Expand Down

0 comments on commit 705f51e

Please sign in to comment.