/// <summary> /// Get the current status of a transaction /// </summary> /// <param name="transactionId">transaction id</param> /// <returns></returns> public async Task <TransactionResultDto> GetTransactionResultAsync(string transactionId) { Hash transactionIdHash; try { transactionIdHash = Hash.LoadFromHex(transactionId); } catch { throw new UserFriendlyException(Error.Message[Error.InvalidTransactionId], Error.InvalidTransactionId.ToString()); } var transactionResult = await GetTransactionResultAsync(transactionIdHash); var output = _objectMapper.GetMapper() .Map <TransactionResult, TransactionResultDto>(transactionResult, opt => opt.Items[TransactionProfile.ErrorTrace] = _webAppOptions.IsDebugMode); var transaction = await _transactionManager.GetTransactionAsync(transactionResult.TransactionId); output.Transaction = _objectMapper.Map <Transaction, TransactionDto>(transaction); output.TransactionSize = transaction?.CalculateSize() ?? 0; if (transactionResult.Status == TransactionResultStatus.NotExisted) { var validationStatus = _transactionResultStatusCacheProvider.GetTransactionResultStatus(transactionIdHash); if (validationStatus != null) { output.Status = validationStatus.TransactionResultStatus.ToString().ToUpper(); output.Error = TransactionErrorResolver.TakeErrorMessage(validationStatus.Error, _webAppOptions.IsDebugMode); } return(output); } var methodDescriptor = await GetContractMethodDescriptorAsync(transaction.To, transaction.MethodName, false); if (methodDescriptor != null) { var parameters = methodDescriptor.InputType.Parser.ParseFrom(transaction.Params); if (!IsValidMessage(parameters)) { throw new UserFriendlyException(Error.Message[Error.InvalidParams], Error.InvalidParams.ToString()); } output.Transaction.Params = JsonFormatter.ToDiagnosticString(parameters); } return(output); }
/// <summary> /// Get peer info about the connected network nodes /// </summary> /// <returns></returns> public List <PeerDto> GetPeers(bool withMetrics = false) { var peerList = _networkService.GetPeers(); return(_objectMapper.GetMapper().Map <List <PeerInfo>, List <PeerDto> >(peerList, opt => opt.Items[PeerInfoProfile.WithMetrics] = withMetrics)); }
private BlockDto CreateBlockDto(Block block, bool includeTransactions) { if (block == null) { throw new UserFriendlyException(Error.Message[Error.NotFound], Error.NotFound.ToString()); } return(_objectMapper.GetMapper().Map <Block, BlockDto>(block, opt => opt.Items[BlockProfile.IncludeTransactions] = includeTransactions)); }
public void Should_Get_Internal_Mapper() { _objectMapper.GetMapper().ShouldNotBeNull(); _objectMapper.AutoObjectMappingProvider.GetMapper().ShouldNotBeNull(); }