Skip to content

Commit 607558b

Browse files
committed
feat: bump sdk to v0.20.0
1 parent 82e7bb4 commit 607558b

9 files changed

Lines changed: 95 additions & 96 deletions

File tree

packages/neuron-ui/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"last 2 chrome versions"
4444
],
4545
"dependencies": {
46-
"@nervosnetwork/ckb-sdk-core": "0.19.1",
46+
"@nervosnetwork/ckb-sdk-core": "0.20.0",
4747
"@uifabric/experiments": "7.10.0",
4848
"@uifabric/styling": "7.4.0",
4949
"canvg": "2.0.0",

packages/neuron-wallet/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
]
3535
},
3636
"dependencies": {
37-
"@nervosnetwork/ckb-sdk-core": "0.19.1",
38-
"@nervosnetwork/ckb-sdk-utils": "0.19.1",
37+
"@nervosnetwork/ckb-sdk-core": "0.20.0",
38+
"@nervosnetwork/ckb-sdk-utils": "0.20.0",
3939
"bn.js": "4.11.8",
4040
"chalk": "2.4.2",
4141
"electron-log": "3.0.7",
@@ -51,7 +51,7 @@
5151
"uuid": "3.3.2"
5252
},
5353
"devDependencies": {
54-
"@nervosnetwork/ckb-types": "0.19.1",
54+
"@nervosnetwork/ckb-types": "0.20.0",
5555
"@types/electron-devtools-installer": "2.2.0",
5656
"@types/elliptic": "6.4.8",
5757
"@types/sqlite3": "3.1.5",

packages/neuron-wallet/src/models/lock-utils.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { scriptToHash } from '@nervosnetwork/ckb-sdk-utils'
12
import NodeService from 'services/node'
23
import { OutPoint, Script, ScriptHashType } from 'types/cell-types'
34
import env from 'env'
@@ -65,17 +66,17 @@ export default class LockUtils {
6566
SystemScriptSubject.next({ codeHash: info.codeHash })
6667
}
6768

68-
static computeScriptHash = async (script: Script): Promise<string> => {
69+
static computeScriptHash = (script: Script): string => {
6970
const ckbScript: CKBComponents.Script = ConvertTo.toSdkScript(script)
70-
const hash: string = await (core.rpc as any).computeScriptHash(ckbScript)
71+
const hash: string = scriptToHash(ckbScript)
7172
if (!hash.startsWith('0x')) {
7273
return `0x${hash}`
7374
}
7475
return hash
7576
}
7677

7778
// use SDK lockScriptToHash
78-
static lockScriptToHash = async (lock: Script) => {
79+
static lockScriptToHash = (lock: Script) => {
7980
return LockUtils.computeScriptHash(lock)
8081
}
8182

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

9394
static async addressToLockHash(address: string, hashType: ScriptHashType = ScriptHashType.Type): Promise<string> {
9495
const lock: Script = await this.addressToLockScript(address, hashType)
95-
const lockHash: string = await this.lockScriptToHash(lock)
96+
const lockHash: string = this.lockScriptToHash(lock)
9697

9798
return lockHash
9899
}

packages/neuron-wallet/src/services/sync/check-and-save/output.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,19 @@ export default class CheckOutput {
66

77
constructor(output: Cell) {
88
this.output = output
9-
// this.calcLockHash()
9+
this.calcLockHash()
1010
}
1111

12-
public calcLockHash = async (): Promise<Cell> => {
12+
public calcLockHash = (): Cell => {
1313
if (this.output.lockHash) {
1414
return this.output
1515
}
1616

17-
this.output.lockHash = await LockUtils.lockScriptToHash(this.output.lock)
17+
this.output.lockHash = LockUtils.lockScriptToHash(this.output.lock)
1818
return this.output
1919
}
2020

2121
public checkLockHash = async (lockHashList: string[]): Promise<boolean | undefined> => {
22-
await this.calcLockHash()
2322
return lockHashList.includes(this.output.lockHash!)
2423
}
2524
}

packages/neuron-wallet/src/services/tx/transaction-persistor.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,11 @@ export class TransactionPersistor {
185185
saveType: TxSaveType
186186
): Promise<TransactionEntity> => {
187187
const tx: Transaction = transaction
188-
tx.outputs = await Promise.all(
189-
tx.outputs!.map(async o => {
190-
const output = o
191-
output.lockHash = await LockUtils.lockScriptToHash(output.lock!)
192-
return output
193-
})
194-
)
188+
tx.outputs = tx.outputs!.map(o => {
189+
const output = o
190+
output.lockHash = LockUtils.lockScriptToHash(output.lock!)
191+
return output
192+
})
195193

196194
tx.inputs = await Promise.all(
197195
tx.inputs!.map(async i => {

packages/neuron-wallet/src/services/wallets.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,10 @@ export default class WalletService {
345345
fee
346346
)
347347

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

350353
const { inputs } = tx
351354

packages/neuron-wallet/src/types/convert-to.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export default class ConvertTo {
2121
}
2222
}
2323

24-
public static toSdkTxWithoutHash = (tx: TransactionWithoutHash): any => {
24+
public static toSdkTxWithoutHash = (tx: TransactionWithoutHash): CKBComponents.RawTransaction => {
2525
const transaction = {
2626
...tx,
2727
inputs: tx.inputs!.map(input => ConvertTo.toSdkInput(input)),

packages/neuron-wallet/tests/models/lock-utils.test.ts

Lines changed: 40 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,41 @@ import LockUtils from '../../src/models/lock-utils'
33

44
const systemScript = {
55
outPoint: {
6-
txHash: '0xc640423e9c8f53855a471c66e3d915fee4f653ac7f7e82033139d25df2ad9aad',
6+
txHash: '0x74e34a76d68f5ed864c0ad139a82461ee809e981939cd9cfcd92ac0fdbb1114b',
77
index: '0',
88
},
9-
codeHash: '0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88',
9+
codeHash: '0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2',
1010
hashType: ScriptHashType.Type,
1111
}
1212

1313
describe('LockUtils Test', () => {
1414
const bob = {
1515
lockScript: {
16-
codeHash: '0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88',
16+
codeHash: '0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2',
1717
args: ['0x36c329ed630d6ce750712a477543672adab57f4c'],
1818
hashType: ScriptHashType.Type,
1919
},
20-
lockHash: '0x024b0fd0c4912e98aab6808f6474cacb1969255d526b3cac5d3bdd15962a8818',
20+
lockHash: '0xecaeea8c8581d08a3b52980272001dbf203bc6fa2afcabe7cc90cc2afff488ba',
2121
address: 'ckt1qyqrdsefa43s6m882pcj53m4gdnj4k440axqswmu83',
2222
blake160: '0x36c329ed630d6ce750712a477543672adab57f4c',
2323
}
2424

25-
// const alice = {
26-
// lockScript: {
27-
// codeHash: '0x68d5438ac952d2f584abf879527946a537e82c7f3c1cbf6d8ebf9767437d8e88',
28-
// args: ['0xe2193df51d78411601796b35b17b4f8f2cd85bd0'],
29-
// hashType: ScriptHashType.Type,
30-
// },
31-
// lockHash: '0xf7173d209ce5773a6395735288a53b7182da4a8b0aa4718123208acf37a95196',
32-
// address: 'ckt1qyqwyxfa75whssgkq9ukkdd30d8c7txct0gqfvmy2v',
33-
// blake160: '0xe2193df51d78411601796b35b17b4f8f2cd85bd0',
34-
// }
25+
const alice = {
26+
lockScript: {
27+
codeHash: '0x1892ea40d82b53c678ff88312450bbb17e164d7a3e0a90941aa58839f56f8df2',
28+
args: ['0xe2193df51d78411601796b35b17b4f8f2cd85bd0'],
29+
hashType: ScriptHashType.Type,
30+
},
31+
lockHash: '0x489306d801d54bee2d8562ae20fdc53635b568f8107bddff15bb357f520cc02c',
32+
address: 'ckt1qyqwyxfa75whssgkq9ukkdd30d8c7txct0gqfvmy2v',
33+
blake160: '0xe2193df51d78411601796b35b17b4f8f2cd85bd0',
34+
}
3535

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

40-
// expect(lockHash).toEqual(bob.lockHash)
41-
// })
39+
expect(lockHash).toEqual(bob.lockHash)
40+
})
4241

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

54-
// TODO: it need network and node
55-
// it('addressToLockHash', async () => {
56-
// const mockContractInfo = jest.fn()
57-
// mockContractInfo.mockReturnValue(systemScript)
58-
// LockUtils.systemScript = mockContractInfo.bind(LockUtils)
53+
it('addressToLockHash', async () => {
54+
const mockContractInfo = jest.fn()
55+
mockContractInfo.mockReturnValue(systemScript)
56+
LockUtils.systemScript = mockContractInfo.bind(LockUtils)
5957

60-
// const lockHash: string = await LockUtils.addressToLockHash(bob.address)
58+
const lockHash: string = await LockUtils.addressToLockHash(bob.address)
6159

62-
// expect(lockHash).toEqual(bob.lockHash)
63-
// })
60+
expect(lockHash).toEqual(bob.lockHash)
61+
})
6462

65-
// it('addressToAllLockHashes', async () => {
66-
// const mockContractInfo = jest.fn()
67-
// mockContractInfo.mockReturnValue(systemScript)
68-
// LockUtils.systemScript = mockContractInfo.bind(LockUtils)
63+
it('addressToAllLockHashes', async () => {
64+
const mockContractInfo = jest.fn()
65+
mockContractInfo.mockReturnValue(systemScript)
66+
LockUtils.systemScript = mockContractInfo.bind(LockUtils)
6967

70-
// const lockHashes: string[] = await LockUtils.addressToAllLockHashes(bob.address)
68+
const lockHashes: string[] = await LockUtils.addressToAllLockHashes(bob.address)
7169

72-
// expect(lockHashes).toEqual([bob.lockHash])
73-
// })
70+
expect(lockHashes).toEqual([bob.lockHash])
71+
})
7472

75-
// it('addressesToAllLockHashes', async () => {
76-
// const mockContractInfo = jest.fn()
77-
// mockContractInfo.mockReturnValue(systemScript)
78-
// LockUtils.systemScript = mockContractInfo.bind(LockUtils)
73+
it('addressesToAllLockHashes', async () => {
74+
const mockContractInfo = jest.fn()
75+
mockContractInfo.mockReturnValue(systemScript)
76+
LockUtils.systemScript = mockContractInfo.bind(LockUtils)
7977

80-
// const lockHashes: string[] = await LockUtils.addressesToAllLockHashes([bob.address, alice.address])
78+
const lockHashes: string[] = await LockUtils.addressesToAllLockHashes([bob.address, alice.address])
8179

82-
// const expectedResult = [bob.lockHash, alice.lockHash]
80+
const expectedResult = [bob.lockHash, alice.lockHash]
8381

84-
// expect(lockHashes).toEqual(expectedResult)
85-
// })
82+
expect(lockHashes).toEqual(expectedResult)
83+
})
8684

8785
it('lockScriptToAddress', async () => {
8886
const address: string = LockUtils.lockScriptToAddress(bob.lockScript)

yarn.lock

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2604,45 +2604,45 @@
26042604
call-me-maybe "^1.0.1"
26052605
glob-to-regexp "^0.3.0"
26062606

2607-
"@nervosnetwork/ckb-sdk-address@0.19.1":
2608-
version "0.19.1"
2609-
resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-address/-/ckb-sdk-address-0.19.1.tgz#ec1927310a88a87759010b9e0089e2fce87371f3"
2610-
integrity sha512-ZEVX49G1PoXH2+qd4KMnrbYTU4U7fF3uJww/09OIS5xP285Gqb19JBjNCY+tnRj/hSC6HLp9/UqZex1vUZWOWg==
2611-
dependencies:
2612-
"@nervosnetwork/ckb-sdk-utils" "0.19.1"
2613-
"@nervosnetwork/ckb-types" "0.19.1"
2614-
2615-
"@nervosnetwork/ckb-sdk-core@0.19.1":
2616-
version "0.19.1"
2617-
resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-core/-/ckb-sdk-core-0.19.1.tgz#23042993d083cfc21629bebf5c8270c1878df7dd"
2618-
integrity sha512-nWj2BZ4letebndIC+Ohd+eqanYJFF/FLEy1h3nhpN+jPPwKwhHNnt3QARTOOqAOBxUFIz7t6WNXFI7icvmxdTA==
2619-
dependencies:
2620-
"@nervosnetwork/ckb-sdk-address" "0.19.1"
2621-
"@nervosnetwork/ckb-sdk-rpc" "0.19.1"
2622-
"@nervosnetwork/ckb-sdk-utils" "0.19.1"
2623-
"@nervosnetwork/ckb-types" "0.19.1"
2624-
2625-
"@nervosnetwork/ckb-sdk-rpc@0.19.1":
2626-
version "0.19.1"
2627-
resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-rpc/-/ckb-sdk-rpc-0.19.1.tgz#1f6505e08d989da51a6025c7c6600aaffbce86a9"
2628-
integrity sha512-HdeoXUd4s44de9rRYKk/33pOzdfBWP83zUGbQWgFUeTPgNTKd/poCJB9PKChb1HgZENkz2aQgRyY5hObPE1pJA==
2629-
dependencies:
2630-
"@nervosnetwork/ckb-sdk-utils" "0.19.1"
2607+
"@nervosnetwork/ckb-sdk-address@0.20.0":
2608+
version "0.20.0"
2609+
resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-address/-/ckb-sdk-address-0.20.0.tgz#3de8824c860e22e185664f2f4c39001648431f56"
2610+
integrity sha512-3FEP1I/+fRVuvafD6h1adRlv/6lfbRVwpgA/XrW4jYQBqghlaBcHVZbYqVAn5HFKAcJWtk9r9Xb8avCzfjaobg==
2611+
dependencies:
2612+
"@nervosnetwork/ckb-sdk-utils" "0.20.0"
2613+
"@nervosnetwork/ckb-types" "0.20.0"
2614+
2615+
"@nervosnetwork/ckb-sdk-core@0.20.0":
2616+
version "0.20.0"
2617+
resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-core/-/ckb-sdk-core-0.20.0.tgz#c05faef381ba10f6efa246943237fe3b8aef5e16"
2618+
integrity sha512-My0xdhRZcXVzrQRk8pi00guyaf9kGaVdKhKE+oTLthyPHxAqGtbyl7sc4Fx0RNuQhVtwe1jmh6LEtPgZbqbiLw==
2619+
dependencies:
2620+
"@nervosnetwork/ckb-sdk-address" "0.20.0"
2621+
"@nervosnetwork/ckb-sdk-rpc" "0.20.0"
2622+
"@nervosnetwork/ckb-sdk-utils" "0.20.0"
2623+
"@nervosnetwork/ckb-types" "0.20.0"
2624+
2625+
"@nervosnetwork/ckb-sdk-rpc@0.20.0":
2626+
version "0.20.0"
2627+
resolved "https://registry.yarnpkg.com/@nervosnetwork/ckb-sdk-rpc/-/ckb-sdk-rpc-0.20.0.tgz#3fa2bb17f4d81e56569859c40f147eb6b53a11b4"
2628+
integrity sha512-0F6j/hop1JOTLGalX+0LsjXRKc4+4gMBV7cdSOZh9O56Qd4m1yZS+2t6+nrN9Xi9+pAC+8wkhKvGJl2B3mXBnQ==
2629+
dependencies:
2630+
"@nervosnetwork/ckb-sdk-utils" "0.20.0"
26312631
axios "0.19.0"
26322632

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

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

26472647
"@nodelib/fs.stat@^1.1.2":
26482648
version "1.1.3"

0 commit comments

Comments
 (0)