use of io.nem.symbol.sdk.model.network.NetworkType in project nem2-sdk-java by nemtech.
the class MetadataTransactionServiceImpl method processMetadata.
/**
* Generic way of processing a metadata entity and creating a new metadata transaction factory
* depending on the existing metadata value. This works for Account, Mosaic and Namespace
* metadata.
*
* @param criteria the criteria
* @param transactionFactory the function that creates a transaction factory
* @param newValue the new value you want to set.
* @param <T> the type of the transaction factory.
* @return an Observable of a transaction factory.
*/
private <T extends MetadataTransactionFactory> Observable<T> processMetadata(MetadataSearchCriteria criteria, TriFunction<byte[], NetworkType, Deadline, T> transactionFactory, String newValue) {
return Observable.combineLatest(networkTypeObservable, epochAdjustmentObservable, (networkType, epochAdjustment) -> metadataRepository.search(criteria).map(page -> {
Deadline deadline = Deadline.create(epochAdjustment);
if (page.getData().isEmpty()) {
return transactionFactory.apply(StringEncoder.getBytes(newValue), networkType, deadline);
} else {
byte[] originalValue = page.getData().get(0).getValue();
byte[] newValueBytes = StringEncoder.getBytes(newValue);
byte[] xoredBytes = ConvertUtils.xor(originalValue, newValueBytes);
T factory = transactionFactory.apply(xoredBytes, networkType, deadline);
factory.valueSizeDelta(newValueBytes.length - originalValue.length);
return factory;
}
})).flatMap(f -> f);
}
use of io.nem.symbol.sdk.model.network.NetworkType in project nem2-sdk-java by nemtech.
the class AccountOperationRestrictionTransactionMapper method createFactory.
@Override
protected AccountOperationRestrictionTransactionFactory createFactory(NetworkType networkType, Deadline deadline, AccountOperationRestrictionTransactionDTO transaction) {
AccountOperationRestrictionFlags restrictionFlags = AccountOperationRestrictionFlags.rawValueOf(transaction.getRestrictionFlags().getValue());
List<TransactionType> additions = transaction.getRestrictionAdditions().stream().map(transactionTypeEnum -> TransactionType.rawValueOf(transactionTypeEnum.getValue())).collect(Collectors.toList());
List<TransactionType> deletions = transaction.getRestrictionDeletions().stream().map(transactionTypeEnum -> TransactionType.rawValueOf(transactionTypeEnum.getValue())).collect(Collectors.toList());
return AccountOperationRestrictionTransactionFactory.create(networkType, deadline, restrictionFlags, additions, deletions);
}
use of io.nem.symbol.sdk.model.network.NetworkType in project nem2-sdk-java by nemtech.
the class Config method loadNemesisAccountsFromBootstrap.
private static List<Account> loadNemesisAccountsFromBootstrap(NetworkType networkType, File generatedAddresses) {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
try {
if (!generatedAddresses.exists()) {
System.out.println("Generated addresses could not be found in " + generatedAddresses.getAbsolutePath() + " Nemesis address must bue added manually");
return Collections.emptyList();
}
List<Map<String, String>> bootstrapAddresses;
List<Map<String, List<Map<String, String>>>> mosaics = (List<Map<String, List<Map<String, String>>>>) mapper.readValue(generatedAddresses, Map.class).get("mosaics");
bootstrapAddresses = mosaics.get(0).get("accounts");
return bootstrapAddresses.stream().map(m -> Account.createFromPrivateKey(m.get("privateKey"), networkType)).collect(Collectors.toList());
} catch (Exception e) {
throw new IllegalStateException("Nemesis account could not be loaded from Bootstrap: " + ExceptionUtils.getMessage(e), e);
}
}
use of io.nem.symbol.sdk.model.network.NetworkType in project nem2-sdk-java by nemtech.
the class NetworkRepositoryVertxImplTest method shouldGetNetworkType.
@Test
void shouldGetNetworkType() throws Exception {
NodeInfoDTO dto = new NodeInfoDTO();
dto.setNetworkIdentifier(NetworkType.MIJIN_TEST.getValue());
mockRemoteCall(dto);
NetworkType info = repository.getNetworkType().toFuture().get();
Assertions.assertNotNull(info);
Assertions.assertEquals(NetworkType.MIJIN_TEST, info);
}
use of io.nem.symbol.sdk.model.network.NetworkType in project nem2-sdk-java by nemtech.
the class AccountOperationRestrictionTransactionMapper method createFactory.
@Override
protected AccountOperationRestrictionTransactionFactory createFactory(NetworkType networkType, Deadline deadline, AccountOperationRestrictionTransactionDTO transaction) {
AccountOperationRestrictionFlags restrictionFlags = AccountOperationRestrictionFlags.rawValueOf(transaction.getRestrictionFlags().getValue());
List<TransactionType> additions = transaction.getRestrictionAdditions().stream().map(transactionTypeEnum -> TransactionType.rawValueOf(transactionTypeEnum.getValue())).collect(Collectors.toList());
List<TransactionType> deletions = transaction.getRestrictionDeletions().stream().map(transactionTypeEnum -> TransactionType.rawValueOf(transactionTypeEnum.getValue())).collect(Collectors.toList());
return AccountOperationRestrictionTransactionFactory.create(networkType, deadline, restrictionFlags, additions, deletions);
}
Aggregations