• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 13523316608

25 Feb 2025 02:12PM UTC coverage: 49.351% (-9.5%) from 58.835%
13523316608

Pull #9549

github

yyforyongyu
routing/chainview: refactor `TestFilteredChainView`

So each test has its own miner and chainView.
Pull Request #9549: Fix unit test flake `TestHistoricalConfDetailsTxIndex`

0 of 120 new or added lines in 1 file covered. (0.0%)

27196 existing lines in 434 files now uncovered.

100945 of 204543 relevant lines covered (49.35%)

1.54 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/channeldb/migration/lnwire21/msat.go
1
package lnwire
2

3
import (
4
        "fmt"
5
        "io"
6

7
        "github.com/btcsuite/btcd/btcutil"
8
        "github.com/lightningnetwork/lnd/tlv"
9
)
10

11
const (
12
        // mSatScale is a value that's used to scale satoshis to milli-satoshis, and
13
        // the other way around.
14
        mSatScale uint64 = 1000
15

16
        // MaxMilliSatoshi is the maximum number of msats that can be expressed
17
        // in this data type.
18
        MaxMilliSatoshi = ^MilliSatoshi(0)
19
)
20

21
// MilliSatoshi are the native unit of the Lightning Network. A milli-satoshi
22
// is simply 1/1000th of a satoshi. There are 1000 milli-satoshis in a single
23
// satoshi. Within the network, all HTLC payments are denominated in
24
// milli-satoshis. As milli-satoshis aren't deliverable on the native
25
// blockchain, before settling to broadcasting, the values are rounded down to
26
// the nearest satoshi.
27
type MilliSatoshi uint64
28

29
// NewMSatFromSatoshis creates a new MilliSatoshi instance from a target amount
30
// of satoshis.
UNCOV
31
func NewMSatFromSatoshis(sat btcutil.Amount) MilliSatoshi {
×
UNCOV
32
        return MilliSatoshi(uint64(sat) * mSatScale)
×
UNCOV
33
}
×
34

35
// ToBTC converts the target MilliSatoshi amount to its corresponding value
36
// when expressed in BTC.
37
func (m MilliSatoshi) ToBTC() float64 {
×
38
        sat := m.ToSatoshis()
×
39
        return sat.ToBTC()
×
40
}
×
41

42
// ToSatoshis converts the target MilliSatoshi amount to satoshis. Simply, this
43
// sheds a factor of 1000 from the mSAT amount in order to convert it to SAT.
UNCOV
44
func (m MilliSatoshi) ToSatoshis() btcutil.Amount {
×
UNCOV
45
        return btcutil.Amount(uint64(m) / mSatScale)
×
UNCOV
46
}
×
47

48
// String returns the string representation of the mSAT amount.
49
func (m MilliSatoshi) String() string {
×
50
        return fmt.Sprintf("%v mSAT", uint64(m))
×
51
}
×
52

53
// TODO(roasbeef): extend with arithmetic operations?
54

55
// Record returns a TLV record that can be used to encode/decode a MilliSatoshi
56
// to/from a TLV stream.
UNCOV
57
func (m *MilliSatoshi) Record() tlv.Record {
×
UNCOV
58
        return tlv.MakeDynamicRecord(
×
UNCOV
59
                0, m, tlv.SizeBigSize(m), encodeMilliSatoshis,
×
UNCOV
60
                decodeMilliSatoshis,
×
UNCOV
61
        )
×
UNCOV
62
}
×
UNCOV
63
func encodeMilliSatoshis(w io.Writer, val interface{}, buf *[8]byte) error {
×
UNCOV
64
        if v, ok := val.(*MilliSatoshi); ok {
×
UNCOV
65
                bigSize := uint64(*v)
×
UNCOV
66

×
UNCOV
67
                return tlv.EBigSize(w, &bigSize, buf)
×
UNCOV
68
        }
×
69

70
        return tlv.NewTypeForEncodingErr(val, "lnwire.MilliSatoshi")
×
71
}
72

73
func decodeMilliSatoshis(r io.Reader, val interface{}, buf *[8]byte,
74
        l uint64) error {
×
75

×
76
        if v, ok := val.(*MilliSatoshi); ok {
×
77
                var bigSize uint64
×
78
                err := tlv.DBigSize(r, &bigSize, buf, l)
×
79
                if err != nil {
×
80
                        return err
×
81
                }
×
82

83
                *v = MilliSatoshi(bigSize)
×
84

×
85
                return nil
×
86
        }
87

88
        return tlv.NewTypeForDecodingErr(val, "lnwire.MilliSatoshi", l, l)
×
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc