Skip to content

Commit b024836

Browse files
committed
Added getAccountNames and GetMosaicNames endpoints
1 parent 409941f commit b024836

File tree

10 files changed

+397
-102
lines changed

10 files changed

+397
-102
lines changed

e2e/infrastructure/AccountHttp.spec.ts

Lines changed: 226 additions & 95 deletions
Large diffs are not rendered by default.

e2e/infrastructure/BlockHttp.spec.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ describe('BlockHttp', () => {
5151
});
5252
});
5353

54-
describe('Setup test data', () => {
54+
/**
55+
* =========================
56+
* Setup Test Data
57+
* =========================
58+
*/
59+
60+
describe('Setup Test Data', () => {
5561
let listener: Listener;
5662
before (() => {
5763
listener = new Listener(config.apiUrl);
@@ -61,7 +67,7 @@ describe('BlockHttp', () => {
6167
return listener.close();
6268
});
6369

64-
it('standalone', (done) => {
70+
it('Announce TransferTransaction', (done) => {
6571
const transferTransaction = TransferTransaction.create(
6672
Deadline.create(),
6773
account2.address,

e2e/infrastructure/MosaicHttp.spec.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,13 @@ describe('MosaicHttp', () => {
4545
done();
4646
});
4747
});
48-
describe('MosaicDefinitionTransaction', () => {
48+
49+
/**
50+
* =========================
51+
* Setup Test Data
52+
* =========================
53+
*/
54+
describe('Setup test MosaicId', () => {
4955
let listener: Listener;
5056
before (() => {
5157
listener = new Listener(config.apiUrl);
@@ -54,7 +60,7 @@ describe('MosaicHttp', () => {
5460
after(() => {
5561
return listener.close();
5662
});
57-
it('standalone', (done) => {
63+
it('Announce MosaicDefinitionTransaction', (done) => {
5864
const nonce = MosaicNonce.createRandom();
5965
mosaicId = MosaicId.createFromNonce(nonce, account.publicAccount);
6066
const mosaicDefinitionTransaction = MosaicDefinitionTransaction.create(
@@ -103,4 +109,18 @@ describe('MosaicHttp', () => {
103109
});
104110
});
105111
});
112+
113+
describe('getMosaics', () => {
114+
it('should return mosaics given array of mosaicIds', (done) => {
115+
mosaicHttp.getMosaics([mosaicId])
116+
.subscribe((mosaicInfos) => {
117+
expect(mosaicInfos[0].height.lower).not.to.be.null;
118+
expect(mosaicInfos[0].divisibility).to.be.equal(3);
119+
expect(mosaicInfos[0].isSupplyMutable()).to.be.equal(true);
120+
expect(mosaicInfos[0].isTransferable()).to.be.equal(true);
121+
expect(mosaicInfos[0].isLevyMutable()).to.be.equal(true);
122+
done();
123+
});
124+
});
125+
});
106126
});

src/infrastructure/AccountHttp.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@ import {from as observableFrom, Observable} from 'rxjs';
1919
import {map, mergeMap} from 'rxjs/operators';
2020
import { DtoMapping } from '../core/utils/DtoMapping';
2121
import {AccountInfo} from '../model/account/AccountInfo';
22+
import { AccountNames } from '../model/account/AccountNames';
2223
import { AccountPropertiesInfo } from '../model/account/AccountPropertiesInfo';
2324
import {Address} from '../model/account/Address';
2425
import {MultisigAccountGraphInfo} from '../model/account/MultisigAccountGraphInfo';
2526
import {MultisigAccountInfo} from '../model/account/MultisigAccountInfo';
2627
import {PublicAccount} from '../model/account/PublicAccount';
2728
import {Mosaic} from '../model/mosaic/Mosaic';
2829
import {MosaicId} from '../model/mosaic/MosaicId';
30+
import { NamespaceId } from '../model/namespace/NamespaceId';
2931
import {AggregateTransaction} from '../model/transaction/AggregateTransaction';
3032
import {Transaction} from '../model/transaction/Transaction';
3133
import {UInt64} from '../model/UInt64';
@@ -99,7 +101,7 @@ export class AccountHttp extends Http implements AccountRepository {
99101
*/
100102
public getAccountPropertiesFromAccounts(addresses: Address[]): Observable<AccountPropertiesInfo[]> {
101103
const accountIds = {
102-
addresses: addresses.map((address) => address.plain())
104+
addresses: addresses.map((address) => address.plain()),
103105
};
104106
return observableFrom(
105107
this.accountRoutesApi.getAccountPropertiesFromAccounts(accountIds)).pipe(map((accountProperties) => {
@@ -135,6 +137,22 @@ export class AccountHttp extends Http implements AccountRepository {
135137
}));
136138
}
137139

140+
public getAccountsNames(addresses: Address[]): Observable<AccountNames[]> {
141+
const accountIdsBody = {
142+
addresses: addresses.map((address) => address.plain()),
143+
};
144+
return observableFrom(
145+
this.accountRoutesApi.getAccountsNames(accountIdsBody)).pipe(map((accountNames) => {
146+
return accountNames.map((accountName) => {
147+
return new AccountNames(
148+
Address.createFromEncoded(accountName.address),
149+
accountName.names.map((name) => {
150+
new NamespaceId(name);
151+
}),
152+
);
153+
});
154+
}));
155+
}
138156
/**
139157
* Gets a MultisigAccountInfo for an account.
140158
* @param address - User address

src/infrastructure/AccountRepository.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import {AggregateTransaction} from '../model/transaction/AggregateTransaction';
2424
import {Transaction} from '../model/transaction/Transaction';
2525
import {QueryParams} from './QueryParams';
2626
import {AccountPropertiesInfo} from "../model/account/AccountPropertiesInfo";
27+
import { AccountNames } from '../model/account/AccountNames';
2728

2829
/**
2930
* Account interface repository.
@@ -46,6 +47,14 @@ export interface AccountRepository {
4647
*/
4748
getAccountsInfo(addresses: Address[]): Observable<AccountInfo[]>;
4849

50+
/**
51+
* Get readable names for a set of accountIds.
52+
* Returns friendly names for accounts.
53+
* @param accountIds List of Address
54+
* @return Observable<AccountNames>
55+
*/
56+
getAccountsNames(accountIds: Address[]): Observable<AccountNames[]>;
57+
4958
/**
5059
* Gets Account property.
5160
* @param publicAccount public account

src/infrastructure/MosaicHttp.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ import {map, mergeMap} from 'rxjs/operators';
2020
import {PublicAccount} from '../model/account/PublicAccount';
2121
import {MosaicId} from '../model/mosaic/MosaicId';
2222
import {MosaicInfo} from '../model/mosaic/MosaicInfo';
23+
import { MosaicNames } from '../model/mosaic/MosaicNames';
2324
import {MosaicProperties} from '../model/mosaic/MosaicProperties';
2425
import {NamespaceId} from '../model/namespace/NamespaceId';
2526
import {UInt64} from '../model/UInt64';
2627
import {Http} from './Http';
2728
import {MosaicRepository} from './MosaicRepository';
2829
import {NetworkHttp} from './NetworkHttp';
29-
import {QueryParams} from './QueryParams';
3030

3131
/**
3232
* Mosaic http repository.
@@ -107,4 +107,27 @@ export class MosaicHttp extends Http implements MosaicRepository {
107107
});
108108
}))));
109109
}
110+
111+
/**
112+
* Get readable names for a set of mosaics
113+
* Returns friendly names for mosaics.
114+
* @param mosaicIds - Array of mosaic ids
115+
* @return Observable<MosaicNames[]>
116+
*/
117+
public getMosaicsNames(mosaicIds: MosaicId[]): Observable<MosaicNames[]> {
118+
const mosaicIdsBody = {
119+
mosaicIds: mosaicIds.map((id) => id.toHex()),
120+
};
121+
return observableFrom(
122+
this.mosaicRoutesApi.getMosaicsNames(mosaicIdsBody)).pipe(map((mosaics) => {
123+
return mosaics.map((mosaic) => {
124+
return new MosaicNames(
125+
new MosaicId(mosaic.mosaicId),
126+
mosaic.names.map((name) => {
127+
new NamespaceId(name);
128+
}),
129+
);
130+
});
131+
}));
132+
}
110133
}

src/infrastructure/MosaicRepository.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import {Observable} from 'rxjs';
1818
import {MosaicId} from '../model/mosaic/MosaicId';
1919
import {MosaicInfo} from '../model/mosaic/MosaicInfo';
20-
import {QueryParams} from './QueryParams';
20+
import { MosaicNames } from '../model/mosaic/MosaicNames';
2121

2222
/**
2323
* Mosaic interface repository.
@@ -39,4 +39,12 @@ export interface MosaicRepository {
3939
* @returns Observable<MosaicInfo[]>
4040
*/
4141
getMosaics(mosaicIds: MosaicId[]): Observable<MosaicInfo[]>;
42+
43+
/**
44+
* Get readable names for a set of mosaics
45+
* Returns friendly names for mosaics.
46+
* @param mosaicIds - Array of mosaic ids
47+
* @return Observable<MosaicNames[]>
48+
*/
49+
getMosaicsNames(mosaicIds: MosaicId[]): Observable<MosaicNames[]>;
4250
}

src/model/account/AccountNames.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2018 NEM
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { NamespaceId } from '../namespace/NamespaceId';
18+
import {Address} from './Address';
19+
20+
/**
21+
* Account with linked names
22+
*/
23+
export class AccountNames {
24+
25+
/**
26+
*
27+
*/
28+
constructor(
29+
/**
30+
* Address of the account.
31+
*/
32+
public readonly address: Address,
33+
/**
34+
* Address linked namespace names
35+
*/
36+
public readonly names: NamespaceId[]) {
37+
38+
}
39+
}

src/model/model.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export * from './account/AccountPropertiesInfo';
2929
export * from './account/AccountProperty';
3030
export * from './account/PropertyModificationType';
3131
export * from './account/PropertyType';
32+
export * from './account/AccountNames';
3233

3334
// Blockchain
3435
export * from './blockchain/BlockchainScore';
@@ -53,6 +54,7 @@ export * from '../service/MosaicView';
5354
export * from '../service/MosaicAmountView';
5455
export * from './mosaic/NetworkCurrencyMosaic';
5556
export * from './mosaic/NetworkHarvestMosaic';
57+
export * from './mosaic/MosaicNames';
5658

5759
// Namespace
5860
export * from '../service/Namespace';

src/model/mosaic/MosaicNames.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2018 NEM
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { NamespaceId } from '../namespace/NamespaceId';
18+
import { MosaicId } from './MosaicId';
19+
20+
/**
21+
* Mosaic with linked names
22+
*/
23+
export class MosaicNames {
24+
25+
/**
26+
*
27+
*/
28+
constructor(
29+
/**
30+
* Mosaic Id
31+
*/
32+
public readonly mosaicId: MosaicId,
33+
/**
34+
* Address linked namespace names
35+
*/
36+
public readonly names: string[]) {
37+
38+
}
39+
}

0 commit comments

Comments
 (0)