public async Task <TimestampDao> GetTimestampDetails(string timestampId, string requestedUserId, CancellationToken cancellationToken) { Guard.Argument(timestampId, nameof(timestampId)).NotNull().NotEmpty().NotWhiteSpace(); Guard.Argument(requestedUserId, nameof(requestedUserId)).NotNull().NotEmpty().NotWhiteSpace(); var timestamp = await _timestampRepository.GetTimestampById(timestampId, cancellationToken); if (timestamp != null && !timestamp.UserId.Equals(requestedUserId, StringComparison.InvariantCultureIgnoreCase)) { var message = $"Invalid time stamp detail request. Detail requested by '{requestedUserId}' which belong to '{timestamp.UserId}' for identifier '{timestamp.Id}'"; _logger.Warning(message); throw new TimestampException(message); } return(timestamp); }
private async Task <bool> HasTransactionMinned(string timestampId, string transactionId, bool isPremiumPlan, CancellationToken cancellationToken) { Guard.Argument(timestampId, nameof(timestampId)).NotNull().NotEmpty().NotWhiteSpace(); Guard.Argument(transactionId, nameof(transactionId)).NotNull().NotEmpty().NotWhiteSpace(); IWeb3 web3 = null; if (isPremiumPlan) { var premiumAccount = new ManagedAccount(_settings.NetheriumPremiumAccountFromAddress, string.Empty); web3 = new Web3(premiumAccount, _settings.NetheriumAccountNodeEndpoint); } else { var basicAccount = new ManagedAccount(_settings.NetheriumBasicAccountFromAddress, string.Empty); web3 = new Web3(basicAccount, _settings.NetheriumAccountNodeEndpoint); } _logger.Information($"Checking ETH transaction with transactionId '{transactionId}' for timestampId '{timestampId}' on '{web3.TransactionManager.Account.Address}'."); var receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionId); if (receipt == null || receipt.BlockNumber.Value < 0) { _logger.Information($"ETH transaction with transactionId '{transactionId}' still pending."); return(false); } _logger.Information($"ETH transaction with transactionId '{transactionId}' succeeded."); var timestamp = await _timestampRepository.GetTimestampById(timestampId, cancellationToken); if (timestamp.Status != TimestampState.Pending) { _logger.Warning($"It is not ideal work-flow. Investigate with time stamp identifier '{timestamp.Id}' and transaction identifier '{timestamp.TransactionId}'"); } else { timestamp.BlockNumber = (long)receipt.BlockNumber.Value; timestamp.Status = TimestampState.Succeeded; timestamp.Timestamp = DateTime.UtcNow; _logger.Information($"Transaction successful for an user '{timestamp.UserId}' with transaction identifier '{timestamp.TransactionId}'."); await _timestampRepository.UpdateTimestamp(timestamp, cancellationToken); } return(true); }