Search in sources :

Example 6 with MosaicRestriction

use of io.nem.symbol.sdk.model.restriction.MosaicRestriction in project nem2-sdk-java by nemtech.

the class RestrictionMosaicRepositoryVertxImpl method search.

@Override
public Observable<Page<MosaicRestriction<?>>> search(MosaicRestrictionSearchCriteria criteria) {
    String mosaicId = criteria.getMosaicId() == null ? null : criteria.getMosaicId().getIdAsHex();
    MosaicRestrictionEntryTypeEnum entryType = criteria.getEntryType() == null ? null : MosaicRestrictionEntryTypeEnum.fromValue(criteria.getEntryType().getValue());
    String targetAddress = toDto(criteria.getTargetAddress());
    Integer pageSize = criteria.getPageSize();
    Integer pageNumber = criteria.getPageNumber();
    String offset = criteria.getOffset();
    Order order = toDto(criteria.getOrder());
    Consumer<Handler<AsyncResult<MosaicRestrictionsPage>>> callback = (h) -> getClient().searchMosaicRestrictions(mosaicId, entryType, targetAddress, pageSize, pageNumber, offset, order, h);
    return call(callback, page -> toPage(page.getPagination(), page.getData().stream().map(this::toMosaicRestriction).collect(Collectors.toList())));
}
Also used : BigInteger(java.math.BigInteger) Order(io.nem.symbol.sdk.openapi.vertx.model.Order) MosaicAddressRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionEntryWrapperDTO) RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) RestrictionMosaicRoutesApi(io.nem.symbol.sdk.openapi.vertx.api.RestrictionMosaicRoutesApi) MosaicRestrictionEntryTypeEnum(io.nem.symbol.sdk.openapi.vertx.model.MosaicRestrictionEntryTypeEnum) MosaicRestrictionsPage(io.nem.symbol.sdk.openapi.vertx.model.MosaicRestrictionsPage) LinkedHashMap(java.util.LinkedHashMap) MosaicGlobalRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryWrapperDTO) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) Order(io.nem.symbol.sdk.openapi.vertx.model.Order) MosaicRestrictionType(io.nem.symbol.sdk.model.transaction.MosaicRestrictionType) ObjectUtils(org.apache.commons.lang3.ObjectUtils) Map(java.util.Map) MerkleStateInfo(io.nem.symbol.sdk.model.blockchain.MerkleStateInfo) MosaicGlobalRestrictionEntryRestrictionDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryRestrictionDTO) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) AsyncResult(io.vertx.core.AsyncResult) MosaicGlobalRestrictionDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionDTO) MapperUtils(io.nem.symbol.core.utils.MapperUtils) ApiClient(io.nem.symbol.sdk.openapi.vertx.invoker.ApiClient) MosaicAddressRestrictionDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionDTO) RestrictionMosaicRoutesApiImpl(io.nem.symbol.sdk.openapi.vertx.api.RestrictionMosaicRoutesApiImpl) MosaicGlobalRestriction(io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction) MosaicRestrictionEntryType(io.nem.symbol.sdk.model.restriction.MosaicRestrictionEntryType) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) MosaicGlobalRestrictionItem(io.nem.symbol.sdk.model.restriction.MosaicGlobalRestrictionItem) Handler(io.vertx.core.Handler) Page(io.nem.symbol.sdk.api.Page) MosaicAddressRestriction(io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction) Handler(io.vertx.core.Handler) MosaicRestrictionEntryTypeEnum(io.nem.symbol.sdk.openapi.vertx.model.MosaicRestrictionEntryTypeEnum) MosaicRestrictionsPage(io.nem.symbol.sdk.openapi.vertx.model.MosaicRestrictionsPage)

Example 7 with MosaicRestriction

use of io.nem.symbol.sdk.model.restriction.MosaicRestriction in project nem2-sdk-java by nemtech.

the class MosaicAddressRestrictionIntegrationTest method assertMosaicAddressRestriction.

private void assertMosaicAddressRestriction(RestrictionMosaicRepository restrictionRepository, Address address, MosaicAddressRestrictionTransaction transaction, Address targetAddress, MosaicId mosaicId) {
    Page<MosaicRestriction<?>> page = get(restrictionRepository.search(new MosaicRestrictionSearchCriteria().entryType(MosaicRestrictionEntryType.ADDRESS).targetAddress(targetAddress).mosaicId(mosaicId)));
    Assertions.assertEquals(1, page.getData().size(), "Cannot find restriction target address " + targetAddress.plain() + " encoded: " + targetAddress.encoded() + " mosaicId " + mosaicId.getIdAsHex());
    MosaicAddressRestriction restriction = (MosaicAddressRestriction) page.getData().get(0);
    BigInteger restrictionKey = transaction.getRestrictionKey();
    BigInteger newRestrictionValue = transaction.getNewRestrictionValue();
    Assertions.assertEquals(Collections.singleton(restrictionKey), restriction.getRestrictions().keySet());
    Assertions.assertEquals(address, restriction.getTargetAddress());
    Assertions.assertEquals(1, restriction.getRestrictions().size());
    Assertions.assertEquals(newRestrictionValue, restriction.getRestrictions().get(restrictionKey));
    Assertions.assertEquals(transaction.getNewRestrictionValue(), restriction.getRestrictions().get(restrictionKey));
}
Also used : MosaicAddressRestriction(io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction) BigInteger(java.math.BigInteger) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria)

Example 8 with MosaicRestriction

use of io.nem.symbol.sdk.model.restriction.MosaicRestriction in project nem2-sdk-java by nemtech.

the class MosaicAddressRestrictionIntegrationTest method getMosaicAddressRestrictionWhenMosaicDoesNotExist.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getMosaicAddressRestrictionWhenMosaicDoesNotExist(RepositoryType type) {
    RestrictionMosaicRepository repository = getRepositoryFactory(type).createRestrictionMosaicRepository();
    Address address = Address.createFromPublicKey("67F69FA4BFCD158F6E1AF1ABC82F725F5C5C4710D6E29217B12BE66397435DFB", getNetworkType());
    Page<MosaicRestriction<?>> page = get(repository.search(new MosaicRestrictionSearchCriteria().mosaicId(new MosaicId(BigInteger.valueOf(888888))).targetAddress(address).entryType(MosaicRestrictionEntryType.ADDRESS)));
    Assertions.assertTrue(page.getData().isEmpty());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 9 with MosaicRestriction

use of io.nem.symbol.sdk.model.restriction.MosaicRestriction in project nem2-sdk-java by nemtech.

the class RestrictionMosaicRepositoryVertxImplTest method shouldGetMosaicAddressRestrictions.

@Test
public void shouldGetMosaicAddressRestrictions() throws Exception {
    Address address = Address.generateRandom(this.networkType);
    MosaicId mosaicId = MapperUtils.toMosaicId("123");
    MosaicAddressRestrictionDTO dto = new MosaicAddressRestrictionDTO();
    MosaicAddressRestrictionEntryWrapperDTO wrapperDTO = new MosaicAddressRestrictionEntryWrapperDTO();
    dto.setMosaicRestrictionEntry(wrapperDTO);
    MosaicAddressRestrictionEntryDTO entryDTO = new MosaicAddressRestrictionEntryDTO();
    entryDTO.setKey(ConvertUtils.toString(BigInteger.valueOf(1111)));
    entryDTO.setValue("2222");
    List<MosaicAddressRestrictionEntryDTO> restrictions = new ArrayList<>();
    restrictions.add(entryDTO);
    wrapperDTO.setCompositeHash("compositeHash");
    wrapperDTO.setMosaicId(mosaicId.getIdAsHex());
    wrapperDTO.setRestrictions(restrictions);
    wrapperDTO.setEntryType(MosaicRestrictionEntryTypeEnum.NUMBER_0);
    wrapperDTO.setVersion(1);
    wrapperDTO.setTargetAddress(address.encoded());
    mockRemoteCall(toPage(dto));
    List<MosaicRestriction<?>> mosaicAddressRestrictions = repository.search(new MosaicRestrictionSearchCriteria()).toFuture().get().getData();
    Assertions.assertEquals(1, mosaicAddressRestrictions.size());
    MosaicAddressRestriction mosaicAddressRestriction = (MosaicAddressRestriction) mosaicAddressRestrictions.get(0);
    Assertions.assertEquals(wrapperDTO.getCompositeHash(), mosaicAddressRestriction.getCompositeHash());
    Assertions.assertEquals(MosaicRestrictionEntryType.ADDRESS, mosaicAddressRestriction.getEntryType());
    Assertions.assertEquals(mosaicId, mosaicAddressRestriction.getMosaicId());
    Assertions.assertEquals(address, mosaicAddressRestriction.getTargetAddress());
    Assertions.assertEquals(1, mosaicAddressRestriction.getRestrictions().size());
    Assertions.assertEquals(BigInteger.valueOf(2222), mosaicAddressRestriction.getRestrictions().get(BigInteger.valueOf(1111)));
}
Also used : MosaicAddressRestriction(io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction) Address(io.nem.symbol.sdk.model.account.Address) MosaicAddressRestrictionDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionDTO) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ArrayList(java.util.ArrayList) MosaicAddressRestrictionEntryDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionEntryDTO) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) MosaicAddressRestrictionEntryWrapperDTO(io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionEntryWrapperDTO) Test(org.junit.jupiter.api.Test)

Example 10 with MosaicRestriction

use of io.nem.symbol.sdk.model.restriction.MosaicRestriction in project nem2-sdk-java by nemtech.

the class MosaicRestrictionServiceIntegrationTest method getMosaicGlobalRestrictionWhenMosaicDoesNotExist.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getMosaicGlobalRestrictionWhenMosaicDoesNotExist(RepositoryType type) {
    RestrictionMosaicRepository repository = getRepositoryFactory(type).createRestrictionMosaicRepository();
    Address address = Address.createFromPublicKey("67F69FA4BFCD158F6E1AF1ABC82F725F5C5C4710D6E29217B12BE66397435DFB", getNetworkType());
    Page<MosaicRestriction<?>> page = get(repository.search(new MosaicRestrictionSearchCriteria().mosaicId(new MosaicId(BigInteger.valueOf(888888))).targetAddress(address).entryType(MosaicRestrictionEntryType.GLOBAL)));
    Assertions.assertTrue(page.getData().isEmpty());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

MosaicRestriction (io.nem.symbol.sdk.model.restriction.MosaicRestriction)12 MosaicRestrictionSearchCriteria (io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria)11 RestrictionMosaicRepository (io.nem.symbol.sdk.api.RestrictionMosaicRepository)7 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)7 MosaicAddressRestriction (io.nem.symbol.sdk.model.restriction.MosaicAddressRestriction)5 Test (org.junit.jupiter.api.Test)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 EnumSource (org.junit.jupiter.params.provider.EnumSource)5 Address (io.nem.symbol.sdk.model.account.Address)4 MosaicGlobalRestriction (io.nem.symbol.sdk.model.restriction.MosaicGlobalRestriction)4 ArrayList (java.util.ArrayList)4 MosaicRestrictionEntryType (io.nem.symbol.sdk.model.restriction.MosaicRestrictionEntryType)3 BigInteger (java.math.BigInteger)3 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)2 MosaicAddressRestrictionDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionDTO)2 MosaicAddressRestrictionEntryWrapperDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicAddressRestrictionEntryWrapperDTO)2 MosaicGlobalRestrictionDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionDTO)2 MosaicGlobalRestrictionEntryRestrictionDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryRestrictionDTO)2 MosaicGlobalRestrictionEntryWrapperDTO (io.nem.symbol.sdk.openapi.vertx.model.MosaicGlobalRestrictionEntryWrapperDTO)2 MapperUtils (io.nem.symbol.core.utils.MapperUtils)1