Search in sources :

Example 1 with BlockInfo

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());
    }
}
Also used : BlockType(io.nem.symbol.sdk.model.blockchain.BlockType) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) BlockInfo(io.nem.symbol.sdk.model.blockchain.BlockInfo) ImportanceBlockInfo(io.nem.symbol.sdk.model.blockchain.ImportanceBlockInfo) ImportanceBlockDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.ImportanceBlockDTO) ImportanceBlockInfo(io.nem.symbol.sdk.model.blockchain.ImportanceBlockInfo)

Example 2 with BlockInfo

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());
    }
}
Also used : BlockType(io.nem.symbol.sdk.model.blockchain.BlockType) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) BlockInfo(io.nem.symbol.sdk.model.blockchain.BlockInfo) ImportanceBlockInfo(io.nem.symbol.sdk.model.blockchain.ImportanceBlockInfo) ImportanceBlockDTO(io.nem.symbol.sdk.openapi.vertx.model.ImportanceBlockDTO) ImportanceBlockInfo(io.nem.symbol.sdk.model.blockchain.ImportanceBlockInfo)

Example 3 with BlockInfo

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);
}
Also used : BlockSearchCriteria(io.nem.symbol.sdk.api.BlockSearchCriteria) BlockInfo(io.nem.symbol.sdk.model.blockchain.BlockInfo) BlockPaginationStreamer(io.nem.symbol.sdk.api.BlockPaginationStreamer) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with BlockInfo

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());
}
Also used : BlockRepository(io.nem.symbol.sdk.api.BlockRepository) BlockSearchCriteria(io.nem.symbol.sdk.api.BlockSearchCriteria) Address(io.nem.symbol.sdk.model.account.Address) BlockInfo(io.nem.symbol.sdk.model.blockchain.BlockInfo) BlockPaginationStreamer(io.nem.symbol.sdk.api.BlockPaginationStreamer) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with BlockInfo

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());
}
Also used : BlockRepository(io.nem.symbol.sdk.api.BlockRepository) BlockSearchCriteria(io.nem.symbol.sdk.api.BlockSearchCriteria) PublicKey(io.nem.symbol.core.crypto.PublicKey) BlockInfo(io.nem.symbol.sdk.model.blockchain.BlockInfo) BlockPaginationStreamer(io.nem.symbol.sdk.api.BlockPaginationStreamer) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

BlockInfo (io.nem.symbol.sdk.model.blockchain.BlockInfo)24 Test (org.junit.jupiter.api.Test)13 BigInteger (java.math.BigInteger)11 BlockSearchCriteria (io.nem.symbol.sdk.api.BlockSearchCriteria)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 EnumSource (org.junit.jupiter.params.provider.EnumSource)9 MerklePathItem (io.nem.symbol.sdk.model.blockchain.MerklePathItem)8 MerkleProofInfo (io.nem.symbol.sdk.model.blockchain.MerkleProofInfo)8 ArrayList (java.util.ArrayList)8 BlockPaginationStreamer (io.nem.symbol.sdk.api.BlockPaginationStreamer)7 Address (io.nem.symbol.sdk.model.account.Address)6 ImportanceBlockInfo (io.nem.symbol.sdk.model.blockchain.ImportanceBlockInfo)6 BlockRepository (io.nem.symbol.sdk.api.BlockRepository)5 ImportanceBlockDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.ImportanceBlockDTO)3 ImportanceBlockDTO (io.nem.symbol.sdk.openapi.vertx.model.ImportanceBlockDTO)3 PublicKey (io.nem.symbol.core.crypto.PublicKey)2 BlockType (io.nem.symbol.sdk.model.blockchain.BlockType)2 NetworkType (io.nem.symbol.sdk.model.network.NetworkType)2 BlockDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.BlockDTO)2 BlockInfoDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.BlockInfoDTO)2