use of io.nem.symbol.catapult.builders.SignatureDto 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.SignatureDto in project nem2-sdk-java by nemtech.
the class AggregateTransaction method signTransactionGivenSignatures.
/**
* Sign transaction with cosignatures creating a new SignedTransaction.
*
* @param initiatorAccount Initiator account
* @param cosignatures The list of precreated cosignatures.
* @param generationHash the block 1 generation hash used to sign.
* @return {@link SignedTransaction}
*/
public SignedTransaction signTransactionGivenSignatures(final Account initiatorAccount, final List<? extends AggregateTransactionCosignature> cosignatures, final String generationHash) {
SignedTransaction signedTransaction = this.signWith(initiatorAccount, generationHash);
StringBuilder payload = new StringBuilder(signedTransaction.getPayload());
for (AggregateTransactionCosignature cosignatory : cosignatures) {
SignatureDto signature = SerializationUtils.toSignatureDto(cosignatory.getSignature());
CosignatureBuilder builder = CosignatureBuilder.create(cosignatory.getVersion().longValue(), SerializationUtils.toKeyDto(cosignatory.getSigner().getPublicKey()), signature);
payload.append(ConvertUtils.toHex(builder.serialize()));
}
byte[] payloadBytes = ConvertUtils.fromHexToBytes(payload.toString());
byte[] size = BigInteger.valueOf(payloadBytes.length).toByteArray();
ArrayUtils.reverse(size);
System.arraycopy(size, 0, payloadBytes, 0, size.length);
return new SignedTransaction(initiatorAccount.getPublicAccount(), ConvertUtils.toHex(payloadBytes), signedTransaction.getHash(), getType());
}
Aggregations