use of io.nem.symbol.sdk.model.blockchain.BlockInfo in project nem2-sdk-java by nemtech.
the class BlockRepositoryOkHttpImpl method toBlockInfo.
public static BlockInfo toBlockInfo(BlockInfoDTO blockInfoDTO, JsonHelper jsonHelper) {
ImportanceBlockDTO block = jsonHelper.convert(blockInfoDTO.getBlock(), ImportanceBlockDTO.class);
NetworkType networkType = NetworkType.rawValueOf(block.getNetwork().getValue());
BlockType type = BlockType.rawValueOf(block.getType());
// Remove before public net release
if (type == BlockType.NORMAL_BLOCK || block.getVotingEligibleAccountsCount() == null)
return new BlockInfo(blockInfoDTO.getId(), block.getSize(), blockInfoDTO.getMeta().getHash(), blockInfoDTO.getMeta().getGenerationHash(), blockInfoDTO.getMeta().getTotalFee(), blockInfoDTO.getMeta().getStateHashSubCacheMerkleRoots(), blockInfoDTO.getMeta().getTransactionsCount(), blockInfoDTO.getMeta().getTotalTransactionsCount(), blockInfoDTO.getMeta().getStatementsCount(), blockInfoDTO.getMeta().getStateHashSubCacheMerkleRoots(), block.getSignature(), PublicAccount.createFromPublicKey(block.getSignerPublicKey(), networkType), networkType, block.getVersion(), type, block.getHeight(), block.getTimestamp(), block.getDifficulty(), block.getFeeMultiplier(), block.getPreviousBlockHash(), block.getTransactionsHash(), block.getReceiptsHash(), block.getStateHash(), block.getProofGamma(), block.getProofScalar(), block.getProofVerificationHash(), MapperUtils.toAddress(block.getBeneficiaryAddress()));
else {
return new ImportanceBlockInfo(blockInfoDTO.getId(), block.getSize(), blockInfoDTO.getMeta().getHash(), blockInfoDTO.getMeta().getGenerationHash(), blockInfoDTO.getMeta().getTotalFee(), blockInfoDTO.getMeta().getStateHashSubCacheMerkleRoots(), blockInfoDTO.getMeta().getTransactionsCount(), blockInfoDTO.getMeta().getTotalTransactionsCount(), blockInfoDTO.getMeta().getStatementsCount(), blockInfoDTO.getMeta().getStateHashSubCacheMerkleRoots(), block.getSignature(), PublicAccount.createFromPublicKey(block.getSignerPublicKey(), networkType), networkType, block.getVersion(), type, block.getHeight(), block.getTimestamp(), block.getDifficulty(), block.getFeeMultiplier(), block.getPreviousBlockHash(), block.getTransactionsHash(), block.getReceiptsHash(), block.getStateHash(), block.getProofGamma(), block.getProofScalar(), block.getProofVerificationHash(), MapperUtils.toAddress(block.getBeneficiaryAddress()), block.getVotingEligibleAccountsCount(), block.getHarvestingEligibleAccountsCount(), block.getTotalVotingBalance(), block.getPreviousImportanceBlockHash());
}
}
use of io.nem.symbol.sdk.model.blockchain.BlockInfo in project nem2-sdk-java by nemtech.
the class BlockRepositoryVertxImpl method toBlockInfo.
public static BlockInfo toBlockInfo(BlockInfoDTO blockInfoDTO, JsonHelper jsonHelper) {
ImportanceBlockDTO block = jsonHelper.convert(blockInfoDTO.getBlock(), ImportanceBlockDTO.class);
NetworkType networkType = NetworkType.rawValueOf(block.getNetwork().getValue());
BlockType type = BlockType.rawValueOf(block.getType());
// Remove before public net release
if (type == BlockType.NORMAL_BLOCK || block.getVotingEligibleAccountsCount() == null)
return new BlockInfo(blockInfoDTO.getId(), block.getSize(), blockInfoDTO.getMeta().getHash(), blockInfoDTO.getMeta().getGenerationHash(), blockInfoDTO.getMeta().getTotalFee(), blockInfoDTO.getMeta().getStateHashSubCacheMerkleRoots(), blockInfoDTO.getMeta().getTransactionsCount(), blockInfoDTO.getMeta().getTotalTransactionsCount(), blockInfoDTO.getMeta().getStatementsCount(), blockInfoDTO.getMeta().getStateHashSubCacheMerkleRoots(), block.getSignature(), PublicAccount.createFromPublicKey(block.getSignerPublicKey(), networkType), networkType, block.getVersion(), type, block.getHeight(), block.getTimestamp(), block.getDifficulty(), block.getFeeMultiplier(), block.getPreviousBlockHash(), block.getTransactionsHash(), block.getReceiptsHash(), block.getStateHash(), block.getProofGamma(), block.getProofScalar(), block.getProofVerificationHash(), MapperUtils.toAddress(block.getBeneficiaryAddress()));
else {
return new ImportanceBlockInfo(blockInfoDTO.getId(), block.getSize(), blockInfoDTO.getMeta().getHash(), blockInfoDTO.getMeta().getGenerationHash(), blockInfoDTO.getMeta().getTotalFee(), blockInfoDTO.getMeta().getStateHashSubCacheMerkleRoots(), blockInfoDTO.getMeta().getTransactionsCount(), blockInfoDTO.getMeta().getTotalTransactionsCount(), blockInfoDTO.getMeta().getStatementsCount(), blockInfoDTO.getMeta().getStateHashSubCacheMerkleRoots(), block.getSignature(), PublicAccount.createFromPublicKey(block.getSignerPublicKey(), networkType), networkType, block.getVersion(), type, block.getHeight(), block.getTimestamp(), block.getDifficulty(), block.getFeeMultiplier(), block.getPreviousBlockHash(), block.getTransactionsHash(), block.getReceiptsHash(), block.getStateHash(), block.getProofGamma(), block.getProofScalar(), block.getProofVerificationHash(), MapperUtils.toAddress(block.getBeneficiaryAddress()), block.getVotingEligibleAccountsCount(), block.getHarvestingEligibleAccountsCount(), block.getTotalVotingBalance(), block.getPreviousImportanceBlockHash());
}
}
use of io.nem.symbol.sdk.model.blockchain.BlockInfo in project nem2-sdk-java by nemtech.
the class BlockRepositoryIntegrationTest method searchOrderByHeightAsc.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchOrderByHeightAsc(RepositoryType type) {
BlockSearchCriteria criteria = new BlockSearchCriteria();
criteria.setOrderBy(BlockOrderBy.HEIGHT);
criteria.setOrder(OrderBy.ASC);
BlockPaginationStreamer streamer = new BlockPaginationStreamer(getBlockRepository(type));
List<BlockInfo> blocks = get(streamer.search(criteria).toList().toObservable());
List<BlockInfo> sorted = blocks.stream().sorted(Comparator.comparing(BlockInfo::getHeight)).collect(Collectors.toList());
Assertions.assertEquals(blocks, sorted);
}
use of io.nem.symbol.sdk.model.blockchain.BlockInfo in project nem2-sdk-java by nemtech.
the class BlockRepositoryIntegrationTest method searchByBeneficiaryAddressWhenInvalid.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchByBeneficiaryAddressWhenInvalid(RepositoryType type) {
BlockRepository blockRepository = getBlockRepository(type);
BlockSearchCriteria criteria = new BlockSearchCriteria();
Address expectedBeneficiaryAddress = Account.generateNewAccount(getNetworkType()).getAddress();
criteria.setBeneficiaryAddress(expectedBeneficiaryAddress);
BlockPaginationStreamer streamer = new BlockPaginationStreamer(blockRepository);
List<BlockInfo> blocks = get(streamer.search(criteria).toList().toObservable());
Assertions.assertTrue(blocks.isEmpty());
}
use of io.nem.symbol.sdk.model.blockchain.BlockInfo in project nem2-sdk-java by nemtech.
the class BlockRepositoryIntegrationTest method searchBySignerPublicKeyWhenInvalid.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void searchBySignerPublicKeyWhenInvalid(RepositoryType type) {
BlockRepository blockRepository = getBlockRepository(type);
BlockSearchCriteria criteria = new BlockSearchCriteria();
PublicKey expectedSignerPublicKey = PublicKey.generateRandom();
criteria.setSignerPublicKey(expectedSignerPublicKey);
BlockPaginationStreamer streamer = new BlockPaginationStreamer(blockRepository);
List<BlockInfo> blocks = get(streamer.search(criteria).toList().toObservable());
Assertions.assertTrue(blocks.isEmpty());
}
Aggregations