Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Commit

Permalink
change the structure of config.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Zhang committed Dec 13, 2017
1 parent 8a6156b commit 6506575
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 36 deletions.
8 changes: 4 additions & 4 deletions neo-gui/Cryptography/CertificateQueryService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internal static class CertificateQueryService

static CertificateQueryService()
{
Directory.CreateDirectory(Settings.Default.CertCachePath);
Directory.CreateDirectory(Settings.Default.Paths.CertCache);
}

private static void Web_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
Expand All @@ -37,7 +37,7 @@ private static void Web_DownloadDataCompleted(object sender, DownloadDataComplet
else
{
string address = Wallet.ToAddress(hash);
string path = Path.Combine(Settings.Default.CertCachePath, $"{address}.cer");
string path = Path.Combine(Settings.Default.Paths.CertCache, $"{address}.cer");
File.WriteAllBytes(path, e.Result);
lock (results)
{
Expand All @@ -60,7 +60,7 @@ public static CertificateQueryResult Query(UInt160 hash)
results[hash] = new CertificateQueryResult { Type = CertificateQueryResultType.Querying };
}
string address = Wallet.ToAddress(hash);
string path = Path.Combine(Settings.Default.CertCachePath, $"{address}.cer");
string path = Path.Combine(Settings.Default.Paths.CertCache, $"{address}.cer");
if (File.Exists(path))
{
lock (results)
Expand All @@ -84,7 +84,7 @@ private static void UpdateResultFromFile(UInt160 hash)
X509Certificate2 cert;
try
{
cert = new X509Certificate2(Path.Combine(Settings.Default.CertCachePath, $"{address}.cer"));
cert = new X509Certificate2(Path.Combine(Settings.Default.Paths.CertCache, $"{address}.cer"));
}
catch (CryptographicException)
{
Expand Down
2 changes: 1 addition & 1 deletion neo-gui/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static void Main()
{
LocalNode.LoadState(fs);
}
using (Blockchain.RegisterBlockchain(new LevelDBBlockchain(Settings.Default.DataDirectoryPath)))
using (Blockchain.RegisterBlockchain(new LevelDBBlockchain(Settings.Default.Paths.Chain)))
using (LocalNode = new LocalNode())
{
LocalNode.UpnpEnabled = true;
Expand Down
36 changes: 28 additions & 8 deletions neo-gui/Properties/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ namespace Neo.Properties
{
internal sealed partial class Settings
{
public string DataDirectoryPath { get; }
public string CertCachePath { get; }
public ushort NodePort { get; }
public ushort WsPort { get; }
public PathsSettings Paths { get; }
public P2PSettings P2P { get; }
public BrowserSettings Urls { get; }
public ContractSettings Contracts { get; }

Expand All @@ -21,15 +19,37 @@ public Settings()
Save();
}
IConfigurationSection section = new ConfigurationBuilder().AddJsonFile("config.json").Build().GetSection("ApplicationConfiguration");
this.DataDirectoryPath = section.GetSection("DataDirectoryPath").Value;
this.CertCachePath = section.GetSection("CertCachePath").Value;
this.NodePort = ushort.Parse(section.GetSection("NodePort").Value);
this.WsPort = ushort.Parse(section.GetSection("WsPort").Value);
this.Paths = new PathsSettings(section.GetSection("Paths"));
this.P2P = new P2PSettings(section.GetSection("P2P"));
this.Urls = new BrowserSettings(section.GetSection("Urls"));
this.Contracts = new ContractSettings(section.GetSection("Contracts"));
}
}

internal class PathsSettings
{
public string Chain { get; }
public string CertCache { get; }

public PathsSettings(IConfigurationSection section)
{
this.Chain = section.GetSection("Chain").Value;
this.CertCache = section.GetSection("CertCache").Value;
}
}

internal class P2PSettings
{
public ushort Port { get; }
public ushort WsPort { get; }

public P2PSettings(IConfigurationSection section)
{
this.Port = ushort.Parse(section.GetSection("Port").Value);
this.WsPort = ushort.Parse(section.GetSection("WsPort").Value);
}
}

internal class BrowserSettings
{
public string AddressUrl { get; }
Expand Down
4 changes: 2 additions & 2 deletions neo-gui/UI/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ private void MainForm_Load(object sender, EventArgs e)
File.Delete(acc_zip_path);
}
Blockchain.PersistCompleted += Blockchain_PersistCompleted;
Program.LocalNode.Start(Settings.Default.NodePort, Settings.Default.WsPort);
Program.LocalNode.Start(Settings.Default.P2P.Port, Settings.Default.P2P.WsPort);
});
}

Expand Down Expand Up @@ -945,7 +945,7 @@ private void viewCertificateToolStripMenuItem_Click(object sender, EventArgs e)
AssetState asset = (AssetState)listView2.SelectedItems[0].Tag;
UInt160 hash = Contract.CreateSignatureRedeemScript(asset.Owner).ToScriptHash();
string address = Wallet.ToAddress(hash);
string path = Path.Combine(Settings.Default.CertCachePath, $"{address}.cer");
string path = Path.Combine(Settings.Default.Paths.CertCache, $"{address}.cer");
Process.Start(path);
}

Expand Down
15 changes: 8 additions & 7 deletions neo-gui/config.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"ApplicationConfiguration": {
"DataDirectoryPath": "Chain",
"CertCachePath": "Certs",
"NodePort": 10333,
"WsPort": 10334,
"UriPrefix": [ "http://*:10332" ],
"SslCert": "",
"SslCertPassword": "",
"Paths": {
"Chain": "Chain",
"CertCache": "Certs"
},
"P2P": {
"Port": 10333,
"WsPort": 10334
},
"Urls": {
"AddressUrl": "https://www.antchain.xyz/address/{0}",
"AssetUrl": "https://www.antchain.xyz/asset/hash/{0}",
Expand Down
15 changes: 8 additions & 7 deletions neo-gui/config.mainnet.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"ApplicationConfiguration": {
"DataDirectoryPath": "Chain",
"CertCachePath": "Certs",
"NodePort": 10333,
"WsPort": 10334,
"UriPrefix": [ "http://*:10332" ],
"SslCert": "",
"SslCertPassword": "",
"Paths": {
"Chain": "Chain",
"CertCache": "Certs"
},
"P2P": {
"Port": 10333,
"WsPort": 10334
},
"Urls": {
"AddressUrl": "https://www.antchain.xyz/address/{0}",
"AssetUrl": "https://www.antchain.xyz/asset/hash/{0}",
Expand Down
15 changes: 8 additions & 7 deletions neo-gui/config.testnet.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"ApplicationConfiguration": {
"DataDirectoryPath": "ChainTestNet",
"CertCachePath": "Certs",
"NodePort": 20333,
"WsPort": 20334,
"UriPrefix": [ "http://*:20332" ],
"SslCert": "",
"SslCertPassword": "",
"Paths": {
"Chain": "ChainTestNet",
"CertCache": "Certs"
},
"P2P": {
"Port": 20333,
"WsPort": 20334
},
"Urls": {
"AddressUrl": "http://testnet.antchain.xyz/address/{0}",
"AssetUrl": "http://testnet.antchain.xyz/asset/hash/{0}",
Expand Down

0 comments on commit 6506575

Please sign in to comment.