Пример #1
0
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 {
			return err
		}
		cmdslice := strings.Fields(msg)
		if len(cmdslice) < 1 {
			continue
		}
		fmt.Printf("entered command: %s\n", msg)
		err = Shellparse(cmdslice)
		if err != nil {
			return err
		}
	}
}
Пример #2
0
// start launches a new process running lnd. Additionally, the PID of the
// launched process is saved in order to possibly kill the process forcibly
// later.
func (l *lightningNode) start(lndError chan error) error {
	args := l.genArgs()

	l.cmd = exec.Command("lnd", args...)

	// Redirect stderr output to buffer
	var errb bytes.Buffer
	l.cmd.Stderr = &errb

	if err := l.cmd.Start(); err != nil {
		return err
	}

	// Launch a new goroutine which that bubbles up any potential fatal
	// process errors to the goroutine running the tests.
	go func() {
		if err := l.cmd.Wait(); err != nil {
			lndError <- errors.New(errb.String())
		}
	}()

	pid, err := os.Create(filepath.Join(l.cfg.DataDir,
		fmt.Sprintf("%s.pid", l.nodeId)))
	if err != nil {
		return err
	}
	l.pidFile = pid.Name()
	if _, err = fmt.Fprintf(pid, "%s\n", l.cmd.Process.Pid); err != nil {
		return err
	}
	if err := pid.Close(); err != nil {
		return err
	}

	opts := []grpc.DialOption{
		grpc.WithInsecure(),
		grpc.WithBlock(),
		grpc.WithTimeout(time.Second * 20),
	}
	conn, err := grpc.Dial(l.rpcAddr, opts...)
	if err != nil {
		return nil
	}

	l.LightningClient = lnrpc.NewLightningClient(conn)

	// Obtain the lnid of this node for quick identification purposes.
	ctxb := context.Background()
	info, err := l.GetInfo(ctxb, &lnrpc.GetInfoRequest{})
	if err != nil {
		return nil
	}

	l.PubKeyStr = info.IdentityPubkey

	pubkey, err := hex.DecodeString(info.IdentityPubkey)
	if err != nil {
		return err
	}
	copy(l.PubKey[:], pubkey)

	return nil
}
Пример #3
0
func getClient(ctx *cli.Context) lnrpc.LightningClient {
	conn := getClientConn(ctx)
	return lnrpc.NewLightningClient(conn)
}