Skip to content

Commit

Permalink
Merge pull request #595 from NethermindEth/wip
Browse files Browse the repository at this point in the history
Wip
  • Loading branch information
tkstanczak authored Jun 30, 2019
2 parents f80da4b + 89e318b commit f06e7a5
Show file tree
Hide file tree
Showing 43 changed files with 525 additions and 289 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ sudo: required
dist: xenial
dotnet: 2.2
git:
depth: 3
submodules_depth: 3
depth: 1
submodules_depth: 1
before_script:
- chmod -R +x scripts
notifications:
Expand Down
8 changes: 5 additions & 3 deletions src/Nethermind/Nethermind.Cli/CliEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,15 @@ public CliEngine()
JintEngine = new Engine();
JintEngine.SetValue("gasPrice", (double) 20.GWei());
JintEngine.SetValue("load", new Action<string>(LoadFile));
JintEngine.SetValue("log", new Action<JsValue>(v => Console.WriteLine(v.ToString())));
}

private void LoadFile(string filePath)
{
string content = File.ReadAllText(filePath);
JintEngine.Execute(content);
}

private static Delegate CreateDelegate(MethodInfo methodInfo, CliModuleBase module)
{
if (methodInfo == null)
Expand All @@ -64,12 +65,13 @@ private static Delegate CreateDelegate(MethodInfo methodInfo, CliModuleBase modu

return methodInfo.CreateDelegate(Expression.GetDelegateType(), module);
}

public JsValue Execute(string statement)
{
try
{
return JintEngine.Execute(statement).GetCompletionValue();
Engine e = JintEngine.Execute(statement);
return e.GetCompletionValue();
}
catch (ParserException e)
{
Expand Down
4 changes: 4 additions & 0 deletions src/Nethermind/Nethermind.Cli/INodeManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/

using System;
using System.Threading.Tasks;
using Jint.Native;
using Nethermind.JsonRpc.Client;

namespace Nethermind.Cli
Expand All @@ -26,5 +28,7 @@ public interface INodeManager : IJsonRpcClient
string CurrentUri { get; }

void SwitchUri(Uri uri);

Task<JsValue> PostJint(string method, params object[] parameters);
}
}
38 changes: 19 additions & 19 deletions src/Nethermind/Nethermind.Cli/Modules/CliqueCliModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,65 +16,65 @@
* along with the Nethermind. If not, see <http://www.gnu.org/licenses/>.
*/

using Nethermind.Core;
using Jint.Native;

namespace Nethermind.Cli.Modules
{
[CliModule("clique")]
public class CliqueCliModule : CliModuleBase
{
[CliFunction("clique", "getSnapshot")]
public object GetSnapshot()
public JsValue GetSnapshot()
{
return NodeManager.Post<object>("clique_getSnapshot").Result;
return NodeManager.PostJint("clique_getSnapshot").Result;
}

[CliFunction("clique", "getSnapshotAtHash")]
public object GetSnapshotAtHash(string hash)
public JsValue GetSnapshotAtHash(string hash)
{
return NodeManager.Post<object>("clique_getSnapshotAtHash", CliParseHash(hash)).Result;
return NodeManager.PostJint("clique_getSnapshotAtHash", CliParseHash(hash)).Result;
}

[CliFunction("clique", "getSigners")]
public string[] GetSigners()
public JsValue GetSigners()
{
return NodeManager.Post<string[]>("clique_getSigners").Result;
return NodeManager.PostJint("clique_getSigners").Result;
}

[CliFunction("clique", "getSignersAtNumber")]
public Address[] GetSignersAtNumber(long number)
public JsValue GetSignersAtNumber(long number)
{
return NodeManager.Post<Address[]>("clique_getSignersAtNumber", number.ToString()).Result;
return NodeManager.PostJint("clique_getSignersAtNumber", number.ToString()).Result;
}

[CliFunction("clique", "getSignersAtHash")]
public string[] GetSignersAtHash(string hash)
public JsValue GetSignersAtHash(string hash)
{
return NodeManager.Post<string[]>("clique_getSignersAtHash", CliParseHash(hash)).Result;
return NodeManager.PostJint("clique_getSignersAtHash", CliParseHash(hash)).Result;
}

[CliFunction("clique", "getSignersAnnotated")]
public string[] GetSignersAnnotated()
public JsValue GetSignersAnnotated()
{
return NodeManager.Post<string[]>("clique_getSignersAnnotated").Result;
return NodeManager.PostJint("clique_getSignersAnnotated").Result;
}

[CliFunction("clique", "getSignersAtHashAnnotated")]
public string[] GetSignersAtHashAnnotated(string hash)
public JsValue GetSignersAtHashAnnotated(string hash)
{
return NodeManager.Post<string[]>("clique_getSignersAtHashAnnotated", CliParseHash(hash)).Result;
return NodeManager.PostJint("clique_getSignersAtHashAnnotated", CliParseHash(hash)).Result;
}

[CliFunction("clique", "propose")]
public bool Propose(string address, bool vote)
public JsValue Propose(string address, bool vote)
{
return NodeManager.Post<bool>("clique_propose", CliParseAddress(address), vote).Result;
return NodeManager.PostJint("clique_propose", CliParseAddress(address), vote).Result;
}

[CliFunction("clique", "discard")]
public bool Propose(string address)
public JsValue Propose(string address)
{
return NodeManager.Post<bool>("clique_discard", CliParseAddress(address)).Result;
return NodeManager.PostJint("clique_discard", CliParseAddress(address)).Result;
}

public CliqueCliModule(ICliEngine cliEngine, INodeManager nodeManager) : base(cliEngine, nodeManager)
Expand Down
29 changes: 15 additions & 14 deletions src/Nethermind/Nethermind.Cli/Modules/DebugCliModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
* along with the Nethermind. If not, see <http://www.gnu.org/licenses/>.
*/

using Jint.Native;
using Nethermind.JsonRpc.Modules.DebugModule;

namespace Nethermind.Cli.Modules
Expand All @@ -24,45 +25,45 @@ namespace Nethermind.Cli.Modules
public class DebugCliModule : CliModuleBase
{
[CliFunction("debug", "traceBlock")]
public object TraceBlock(string hash)
public JsValue TraceBlock(string hash)
{
return NodeManager.Post<object>("debug_traceBlock", hash).Result;
return NodeManager.PostJint("debug_traceBlock", hash).Result;
}

[CliFunction("debug", "traceBlockByNumber")]
public object TraceBlockByNumber(string number)
public JsValue TraceBlockByNumber(string number)
{
return NodeManager.Post<object>("debug_traceBlockByNumber", number).Result;
return NodeManager.PostJint("debug_traceBlockByNumber", number).Result;
}

[CliFunction("debug", "traceBlockByHash")]
public object TraceBlockByHash(string hash)
public JsValue TraceBlockByHash(string hash)
{
return NodeManager.Post<object>("debug_traceBlockByHash", hash).Result;
return NodeManager.PostJint("debug_traceBlockByHash", hash).Result;
}

[CliFunction("debug", "traceTransaction")]
public object TraceTransaction(string hash)
public JsValue TraceTransaction(string hash)
{
return NodeManager.Post<object>("debug_traceTransaction", hash, new TraceOptions()).Result;
return NodeManager.PostJint("debug_traceTransaction", hash, new TraceOptions()).Result;
}

[CliFunction("debug", "traceTransactionByBlockAndIndex")]
public object TraceTransactionByBlockAndIndex(string hash)
public JsValue TraceTransactionByBlockAndIndex(string hash)
{
return NodeManager.Post<object>("debug_traceTransactionByBlockAndIndex", hash).Result;
return NodeManager.PostJint("debug_traceTransactionByBlockAndIndex", hash).Result;
}

[CliFunction("debug", "traceTransactionByBlockhashAndIndex")]
public object TraceTransactionByBlockhashAndIndex(string hash)
public JsValue TraceTransactionByBlockhashAndIndex(string hash)
{
return NodeManager.Post<object>("debug_traceTransactionByBlockhashAndIndex", hash).Result;
return NodeManager.PostJint("debug_traceTransactionByBlockhashAndIndex", hash).Result;
}

[CliFunction("debug", "config")]
public string GetConfigValue(string category, string name)
public JsValue GetConfigValue(string category, string name)
{
return NodeManager.Post<string>("debug_getConfigValue", category, name).Result;
return NodeManager.PostJint("debug_getConfigValue", category, name).Result;
}

public DebugCliModule(ICliEngine cliEngine, INodeManager nodeManager) : base(cliEngine, nodeManager)
Expand Down
5 changes: 3 additions & 2 deletions src/Nethermind/Nethermind.Cli/Modules/DiagCliModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System;
using System.IO;
using System.Reflection;
using Jint.Native;
using Nethermind.Core.Crypto;
using Nethermind.Core.Extensions;
using Nethermind.Network;
Expand All @@ -29,9 +30,9 @@ namespace Nethermind.Cli.Modules
public class DiagCliModule : CliModuleBase
{
[CliProperty("diag", "cliVersion")]
public string CliVersion()
public JsValue CliVersion()
{
return this.GetType().Assembly.FullName;
return GetType().Assembly.FullName;
}

public DiagCliModule(ICliEngine cliEngine, INodeManager nodeManager) : base(cliEngine, nodeManager)
Expand Down
41 changes: 21 additions & 20 deletions src/Nethermind/Nethermind.Cli/Modules/EthCliModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/

using System.Numerics;
using Jint.Native;
using Nethermind.Core;
using Nethermind.Core.Crypto;
using Nethermind.Core.Extensions;
Expand Down Expand Up @@ -52,9 +53,9 @@ public object GetBlockByHash(string hash, bool returnFullTransactionObjects)
}

[CliFunction("eth", "getBlockByNumber")]
public object GetBlockByNumber(string blockParameter, bool returnFullTransactionObjects)
public JsValue GetBlockByNumber(string blockParameter, bool returnFullTransactionObjects)
{
return NodeManager.Post<object>("eth_getBlockByNumber", blockParameter, returnFullTransactionObjects).Result;
return NodeManager.PostJint("eth_getBlockByNumber", blockParameter, returnFullTransactionObjects).Result;
}

[CliFunction("eth", "sendEth")]
Expand All @@ -70,57 +71,57 @@ public string SendWei(string from, string to, BigInteger amountInWei)
}

[CliProperty("eth", "blockNumber")]
public long BlockNumber()
public JsValue BlockNumber()
{
return NodeManager.Post<long>("eth_blockNumber").Result;
return NodeManager.Post("eth_blockNumber").Result;
}

[CliFunction("eth", "getCode")]
public string GetCode(string address, string blockParameter)
public JsValue GetCode(string address, string blockParameter)
{
return NodeManager.Post<string>("eth_getCode", address, blockParameter).Result;
return NodeManager.PostJint("eth_getCode", address, blockParameter).Result;
}

[CliFunction("eth", "getBlockTransactionCountByNumber")]
public string GetBlockTransactionCountByNumber(string blockParameter)
public JsValue GetBlockTransactionCountByNumber(string blockParameter)
{
return NodeManager.Post<string>("eth_getBlockTransactionCountByNumber", blockParameter).Result;
return NodeManager.PostJint("eth_getBlockTransactionCountByNumber", blockParameter).Result;
}

[CliFunction("eth", "getBlockTransactionCountByHash")]
public string GetBlockTransactionCountByHash(string hash)
public JsValue GetBlockTransactionCountByHash(string hash)
{
return NodeManager.Post<string>("eth_getBlockTransactionCountByHash", hash).Result;
return NodeManager.PostJint("eth_getBlockTransactionCountByHash", hash).Result;
}

[CliFunction("eth", "getUncleCountByBlockNumber")]
public string GetUncleCountByBlockNumber(string blockParameter)
public JsValue GetUncleCountByBlockNumber(string blockParameter)
{
return NodeManager.Post<string>("eth_getUncleCountByBlockNumber", blockParameter).Result;
return NodeManager.PostJint("eth_getUncleCountByBlockNumber", blockParameter).Result;
}

[CliFunction("eth", "getTransactionByBlockNumberAndIndex")]
public object GetTransactionByBlockNumberAndIndex(string blockParameter, string index)
public JsValue GetTransactionByBlockNumberAndIndex(string blockParameter, string index)
{
return NodeManager.Post<object>("eth_getTransactionByBlockNumberAndIndex", blockParameter, index).Result;
return NodeManager.PostJint("eth_getTransactionByBlockNumberAndIndex", blockParameter, index).Result;
}

[CliFunction("eth", "getTransactionReceipt")]
public object GetTransactionReceipt(string txHash)
public JsValue GetTransactionReceipt(string txHash)
{
return NodeManager.Post<object>("eth_getTransactionReceipt", txHash).Result;
return NodeManager.PostJint("eth_getTransactionReceipt", txHash).Result;
}

[CliFunction("eth", "getBalance")]
public string GetBalance(string address, string blockParameter)
public JsValue GetBalance(string address, string blockParameter)
{
return NodeManager.Post<string>("eth_getBalance", CliParseAddress(address), blockParameter).Result;
return NodeManager.PostJint("eth_getBalance", CliParseAddress(address), blockParameter).Result;
}

[CliProperty("eth", "protocolVersion")]
public int ProtocolVersion()
public JsValue ProtocolVersion()
{
return NodeManager.Post<int>("eth_protocolVersion").Result;
return NodeManager.PostJint("eth_protocolVersion").Result;
}

public EthCliModule(ICliEngine cliEngine, INodeManager nodeManager) : base(cliEngine, nodeManager)
Expand Down
7 changes: 4 additions & 3 deletions src/Nethermind/Nethermind.Cli/Modules/NetCliModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,21 @@

using System;
using System.Numerics;
using Jint.Native;

namespace Nethermind.Cli.Modules
{
[CliModule("net")]
public class NetCliModule : CliModuleBase
{
[CliProperty("net", "localEnode")]
public string LocalEnode() => NodeManager.Post<string>("net_localEnode").Result;
public JsValue LocalEnode() => NodeManager.PostJint("net_localEnode").Result;

[CliProperty("net", "version")]
public BigInteger Version() => NodeManager.Post<BigInteger>("net_version").Result;
public JsValue Version() => NodeManager.PostJint("net_version").Result;

[CliProperty("net", "peerCount")]
public BigInteger PeerCount() => NodeManager.Post<BigInteger>("net_peerCount").Result;
public JsValue PeerCount() => NodeManager.PostJint("net_peerCount").Result;

public NetCliModule(ICliEngine cliEngine, INodeManager nodeManager) : base(cliEngine, nodeManager)
{
Expand Down
10 changes: 5 additions & 5 deletions src/Nethermind/Nethermind.Cli/Modules/NodeCliModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System;
using System.IO;
using System.Reflection;
using Jint.Native;
using Nethermind.Core.Crypto;
using Nethermind.Core.Extensions;
using Nethermind.Network;
Expand Down Expand Up @@ -70,18 +71,17 @@ private string GetVariable(string name, string defaultValue)
[CliProperty("node", "address")]
public string Address()
{
return new Enode(Enode()).Address.ToString();
return new Enode(Enode().ToString()).Address.ToString();
}

[CliProperty("node", "enode")]
public string Enode()
public JsValue Enode()
{
string result = NodeManager.Post<string>("net_localEnode").Result;
return result;
return NodeManager.PostJint("net_localEnode").Result;
}

[CliProperty("node", "uri")]
public string Uri()
public JsValue Uri()
{
return NodeManager.CurrentUri;
}
Expand Down
Loading

0 comments on commit f06e7a5

Please sign in to comment.