Skip to content

Commit

Permalink
Merge pull request #911 from GeorgeTsagk/fix-litcli-panic
Browse files Browse the repository at this point in the history
Fix litcli sendpayment panic
  • Loading branch information
Roasbeef authored Dec 4, 2024
2 parents d48feca + 7220dae commit d4505dd
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cmd/litcli/ln.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,28 @@ func (w *resultStreamWrapper) Recv() (*lnrpc.Payment, error) {
amountMsat := lnwire.MilliSatoshi(w.amountMsat)
milliSatsFP := rfqmath.MilliSatoshiToUnits(amountMsat, *rate)
numUnits := milliSatsFP.ScaleTo(0).ToUint64()

// If the calculated number of units is 0 then the asset rate
// was not sufficient to represent the value of this payment.
if numUnits == 0 {
// We will calculate the minimum amount that can be
// effectively sent with this asset by calculating the
// value of a single asset unit, based on the provided
// asset rate.

// We create the single unit.
unit := rfqmath.FixedPointFromUint64[rfqmath.BigInt](
1, 0,
)
// We derive the minimum amount.
minAmt := rfqmath.UnitsToMilliSatoshi(unit, *rate)

// We return the error to the user.
return nil, fmt.Errorf("smallest payment with asset "+
"rate %v is %v, cannot send %v",
rate.ToUint64(), minAmt, amountMsat)
}

msatPerUnit := uint64(w.amountMsat) / numUnits

fmt.Printf("Got quote for %v asset units at %v msat/unit from "+
Expand Down

0 comments on commit d4505dd

Please sign in to comment.