lnrpc: send custom message

This commit is contained in:
Joost Jager
2021-05-31 10:03:47 +02:00
parent 5d7e814ea8
commit ae959b16ae
14 changed files with 4451 additions and 3825 deletions

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
}