lnrpc: send custom message

This commit is contained in:
Joost Jager committed 2021-10-15 17:08:53 +02:00
1 parent 5d7e814ea8
commit ae959b16ae
14 files changed
+4451 -3825

No files matched your search

+26
View File
@@ -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
}