2015-12-31 05:58:15 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"time"
|
|
|
|
|
2016-01-16 21:45:54 +03:00
|
|
|
"github.com/lightningnetwork/lnd/lnrpc"
|
2015-12-31 05:58:15 +03:00
|
|
|
"google.golang.org/grpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
// connects via grpc to the ln node. default (hardcoded?) local:10K
|
|
|
|
func RpcConnect(args []string) error {
|
|
|
|
// client := getClient(ctx)
|
|
|
|
opts := []grpc.DialOption{grpc.WithInsecure()}
|
|
|
|
conn, err := grpc.Dial("localhost:10000", opts...)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
state, err := conn.State()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Printf("connection state: %s\n", state.String())
|
|
|
|
time.Sleep(time.Second * 2)
|
|
|
|
// lnClient := lnrpc.NewLightningClient(conn)
|
|
|
|
// lnClient.NewAddress(nil, nil, nil) // crashes
|
|
|
|
|
|
|
|
state, err = conn.State()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Printf("connection state: %s\n", state.String())
|
|
|
|
|
|
|
|
err = conn.Close()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func LnConnect(args []string) error {
|
2015-12-31 06:56:57 +03:00
|
|
|
if len(args) == 0 {
|
|
|
|
return fmt.Errorf("need: lnc pubkeyhash@hostname or pkh (via pbx)")
|
|
|
|
}
|
|
|
|
|
2016-01-17 06:12:03 +03:00
|
|
|
req := &lnrpc.ConnectPeerRequest{args[0]}
|
|
|
|
resp, err := z.ConnectPeer(stub, req)
|
2015-12-31 08:40:41 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-01-17 06:12:03 +03:00
|
|
|
fmt.Printf("connected. remote lnid is %x\n", resp.LnID)
|
2015-12-31 05:58:15 +03:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// For testing. Syntax: lnhi hello world
|
2016-01-17 06:12:03 +03:00
|
|
|
/*func LnChat(args []string) error {
|
2016-01-02 07:27:40 +03:00
|
|
|
var err error
|
|
|
|
if len(args) < 2 {
|
|
|
|
return fmt.Errorf("too short, need: lnhi 32hexcharLNID message.\n")
|
|
|
|
}
|
|
|
|
req := new(lnrpc.LnChatRequest)
|
|
|
|
req.DestID, err = hex.DecodeString(args[0])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if len(req.DestID) != 16 {
|
|
|
|
return fmt.Errorf("requested destination %x is %d bytes, expenct 16\n",
|
|
|
|
req.DestID, len(req.DestID))
|
|
|
|
}
|
2015-12-31 05:58:15 +03:00
|
|
|
|
|
|
|
var chat string
|
2016-01-02 07:27:40 +03:00
|
|
|
for _, s := range args[1:] {
|
2015-12-31 05:58:15 +03:00
|
|
|
chat += s + " "
|
|
|
|
}
|
|
|
|
|
2016-01-02 07:27:40 +03:00
|
|
|
fmt.Printf("will send to %x text message: %s\n", req.DestID, chat)
|
|
|
|
|
2015-12-31 06:56:57 +03:00
|
|
|
req.Msg = chat
|
2016-01-02 07:27:40 +03:00
|
|
|
_, err = z.LNChat(stub, req)
|
2015-12-31 06:56:57 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
fmt.Printf("got response but there's nothing in it\n")
|
2015-12-31 05:58:15 +03:00
|
|
|
return nil
|
2016-01-17 06:12:03 +03:00
|
|
|
}*/
|