mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-03-04 01:36:24 +01:00
cmd/lncli: add --stateless_init to createwatchonly command
This commit is contained in:
parent
d321182220
commit
04376b3b23
1 changed files with 29 additions and 5 deletions
|
@ -687,6 +687,10 @@ var createWatchOnlyCommand = cli.Command{
|
|||
Read the documentation under docs/remote-signing.md for more information
|
||||
on how to set up a remote signing node over RPC.
|
||||
`,
|
||||
Flags: []cli.Flag{
|
||||
statelessInitFlag,
|
||||
saveToFlag,
|
||||
},
|
||||
Action: actionDecorator(createWatchOnly),
|
||||
}
|
||||
|
||||
|
@ -699,6 +703,15 @@ func createWatchOnly(ctx *cli.Context) error {
|
|||
return cli.ShowCommandHelp(ctx, "createwatchonly")
|
||||
}
|
||||
|
||||
// Should the daemon be initialized stateless? Then we expect an answer
|
||||
// with the admin macaroon later. Because the --save_to is related to
|
||||
// stateless init, it doesn't make sense to be set on its own.
|
||||
statelessInit := ctx.Bool(statelessInitFlag.Name)
|
||||
if !statelessInit && ctx.IsSet(saveToFlag.Name) {
|
||||
return fmt.Errorf("cannot set save_to parameter without " +
|
||||
"stateless_init")
|
||||
}
|
||||
|
||||
jsonFile := lncfg.CleanAndExpandPath(ctx.Args().First())
|
||||
jsonBytes, err := ioutil.ReadFile(jsonFile)
|
||||
if err != nil {
|
||||
|
@ -754,22 +767,33 @@ func createWatchOnly(ctx *cli.Context) error {
|
|||
}
|
||||
}
|
||||
|
||||
_, err = client.InitWallet(ctxc, &lnrpc.InitWalletRequest{
|
||||
initResp, err := client.InitWallet(ctxc, &lnrpc.InitWalletRequest{
|
||||
WalletPassword: walletPassword,
|
||||
WatchOnly: rpcResp,
|
||||
RecoveryWindow: recoveryWindow,
|
||||
StatelessInit: statelessInit,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if statelessInit {
|
||||
return storeOrPrintAdminMac(ctx, initResp.AdminMacaroon)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// storeOrPrintAdminMac either stores the admin macaroon to a file specified or
|
||||
// prints it to standard out, depending on the user flags set.
|
||||
func storeOrPrintAdminMac(ctx *cli.Context, adminMac []byte) error {
|
||||
// The user specified the optional --save_to parameter. We'll save the
|
||||
// macaroon to that file.
|
||||
if ctx.IsSet("save_to") {
|
||||
macSavePath := lncfg.CleanAndExpandPath(ctx.String("save_to"))
|
||||
err := ioutil.WriteFile(macSavePath, adminMac, 0644)
|
||||
if ctx.IsSet(saveToFlag.Name) {
|
||||
macSavePath := lncfg.CleanAndExpandPath(ctx.String(
|
||||
saveToFlag.Name,
|
||||
))
|
||||
err := os.WriteFile(macSavePath, adminMac, 0644)
|
||||
if err != nil {
|
||||
_ = os.Remove(macSavePath)
|
||||
return err
|
||||
|
|
Loading…
Add table
Reference in a new issue