static async Task <int> DeployTokenAsync( string settingsUrl, string tokenCfgPath) { #region RegisterDependencies var appSettings = GetCurrentSettingsFromUrl(settingsUrl); ContainerBuilder containerBuilder = new ContainerBuilder(); IServiceCollection collection = new Microsoft.Extensions.DependencyInjection.ServiceCollection(); containerBuilder.RegisterInstance(appSettings); containerBuilder.RegisterInstance <IBaseSettings>(appSettings.CurrentValue.EthereumCore); containerBuilder.RegisterInstance <ISlackNotificationSettings>(appSettings.CurrentValue.SlackNotifications); containerBuilder.RegisterInstance(appSettings.Nested(x => x.EthereumCore)); containerBuilder.RegisterInstance(appSettings.CurrentValue); var consoleLogger = new LogToConsole(); collection.AddSingleton <ILog>(consoleLogger); RegisterReposExt.RegisterAzureQueues(containerBuilder, appSettings.Nested(x => x.EthereumCore.Db.DataConnString), appSettings.Nested(x => x.SlackNotifications)); RegisterReposExt.RegisterAzureStorages(containerBuilder, appSettings.Nested(x => x.EthereumCore), appSettings.Nested(x => x.SlackNotifications), consoleLogger); RegisterRabbitQueueEx.RegisterRabbitQueue(collection, appSettings.Nested(x => x.EthereumCore.RabbitMq), appSettings.Nested(x => x.EthereumCore.Db.DataConnString), consoleLogger); RegisterDependency.RegisterServices(collection); RegisterDependency.RegisterServices(containerBuilder); containerBuilder.Populate(collection); containerBuilder.RegisterInstance <ILog>(consoleLogger); var resolver = containerBuilder.Build(); resolver.ActivateRequestInterceptor(); #endregion var web3 = resolver.Resolve <IWeb3>(); var contractService = resolver.Resolve <IContractService>(); var ercInterfaceService = resolver.Resolve <IErcInterfaceService>(); var exchangeContractService = resolver.Resolve <IExchangeContractService>(); var text = File.ReadAllText(tokenCfgPath); var tokenCfg = Newtonsoft.Json.JsonConvert.DeserializeObject <TokenCfg>(text); var addressUtil = new AddressUtil(); if (!exchangeContractService.IsValidAddress(tokenCfg.HotwalletAddress)) { await consoleLogger.WriteInfoAsync(nameof(Main), tokenCfg.ToJson(), $"HotwalletAddress is not a valid address."); return(0); } await consoleLogger.WriteInfoAsync(nameof(Main), "", $"Started Deployment"); foreach (var tokenDescr in tokenCfg.Tokens) { await consoleLogger.WriteInfoAsync(nameof(Main), "", $"Processing {tokenDescr.TokenName}"); if (!BigInteger.TryParse(tokenDescr.InitialSupply, out var initialSupply) || initialSupply == 0) { await consoleLogger.WriteInfoAsync(nameof(Main), tokenDescr.ToJson(), $"Can't parse initial supply value. It is not a BigInt or zero"); continue; } if (!exchangeContractService.IsValidAddress(tokenDescr.IssuerAddress)) { await consoleLogger.WriteInfoAsync(nameof(Main), tokenDescr.ToJson(), $"Issuer address is not a valid address."); continue; } var(abi, bytecode) = GetContractDeploymentForTokenType(tokenDescr.TokenType); string address = tokenDescr.TokenType == TokenType.Emissive ? await contractService.CreateContract(abi, bytecode, 4000000, tokenDescr.IssuerAddress, tokenDescr.TokenName, tokenDescr.Divisibility, tokenDescr.TokenSymbol, tokenDescr.Version) : await contractService.CreateContract(abi, bytecode, 4000000, tokenDescr.IssuerAddress, tokenDescr.TokenName, tokenDescr.Divisibility, tokenDescr.TokenSymbol, tokenDescr.Version, initialSupply); await consoleLogger.WriteInfoAsync(nameof(Main), tokenDescr.ToJson(), $"Deployed at address {address}"); if (tokenDescr.TokenType == TokenType.Emissive) { await consoleLogger.WriteInfoAsync(nameof(Main), tokenDescr.ToJson(), $"Starting Emission to {tokenCfg.HotwalletAddress}"); var transactionHash = await ercInterfaceService.Transfer(address, addressUtil.ConvertToChecksumAddress(tokenDescr.IssuerAddress), //Should be in SigningService tokenCfg.HotwalletAddress, initialSupply); await consoleLogger.WriteInfoAsync(nameof(Main), tokenDescr.ToJson(), $"Emission txHash is {transactionHash}. " + $"Waiting for compleation"); WaitForTransactionCompleation(web3, transactionHash); await consoleLogger.WriteInfoAsync(nameof(Main), tokenDescr.ToJson(), "Completed."); } } await consoleLogger.WriteInfoAsync(nameof(Main), "", "Completed processing all tokens."); return(0); }
public async Task WriteInfoAsync(string component, string process, string context, string info, DateTime?dateTime = null) { await _consoleLog.WriteInfoAsync(component, process, context, info); await _tableLog.WriteInfoAsync(component, process, context, info); }