| | 1 | | using EF.Blockchain.Domain; |
| | 2 | | using EF.Blockchain.Server.Dtos; |
| | 3 | |
|
| | 4 | | namespace EF.Blockchain.Server.Mappers; |
| | 5 | |
|
| | 6 | | public static class TransactionMapper |
| | 7 | | { |
| | 8 | | public static Transaction ToDomain(TransactionDto dto) |
| 24 | 9 | | { |
| 24 | 10 | | if (dto == null) |
| 0 | 11 | | return null; |
| | 12 | |
|
| 24 | 13 | | var txInputs = dto.TxInputs? |
| 24 | 14 | | .Select(TransactionInputMapper.ToDomain) |
| 24 | 15 | | .ToList() ?? new List<TransactionInput>(); |
| | 16 | |
|
| 24 | 17 | | var txOutputs = dto.TxOutputs? |
| 24 | 18 | | .Select(TransactionOutputMapper.ToDomain) |
| 24 | 19 | | .ToList() ?? new List<TransactionOutput>(); |
| | 20 | |
|
| 24 | 21 | | return new Transaction( |
| 24 | 22 | | type: dto.Type, |
| 24 | 23 | | timestamp: dto.Timestamp, |
| 24 | 24 | | txInputs: txInputs, |
| 24 | 25 | | txOutputs: txOutputs); |
| 24 | 26 | | } |
| | 27 | |
|
| | 28 | | public static TransactionDto ToDto(Transaction domain) |
| 72 | 29 | | { |
| 72 | 30 | | if (domain == null) |
| 0 | 31 | | return null; |
| | 32 | |
|
| 72 | 33 | | var txInputs = domain.TxInputs? |
| 72 | 34 | | .Select(TransactionInputMapper.ToDto) |
| 72 | 35 | | .ToList() ?? new List<TransactionInputDto>(); |
| | 36 | |
|
| 72 | 37 | | var txOutputs = domain.TxOutputs? |
| 72 | 38 | | .Select(TransactionOutputMapper.ToDto) |
| 72 | 39 | | .ToList() ?? new List<TransactionOutputDto>(); |
| | 40 | |
|
| 72 | 41 | | return new TransactionDto |
| 72 | 42 | | { |
| 72 | 43 | | Type = domain.Type, |
| 72 | 44 | | Timestamp = domain.Timestamp, |
| 72 | 45 | | Hash = domain.Hash, |
| 72 | 46 | | TxInputs = txInputs, |
| 72 | 47 | | TxOutputs = txOutputs |
| 72 | 48 | | }; |
| 72 | 49 | | } |
| | 50 | | } |