From f83d56c91ff7bb5555e25b6b76d9a74584c9545b Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sat, 24 Feb 2018 19:08:43 -0800 Subject: [PATCH] lnwire: modify lnwire.MilliSatoshi to be an unsigned integer In this commit, we modify lnwire.MilliSatoshi to be an unsigned integer. We do this as all values within the specification are meant to be unsigned unless otherwise specified. Our usage of signed integers to this date has caused some compatibility issues with the other implementations, so this is the first step to reconciling these compatibility issues. --- lnwire/msat.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lnwire/msat.go b/lnwire/msat.go index 1a1e21e0..9ab0e31d 100644 --- a/lnwire/msat.go +++ b/lnwire/msat.go @@ -8,7 +8,7 @@ import ( // mSatScale is a value that's used to scale satoshis to milli-satoshis, and // the other way around. -const mSatScale int64 = 1000 +const mSatScale uint64 = 1000 // MilliSatoshi are the native unit of the Lightning Network. A milli-satoshi // is simply 1/1000th of a satoshi. There are 1000 milli-satoshis in a single @@ -16,12 +16,12 @@ const mSatScale int64 = 1000 // milli-satoshis. As milli-satoshis aren't deliverable on the native // blockchain, before settling to broadcasting, the values are rounded down to // the nearest satoshi. -type MilliSatoshi int64 +type MilliSatoshi uint64 // NewMSatFromSatoshis creates a new MilliSatoshi instance from a target amount // of satoshis. func NewMSatFromSatoshis(sat btcutil.Amount) MilliSatoshi { - return MilliSatoshi(int64(sat) * mSatScale) + return MilliSatoshi(uint64(sat) * mSatScale) } // ToBTC converts the target MilliSatoshi amount to its corresponding value @@ -34,10 +34,12 @@ func (m MilliSatoshi) ToBTC() float64 { // ToSatoshis converts the target MilliSatoshi amount to satoshis. Simply, this // sheds a factor of 1000 from the mSAT amount in order to convert it to SAT. func (m MilliSatoshi) ToSatoshis() btcutil.Amount { - return btcutil.Amount(int64(m) / mSatScale) + return btcutil.Amount(uint64(m) / mSatScale) } // String returns the string representation of the mSAT amount. func (m MilliSatoshi) String() string { - return fmt.Sprintf("%v mSAT", int64(m)) + return fmt.Sprintf("%v mSAT", uint64(m)) } + +// TODO(roasbeef): extend with arithmetic operations?