Search in sources :

Example 41 with Address

use of io.nem.symbol.sdk.model.account.Address in project nem2-sdk-java by nemtech.

the class AggregateTransactionServiceImpl method isComplete.

@Override
public Observable<Boolean> isComplete(SignedTransaction signedTransaction) {
    Validate.notNull(signedTransaction, "signedTransaction is required");
    Validate.isTrue(signedTransaction.getType() == TransactionType.AGGREGATE_COMPLETE, "signedTransaction type must be AGGREGATE_COMPLETE");
    AggregateTransaction transaction = (AggregateTransaction) BinarySerializationImpl.INSTANCE.deserialize(ConvertUtils.fromHexToBytes(signedTransaction.getPayload()));
    /*
     * Include both initiator & cosigners
     */
    Set<Address> signers = transaction.getCosignatures().stream().map(AggregateTransactionCosignature::getSigner).map(PublicAccount::getAddress).collect(Collectors.toSet());
    signers.add(signedTransaction.getSigner().getAddress());
    return Observable.fromIterable(transaction.getInnerTransactions()).flatMap(innerTransaction -> multisigRepository.getMultisigAccountInfo(innerTransaction.getSigner().orElseThrow(IllegalArgumentException::new).getAddress()).flatMap(multisigAccountInfo -> multisigAccountInfo.getMinRemoval() != 0 && multisigAccountInfo.getMinApproval() != 0 ? multisigRepository.getMultisigAccountGraphInfo(multisigAccountInfo.getAccountAddress()).map(graphInfo -> validateCosignatories(graphInfo, signers, innerTransaction)) : Observable.just(signers.stream().anyMatch(s -> s.equals(multisigAccountInfo.getAccountAddress()))))).all(v -> v).toObservable();
}
Also used : MultisigAccountInfo(io.nem.symbol.sdk.model.account.MultisigAccountInfo) AggregateTransactionCosignature(io.nem.symbol.sdk.model.transaction.AggregateTransactionCosignature) Set(java.util.Set) ConvertUtils(io.nem.symbol.core.utils.ConvertUtils) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) Collectors(java.util.stream.Collectors) MultisigAccountGraphInfo(io.nem.symbol.sdk.model.account.MultisigAccountGraphInfo) HashSet(java.util.HashSet) List(java.util.List) Stream(java.util.stream.Stream) Validate(org.apache.commons.lang3.Validate) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) TreeMap(java.util.TreeMap) MultisigRepository(io.nem.symbol.sdk.api.MultisigRepository) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Map(java.util.Map) NetworkRepository(io.nem.symbol.sdk.api.NetworkRepository) TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType) Observable(io.reactivex.Observable) Address(io.nem.symbol.sdk.model.account.Address) MultisigAccountModificationTransaction(io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction) AggregateTransactionService(io.nem.symbol.sdk.api.AggregateTransactionService) Address(io.nem.symbol.sdk.model.account.Address) AggregateTransactionCosignature(io.nem.symbol.sdk.model.transaction.AggregateTransactionCosignature) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction)

Example 42 with Address

use of io.nem.symbol.sdk.model.account.Address in project nem2-sdk-java by nemtech.

the class ResolutionEntry method serialize.

/**
 * Serialize receipt and returns receipt bytes
 *
 * @return receipt bytes
 */
public byte[] serialize() {
    ReceiptSourceBuilder receiptSourceBuilder = ReceiptSourceBuilder.create((int) getReceiptSource().getPrimaryId(), (int) getReceiptSource().getSecondaryId());
    Class<?> resolutionClass = this.resolved.getClass();
    if (Address.class.isAssignableFrom(resolutionClass)) {
        AddressDto addressBuilder = new AddressDto(SerializationUtils.fromAddressToByteBuffer((Address) getResolved()));
        AddressResolutionEntryBuilder builder = AddressResolutionEntryBuilder.create(receiptSourceBuilder, addressBuilder);
        return builder.serialize();
    } else {
        MosaicIdDto mosaicIdDto = SerializationUtils.toMosaicIdDto((MosaicId) getResolved());
        MosaicResolutionEntryBuilder builder = MosaicResolutionEntryBuilder.create(receiptSourceBuilder, mosaicIdDto);
        return builder.serialize();
    }
}
Also used : AddressResolutionEntryBuilder(io.nem.symbol.catapult.builders.AddressResolutionEntryBuilder) Address(io.nem.symbol.sdk.model.account.Address) MosaicIdDto(io.nem.symbol.catapult.builders.MosaicIdDto) MosaicResolutionEntryBuilder(io.nem.symbol.catapult.builders.MosaicResolutionEntryBuilder) AddressDto(io.nem.symbol.catapult.builders.AddressDto) ReceiptSourceBuilder(io.nem.symbol.catapult.builders.ReceiptSourceBuilder)

Example 43 with Address

use of io.nem.symbol.sdk.model.account.Address in project nem2-sdk-java by nemtech.

the class MosaicRepositoryOkHttpImplTest method shouldGetMosaic.

@Test
public void shouldGetMosaic() throws Exception {
    MosaicId mosaicId = MapperUtils.toMosaicId("481110499AAA");
    Address ownerAddress = Account.generateNewAccount(networkType).getAddress();
    MosaicDTO mosaicDto = new MosaicDTO();
    MosaicInfoDTO mosaicInfoDto = new MosaicInfoDTO();
    mosaicDto.setOwnerAddress(ownerAddress.encoded());
    mosaicDto.setId("481110499AAA");
    mosaicDto.setRevision(123L);
    mosaicDto.setFlags(5);
    mosaicDto.setDivisibility(6);
    mosaicDto.setDuration(BigInteger.valueOf(7));
    mosaicDto.supply(BigInteger.valueOf(1000));
    mosaicDto.startHeight(BigInteger.valueOf(100));
    mosaicDto.setVersion(1);
    mosaicInfoDto.setMosaic(mosaicDto);
    mockRemoteCall(mosaicInfoDto);
    MosaicInfo mosaicInfo = repository.getMosaic(mosaicId).toFuture().get();
    Assertions.assertEquals(mosaicId, mosaicInfo.getMosaicId());
    Assertions.assertEquals(mosaicDto.getRevision(), mosaicInfo.getRevision());
    Assertions.assertEquals(mosaicDto.getOwnerAddress(), mosaicInfo.getOwnerAddress().encoded(networkType));
    Assertions.assertFalse(mosaicInfo.isTransferable());
    Assertions.assertEquals(6, mosaicInfo.getDivisibility());
    Assertions.assertEquals(BigInteger.valueOf(7), mosaicInfo.getDuration());
    Assertions.assertEquals(mosaicDto.getStartHeight(), mosaicInfo.getStartHeight());
    Assertions.assertEquals(mosaicDto.getSupply(), mosaicInfo.getSupply());
}
Also used : MosaicInfo(io.nem.symbol.sdk.model.mosaic.MosaicInfo) Address(io.nem.symbol.sdk.model.account.Address) MosaicDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicDTO) MosaicInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicInfoDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Test(org.junit.jupiter.api.Test)

Example 44 with Address

use of io.nem.symbol.sdk.model.account.Address in project nem2-sdk-java by nemtech.

the class MosaicRepositoryOkHttpImplTest method shouldGetMosaics.

@Test
public void shouldGetMosaics() throws Exception {
    MosaicId mosaicId = MapperUtils.toMosaicId("481110499AAA");
    Address ownerAddress = Account.generateNewAccount(networkType).getAddress();
    MosaicDTO mosaicDto = new MosaicDTO();
    MosaicInfoDTO mosaicInfoDto = new MosaicInfoDTO();
    mosaicDto.setOwnerAddress(ownerAddress.encoded());
    mosaicDto.setId("481110499AAA");
    mosaicDto.setRevision(123L);
    mosaicDto.setFlags(5);
    mosaicDto.setDivisibility(6);
    mosaicDto.setDuration(BigInteger.valueOf(7));
    mosaicDto.supply(BigInteger.valueOf(1000));
    mosaicDto.startHeight(BigInteger.valueOf(100));
    mosaicDto.setVersion(1);
    mosaicInfoDto.setMosaic(mosaicDto);
    mockRemoteCall(Collections.singletonList(mosaicInfoDto));
    List<MosaicInfo> resolvedList = repository.getMosaics(Collections.singletonList(mosaicId)).toFuture().get();
    Assertions.assertEquals(1, resolvedList.size());
    MosaicInfo mosaicInfo = resolvedList.get(0);
    Assertions.assertEquals(mosaicId, mosaicInfo.getMosaicId());
    Assertions.assertEquals(mosaicDto.getRevision(), mosaicInfo.getRevision());
    Assertions.assertEquals(mosaicDto.getOwnerAddress(), mosaicInfo.getOwnerAddress().encoded(networkType));
    Assertions.assertFalse(mosaicInfo.isTransferable());
    Assertions.assertEquals(6, mosaicInfo.getDivisibility());
    Assertions.assertEquals(BigInteger.valueOf(7), mosaicInfo.getDuration());
    Assertions.assertEquals(mosaicDto.getStartHeight(), mosaicInfo.getStartHeight());
    Assertions.assertEquals(mosaicDto.getSupply(), mosaicInfo.getSupply());
}
Also used : MosaicInfo(io.nem.symbol.sdk.model.mosaic.MosaicInfo) Address(io.nem.symbol.sdk.model.account.Address) MosaicDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicDTO) MosaicInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MosaicInfoDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Test(org.junit.jupiter.api.Test)

Example 45 with Address

use of io.nem.symbol.sdk.model.account.Address in project nem2-sdk-java by nemtech.

the class NamespaceRepositoryOkHttpImplTest method shouldGetNamespace.

@Test
public void shouldGetNamespace() throws Exception {
    Address ownerAccount = Account.generateNewAccount(NetworkType.MIJIN_TEST).getAddress();
    NamespaceId namespaceId = NamespaceId.createFromName("accountalias");
    NamespaceInfoDTO dto = new NamespaceInfoDTO();
    NamespaceMetaDTO meta = new NamespaceMetaDTO();
    meta.setActive(true);
    dto.setId("SomeId");
    meta.setIndex(123);
    dto.setMeta(meta);
    NamespaceDTO namespace = new NamespaceDTO();
    namespace.setDepth(111);
    namespace.setStartHeight(BigInteger.valueOf(4));
    namespace.setEndHeight(BigInteger.valueOf(5));
    namespace.setRegistrationType(NamespaceRegistrationTypeEnum.NUMBER_1);
    namespace.setOwnerAddress(ownerAccount.encoded());
    namespace.setVersion(1);
    AliasDTO alias = new AliasDTO();
    alias.setType(AliasTypeEnum.NUMBER_1);
    alias.setMosaicId("123");
    namespace.setAlias(alias);
    dto.setNamespace(namespace);
    mockRemoteCall(dto);
    NamespaceInfo info = repository.getNamespace(namespaceId).toFuture().get();
    Assertions.assertNotNull(info);
    Assertions.assertEquals(NamespaceRegistrationType.SUB_NAMESPACE, info.getRegistrationType());
    Assertions.assertEquals(dto.getId(), info.getRecordId().get());
    Assertions.assertEquals(meta.getIndex(), info.getIndex());
    Assertions.assertEquals(meta.getActive(), info.isActive());
    Assertions.assertEquals(BigInteger.valueOf(4), info.getStartHeight());
    Assertions.assertEquals(BigInteger.valueOf(5), info.getEndHeight());
}
Also used : NamespaceDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespaceDTO) Address(io.nem.symbol.sdk.model.account.Address) NamespaceMetaDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespaceMetaDTO) NamespaceInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespaceInfoDTO) AliasDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AliasDTO) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) NamespaceInfo(io.nem.symbol.sdk.model.namespace.NamespaceInfo) Test(org.junit.jupiter.api.Test)

Aggregations

Address (io.nem.symbol.sdk.model.account.Address)172 Test (org.junit.jupiter.api.Test)124 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)53 BigInteger (java.math.BigInteger)36 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)34 ArrayList (java.util.ArrayList)28 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)27 EnumSource (org.junit.jupiter.params.provider.EnumSource)26 Account (io.nem.symbol.sdk.model.account.Account)20 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)19 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)19 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)16 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)16 ListenerSubscribeMessage (io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage)15 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)14 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)13 CosignatureSignedTransaction (io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)13 Observable (io.reactivex.Observable)13 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)12 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)10