lncli: add estimatefee command

This commit is contained in:
Johan T. Halseth 2019-03-05 14:22:30 +01:00
parent 1e2af38f5a
commit a5becc2063
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26
2 changed files with 47 additions and 0 deletions

@ -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",

@ -257,6 +257,7 @@ func main() {
unlockCommand,
changePasswordCommand,
newAddressCommand,
estimateFeeCommand,
sendManyCommand,
sendCoinsCommand,
listUnspentCommand,