Skip to content

Commit d4505dd

Browse files
authored
Merge pull request #911 from GeorgeTsagk/fix-litcli-panic
Fix litcli sendpayment panic
2 parents d48feca + 7220dae commit d4505dd

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

cmd/litcli/ln.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,28 @@ func (w *resultStreamWrapper) Recv() (*lnrpc.Payment, error) {
216216
amountMsat := lnwire.MilliSatoshi(w.amountMsat)
217217
milliSatsFP := rfqmath.MilliSatoshiToUnits(amountMsat, *rate)
218218
numUnits := milliSatsFP.ScaleTo(0).ToUint64()
219+
220+
// If the calculated number of units is 0 then the asset rate
221+
// was not sufficient to represent the value of this payment.
222+
if numUnits == 0 {
223+
// We will calculate the minimum amount that can be
224+
// effectively sent with this asset by calculating the
225+
// value of a single asset unit, based on the provided
226+
// asset rate.
227+
228+
// We create the single unit.
229+
unit := rfqmath.FixedPointFromUint64[rfqmath.BigInt](
230+
1, 0,
231+
)
232+
// We derive the minimum amount.
233+
minAmt := rfqmath.UnitsToMilliSatoshi(unit, *rate)
234+
235+
// We return the error to the user.
236+
return nil, fmt.Errorf("smallest payment with asset "+
237+
"rate %v is %v, cannot send %v",
238+
rate.ToUint64(), minAmt, amountMsat)
239+
}
240+
219241
msatPerUnit := uint64(w.amountMsat) / numUnits
220242

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

0 commit comments

Comments
 (0)