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

lightningnetwork / lnd / 15249422085

26 May 2025 08:11AM UTC coverage: 57.977% (-11.0%) from 69.015%
15249422085

push

github

web-flow
Merge pull request #9853 from lightningnetwork/elle-graphSQL8-prep

graph/db: init SQLStore caches and batch schedulers

9 of 34 new or added lines in 4 files covered. (26.47%)

29283 existing lines in 458 files now uncovered.

96475 of 166402 relevant lines covered (57.98%)

1.22 hits per line

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

80.0
/lnwire/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.
31
func NewMSatFromSatoshis(sat btcutil.Amount) MilliSatoshi {
2✔
32
        return MilliSatoshi(uint64(sat) * mSatScale)
2✔
33
}
2✔
34

35
// ToBTC converts the target MilliSatoshi amount to its corresponding value
36
// when expressed in BTC.
UNCOV
37
func (m MilliSatoshi) ToBTC() float64 {
×
UNCOV
38
        sat := m.ToSatoshis()
×
UNCOV
39
        return sat.ToBTC()
×
UNCOV
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.
44
func (m MilliSatoshi) ToSatoshis() btcutil.Amount {
2✔
45
        return btcutil.Amount(uint64(m) / mSatScale)
2✔
46
}
2✔
47

48
// String returns the string representation of the mSAT amount.
49
func (m MilliSatoshi) String() string {
2✔
50
        return fmt.Sprintf("%v mSAT", uint64(m))
2✔
51
}
2✔
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.
57
func (m *MilliSatoshi) Record() tlv.Record {
2✔
58
        msat := uint64(*m)
2✔
59

2✔
60
        return tlv.MakeDynamicRecord(
2✔
61
                0, m, tlv.SizeBigSize(&msat), encodeMilliSatoshis,
2✔
62
                decodeMilliSatoshis,
2✔
63
        )
2✔
64
}
2✔
65

66
func encodeMilliSatoshis(w io.Writer, val interface{}, buf *[8]byte) error {
2✔
67
        if v, ok := val.(*MilliSatoshi); ok {
4✔
68
                bigSize := uint64(*v)
2✔
69

2✔
70
                return tlv.EBigSize(w, &bigSize, buf)
2✔
71
        }
2✔
72

73
        return tlv.NewTypeForEncodingErr(val, "lnwire.MilliSatoshi")
×
74
}
75

76
func decodeMilliSatoshis(r io.Reader, val interface{}, buf *[8]byte,
77
        l uint64) error {
2✔
78

2✔
79
        if v, ok := val.(*MilliSatoshi); ok {
4✔
80
                var bigSize uint64
2✔
81
                err := tlv.DBigSize(r, &bigSize, buf, l)
2✔
82
                if err != nil {
2✔
UNCOV
83
                        return err
×
UNCOV
84
                }
×
85

86
                *v = MilliSatoshi(bigSize)
2✔
87

2✔
88
                return nil
2✔
89
        }
90

91
        return tlv.NewTypeForDecodingErr(val, "lnwire.MilliSatoshi", l, l)
×
92
}
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