Skip to content

Commit 35229d4

Browse files
authored
Merge branch 'dev' into nep-25
2 parents 7cd74e6 + 5dd874c commit 35229d4

File tree

20 files changed

+91
-36
lines changed

20 files changed

+91
-36
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ jobs:
156156
${{ github.workspace }}/TestResults/Neo.Plugins.RpcServer.Tests/coverage.info
157157
${{ github.workspace }}/TestResults/Neo.Plugins.Storage.Tests/coverage.info
158158
${{ github.workspace }}/TestResults/Neo.Plugins.ApplicationLogs.Tests/coverage.info
159+
${{ github.workspace }}/TestResults/Neo.Plugins.StateService.Tests/coverage.info
159160
${{ github.workspace }}/TestResults/Neo.Extensions.Tests/coverage.info
160161

161162
PublishPackage:

src/Neo.CLI/CLI/CommandLineOption.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class CommandLineOptions
2121
public string? DBPath { get; init; }
2222
public LogLevel Verbose { get; init; } = LogLevel.Info;
2323
public bool? NoVerify { get; init; }
24+
public bool Background { get; init; }
2425

2526
/// <summary>
2627
/// Check if CommandLineOptions was configured

src/Neo.CLI/CLI/MainService.CommandLine.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ public partial class MainService
2121
{
2222
public int OnStartWithCommandLine(string[] args)
2323
{
24-
RootCommand rootCommand = new(Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyTitleAttribute>()!.Title)
24+
var rootCommand = new RootCommand(Assembly.GetExecutingAssembly().GetCustomAttribute<AssemblyTitleAttribute>()!.Title)
2525
{
2626
new Option<string>(["-c", "--config","/config"], "Specifies the config file."),
2727
new Option<string>(["-w", "--wallet","/wallet"], "The path of the neo3 wallet [*.json]."),
2828
new Option<string>(["-p", "--password" ,"/password"], "Password to decrypt the wallet, either from the command line or config file."),
29+
new Option<bool>(["--background","/background"], "Run the service in background."),
2930
new Option<string>(["--db-engine","/db-engine"], "Specify the db engine."),
3031
new Option<string>(["--db-path","/db-path"], "Specify the db path."),
3132
new Option<string>(["--noverify","/noverify"], "Indicates whether the blocks need to be verified when importing."),
@@ -39,6 +40,7 @@ public int OnStartWithCommandLine(string[] args)
3940

4041
private void Handle(RootCommand command, CommandLineOptions options, InvocationContext context)
4142
{
43+
IsBackground = options.Background;
4244
Start(options);
4345
}
4446

@@ -72,7 +74,9 @@ private static void CustomProtocolSettings(CommandLineOptions options, ProtocolS
7274

7375
private static void CustomApplicationSettings(CommandLineOptions options, Settings settings)
7476
{
75-
var tempSetting = string.IsNullOrEmpty(options.Config) ? settings : new Settings(new ConfigurationBuilder().AddJsonFile(options.Config, optional: true).Build().GetSection("ApplicationConfiguration"));
77+
var tempSetting = string.IsNullOrEmpty(options.Config)
78+
? settings
79+
: new Settings(new ConfigurationBuilder().AddJsonFile(options.Config, optional: true).Build().GetSection("ApplicationConfiguration"));
7680
var customSetting = new Settings
7781
{
7882
Logger = tempSetting.Logger,

src/Neo.CLI/Settings.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
using Neo.Network.P2P;
1414
using Neo.Persistence.Providers;
1515
using System;
16+
using System.IO;
1617
using System.Reflection;
1718
using System.Threading;
1819

@@ -46,7 +47,8 @@ public static Settings Default
4647
{
4748
if (s_default == null)
4849
{
49-
var config = new ConfigurationBuilder().AddJsonFile("config.json", optional: true).Build();
50+
var configFile = ProtocolSettings.FindFile("config.json", Environment.CurrentDirectory);
51+
var config = new ConfigurationBuilder().AddJsonFile(configFile, optional: true).Build();
5052
Initialize(config);
5153
}
5254
return Custom ?? s_default!;

src/Neo.ConsoleService/ConsoleHelper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public static string ReadUserInput(string prompt, bool password = false)
103103
do
104104
{
105105
key = Console.ReadKey(true);
106-
if (PrintableASCIIChars.IndexOf(key.KeyChar) != -1)
106+
if (PrintableASCIIChars.Contains(key.KeyChar))
107107
{
108108
sb.Append(key.KeyChar);
109109
Console.Write(password ? '*' : key.KeyChar);
@@ -138,7 +138,7 @@ public static SecureString ReadSecureString(string prompt)
138138
do
139139
{
140140
key = Console.ReadKey(true);
141-
if (PrintableASCIIChars.IndexOf(key.KeyChar) != -1)
141+
if (PrintableASCIIChars.Contains(key.KeyChar))
142142
{
143143
securePwd.AppendChar(key.KeyChar);
144144
Console.Write('*');

src/Neo.ConsoleService/ConsoleServiceBase.cs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public abstract class ConsoleServiceBase
3535

3636
protected bool ShowPrompt { get; set; } = true;
3737

38+
protected bool IsBackground { get; set; } = false;
39+
3840
private bool _running;
3941
private readonly CancellationTokenSource _shutdownTokenSource = new();
4042
private readonly CountdownEvent _shutdownAcknowledged = new(1);
@@ -522,7 +524,7 @@ private void OnScCommand(string action)
522524
}
523525

524526
string arguments;
525-
if (action == "/install")
527+
if (action == "install")
526528
{
527529
var fileName = Process.GetCurrentProcess().MainModule!.FileName;
528530
arguments = $"create {ServiceName} start= auto binPath= \"{fileName}\"";
@@ -551,17 +553,39 @@ private void OnScCommand(string action)
551553
}
552554
}
553555

556+
private void WaitForShutdown()
557+
{
558+
_running = true;
559+
try
560+
{
561+
_shutdownTokenSource.Token.WaitHandle.WaitOne();
562+
}
563+
catch (OperationCanceledException)
564+
{
565+
// Expected when shutdown is triggered
566+
}
567+
_running = false;
568+
}
569+
554570
public void Run(string[] args)
555571
{
556572
if (Environment.UserInteractive)
557573
{
558-
if (args.Length == 1 && (args[0] == "/install" || args[0] == "/uninstall"))
574+
if (args.Length == 1 && (args[0] == "--install" || args[0] == "/install"))
559575
{
560-
OnScCommand(args[0]);
576+
OnScCommand("install");
577+
}
578+
else if (args.Length == 1 && (args[0] == "--uninstall" || args[0] == "/uninstall"))
579+
{
580+
OnScCommand("uninstall");
561581
}
562582
else
563583
{
564-
if (OnStart(args)) RunConsole();
584+
if (OnStart(args))
585+
{
586+
if (IsBackground) WaitForShutdown();
587+
else RunConsole();
588+
}
565589
OnStop();
566590
}
567591
}

src/Neo/Ledger/MemoryPool.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ private void RemoveConflictsOfVerified(PoolItem item)
447447
if (_conflicts.TryGetValue(h, out var conflicts))
448448
{
449449
conflicts.Remove(item.Tx.Hash);
450-
if (conflicts.Count() == 0)
450+
if (conflicts.Count == 0)
451451
{
452452
_conflicts.Remove(h);
453453
}

src/Plugins/OracleService/OracleSettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private OracleSettings(IConfigurationSection section)
6363
AllowPrivateHost = section.GetValue("AllowPrivateHost", false);
6464
AllowedContentTypes = section.GetSection("AllowedContentTypes").GetChildren().Select(p => p.Get<string>()).ToArray();
6565
ExceptionPolicy = section.GetValue("UnhandledExceptionPolicy", UnhandledExceptionPolicy.Ignore);
66-
if (AllowedContentTypes.Count() == 0)
66+
if (AllowedContentTypes.Length == 0)
6767
AllowedContentTypes = AllowedContentTypes.Concat("application/json").ToArray();
6868
Https = new HttpsSettings(section.GetSection("Https"));
6969
NeoFS = new NeoFSSettings(section.GetSection("NeoFS"));

src/Plugins/RestServer/RestWebServer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ public void Start()
166166
options.OnRejected = async (context, token) =>
167167
{
168168
context.HttpContext.Response.StatusCode = StatusCodes.Status429TooManyRequests;
169-
context.HttpContext.Response.Headers["Retry-After"] = _settings.RateLimitWindowSeconds.ToString();
169+
context.HttpContext.Response.Headers.RetryAfter = _settings.RateLimitWindowSeconds.ToString();
170170
context.HttpContext.Response.ContentType = "text/plain";
171171

172172
if (context.Lease.TryGetMetadata(MetadataName.RetryAfter, out var retryAfter))

src/Plugins/RpcServer/RpcServer.Wallet.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,8 +710,8 @@ private JObject GetVerificationResult(UInt160 scriptHash, ContractParameter[] ar
710710
var contract = NativeContract.ContractManagement.GetContract(snapshot, scriptHash)
711711
.NotNull_Or(RpcError.UnknownContract);
712712

713-
var md = contract.Manifest.Abi.GetMethod(ContractBasicMethod.Verify, args.Count())
714-
.NotNull_Or(RpcErrorFactory.InvalidContractVerification(contract.Hash, args.Count()));
713+
var md = contract.Manifest.Abi.GetMethod(ContractBasicMethod.Verify, args.Length)
714+
.NotNull_Or(RpcErrorFactory.InvalidContractVerification(contract.Hash, args.Length));
715715

716716
(md.ReturnType == ContractParameterType.Boolean)
717717
.True_Or(RpcErrorFactory.InvalidContractVerification("The verify method doesn't return boolean value."));

0 commit comments

Comments
 (0)