Skip to content

Commit

Permalink
feat(core): use the secp256k1 type script hash as the code hash of th…
Browse files Browse the repository at this point in the history
…e secp256k1 dep
  • Loading branch information
Keith-CY committed Aug 23, 2019
1 parent 40cdbaa commit 617487e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
6 changes: 4 additions & 2 deletions packages/ckb-sdk-core/examples/sendTransaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const bootstrap = async () => {
*/

const script = {
type: 'Data',
type: secp256k1Dep.type,
codeHash: `0x${secp256k1Dep.codeHash}`,
args: [`0x${myAddressObj.identifier}`],
}
Expand Down Expand Up @@ -117,6 +117,7 @@ const bootstrap = async () => {
const targetOutput = {
capacity: targetCapacity,
lock: {
type: secp256k1Dep.type,
codeHash: secp256k1Dep.codeHash,
args: [targetIdentifier],
},
Expand All @@ -128,7 +129,8 @@ const bootstrap = async () => {
const changeOutput = {
capacity: 0n,
lock: {
codeHash: secp256k1Dep.codeHash,
type: secp256k1Dep.type,
codeHash: `0x${secp256k1Dep.codeHash}`,
args: [`0x${myAddressObj.identifier}`],
},
}
Expand Down
11 changes: 8 additions & 3 deletions packages/ckb-sdk-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Address from '@nervosnetwork/ckb-sdk-address'
import * as utils from '@nervosnetwork/ckb-sdk-utils'

interface DepCellInfo {
type: CKBComponents.ScriptHashType
codeHash: CKBComponents.Hash256
outPoint: CKBComponents.OutPoint
}
Expand Down Expand Up @@ -90,10 +91,13 @@ class Core {
const secp256k1CodeTx = block.transactions[0]
if (!secp256k1CodeTx) throw new Error('Cannot load the transaction which has the secp256k1 code cell')
if (!secp256k1CodeTx.outputs[1]) {
throw new Error('Cannot load the secp256k1 code because the specific output is not found')
throw new Error('Cannot load the secp256k1 cell because the specific output is not found')
}
if (!secp256k1CodeTx.outputs[1].type) {
throw new Error('Secp256k1 type script not found in the cell')
}

const secp256k1CodeHash = this.utils.blake160(secp256k1CodeTx.outputsData[1], 'hex')
const secp256k1TypeHash = this.utils.scriptToHash(secp256k1CodeTx.outputs[1].type)

const secp256k1DepTx = block.transactions[1]
if (!secp256k1DepTx) throw new Error('Cannot load the transaction which has the secp256k1 dep cell')
Expand All @@ -102,7 +106,8 @@ class Core {
}

this.config.secp256k1Dep = {
codeHash: secp256k1CodeHash,
type: 'Type' as CKBComponents.ScriptHashType.Type,
codeHash: secp256k1TypeHash,
outPoint: {
txHash: secp256k1DepTx.hash.replace(/^0x/, ''),
index: '0',
Expand Down

0 comments on commit 617487e

Please sign in to comment.