@@ -27,6 +27,7 @@ import { NetworkType } from '../model/network/NetworkType';
2727import { MosaicAddressRestriction } from '../model/restriction/MosaicAddressRestriction' ;
2828import { MosaicGlobalRestriction } from '../model/restriction/MosaicGlobalRestriction' ;
2929import { MosaicGlobalRestrictionItem } from '../model/restriction/MosaicGlobalRestrictionItem' ;
30+ import { MosaicRestrictionEntryType } from '../model/restriction/MosaicRestrictionEntryType' ;
3031import { MosaicRestrictionType } from '../model/restriction/MosaicRestrictionType' ;
3132import { Deadline } from '../model/transaction/Deadline' ;
3233import { MosaicAddressRestrictionTransaction } from '../model/transaction/MosaicAddressRestrictionTransaction' ;
@@ -125,7 +126,9 @@ export class MosaicRestrictionTransactionService {
125126 this . getGlobalRestrictionEntry ( resolvedMosaicId , restrictionKey ) . pipe (
126127 mergeMap ( ( restrictionEntry : MosaicGlobalRestrictionItem | undefined ) => {
127128 if ( ! restrictionEntry ) {
128- throw new Error ( 'Global restriction is not valid for RestrictionKey: ' + restrictionKey ) ;
129+ throw new Error (
130+ `Global restriction for mosaic: ${ mosaicId } is not valid for with RestrictionKey: ${ restrictionKey } ` ,
131+ ) ;
129132 }
130133 return this . getAddressRestrictionEntry ( resolvedMosaicId , restrictionKey , resolvedAddress ) . pipe (
131134 map ( ( optionalValue ) => {
@@ -156,16 +159,14 @@ export class MosaicRestrictionTransactionService {
156159 * @return {Observable<string | undefined> }
157160 */
158161 private getAddressRestrictionEntry ( mosaicId : MosaicId , restrictionKey : UInt64 , targetAddress : Address ) : Observable < UInt64 | undefined > {
159- return this . restrictionMosaicRepository . search ( { mosaicId, targetAddress } ) . pipe (
162+ return this . restrictionMosaicRepository . search ( { mosaicId, targetAddress, entryType : MosaicRestrictionEntryType . ADDRESS } ) . pipe (
160163 map ( ( mosaicRestriction ) => {
161- return ( mosaicRestriction . data [ 0 ] as MosaicAddressRestriction ) . getRestriction ( restrictionKey ) ?. restrictionValue ;
162- } ) ,
163- catchError ( ( err : Error ) => {
164- const error = JSON . parse ( err . message ) ;
165- if ( error && error . statusCode && error . statusCode === 404 ) {
166- return of ( undefined ) ;
167- }
168- throw new Error ( err . message ) ;
164+ return mosaicRestriction . data
165+ . find (
166+ ( r ) =>
167+ r instanceof MosaicAddressRestriction && r . mosaicId . equals ( mosaicId ) && r . targetAddress . equals ( targetAddress ) ,
168+ ) !
169+ . getRestriction ( restrictionKey ) ?. restrictionValue ;
169170 } ) ,
170171 ) ;
171172 }
@@ -177,20 +178,11 @@ export class MosaicRestrictionTransactionService {
177178 * @return {Observable<MosaicGlobalRestrictionItem | undefined> }
178179 */
179180 private getGlobalRestrictionEntry ( mosaicId : MosaicId , restrictionKey : UInt64 ) : Observable < MosaicGlobalRestrictionItem | undefined > {
180- return this . restrictionMosaicRepository . search ( { mosaicId } ) . pipe (
181+ return this . restrictionMosaicRepository . search ( { mosaicId, entryType : MosaicRestrictionEntryType . GLOBAL } ) . pipe (
181182 map ( ( mosaicRestrictionPage : Page < MosaicGlobalRestriction > ) => {
182- const globalRestriction = mosaicRestrictionPage . data . find ( ( r ) => r instanceof MosaicGlobalRestriction ) ;
183- if ( globalRestriction !== undefined ) {
184- return globalRestriction . getRestriction ( restrictionKey ) ;
185- }
186- throw new Error ( 'No global restriction found for mosaic' + mosaicId . toHex ( ) ) ;
187- } ) ,
188- catchError ( ( err : Error ) => {
189- const error = JSON . parse ( err . message ) ;
190- if ( error && error . statusCode && error . statusCode === 404 ) {
191- return of ( undefined ) ;
192- }
193- throw new Error ( err . message ) ;
183+ return mosaicRestrictionPage . data
184+ . find ( ( r ) => r instanceof MosaicGlobalRestriction && r . mosaicId . equals ( mosaicId ) ) !
185+ . getRestriction ( restrictionKey ) ;
194186 } ) ,
195187 ) ;
196188 }
0 commit comments