Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
ead59ae
Add NNS to UInt160 parameters for neo-cli
cschuchardt88 Dec 17, 2023
b913fa2
Fixed typo
cschuchardt88 Dec 17, 2023
f22224b
Update src/Neo.ConsoleService/ConsoleServiceBase.cs
shargon Dec 19, 2023
e8d9db4
Added NNS hashes to config files.
cschuchardt88 Dec 20, 2023
2d74750
Merge branch 'add-nns' of https://github.com/cschuchardt88/neo into a…
cschuchardt88 Dec 20, 2023
69f1f31
Updated support for neofs
cschuchardt88 Dec 20, 2023
0a5b273
Added ReadOnly Call Flag to the contract call
cschuchardt88 Dec 20, 2023
111ef31
Updated to allow all domains
cschuchardt88 Dec 20, 2023
6c4451f
Merge branch 'master' into add-nns
cschuchardt88 Dec 26, 2023
21f021b
Update src/Neo.CLI/Settings.cs
shargon Dec 27, 2023
5fd63d7
Merge branch 'master' into add-nns
cschuchardt88 Dec 27, 2023
7ce7a3b
null check
cschuchardt88 Dec 29, 2023
b49f449
Update config.testnet.json with contract hash
cschuchardt88 Jan 3, 2024
8f9c0d7
Merge branch 'master' into add-nns
shargon Jan 3, 2024
d95d352
Merge branch 'master' into add-nns
cschuchardt88 Jan 4, 2024
15e014e
Merge branch 'master' into add-nns
cschuchardt88 Jan 5, 2024
57cc30a
Merge branch 'master' into add-nns
cschuchardt88 Jan 9, 2024
6d556ce
Fixes
cschuchardt88 Jan 9, 2024
2e86ad0
Merge branch 'master' into add-nns
shargon Jan 9, 2024
0f3ecc9
Merge branch 'master' into add-nns
cschuchardt88 Jan 10, 2024
be86ed6
fixed wallet
cschuchardt88 Jan 11, 2024
70c40e5
Merge branch 'master' into add-nns
cschuchardt88 Jan 11, 2024
8228472
Merge branch 'master' into add-nns
shargon Jan 11, 2024
138c7b3
Update src/Neo.CLI/Settings.cs
shargon Jan 11, 2024
e6291aa
Update Settings.cs
cschuchardt88 Jan 11, 2024
0dc6229
Update Settings.cs
cschuchardt88 Jan 11, 2024
000ba5c
Refactor NNS definition
shargon Jan 11, 2024
3e6a0cb
clean new
shargon Jan 11, 2024
0430430
Show NNS Fault error
shargon Jan 11, 2024
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
9 changes: 5 additions & 4 deletions src/Neo.CLI/CLI/MainService.Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ private void OnSendCommand(UInt160 asset, UInt160 to, string amount, UInt160? fr
ConsoleHelper.Error("Incorrect password");
return;
}

var snapshot = NeoSystem.StoreView;
Transaction tx;
AssetDescriptor descriptor = new(snapshot, NeoSystem.Settings, asset);
Expand Down Expand Up @@ -550,10 +551,10 @@ private void OnSendCommand(UInt160 asset, UInt160 to, string amount, UInt160? fr
return;
}

ConsoleHelper.Info("Network fee: ",
$"{new BigDecimal((BigInteger)tx.NetworkFee, NativeContract.GAS.Decimals)}\t",
"Total fee: ",
$"{new BigDecimal((BigInteger)(tx.SystemFee + tx.NetworkFee), NativeContract.GAS.Decimals)} GAS");
ConsoleHelper.Info(
"Send To: ", $"{to.ToAddress(NeoSystem.Settings.AddressVersion)}\n",
"Network fee: ", $"{new BigDecimal((BigInteger)tx.NetworkFee, NativeContract.GAS.Decimals)}\t",
"Total fee: ", $"{new BigDecimal((BigInteger)(tx.SystemFee + tx.NetworkFee), NativeContract.GAS.Decimals)} GAS");
if (!ConsoleHelper.ReadUserInput("Relay tx? (no|yes)").IsYes())
{
return;
Expand Down
47 changes: 46 additions & 1 deletion src/Neo.CLI/CLI/MainService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,19 @@ public MainService() : base()
Initialize_Logger();
}

internal static UInt160 StringToAddress(string input, byte version)
internal UInt160 StringToAddress(string input, byte version)
{
switch (input.ToLowerInvariant())
{
case "neo": return NativeContract.NEO.Hash;
case "gas": return NativeContract.GAS.Hash;
}

if (input.IndexOf('.') > 0 && input.LastIndexOf('.') < input.Length)
{
return ResolveNeoNameServiceAddress(input);
}

// Try to parse as UInt160

if (UInt160.TryParse(input, out var addr))
Expand Down Expand Up @@ -636,5 +641,45 @@ static string GetExceptionMessage(Exception exception)

return exception.Message;
}

public UInt160 ResolveNeoNameServiceAddress(string domain)
{
if (Settings.Default.Contracts.NeoNameService == UInt160.Zero)
throw new Exception("Neo Name Service (NNS): is disabled on this network.");

using var sb = new ScriptBuilder();
sb.EmitDynamicCall(Settings.Default.Contracts.NeoNameService, "resolve", CallFlags.ReadOnly, domain, 16);

using var appEng = ApplicationEngine.Run(sb.ToArray(), NeoSystem.StoreView, settings: NeoSystem.Settings);
if (appEng.State == VMState.HALT)
{
var data = appEng.ResultStack.Pop();
if (data is ByteString)
{
try
{
var addressData = data.GetString();
if (UInt160.TryParse(addressData, out var address))
return address;
else
return addressData.ToScriptHash(NeoSystem.Settings.AddressVersion);
}
catch { }
}
else if (data is Null)
{
throw new Exception($"Neo Name Service (NNS): \"{domain}\" domain not found.");
}
throw new Exception("Neo Name Service (NNS): Record invalid address format.");
}
else
{
if (appEng.FaultException is not null)
{
throw new Exception($"Neo Name Service (NNS): \"{appEng.FaultException.Message}\".");
}
}
throw new Exception($"Neo Name Service (NNS): \"{domain}\" domain not found.");
}
}
}
21 changes: 21 additions & 0 deletions src/Neo.CLI/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

using Microsoft.Extensions.Configuration;
using Neo.Network.P2P;
using System;
using System.Threading;

namespace Neo
Expand All @@ -21,6 +22,7 @@ public class Settings
public StorageSettings Storage { get; }
public P2PSettings P2P { get; }
public UnlockWalletSettings UnlockWallet { get; }
public ContractsSettings Contracts { get; }

static Settings? s_default;

Expand Down Expand Up @@ -51,6 +53,7 @@ public static Settings Default

public Settings(IConfigurationSection section)
{
Contracts = new(section.GetSection(nameof(Contracts)));
Logger = new(section.GetSection(nameof(Logger)));
Storage = new(section.GetSection(nameof(Storage)));
P2P = new(section.GetSection(nameof(P2P)));
Expand Down Expand Up @@ -116,4 +119,22 @@ public UnlockWalletSettings(IConfigurationSection section)
}
}
}

public class ContractsSettings
{
public UInt160 NeoNameService { get; } = UInt160.Zero;

public ContractsSettings(IConfigurationSection section)
{
if (section.Exists())
{
if (UInt160.TryParse(section.GetValue(nameof(NeoNameService), string.Empty), out var hash))
{
NeoNameService = hash;
}
else
throw new ArgumentException("Neo Name Service (NNS): NeoNameService hash is invalid. Check your config.json.", nameof(NeoNameService));
}
}
}
}
3 changes: 3 additions & 0 deletions src/Neo.CLI/config.fs.mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"Path": "",
"Password": "",
"IsActive": false
},
"Contracts": {
"NeoNameService": "0x7061fbd31562664b58f422c3dee4acfd70dba8af"
}
},
"ProtocolConfiguration": {
Expand Down
3 changes: 3 additions & 0 deletions src/Neo.CLI/config.fs.testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"Path": "",
"Password": "",
"IsActive": false
},
"Contracts": {
"NeoNameService": "0xfb08ccf30ab534a871b7b092a49fe70c154ed678"
}
},
"ProtocolConfiguration": {
Expand Down
3 changes: 3 additions & 0 deletions src/Neo.CLI/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"Path": "",
"Password": "",
"IsActive": false
},
"Contracts": {
"NeoNameService": "0x50ac1c37690cc2cfc594472833cf57505d5f46de"
}
},
"ProtocolConfiguration": {
Expand Down
3 changes: 3 additions & 0 deletions src/Neo.CLI/config.mainnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"Path": "",
"Password": "",
"IsActive": false
},
"Contracts": {
"NeoNameService": "0x50ac1c37690cc2cfc594472833cf57505d5f46de"
}
},
"ProtocolConfiguration": {
Expand Down
3 changes: 3 additions & 0 deletions src/Neo.CLI/config.testnet.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"Path": "",
"Password": "",
"IsActive": false
},
"Contracts": {
"NeoNameService": "0x50ac1c37690cc2cfc594472833cf57505d5f46de"
}
},
"ProtocolConfiguration": {
Expand Down
3 changes: 2 additions & 1 deletion src/Neo.ConsoleService/ConsoleServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,11 @@ private bool OnCommand(string commandLine)

availableCommands.Add((command, arguments.ToArray()));
}
catch
catch (Exception ex)
{
// Skip parse errors
possibleHelp = command.Key;
ConsoleHelper.Error($"{ex.InnerException?.Message ?? ex.Message}");
}
}
}
Expand Down