Skip to content

Commit

Permalink
EpicChain Core - EpicChain Lab's
Browse files Browse the repository at this point in the history
  • Loading branch information
xmoohad committed Sep 24, 2024
1 parent c6d53be commit 1080a01
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/EpicChain/SmartContract/Native/Role.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public enum Role : byte
/// <summary>
/// EpicChain Alphabet nodes.
/// </summary>
NeoFSAlphabetNode = 16,
EpicChainNovaAlphabetNode = 16,

/// <summary>
/// P2P Notary nodes used to process P2P notary requests.
Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/OracleService/OracleService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public void Start(Wallet wallet)

this.wallet = wallet;
protocols["https"] = new OracleHttpsProtocol();
protocols["neofs"] = new OracleNeoFSProtocol(wallet, oracles);
protocols["EpicChainNova"] = new OracleEpicChainNovaProtocol(wallet, oracles);
status = OracleStatus.Running;
timer = new Timer(OnTimer, null, RefreshIntervalMilliSeconds, Timeout.Infinite);
ConsoleHelper.Info($"Oracle started");
Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/OracleService/OracleService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="NeoFS.API" Version="3.5.0" />
<PackageReference Include="EpicChainNova.API" Version="3.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Plugins/OracleService/OracleService.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"Https": {
"Timeout": 5000
},
"NeoFS": {
"EpicChainNova": {
"EndPoint": "http://127.0.0.1:8080",
"Timeout": 15000
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (C) 2021-2024 EpicChain Labs.

//
// OracleNeoFSProtocol.cs is a component of the EpicChain Labs project, founded by xmoohad. This file is
// OracleEpicChainNovaProtocol.cs is a component of the EpicChain Labs project, founded by xmoohad. This file is
// distributed as free software under the MIT License, allowing for wide usage and modification
// with minimal restrictions. For comprehensive details regarding the license, please refer to
// the LICENSE file located in the root directory of the repository or visit
Expand Down Expand Up @@ -36,11 +36,11 @@

namespace EpicChain.Plugins.OracleService
{
class OracleNeoFSProtocol : IOracleProtocol
class OracleEpicChainNovaProtocol : IOracleProtocol
{
private readonly System.Security.Cryptography.ECDsa privateKey;

public OracleNeoFSProtocol(Wallet wallet, ECPoint[] oracles)
public OracleEpicChainNovaProtocol(Wallet wallet, ECPoint[] oracles)
{
byte[] key = oracles.Select(p => wallet.GetAccount(p)).Where(p => p is not null && p.HasKey && !p.Lock).FirstOrDefault().GetKey().PrivateKey;
privateKey = key.LoadPrivateKey();
Expand All @@ -57,33 +57,33 @@ public void Dispose()

public async Task<(OracleResponseCode, string)> ProcessAsync(Uri uri, CancellationToken cancellation)
{
Utility.Log(nameof(OracleNeoFSProtocol), LogLevel.Debug, $"Request: {uri.AbsoluteUri}");
Utility.Log(nameof(OracleEpicChainNovaProtocol), LogLevel.Debug, $"Request: {uri.AbsoluteUri}");
try
{
(OracleResponseCode code, string data) = await GetAsync(uri, Settings.Default.NeoFS.EndPoint, cancellation);
Utility.Log(nameof(OracleNeoFSProtocol), LogLevel.Debug, $"NeoFS result, code: {code}, data: {data}");
(OracleResponseCode code, string data) = await GetAsync(uri, Settings.Default.EpicChainNova.EndPoint, cancellation);
Utility.Log(nameof(OracleEpicChainNovaProtocol), LogLevel.Debug, $"EpicChainNova result, code: {code}, data: {data}");
return (code, data);
}
catch (Exception e)
{
Utility.Log(nameof(OracleNeoFSProtocol), LogLevel.Debug, $"NeoFS result: error,{e.Message}");
Utility.Log(nameof(OracleEpicChainNovaProtocol), LogLevel.Debug, $"EpicChainNova result: error,{e.Message}");
return (OracleResponseCode.Error, null);
}
}


/// <summary>
/// GetAsync returns neofs object from the provided url.
/// GetAsync returns epicchainnova object from the provided url.
/// If Command is not provided, full object is requested.
/// </summary>
/// <param name="uri">URI scheme is "neofs:ContainerID/ObjectID/Command/offset|length".</param>
/// <param name="uri">URI scheme is "epicchainnova:ContainerID/ObjectID/Command/offset|length".</param>
/// <param name="host">Client host.</param>
/// <param name="cancellation">Cancellation token object.</param>
/// <returns>Returns neofs object.</returns>
/// <returns>Returns epicchainnova object.</returns>
private async Task<(OracleResponseCode, string)> GetAsync(Uri uri, string host, CancellationToken cancellation)
{
string[] ps = uri.AbsolutePath.Split("/");
if (ps.Length < 2) throw new FormatException("Invalid neofs url");
if (ps.Length < 2) throw new FormatException("Invalid epicchainnova url");
ContainerID containerID = ContainerID.FromString(ps[0]);
ObjectID objectID = ObjectID.FromString(ps[1]);
Address objectAddr = new()
Expand All @@ -93,7 +93,7 @@ public void Dispose()
};
using Client client = new(privateKey, host);
var tokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellation);
tokenSource.CancelAfter(Settings.Default.NeoFS.Timeout);
tokenSource.CancelAfter(Settings.Default.EpicChainNova.Timeout);
if (ps.Length == 2)
return GetPayload(client, objectAddr, tokenSource.Token);
return ps[2] switch
Expand Down
8 changes: 4 additions & 4 deletions src/Plugins/OracleService/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ public HttpsSettings(IConfigurationSection section)
}
}

class NeoFSSettings
class EpicChainNovaSettings
{
public string EndPoint { get; }
public TimeSpan Timeout { get; }

public NeoFSSettings(IConfigurationSection section)
public EpicChainNovaSettings(IConfigurationSection section)
{
EndPoint = section.GetValue("EndPoint", "127.0.0.1:8080");
Timeout = TimeSpan.FromMilliseconds(section.GetValue("Timeout", 15000));
Expand All @@ -56,7 +56,7 @@ class Settings : PluginSettings
public bool AllowPrivateHost { get; }
public string[] AllowedContentTypes { get; }
public HttpsSettings Https { get; }
public NeoFSSettings NeoFS { get; }
public EpicChainNovaSettings EpicChainNova { get; }
public bool AutoStart { get; }

public static Settings Default { get; private set; }
Expand All @@ -70,7 +70,7 @@ private Settings(IConfigurationSection section) : base(section)
AllowPrivateHost = section.GetValue("AllowPrivateHost", false);
AllowedContentTypes = section.GetSection("AllowedContentTypes").GetChildren().Select(p => p.Get<string>()).ToArray();
Https = new HttpsSettings(section.GetSection("Https"));
NeoFS = new NeoFSSettings(section.GetSection("NeoFS"));
EpicChainNova = new EpicChainNovaSettings(section.GetSection("EpicChainNova"));
AutoStart = section.GetValue("AutoStart", false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void TestSetAndGet()
publicKeys[1] = key2.PublicKey;
publicKeys = publicKeys.OrderBy(p => p).ToArray();

List<Role> roles = new List<Role>() { Role.StateValidator, Role.Oracle, Role.NeoFSAlphabetNode, Role.P2PNotary };
List<Role> roles = new List<Role>() { Role.StateValidator, Role.Oracle, Role.EpicChainNovaAlphabetNode, Role.P2PNotary };
foreach (var role in roles)
{
var snapshot1 = _snapshotCache.CloneCache();
Expand Down

0 comments on commit 1080a01

Please sign in to comment.