use of io.nem.symbol.catapult.builders.KeyDto in project nem2-sdk-java by nemtech.
the class BinarySerializationImpl method getTransactionBuilder.
/**
* Gets the top level {@link TransactionBuilder} for the given transaction
*
* @param transaction the transaction
* @return the top level {@link TransactionBuilder}
*/
private TransactionBuilder getTransactionBuilder(Transaction transaction) {
final SignatureDto signatureDto = transaction.getSignature().map(SerializationUtils::toSignatureDto).orElseGet(() -> new SignatureDto(ByteBuffer.allocate(64)));
final ByteBuffer signerBuffer = transaction.getSigner().map(SerializationUtils::toByteBuffer).orElseGet(() -> ByteBuffer.allocate(32));
int networkTypeValue = transaction.getNetworkType().getValue();
int typeValue = transaction.getType().getValue();
byte version = transaction.getVersion().byteValue();
return TransactionBuilder.create(signatureDto, new KeyDto(signerBuffer), version, NetworkTypeDto.rawValueOf((byte) networkTypeValue), EntityTypeDto.rawValueOf((short) typeValue), SerializationUtils.toAmount(transaction.getMaxFee()), new TimestampDto(transaction.getDeadline().getValue()));
}
use of io.nem.symbol.catapult.builders.KeyDto in project nem2-sdk-java by nemtech.
the class AccountInfo method serialize.
public byte[] serialize() {
AddressDto address = SerializationUtils.toAddressDto(getAddress());
HeightDto addressHeight = new HeightDto(getAddressHeight().longValue());
KeyDto publicKey = SerializationUtils.toKeyDto(getPublicKey());
HeightDto publicKeyHeight = new HeightDto(getPublicKeyHeight().longValue());
AccountTypeDto accountType = AccountTypeDto.rawValueOf((byte) getAccountType().getValue());
EnumSet<AccountKeyTypeFlagsDto> supplementalPublicKeysMask = getAccountKeyTypeFlags();
KeyDto linkedPublicKey = getSupplementalAccountKeys().getLinked().map(SerializationUtils::toKeyDto).orElse(null);
KeyDto nodePublicKey = getSupplementalAccountKeys().getNode().map(SerializationUtils::toKeyDto).orElse(null);
KeyDto vrfPublicKey = getSupplementalAccountKeys().getVrf().map(SerializationUtils::toKeyDto).orElse(null);
List<PinnedVotingKeyBuilder> votingPublicKeys = getSupplementalAccountKeys().getVoting().stream().map(this::toPinnedVotingKeyBuilder).collect(Collectors.toList());
ImportanceDto importanceValue = new ImportanceDto(getImportance().getValue().longValue());
ImportanceHeightDto importanceHeight = new ImportanceHeightDto(getImportance().getHeight().longValue());
ImportanceSnapshotBuilder importanceSnapshots = ImportanceSnapshotBuilder.create(importanceValue, importanceHeight);
HeightActivityBucketsBuilder activityBuckets = toHeightActivityBucketsBuilder();
List<MosaicBuilder> balances = SerializationUtils.toMosaicBuilders(getMosaics());
if (isHighValue()) {
return AccountStateBuilder.createHighValue((short) getVersion(), address, addressHeight, publicKey, publicKeyHeight, accountType, supplementalPublicKeysMask, linkedPublicKey, nodePublicKey, vrfPublicKey, votingPublicKeys, importanceSnapshots, activityBuckets, balances).serialize();
} else {
return AccountStateBuilder.createRegular((short) getVersion(), address, addressHeight, publicKey, publicKeyHeight, accountType, supplementalPublicKeysMask, linkedPublicKey, nodePublicKey, vrfPublicKey, votingPublicKeys, balances).serialize();
}
}
use of io.nem.symbol.catapult.builders.KeyDto in project nem2-sdk-java by nemtech.
the class BinarySerializationImpl method serializeEmbedded.
/**
* Serialized the transfer transaction to embedded bytes.
*
* @param transaction the transaction
* @param <T> the transaction class
* @return bytes of the transaction.
*/
public <T extends Transaction> byte[] serializeEmbedded(T transaction) {
Validate.notNull(transaction, "Transaction must not be null");
EmbeddedTransactionBuilder embeddedTransactionBuilder = EmbeddedTransactionBuilder.create(new KeyDto(getRequiredSignerBytes(transaction.getSigner())), transaction.getVersion().byteValue(), NetworkTypeDto.rawValueOf((byte) transaction.getNetworkType().getValue()), EntityTypeDto.rawValueOf((short) transaction.getType().getValue()));
return serializeTransaction(embeddedTransactionBuilder.serialize(), transaction);
}
Aggregations