モザイクにアタッチされたグローバルモザイク制限を取得する

モザイクのグローバル制限リストの取得

前提条件

方法 #01: SDK を使用する

// 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 };
restrictionHttp.search(criteria).subscribe(
  (mosaicGlobalRestrictions) => {
    if (mosaicGlobalRestrictions.data.length > 0) {
      console.log(
        'Key\t',
        'Reference MosaicId\t',
        'Restriction Type\t',
        'Restriction Value',
      );
      mosaicGlobalRestrictions.data.forEach((mosaicRestriction) => {
        if (mosaicRestriction instanceof MosaicGlobalRestriction) {
          mosaicRestriction.restrictions.forEach(
            (value: MosaicGlobalRestrictionItem) => {
              console.log(
                '\n',
                value.key,
                value.referenceMosaicId.toHex(),
                MosaicRestrictionType[value.restrictionType],
                value.restrictionValue,
              );
            },
          );
        }
      });
    } else {
      console.log(
        '\n The mosaic does not have mosaic global restrictions assigned.',
      );
    }
  },
  (err) => console.log(err),
);
// 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 };
restrictionHttp.search(criteria).subscribe(
  (mosaicGlobalRestrictions) => {
    if (mosaicGlobalRestrictions.data.length > 0) {
      console.log(
        'Key\t',
        'Reference MosaicId\t',
        'Restriction Type\t',
        'Restriction Value',
      );
      mosaicGlobalRestrictions.data.forEach((mosaicRestriction) => {
        if (mosaicRestriction instanceof symbol_sdk_1.MosaicGlobalRestriction) {
          mosaicRestriction.restrictions.forEach((value) => {
            console.log(
              '\n',
              value.key,
              value.referenceMosaicId.toHex(),
              symbol_sdk_1.MosaicRestrictionType[value.restrictionType],
              value.restrictionValue,
            );
          });
        }
      });
    } else {
      console.log(
        '\n The mosaic does not have mosaic global 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);

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

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

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

方法 #02: CLI を使用する

symbol-cli restriction mosaicglobal --mosaic-id 634a8ac3fc2b65b3