Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
95 changes: 95 additions & 0 deletions cmd/commands/cmd_onion_message.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package commands

import (
"encoding/hex"
"fmt"

"github.com/lightningnetwork/lnd/lnrpc"
"github.com/urfave/cli"
)

var sendOnionMessageCommand = cli.Command{
Name: "sendonionmessage",
Category: "Peers",
Usage: "Send an onion message to a peer",
Flags: []cli.Flag{
cli.StringFlag{
Name: "peer",
},
cli.StringFlag{
Name: "path_key",
},
cli.StringFlag{
Name: "onion",
},
},
Action: actionDecorator(sendOnionMessage),
}

// sendOnionMessage sends an onion message to a peer.
func sendOnionMessage(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()

peer, err := hex.DecodeString(ctx.String("peer"))
if err != nil {
return fmt.Errorf("invalid peer hex: %w", err)
}

pathKey, err := hex.DecodeString(ctx.String("path_key"))
if err != nil {
return fmt.Errorf("invalid path_key hex: %w", err)
}

onion, err := hex.DecodeString(ctx.String("onion"))
if err != nil {
return fmt.Errorf("invalid onion hex: %w", err)
}

resp, err := client.SendOnionMessage(
ctxc, &lnrpc.SendOnionMessageRequest{
Peer: peer,
PathKey: pathKey,
Onion: onion,
},
)

if err != nil {
return err
}

printRespJSON(resp)

return nil
}

var subscribeOnionMessageCommand = cli.Command{
Name: "subscribeonionmessage",
Category: "Peers",
Usage: "Subscribe to incoming onion messages",
Action: actionDecorator(subscribeOnionMessage),
}

// subscribeOnionMessage subscribes to incoming onion messages.
func subscribeOnionMessage(ctx *cli.Context) error {
ctxc := getContext()
client, cleanUp := getClient(ctx)
defer cleanUp()

stream, err := client.SubscribeOnionMessages(
ctxc, &lnrpc.SubscribeOnionMessagesRequest{},
)
if err != nil {
return err
}

for {
msg, err := stream.Recv()
if err != nil {
return err
}

printRespJSON(msg)
}
}
2 changes: 2 additions & 0 deletions cmd/commands/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,8 @@ func Main() {
deletePaymentsCommand,
sendCustomCommand,
subscribeCustomCommand,
sendOnionMessageCommand,
subscribeOnionMessageCommand,
fishCompletionCommand,
listAliasesCommand,
estimateRouteFeeCommand,
Expand Down
4 changes: 4 additions & 0 deletions docs/release-notes/release-notes-0.21.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@
* The `estimatefee` command now supports the `--utxos` flag to specify explicit
inputs for fee estimation.

* [`SendOnionMessage` and `SubscribeOnionMessages`](https://github.com/lightningnetwork/lnd/pull/10560)
RPCs now have corresponding `lncli` commands.

# Improvements
## Functional Updates

Expand Down Expand Up @@ -177,6 +180,7 @@

# Contributors (Alphabetical Order)

* Abdulkbk
* Boris Nagaev
* Elle Mouton
* Erick Cestari
Expand Down
4 changes: 2 additions & 2 deletions lnrpc/lightning.proto
Original file line number Diff line number Diff line change
Expand Up @@ -597,13 +597,13 @@ service Lightning {
rpc SubscribeCustomMessages (SubscribeCustomMessagesRequest)
returns (stream CustomMessage);

/* lncli: `sendonion`
/* lncli: `sendonionmessage`
SendOnionMessage sends an onion message to a peer.
*/
rpc SendOnionMessage (SendOnionMessageRequest)
returns (SendOnionMessageResponse);

/* lncli: `subscribeonion`
/* lncli: `subscribeonionmessage`
SubscribeOnionMessages subscribes to a stream of incoming onion messages.
*/
rpc SubscribeOnionMessages (SubscribeOnionMessagesRequest)
Expand Down
4 changes: 2 additions & 2 deletions lnrpc/lightning.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2266,7 +2266,7 @@
},
"/v1/onionmessage": {
"post": {
"summary": "lncli: `sendonion`\nSendOnionMessage sends an onion message to a peer.",
"summary": "lncli: `sendonionmessage`\nSendOnionMessage sends an onion message to a peer.",
"operationId": "Lightning_SendOnionMessage",
"responses": {
"200": {
Expand Down Expand Up @@ -2299,7 +2299,7 @@
},
"/v1/onionmessage/subscribe": {
"get": {
"summary": "lncli: `subscribeonion`\nSubscribeOnionMessages subscribes to a stream of incoming onion messages.",
"summary": "lncli: `subscribeonionmessage`\nSubscribeOnionMessages subscribes to a stream of incoming onion messages.",
"operationId": "Lightning_SubscribeOnionMessages",
"responses": {
"200": {
Expand Down
8 changes: 4 additions & 4 deletions lnrpc/lightning_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading