input+lnwallet: apply the new type lntypes.VByte

This commit is contained in:
yyforyongyu
2024-05-24 23:03:51 +08:00
parent 8da68bb7db
commit 17a089c899
2 changed files with 10 additions and 9 deletions

View File

@@ -863,9 +863,9 @@ type TxWeightEstimator struct {
hasWitness bool hasWitness bool
inputCount uint32 inputCount uint32
outputCount uint32 outputCount uint32
inputSize int inputSize lntypes.VByte
inputWitnessSize lntypes.WeightUnit inputWitnessSize lntypes.WeightUnit
outputSize int outputSize lntypes.VByte
} }
// AddP2PKHInput updates the weight estimate to account for an additional input // AddP2PKHInput updates the weight estimate to account for an additional input
@@ -975,7 +975,7 @@ func (twe *TxWeightEstimator) AddNestedP2WSHInput(
// AddTxOutput adds a known TxOut to the weight estimator. // AddTxOutput adds a known TxOut to the weight estimator.
func (twe *TxWeightEstimator) AddTxOutput(txOut *wire.TxOut) *TxWeightEstimator { func (twe *TxWeightEstimator) AddTxOutput(txOut *wire.TxOut) *TxWeightEstimator {
twe.outputSize += txOut.SerializeSize() twe.outputSize += lntypes.VByte(txOut.SerializeSize())
twe.outputCount++ twe.outputCount++
return twe return twe
@@ -1028,7 +1028,7 @@ func (twe *TxWeightEstimator) AddP2SHOutput() *TxWeightEstimator {
// AddOutput estimates the weight of an output based on the pkScript. // AddOutput estimates the weight of an output based on the pkScript.
func (twe *TxWeightEstimator) AddOutput(pkScript []byte) *TxWeightEstimator { func (twe *TxWeightEstimator) AddOutput(pkScript []byte) *TxWeightEstimator {
twe.outputSize += BaseOutputSize + len(pkScript) twe.outputSize += BaseOutputSize + lntypes.VByte(len(pkScript))
twe.outputCount++ twe.outputCount++
return twe return twe
@@ -1036,9 +1036,10 @@ func (twe *TxWeightEstimator) AddOutput(pkScript []byte) *TxWeightEstimator {
// Weight gets the estimated weight of the transaction. // Weight gets the estimated weight of the transaction.
func (twe *TxWeightEstimator) Weight() lntypes.WeightUnit { func (twe *TxWeightEstimator) Weight() lntypes.WeightUnit {
txSizeStripped := BaseTxSize + inputCount := wire.VarIntSerializeSize(uint64(twe.inputCount))
wire.VarIntSerializeSize(uint64(twe.inputCount)) + twe.inputSize + outputCount := wire.VarIntSerializeSize(uint64(twe.outputCount))
wire.VarIntSerializeSize(uint64(twe.outputCount)) + twe.outputSize txSizeStripped := BaseTxSize + lntypes.VByte(inputCount) +
twe.inputSize + lntypes.VByte(outputCount) + twe.outputSize
weight := lntypes.WeightUnit(txSizeStripped * witnessScaleFactor) weight := lntypes.WeightUnit(txSizeStripped * witnessScaleFactor)
if twe.hasWitness { if twe.hasWitness {

View File

@@ -42,7 +42,7 @@ type SatPerKVByte btcutil.Amount
// FeeForVSize calculates the fee resulting from this fee rate and the given // FeeForVSize calculates the fee resulting from this fee rate and the given
// vsize in vbytes. // vsize in vbytes.
func (s SatPerKVByte) FeeForVSize(vbytes int64) btcutil.Amount { func (s SatPerKVByte) FeeForVSize(vbytes lntypes.VByte) btcutil.Amount {
return btcutil.Amount(s) * btcutil.Amount(vbytes) / 1000 return btcutil.Amount(s) * btcutil.Amount(vbytes) / 1000
} }
@@ -73,7 +73,7 @@ func (s SatPerKWeight) FeeForWeight(wu lntypes.WeightUnit) btcutil.Amount {
// FeeForVByte calculates the fee resulting from this fee rate and the given // FeeForVByte calculates the fee resulting from this fee rate and the given
// size in vbytes (vb). // size in vbytes (vb).
func (s SatPerKWeight) FeeForVByte(vb int64) btcutil.Amount { func (s SatPerKWeight) FeeForVByte(vb lntypes.VByte) btcutil.Amount {
return s.FeePerKVByte().FeeForVSize(vb) return s.FeePerKVByte().FeeForVSize(vb)
} }