use of io.nem.symbol.sdk.openapi.vertx.model.TransactionDTO in project nem2-sdk-java by nemtech.
the class AbstractTransactionMapper method mapTransaction.
private D mapTransaction(Transaction transaction, boolean embedded) {
TransactionDTO dto = new TransactionDTO();
dto.setSignerPublicKey(transaction.getSigner().map(PublicAccount::getPublicKey).map(PublicKey::toHex).orElse(null));
dto.setVersion(transaction.getVersion());
dto.setType(transaction.getType().getValue());
dto.setNetwork(NetworkTypeEnum.fromValue(transaction.getNetworkType().getValue()));
if (!embedded) {
dto.setSize(transaction.getSize());
dto.setMaxFee(transaction.getMaxFee());
dto.setDeadline(transaction.getDeadline().toBigInteger());
dto.setSignature(transaction.getSignature().orElse(null));
}
D specificDto = getJsonHelper().parse(getJsonHelper().print(dto), transactionDtoClass);
copyToDto((T) transaction, specificDto);
return specificDto;
}
use of io.nem.symbol.sdk.openapi.vertx.model.TransactionDTO in project nem2-sdk-java by nemtech.
the class AbstractTransactionMapper method createFactory.
protected final TransactionFactory<T> createFactory(TransactionInfo transactionInfo, Object transactionDto) {
D transaction = getJsonHelper().convert(transactionDto, transactionDtoClass);
TransactionDTO transactionDTO = getJsonHelper().convert(transactionDto, TransactionDTO.class);
NetworkType networkType = NetworkType.rawValueOf(transactionDTO.getNetwork().getValue());
Deadline deadline = transactionDTO.getDeadline() != null ? new Deadline(transactionDTO.getDeadline()) : new Deadline(BigInteger.ZERO);
TransactionFactory<T> factory = createFactory(networkType, deadline, transaction);
factory.version(transactionDTO.getVersion());
if (transactionDTO.getSignerPublicKey() != null) {
factory.signer(PublicAccount.createFromPublicKey(transactionDTO.getSignerPublicKey(), networkType));
}
if (transactionDTO.getSignature() != null) {
factory.signature(transactionDTO.getSignature());
}
if (transactionDTO.getMaxFee() != null) {
factory.maxFee(transactionDTO.getMaxFee());
}
if (transactionDTO.getSize() != null) {
factory.size(transactionDTO.getSize());
}
if (transactionInfo != null) {
factory.transactionInfo(transactionInfo);
}
if (factory.getType() != getTransactionType()) {
throw new IllegalStateException("Expected transaction to be " + getTransactionType() + " but got " + factory.getType());
}
return factory;
}
Aggregations