Skip to content

Commit 77a505d

Browse files
committed
fix: deposit dao and withdraw step1 error
1 parent 55dc8d8 commit 77a505d

5 files changed

Lines changed: 28 additions & 10 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default class DaoUtils {
2222
const systemCellTransaction = genesisBlock.transactions[0]
2323
const daoOutPoint = {
2424
txHash: systemCellTransaction.hash,
25-
index: '2'
25+
index: '0x2'
2626
}
2727

2828
const daoTypeHash = scriptToHash(systemCellTransaction.outputs[2].type!)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,9 @@ export default class CellsService {
116116
// use min secp size (without data)
117117
const minChangeCapacity = BigInt(MIN_CELL_CAPACITY)
118118

119-
if (capacityInt < BigInt(MIN_CELL_CAPACITY)) {
120-
throw new Error(`capacity can't be less than ${MIN_CELL_CAPACITY}`)
121-
}
119+
// if (capacityInt < BigInt(MIN_CELL_CAPACITY)) {
120+
// throw new Error(`capacity can't be less than ${MIN_CELL_CAPACITY}`)
121+
// }
122122

123123
const queryParams = {
124124
lockHash: In(lockHashes),

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ export class TransactionGenerator {
193193
hashType: daoScriptInfo.hashType,
194194
args: '0x',
195195
},
196-
data: '0x0000000000000000'
196+
data: '0x0000000000000000',
197+
daoData: '0x0000000000000000',
197198
}
198199

199200
const outputs: Cell[] = [output]

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

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,9 @@ export default class WalletService {
510510
throw new WalletNotFound(walletID)
511511
}
512512

513-
const cellStatus = await core.rpc.getLiveCell(outPoint, false)
513+
const sdkOutPoint = ConvertTo.toSdkOutPoint(outPoint)
514+
515+
const cellStatus = await core.rpc.getLiveCell(sdkOutPoint, false)
514516
if (cellStatus.status !== 'live') {
515517
throw new CellIsNotYetLive()
516518
}
@@ -529,6 +531,7 @@ export default class WalletService {
529531
const feeRateInt = BigInt(feeRate)
530532
const mode = new FeeMode(feeRateInt)
531533

534+
// 4 + 44 + 89 is input of deposited dao and witness size
532535
const sizeWithoutInputs: number = TransactionGenerator.txSerializedSizeInBlockWithoutInputsForDeposit() + (4+44+89)
533536
const feeWithoutInputs: bigint = TransactionGenerator.txFee(sizeWithoutInputs, feeRateInt)
534537

@@ -539,6 +542,7 @@ export default class WalletService {
539542
const buf = Buffer.alloc(8)
540543
buf.writeBigUInt64LE(BigInt(depositBlockNumber))
541544
output.data = `0x${buf.toString('hex')}`
545+
output.daoData = output.data
542546

543547
const capacityInt = BigInt(output.capacity)
544548
const outputs: Cell[] = [output]
@@ -559,16 +563,24 @@ export default class WalletService {
559563
const { codeHash, outPoint: secpOutPoint, hashType } = await LockUtils.systemScript()
560564
const daoScriptInfo = await DaoUtils.daoScript()
561565

566+
const input: Input = {
567+
previousOutput: outPoint,
568+
since: '0',
569+
lock: output.lock,
570+
lockHash: LockUtils.lockScriptToHash(output.lock),
571+
capacity: output.capacity,
572+
}
573+
562574
// change
563575
if (
564576
mode.isFeeMode() && BigInt(capacities) > capacityInt + feeInt ||
565577
mode.isFeeRateMode() && BigInt(capacities) > capacityInt + feeWithoutInputs + needFeeInt
566578
) {
567579
const changeAddress = await AddressesService.nextUnusedChangeAddress(walletID)
568580
const changeBlake160: string = LockUtils.addressToBlake160(changeAddress!.address)
569-
let changeCapacity = BigInt(capacities) - capacityInt - feeInt
581+
let changeCapacity = BigInt(capacities) - feeInt
570582
if (mode.isFeeRateMode()) {
571-
changeCapacity = BigInt(capacities) - capacityInt - totalFee
583+
changeCapacity = BigInt(capacities) - totalFee
572584
}
573585

574586
const changeOutput: Cell = {
@@ -596,8 +608,10 @@ export default class WalletService {
596608
depType: DepType.Code,
597609
},
598610
],
599-
headerDeps: [],
600-
inputs,
611+
headerDeps: [
612+
depositBlock.hash,
613+
],
614+
inputs: [input].concat(inputs),
601615
outputs,
602616
outputsData: outputs.map(o => o.data || '0x'),
603617
witnesses: [],

packages/neuron-wallet/src/utils/hex.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ export default class HexUtils {
44
}
55

66
public static toHex(num: string): string {
7+
if (num.startsWith('0x')) {
8+
return num
9+
}
710
return `0x${BigInt(num).toString(16)}`
811
}
912
}

0 commit comments

Comments
 (0)