mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-10-09 21:53:07 +02:00
lnrpc: send custom message
This commit is contained in:
26
rpcserver.go
26
rpcserver.go
@@ -568,6 +568,10 @@ func MainRPCServerPermissions() map[string][]bakery.Op {
|
||||
Entity: "macaroon",
|
||||
Action: "write",
|
||||
}},
|
||||
"/lnrpc.Lightning/SendCustomMessage": {{
|
||||
Entity: "offchain",
|
||||
Action: "write",
|
||||
}},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7319,3 +7323,25 @@ func (r *rpcServer) RegisterRPCMiddleware(
|
||||
|
||||
return middleware.Run()
|
||||
}
|
||||
|
||||
// SendCustomMessage sends a custom peer message.
|
||||
func (r *rpcServer) SendCustomMessage(ctx context.Context, req *lnrpc.SendCustomMessageRequest) (
|
||||
*lnrpc.SendCustomMessageResponse, error) {
|
||||
|
||||
peer, err := route.NewVertexFromBytes(req.Peer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = r.server.SendCustomMessage(
|
||||
peer, lnwire.MessageType(req.Type), req.Data,
|
||||
)
|
||||
switch {
|
||||
case err == ErrPeerNotConnected:
|
||||
return nil, status.Error(codes.NotFound, err.Error())
|
||||
case err != nil:
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &lnrpc.SendCustomMessageResponse{}, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user