mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-19 01:43:16 +01:00
can send messages from shell over grpc. doesn't do anything yet.
This commit is contained in:
parent
e5e2a9a162
commit
8bd8293c8c
@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"li.lan/labs/plasma/lnrpc"
|
||||
)
|
||||
|
||||
// connects via grpc to the ln node. default (hardcoded?) local:10K
|
||||
@ -38,7 +39,18 @@ func RpcConnect(args []string) error {
|
||||
}
|
||||
|
||||
func LnConnect(args []string) error {
|
||||
fmt.Printf("lnconnect, %d args\n", len(args))
|
||||
// var err error
|
||||
if len(args) == 0 {
|
||||
return fmt.Errorf("need: lnc pubkeyhash@hostname or pkh (via pbx)")
|
||||
}
|
||||
|
||||
req := new(lnrpc.LNConnectRequest)
|
||||
req.IdAtHost = args[0]
|
||||
resp, err := z.LNConnect(stub, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("connected. remote lnid is %x\n", resp.LnID)
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -59,5 +71,13 @@ func LnChat(args []string) error {
|
||||
// msg := append([]byte{lnwire.MSGID_TEXTCHAT}, []byte(chat)...)
|
||||
|
||||
fmt.Printf("will send text message: %s\n", chat)
|
||||
req := new(lnrpc.LnChatRequest)
|
||||
req.DestID = []byte("testID")
|
||||
req.Msg = chat
|
||||
_, err := z.LNChat(stub, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Printf("got response but there's nothing in it\n")
|
||||
return nil
|
||||
}
|
||||
|
@ -6,22 +6,40 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"golang.org/x/net/context"
|
||||
"google.golang.org/grpc"
|
||||
"li.lan/labs/plasma/lnrpc"
|
||||
)
|
||||
|
||||
var z lnrpc.LightningClient
|
||||
var stub context.Context
|
||||
|
||||
func main() {
|
||||
fmt.Printf("LNShell v0.0. \n")
|
||||
fmt.Printf("Connects to LN daemon, default on 127.0.0.1:10000.\n")
|
||||
shellPrompt()
|
||||
err := shellPrompt()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func shellPrompt() {
|
||||
func shellPrompt() error {
|
||||
stub = context.Background()
|
||||
opts := []grpc.DialOption{grpc.WithInsecure()}
|
||||
conn, err := grpc.Dial("localhost:10000", opts...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
z = lnrpc.NewLightningClient(conn)
|
||||
|
||||
for {
|
||||
reader := bufio.NewReaderSize(os.Stdin, 4000)
|
||||
fmt.Printf("->")
|
||||
msg, err := reader.ReadString('\n')
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
cmdslice := strings.Fields(msg)
|
||||
if len(cmdslice) < 1 {
|
||||
@ -30,7 +48,7 @@ func shellPrompt() {
|
||||
fmt.Printf("entered command: %s\n", msg)
|
||||
err = Shellparse(cmdslice)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -60,15 +78,13 @@ func Shellparse(cmdslice []string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if cmd == "rpc" {
|
||||
err = RpcConnect(args)
|
||||
if cmd == "lnl" {
|
||||
err = LnListen(args)
|
||||
if err != nil {
|
||||
fmt.Printf("RPC connect error: %s\n", err)
|
||||
fmt.Printf("LN listen error: %s\n", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
fmt.Printf("Command not recognized.\n")
|
||||
return nil
|
||||
}
|
||||
|
27
rpcserver.go
27
rpcserver.go
@ -2,6 +2,7 @@ package main
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"log"
|
||||
|
||||
"github.com/btcsuite/btcutil"
|
||||
"github.com/btcsuite/btcwallet/waddrmgr"
|
||||
@ -55,3 +56,29 @@ func (r *rpcServer) NewAddress(ctx context.Context, in *lnrpc.NewAddressRequest)
|
||||
|
||||
return &lnrpc.NewAddressResponse{Address: addr.String()}, nil
|
||||
}
|
||||
|
||||
// LNConnect
|
||||
func (r *rpcServer) LNConnect(ctx context.Context,
|
||||
in *lnrpc.LNConnectRequest) (*lnrpc.LnConnectResponse, error) {
|
||||
|
||||
resp := new(lnrpc.LnConnectResponse)
|
||||
resp.LnID = []byte("ya")
|
||||
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// TCPListen
|
||||
func (r *rpcServer) TCPListen(ctx context.Context,
|
||||
in *lnrpc.TCPListenRequest) (*lnrpc.TCPListenResponse, error) {
|
||||
|
||||
resp := new(lnrpc.TCPListenResponse)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// LNChat
|
||||
func (r *rpcServer) LNChat(ctx context.Context,
|
||||
in *lnrpc.LnChatRequest) (*lnrpc.LnChatResponse, error) {
|
||||
log.Printf("requested to chat, message: %s\n", in.Msg)
|
||||
resp := new(lnrpc.LnChatResponse)
|
||||
return resp, nil
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user