use of io.nem.symbol.sdk.openapi.okhttp_gson.model.UnresolvedMosaic in project nem2-sdk-java by nemtech.
the class TransactionMapperOkHttpTest method validateTransferTx.
void validateTransferTx(TransferTransaction transaction, TransactionInfoDTO transactionDTO) {
TransferTransactionDTO transferTransaction = jsonHelper.convert(transactionDTO.getTransaction(), TransferTransactionDTO.class);
assertEquals(MapperUtils.toUnresolvedAddress(transferTransaction.getRecipientAddress()), transaction.getRecipient());
List<UnresolvedMosaic> mosaicsDTO = transferTransaction.getMosaics();
if (mosaicsDTO != null && mosaicsDTO.size() > 0) {
assertEquals(MapperUtils.fromHexToBigInteger(mosaicsDTO.get(0).getId()), transaction.getMosaics().get(0).getId().getId());
assertEquals(mosaicsDTO.get(0).getAmount(), transaction.getMosaics().get(0).getAmount());
}
if (StringUtils.isEmpty(transferTransaction.getMessage())) {
assertFalse(transaction.getMessage().isPresent());
} else if (transaction.getMessage().get().getText().isEmpty()) {
assertEquals("", transaction.getMessage().get().getText());
} else {
assertEquals(new String(ConvertUtils.fromHexToBytes(transferTransaction.getMessage().substring(2)), StandardCharsets.UTF_8), transaction.getMessage().get().getText());
}
}
use of io.nem.symbol.sdk.openapi.okhttp_gson.model.UnresolvedMosaic in project nem2-sdk-java by nemtech.
the class TransferTransactionMapper method copyToDto.
@Override
protected void copyToDto(TransferTransaction transaction, TransferTransactionDTO dto) {
List<UnresolvedMosaic> mosaics = new ArrayList<>();
if (transaction.getMosaics() != null) {
mosaics = transaction.getMosaics().stream().map(mosaic -> {
UnresolvedMosaic mosaicDto = new UnresolvedMosaic();
mosaicDto.setAmount(mosaic.getAmount());
mosaicDto.setId(MapperUtils.getIdAsHex(mosaic.getId()));
return mosaicDto;
}).collect(Collectors.toList());
}
String message = transaction.getMessage().map(Message::getPayloadHex).orElse(null);
dto.setRecipientAddress(transaction.getRecipient().encoded(transaction.getNetworkType()));
dto.setMosaics(mosaics);
dto.setMessage(message);
}
Aggregations