@@ -25,6 +25,8 @@ import { MosaicGlobalRestrictionItem } from '../model/restriction/MosaicGlobalRe
2525import { RestrictionMosaicRoutesApi } from './api/restrictionMosaicRoutesApi' ;
2626import { Http } from './Http' ;
2727import { RestrictionMosaicRepository } from './RestrictionMosaicRespository' ;
28+ import { MosaicAddressRestrictionDTO } from "./model/mosaicAddressRestrictionDTO" ;
29+ import { MosaicGlobalRestrictionDTO } from "./model/mosaicGlobalRestrictionDTO" ;
2830
2931/**
3032 * RestrictionMosaic http repository.
@@ -58,20 +60,7 @@ export class RestrictionMosaicHttp extends Http implements RestrictionMosaicRepo
5860 getMosaicAddressRestriction ( mosaicId : MosaicId , address : Address ) : Observable < MosaicAddressRestriction > {
5961 return observableFrom (
6062 this . restrictionMosaicRoutesApi . getMosaicAddressRestriction ( mosaicId . toHex ( ) , address . plain ( ) ) ) . pipe (
61- map ( ( { body} ) => {
62- const payload = body . mosaicRestrictionEntry ;
63- const restirctionItems = new Map < string , string > ( ) ;
64- payload . restrictions . forEach ( ( restriction ) => {
65- restirctionItems . set ( restriction . key , restriction . value ) ;
66- } ) ;
67- return new MosaicAddressRestriction (
68- payload . compositeHash ,
69- payload . entryType . valueOf ( ) ,
70- new MosaicId ( payload . mosaicId ) ,
71- Address . createFromEncoded ( payload . targetAddress ) ,
72- restirctionItems ,
73- ) ;
74- } ) ,
63+ map ( ( { body} ) => this . toMosaicAddressRestriction ( body ) ) ,
7564 catchError ( ( error ) => throwError ( this . errorHandling ( error ) ) ) ,
7665 ) ;
7766 }
@@ -89,23 +78,32 @@ export class RestrictionMosaicHttp extends Http implements RestrictionMosaicRepo
8978 } ;
9079 return observableFrom (
9180 this . restrictionMosaicRoutesApi . getMosaicAddressRestrictions ( mosaicId . toHex ( ) , accountIds ) ) . pipe (
92- map ( ( { body} ) => body . map ( ( payload ) => {
93- const restirctionItems = new Map < string , string > ( ) ;
94- payload . mosaicRestrictionEntry . restrictions . forEach ( ( restriction ) => {
95- restirctionItems . set ( restriction . key , restriction . value ) ;
96- } ) ;
97- return new MosaicAddressRestriction (
98- payload . mosaicRestrictionEntry . compositeHash ,
99- payload . mosaicRestrictionEntry . entryType . valueOf ( ) ,
100- new MosaicId ( payload . mosaicRestrictionEntry . mosaicId ) ,
101- Address . createFromEncoded ( payload . mosaicRestrictionEntry . targetAddress ) ,
102- restirctionItems ,
103- ) ;
104- } ) ) ,
81+ map ( ( { body} ) => body . map ( this . toMosaicAddressRestriction ) ) ,
10582 catchError ( ( error ) => throwError ( this . errorHandling ( error ) ) ) ,
10683 ) ;
10784 }
10885
86+ /**
87+ * This method maps a MosaicAddressRestrictionDTO from rest to the SDK's MosaicAddressRestriction model object.
88+ *
89+ * @internal
90+ * @param {MosaicAddressRestrictionDTO } dto the MosaicAddressRestrictionDTO object from rest.
91+ * @returns {MosaicAddressRestriction } a MosaicAddressRestriction model
92+ */
93+ private toMosaicAddressRestriction ( dto : MosaicAddressRestrictionDTO ) : MosaicAddressRestriction {
94+ const restrictionItems = new Map < string , string > ( ) ;
95+ dto . mosaicRestrictionEntry . restrictions . forEach ( ( restriction ) => {
96+ restrictionItems . set ( restriction . key , restriction . value ) ;
97+ } ) ;
98+ return new MosaicAddressRestriction (
99+ dto . mosaicRestrictionEntry . compositeHash ,
100+ dto . mosaicRestrictionEntry . entryType . valueOf ( ) ,
101+ new MosaicId ( dto . mosaicRestrictionEntry . mosaicId ) ,
102+ Address . createFromEncoded ( dto . mosaicRestrictionEntry . targetAddress ) ,
103+ restrictionItems ,
104+ ) ;
105+ }
106+
109107 /**
110108 * Get mosaic global restriction.
111109 * @summary Get mosaic global restrictions for a given mosaic identifier.
@@ -115,23 +113,7 @@ export class RestrictionMosaicHttp extends Http implements RestrictionMosaicRepo
115113 getMosaicGlobalRestriction ( mosaicId : MosaicId ) : Observable < MosaicGlobalRestriction > {
116114 return observableFrom (
117115 this . restrictionMosaicRoutesApi . getMosaicGlobalRestriction ( mosaicId . toHex ( ) ) ) . pipe (
118- map ( ( { body} ) => {
119- const payload = body . mosaicRestrictionEntry ;
120- const restirctionItems = new Map < string , MosaicGlobalRestrictionItem > ( ) ;
121- payload . restrictions . forEach ( ( restriction ) =>
122- restirctionItems . set ( restriction . key ,
123- new MosaicGlobalRestrictionItem (
124- new MosaicId ( restriction . restriction . referenceMosaicId ) ,
125- restriction . restriction . restrictionValue ,
126- restriction . restriction . restrictionType . valueOf ( ) ,
127- ) ) ) ;
128- return new MosaicGlobalRestriction (
129- payload . compositeHash ,
130- payload . entryType . valueOf ( ) ,
131- new MosaicId ( payload . mosaicId ) ,
132- restirctionItems ,
133- ) ;
134- } ) ,
116+ map ( ( { body} ) => this . toMosaicGlobalRestriction ( body ) ) ,
135117 catchError ( ( error ) => throwError ( this . errorHandling ( error ) ) ) ,
136118 ) ;
137119 }
@@ -148,23 +130,32 @@ export class RestrictionMosaicHttp extends Http implements RestrictionMosaicRepo
148130 } ;
149131 return observableFrom (
150132 this . restrictionMosaicRoutesApi . getMosaicGlobalRestrictions ( mosaicIdsBody ) ) . pipe (
151- map ( ( { body} ) => body . map ( ( payload ) => {
152- const restirctionItems = new Map < string , MosaicGlobalRestrictionItem > ( ) ;
153- payload . mosaicRestrictionEntry . restrictions . forEach ( ( restriction ) =>
154- restirctionItems . set ( restriction . key ,
155- new MosaicGlobalRestrictionItem (
156- new MosaicId ( restriction . restriction . referenceMosaicId ) ,
157- restriction . restriction . restrictionValue ,
158- restriction . restriction . restrictionType . valueOf ( ) ,
159- ) ) ) ;
160- return new MosaicGlobalRestriction (
161- payload . mosaicRestrictionEntry . compositeHash ,
162- payload . mosaicRestrictionEntry . entryType . valueOf ( ) ,
163- new MosaicId ( payload . mosaicRestrictionEntry . mosaicId ) ,
164- restirctionItems ,
165- ) ;
166- } ) ) ,
133+ map ( ( { body} ) => body . map ( this . toMosaicGlobalRestriction ) ) ,
167134 catchError ( ( error ) => throwError ( this . errorHandling ( error ) ) ) ,
168135 ) ;
169136 }
137+
138+ /**
139+ * This method maps a MosaicGlobalRestrictionDTO from rest to the SDK's MosaicGlobalRestriction model object.
140+ *
141+ * @internal
142+ * @param {MosaicGlobalRestrictionDTO } dto the MosaicGlobalRestrictionDTO object from rest.
143+ * @returns {MosaicGlobalRestriction } a MosaicGlobalRestriction model
144+ */
145+ private toMosaicGlobalRestriction ( dto : MosaicGlobalRestrictionDTO ) : MosaicGlobalRestriction {
146+ const restirctionItems = new Map < string , MosaicGlobalRestrictionItem > ( ) ;
147+ dto . mosaicRestrictionEntry . restrictions . forEach ( ( restriction ) =>
148+ restirctionItems . set ( restriction . key ,
149+ new MosaicGlobalRestrictionItem (
150+ new MosaicId ( restriction . restriction . referenceMosaicId ) ,
151+ restriction . restriction . restrictionValue ,
152+ restriction . restriction . restrictionType . valueOf ( ) ,
153+ ) ) ) ;
154+ return new MosaicGlobalRestriction (
155+ dto . mosaicRestrictionEntry . compositeHash ,
156+ dto . mosaicRestrictionEntry . entryType . valueOf ( ) ,
157+ new MosaicId ( dto . mosaicRestrictionEntry . mosaicId ) ,
158+ restirctionItems ,
159+ ) ;
160+ }
170161}
0 commit comments