Search in sources :

Example 11 with NetworkType

use of io.nem.symbol.sdk.model.network.NetworkType in project nem2-sdk-java by nemtech.

the class TestnetTester method readTransactions.

private static void readTransactions(RepositoryFactory repositoryFactory) throws Exception {
    String generationHash = repositoryFactory.getGenerationHash().toFuture().get();
    NetworkType networkType = repositoryFactory.getNetworkType().toFuture().get();
    List<Transaction> transactions = repositoryFactory.createTransactionRepository().streamer().search(new TransactionSearchCriteria(TransactionGroup.CONFIRMED).order(OrderBy.DESC).transactionTypes(Arrays.asList(TransactionType.VOTING_KEY_LINK))).take(50).toList().blockingGet();
    transactions.forEach(t -> {
        System.out.println(t.getVersion());
        System.out.println(t.getTransactionInfo().get().getHash().get());
        System.out.println(t.createTransactionHash(ConvertUtils.toHex(t.serialize()), ConvertUtils.fromHexToBytes(generationHash)));
    });
}
Also used : VotingKeyLinkTransaction(io.nem.symbol.sdk.model.transaction.VotingKeyLinkTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria)

Example 12 with NetworkType

use of io.nem.symbol.sdk.model.network.NetworkType in project nem2-sdk-java by nemtech.

the class TransferTransactionIntegrationTest method transferTransactionNotEnoughFundAccount.

@ParameterizedTest
@EnumSource(RepositoryType.class)
public void transferTransactionNotEnoughFundAccount(RepositoryType type) {
    Address recipient = config().getTestAccount2().getAddress();
    NetworkType networkType = getNetworkType();
    Account account = Account.generateNewAccount(networkType);
    TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipient, Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(1000000000)))).message(new PlainMessage("")).maxFee(maxFee).build();
    IllegalArgumentException exceptions = Assertions.assertThrows(IllegalArgumentException.class, () -> announceAndValidate(type, account, transferTransaction));
    Assertions.assertTrue(exceptions.getMessage().contains("Failure_Core_Insufficient_Balance"));
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 13 with NetworkType

use of io.nem.symbol.sdk.model.network.NetworkType in project nem2-sdk-java by nemtech.

the class BinarySerializationImpl method toTransaction.

/**
 * It converts a {@link EmbeddedTransactionBuilder} to a {@link Transaction}
 *
 * @param builder the builder
 * @return the {@link Transaction} model.
 */
private Transaction toTransaction(EmbeddedTransactionBuilder builder) {
    TransactionType transactionType = TransactionType.rawValueOf(SerializationUtils.shortToUnsignedInt(builder.getType().getValue()));
    NetworkType networkType = NetworkType.rawValueOf(SerializationUtils.byteToUnsignedInt(builder.getNetwork().getValue()));
    TransactionFactory<?> factory = resolveSerializer(transactionType, builder.getVersion()).fromBodyBuilder(networkType, new Deadline(BigInteger.ZERO), builder.getBody());
    factory.signer(SerializationUtils.toPublicAccount(builder.getSignerPublicKey(), networkType));
    factory.version(SerializationUtils.byteToUnsignedInt(builder.getVersion()));
    return factory.build();
}
Also used : TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) Deadline(io.nem.symbol.sdk.model.transaction.Deadline)

Example 14 with NetworkType

use of io.nem.symbol.sdk.model.network.NetworkType in project nem2-sdk-java by nemtech.

the class NetworkRepositoryOkHttpImplTest 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);
}
Also used : NetworkType(io.nem.symbol.sdk.model.network.NetworkType) NodeInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.NodeInfoDTO) Test(org.junit.jupiter.api.Test)

Example 15 with NetworkType

use of io.nem.symbol.sdk.model.network.NetworkType 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)

Aggregations

NetworkType (io.nem.symbol.sdk.model.network.NetworkType)31 Test (org.junit.jupiter.api.Test)13 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)11 BigInteger (java.math.BigInteger)10 Address (io.nem.symbol.sdk.model.account.Address)9 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)7 Account (io.nem.symbol.sdk.model.account.Account)5 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)5 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)5 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)5 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)5 Duration (java.time.Duration)5 TransactionType (io.nem.symbol.sdk.model.transaction.TransactionType)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 BinarySerializationImpl (io.nem.symbol.sdk.infrastructure.BinarySerializationImpl)3 UnresolvedMosaicId (io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId)3 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)3 Optional (java.util.Optional)3 ConvertUtils (io.nem.symbol.core.utils.ConvertUtils)2