public static void Save() { ConfigFileSerializer.Serialize( DefaultWalletFileName, Network.ToString(), ConnectionType.ToString(), CanSpendUnconfirmed.ToString(), UseTor.ToString(), TorHost, TorSocksPort.ToString(), TorControlPort.ToString(), TorControlPortPassword); Load(); }
public static void Load() { var rawContent = ConfigFileSerializer.Deserialize(); DefaultWalletFileName = rawContent.DefaultWalletFileName; if (rawContent.Network == Network.Main.ToString()) { Network = Network.Main; } else if (rawContent.Network == Network.TestNet.ToString()) { Network = Network.TestNet; } else if (rawContent.Network == null) { throw new Exception($"Network is missing from {ConfigFileSerializer.ConfigFilePath}"); } else { throw new Exception($"Wrong Network is specified in {ConfigFileSerializer.ConfigFilePath}"); } if (rawContent.ConnectionType == ConnectionType.FullNode.ToString()) { ConnectionType = ConnectionType.FullNode; } else if (rawContent.ConnectionType == ConnectionType.Http.ToString()) { ConnectionType = ConnectionType.Http; } else if (rawContent.ConnectionType == null) { throw new Exception($"ConnectionType is missing from {ConfigFileSerializer.ConfigFilePath}"); } else { throw new Exception($"Wrong ConnectionType is specified in {ConfigFileSerializer.ConfigFilePath}"); } try { CanSpendUnconfirmed = bool.Parse(rawContent.CanSpendUnconfirmed.Trim()); } catch (Exception ex) { throw new Exception($"Wrong CanSpendUnconfirmed value in {ConfigFileSerializer.ConfigFilePath}", ex); } try { UseTor = bool.Parse(rawContent.UseTor.Trim()); } catch (Exception ex) { throw new Exception($"Wrong UseTor value in {ConfigFileSerializer.ConfigFilePath}", ex); } TorHost = rawContent.TorHost.Trim(); try { TorSocksPort = int.Parse(rawContent.TorSocksPort.Trim()); } catch (Exception ex) { throw new Exception($"Wrong TorSocksPort value in {ConfigFileSerializer.ConfigFilePath}", ex); } try { TorControlPort = int.Parse(rawContent.TorControlPort.Trim()); } catch (Exception ex) { throw new Exception($"Wrong TorControlPort value in {ConfigFileSerializer.ConfigFilePath}", ex); } TorControlPortPassword = rawContent.TorControlPortPassword; }