Skip to content
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
2 changes: 2 additions & 0 deletions All.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<Project Path="src/Neo.Core/Neo.Core.csproj" />
<Project Path="src/Neo.IO/Neo.IO.csproj" Id="476db0c1-403f-4d31-92f8-dc55985e81a4" />
<Project Path="src/Neo.Localization/Neo.Localization.csproj" Id="cf344ed8-cbf9-4f00-a5d4-d0c7bac43145" />
<Project Path="src/Neo.Platform.CLI/Neo.Platform.CLI.csproj" Id="febe8581-30b0-4de6-8a3e-92dbad252849" />
<Project Path="src/Neo.Platform.Hosting/Neo.Platform.Hosting.csproj" Id="de3bb911-e4a4-40e5-ab44-667ac6f8fe5e" />
<Project Path="src/Neo.VM/Neo.VM.csproj" Id="e38e01be-d9e4-4c1d-a0bc-b9a37250d446" />
<Project Path="src/Neo.Wallet/Neo.Wallet.csproj" Id="49b273b6-b9a6-402e-8ea6-db4e23a3fe40" />
</Folder>
Expand Down
82 changes: 82 additions & 0 deletions src/Neo.Configuration/Json/Converters/JsonIPEndPointConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// BSD 2-Clause License
//
// Copyright (c) 2026, Rapid Loop
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES

using System;
using System.Net;
using System.Net.Sockets;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace Neo.Configuration.Json.Converters
{
public class JsonIPEndPointConverter : JsonConverter<IPEndPoint?>
{
public override IPEndPoint? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (reader.TokenType != JsonTokenType.String)
throw new FormatException();

var valueString = reader.GetString();

if (string.IsNullOrEmpty(valueString))
return default;

if (IPEndPoint.TryParse(valueString, out var value))
return value;
else
{
// Try to see if its a hostname
var spString = valueString.Split(':', StringSplitOptions.TrimEntries);
if (spString.Length == 2)
{
try
{
var host = Dns.GetHostEntry(spString[0]);
if (host.AddressList.Length > 0)
{
var length = host.AddressList.Length - 1;
var ipAddress = host.AddressList
[
length > 0 ? Random.Shared.Next(length) : 0
];

return new IPEndPoint(ipAddress, int.Parse(spString[1]));
}
}
catch (SocketException) // Host doesn't exist or network is down
{
}
}
}

return default;
}

public override void Write(Utf8JsonWriter writer, IPEndPoint? value, JsonSerializerOptions options)
{
if (value is null)
writer.WriteNullValue();
else
writer.WriteStringValue($"{value}");
}
}
}
1 change: 1 addition & 0 deletions src/Neo.Configuration/Json/JsonDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public static class JsonDefaults
new JsonStringEnumConverter(),
new JsonStringECPointConverter(),
new JsonStringUInt160Converter(),
new JsonIPEndPointConverter(),
},
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,19 @@
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES

using Neo.Configuration.Json;
using Neo.Core;
using Neo.Core.Cryptography.ECC;
using Neo.Core.Interfaces;
using Neo.Core.VM;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Net;

namespace Neo.Configuration.Json
namespace Neo.Configuration
{
public class ProtocolSettingsModel : JsonModel, IMap<ProtocolSettings>
public class ProtocolSettingsOptions : JsonModel, IMap<ProtocolSettings>
{
public uint Network { get; set; }

Expand All @@ -48,7 +50,7 @@ public class ProtocolSettingsModel : JsonModel, IMap<ProtocolSettings>

public int ValidatorsCount { get; set; }

public string[]? SeedList { get; set; }
public IPEndPoint[]? SeedList { get; set; }

public IDictionary<HardFork, uint>? HardForks { get; set; }

Expand Down
3 changes: 3 additions & 0 deletions src/Neo.Core/Cryptography/ECC/ECPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@

using Neo.Core.Extensions;
using Neo.Core.Serialization;
using Neo.Core.Types.Converter;
using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Numerics;
using System.Security.Cryptography;

namespace Neo.Core.Cryptography.ECC
{
[TypeConverter(typeof(ECPointTypeConverter))]
public class ECPoint : IEquatable<ECPoint>, IComparable, IComparable<ECPoint>, INeoSerializable
{
public const int UncompressedLength = 65;
Expand Down
3 changes: 2 additions & 1 deletion src/Neo.Core/ProtocolSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
using System.Net;

namespace Neo.Core
{
Expand Down Expand Up @@ -59,7 +60,7 @@ public class ProtocolSettings
/// <summary>
/// The default seed nodes list.
/// </summary>
public IReadOnlyList<string> SeedList { get; init; } = [];
public IPEndPoint[] SeedList { get; init; } = [];

/// <summary>
/// Indicates the time in milliseconds between two blocks. Note that starting from
Expand Down
54 changes: 54 additions & 0 deletions src/Neo.Core/Types/Converter/ECPointTypeConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// BSD 2-Clause License
//
// Copyright (c) 2026, Rapid Loop
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES

using Neo.Core.Cryptography.ECC;
using System;
using System.ComponentModel;
using System.Globalization;

namespace Neo.Core.Types.Converter
{
internal class ECPointTypeConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType) =>
sourceType == typeof(string) && base.CanConvertFrom(context, sourceType);

public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
{
if (value is string pointString)
{
if (ECPoint.TryParse(pointString, ECCurve.SecP256r1, out var point))
return point;
}

return base.ConvertFrom(context, culture, value);
}

public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType) =>
CanConvertTo(context, destinationType) ?
value switch
{
ECPoint e => e.Encode(shouldCompress: true),
_ => base.ConvertTo(context, culture, value, destinationType),
} : base.ConvertTo(context, culture, value, destinationType);
}
}
46 changes: 46 additions & 0 deletions src/Neo.Core/Types/Converter/IPAddressTypeConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// BSD 2-Clause License
//
// Copyright (c) 2026, Rapid Loop
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES

using System;
using System.ComponentModel;
using System.Globalization;
using System.Net;

namespace Neo.Core.Types.Converter
{
public class IPAddressTypeConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType) =>
sourceType == typeof(string) && base.CanConvertFrom(context, sourceType);

public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
{
if (value is string ipString)
{
if (IPAddress.TryParse(ipString, out var ipAddress))
return ipAddress;
}

return base.ConvertFrom(context, culture, value);
}
}
}
72 changes: 72 additions & 0 deletions src/Neo.Core/Types/Converter/IPEndPointTypeConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// BSD 2-Clause License
//
// Copyright (c) 2026, Rapid Loop
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES

using System;
using System.ComponentModel;
using System.Globalization;
using System.Net;
using System.Net.Sockets;

namespace Neo.Core.Types.Converter
{
public class IPEndPointTypeConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType) =>
sourceType == typeof(string) && base.CanConvertFrom(context, sourceType);

public override object? ConvertFrom(ITypeDescriptorContext? context, CultureInfo? culture, object value)
{
if (value is string endPointString)
{
if (IPEndPoint.TryParse(endPointString, out var ipEndPoint))
return ipEndPoint;
else
{
// Try to see if its a hostname
var spString = endPointString.Split(':', StringSplitOptions.TrimEntries);
if (spString.Length == 2)
{
try
{
var host = Dns.GetHostEntry(spString[0]);
if (host.AddressList.Length > 0)
{
var length = host.AddressList.Length - 1;
var ipAddress = host.AddressList
[
length > 0 ? Random.Shared.Next(length) : 0
];

return new IPEndPoint(ipAddress, int.Parse(spString[1]));
}
}
catch (SocketException) // Host doesn't exist or network is down
{
}
}
}
}

return base.ConvertFrom(context, culture, value);
}
}
}
37 changes: 37 additions & 0 deletions src/Neo.Platform.CLI/Commands/EmptyHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// BSD 2-Clause License
//
// Copyright (c) 2026, Rapid Loop
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice, this
// list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES

using System.CommandLine;
using System.CommandLine.Invocation;
using System.Threading;
using System.Threading.Tasks;

namespace Neo.Platform.CLI.Commands
{
public class EmptyHandler : AsynchronousCommandLineAction
{
public override Task<int> InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken = default)
{
return Task.FromResult(0);
}
}
}
Loading
Loading