lnwallet: use btcutil.NewAmount for BTC -> SAT conversions
In this commit, we fix an existing rounding related bug in the codebase. The RPC interface for btcd and bitcoind return values in BTC rather than in satoshis. So in several places, we're forced to convert ourselves manually. The existing logic attempted to do this, but didn't properly account for rounding. As a result, our values can be off due to not rounding incorrectly. The fix for this is easy: simply properly use btcutil.NewAmount everywhere which does rounding properly. Fixes #939.
This commit is contained in:
4 files changed
+66
-21
No files matched your search
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/roasbeef/btcd/chaincfg/chainhash"
|
||||
"github.com/roasbeef/btcd/wire"
|
||||
"github.com/roasbeef/btcutil"
|
||||
|
||||
"github.com/lightninglabs/neutrino"
|
||||
"github.com/lightningnetwork/lnd/lnwallet"
|
||||
@@ -77,10 +78,15 @@ func (b *BtcWallet) GetUtxo(op *wire.OutPoint, heightHint uint32) (*wire.TxOut,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// We'll ensure we properly convert the amount given in BTC to
|
||||
// satoshis.
|
||||
amt, err := btcutil.NewAmount(txout.Value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &wire.TxOut{
|
||||
// Sadly, gettxout returns the output value in BTC
|
||||
// instead of satoshis.
|
||||
Value: int64(txout.Value * 1e8),
|
||||
Value: int64(amt),
|
||||
PkScript: pkScript,
|
||||
}, nil
|
||||
|
||||
@@ -97,10 +103,15 @@ func (b *BtcWallet) GetUtxo(op *wire.OutPoint, heightHint uint32) (*wire.TxOut,
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Sadly, gettxout returns the output value in BTC instead of
|
||||
// satoshis.
|
||||
amt, err := btcutil.NewAmount(txout.Value)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &wire.TxOut{
|
||||
// Sadly, gettxout returns the output value in BTC
|
||||
// instead of satoshis.
|
||||
Value: int64(txout.Value * 1e8),
|
||||
Value: int64(amt),
|
||||
PkScript: pkScript,
|
||||
}, nil
|
||||
|
||||
|
||||
Reference in new issue
Block a user