Skip to content

[Add]: set name when create wallet #3866

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/Neo.CLI/CLI/MainService.Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,28 +212,39 @@ private void OnExportKeyCommand(string? path = null, UInt160? scriptHash = null)
/// <summary>
/// Process "create wallet" command
/// </summary>
/// <param name="path">The path of the wallet file.</param>
/// <param name="wifOrFile">
/// The WIF or file of the wallet.
/// If <see langword="null"/> or empty, a new wallet will be created.
/// If it is a WIF, it will be added to the wallet.
/// If it is a file, it will be read each line as a WIF and added to the wallet.
/// </param>
/// <param name="walletName">The name of the wallet.</param>
[ConsoleCommand("create wallet", Category = "Wallet Commands")]
private void OnCreateWalletCommand(string path, string? wifOrFile = null)
private void OnCreateWalletCommand(string path, string? wifOrFile = null, string? walletName = null)
{
string password = ConsoleHelper.ReadUserInput("password", true);
if (password.Length == 0)
{
ConsoleHelper.Info("Cancelled");
return;
}

string password2 = ConsoleHelper.ReadUserInput("repeat password", true);
if (password != password2)
{
ConsoleHelper.Error("Two passwords not match.");
return;
}

if (File.Exists(path))
{
Console.WriteLine("This wallet already exists, please create another one.");
return;
}
bool createDefaultAccount = wifOrFile is null;
CreateWallet(path, password, createDefaultAccount);

bool createDefaultAccount = string.IsNullOrEmpty(wifOrFile);
CreateWallet(path, password, createDefaultAccount, walletName);
if (!createDefaultAccount) OnImportKeyCommand(wifOrFile!);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Neo.CLI/CLI/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ public override void RunConsole()
base.RunConsole();
}

public void CreateWallet(string path, string password, bool createDefaultAccount = true)
public void CreateWallet(string path, string password, bool createDefaultAccount = true, string? walletName = null)
{
Wallet wallet = Wallet.Create(null, path, password, NeoSystem.Settings);
Wallet wallet = Wallet.Create(walletName, path, password, NeoSystem.Settings);
if (wallet == null)
{
ConsoleHelper.Warning("Wallet files in that format are not supported, please use a .json or .db3 file extension.");
Expand Down
2 changes: 2 additions & 0 deletions src/Neo.ConsoleService/ConsoleServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,11 +515,13 @@ public virtual void RunConsole()
{
_running = true;
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
try
{
Console.Title = ServiceName;
}
catch { }
}

Console.ForegroundColor = ConsoleColor.DarkGreen;
Console.SetIn(new StreamReader(Console.OpenStandardInput(), Console.InputEncoding, false, ushort.MaxValue));
Expand Down
20 changes: 20 additions & 0 deletions src/Neo/Wallets/IWalletFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,30 @@ namespace Neo.Wallets
{
public interface IWalletFactory
{
/// <summary>
/// Determines whether the factory can handle the specified path.
/// </summary>
/// <param name="path">The path of the wallet file.</param>
/// <returns>
/// <see langword="true"/> if the factory can handle the specified path; otherwise, <see langword="false"/>.
/// </returns>
public bool Handle(string path);

/// <summary>
/// Creates a new wallet.
/// </summary>
/// <param name="name">The name of the wallet.</param>
/// <param name="path">The path of the wallet file.</param>
/// <param name="password">The password of the wallet.</param>
/// <param name="settings">The settings of the wallet.</param>
public Wallet CreateWallet(string name, string path, string password, ProtocolSettings settings);

/// <summary>
/// Opens a wallet.
/// </summary>
/// <param name="path">The path of the wallet file.</param>
/// <param name="password">The password of the wallet.</param>
/// <param name="settings">The settings of the wallet.</param>
public Wallet OpenWallet(string path, string password, ProtocolSettings settings);
}
}