Search in sources :

Example 26 with NetworkType

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

the class TestnetTester method sendVotingKey2.

private static void sendVotingKey2(RepositoryFactory repositoryFactory) throws Exception {
    NetworkType networkType = repositoryFactory.getNetworkType().toFuture().get();
    Account account = Account.createFromPrivateKey(PRIVATE_KEY, networkType);
    System.out.println(account.getAddress().plain());
    Duration duration = repositoryFactory.getEpochAdjustment().toFuture().get();
    Deadline deadline = Deadline.create(duration);
    PublicKey votingKey = PublicKey.fromHexString("463CCC639B5306DD06E56A273E13EF08CAB8D46A8ACA1D3919F19AF89DE116C5");
    VotingKeyLinkTransaction transaction = VotingKeyLinkTransactionFactory.create(networkType, deadline, votingKey, (1), (26280), LinkAction.LINK).maxFee(MAX_FEE).build();
    announceTransaction(repositoryFactory, account, transaction);
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) PublicKey(io.nem.symbol.core.crypto.PublicKey) VotingKeyLinkTransaction(io.nem.symbol.sdk.model.transaction.VotingKeyLinkTransaction) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) Duration(java.time.Duration)

Example 27 with NetworkType

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

the class NetworkRepositoryIntegrationTest method testNetworkType.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void testNetworkType(RepositoryType type) {
    NetworkType networkType = get(getNetworkRepository(type).getNetworkType());
    assertEquals(getNetworkType(), networkType);
}
Also used : NetworkType(io.nem.symbol.sdk.model.network.NetworkType) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with NetworkType

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

the class RepositoryFactoryConfigurationExamplesIntegrationTest method appDoSomeStuff.

public void appDoSomeStuff(RepositoryFactory repositoryFactory) throws ExecutionException, InterruptedException {
    // The application logic is exactly the same regardless of how the repository
    // factory was
    // set
    // Note: if rest is used, these values are cached form rest
    Currency currency = repositoryFactory.getNetworkCurrency().toFuture().get();
    String generationHash = repositoryFactory.getGenerationHash().toFuture().get();
    NetworkType networkType = repositoryFactory.getNetworkType().toFuture().get();
    Account sender = Account.generateNewAccount(networkType);
    Account recipient = Account.generateNewAccount(networkType);
    Duration epochAdjustment = repositoryFactory.getEpochAdjustment().toFuture().get();
    TransferTransaction transferTransaction = TransferTransactionFactory.create(networkType, Deadline.create(epochAdjustment), recipient.getAddress(), Collections.singletonList(currency.createRelative(BigInteger.TEN))).message(new PlainMessage("")).build();
    SignedTransaction signedTransaction = transferTransaction.signWith(sender, generationHash);
// Announce or store somewhere....
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) Currency(io.nem.symbol.sdk.model.mosaic.Currency) Duration(java.time.Duration) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction)

Example 29 with NetworkType

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

the class AccountTest method shouldAcceptKeyPairAsConstructor.

@Test
void shouldAcceptKeyPairAsConstructor() {
    NetworkType networkType = NetworkType.MIJIN_TEST;
    KeyPair random = KeyPair.random(new Ed25519CryptoEngine());
    Account account = new Account(random, networkType);
    assertEquals(random.getPrivateKey().toHex().toUpperCase(), account.getPrivateKey());
    assertEquals(networkType, account.getAddress().getNetworkType());
}
Also used : KeyPair(io.nem.symbol.core.crypto.KeyPair) Ed25519CryptoEngine(io.nem.symbol.core.crypto.ed25519.Ed25519CryptoEngine) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) Test(org.junit.jupiter.api.Test)

Example 30 with NetworkType

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

the class ResolutionStatement method serialize.

/**
 * Serializes the statement using the catuffer builders
 *
 * @param networkType the network type.
 * @return the serialized content.
 */
private byte[] serialize(NetworkType networkType) {
    ReceiptType type = this.resolutionType == ResolutionType.ADDRESS ? ReceiptType.ADDRESS_ALIAS_RESOLUTION : ReceiptType.MOSAIC_ALIAS_RESOLUTION;
    ReceiptTypeDto recipientTypeDto = ReceiptTypeDto.rawValueOf((short) type.getValue());
    short version = (short) ReceiptVersion.RESOLUTION_STATEMENT.getValue();
    Serializer serializer = this.resolutionType == ResolutionType.ADDRESS ? AddressResolutionStatementBuilder.create(version, recipientTypeDto, SerializationUtils.toUnresolvedAddress((UnresolvedAddress) this.unresolved, networkType), this.resolutionEntries.stream().map((entry) -> AddressResolutionEntryBuilder.create(ReceiptSourceBuilder.create((int) entry.getReceiptSource().getPrimaryId(), (int) entry.getReceiptSource().getSecondaryId()), SerializationUtils.toAddressDto((Address) entry.getResolved()))).collect(Collectors.toList())) : MosaicResolutionStatementBuilder.create(version, recipientTypeDto, SerializationUtils.toUnresolvedMosaicIdDto((UnresolvedMosaicId) this.unresolved), this.resolutionEntries.stream().map((entry) -> MosaicResolutionEntryBuilder.create(ReceiptSourceBuilder.create((int) entry.getReceiptSource().getPrimaryId(), (int) entry.getReceiptSource().getSecondaryId()), SerializationUtils.toMosaicIdDto((MosaicId) entry.getResolved()))).collect(Collectors.toList()));
    return serializer.serialize();
}
Also used : UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId) MosaicResolutionStatementBuilder(io.nem.symbol.catapult.builders.MosaicResolutionStatementBuilder) Hashes(io.nem.symbol.core.crypto.Hashes) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) ConvertUtils(io.nem.symbol.core.utils.ConvertUtils) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ReceiptSourceBuilder(io.nem.symbol.catapult.builders.ReceiptSourceBuilder) ReceiptTypeDto(io.nem.symbol.catapult.builders.ReceiptTypeDto) Collectors(java.util.stream.Collectors) Stored(io.nem.symbol.sdk.model.Stored) AddressResolutionStatementBuilder(io.nem.symbol.catapult.builders.AddressResolutionStatementBuilder) MosaicResolutionEntryBuilder(io.nem.symbol.catapult.builders.MosaicResolutionEntryBuilder) Serializer(io.nem.symbol.catapult.builders.Serializer) List(java.util.List) AddressResolutionEntryBuilder(io.nem.symbol.catapult.builders.AddressResolutionEntryBuilder) Optional(java.util.Optional) BigInteger(java.math.BigInteger) Address(io.nem.symbol.sdk.model.account.Address) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) SerializationUtils(io.nem.symbol.sdk.infrastructure.SerializationUtils) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) Address(io.nem.symbol.sdk.model.account.Address) UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ReceiptTypeDto(io.nem.symbol.catapult.builders.ReceiptTypeDto) Serializer(io.nem.symbol.catapult.builders.Serializer)

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