Getting mosaic address restrictions attached to an account

Get the list of mosaic address restrictions.

Prerequisites

Method #01: Using the SDK

// replace with address
const rawAddress = 'TCHBDE-NCLKEB-ILBPWP-3JPB2X-NY64OE-7PYHHE-32I';
const address = Address.createFromRawAddress(rawAddress);
// replace with mosaic id
const mosaicIdHex = '634a8ac3fc2b65b3';
const mosaicId = new MosaicId(mosaicIdHex);
// replace with node endpoint
const nodeUrl = 'http://ngl-dual-101.testnet.symboldev.network:3000';
const repositoryFactory = new RepositoryFactoryHttp(nodeUrl);
const restrictionHttp = repositoryFactory.createRestrictionMosaicRepository();

const criteria = { mosaicId, targetAddress: address };
restrictionHttp.search(criteria).subscribe(
  (mosaicAddressRestrictions) => {
    if (mosaicAddressRestrictions.data.length > 0) {
      mosaicAddressRestrictions.data.forEach((mosaicRestriction) => {
        mosaicRestriction.restrictions.forEach(
          (value: MosaicAddressRestrictionItem) => {
            console.log('\n', value.key, value.restrictionValue);
          },
        );
      });
    } else {
      console.log(
        '\n The address does not have mosaic address restrictions assigned.',
      );
    }
  },
  (err) => console.log(err),
);
// replace with address
const rawAddress = 'TCHBDE-NCLKEB-ILBPWP-3JPB2X-NY64OE-7PYHHE-32I';
const address = symbol_sdk_1.Address.createFromRawAddress(rawAddress);
// replace with mosaic id
const mosaicIdHex = '634a8ac3fc2b65b3';
const mosaicId = new symbol_sdk_1.MosaicId(mosaicIdHex);
// replace with node endpoint
const nodeUrl = 'http://ngl-dual-101.testnet.symboldev.network:3000';
const repositoryFactory = new symbol_sdk_1.RepositoryFactoryHttp(nodeUrl);
const restrictionHttp = repositoryFactory.createRestrictionMosaicRepository();
const criteria = { mosaicId, targetAddress: address };
restrictionHttp.search(criteria).subscribe((mosaicAddressRestrictions) => {
    if (mosaicAddressRestrictions.data.length > 0) {
        mosaicAddressRestrictions.data.forEach((mosaicRestriction) => {
            mosaicRestriction.restrictions.forEach((value) => {
                console.log('\n', value.key, value.restrictionValue);
            });
        });
    }
    else {
        console.log('\n The address does not have mosaic address restrictions assigned.');
    }
}, (err) => console.log(err));
        // replace with node endpoint
        try (final RepositoryFactory repositoryFactory = new RepositoryFactoryVertxImpl(
            "http://ngl-dual-101.testnet.symboldev.network:3000")) {
            final RestrictionMosaicRepository restrictionRepository = repositoryFactory
                .createRestrictionMosaicRepository();

            // replace with mosaicId
            final String mosaicIdHex = "634a8ac3fc2b65b3";
            final MosaicId mosaicId = new MosaicId(mosaicIdHex);

            // replace with address
            final String rawAddress = "TCHBDE-NCLKEB-ILBPWP-3JPB2X-NY64OE-7PYHHE-32I";
            final Address address = Address.createFromRawAddress(rawAddress);

            MosaicRestrictionSearchCriteria criteria = new MosaicRestrictionSearchCriteria()
                .mosaicId(mosaicId).targetAddress(address);

            List<MosaicAddressRestriction> restrictions = MosaicRestrictionPaginationStreamer
                .address(restrictionRepository, criteria).toList().toFuture().get();

            final JsonHelper helper = new JsonHelperJackson2();
            System.out.println(helper.prettyPrint(restrictions));
        }

Method #02: Using the CLI

symbol-cli restriction mosaicaddress --mosaic-id 634a8ac3fc2b65b3 --address TCHBDE-NCLKEB-ILBPWP-3JPB2X-NY64OE-7PYHHE-32I

Did you find what you were looking for? Give us your feedback.