Skip to content

Commit

Permalink
refactor: make withdraw compatible with the light client (#2945)
Browse files Browse the repository at this point in the history
* refactor: make withdraw compatible with the light client

* test: ci failed because of unmock methods

* chore: unifying and fixing lumos version
  • Loading branch information
homura authored Nov 20, 2023
1 parent d168e73 commit 170f6e4
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 21 deletions.
17 changes: 9 additions & 8 deletions packages/neuron-wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@
]
},
"dependencies": {
"@ckb-lumos/base": "^0.21.0-next.1",
"@ckb-lumos/bi": "^0.21.0-next.1",
"@ckb-lumos/ckb-indexer": "^0.21.0-next.1",
"@ckb-lumos/codec": "^0.21.0-next.1",
"@ckb-lumos/config-manager": "^0.21.0-next.1",
"@ckb-lumos/hd": "^0.21.0-next.1",
"@ckb-lumos/helpers": "^0.21.0-next.1",
"@ckb-lumos/rpc": "^0.21.0-next.1",
"@ckb-lumos/base": "0.21.0-next.1",
"@ckb-lumos/bi": "0.21.0-next.1",
"@ckb-lumos/ckb-indexer": "0.21.0-next.1",
"@ckb-lumos/codec": "0.21.0-next.1",
"@ckb-lumos/common-scripts": "0.21.0-next.1",
"@ckb-lumos/config-manager": "0.21.0-next.1",
"@ckb-lumos/hd": "0.21.0-next.1",
"@ckb-lumos/helpers": "0.21.0-next.1",
"@ckb-lumos/rpc": "0.21.0-next.1",
"@iarna/toml": "2.2.5",
"@ledgerhq/hw-transport-node-hid": "6.27.16",
"@spore-sdk/core": "0.1.0-beta.9",
Expand Down
24 changes: 20 additions & 4 deletions packages/neuron-wallet/src/services/transaction-sender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ import { getMultisigStatus } from '../utils/multisig'
import { SignStatus } from '../models/offline-sign'
import NetworksService from './networks'
import { generateRPC } from '../utils/ckb-rpc'
import { CKBRPC } from '@ckb-lumos/rpc'
import CellsService from './cells'
import hd from '@ckb-lumos/hd'
import { getClusterCellByOutPoint } from '@spore-sdk/core'
import CellDep, { DepType } from '../models/chain/cell-dep'
import { dao } from '@ckb-lumos/common-scripts'

interface SignInfo {
witnessArgs: WitnessArgs
Expand Down Expand Up @@ -840,9 +840,25 @@ export default class TransactionSender {
withdrawBlockHash: string
): Promise<bigint> => {
const currentNetwork = NetworksService.getInstance().getCurrent()
const ckb = new CKBRPC(currentNetwork.remote)
const result = await ckb.calculateDaoMaximumWithdraw(depositOutPoint.toSDK(), withdrawBlockHash)
return BigInt(result)
const rpc = generateRPC(currentNetwork.remote, currentNetwork.type)

let tx = await rpc.getTransaction(depositOutPoint.txHash)
if (tx.txStatus.status !== 'committed') throw new Error('Transaction is not committed yet')
const depositBlockHash = tx.txStatus.blockHash

const cellOutput = tx.transaction.outputs[+depositOutPoint.index]
const cellOutputData = tx.transaction.outputsData[+depositOutPoint.index]

const [depositHeader, withDrawHeader] = await Promise.all([
rpc.getHeader(depositBlockHash),
rpc.getHeader(withdrawBlockHash),
])

return dao.calculateMaximumWithdraw(
{ outPoint: depositOutPoint.toSDK(), data: cellOutputData, cellOutput: cellOutput },
depositHeader.dao,
withDrawHeader.dao
)
}

private parseEpoch = (epoch: bigint) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,20 @@ jest.doMock('@ckb-lumos/rpc', () => {
}
})

jest.doMock('@ckb-lumos/common-scripts', () => {
return {
dao: {
calculateMaximumWithdraw: stubbedCalculateDaoMaximumWithdraw,
},
}
})

jest.doMock('utils/ckb-rpc.ts', () => ({
generateRPC() {
return {
sendTransaction: stubbedSendTransaction,
getTransaction: stubbedGetTransaction,
getHeader: stubbedGetHeader,
}
},
}))
Expand Down Expand Up @@ -802,7 +812,7 @@ describe('TransactionSender Test', () => {
}
stubbedGetHeader.mockResolvedValue(withdrawBlockHeader)

stubbedCalculateDaoMaximumWithdraw.mockResolvedValue(10300000000)
stubbedCalculateDaoMaximumWithdraw.mockResolvedValue(BigInt(10300000000))
stubbedGetNextAddress.mockReturnValue({
address: fakeAddress1,
})
Expand Down
30 changes: 22 additions & 8 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1703,7 +1703,7 @@
js-xxhash "^1.0.4"
lodash.isequal "^4.5.0"

"@ckb-lumos/[email protected]", "@ckb-lumos/base@^0.21.0-next.1":
"@ckb-lumos/[email protected]":
version "0.21.0-next.1"
resolved "https://registry.yarnpkg.com/@ckb-lumos/base/-/base-0.21.0-next.1.tgz#ad82d0147c479b84bc0e80c3e32ad6a39ee75285"
integrity sha512-dJL3pqa28oJcNfYLNOuWRIJCeWhUq9l7l2/SZItb9wIT4MX5pD0Z1tA8/s9qbvwmmsab+QGKaLCHXNNeOvS0hg==
Expand All @@ -1724,7 +1724,7 @@
dependencies:
jsbi "^4.1.0"

"@ckb-lumos/[email protected]", "@ckb-lumos/bi@^0.21.0-next.1":
"@ckb-lumos/[email protected]":
version "0.21.0-next.1"
resolved "https://registry.yarnpkg.com/@ckb-lumos/bi/-/bi-0.21.0-next.1.tgz#357b8da31882ab5e3e3f8aca54c30dd576e4544d"
integrity sha512-FaMKBbtr826upcEVYt9/K/hutxHySD21t7ut5yv8lfj6LYcg6hWjtrbCM2INVV6/8HatfAf8YV2KsNRaluyt3A==
Expand All @@ -1743,7 +1743,7 @@
cross-fetch "^3.1.5"
events "^3.3.0"

"@ckb-lumos/ckb-indexer@^0.21.0-next.1":
"@ckb-lumos/[email protected]":
version "0.21.0-next.1"
resolved "https://registry.yarnpkg.com/@ckb-lumos/ckb-indexer/-/ckb-indexer-0.21.0-next.1.tgz#bc2fd6fcd2c482040565c255d7a9f8fd9269b462"
integrity sha512-ftT8Rodv/oXIOZLfsXEOLQnHy05c8Wj3h6QasXPlZlRGMdtWrThGz+XVI6lz4VSIfVMPSbwnYT+Dv7bf8fDfdw==
Expand All @@ -1763,7 +1763,7 @@
dependencies:
"@ckb-lumos/bi" "0.20.0"

"@ckb-lumos/[email protected]", "@ckb-lumos/codec@^0.21.0-next.1":
"@ckb-lumos/[email protected]":
version "0.21.0-next.1"
resolved "https://registry.yarnpkg.com/@ckb-lumos/codec/-/codec-0.21.0-next.1.tgz#a75f5331026039799afb4f3419bea388e220d26c"
integrity sha512-b1w4wbIAbuYngNTKtu6np93EYgnmM4tb6NGdaYN0vZ3kyunlODkLWyRHyMo+FGeBdWQjBwBbmxGNyXwDxtTEGQ==
Expand All @@ -1784,6 +1784,20 @@
"@ckb-lumos/toolkit" "0.20.0"
immutable "^4.0.0-rc.12"

"@ckb-lumos/[email protected]":
version "0.21.0-next.1"
resolved "https://registry.yarnpkg.com/@ckb-lumos/common-scripts/-/common-scripts-0.21.0-next.1.tgz#92e0295f9e123f3fdfe80e02706cc08c6310ffca"
integrity sha512-KhnWbNY1fNKTxp9CR4GAGyWsjjN1eOvidNLFwltLY03n8er2jtoHRbx3t944fIhUMtIwUVkWBi43SqpUCgSJbw==
dependencies:
"@ckb-lumos/base" "0.21.0-next.1"
"@ckb-lumos/bi" "0.21.0-next.1"
"@ckb-lumos/codec" "0.21.0-next.1"
"@ckb-lumos/config-manager" "0.21.0-next.1"
"@ckb-lumos/helpers" "0.21.0-next.1"
"@ckb-lumos/rpc" "0.21.0-next.1"
"@ckb-lumos/toolkit" "0.21.0-next.1"
immutable "^4.3.0"

"@ckb-lumos/[email protected]", "@ckb-lumos/config-manager@^0.20.0":
version "0.20.0"
resolved "https://registry.yarnpkg.com/@ckb-lumos/config-manager/-/config-manager-0.20.0.tgz#f24946971005f62df62e22c3306947b5e820c181"
Expand All @@ -1795,7 +1809,7 @@
"@types/deep-freeze-strict" "^1.1.0"
deep-freeze-strict "^1.1.1"

"@ckb-lumos/[email protected]", "@ckb-lumos/config-manager@^0.21.0-next.1":
"@ckb-lumos/[email protected]":
version "0.21.0-next.1"
resolved "https://registry.yarnpkg.com/@ckb-lumos/config-manager/-/config-manager-0.21.0-next.1.tgz#927e21a5d9450155ebf766422a707fd3b0856a14"
integrity sha512-G8CO+q1RH/Gt8ou8p/N99AUh5hIdU+MZcTZHwABOa4CLbXk2xFenRfeGhHv4u4ddYZ3SLx1zND7pSnbImmrh2A==
Expand All @@ -1819,7 +1833,7 @@
sha3 "^2.1.3"
uuid "^8.3.0"

"@ckb-lumos/hd@^0.21.0-next.1":
"@ckb-lumos/[email protected]":
version "0.21.0-next.1"
resolved "https://registry.yarnpkg.com/@ckb-lumos/hd/-/hd-0.21.0-next.1.tgz#ffa4b80b974187982bbfa280138ca1dab0b2df0e"
integrity sha512-gISrSs4OWoBVecRnYMfjYQc83aE0Khjjs1KmAkAg1J53PWGeU3kjbUQSCHjF6poFL5ylEARX9vOKixRfm6nktg==
Expand All @@ -1844,7 +1858,7 @@
bech32 "^2.0.0"
immutable "^4.0.0-rc.12"

"@ckb-lumos/helpers@^0.21.0-next.1":
"@ckb-lumos/[email protected]":
version "0.21.0-next.1"
resolved "https://registry.yarnpkg.com/@ckb-lumos/helpers/-/helpers-0.21.0-next.1.tgz#f0f2d9e231f5a266d53df0c60e7b7610b87e10b5"
integrity sha512-lSvn2L97be7IlONFTdjjz+/jG6QlpEGyETyrcSfJxeOOtgjicPFaLXLnaTBIt/IElRZ2ZpclbTFvSNcbVOvKdQ==
Expand Down Expand Up @@ -1883,7 +1897,7 @@
axios "0.27.2"
tslib "2.3.1"

"@ckb-lumos/[email protected]", "@ckb-lumos/rpc@^0.21.0-next.1":
"@ckb-lumos/[email protected]":
version "0.21.0-next.1"
resolved "https://registry.yarnpkg.com/@ckb-lumos/rpc/-/rpc-0.21.0-next.1.tgz#f31610fc1713ae63e25475d3653ee8cc3eeabc0f"
integrity sha512-6IjnME2wGg1rmVnajQ7CTBqbLnXkdNqRERRmnD1J9EnoHBc+onSYSfkC58ZCVCOe0xZIR2vNKmOUQ++dmlKKiQ==
Expand Down

2 comments on commit 170f6e4

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packaging for test is done in 6928308517

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Packaging for test is done in 6928309999

Please sign in to comment.