can send messages from shell over grpc. doesn't do anything yet.

This commit is contained in:
Tadge Dryja
2015-12-30 23:56:57 -04:00
committed by Olaoluwa Osuntokun
parent e5e2a9a162
commit 8bd8293c8c
3 changed files with 73 additions and 10 deletions

View File

@@ -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
}

View File

@@ -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
}