-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into 'master'
Develop See merge request company-projects/Meadow!36
- Loading branch information
Showing
11 changed files
with
201 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp2.1</TargetFramework> | ||
<GeneratePackageOnBuild Condition="'$(Configuration)' == 'Release'">true</GeneratePackageOnBuild> | ||
<PackAsTool>true</PackAsTool> | ||
<ToolCommandName>meadow-testnode</ToolCommandName> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="2.2.5" /> | ||
<PackageReference Include="Secp256k1.Native" Version="0.1.18" ExcludeAssets="native" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Meadow.JsonRpc.Server.Proxy\Meadow.JsonRpc.Server.Proxy.csproj" /> | ||
<ProjectReference Include="..\Meadow.TestNode\Meadow.TestNode.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using McMaster.Extensions.CommandLineUtils; | ||
|
||
namespace Meadow.TestNode.Host | ||
{ | ||
|
||
class ProcessArgs | ||
{ | ||
[Option("-p|--port", "TODO.", CommandOptionType.SingleValue)] | ||
public uint? Port { get; } | ||
|
||
[Option("-h|--host", "TODO", CommandOptionType.SingleValue)] | ||
public string Host { get; } | ||
|
||
[Option("-a|--account_count", "TODO", CommandOptionType.SingleValue)] | ||
public uint? AccountCount { get; } | ||
|
||
[Option("-b|--account_balance", "TODO", CommandOptionType.SingleValue)] | ||
public uint? AccountBalance { get; } | ||
|
||
[Option("-m|--mnemonic", "TODO", CommandOptionType.SingleValue)] | ||
public string Mnemonic { get; } | ||
|
||
[Option("--proxy_node", "TODO", CommandOptionType.SingleValue)] | ||
public string Proxy { get; } | ||
|
||
public static ProcessArgs Parse(string[] args) | ||
{ | ||
var app = new CommandLineApplication<ProcessArgs>(throwOnUnexpectedArg: true); | ||
app.Conventions.UseDefaultConventions(); | ||
app.Parse(args); | ||
return app.Model; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
using Meadow.Core.AccountDerivation; | ||
using System; | ||
using System.Net; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Meadow.TestNode.Host | ||
{ | ||
class Program | ||
{ | ||
|
||
static async Task Main(string[] args) | ||
{ | ||
var opts = ProcessArgs.Parse(args); | ||
|
||
if (!string.IsNullOrWhiteSpace(opts.Proxy)) | ||
{ | ||
// TODO: testnode.host proxy support | ||
throw new NotImplementedException(); | ||
} | ||
|
||
IPAddress host; | ||
if (string.IsNullOrWhiteSpace(opts.Host) || opts.Host.Equals("localhost", StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
host = IPAddress.Loopback; | ||
} | ||
else if (opts.Host == "*") | ||
{ | ||
host = IPAddress.Any; | ||
} | ||
else if (IPAddress.TryParse(opts.Host, out var addr)) | ||
{ | ||
host = addr; | ||
} | ||
else | ||
{ | ||
var entry = await Dns.GetHostEntryAsync(opts.Host); | ||
host = entry.AddressList[0]; | ||
} | ||
|
||
// Setup account derivation / keys | ||
IAccountDerivation accountDerivation; | ||
if (string.IsNullOrWhiteSpace(opts.Mnemonic)) | ||
{ | ||
var hdWalletAccountDerivation = HDAccountDerivation.Create(); | ||
accountDerivation = hdWalletAccountDerivation; | ||
Console.WriteLine($"Using mnemonic phrase: '{hdWalletAccountDerivation.MnemonicPhrase}'"); | ||
Console.WriteLine("Warning: this private key generation is not secure and should not be used in production."); | ||
} | ||
else | ||
{ | ||
accountDerivation = new HDAccountDerivation(opts.Mnemonic); | ||
} | ||
|
||
|
||
var accountConfig = new AccountConfiguration | ||
{ | ||
AccountGenerationCount = (int)(opts.AccountCount ?? 100), | ||
DefaultAccountEtherBalance = opts.AccountBalance ?? 1000, | ||
AccountDerivationMethod = accountDerivation | ||
}; | ||
|
||
// Create our local test node. | ||
using (var testNodeServer = new TestNodeServer( | ||
port: (int)opts.Port.GetValueOrDefault(), | ||
address: host, | ||
accountConfig: accountConfig)) | ||
{ | ||
Console.WriteLine("Starting server..."); | ||
|
||
// Start our local test node. | ||
await testNodeServer.RpcServer.StartAsync(); | ||
|
||
// Create an RPC client for our local test node. | ||
var serverAddresses = string.Join(", ", testNodeServer.RpcServer.ServerAddresses); | ||
Console.WriteLine($"Test node server listening on: {serverAddresses}"); | ||
|
||
// Listen for exit request. | ||
var exitEvent = new SemaphoreSlim(0, 1); | ||
Console.CancelKeyPress += (s, e) => | ||
{ | ||
exitEvent.Release(); | ||
e.Cancel = true; | ||
}; | ||
|
||
// Shutdown. | ||
await exitEvent.WaitAsync(); | ||
Console.WriteLine("Stopping server and exiting..."); | ||
await testNodeServer.RpcServer.StopAsync(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters