Skip to content

Commit 2088d5c

Browse files
committed
fix: calculate tx serialized size for dao
1 parent 430a580 commit 2088d5c

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,17 @@ export class TransactionGenerator {
2424
* a transaction with empty inputs/outputs/cellDeps/header/outputs_data/witnesses need 68 Bytes
2525
* every cellDep need 37 Bytes, transaction for deposit needs 2 cellDeps(lock / type)
2626
* every output without typeScript & with lock in secp need 97 Bytes and 4 Bytes for offset (add to transaction)
27-
* every output for deposit with typeScript in dao & with lock in secp need 130 Bytes and 4 Bytes for offset (add to transaction)
27+
* every output for deposit with typeScript in dao & with lock in secp need 150 Bytes and 4 Bytes for offset (add to transaction)
2828
* every outputsData in "0x" need 4 Bytes and 4 Bytes for offset
2929
* every outputsData in "0x0000000000000000" need 12 Bytes and 4 Bytes for offset
3030
*/
31-
return 4 + 68 + 37 * 2 + (4 + 97 + 4 + 4) + (130 + 4 + 12 + 4)
31+
return 4 + 68 + 37 * 2 + (4 + 97 + 4 + 4) + (150 + 4 + 12 + 4)
32+
}
33+
34+
public static txSerializedSizeInBlockWithoputInputsForWitdrawStep1 = (): number => {
35+
// a fixed input for (4+44+89) Bytes
36+
// a fixed headerDep for 32 Bytes
37+
return TransactionGenerator.txSerializedSizeInBlockWithoutInputsForDeposit() + (4 + 44 + 89) + 32
3238
}
3339

3440
public static txSerializedSizeInBlockForWithdraw = (): number => {
@@ -42,7 +48,7 @@ export class TransactionGenerator {
4248
* only one input, for 44 Bytes
4349
* one witness with extra inputType "0x0000000000000000", 101 Bytes, extra 4 Bytes for add to transaction
4450
*/
45-
return 4 + 68 + 37 * 2 + 32 * 2 + (4 + 97 + 4 + 4) + (101 + 4)
51+
return 4 + 68 + 37 * 2 + 32 * 2 + (4 + 97 + 4 + 4) + 44 + (101 + 4)
4652
}
4753

4854
public static txFee = (size: number, feeRate: bigint) => {

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ export default class WalletService {
554554
const mode = new FeeMode(feeRateInt)
555555

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

560560
const depositBlock = await core.rpc.getHeader(tx.txStatus.blockHash!)
@@ -691,7 +691,6 @@ export default class WalletService {
691691

692692
const minimalSince = this.epochSince(minimalSinceEpochLength, minimalSinceEpochIndex, minimalSinceEpochNumber)
693693

694-
// TODO: calculate_dao_maximum_withdraw rpc
695694
const outputCapacity: bigint = await this.calculateDaoMaximumWithdraw(depositOutPoint, withdrawBlock.hash)
696695

697696
const { codeHash, outPoint: secpOutPoint, hashType } = await LockUtils.systemScript()

0 commit comments

Comments
 (0)