Merge pull request #7462 from guggero/createwatchonly-stateless
remote signer: allow stateless init of watch-only node
This commit is contained in:
2 files changed
+32
-5
No files matched your search
@@ -687,6 +687,10 @@ var createWatchOnlyCommand = cli.Command{
|
|||||||
Read the documentation under docs/remote-signing.md for more information
|
Read the documentation under docs/remote-signing.md for more information
|
||||||
on how to set up a remote signing node over RPC.
|
on how to set up a remote signing node over RPC.
|
||||||
`,
|
`,
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
statelessInitFlag,
|
||||||
|
saveToFlag,
|
||||||
|
},
|
||||||
Action: actionDecorator(createWatchOnly),
|
Action: actionDecorator(createWatchOnly),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -699,6 +703,15 @@ func createWatchOnly(ctx *cli.Context) error {
|
|||||||
return cli.ShowCommandHelp(ctx, "createwatchonly")
|
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())
|
jsonFile := lncfg.CleanAndExpandPath(ctx.Args().First())
|
||||||
jsonBytes, err := ioutil.ReadFile(jsonFile)
|
jsonBytes, err := ioutil.ReadFile(jsonFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -754,12 +767,21 @@ func createWatchOnly(ctx *cli.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = client.InitWallet(ctxc, &lnrpc.InitWalletRequest{
|
initResp, err := client.InitWallet(ctxc, &lnrpc.InitWalletRequest{
|
||||||
WalletPassword: walletPassword,
|
WalletPassword: walletPassword,
|
||||||
WatchOnly: rpcResp,
|
WatchOnly: rpcResp,
|
||||||
RecoveryWindow: recoveryWindow,
|
RecoveryWindow: recoveryWindow,
|
||||||
|
StatelessInit: statelessInit,
|
||||||
})
|
})
|
||||||
return err
|
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
|
// storeOrPrintAdminMac either stores the admin macaroon to a file specified or
|
||||||
@@ -767,9 +789,11 @@ func createWatchOnly(ctx *cli.Context) error {
|
|||||||
func storeOrPrintAdminMac(ctx *cli.Context, adminMac []byte) error {
|
func storeOrPrintAdminMac(ctx *cli.Context, adminMac []byte) error {
|
||||||
// The user specified the optional --save_to parameter. We'll save the
|
// The user specified the optional --save_to parameter. We'll save the
|
||||||
// macaroon to that file.
|
// macaroon to that file.
|
||||||
if ctx.IsSet("save_to") {
|
if ctx.IsSet(saveToFlag.Name) {
|
||||||
macSavePath := lncfg.CleanAndExpandPath(ctx.String("save_to"))
|
macSavePath := lncfg.CleanAndExpandPath(ctx.String(
|
||||||
err := ioutil.WriteFile(macSavePath, adminMac, 0644)
|
saveToFlag.Name,
|
||||||
|
))
|
||||||
|
err := os.WriteFile(macSavePath, adminMac, 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
_ = os.Remove(macSavePath)
|
_ = os.Remove(macSavePath)
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -355,6 +355,9 @@ in the lnwire package](https://github.com/lightningnetwork/lnd/pull/7303)
|
|||||||
* [Sign/Verify messages and signatures for single
|
* [Sign/Verify messages and signatures for single
|
||||||
addresses](https://github.com/lightningnetwork/lnd/pull/7231).
|
addresses](https://github.com/lightningnetwork/lnd/pull/7231).
|
||||||
|
|
||||||
|
* [Allow `--stateless_init` mode to be used for watch-only
|
||||||
|
wallets](https://github.com/lightningnetwork/lnd/pull/7462).
|
||||||
|
|
||||||
## Code Health
|
## Code Health
|
||||||
|
|
||||||
* [test: use `T.TempDir` to create temporary test
|
* [test: use `T.TempDir` to create temporary test
|
||||||
|
|||||||
Reference in new issue
Block a user