アカウントにアタッチされたモザイクアドレス制限を取得する

モザイクのアドレス制限リストの取得

前提条件

方法 #01: 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 = 'NODE_URL';
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 = 'NODE_URL';
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(
            "NODE_URL")) {
            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));
        }

方法 #02: CLI を使用する

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