Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Moving rpc to plugin #1290

Closed
wants to merge 1 commit into from
Closed
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
73 changes: 0 additions & 73 deletions .github/workflows/dotnetcore.yml

This file was deleted.

9 changes: 9 additions & 0 deletions src/neo/IO/Json/JArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,5 +151,14 @@ public override string ToString()
}
return sb.ToString();
}

public override object ToPrimitive()
{
ArrayList list = new ArrayList();

items.ForEach(o => list.Add(o.ToPrimitive()));

return list.ToArray();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these methods are only used in plugins, it is recommended to put them in plugin extension methods.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't do this using extension methods because I need to overload the method.

}
}
5 changes: 5 additions & 0 deletions src/neo/IO/Json/JBoolean.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,10 @@ public override string ToString()
{
return AsString();
}

public override object ToPrimitive()
{
return AsBoolean();
}
}
}
5 changes: 5 additions & 0 deletions src/neo/IO/Json/JNumber.cs
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,10 @@ public override T TryGetEnum<T>(T defaultValue = default, bool ignoreCase = fals
object result = Enum.ToObject(enumType, value);
return Enum.IsDefined(enumType, result) ? (T)result : defaultValue;
}

public override object ToPrimitive()
{
return AsNumber();
}
}
}
70 changes: 69 additions & 1 deletion src/neo/IO/Json/JObject.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Neo.IO.Caching;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Akka.Util.Internal;
using Neo.IO.Caching;

namespace Neo.IO.Json
{
Expand Down Expand Up @@ -193,5 +194,72 @@ public static implicit operator JObject(string value)
{
return value == null ? null : new JString(value);
}

public virtual object ToPrimitive()
{
Dictionary<string, object> dict = new Dictionary<string, object>();

Properties.ForEach(pair => dict.Add(pair.Key, pair.Value.ToPrimitive()));

return dict;
}

public static JObject FromPrimitive(object primitive)
{
if (primitive is JObject it)
{
return it;
}

if (primitive is Dictionary<string, object> dict)
{
var jobj = new JObject();
dict.ForEach(pair =>
{
jobj.Properties.Add(pair.Key, FromPrimitive(pair.Value));
});

return jobj;
}

if (primitive is object[] arr)
{
var jobj = new List<JObject>();
arr.ForEach(item => jobj.Add(FromPrimitive(item)));
return new JArray(jobj.ToArray());
}

if (primitive is bool boolean)
{
return new JBoolean(boolean);
}

if (primitive is string str)
{
return new JString(str);
}

if (IsNumber(primitive))
{
return new JNumber(Convert.ToDouble(primitive));
}

return null;
}

private static bool IsNumber(object value)
{
return value is sbyte
|| value is byte
|| value is short
|| value is ushort
|| value is int
|| value is uint
|| value is long
|| value is ulong
|| value is float
|| value is double
|| value is decimal;
}
}
}
5 changes: 5 additions & 0 deletions src/neo/IO/Json/JString.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,5 +86,10 @@ public override T TryGetEnum<T>(T defaultValue = default, bool ignoreCase = fals
return defaultValue;
}
}

public override object ToPrimitive()
{
return AsString();
}
}
}
9 changes: 0 additions & 9 deletions src/neo/NeoSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ public class NeoSystem : IDisposable
public IActorRef LocalNode { get; }
internal IActorRef TaskManager { get; }
public IActorRef Consensus { get; private set; }
public RpcServer RpcServer { get; private set; }

private readonly IStore store;
private ChannelsConfig start_message = null;
Expand All @@ -45,7 +44,6 @@ public void Dispose()
{
foreach (var p in Plugin.Plugins)
p.Dispose();
RpcServer?.Dispose();
EnsureStoped(LocalNode);
// Dispose will call ActorSystem.Terminate()
ActorSystem.Dispose();
Expand Down Expand Up @@ -88,13 +86,6 @@ public void StartNode(ChannelsConfig config)
}
}

public void StartRpc(IPAddress bindAddress, int port, Wallet wallet = null, string sslCert = null, string password = null,
string[] trustedAuthorities = null, long maxGasInvoke = default)
{
RpcServer = new RpcServer(this, wallet, maxGasInvoke);
RpcServer.Start(bindAddress, port, sslCert, password, trustedAuthorities);
}

internal void SuspendNodeStartup()
{
suspend = true;
Expand Down
12 changes: 12 additions & 0 deletions src/neo/Network/HttpException.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;

namespace Neo.Network
{
public class HttpException : Exception
{
public HttpException(int code, string message) : base(message)
{
HResult = code;
}
}
}
2 changes: 1 addition & 1 deletion src/neo/Network/RPC/RpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task<RpcResponse> SendAsync(RpcRequest request)

if (response.Error != null)
{
throw new RpcException(response.Error.Code, response.Error.Message);
throw new HttpException(response.Error.Code, response.Error.Message);
}

return response;
Expand Down
12 changes: 0 additions & 12 deletions src/neo/Network/RPC/RpcException.cs

This file was deleted.

Loading