Skip to content

Commit 48ba4a9

Browse files
committed
itest+rpcserver: check channel balance on keysend
1 parent e0d18c6 commit 48ba4a9

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

itest/channels_test.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ func testChannelRPCs(t *harnessTest) {
6161
require.NoError(t.t, err)
6262

6363
_, err = stream.Recv()
64-
require.ErrorContains(t.t, err, "invalid vertex length of 0, want 33")
64+
require.ErrorContains(
65+
t.t, err, "destination node must be specified for keysend "+
66+
"payment",
67+
)
6568

6669
// Now let's also try the invoice path, which should fail because we
6770
// don't have any asset channels with peers that we could ask for a

rpcserver.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7743,8 +7743,26 @@ func (r *rpcServer) SendPayment(req *tchrpc.SendPaymentRequest,
77437743
"for keysend payment")
77447744
}
77457745

7746-
var balances []*rfqmsg.AssetBalance
7746+
if len(req.PaymentRequest.Dest) == 0 {
7747+
return fmt.Errorf("destination node must be " +
7748+
"specified for keysend payment")
7749+
}
7750+
7751+
dest, err := route.NewVertexFromBytes(req.PaymentRequest.Dest)
7752+
if err != nil {
7753+
return fmt.Errorf("error parsing destination node "+
7754+
"pubkey: %w", err)
7755+
}
77477756

7757+
// We check that we have the asset amount available in the
7758+
// channel.
7759+
_, err = r.rfqChannel(ctx, specifier, &dest, SendIntention)
7760+
if err != nil {
7761+
return fmt.Errorf("error finding asset channel to "+
7762+
"use: %w", err)
7763+
}
7764+
7765+
var balances []*rfqmsg.AssetBalance
77487766
switch {
77497767
case specifier.HasId():
77507768
balances = []*rfqmsg.AssetBalance{

0 commit comments

Comments
 (0)