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

lightningnetwork / lnd / 9915780197

13 Jul 2024 12:30AM UTC coverage: 49.268% (-9.1%) from 58.413%
9915780197

push

github

web-flow
Merge pull request #8653 from ProofOfKeags/fn-prim

DynComms [0/n]: `fn` package additions

92837 of 188433 relevant lines covered (49.27%)

1.55 hits per line

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

69.23
/lnwire/msat.go
1
package lnwire
2

3
import (
4
        "fmt"
5

6
        "github.com/btcsuite/btcd/btcutil"
7
)
8

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

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

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

27
// NewMSatFromSatoshis creates a new MilliSatoshi instance from a target amount
28
// of satoshis.
29
func NewMSatFromSatoshis(sat btcutil.Amount) MilliSatoshi {
3✔
30
        return MilliSatoshi(uint64(sat) * mSatScale)
3✔
31
}
3✔
32

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

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

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

51
// TODO(roasbeef): extend with arithmetic operations?
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