private async Task HandleReserveNextAddress(ReserveEthereumAddress reserveEthereumAddress) { var store = await _storeRepository.FindStore(reserveEthereumAddress.StoreId); var ethereumSupportedPaymentMethod = store.GetSupportedPaymentMethods(_btcPayNetworkProvider) .OfType <EthereumSupportedPaymentMethod>() .SingleOrDefault(method => method.PaymentId.CryptoCode == reserveEthereumAddress.CryptoCode); if (ethereumSupportedPaymentMethod == null) { _eventAggregator.Publish(new ReserveEthereumAddressResponse() { OpId = reserveEthereumAddress.OpId, Failed = true }); return; } ethereumSupportedPaymentMethod.CurrentIndex++; var address = ethereumSupportedPaymentMethod.GetWalletDerivator()? .Invoke((int)ethereumSupportedPaymentMethod.CurrentIndex); if (string.IsNullOrEmpty(address)) { _eventAggregator.Publish(new ReserveEthereumAddressResponse() { OpId = reserveEthereumAddress.OpId, Failed = true }); return; } store.SetSupportedPaymentMethod(ethereumSupportedPaymentMethod.PaymentId, ethereumSupportedPaymentMethod); await _storeRepository.UpdateStore(store); _eventAggregator.Publish(new ReserveEthereumAddressResponse() { Address = address, Index = ethereumSupportedPaymentMethod.CurrentIndex, CryptoCode = ethereumSupportedPaymentMethod.CryptoCode, OpId = reserveEthereumAddress.OpId, StoreId = reserveEthereumAddress.StoreId, XPub = ethereumSupportedPaymentMethod.XPub }); }
public async Task <ReserveEthereumAddressResponse> ReserveNextAddress(ReserveEthereumAddress address) { address.OpId = string.IsNullOrEmpty(address.OpId) ? Guid.NewGuid().ToString() : address.OpId; var tcs = new TaskCompletionSource <ReserveEthereumAddressResponse>(); var subscription = _eventAggregator.Subscribe <ReserveEthereumAddressResponse>(response => { if (response.OpId == address.OpId) { tcs.SetResult(response); } }); _eventAggregator.Publish(address); if (tcs.Task.Wait(TimeSpan.FromSeconds(60))) { subscription?.Dispose(); return(await tcs.Task); } subscription?.Dispose(); return(null); }