lncli: extract askRecoveryWindow

This commit is contained in:
Oliver Gugger 2020-10-24 23:18:51 +02:00
parent aa9435be84
commit bdae6711af
No known key found for this signature in database
GPG Key ID: 8E4256593F177720

View File

@ -288,36 +288,9 @@ mnemonicCheck:
return err
}
for {
fmt.Println()
fmt.Printf("Input an optional address look-ahead "+
"used to scan for used keys (default %d): ",
defaultRecoveryWindow)
reader := bufio.NewReader(os.Stdin)
answer, err := reader.ReadString('\n')
if err != nil {
return err
}
fmt.Println()
answer = strings.TrimSpace(answer)
if len(answer) == 0 {
recoveryWindow = defaultRecoveryWindow
break
}
lookAhead, err := strconv.Atoi(answer)
if err != nil {
fmt.Printf("Unable to parse recovery "+
"window: %v\n", err)
continue
}
recoveryWindow = int32(lookAhead)
break
recoveryWindow, err = askRecoveryWindow()
if err != nil {
return err
}
} else {
// Otherwise, if the user doesn't have a mnemonic that they
@ -663,3 +636,33 @@ func storeOrPrintAdminMac(ctx *cli.Context, adminMac []byte) error {
fmt.Printf("Admin macaroon: %s\n", hex.EncodeToString(adminMac))
return nil
}
func askRecoveryWindow() (int32, error) {
for {
fmt.Println()
fmt.Printf("Input an optional address look-ahead used to scan "+
"for used keys (default %d): ", defaultRecoveryWindow)
reader := bufio.NewReader(os.Stdin)
answer, err := reader.ReadString('\n')
if err != nil {
return 0, err
}
fmt.Println()
answer = strings.TrimSpace(answer)
if len(answer) == 0 {
return defaultRecoveryWindow, nil
}
lookAhead, err := strconv.Atoi(answer)
if err != nil {
fmt.Printf("Unable to parse recovery window: %v\n", err)
continue
}
return int32(lookAhead), nil
}
}