2015-12-30 05:31:03 +03:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2015-12-30 05:58:58 +03:00
|
|
|
"bytes"
|
2015-12-30 05:31:03 +03:00
|
|
|
"encoding/json"
|
2015-12-30 05:58:58 +03:00
|
|
|
"os"
|
2015-12-30 05:31:03 +03:00
|
|
|
|
|
|
|
"github.com/codegangsta/cli"
|
2016-01-16 21:45:54 +03:00
|
|
|
"github.com/lightningnetwork/lnd/lnrpc"
|
2015-12-30 05:31:03 +03:00
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
2015-12-30 05:58:58 +03:00
|
|
|
func printRespJson(resp interface{}) {
|
|
|
|
b, err := json.Marshal(resp)
|
|
|
|
if err != nil {
|
|
|
|
fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var out bytes.Buffer
|
|
|
|
json.Indent(&out, b, "", "\t")
|
|
|
|
out.WriteTo(os.Stdout)
|
|
|
|
}
|
|
|
|
|
2015-12-30 23:19:09 +03:00
|
|
|
var ShellCommand = cli.Command{
|
2016-01-18 06:18:08 +03:00
|
|
|
Name: "shell",
|
|
|
|
Usage: "enter interactive shell",
|
|
|
|
Action: func(c *cli.Context) {
|
|
|
|
println("not implemented yet")
|
|
|
|
},
|
2015-12-30 23:19:09 +03:00
|
|
|
}
|
|
|
|
|
2015-12-30 05:31:03 +03:00
|
|
|
var NewAddressCommand = cli.Command{
|
|
|
|
Name: "newaddress",
|
|
|
|
Usage: "gets the next address in the HD chain",
|
|
|
|
Action: newAddress,
|
|
|
|
}
|
|
|
|
|
|
|
|
func newAddress(ctx *cli.Context) {
|
|
|
|
client := getClient(ctx)
|
|
|
|
|
|
|
|
ctxb := context.Background()
|
|
|
|
addr, err := client.NewAddress(ctxb, &lnrpc.NewAddressRequest{})
|
|
|
|
if err != nil {
|
|
|
|
fatal(err)
|
|
|
|
}
|
|
|
|
|
2015-12-30 05:58:58 +03:00
|
|
|
printRespJson(addr)
|
2015-12-30 05:31:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
var SendManyCommand = cli.Command{
|
|
|
|
Name: "sendmany",
|
|
|
|
Usage: "create and broadcast a transaction paying the specified " +
|
|
|
|
"amount(s) to the passed address(es)",
|
|
|
|
Action: sendMany,
|
|
|
|
}
|
|
|
|
|
|
|
|
func sendMany(ctx *cli.Context) {
|
|
|
|
var amountToAddr map[string]int64
|
|
|
|
|
|
|
|
jsonMap := ctx.Args().Get(0)
|
|
|
|
if err := json.Unmarshal([]byte(jsonMap), &amountToAddr); err != nil {
|
|
|
|
fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
ctxb := context.Background()
|
|
|
|
client := getClient(ctx)
|
|
|
|
|
|
|
|
txid, err := client.SendMany(ctxb, &lnrpc.SendManyRequest{amountToAddr})
|
|
|
|
if err != nil {
|
|
|
|
fatal(err)
|
|
|
|
}
|
|
|
|
|
2015-12-30 05:58:58 +03:00
|
|
|
printRespJson(txid)
|
2015-12-30 05:31:03 +03:00
|
|
|
}
|
2016-01-17 06:10:29 +03:00
|
|
|
|
|
|
|
var ConnectCommand = cli.Command{
|
|
|
|
Name: "connect",
|
|
|
|
Usage: "connect to a remote lnd peer: <lnid>@host",
|
|
|
|
Action: connectPeer,
|
|
|
|
}
|
|
|
|
|
|
|
|
func connectPeer(ctx *cli.Context) {
|
|
|
|
ctxb := context.Background()
|
|
|
|
client := getClient(ctx)
|
|
|
|
|
|
|
|
targetAddress := ctx.Args().Get(0)
|
|
|
|
req := &lnrpc.ConnectPeerRequest{targetAddress}
|
|
|
|
|
|
|
|
lnid, err := client.ConnectPeer(ctxb, req)
|
|
|
|
if err != nil {
|
|
|
|
fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
printRespJson(lnid)
|
|
|
|
}
|