Skip to content
This repository has been archived by the owner on Dec 7, 2023. It is now read-only.

Use wallet factory #861

Merged
merged 4 commits into from
May 19, 2022
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
4 changes: 2 additions & 2 deletions neo-cli/CLI/MainService.Node.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2016-2021 The Neo Project.
// Copyright (C) 2016-2022 The Neo Project.
//
// The neo-cli is free software distributed under the MIT software
// license, see the accompanying file LICENSE in the main directory of
Expand Down Expand Up @@ -87,7 +87,7 @@ private void OnShowStateCommand()
foreach (RemoteNode node in LocalNode.GetRemoteNodes().OrderByDescending(u => u.LastBlockIndex).Take(Console.WindowHeight - 2).ToArray())
{
ConsoleHelper.Info(" ip: ",
$"{ node.Remote.Address,-15}\t",
$"{node.Remote.Address,-15}\t",
"port: ",
$"{node.Remote.Port,-5}\t",
"listen: ",
Expand Down
56 changes: 13 additions & 43 deletions neo-cli/CLI/MainService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (C) 2016-2021 The Neo Project.
// Copyright (C) 2016-2022 The Neo Project.
//
// The neo-cli is free software distributed under the MIT software
// license, see the accompanying file LICENSE in the main directory of
Expand All @@ -23,8 +23,6 @@
using Neo.VM;
using Neo.VM.Types;
using Neo.Wallets;
using Neo.Wallets.NEP6;
using Neo.Wallets.SQLite;
using System;
using System.Collections.Generic;
using System.Globalization;
Expand Down Expand Up @@ -127,28 +125,21 @@ public override void RunConsole()

public void CreateWallet(string path, string password, bool createDefaultAccount = true)
{
switch (Path.GetExtension(path))
{
case ".db3":
CurrentWallet = UserWallet.Create(path, password, NeoSystem.Settings);
break;
case ".json":
CurrentWallet = new NEP6Wallet(path, NeoSystem.Settings);
((NEP6Wallet)CurrentWallet).Unlock(password);
break;
default:
ConsoleHelper.Warning("Wallet files in that format are not supported, please use a .json or .db3 file extension.");
return;
Wallet wallet = Wallet.Create(null, 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.");
return;
}
if (createDefaultAccount)
{
WalletAccount account = CurrentWallet.CreateAccount();
WalletAccount account = wallet.CreateAccount();
ConsoleHelper.Info(" Address: ", account.Address);
ConsoleHelper.Info(" Pubkey: ", account.GetKey().PublicKey.EncodePoint(true).ToHexString());
ConsoleHelper.Info("ScriptHash: ", $"{account.ScriptHash}");
}
if (CurrentWallet is NEP6Wallet wallet)
wallet.Save();
wallet.Save();
CurrentWallet = wallet;
}

private IEnumerable<Block> GetBlocks(Stream stream, bool read_start = false)
Expand Down Expand Up @@ -246,10 +237,7 @@ private byte[] LoadDeploymentScript(string nefFilePath, string manifestFilePath,
throw new ArgumentException(nameof(nefFilePath));
}

using (var stream = new BinaryReader(File.OpenRead(nefFilePath), Utility.StrictUTF8, false))
{
nef = stream.ReadSerializable<NefFile>();
}
nef = File.ReadAllBytes(nefFilePath).AsSerializable<NefFile>();

ContractParameter dataParameter = null;
if (data is not null)
Expand Down Expand Up @@ -315,10 +303,7 @@ private byte[] LoadUpdateScript(UInt160 scriptHash, string nefFilePath, string m
throw new ArgumentException(nameof(nefFilePath));
}

using (var stream = new BinaryReader(File.OpenRead(nefFilePath), Utility.StrictUTF8, false))
{
nef = stream.ReadSerializable<NefFile>();
}
nef = File.ReadAllBytes(nefFilePath).AsSerializable<NefFile>();

ContractParameter dataParameter = null;
if (data is not null)
Expand Down Expand Up @@ -377,22 +362,7 @@ public void OpenWallet(string path, string password)
throw new FileNotFoundException();
}

switch (Path.GetExtension(path).ToLowerInvariant())
{
case ".db3":
{
CurrentWallet = UserWallet.Open(path, password, NeoSystem.Settings);
break;
}
case ".json":
{
NEP6Wallet nep6wallet = new NEP6Wallet(path, NeoSystem.Settings);
nep6wallet.Unlock(password);
CurrentWallet = nep6wallet;
break;
}
default: throw new NotSupportedException();
}
CurrentWallet = Wallet.Open(path, password, NeoSystem.Settings) ?? throw new NotSupportedException();
}

public async void Start(string[] args)
Expand Down Expand Up @@ -554,7 +524,7 @@ private void SendTransaction(byte[] script, UInt160 account = null, long gas = T
try
{
Transaction tx = CurrentWallet.MakeTransaction(snapshot, script, account, signers, maxGas: gas);
ConsoleHelper.Info("Invoking script with: ", $"'{tx.Script.ToBase64String()}'");
ConsoleHelper.Info("Invoking script with: ", $"'{Convert.ToBase64String(tx.Script)}'");

using (ApplicationEngine engine = ApplicationEngine.Run(tx.Script, snapshot, container: tx, settings: NeoSystem.Settings, gas: gas))
{
Expand Down
2 changes: 1 addition & 1 deletion neo-cli/neo-cli.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Neo" Version="3.2.1" />
<PackageReference Include="Neo" Version="3.2.1-CI01355" />
</ItemGroup>

<ItemGroup>
Expand Down