feat(cli): add restore-address command for pure address watch-only
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.
This commit is contained in:
@@ -18,6 +18,7 @@ try
|
|||||||
["create", .. var rest] => Create(rest),
|
["create", .. var rest] => Create(rest),
|
||||||
["restore", var words, .. var rest] => Restore(words, rest),
|
["restore", var words, .. var rest] => Restore(words, rest),
|
||||||
["restore-xpub", var xpub, .. var rest] => RestoreXpub(xpub, rest),
|
["restore-xpub", var xpub, .. var rest] => RestoreXpub(xpub, rest),
|
||||||
|
["restore-address", var addrs, .. var rest] => RestoreAddress(addrs, rest),
|
||||||
["info", .. var rest] => Info(rest),
|
["info", .. var rest] => Info(rest),
|
||||||
["sync", .. var rest] => await Sync(rest),
|
["sync", .. var rest] => await Sync(rest),
|
||||||
["send", .. var rest] => await Send(rest),
|
["send", .. var rest] => await Send(rest),
|
||||||
@@ -95,6 +96,31 @@ static int RestoreXpub(string xpubText, string[] o)
|
|||||||
return 0;
|
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)
|
static int Info(string[] o)
|
||||||
{
|
{
|
||||||
var (doc, account, path) = OpenWallet(o);
|
var (doc, account, path) = OpenWallet(o);
|
||||||
@@ -352,6 +378,7 @@ static int Usage()
|
|||||||
[--passphrase W] [--password P] [--file PATH]
|
[--passphrase W] [--password P] [--file PATH]
|
||||||
restore "<mnemonic>" [same options as create] [--path m/...]
|
restore "<mnemonic>" [same options as create] [--path m/...]
|
||||||
restore-xpub <slip132 xpub> [--net ...] [--password P] [--file PATH] (watch-only)
|
restore-xpub <slip132 xpub> [--net ...] [--password P] [--file PATH] (watch-only)
|
||||||
|
restore-address <addr1,addr2,...> [--net ...] [--password P] [--file PATH] (watch-only, no keys)
|
||||||
info [--net ...] [--password P] [--file PATH]
|
info [--net ...] [--password P] [--file PATH]
|
||||||
|
|
||||||
Network (indexing server; without --server the first known server is used):
|
Network (indexing server; without --server the first known server is used):
|
||||||
|
|||||||
Reference in New Issue
Block a user