Skip to content

Commit c503cd7

Browse files
author
Greg S
committed
WIP #55: added first draft of NamespaceHttp.getLinkedMosaicId and NamespaceHttp.getLinkedAddress
1 parent c491bea commit c503cd7

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

src/infrastructure/NamespaceHttp.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,44 @@ export class NamespaceHttp extends Http implements NamespaceRepository {
165165
}));
166166
}
167167

168+
/**
169+
* Gets the MosaicId from a MosaicAlias
170+
* @param alias - String containing the address alias
171+
* @returns Observable<MosaicId | null>
172+
*/
173+
public getLinkedMosaicId(alias: string): Observable<MosaicId | null> {
174+
return this.getNetworkTypeObservable().pipe(
175+
mergeMap((networkType) => observableFrom(
176+
this.namespaceRoutesApi.getNamespace(alias)).pipe(
177+
map((namespaceInfoDTO) => {
178+
179+
if (namespaceInfoDTO.namespace.alias.type === AliasType.Mosaic) {
180+
return new MosaicId(namespaceInfoDTO.namespace.alias.mosaicId);
181+
}
182+
183+
return null;
184+
}))));
185+
}
186+
187+
/**
188+
* Gets the Address from a AddressAlias
189+
* @param alias - String containing the address alias
190+
* @returns Observable<Address>
191+
*/
192+
public getLinkedAddress(alias: string): Observable<Address | null> {
193+
return this.getNetworkTypeObservable().pipe(
194+
mergeMap((networkType) => observableFrom(
195+
this.namespaceRoutesApi.getNamespace(alias)).pipe(
196+
map((namespaceInfoDTO) => {
197+
198+
if (namespaceInfoDTO.namespace.alias.type === AliasType.Address) {
199+
return Address.createFromRawAddress(namespaceInfoDTO.namespace.alias.address);
200+
}
201+
202+
return null;
203+
}))));
204+
}
205+
168206
private extractLevels(namespace: any): NamespaceId[] {
169207
const result: NamespaceId[] = [];
170208
if (namespace.level0) {

src/infrastructure/NamespaceRepository.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import {Observable} from 'rxjs';
1818
import {Address} from '../model/account/Address';
1919
import {PublicAccount} from '../model/account/PublicAccount';
20+
import {MosaicId} from '../model/mosaic/MosaicId';
2021
import {NamespaceId} from '../model/namespace/NamespaceId';
2122
import {NamespaceInfo} from '../model/namespace/NamespaceInfo';
2223
import {NamespaceName} from '../model/namespace/NamespaceName';
@@ -60,4 +61,18 @@ export interface NamespaceRepository {
6061
* @returns Observable<NamespaceName[]>
6162
*/
6263
getNamespacesName(namespaceIds: NamespaceId[]): Observable<NamespaceName[]>;
64+
65+
/**
66+
* Gets the MosaicId from a MosaicAlias
67+
* @param alias - String containing the address alias
68+
* @returns Observable<MosaicId | null>
69+
*/
70+
getLinkedMosaicId(alias: string): Observable<MosaicId | null>;
71+
72+
/**
73+
* Gets the Address from a AddressAlias
74+
* @param alias - String containing the address alias
75+
* @returnsObservable<Address | null>
76+
*/
77+
getLinkedAddress(alias: string): Observable<Address | null>;
6378
}

0 commit comments

Comments
 (0)