Skip to content

Commit 4075634

Browse files
authored
Restriction endpoint refactoring and finalityPoint renaming (#668)
* refactored restriction endpoints * update package * Renamed finalizationPoint to finalizationEpoch * Fixed doc * more doc fixed
1 parent 90de311 commit 4075634

29 files changed

+397
-425
lines changed

e2e/infrastructure/RestrictionHttp.spec.ts

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { MosaicGlobalRestrictionTransaction } from '../../src/model/transaction/
3535
import { UInt64 } from '../../src/model/UInt64';
3636
import { IntegrationTestHelper } from './IntegrationTestHelper';
3737
import { AddressRestrictionFlag } from '../../src/model/restriction/AddressRestrictionFlag';
38+
import { MosaicAddressRestriction } from '../../src/model/restriction/MosaicAddressRestriction';
3839

3940
describe('RestrictionHttp', () => {
4041
const helper = new IntegrationTestHelper();
@@ -203,66 +204,15 @@ describe('RestrictionHttp', () => {
203204
});
204205
});
205206

206-
describe('getAccountRestrictionsFromAccounts', () => {
207-
it('should call getAccountRestrictionsFromAccounts successfully', async () => {
208-
const accountRestrictions = await restrictionAccountRepository.getAccountRestrictionsFromAccounts([accountAddress]).toPromise();
209-
deepEqual(accountRestrictions[0]!.address, accountAddress);
210-
});
211-
});
212-
213-
describe('getMosaicAddressRestriction', () => {
214-
it('should call getMosaicAddressRestriction successfully', async () => {
215-
const mosaicRestriction = await restrictionMosaicRepository.getMosaicAddressRestriction(mosaicId, account3.address).toPromise();
216-
deepEqual(mosaicRestriction.mosaicId.toHex(), mosaicId.toHex());
217-
deepEqual(mosaicRestriction.entryType, MosaicRestrictionEntryType.ADDRESS);
218-
deepEqual(mosaicRestriction.targetAddress.plain(), account3.address.plain());
219-
deepEqual(mosaicRestriction.restrictions.get(UInt64.fromUint(60641).toString()), UInt64.fromUint(2).toString());
220-
});
221-
});
222-
223-
describe('getMosaicAddressRestrictions', () => {
224-
it('should call getMosaicAddressRestrictions successfully', async () => {
225-
const mosaicRestriction = await restrictionMosaicRepository
226-
.getMosaicAddressRestrictions(mosaicId, [account3.address])
207+
describe('search', () => {
208+
it('should call search successfully', async () => {
209+
const mosaicRestrictionPage = await restrictionMosaicRepository
210+
.searchMosaicRestrictions({ mosaicId, targetAddress: account3.address })
227211
.toPromise();
228-
deepEqual(mosaicRestriction[0].mosaicId.toHex(), mosaicId.toHex());
229-
deepEqual(mosaicRestriction[0].entryType, MosaicRestrictionEntryType.ADDRESS);
230-
deepEqual(mosaicRestriction[0].targetAddress.plain(), account3.address.plain());
231-
deepEqual(mosaicRestriction[0].restrictions.get(UInt64.fromUint(60641).toString()), UInt64.fromUint(2).toString());
232-
});
233-
});
234-
235-
describe('getMosaicGlobalRestriction', () => {
236-
it('should call getMosaicGlobalRestriction successfully', async () => {
237-
const mosaicRestriction = await restrictionMosaicRepository.getMosaicGlobalRestriction(mosaicId).toPromise();
238-
deepEqual(mosaicRestriction.mosaicId.toHex(), mosaicId.toHex());
239-
deepEqual(mosaicRestriction.entryType, MosaicRestrictionEntryType.GLOBAL);
240-
deepEqual(
241-
mosaicRestriction.restrictions.get(UInt64.fromUint(60641).toString())!.referenceMosaicId.toHex(),
242-
new MosaicId(UInt64.fromUint(0).toHex()).toHex(),
243-
);
244-
deepEqual(mosaicRestriction.restrictions.get(UInt64.fromUint(60641).toString())!.restrictionType, MosaicRestrictionType.GE);
245-
deepEqual(
246-
mosaicRestriction.restrictions.get(UInt64.fromUint(60641).toString())!.restrictionValue.toString(),
247-
UInt64.fromUint(0).toString(),
248-
);
249-
});
250-
});
251-
252-
describe('getMosaicGlobalRestrictions', () => {
253-
it('should call getMosaicGlobalRestrictions successfully', async () => {
254-
const mosaicRestriction = await restrictionMosaicRepository.getMosaicGlobalRestrictions([mosaicId]).toPromise();
255-
deepEqual(mosaicRestriction[0].mosaicId.toHex(), mosaicId.toHex());
256-
deepEqual(mosaicRestriction[0].entryType, MosaicRestrictionEntryType.GLOBAL);
257-
deepEqual(
258-
mosaicRestriction[0].restrictions.get(UInt64.fromUint(60641).toString())!.referenceMosaicId.toHex(),
259-
new MosaicId(UInt64.fromUint(0).toHex()).toHex(),
260-
);
261-
deepEqual(mosaicRestriction[0].restrictions.get(UInt64.fromUint(60641).toString())!.restrictionType, MosaicRestrictionType.GE);
262-
deepEqual(
263-
mosaicRestriction[0].restrictions.get(UInt64.fromUint(60641).toString())!.restrictionValue.toString(),
264-
UInt64.fromUint(0).toString(),
265-
);
212+
deepEqual(mosaicRestrictionPage.data[0].mosaicId.toHex(), mosaicId.toHex());
213+
deepEqual(mosaicRestrictionPage.data[0].entryType, MosaicRestrictionEntryType.ADDRESS);
214+
deepEqual((mosaicRestrictionPage.data[0] as MosaicAddressRestriction).targetAddress.plain(), account3.address.plain());
215+
deepEqual(mosaicRestrictionPage.data[0].restrictions.get(UInt64.fromUint(60641).toString()), UInt64.fromUint(2).toString());
266216
});
267217
});
268218

e2e/infrastructure/TransactionHttp.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -732,8 +732,8 @@ describe('TransactionHttp', () => {
732732
const votingLinkTransaction = VotingKeyLinkTransaction.create(
733733
Deadline.create(),
734734
votingKey,
735-
UInt64.fromUint(100),
736-
UInt64.fromUint(300),
735+
100,
736+
300,
737737
LinkAction.Link,
738738
networkType,
739739
helper.maxFee,
@@ -742,8 +742,8 @@ describe('TransactionHttp', () => {
742742

743743
return helper.announce(signedTransaction).then((transaction: VotingKeyLinkTransaction) => {
744744
expect(transaction.linkedPublicKey, 'LinkedPublicKey').not.to.be.undefined;
745-
expect(transaction.startPoint, 'StartPoint').not.to.be.undefined;
746-
expect(transaction.endPoint, 'EndPoint').not.to.be.undefined;
745+
expect(transaction.startEpoch, 'startEpoch').not.to.be.undefined;
746+
expect(transaction.endEpoch, 'endEpoch').not.to.be.undefined;
747747
expect(transaction.linkAction, 'LinkAction').not.to.be.undefined;
748748
return signedTransaction;
749749
});
@@ -754,8 +754,8 @@ describe('TransactionHttp', () => {
754754
const votingLinkTransaction = VotingKeyLinkTransaction.create(
755755
Deadline.create(),
756756
votingKey,
757-
UInt64.fromUint(100),
758-
UInt64.fromUint(300),
757+
100,
758+
300,
759759
LinkAction.Unlink,
760760
networkType,
761761
helper.maxFee,

package-lock.json

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@
8484
},
8585
"dependencies": {
8686
"bluebird": "^3.7.2",
87-
"catbuffer-typescript": "0.0.21",
87+
"catbuffer-typescript": "0.0.22",
8888
"crypto-js": "^4.0.0",
8989
"diff": "^4.0.2",
9090
"futoin-hkdf": "^1.3.1",
@@ -101,7 +101,7 @@
101101
"ripemd160": "^2.0.2",
102102
"rxjs": "^6.5.3",
103103
"rxjs-compat": "^6.5.3",
104-
"symbol-openapi-typescript-fetch-client": "0.9.7-SNAPSHOT.202009100936",
104+
"symbol-openapi-typescript-fetch-client": "0.9.7-SNAPSHOT.202009110940",
105105
"tweetnacl": "^1.0.3",
106106
"utf8": "^3.0.0",
107107
"ws": "^7.2.3"

src/infrastructure/AccountHttp.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,7 @@ export class AccountHttp extends Http implements AccountRepository {
119119
: undefined,
120120
dto.account.supplementalPublicKeys.voting
121121
? dto.account.supplementalPublicKeys.voting?.publicKeys.map(
122-
(v) =>
123-
new AccountLinkVotingKey(
124-
v.publicKey,
125-
UInt64.fromNumericString(v.startPoint),
126-
UInt64.fromNumericString(v.endPoint),
127-
),
122+
(v) => new AccountLinkVotingKey(v.publicKey, v.startEpoch, v.endEpoch),
128123
)
129124
: undefined,
130125
),

src/infrastructure/RepositoryFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export interface RepositoryFactory {
4848

4949
/**
5050
* @returns the generation hash used to sign transactions. Value retrieved from the block/1
51-
* endpoint. This method is cached, the server is only called the first time.
51+
* endEpoch. This method is cached, the server is only called the first time.
5252
*/
5353
getGenerationHash(): Observable<string>;
5454

src/infrastructure/RestrictionAccountHttp.ts

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import { RestrictionAccountRoutesApi } from 'symbol-openapi-typescript-fetch-cli
1919
import { DtoMapping } from '../core/utils/DtoMapping';
2020
import { Address } from '../model/account/Address';
2121
import { AccountRestriction } from '../model/restriction/AccountRestriction';
22-
import { AccountRestrictions } from '../model/restriction/AccountRestrictions';
2322
import { Http } from './Http';
2423
import { RestrictionAccountRepository } from './RestrictionAccountRepository';
2524

@@ -55,20 +54,4 @@ export class RestrictionAccountHttp extends Http implements RestrictionAccountRe
5554
(body) => DtoMapping.extractAccountRestrictionFromDto(body).accountRestrictions.restrictions,
5655
);
5756
}
58-
59-
/**
60-
* Get Account restrictions.
61-
* @param address list of addresses
62-
* @returns Observable<AccountRestrictionsInfo[]>
63-
*/
64-
public getAccountRestrictionsFromAccounts(addresses: Address[]): Observable<AccountRestrictions[]> {
65-
const accountIds = {
66-
addresses: addresses.map((address) => address.plain()),
67-
};
68-
return this.call(this.restrictionAccountRoutesApi.getAccountRestrictionsFromAccounts(accountIds), (body) =>
69-
body.map((restriction) => {
70-
return DtoMapping.extractAccountRestrictionFromDto(restriction).accountRestrictions;
71-
}),
72-
);
73-
}
7457
}

src/infrastructure/RestrictionAccountRepository.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import { Observable } from 'rxjs/internal/Observable';
1818
import { Address } from '../model/account/Address';
1919
import { AccountRestriction } from '../model/restriction/AccountRestriction';
20-
import { AccountRestrictions } from '../model/restriction/AccountRestrictions';
2120

2221
export interface RestrictionAccountRepository {
2322
/**
@@ -26,11 +25,4 @@ export interface RestrictionAccountRepository {
2625
* @returns Observable<AccountRestrictionsInfo>
2726
*/
2827
getAccountRestrictions(address: Address): Observable<AccountRestriction[]>;
29-
30-
/**
31-
* Gets Account restrictions.
32-
* @param addresses list of addresses
33-
* @returns Observable<AccountRestrictionsInfo[]>
34-
*/
35-
getAccountRestrictionsFromAccounts(addresses: Address[]): Observable<AccountRestrictions[]>;
3628
}

src/infrastructure/RestrictionMosaicHttp.ts

Lines changed: 39 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ import { MosaicGlobalRestriction } from '../model/restriction/MosaicGlobalRestri
2727
import { MosaicGlobalRestrictionItem } from '../model/restriction/MosaicGlobalRestrictionItem';
2828
import { Http } from './Http';
2929
import { 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

Comments
 (0)