@@ -383,6 +383,14 @@ func (s *SwapService) SwapOut(peer string, chain string, channelId string, initi
383
383
return nil , err
384
384
}
385
385
386
+ sp , err := s .swapServices .lightning .SpendableMsat (channelId )
387
+ if err != nil {
388
+ return nil , err
389
+ }
390
+ if sp <= amtSat * 1000 {
391
+ return nil , fmt .Errorf ("exceeding spendable amount_msat: %d" , sp )
392
+ }
393
+
386
394
success , failureReason , err := s .swapServices .lightning .ProbePayment (channelId , amtSat * 1000 )
387
395
if err != nil {
388
396
return nil , err
@@ -506,6 +514,30 @@ func (s *SwapService) OnSwapInRequestReceived(swapId *SwapId, peerId string, mes
506
514
return err
507
515
}
508
516
517
+ sp , err := s .swapServices .lightning .SpendableMsat (message .Scid )
518
+ if err != nil {
519
+ msg := fmt .Sprintf ("from the %s peer: %s" , s .swapServices .lightning .Implementation (), err .Error ())
520
+ // We want to tell our peer why we can not do this swap.
521
+ msgBytes , msgType , err := MarshalPeerswapMessage (& CancelMessage {
522
+ SwapId : swapId ,
523
+ Message : msg ,
524
+ })
525
+ s .swapServices .messenger .SendMessage (peerId , msgBytes , msgType )
526
+ return err
527
+ }
528
+
529
+ if sp <= message .Amount * 1000 {
530
+ err = fmt .Errorf ("exceeding spendable amount_msat: %d" , sp )
531
+ msg := fmt .Sprintf ("from the %s peer: %s" , s .swapServices .lightning .Implementation (), err .Error ())
532
+ // We want to tell our peer why we can not do this swap.
533
+ msgBytes , msgType , err := MarshalPeerswapMessage (& CancelMessage {
534
+ SwapId : swapId ,
535
+ Message : msg ,
536
+ })
537
+ s .swapServices .messenger .SendMessage (peerId , msgBytes , msgType )
538
+ return err
539
+ }
540
+
509
541
success , failureReason , err := s .swapServices .lightning .ProbePayment (message .Scid , message .Amount * 1000 )
510
542
if err != nil {
511
543
msg := fmt .Sprintf ("from the %s peer: %s" , s .swapServices .lightning .Implementation (), err .Error ())
0 commit comments