use of io.nem.symbol.sdk.model.network.NetworkType in project nem2-sdk-java by nemtech.
the class AggregateTransactionTest method serializeEmpty.
@Test
void serializeEmpty() {
NetworkType networkType = NetworkType.MIJIN_TEST;
AggregateTransaction aggregateTransaction = AggregateTransactionFactory.create(TransactionType.AGGREGATE_BONDED, networkType, new Deadline(BigInteger.ONE), Collections.emptyList(), Collections.emptyList()).build();
String expected = "a80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000019041420000000000000000010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
Assertions.assertThrows(IllegalArgumentException.class, () -> assertSerialization(expected, aggregateTransaction));
}
use of io.nem.symbol.sdk.model.network.NetworkType in project nem2-sdk-java by nemtech.
the class AbstractTransactionMapper method createFactory.
protected final TransactionFactory<T> createFactory(TransactionInfo transactionInfo, Object transactionDto) {
D transaction = getJsonHelper().convert(transactionDto, transactionDtoClass);
TransactionDTO transactionDTO = getJsonHelper().convert(transactionDto, TransactionDTO.class);
NetworkType networkType = NetworkType.rawValueOf(transactionDTO.getNetwork().getValue());
Deadline deadline = transactionDTO.getDeadline() != null ? new Deadline(transactionDTO.getDeadline()) : new Deadline(BigInteger.ZERO);
TransactionFactory<T> factory = createFactory(networkType, deadline, transaction);
factory.version(transactionDTO.getVersion());
if (transactionDTO.getSignerPublicKey() != null) {
factory.signer(PublicAccount.createFromPublicKey(transactionDTO.getSignerPublicKey(), networkType));
}
if (transactionDTO.getSignature() != null) {
factory.signature(transactionDTO.getSignature());
}
if (transactionDTO.getMaxFee() != null) {
factory.maxFee(transactionDTO.getMaxFee());
}
if (transactionDTO.getSize() != null) {
factory.size(transactionDTO.getSize());
}
if (transactionInfo != null) {
factory.transactionInfo(transactionInfo);
}
if (factory.getType() != getTransactionType()) {
throw new IllegalStateException("Expected transaction to be " + getTransactionType() + " but got " + factory.getType());
}
return factory;
}
use of io.nem.symbol.sdk.model.network.NetworkType in project nem2-sdk-java by nemtech.
the class MosaicDefinitionTransactionTest method shouldGenerateEmbeddedBytes.
@Test
@DisplayName("SerializationEmbeddedBytes")
void shouldGenerateEmbeddedBytes() {
String expected = "460000000000000068b3fbb18729c1fde225c57f8ce080fa828f0067e451a3fd81fa628842b0b7630000000001904d4100000000000000000a00000000000000000000000203";
NetworkType networkType = NetworkType.MIJIN_TEST;
MosaicId mosaicId = new MosaicId(new BigInteger("0"));
BigInteger fee = BigInteger.ONE;
MosaicNonce mosaicNonce = MosaicNonce.createFromBigInteger(new BigInteger("0"));
MosaicFlags mosaicFlags = MosaicFlags.create(false, true, false);
PublicAccount signature = PublicAccount.createFromPublicKey("68b3fbb18729c1fde225c57f8ce080fa828f0067e451a3fd81fa628842b0b763", NetworkType.MIJIN_TEST);
TransactionInfo transactionInfo = TransactionInfo.createAggregate(new BigInteger("121855"), 1, "5A3D23889CD1E800015929A9", "3D28C804EDD07D5A728E5C5FFEC01AB07AFA5766AE6997B38526D36015A4D006", "5A0069D83F17CF0001777E55");
MosaicDefinitionTransaction transaction = MosaicDefinitionTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), mosaicNonce, mosaicId, mosaicFlags, 3, new BlockDuration(10)).maxFee(fee).signature("theSigner").signer(signature).transactionInfo(transactionInfo).build();
assertEmbeddedSerialization(expected, transaction);
}
use of io.nem.symbol.sdk.model.network.NetworkType 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.network.NetworkType in project nem2-sdk-java by nemtech.
the class TestnetTester method sendMosaics.
private static void sendMosaics(RepositoryFactory repositoryFactory) throws Exception {
NetworkType networkType = repositoryFactory.getNetworkType().blockingFirst();
Account account = Account.createFromPrivateKey(PRIVATE_KEY, networkType);
Account recipient = Account.generateNewAccount(networkType);
Mosaic mosaic = repositoryFactory.getNetworkCurrency().blockingFirst().createAbsolute(1);
System.out.println(account.getAddress().plain());
Duration duration = repositoryFactory.getEpochAdjustment().blockingFirst();
Deadline deadline = Deadline.create(duration);
TransferTransaction transaction = TransferTransactionFactory.create(networkType, deadline, recipient.getAddress(), Collections.singletonList(mosaic)).maxFee(MAX_FEE).build();
announceTransaction(repositoryFactory, account, transaction);
}
Aggregations