@@ -27,6 +27,9 @@ import { MosaicGlobalRestriction } from '../model/restriction/MosaicGlobalRestri
2727import { MosaicGlobalRestrictionItem } from '../model/restriction/MosaicGlobalRestrictionItem' ;
2828import { Http } from './Http' ;
2929import { RestrictionMosaicRepository } from './RestrictionMosaicRepository' ;
30+ import { RestrictionMosaicSearchCriteria } from './searchCriteria/RestrictionMosaicSearchCriteria' ;
31+ import { DtoMapping } from '../core/utils/DtoMapping' ;
32+ import { Page } from './Page' ;
3033
3134/**
3235 * RestrictionMosaic http repository.
@@ -50,90 +53,51 @@ export class RestrictionMosaicHttp extends Http implements RestrictionMosaicRepo
5053 }
5154
5255 /**
53- * Get mosaic address restriction.
54- * @summary Get mosaic address restrictions for a given mosaic and account identifier.
55- * @param mosaicId Mosaic identifier.
56- * @param address address
57- * @returns Observable<MosaicAddressRestriction>
58- */
59- getMosaicAddressRestriction ( mosaicId : MosaicId , address : Address ) : Observable < MosaicAddressRestriction > {
60- return this . call ( this . restrictionMosaicRoutesApi . getMosaicAddressRestriction ( mosaicId . toHex ( ) , address . plain ( ) ) , ( body ) =>
61- this . toMosaicAddressRestriction ( body ) ,
62- ) ;
63- }
64-
65- /**
66- * Get mosaic address restrictions.
67- * @summary Get mosaic address restrictions for a given mosaic and account identifiers array
68- * @param mosaicId Mosaic identifier.
69- * @param addresses list of addresses
70- * @returns Observable<MosaicAddressRestriction[]>
71- */
72- getMosaicAddressRestrictions ( mosaicId : MosaicId , addresses : Address [ ] ) : Observable < MosaicAddressRestriction [ ] > {
73- const accountIds = {
74- addresses : addresses . map ( ( address ) => address . plain ( ) ) ,
75- } ;
76- return this . call ( this . restrictionMosaicRoutesApi . getMosaicAddressRestrictions ( mosaicId . toHex ( ) , accountIds ) , ( body ) =>
77- body . map ( this . toMosaicAddressRestriction ) ,
78- ) ;
79- }
80-
81- /**
82- * Get mosaic global restriction.
83- * @summary Get mosaic global restrictions for a given mosaic identifier.
84- * @param mosaicId Mosaic identifier.
85- * @returns Observable<MosaicGlobalRestriction>
86- */
87- getMosaicGlobalRestriction ( mosaicId : MosaicId ) : Observable < MosaicGlobalRestriction > {
88- return this . call ( this . restrictionMosaicRoutesApi . getMosaicGlobalRestriction ( mosaicId . toHex ( ) ) , ( body ) =>
89- this . toMosaicGlobalRestriction ( body ) ,
90- ) ;
91- }
92-
93- /**
94- * Get mosaic global restrictions.
95- * @summary Get mosaic global restrictions for a given list of mosaics.
96- * @param mosaicIds List of mosaic identifier.
97- * @returns Observable<MosaicGlobalRestriction[]>
98- */
99- getMosaicGlobalRestrictions ( mosaicIds : MosaicId [ ] ) : Observable < MosaicGlobalRestriction [ ] > {
100- const mosaicIdsBody = {
101- mosaicIds : mosaicIds . map ( ( id ) => id . toHex ( ) ) ,
102- } ;
103- return this . call ( this . restrictionMosaicRoutesApi . getMosaicGlobalRestrictions ( mosaicIdsBody ) , ( body ) =>
104- body . map ( this . toMosaicGlobalRestriction ) ,
105- ) ;
106- }
107-
108- /**
109- * This method maps a MosaicAddressRestrictionDTO from rest to the SDK's MosaicAddressRestriction model object.
56+ * Returns a mosaic restrictions page based on the criteria.
11057 *
111- * @internal
112- * @param {MosaicAddressRestrictionDTO } dto the MosaicAddressRestrictionDTO object from rest.
113- * @returns {MosaicAddressRestriction } a MosaicAddressRestriction model
58+ * @param criteria the criteria
59+ * @return a page of {@link MosaicAddressRestriction | MosaicGlobalRestriction}
11460 */
115- private toMosaicAddressRestriction ( dto : MosaicAddressRestrictionDTO ) : MosaicAddressRestriction {
116- const restrictionItems = new Map < string , string > ( ) ;
117- dto . mosaicRestrictionEntry . restrictions . forEach ( ( restriction ) => {
118- restrictionItems . set ( restriction . key , restriction . value ) ;
119- } ) ;
120- return new MosaicAddressRestriction (
121- dto . mosaicRestrictionEntry . compositeHash ,
122- dto . mosaicRestrictionEntry . entryType . valueOf ( ) ,
123- new MosaicId ( dto . mosaicRestrictionEntry . mosaicId ) ,
124- Address . createFromEncoded ( dto . mosaicRestrictionEntry . targetAddress ) ,
125- restrictionItems ,
61+ public searchMosaicRestrictions (
62+ criteria : RestrictionMosaicSearchCriteria ,
63+ ) : Observable < Page < MosaicAddressRestriction | MosaicGlobalRestriction > > {
64+ return this . call (
65+ this . restrictionMosaicRoutesApi . searchMosaicRestriction (
66+ criteria . mosaicId ?. toHex ( ) ,
67+ criteria . entryType ?. valueOf ( ) ,
68+ criteria . targetAddress ?. plain ( ) ,
69+ criteria . pageSize ,
70+ criteria . pageNumber ,
71+ criteria . offset ,
72+ DtoMapping . mapEnum ( criteria . order ) ,
73+ ) ,
74+ ( body ) => super . toPage ( body . pagination , body . data , this . toMosaicRestriction ) ,
12675 ) ;
12776 }
12877
12978 /**
130- * This method maps a MosaicGlobalRestrictionDTO from rest to the SDK's MosaicGlobalRestriction model object.
79+ * This method maps a mosaic restriction dto from rest to the SDK's model object.
13180 *
13281 * @internal
133- * @param {MosaicGlobalRestrictionDTO } dto the MosaicGlobalRestrictionDTO object from rest.
134- * @returns {MosaicGlobalRestriction } a MosaicGlobalRestriction model
82+ * @param {MosaicAddressRestrictionDTO | MosaicGlobalRestrictionDTO } dto the restriction object from rest.
83+ * @returns {MosaicAddressRestriction | MosaicGlobalRestriction } a restriction model
13584 */
136- private toMosaicGlobalRestriction ( dto : MosaicGlobalRestrictionDTO ) : MosaicGlobalRestriction {
85+ private toMosaicRestriction (
86+ dto : MosaicAddressRestrictionDTO | MosaicGlobalRestrictionDTO ,
87+ ) : MosaicAddressRestriction | MosaicGlobalRestriction {
88+ if ( ( dto . mosaicRestrictionEntry as any ) . targetAddress ) {
89+ const mosaicAddressrestrictionItems = new Map < string , string > ( ) ;
90+ dto . mosaicRestrictionEntry . restrictions . forEach ( ( restriction ) => {
91+ mosaicAddressrestrictionItems . set ( restriction . key , restriction . value ) ;
92+ } ) ;
93+ return new MosaicAddressRestriction (
94+ dto . mosaicRestrictionEntry . compositeHash ,
95+ dto . mosaicRestrictionEntry . entryType . valueOf ( ) ,
96+ new MosaicId ( dto . mosaicRestrictionEntry . mosaicId ) ,
97+ Address . createFromEncoded ( ( dto as MosaicAddressRestrictionDTO ) . mosaicRestrictionEntry . targetAddress ) ,
98+ mosaicAddressrestrictionItems ,
99+ ) ;
100+ }
137101 const restirctionItems = new Map < string , MosaicGlobalRestrictionItem > ( ) ;
138102 dto . mosaicRestrictionEntry . restrictions . forEach ( ( restriction ) =>
139103 restirctionItems . set (
0 commit comments