Skip to content

Commit

Permalink
change calculateMaximumWithdraw return value to hex string
Browse files Browse the repository at this point in the history
  • Loading branch information
yanguoyu committed Mar 2, 2022
1 parent cbe3765 commit 8cd4f45
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
6 changes: 3 additions & 3 deletions packages/ckb-sdk-core/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ describe('ckb', () => {
.mockResolvedValueOnce({ dao: '0x9bafffa73e432e3c94c6f9db34cb25009f9e4efe4b5fd60200ea63c6d4ffb407' })
}
const res = await ckb.calculateDaoMaximumWithdraw({ tx: '', index: '0x0' }, '')
expect(res).toBe('1000183501854')
expect(res).toBe('0xe8df95141e')
ckb.rpc = rpc
})
it('another normal withdraw hash', async () => {
Expand Down Expand Up @@ -249,7 +249,7 @@ describe('ckb', () => {
.mockResolvedValueOnce({ dao: '0xd87090655733433c2395d67a64ce2500d73e963e54ccda0200f244c504a4b707' })
}
const res = await ckb.calculateDaoMaximumWithdraw({index: '0x0', txHash: '0xabd4f1b9e914cd859cb7ecf4f57009ef7cd2d84a799ed61acff904bdf5fea91a'}, '0x04914c83fa9ea4126279ebe2d2cdff74235f63227821882e4e16f6a908f43691')
expect(res).toBe('30000000155')
expect(res).toBe('0x6fc23ac9b')
ckb.rpc = rpc
})
it('normal withdraw outputpoint', async () => {
Expand Down Expand Up @@ -292,7 +292,7 @@ describe('ckb', () => {
.mockResolvedValueOnce({ dao: '0xd87090655733433c2395d67a64ce2500d73e963e54ccda0200f244c504a4b707' })
}
const res = await ckb.calculateDaoMaximumWithdraw({index: '0x0', txHash: '0xabd4f1b9e914cd859cb7ecf4f57009ef7cd2d84a799ed61acff904bdf5fea91a'}, '0x04914c83fa9ea4126279ebe2d2cdff74235f63227821882e4e16f6a908f43691')
expect(res).toBe('30000000155')
expect(res).toBe('0x6fc23ac9b')
ckb.rpc = rpc
})
it('exception', async () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/ckb-sdk-utils/__tests__/utils/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ describe('calculate-maximum-withdraw', () => {
'0x0000000000000000',
'0x1aaf2ca6847c223c3ef9e8c069c9250020212a6311e2d30200609349396eb407',
'0x9bafffa73e432e3c94c6f9db34cb25009f9e4efe4b5fd60200ea63c6d4ffb407'
)).toBe('1000183501854')
)).toBe('0xe8df95141e')
})

describe('extract header dao', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/ckb-sdk-utils/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const calculateMaximumWithdraw = (
128,
JSBI.multiply(JSBI.BigInt(100000000), JSBI.BigInt(depositCellSerialized))
)
return JSBI.add(
return `0x${JSBI.add(
JSBI.divide(
JSBI.multiply(
JSBI.subtract(
Expand All @@ -84,5 +84,5 @@ export const calculateMaximumWithdraw = (
JSBI.asUintN(128, JSBI.BigInt(extractDAOData(depositDAO).ar))
),
occupiedCapacity
).toString()
).toString(16)}`
}
5 changes: 4 additions & 1 deletion packages/ckb-sdk-utils/src/occupiedCapacity.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const codeHashOccupied = 32
const hashTypeOccupied = 1

export const scriptOccupied = (script: CKBComponents.Script) => {
return script.args.slice(2).length / 2 + 32 + 1
return script.args.slice(2).length / 2 + codeHashOccupied + hashTypeOccupied
}

export const cellOccupied = (cell: CKBComponents.CellOutput) => {
Expand Down

0 comments on commit 8cd4f45

Please sign in to comment.