Skip to content

Commit

Permalink
fix: calculate tx serialized size for dao
Browse files Browse the repository at this point in the history
  • Loading branch information
classicalliu committed Nov 8, 2019
1 parent 430a580 commit 2088d5c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 9 additions & 3 deletions packages/neuron-wallet/src/services/tx/transaction-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,17 @@ export class TransactionGenerator {
* a transaction with empty inputs/outputs/cellDeps/header/outputs_data/witnesses need 68 Bytes
* every cellDep need 37 Bytes, transaction for deposit needs 2 cellDeps(lock / type)
* every output without typeScript & with lock in secp need 97 Bytes and 4 Bytes for offset (add to transaction)
* every output for deposit with typeScript in dao & with lock in secp need 130 Bytes and 4 Bytes for offset (add to transaction)
* every output for deposit with typeScript in dao & with lock in secp need 150 Bytes and 4 Bytes for offset (add to transaction)
* every outputsData in "0x" need 4 Bytes and 4 Bytes for offset
* every outputsData in "0x0000000000000000" need 12 Bytes and 4 Bytes for offset
*/
return 4 + 68 + 37 * 2 + (4 + 97 + 4 + 4) + (130 + 4 + 12 + 4)
return 4 + 68 + 37 * 2 + (4 + 97 + 4 + 4) + (150 + 4 + 12 + 4)
}

public static txSerializedSizeInBlockWithoputInputsForWitdrawStep1 = (): number => {
// a fixed input for (4+44+89) Bytes
// a fixed headerDep for 32 Bytes
return TransactionGenerator.txSerializedSizeInBlockWithoutInputsForDeposit() + (4 + 44 + 89) + 32
}

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

public static txFee = (size: number, feeRate: bigint) => {
Expand Down
3 changes: 1 addition & 2 deletions packages/neuron-wallet/src/services/wallets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ export default class WalletService {
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 sizeWithoutInputs: number = TransactionGenerator.txSerializedSizeInBlockWithoputInputsForWitdrawStep1()
const feeWithoutInputs: bigint = TransactionGenerator.txFee(sizeWithoutInputs, feeRateInt)

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

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

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

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

0 comments on commit 2088d5c

Please sign in to comment.