Search in sources :

Example 1 with UnresolvedMosaic

use of io.nem.symbol.sdk.openapi.vertx.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);
}
Also used : ArrayList(java.util.ArrayList) UnresolvedMosaic(io.nem.symbol.sdk.openapi.vertx.model.UnresolvedMosaic)

Example 2 with UnresolvedMosaic

use of io.nem.symbol.sdk.openapi.vertx.model.UnresolvedMosaic in project nem2-sdk-java by nemtech.

the class TransactionMapperVertxTest 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());
    }
}
Also used : UnresolvedMosaic(io.nem.symbol.sdk.openapi.vertx.model.UnresolvedMosaic) TransferTransactionDTO(io.nem.symbol.sdk.openapi.vertx.model.TransferTransactionDTO)

Aggregations

UnresolvedMosaic (io.nem.symbol.sdk.openapi.vertx.model.UnresolvedMosaic)2 TransferTransactionDTO (io.nem.symbol.sdk.openapi.vertx.model.TransferTransactionDTO)1 ArrayList (java.util.ArrayList)1