diff --git a/packages/neuron-wallet/src/models/dao-utils.ts b/packages/neuron-wallet/src/models/dao-utils.ts index 75f5cb36ec..04d76060c5 100644 --- a/packages/neuron-wallet/src/models/dao-utils.ts +++ b/packages/neuron-wallet/src/models/dao-utils.ts @@ -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!) diff --git a/packages/neuron-wallet/src/services/cells.ts b/packages/neuron-wallet/src/services/cells.ts index 231efa00db..e3eda1ac90 100644 --- a/packages/neuron-wallet/src/services/cells.ts +++ b/packages/neuron-wallet/src/services/cells.ts @@ -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), diff --git a/packages/neuron-wallet/src/services/tx/transaction-generator.ts b/packages/neuron-wallet/src/services/tx/transaction-generator.ts index e36e24bedb..749812b109 100644 --- a/packages/neuron-wallet/src/services/tx/transaction-generator.ts +++ b/packages/neuron-wallet/src/services/tx/transaction-generator.ts @@ -193,7 +193,8 @@ export class TransactionGenerator { hashType: daoScriptInfo.hashType, args: '0x', }, - data: '0x0000000000000000' + data: '0x0000000000000000', + daoData: '0x0000000000000000', } const outputs: Cell[] = [output] diff --git a/packages/neuron-wallet/src/services/wallets.ts b/packages/neuron-wallet/src/services/wallets.ts index ab161e6528..c1a8591a43 100644 --- a/packages/neuron-wallet/src/services/wallets.ts +++ b/packages/neuron-wallet/src/services/wallets.ts @@ -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() } @@ -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) @@ -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] @@ -559,6 +563,14 @@ 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 || @@ -566,9 +578,9 @@ export default class WalletService { ) { 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 = { @@ -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: [], diff --git a/packages/neuron-wallet/src/utils/hex.ts b/packages/neuron-wallet/src/utils/hex.ts index 911efab8ca..860d7e3424 100644 --- a/packages/neuron-wallet/src/utils/hex.ts +++ b/packages/neuron-wallet/src/utils/hex.ts @@ -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)}` } }