From 9fa5440ae5cf845dc0bd3a396d4ecbf467abf0f2 Mon Sep 17 00:00:00 2001 From: Davide Grilli Date: Sun, 19 Jul 2026 12:37:47 +0200 Subject: [PATCH] feat(cli): add restore-address command for pure address watch-only MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Parallels restore-xpub but for one or more plain addresses with no extended key and no private key — output is explicitly labelled "cannot sign" since the resulting wallet can never produce a signed tx. --- src/Cli/Program.cs | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/Cli/Program.cs b/src/Cli/Program.cs index bb29161..4ffe89c 100644 --- a/src/Cli/Program.cs +++ b/src/Cli/Program.cs @@ -18,6 +18,7 @@ try ["create", .. var rest] => Create(rest), ["restore", var words, .. var rest] => Restore(words, rest), ["restore-xpub", var xpub, .. var rest] => RestoreXpub(xpub, rest), + ["restore-address", var addrs, .. var rest] => RestoreAddress(addrs, rest), ["info", .. var rest] => Info(rest), ["sync", .. var rest] => await Sync(rest), ["send", .. var rest] => await Send(rest), @@ -95,6 +96,31 @@ static int RestoreXpub(string xpubText, string[] o) return 0; } +static int RestoreAddress(string addrsText, string[] o) +{ + var profile = Profile(o); + var addresses = addrsText.Split(',', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); + if (addresses.Length == 0) + { + Console.Error.WriteLine("At least one address is required."); + return 1; + } + WalletDocument doc; + try + { + (doc, _) = WalletLoader.NewFromAddresses(addresses, profile); + } + catch (InvalidDataException ex) + { + Console.Error.WriteLine(ex.Message); + return 1; + } + var path = WalletPath(o, profile); + WalletStore.Save(doc, path, Opt(o, "--password")); + Console.WriteLine($"Watch-only wallet saved to {path} ({addresses.Length} address(es), cannot sign)"); + return 0; +} + static int Info(string[] o) { var (doc, account, path) = OpenWallet(o); @@ -352,6 +378,7 @@ static int Usage() [--passphrase W] [--password P] [--file PATH] restore "" [same options as create] [--path m/...] restore-xpub [--net ...] [--password P] [--file PATH] (watch-only) + restore-address [--net ...] [--password P] [--file PATH] (watch-only, no keys) info [--net ...] [--password P] [--file PATH] Network (indexing server; without --server the first known server is used):