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

@ -5,6 +5,7 @@ import (
"time" "time"
"google.golang.org/grpc" "google.golang.org/grpc"
"li.lan/labs/plasma/lnrpc"
) )
// connects via grpc to the ln node. default (hardcoded?) local:10K // 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 { 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 return nil
} }
@ -59,5 +71,13 @@ func LnChat(args []string) error {
// msg := append([]byte{lnwire.MSGID_TEXTCHAT}, []byte(chat)...) // msg := append([]byte{lnwire.MSGID_TEXTCHAT}, []byte(chat)...)
fmt.Printf("will send text message: %s\n", 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 return nil
} }

@ -6,22 +6,40 @@ import (
"log" "log"
"os" "os"
"strings" "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() { func main() {
fmt.Printf("LNShell v0.0. \n") fmt.Printf("LNShell v0.0. \n")
fmt.Printf("Connects to LN daemon, default on 127.0.0.1:10000.\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 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 { for {
reader := bufio.NewReaderSize(os.Stdin, 4000) reader := bufio.NewReaderSize(os.Stdin, 4000)
fmt.Printf("->") fmt.Printf("->")
msg, err := reader.ReadString('\n') msg, err := reader.ReadString('\n')
if err != nil { if err != nil {
log.Fatal(err) return err
} }
cmdslice := strings.Fields(msg) cmdslice := strings.Fields(msg)
if len(cmdslice) < 1 { if len(cmdslice) < 1 {
@ -30,7 +48,7 @@ func shellPrompt() {
fmt.Printf("entered command: %s\n", msg) fmt.Printf("entered command: %s\n", msg)
err = Shellparse(cmdslice) err = Shellparse(cmdslice)
if err != nil { if err != nil {
log.Fatal(err) return err
} }
} }
} }
@ -60,15 +78,13 @@ func Shellparse(cmdslice []string) error {
} }
return nil return nil
} }
if cmd == "lnl" {
if cmd == "rpc" { err = LnListen(args)
err = RpcConnect(args)
if err != nil { if err != nil {
fmt.Printf("RPC connect error: %s\n", err) fmt.Printf("LN listen error: %s\n", err)
} }
return nil return nil
} }
fmt.Printf("Command not recognized.\n") fmt.Printf("Command not recognized.\n")
return nil return nil
} }

@ -2,6 +2,7 @@ package main
import ( import (
"encoding/hex" "encoding/hex"
"log"
"github.com/btcsuite/btcutil" "github.com/btcsuite/btcutil"
"github.com/btcsuite/btcwallet/waddrmgr" "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 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
}