From e391cf088e3a62a40036c2370b16c7f2158763fa Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 29 Jun 2016 11:29:21 -0700 Subject: [PATCH] cmd/lncli: add support for the sendcoins RPC --- cmd/lncli/commands.go | 37 ++++++++++++++++++++++++++++++++++++- cmd/lncli/main.go | 1 + 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/cmd/lncli/commands.go b/cmd/lncli/commands.go index 2b00d493..107b73f6 100644 --- a/cmd/lncli/commands.go +++ b/cmd/lncli/commands.go @@ -74,10 +74,45 @@ func newAddress(ctx *cli.Context) { printRespJson(addr) } +var SendCoinsCommand = cli.Command{ + Name: "sendcoins", + Description: "send a specified amount of bitcoin to the passed address", + Usage: "sendcoins --addr= --amt=", + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "addr", + Usage: "the bitcoin address to send coins to on-chain", + }, + // TODO(roasbeef): switch to BTC on command line? int may not be sufficient + cli.IntFlag{ + Name: "amt", + Usage: "the number of bitcoin denominated in satoshis to send", + }, + }, + Action: sendCoins, +} + +func sendCoins(ctx *cli.Context) { + ctxb := context.Background() + client := getClient(ctx) + + req := &lnrpc.SendCoinsRequest{ + Addr: ctx.String("addr"), + Amount: int64(ctx.Int("amt")), + } + txid, err := client.SendCoins(ctxb, req) + if err != nil { + fatal(err) + } + + printRespJson(txid) +} + var SendManyCommand = cli.Command{ Name: "sendmany", - Usage: "create and broadcast a transaction paying the specified " + + Description: "create and broadcast a transaction paying the specified " + "amount(s) to the passed address(es)", + Usage: `sendmany '{"ExampleAddr": NumCoinsInSatoshis, "SecondAddr": NumCoins}'`, Action: sendMany, } diff --git a/cmd/lncli/main.go b/cmd/lncli/main.go index 073d31c7..e997cc5d 100644 --- a/cmd/lncli/main.go +++ b/cmd/lncli/main.go @@ -50,6 +50,7 @@ func main() { app.Commands = []cli.Command{ NewAddressCommand, SendManyCommand, + SendCoinsCommand, ConnectCommand, OpenChannelCommand, CloseChannelCommand,