GethInput.cs
1 namespace GethConnector 2 { 3 public static class GethInput 4 { 5 private const string GethHostVar = "GETH_HOST"; 6 private const string GethPortVar = "GETH_HTTP_PORT"; 7 private const string GethPrivKeyVar = "GETH_PRIVATE_KEY"; 8 private const string MarketplaceAddressVar = "CODEXCONTRACTS_MARKETPLACEADDRESS"; 9 private const string TokenAddressVar = "CODEXCONTRACTS_TOKENADDRESS"; 10 private const string AbiVar = "CODEXCONTRACTS_ABI"; 11 12 static GethInput() 13 { 14 var error = new List<string>(); 15 var gethHost = GetEnvVar(error, GethHostVar); 16 var gethPort = Convert.ToInt32(GetEnvVar(error, GethPortVar)); 17 var privateKey = GetEnvVar(error, GethPrivKeyVar); 18 var marketplaceAddress = GetEnvVar(error, MarketplaceAddressVar); 19 var tokenAddress = GetEnvVar(error, TokenAddressVar); 20 var abi = GetEnvVar(error, AbiVar); 21 22 if (error.Any()) 23 { 24 LoadError = string.Join(", ", error); 25 } 26 else 27 { 28 GethHost = gethHost!; 29 GethPort = gethPort; 30 PrivateKey = privateKey!; 31 MarketplaceAddress = marketplaceAddress!; 32 TokenAddress = tokenAddress!; 33 ABI = abi!; 34 } 35 } 36 37 public static string GethHost { get; } = string.Empty; 38 public static int GethPort { get; } 39 public static string PrivateKey { get; } = string.Empty; 40 public static string MarketplaceAddress { get; } = string.Empty; 41 public static string TokenAddress { get; } = string.Empty; 42 public static string ABI { get; } = string.Empty; 43 public static string LoadError { get; } = string.Empty; 44 45 private static string? GetEnvVar(List<string> error, string name) 46 { 47 var result = Environment.GetEnvironmentVariable(name); 48 if (string.IsNullOrEmpty(result)) 49 { 50 error.Add($"'{name}' is not set."); 51 return null; 52 } 53 return result.Trim(); 54 } 55 } 56 }