Skip to content

Commit

Permalink
feat: bump sdk to v0.20.0
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Sep 7, 2019
1 parent 82e7bb4 commit 607558b
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 96 deletions.
2 changes: 1 addition & 1 deletion packages/neuron-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"last 2 chrome versions"
],
"dependencies": {
"@nervosnetwork/ckb-sdk-core": "0.19.1",
"@nervosnetwork/ckb-sdk-core": "0.20.0",
"@uifabric/experiments": "7.10.0",
"@uifabric/styling": "7.4.0",
"canvg": "2.0.0",
Expand Down
6 changes: 3 additions & 3 deletions packages/neuron-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
]
},
"dependencies": {
"@nervosnetwork/ckb-sdk-core": "0.19.1",
"@nervosnetwork/ckb-sdk-utils": "0.19.1",
"@nervosnetwork/ckb-sdk-core": "0.20.0",
"@nervosnetwork/ckb-sdk-utils": "0.20.0",
"bn.js": "4.11.8",
"chalk": "2.4.2",
"electron-log": "3.0.7",
Expand All @@ -51,7 +51,7 @@
"uuid": "3.3.2"
},
"devDependencies": {
"@nervosnetwork/ckb-types": "0.19.1",
"@nervosnetwork/ckb-types": "0.20.0",
"@types/electron-devtools-installer": "2.2.0",
"@types/elliptic": "6.4.8",
"@types/sqlite3": "3.1.5",
Expand Down
9 changes: 5 additions & 4 deletions packages/neuron-wallet/src/models/lock-utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { scriptToHash } from '@nervosnetwork/ckb-sdk-utils'
import NodeService from 'services/node'
import { OutPoint, Script, ScriptHashType } from 'types/cell-types'
import env from 'env'
Expand Down Expand Up @@ -65,17 +66,17 @@ export default class LockUtils {
SystemScriptSubject.next({ codeHash: info.codeHash })
}

static computeScriptHash = async (script: Script): Promise<string> => {
static computeScriptHash = (script: Script): string => {
const ckbScript: CKBComponents.Script = ConvertTo.toSdkScript(script)
const hash: string = await (core.rpc as any).computeScriptHash(ckbScript)
const hash: string = scriptToHash(ckbScript)
if (!hash.startsWith('0x')) {
return `0x${hash}`
}
return hash
}

// use SDK lockScriptToHash
static lockScriptToHash = async (lock: Script) => {
static lockScriptToHash = (lock: Script) => {
return LockUtils.computeScriptHash(lock)
}

Expand All @@ -92,7 +93,7 @@ export default class LockUtils {

static async addressToLockHash(address: string, hashType: ScriptHashType = ScriptHashType.Type): Promise<string> {
const lock: Script = await this.addressToLockScript(address, hashType)
const lockHash: string = await this.lockScriptToHash(lock)
const lockHash: string = this.lockScriptToHash(lock)

return lockHash
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@ export default class CheckOutput {

constructor(output: Cell) {
this.output = output
// this.calcLockHash()
this.calcLockHash()
}

public calcLockHash = async (): Promise<Cell> => {
public calcLockHash = (): Cell => {
if (this.output.lockHash) {
return this.output
}

this.output.lockHash = await LockUtils.lockScriptToHash(this.output.lock)
this.output.lockHash = LockUtils.lockScriptToHash(this.output.lock)
return this.output
}

public checkLockHash = async (lockHashList: string[]): Promise<boolean | undefined> => {
await this.calcLockHash()
return lockHashList.includes(this.output.lockHash!)
}
}
12 changes: 5 additions & 7 deletions packages/neuron-wallet/src/services/tx/transaction-persistor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,11 @@ export class TransactionPersistor {
saveType: TxSaveType
): Promise<TransactionEntity> => {
const tx: Transaction = transaction
tx.outputs = await Promise.all(
tx.outputs!.map(async o => {
const output = o
output.lockHash = await LockUtils.lockScriptToHash(output.lock!)
return output
})
)
tx.outputs = tx.outputs!.map(o => {
const output = o
output.lockHash = LockUtils.lockScriptToHash(output.lock!)
return output
})

tx.inputs = await Promise.all(
tx.inputs!.map(async i => {
Expand Down
5 changes: 4 additions & 1 deletion packages/neuron-wallet/src/services/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,10 @@ export default class WalletService {
fee
)

const txHash: string = await (core.rpc as any).computeTransactionHash(ConvertTo.toSdkTxWithoutHash(tx))
let txHash: string = await core.utils.rawTransactionToHash(ConvertTo.toSdkTxWithoutHash(tx))
if (!txHash.startsWith('0x')) {
txHash = `0x${txHash}`
}

const { inputs } = tx

Expand Down
2 changes: 1 addition & 1 deletion packages/neuron-wallet/src/types/convert-to.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default class ConvertTo {
}
}

public static toSdkTxWithoutHash = (tx: TransactionWithoutHash): any => {
public static toSdkTxWithoutHash = (tx: TransactionWithoutHash): CKBComponents.RawTransaction => {
const transaction = {
...tx,
inputs: tx.inputs!.map(input => ConvertTo.toSdkInput(input)),
Expand Down
82 changes: 40 additions & 42 deletions packages/neuron-wallet/tests/models/lock-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,41 @@ import LockUtils from '../../src/models/lock-utils'

const systemScript = {
outPoint: {
txHash: '0xc640423e9c8f53855a471c66e3d915fee4f653ac7f7e82033139d25df2ad9aad',
txHash: '0x74e34a76d68f5ed864c0ad139a82461ee809e981939cd9cfcd92ac0fdbb1114b',
index: '0',
},
codeHash: '0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88',
codeHash: '0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2',
hashType: ScriptHashType.Type,
}

describe('LockUtils Test', () => {
const bob = {
lockScript: {
codeHash: '0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88',
codeHash: '0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2',
args: ['0x36c329ed630d6ce750712a477543672adab57f4c'],
hashType: ScriptHashType.Type,
},
lockHash: '0x024b0fd0c4912e98aab6808f6474cacb1969255d526b3cac5d3bdd15962a8818',
lockHash: '0xecaeea8c8581d08a3b52980272001dbf203bc6fa2afcabe7cc90cc2afff488ba',
address: 'ckt1qyqrdsefa43s6m882pcj53m4gdnj4k440axqswmu83',
blake160: '0x36c329ed630d6ce750712a477543672adab57f4c',
}

// const alice = {
// lockScript: {
// codeHash: '0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88',
// args: ['0xe2193df51d78411601796b35b17b4f8f2cd85bd0'],
// hashType: ScriptHashType.Type,
// },
// lockHash: '0xf7173d209ce5773a6395735288a53b7182da4a8b0aa4718123208acf37a95196',
// address: 'ckt1qyqwyxfa75whssgkq9ukkdd30d8c7txct0gqfvmy2v',
// blake160: '0xe2193df51d78411601796b35b17b4f8f2cd85bd0',
// }
const alice = {
lockScript: {
codeHash: '0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2',
args: ['0xe2193df51d78411601796b35b17b4f8f2cd85bd0'],
hashType: ScriptHashType.Type,
},
lockHash: '0x489306d801d54bee2d8562ae20fdc53635b568f8107bddff15bb357f520cc02c',
address: 'ckt1qyqwyxfa75whssgkq9ukkdd30d8c7txct0gqfvmy2v',
blake160: '0xe2193df51d78411601796b35b17b4f8f2cd85bd0',
}

// TODO: it need network and node
// it('lockScriptToHash', async () => {
// const lockHash: string = await LockUtils.lockScriptToHash(bob.lockScript)
it('lockScriptToHash', async () => {
const lockHash: string = await LockUtils.lockScriptToHash(bob.lockScript)

// expect(lockHash).toEqual(bob.lockHash)
// })
expect(lockHash).toEqual(bob.lockHash)
})

// FIXME: test failed, should fix addressToLockScript
it('addressToLockScript', async () => {
Expand All @@ -51,38 +50,37 @@ describe('LockUtils Test', () => {
expect(lockScript).toEqual(bob.lockScript)
})

// TODO: it need network and node
// it('addressToLockHash', async () => {
// const mockContractInfo = jest.fn()
// mockContractInfo.mockReturnValue(systemScript)
// LockUtils.systemScript = mockContractInfo.bind(LockUtils)
it('addressToLockHash', async () => {
const mockContractInfo = jest.fn()
mockContractInfo.mockReturnValue(systemScript)
LockUtils.systemScript = mockContractInfo.bind(LockUtils)

// const lockHash: string = await LockUtils.addressToLockHash(bob.address)
const lockHash: string = await LockUtils.addressToLockHash(bob.address)

// expect(lockHash).toEqual(bob.lockHash)
// })
expect(lockHash).toEqual(bob.lockHash)
})

// it('addressToAllLockHashes', async () => {
// const mockContractInfo = jest.fn()
// mockContractInfo.mockReturnValue(systemScript)
// LockUtils.systemScript = mockContractInfo.bind(LockUtils)
it('addressToAllLockHashes', async () => {
const mockContractInfo = jest.fn()
mockContractInfo.mockReturnValue(systemScript)
LockUtils.systemScript = mockContractInfo.bind(LockUtils)

// const lockHashes: string[] = await LockUtils.addressToAllLockHashes(bob.address)
const lockHashes: string[] = await LockUtils.addressToAllLockHashes(bob.address)

// expect(lockHashes).toEqual([bob.lockHash])
// })
expect(lockHashes).toEqual([bob.lockHash])
})

// it('addressesToAllLockHashes', async () => {
// const mockContractInfo = jest.fn()
// mockContractInfo.mockReturnValue(systemScript)
// LockUtils.systemScript = mockContractInfo.bind(LockUtils)
it('addressesToAllLockHashes', async () => {
const mockContractInfo = jest.fn()
mockContractInfo.mockReturnValue(systemScript)
LockUtils.systemScript = mockContractInfo.bind(LockUtils)

// const lockHashes: string[] = await LockUtils.addressesToAllLockHashes([bob.address, alice.address])
const lockHashes: string[] = await LockUtils.addressesToAllLockHashes([bob.address, alice.address])

// const expectedResult = [bob.lockHash, alice.lockHash]
const expectedResult = [bob.lockHash, alice.lockHash]

// expect(lockHashes).toEqual(expectedResult)
// })
expect(lockHashes).toEqual(expectedResult)
})

it('lockScriptToAddress', async () => {
const address: string = LockUtils.lockScriptToAddress(bob.lockScript)
Expand Down
66 changes: 33 additions & 33 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2604,45 +2604,45 @@
call-me-maybe "^1.0.1"
glob-to-regexp "^0.3.0"

"@nervosnetwork/ckb-sdk-address@0.19.1":
version "0.19.1"
resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-address/-/ckb-sdk-address-0.19.1.tgz#ec1927310a88a87759010b9e0089e2fce87371f3"
integrity sha512-ZEVX49G1PoXH2+qd4KMnrbYTU4U7fF3uJww/09OIS5xP285Gqb19JBjNCY+tnRj/hSC6HLp9/UqZex1vUZWOWg==
dependencies:
"@nervosnetwork/ckb-sdk-utils" "0.19.1"
"@nervosnetwork/ckb-types" "0.19.1"

"@nervosnetwork/ckb-sdk-core@0.19.1":
version "0.19.1"
resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-core/-/ckb-sdk-core-0.19.1.tgz#23042993d083cfc21629bebf5c8270c1878df7dd"
integrity sha512-nWj2BZ4letebndIC+Ohd+eqanYJFF/FLEy1h3nhpN+jPPwKwhHNnt3QARTOOqAOBxUFIz7t6WNXFI7icvmxdTA==
dependencies:
"@nervosnetwork/ckb-sdk-address" "0.19.1"
"@nervosnetwork/ckb-sdk-rpc" "0.19.1"
"@nervosnetwork/ckb-sdk-utils" "0.19.1"
"@nervosnetwork/ckb-types" "0.19.1"

"@nervosnetwork/ckb-sdk-rpc@0.19.1":
version "0.19.1"
resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-rpc/-/ckb-sdk-rpc-0.19.1.tgz#1f6505e08d989da51a6025c7c6600aaffbce86a9"
integrity sha512-HdeoXUd4s44de9rRYKk/33pOzdfBWP83zUGbQWgFUeTPgNTKd/poCJB9PKChb1HgZENkz2aQgRyY5hObPE1pJA==
dependencies:
"@nervosnetwork/ckb-sdk-utils" "0.19.1"
"@nervosnetwork/ckb-sdk-address@0.20.0":
version "0.20.0"
resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-address/-/ckb-sdk-address-0.20.0.tgz#3de8824c860e22e185664f2f4c39001648431f56"
integrity sha512-3FEP1I/+fRVuvafD6h1adRlv/6lfbRVwpgA/XrW4jYQBqghlaBcHVZbYqVAn5HFKAcJWtk9r9Xb8avCzfjaobg==
dependencies:
"@nervosnetwork/ckb-sdk-utils" "0.20.0"
"@nervosnetwork/ckb-types" "0.20.0"

"@nervosnetwork/ckb-sdk-core@0.20.0":
version "0.20.0"
resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-core/-/ckb-sdk-core-0.20.0.tgz#c05faef381ba10f6efa246943237fe3b8aef5e16"
integrity sha512-My0xdhRZcXVzrQRk8pi00guyaf9kGaVdKhKE+oTLthyPHxAqGtbyl7sc4Fx0RNuQhVtwe1jmh6LEtPgZbqbiLw==
dependencies:
"@nervosnetwork/ckb-sdk-address" "0.20.0"
"@nervosnetwork/ckb-sdk-rpc" "0.20.0"
"@nervosnetwork/ckb-sdk-utils" "0.20.0"
"@nervosnetwork/ckb-types" "0.20.0"

"@nervosnetwork/ckb-sdk-rpc@0.20.0":
version "0.20.0"
resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-rpc/-/ckb-sdk-rpc-0.20.0.tgz#3fa2bb17f4d81e56569859c40f147eb6b53a11b4"
integrity sha512-0F6j/hop1JOTLGalX+0LsjXRKc4+4gMBV7cdSOZh9O56Qd4m1yZS+2t6+nrN9Xi9+pAC+8wkhKvGJl2B3mXBnQ==
dependencies:
"@nervosnetwork/ckb-sdk-utils" "0.20.0"
axios "0.19.0"

"@nervosnetwork/ckb-sdk-utils@0.19.1":
version "0.19.1"
resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-utils/-/ckb-sdk-utils-0.19.1.tgz#86edd68b568596b50fd5a6801d9e52280c31376b"
integrity sha512-xRx8P9L3YBWdE4Itw/VTLENhx4xsagg5C79Jgy+E8NexuMDqEjiZD78Qz0/5LyZ3CaolsN4TwfNjRD3/5fb2kg==
"@nervosnetwork/ckb-sdk-utils@0.20.0":
version "0.20.0"
resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-utils/-/ckb-sdk-utils-0.20.0.tgz#0acbed3caef1f9c5180336efed13c6083246c7f7"
integrity sha512-CGXQFCSyZFTtF9yDeNnk6NR9Seq5Sk1haZgLwk0jRHzmZdD/v3PQNnonOBywaVEWNKcsVXrCBJEUAvOBKeaP3g==
dependencies:
"@nervosnetwork/ckb-types" "0.19.1"
"@nervosnetwork/ckb-types" "0.20.0"
blake2b-wasm "1.1.7"
elliptic "6.4.1"

"@nervosnetwork/ckb-types@0.19.1":
version "0.19.1"
resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-types/-/ckb-types-0.19.1.tgz#4e819152b0985a6b8fdd221e6e283c898235dc20"
integrity sha512-Bdlbd2jdSGCZ27Lb0tKTWS8YT01+bLKvpk6Ypnth+nutAywGnh13EOyhXluK6WKXq6uNytBnnBac4O8mccDeVQ==
"@nervosnetwork/ckb-types@0.20.0":
version "0.20.0"
resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-types/-/ckb-types-0.20.0.tgz#d172904262011fdbc0b4970c0a34fbe2842da73e"
integrity sha512-ZqiLayu2wg1vJVt3gXXsRxwYQ/B9nur7WniCBsnQswDVs9hM5lZ628Ov50PIISOLSR//B7dxpnsr4rd/oz4yMA==

"@nodelib/fs.stat@^1.1.2":
version "1.1.3"
Expand Down

0 comments on commit 607558b

Please sign in to comment.