use of io.nem.symbol.catapult.builders.CosignatureBuilder 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