use of io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction in project nem2-sdk-java by nemtech.
the class Account method signCosignatureTransaction.
/**
* Creates a CosignatureSignedTransaction from a hash.
*
* @param transactionHash The transaction hash
* @return {@link CosignatureSignedTransaction}
*/
public CosignatureSignedTransaction signCosignatureTransaction(String transactionHash) {
DsaSigner signer = CryptoEngines.defaultEngine().createDsaSigner(this.getKeyPair());
byte[] bytes = ConvertUtils.fromHexToBytes(transactionHash);
byte[] signatureBytes = signer.sign(bytes).getBytes();
return new CosignatureSignedTransaction(AggregateTransactionCosignature.DEFAULT_VERSION, transactionHash, ConvertUtils.toHex(signatureBytes), this.getPublicAccount());
}
use of io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction in project nem2-sdk-java by nemtech.
the class MultisignIntegrationTest method shouldReturnCosignatureAddedViaListener2.
@Disabled
@ParameterizedTest
@EnumSource(RepositoryType.class)
void shouldReturnCosignatureAddedViaListener2(RepositoryType type) {
Listener listener = getListener(type);
RepositoryFactory repositoryFactory = getRepositoryFactory(type);
TransactionRepository transactionRepository = repositoryFactory.createTransactionRepository();
SignedTransaction signedAggregatedTx = createSignedAggregatedBondTransaction(multisigAccount, cosignAccount1, account2.getAddress());
Object finalObject = get(createHashLockTransactionAndAnnounce(type, signedAggregatedTx, cosignAccount1).flatMap(t -> {
System.out.println("hash lock finished");
TransactionServiceImpl transactionService = new TransactionServiceImpl(getRepositoryFactory(type));
return transactionService.announceAggregateBonded(listener, signedAggregatedTx).flatMap(a -> {
System.out.println("Aggregate bonded finished");
return repositoryFactory.createTransactionRepository().search(new TransactionSearchCriteria(TransactionGroup.PARTIAL).signerPublicKey(cosignAccount1.getPublicAccount().getPublicKey())).flatMap((page) -> {
List<Transaction> transactions = page.getData();
System.out.println("partialTransactions " + transactions.size());
AggregateTransaction transactionToCosign = (AggregateTransaction) transactions.get(0);
CosignatureTransaction cosignatureTransaction = CosignatureTransaction.create(transactionToCosign);
CosignatureSignedTransaction cosignatureSignedTransaction = cosignAccount2.signCosignatureTransaction(cosignatureTransaction);
return transactionRepository.announceAggregateBondedCosignature(cosignatureSignedTransaction).flatMap(r -> {
System.out.println("announceAggregateBondedCosignature " + r);
return listener.cosignatureAdded(cosignAccount1.getAddress());
});
});
});
}));
System.out.println(finalObject.getClass());
Assertions.assertNull(finalObject);
}
use of io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction in project nem2-sdk-java by nemtech.
the class ListenerVertxTest method cosignatureAdded.
@Test
public void cosignatureAdded() throws InterruptedException, ExecutionException, TimeoutException {
simulateWebSocketStartup();
ListenerChannel consignature = ListenerChannel.COSIGNATURE;
NetworkType networkType = NETWORK_TYPE;
Cosignature cosignature = new Cosignature().parentHash("aParentHash").signature("aSignature").version(BigInteger.ONE).signerPublicKey(Account.generateNewAccount(networkType).getPublicKey());
ObjectNode transactionInfoDtoJsonObject = jsonHelper.convert(cosignature, ObjectNode.class);
Address address = Address.createFromPublicKey(cosignature.getSignerPublicKey(), networkType);
String channelName = consignature.toString();
List<CosignatureSignedTransaction> transactions = new ArrayList<>();
listener.cosignatureAdded(address).forEach(transactions::add);
handle(transactionInfoDtoJsonObject, consignature.toString() + "/" + address.plain());
Assertions.assertEquals(1, transactions.size());
Assertions.assertEquals(cosignature.getSignerPublicKey(), transactions.get(0).getSigner().getPublicKey().toHex());
Assertions.assertEquals(cosignature.getParentHash(), transactions.get(0).getParentHash());
Assertions.assertEquals(cosignature.getSignature(), transactions.get(0).getSignature());
Mockito.verify(webSocketMock).handler(Mockito.any());
Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + address.plain())));
}
use of io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction in project nem2-sdk-java by nemtech.
the class TransactionRepositoryVertxImplTest method announceAggregateBondedCosignature.
@Test
public void announceAggregateBondedCosignature() throws Exception {
Account signer = Account.generateNewAccount(networkType);
BigInteger version = AggregateTransactionCosignature.DEFAULT_VERSION;
CosignatureSignedTransaction signedTransaction = new CosignatureSignedTransaction(version, "aParentHash", "aSignature", signer.getPublicAccount());
AnnounceTransactionInfoDTO announceTransactionInfoDTO = new AnnounceTransactionInfoDTO();
announceTransactionInfoDTO.setMessage("SomeMessage");
ArgumentCaptor<Object> parameter = mockRemoteCall(announceTransactionInfoDTO);
TransactionAnnounceResponse response = repository.announceAggregateBondedCosignature(signedTransaction).toFuture().get();
Assertions.assertNotNull(response);
Assertions.assertEquals(announceTransactionInfoDTO.getMessage(), announceTransactionInfoDTO.getMessage());
Cosignature cosignature = (Cosignature) parameter.getValue();
Assertions.assertEquals(signedTransaction.getParentHash(), cosignature.getParentHash());
Assertions.assertEquals(signedTransaction.getSignature(), cosignature.getSignature());
Assertions.assertEquals(signedTransaction.getSigner().getPublicKey().toHex(), cosignature.getSignerPublicKey());
Assertions.assertEquals(signedTransaction.getVersion(), cosignature.getVersion());
}
use of io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction in project nem2-sdk-java by nemtech.
the class OkHttpCosignatureTransactionTest method createACosignatureTransactionViaConstructor.
@Test
void createACosignatureTransactionViaConstructor() {
TransactionInfoDTO transactionInfoDTO = TestHelperOkHttp.loadTransactionInfoDTO("cosignatureTransactionViaConstructor.json");
AggregateTransaction aggregateTransaction = (AggregateTransaction) new GeneralTransactionMapper(jsonHelper).mapFromDto(transactionInfoDTO);
CosignatureTransaction cosignatureTransaction = CosignatureTransaction.create(aggregateTransaction);
CosignatureSignedTransaction cosignatureSignedTransaction = account.signCosignatureTransaction(cosignatureTransaction);
assertTrue(aggregateTransaction.getTransactionInfo().get().getHash().isPresent());
assertEquals(aggregateTransaction.getTransactionInfo().get().getHash().get(), cosignatureSignedTransaction.getParentHash());
assertEquals("5EA75D1A2C8AD25DA4F400C1BD2DA84449FAF583AFD813E1179E72AF0CDF5AC1C0F7404AF6FC7268EE416204240DD3D5B11420D80215F19AA314FC86D6E03E0D", cosignatureSignedTransaction.getSignature());
assertEquals("671653C94E2254F2A23EFEDB15D67C38332AED1FBD24B063C0A8E675582B6A96", cosignatureTransaction.getTransactionToCosign().getTransactionInfo().get().getHash().get());
}
Aggregations