mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-11-23 22:15:54 +00:00
Fix estimateFee change value
This commit is contained in:
parent
af93d5fdfe
commit
2d25c3d7a3
@ -198,7 +198,7 @@ func (s *server) selectUTXOsWithPreselected(preSelectedUTXOs []*walletUTXO, allo
|
|||||||
totalValue += utxo.UTXOEntry.Amount()
|
totalValue += utxo.UTXOEntry.Amount()
|
||||||
|
|
||||||
// We're overestimating a bit by assuming that any transaction will have a change output
|
// We're overestimating a bit by assuming that any transaction will have a change output
|
||||||
fee, err = s.estimateFee(selectedUTXOs, feeRate, maxFee, true)
|
fee, err = s.estimateFee(selectedUTXOs, feeRate, maxFee, spendAmount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
@ -257,7 +257,7 @@ func (s *server) selectUTXOsWithPreselected(preSelectedUTXOs []*walletUTXO, allo
|
|||||||
return selectedUTXOs, totalReceived, totalValue - totalSpend, nil
|
return selectedUTXOs, totalReceived, totalValue - totalSpend, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *server) estimateFee(selectedUTXOs []*libkaspawallet.UTXO, feeRate float64, maxFee uint64, assumeChange bool) (uint64, error) {
|
func (s *server) estimateFee(selectedUTXOs []*libkaspawallet.UTXO, feeRate float64, maxFee uint64, recipientValue uint64) (uint64, error) {
|
||||||
fakePubKey := [util.PublicKeySize]byte{}
|
fakePubKey := [util.PublicKeySize]byte{}
|
||||||
fakeAddr, err := util.NewAddressPublicKey(fakePubKey[:], s.params.Prefix)
|
fakeAddr, err := util.NewAddressPublicKey(fakePubKey[:], s.params.Prefix)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -271,15 +271,15 @@ func (s *server) estimateFee(selectedUTXOs []*libkaspawallet.UTXO, feeRate float
|
|||||||
|
|
||||||
// This is an approximation for the distribution of value between the recipient output and the change output.
|
// This is an approximation for the distribution of value between the recipient output and the change output.
|
||||||
var mockPayments []*libkaspawallet.Payment
|
var mockPayments []*libkaspawallet.Payment
|
||||||
if assumeChange {
|
if totalValue > recipientValue {
|
||||||
mockPayments = []*libkaspawallet.Payment{
|
mockPayments = []*libkaspawallet.Payment{
|
||||||
{
|
{
|
||||||
Address: fakeAddr,
|
Address: fakeAddr,
|
||||||
Amount: totalValue * 99 / 100,
|
Amount: recipientValue,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Address: fakeAddr,
|
Address: fakeAddr,
|
||||||
Amount: totalValue / 100,
|
Amount: totalValue - recipientValue, // We ignore the fee since we expect it to be insignificant in mass calculation.
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@ -72,7 +72,7 @@ func (s *server) mergeTransaction(
|
|||||||
totalValue += output.Value
|
totalValue += output.Value
|
||||||
}
|
}
|
||||||
// We're overestimating a bit by assuming that any transaction will have a change output
|
// We're overestimating a bit by assuming that any transaction will have a change output
|
||||||
fee, err := s.estimateFee(utxos, feeRate, maxFee, true)
|
fee, err := s.estimateFee(utxos, feeRate, maxFee, sentValue)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -253,7 +253,7 @@ func (s *server) createSplitTransaction(transaction *serialization.PartiallySign
|
|||||||
totalSompi += selectedUTXOs[i-startIndex].UTXOEntry.Amount()
|
totalSompi += selectedUTXOs[i-startIndex].UTXOEntry.Amount()
|
||||||
}
|
}
|
||||||
if len(selectedUTXOs) != 0 {
|
if len(selectedUTXOs) != 0 {
|
||||||
fee, err := s.estimateFee(selectedUTXOs, feeRate, maxFee, false)
|
fee, err := s.estimateFee(selectedUTXOs, feeRate, maxFee, totalSompi)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -90,12 +90,13 @@ func parse(conf *parseConfig) error {
|
|||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
||||||
fee := allInputSompi - allOutputSompi
|
fee := allInputSompi - allOutputSompi
|
||||||
fmt.Printf("Fee:\t%d Sompi (%f KAS)\n\n", fee, float64(fee)/float64(constants.SompiPerKaspa))
|
fmt.Printf("Fee:\t%d Sompi (%f KAS)\n", fee, float64(fee)/float64(constants.SompiPerKaspa))
|
||||||
mass, err := server.EstimateMassAfterSignatures(partiallySignedTransaction, keysFile.ECDSA, keysFile.MinimumSignatures, txMassCalculator)
|
mass, err := server.EstimateMassAfterSignatures(partiallySignedTransaction, keysFile.ECDSA, keysFile.MinimumSignatures, txMassCalculator)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Mass: %d grams\n", mass)
|
||||||
feeRate := float64(fee) / float64(mass)
|
feeRate := float64(fee) / float64(mass)
|
||||||
fmt.Printf("Fee rate: %.2f Sompi/Gram\n", feeRate)
|
fmt.Printf("Fee rate: %.2f Sompi/Gram\n", feeRate)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user