Merge pull request #717 from cfromknecht/fix-dust-calc
wallet/txauthor: fix bug in dust calculation
This commit is contained in:
commit
1d31f4ea6f
1 changed files with 4 additions and 4 deletions
|
@ -83,12 +83,12 @@ type ChangeSource func() ([]byte, error)
|
||||||
// InputSourceError is returned.
|
// InputSourceError is returned.
|
||||||
//
|
//
|
||||||
// BUGS: Fee estimation may be off when redeeming non-compressed P2PKH outputs.
|
// BUGS: Fee estimation may be off when redeeming non-compressed P2PKH outputs.
|
||||||
func NewUnsignedTransaction(outputs []*wire.TxOut, relayFeePerKb btcutil.Amount,
|
func NewUnsignedTransaction(outputs []*wire.TxOut, feeRatePerKb btcutil.Amount,
|
||||||
fetchInputs InputSource, fetchChange ChangeSource) (*AuthoredTx, error) {
|
fetchInputs InputSource, fetchChange ChangeSource) (*AuthoredTx, error) {
|
||||||
|
|
||||||
targetAmount := SumOutputValues(outputs)
|
targetAmount := SumOutputValues(outputs)
|
||||||
estimatedSize := txsizes.EstimateVirtualSize(0, 1, 0, outputs, true)
|
estimatedSize := txsizes.EstimateVirtualSize(0, 1, 0, outputs, true)
|
||||||
targetFee := txrules.FeeForSerializeSize(relayFeePerKb, estimatedSize)
|
targetFee := txrules.FeeForSerializeSize(feeRatePerKb, estimatedSize)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
inputAmount, inputs, inputValues, scripts, err := fetchInputs(targetAmount + targetFee)
|
inputAmount, inputs, inputValues, scripts, err := fetchInputs(targetAmount + targetFee)
|
||||||
|
@ -117,7 +117,7 @@ func NewUnsignedTransaction(outputs []*wire.TxOut, relayFeePerKb btcutil.Amount,
|
||||||
|
|
||||||
maxSignedSize := txsizes.EstimateVirtualSize(p2pkh, p2wpkh,
|
maxSignedSize := txsizes.EstimateVirtualSize(p2pkh, p2wpkh,
|
||||||
nested, outputs, true)
|
nested, outputs, true)
|
||||||
maxRequiredFee := txrules.FeeForSerializeSize(relayFeePerKb, maxSignedSize)
|
maxRequiredFee := txrules.FeeForSerializeSize(feeRatePerKb, maxSignedSize)
|
||||||
remainingAmount := inputAmount - targetAmount
|
remainingAmount := inputAmount - targetAmount
|
||||||
if remainingAmount < maxRequiredFee {
|
if remainingAmount < maxRequiredFee {
|
||||||
targetFee = maxRequiredFee
|
targetFee = maxRequiredFee
|
||||||
|
@ -133,7 +133,7 @@ func NewUnsignedTransaction(outputs []*wire.TxOut, relayFeePerKb btcutil.Amount,
|
||||||
changeIndex := -1
|
changeIndex := -1
|
||||||
changeAmount := inputAmount - targetAmount - maxRequiredFee
|
changeAmount := inputAmount - targetAmount - maxRequiredFee
|
||||||
if changeAmount != 0 && !txrules.IsDustAmount(changeAmount,
|
if changeAmount != 0 && !txrules.IsDustAmount(changeAmount,
|
||||||
txsizes.P2WPKHPkScriptSize, relayFeePerKb) {
|
txsizes.P2WPKHPkScriptSize, txrules.DefaultRelayFeePerKb) {
|
||||||
changeScript, err := fetchChange()
|
changeScript, err := fetchChange()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
Loading…
Reference in a new issue