Skip to content

Commit

Permalink
fix: deposit dao and withdraw step1 error
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Nov 7, 2019
1 parent 55dc8d8 commit 77a505d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/neuron-wallet/src/models/dao-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class DaoUtils {
const systemCellTransaction = genesisBlock.transactions[0]
const daoOutPoint = {
txHash: systemCellTransaction.hash,
index: '2'
index: '0x2'
}

const daoTypeHash = scriptToHash(systemCellTransaction.outputs[2].type!)
Expand Down
6 changes: 3 additions & 3 deletions packages/neuron-wallet/src/services/cells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ export default class CellsService {
// use min secp size (without data)
const minChangeCapacity = BigInt(MIN_CELL_CAPACITY)

if (capacityInt < BigInt(MIN_CELL_CAPACITY)) {
throw new Error(`capacity can't be less than ${MIN_CELL_CAPACITY}`)
}
// if (capacityInt < BigInt(MIN_CELL_CAPACITY)) {
// throw new Error(`capacity can't be less than ${MIN_CELL_CAPACITY}`)
// }

const queryParams = {
lockHash: In(lockHashes),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ export class TransactionGenerator {
hashType: daoScriptInfo.hashType,
args: '0x',
},
data: '0x0000000000000000'
data: '0x0000000000000000',
daoData: '0x0000000000000000',
}

const outputs: Cell[] = [output]
Expand Down
24 changes: 19 additions & 5 deletions packages/neuron-wallet/src/services/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,9 @@ export default class WalletService {
throw new WalletNotFound(walletID)
}

const cellStatus = await core.rpc.getLiveCell(outPoint, false)
const sdkOutPoint = ConvertTo.toSdkOutPoint(outPoint)

const cellStatus = await core.rpc.getLiveCell(sdkOutPoint, false)
if (cellStatus.status !== 'live') {
throw new CellIsNotYetLive()
}
Expand All @@ -529,6 +531,7 @@ export default class WalletService {
const feeRateInt = BigInt(feeRate)
const mode = new FeeMode(feeRateInt)

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

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

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

const input: Input = {
previousOutput: outPoint,
since: '0',
lock: output.lock,
lockHash: LockUtils.lockScriptToHash(output.lock),
capacity: output.capacity,
}

// change
if (
mode.isFeeMode() && BigInt(capacities) > capacityInt + feeInt ||
mode.isFeeRateMode() && BigInt(capacities) > capacityInt + feeWithoutInputs + needFeeInt
) {
const changeAddress = await AddressesService.nextUnusedChangeAddress(walletID)
const changeBlake160: string = LockUtils.addressToBlake160(changeAddress!.address)
let changeCapacity = BigInt(capacities) - capacityInt - feeInt
let changeCapacity = BigInt(capacities) - feeInt
if (mode.isFeeRateMode()) {
changeCapacity = BigInt(capacities) - capacityInt - totalFee
changeCapacity = BigInt(capacities) - totalFee
}

const changeOutput: Cell = {
Expand Down Expand Up @@ -596,8 +608,10 @@ export default class WalletService {
depType: DepType.Code,
},
],
headerDeps: [],
inputs,
headerDeps: [
depositBlock.hash,
],
inputs: [input].concat(inputs),
outputs,
outputsData: outputs.map(o => o.data || '0x'),
witnesses: [],
Expand Down
3 changes: 3 additions & 0 deletions packages/neuron-wallet/src/utils/hex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ export default class HexUtils {
}

public static toHex(num: string): string {
if (num.startsWith('0x')) {
return num
}
return `0x${BigInt(num).toString(16)}`
}
}

0 comments on commit 77a505d

Please sign in to comment.