From a5becc2063edb4997377b75722788db801005d9f Mon Sep 17 00:00:00 2001 From: "Johan T. Halseth" Date: Tue, 5 Mar 2019 14:22:30 +0100 Subject: [PATCH] lncli: add `estimatefee` command --- cmd/lncli/commands.go | 46 +++++++++++++++++++++++++++++++++++++++++++ cmd/lncli/main.go | 1 + 2 files changed, 47 insertions(+) diff --git a/cmd/lncli/commands.go b/cmd/lncli/commands.go index 3d51fa98..2b390048 100644 --- a/cmd/lncli/commands.go +++ b/cmd/lncli/commands.go @@ -144,6 +144,52 @@ func newAddress(ctx *cli.Context) error { return nil } +var estimateFeeCommand = cli.Command{ + Name: "estimatefee", + Category: "On-chain", + Usage: "Get fee estimates for sending bitcoin on-chain to multiple addresses.", + ArgsUsage: "send-json-string [--conf_target=N]", + Description: ` + Get fee estimates for sending a transaction paying the specified amount(s) to the passed address(es). + + The send-json-string' param decodes addresses and the amount to send respectively in the following format: + + '{"ExampleAddr": NumCoinsInSatoshis, "SecondAddr": NumCoins}' + `, + Flags: []cli.Flag{ + cli.Int64Flag{ + Name: "conf_target", + Usage: "(optional) the number of blocks that the transaction *should* " + + "confirm in", + }, + }, + Action: actionDecorator(estimateFees), +} + +func estimateFees(ctx *cli.Context) error { + var amountToAddr map[string]int64 + + jsonMap := ctx.Args().First() + if err := json.Unmarshal([]byte(jsonMap), &amountToAddr); err != nil { + return err + } + + ctxb := context.Background() + client, cleanUp := getClient(ctx) + defer cleanUp() + + resp, err := client.EstimateFee(ctxb, &lnrpc.EstimateFeeRequest{ + AddrToAmount: amountToAddr, + TargetConf: int32(ctx.Int64("conf_target")), + }) + if err != nil { + return err + } + + printRespJSON(resp) + return nil +} + var sendCoinsCommand = cli.Command{ Name: "sendcoins", Category: "On-chain", diff --git a/cmd/lncli/main.go b/cmd/lncli/main.go index 6a930c5f..4c9105ff 100644 --- a/cmd/lncli/main.go +++ b/cmd/lncli/main.go @@ -257,6 +257,7 @@ func main() { unlockCommand, changePasswordCommand, newAddressCommand, + estimateFeeCommand, sendManyCommand, sendCoinsCommand, listUnspentCommand,