/// <summary> /// Creates an address for the specified wallet with the userid. /// </summary> /// <param name="walletId">The wallet id.</param> /// <param name="userId">The user id.</param> /// <returns>the new address and private key created in the wallet</returns> public async Task <string[]> CreateAddress(int walletId, Guid userId) { try { using (var currencyRepo = new Repository <Currency>()) { var currency = await currencyRepo.GetOrDefaultAsync(x => x.Id == walletId); if (currency == null) { return(null); } //var wallet = new WalletConnector("127.0.0.1", 33113, "sa_ddam213.3", "213bit"); var wallet = new WalletConnector(currency.WalletHost, currency.WalletPort, currency.WalletUser, currency.WalletPass); if (wallet == null) { Log.Message(LogLevel.Error, "[CreateAddress] - Wallet '{0}' not found.", walletId); return(null); } string address = wallet.GenerateAddress(userId.ToString()); if (string.IsNullOrEmpty(address)) { Log.Message(LogLevel.Error, "[CreateAddress] - Wallet '{0}' failed to generate address.", walletId); return(null); } Log.Message(LogLevel.Debug, "[CreateAddress] - Address '{0}' generated for CurrencyId: {1}, UserId: {2}", address, walletId, userId); string privateKey = wallet.DumpPrivKey(address); if (string.IsNullOrEmpty(privateKey)) { Log.Message(LogLevel.Error, "[CreateAddress] - Wallet '{0}' failed to dump privatekey.", walletId); return(null); } Log.Message(LogLevel.Debug, "[CreateAddress] - Private key '{0}' dumped for CurrencyId: {1}, UserId: {2}", privateKey, walletId, userId); Log.Message(LogLevel.Info, "[CreateAddress] - New address '{0}' created for CurrencyId: {1}, UserId: {2}", address, walletId, userId); return(new string[] { address, privateKey }); } } catch (Exception ex) { Log.Exception("[CreateAddress] - An exception occured creating address, WalletId: {0}, UserId: {1}", ex, walletId, userId); } return(null); }