Search in sources :

Example 1 with KeyDto

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()));
}
Also used : VotingKeyDto(io.nem.symbol.catapult.builders.VotingKeyDto) KeyDto(io.nem.symbol.catapult.builders.KeyDto) TimestampDto(io.nem.symbol.catapult.builders.TimestampDto) SignatureDto(io.nem.symbol.catapult.builders.SignatureDto) ByteBuffer(java.nio.ByteBuffer)

Example 2 with KeyDto

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();
    }
}
Also used : VotingKeyDto(io.nem.symbol.catapult.builders.VotingKeyDto) KeyDto(io.nem.symbol.catapult.builders.KeyDto) PinnedVotingKeyBuilder(io.nem.symbol.catapult.builders.PinnedVotingKeyBuilder) AddressDto(io.nem.symbol.catapult.builders.AddressDto) AccountKeyTypeFlagsDto(io.nem.symbol.catapult.builders.AccountKeyTypeFlagsDto) ImportanceHeightDto(io.nem.symbol.catapult.builders.ImportanceHeightDto) HeightDto(io.nem.symbol.catapult.builders.HeightDto) AccountTypeDto(io.nem.symbol.catapult.builders.AccountTypeDto) ImportanceDto(io.nem.symbol.catapult.builders.ImportanceDto) ImportanceHeightDto(io.nem.symbol.catapult.builders.ImportanceHeightDto) MosaicBuilder(io.nem.symbol.catapult.builders.MosaicBuilder) ImportanceSnapshotBuilder(io.nem.symbol.catapult.builders.ImportanceSnapshotBuilder) HeightActivityBucketsBuilder(io.nem.symbol.catapult.builders.HeightActivityBucketsBuilder)

Example 3 with KeyDto

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);
}
Also used : EmbeddedTransactionBuilder(io.nem.symbol.catapult.builders.EmbeddedTransactionBuilder) VotingKeyDto(io.nem.symbol.catapult.builders.VotingKeyDto) KeyDto(io.nem.symbol.catapult.builders.KeyDto)

Aggregations

KeyDto (io.nem.symbol.catapult.builders.KeyDto)3 VotingKeyDto (io.nem.symbol.catapult.builders.VotingKeyDto)3 AccountKeyTypeFlagsDto (io.nem.symbol.catapult.builders.AccountKeyTypeFlagsDto)1 AccountTypeDto (io.nem.symbol.catapult.builders.AccountTypeDto)1 AddressDto (io.nem.symbol.catapult.builders.AddressDto)1 EmbeddedTransactionBuilder (io.nem.symbol.catapult.builders.EmbeddedTransactionBuilder)1 HeightActivityBucketsBuilder (io.nem.symbol.catapult.builders.HeightActivityBucketsBuilder)1 HeightDto (io.nem.symbol.catapult.builders.HeightDto)1 ImportanceDto (io.nem.symbol.catapult.builders.ImportanceDto)1 ImportanceHeightDto (io.nem.symbol.catapult.builders.ImportanceHeightDto)1 ImportanceSnapshotBuilder (io.nem.symbol.catapult.builders.ImportanceSnapshotBuilder)1 MosaicBuilder (io.nem.symbol.catapult.builders.MosaicBuilder)1 PinnedVotingKeyBuilder (io.nem.symbol.catapult.builders.PinnedVotingKeyBuilder)1 SignatureDto (io.nem.symbol.catapult.builders.SignatureDto)1 TimestampDto (io.nem.symbol.catapult.builders.TimestampDto)1 ByteBuffer (java.nio.ByteBuffer)1