public async Task <Account> GenerateAccountAndSendSomeMoney(int amount) { var networkType = Client.NetworkHttp.GetNetworkType().Wait(); var account = Account.GenerateNewAccount(networkType); var money = (ulong)amount; var mosaicToTransfer = NetworkCurrencyMosaic.CreateRelative(money); var transferTransaction = TransferTransaction.Create( Deadline.Create(), account.Address, new List <Mosaic>() { // mosaicToTransfer }, PlainMessage.Create("transferTest"), networkType); var signedTransaction = SeedAccount.Sign(transferTransaction, Environment.GenerationHash); WatchForFailure(signedTransaction); try { await WebSocket.Listener.Open(); var tx = WebSocket.Listener.ConfirmedTransactionsGiven(account.Address).Take(1).Timeout(TimeSpan.FromSeconds(100)); await Client.TransactionHttp.Announce(signedTransaction); var result = await tx; if (result.IsConfirmed()) { return(account); } else { throw new Exception($"Unable to send money to account {account.Address.Plain}"); } } finally { try { // WebSocket.Listener.Close(); } catch (Exception) { //do nothing } } }
private static async Task InitializeDatabase(IHost host) { using (var scope = host.Services.CreateScope()) { var services = scope.ServiceProvider; await SeedAccount.InitializeAsync(services); //var logger = services // .GetRequiredService<ILogger<Program>>(); //logger.LogError(ex, "Error occurred seeding the DB."); } }