Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 9 additions & 59 deletions e2e/infrastructure/RestrictionHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { MosaicGlobalRestrictionTransaction } from '../../src/model/transaction/
import { UInt64 } from '../../src/model/UInt64';
import { IntegrationTestHelper } from './IntegrationTestHelper';
import { AddressRestrictionFlag } from '../../src/model/restriction/AddressRestrictionFlag';
import { MosaicAddressRestriction } from '../../src/model/restriction/MosaicAddressRestriction';

describe('RestrictionHttp', () => {
const helper = new IntegrationTestHelper();
Expand Down Expand Up @@ -203,66 +204,15 @@ describe('RestrictionHttp', () => {
});
});

describe('getAccountRestrictionsFromAccounts', () => {
it('should call getAccountRestrictionsFromAccounts successfully', async () => {
const accountRestrictions = await restrictionAccountRepository.getAccountRestrictionsFromAccounts([accountAddress]).toPromise();
deepEqual(accountRestrictions[0]!.address, accountAddress);
});
});

describe('getMosaicAddressRestriction', () => {
it('should call getMosaicAddressRestriction successfully', async () => {
const mosaicRestriction = await restrictionMosaicRepository.getMosaicAddressRestriction(mosaicId, account3.address).toPromise();
deepEqual(mosaicRestriction.mosaicId.toHex(), mosaicId.toHex());
deepEqual(mosaicRestriction.entryType, MosaicRestrictionEntryType.ADDRESS);
deepEqual(mosaicRestriction.targetAddress.plain(), account3.address.plain());
deepEqual(mosaicRestriction.restrictions.get(UInt64.fromUint(60641).toString()), UInt64.fromUint(2).toString());
});
});

describe('getMosaicAddressRestrictions', () => {
it('should call getMosaicAddressRestrictions successfully', async () => {
const mosaicRestriction = await restrictionMosaicRepository
.getMosaicAddressRestrictions(mosaicId, [account3.address])
describe('search', () => {
it('should call search successfully', async () => {
const mosaicRestrictionPage = await restrictionMosaicRepository
.searchMosaicRestrictions({ mosaicId, targetAddress: account3.address })
.toPromise();
deepEqual(mosaicRestriction[0].mosaicId.toHex(), mosaicId.toHex());
deepEqual(mosaicRestriction[0].entryType, MosaicRestrictionEntryType.ADDRESS);
deepEqual(mosaicRestriction[0].targetAddress.plain(), account3.address.plain());
deepEqual(mosaicRestriction[0].restrictions.get(UInt64.fromUint(60641).toString()), UInt64.fromUint(2).toString());
});
});

describe('getMosaicGlobalRestriction', () => {
it('should call getMosaicGlobalRestriction successfully', async () => {
const mosaicRestriction = await restrictionMosaicRepository.getMosaicGlobalRestriction(mosaicId).toPromise();
deepEqual(mosaicRestriction.mosaicId.toHex(), mosaicId.toHex());
deepEqual(mosaicRestriction.entryType, MosaicRestrictionEntryType.GLOBAL);
deepEqual(
mosaicRestriction.restrictions.get(UInt64.fromUint(60641).toString())!.referenceMosaicId.toHex(),
new MosaicId(UInt64.fromUint(0).toHex()).toHex(),
);
deepEqual(mosaicRestriction.restrictions.get(UInt64.fromUint(60641).toString())!.restrictionType, MosaicRestrictionType.GE);
deepEqual(
mosaicRestriction.restrictions.get(UInt64.fromUint(60641).toString())!.restrictionValue.toString(),
UInt64.fromUint(0).toString(),
);
});
});

describe('getMosaicGlobalRestrictions', () => {
it('should call getMosaicGlobalRestrictions successfully', async () => {
const mosaicRestriction = await restrictionMosaicRepository.getMosaicGlobalRestrictions([mosaicId]).toPromise();
deepEqual(mosaicRestriction[0].mosaicId.toHex(), mosaicId.toHex());
deepEqual(mosaicRestriction[0].entryType, MosaicRestrictionEntryType.GLOBAL);
deepEqual(
mosaicRestriction[0].restrictions.get(UInt64.fromUint(60641).toString())!.referenceMosaicId.toHex(),
new MosaicId(UInt64.fromUint(0).toHex()).toHex(),
);
deepEqual(mosaicRestriction[0].restrictions.get(UInt64.fromUint(60641).toString())!.restrictionType, MosaicRestrictionType.GE);
deepEqual(
mosaicRestriction[0].restrictions.get(UInt64.fromUint(60641).toString())!.restrictionValue.toString(),
UInt64.fromUint(0).toString(),
);
deepEqual(mosaicRestrictionPage.data[0].mosaicId.toHex(), mosaicId.toHex());
deepEqual(mosaicRestrictionPage.data[0].entryType, MosaicRestrictionEntryType.ADDRESS);
deepEqual((mosaicRestrictionPage.data[0] as MosaicAddressRestriction).targetAddress.plain(), account3.address.plain());
deepEqual(mosaicRestrictionPage.data[0].restrictions.get(UInt64.fromUint(60641).toString()), UInt64.fromUint(2).toString());
});
});

Expand Down
12 changes: 6 additions & 6 deletions e2e/infrastructure/TransactionHttp.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -732,8 +732,8 @@ describe('TransactionHttp', () => {
const votingLinkTransaction = VotingKeyLinkTransaction.create(
Deadline.create(),
votingKey,
UInt64.fromUint(100),
UInt64.fromUint(300),
100,
300,
LinkAction.Link,
networkType,
helper.maxFee,
Expand All @@ -742,8 +742,8 @@ describe('TransactionHttp', () => {

return helper.announce(signedTransaction).then((transaction: VotingKeyLinkTransaction) => {
expect(transaction.linkedPublicKey, 'LinkedPublicKey').not.to.be.undefined;
expect(transaction.startPoint, 'StartPoint').not.to.be.undefined;
expect(transaction.endPoint, 'EndPoint').not.to.be.undefined;
expect(transaction.startEpoch, 'startEpoch').not.to.be.undefined;
expect(transaction.endEpoch, 'endEpoch').not.to.be.undefined;
expect(transaction.linkAction, 'LinkAction').not.to.be.undefined;
return signedTransaction;
});
Expand All @@ -754,8 +754,8 @@ describe('TransactionHttp', () => {
const votingLinkTransaction = VotingKeyLinkTransaction.create(
Deadline.create(),
votingKey,
UInt64.fromUint(100),
UInt64.fromUint(300),
100,
300,
LinkAction.Unlink,
networkType,
helper.maxFee,
Expand Down
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
},
"dependencies": {
"bluebird": "^3.7.2",
"catbuffer-typescript": "0.0.21",
"catbuffer-typescript": "0.0.22",
"crypto-js": "^4.0.0",
"diff": "^4.0.2",
"futoin-hkdf": "^1.3.1",
Expand All @@ -101,7 +101,7 @@
"ripemd160": "^2.0.2",
"rxjs": "^6.5.3",
"rxjs-compat": "^6.5.3",
"symbol-openapi-typescript-fetch-client": "0.9.7-SNAPSHOT.202009100936",
"symbol-openapi-typescript-fetch-client": "0.9.7-SNAPSHOT.202009110940",
"tweetnacl": "^1.0.3",
"utf8": "^3.0.0",
"ws": "^7.2.3"
Expand Down
7 changes: 1 addition & 6 deletions src/infrastructure/AccountHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,7 @@ export class AccountHttp extends Http implements AccountRepository {
: undefined,
dto.account.supplementalPublicKeys.voting
? dto.account.supplementalPublicKeys.voting?.publicKeys.map(
(v) =>
new AccountLinkVotingKey(
v.publicKey,
UInt64.fromNumericString(v.startPoint),
UInt64.fromNumericString(v.endPoint),
),
(v) => new AccountLinkVotingKey(v.publicKey, v.startEpoch, v.endEpoch),
)
: undefined,
),
Expand Down
2 changes: 1 addition & 1 deletion src/infrastructure/RepositoryFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export interface RepositoryFactory {

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

Expand Down
17 changes: 0 additions & 17 deletions src/infrastructure/RestrictionAccountHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { RestrictionAccountRoutesApi } from 'symbol-openapi-typescript-fetch-cli
import { DtoMapping } from '../core/utils/DtoMapping';
import { Address } from '../model/account/Address';
import { AccountRestriction } from '../model/restriction/AccountRestriction';
import { AccountRestrictions } from '../model/restriction/AccountRestrictions';
import { Http } from './Http';
import { RestrictionAccountRepository } from './RestrictionAccountRepository';

Expand Down Expand Up @@ -55,20 +54,4 @@ export class RestrictionAccountHttp extends Http implements RestrictionAccountRe
(body) => DtoMapping.extractAccountRestrictionFromDto(body).accountRestrictions.restrictions,
);
}

/**
* Get Account restrictions.
* @param address list of addresses
* @returns Observable<AccountRestrictionsInfo[]>
*/
public getAccountRestrictionsFromAccounts(addresses: Address[]): Observable<AccountRestrictions[]> {
const accountIds = {
addresses: addresses.map((address) => address.plain()),
};
return this.call(this.restrictionAccountRoutesApi.getAccountRestrictionsFromAccounts(accountIds), (body) =>
body.map((restriction) => {
return DtoMapping.extractAccountRestrictionFromDto(restriction).accountRestrictions;
}),
);
}
}
8 changes: 0 additions & 8 deletions src/infrastructure/RestrictionAccountRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import { Observable } from 'rxjs/internal/Observable';
import { Address } from '../model/account/Address';
import { AccountRestriction } from '../model/restriction/AccountRestriction';
import { AccountRestrictions } from '../model/restriction/AccountRestrictions';

export interface RestrictionAccountRepository {
/**
Expand All @@ -26,11 +25,4 @@ export interface RestrictionAccountRepository {
* @returns Observable<AccountRestrictionsInfo>
*/
getAccountRestrictions(address: Address): Observable<AccountRestriction[]>;

/**
* Gets Account restrictions.
* @param addresses list of addresses
* @returns Observable<AccountRestrictionsInfo[]>
*/
getAccountRestrictionsFromAccounts(addresses: Address[]): Observable<AccountRestrictions[]>;
}
114 changes: 39 additions & 75 deletions src/infrastructure/RestrictionMosaicHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ import { MosaicGlobalRestriction } from '../model/restriction/MosaicGlobalRestri
import { MosaicGlobalRestrictionItem } from '../model/restriction/MosaicGlobalRestrictionItem';
import { Http } from './Http';
import { RestrictionMosaicRepository } from './RestrictionMosaicRepository';
import { RestrictionMosaicSearchCriteria } from './searchCriteria/RestrictionMosaicSearchCriteria';
import { DtoMapping } from '../core/utils/DtoMapping';
import { Page } from './Page';

/**
* RestrictionMosaic http repository.
Expand All @@ -50,90 +53,51 @@ export class RestrictionMosaicHttp extends Http implements RestrictionMosaicRepo
}

/**
* Get mosaic address restriction.
* @summary Get mosaic address restrictions for a given mosaic and account identifier.
* @param mosaicId Mosaic identifier.
* @param address address
* @returns Observable<MosaicAddressRestriction>
*/
getMosaicAddressRestriction(mosaicId: MosaicId, address: Address): Observable<MosaicAddressRestriction> {
return this.call(this.restrictionMosaicRoutesApi.getMosaicAddressRestriction(mosaicId.toHex(), address.plain()), (body) =>
this.toMosaicAddressRestriction(body),
);
}

/**
* Get mosaic address restrictions.
* @summary Get mosaic address restrictions for a given mosaic and account identifiers array
* @param mosaicId Mosaic identifier.
* @param addresses list of addresses
* @returns Observable<MosaicAddressRestriction[]>
*/
getMosaicAddressRestrictions(mosaicId: MosaicId, addresses: Address[]): Observable<MosaicAddressRestriction[]> {
const accountIds = {
addresses: addresses.map((address) => address.plain()),
};
return this.call(this.restrictionMosaicRoutesApi.getMosaicAddressRestrictions(mosaicId.toHex(), accountIds), (body) =>
body.map(this.toMosaicAddressRestriction),
);
}

/**
* Get mosaic global restriction.
* @summary Get mosaic global restrictions for a given mosaic identifier.
* @param mosaicId Mosaic identifier.
* @returns Observable<MosaicGlobalRestriction>
*/
getMosaicGlobalRestriction(mosaicId: MosaicId): Observable<MosaicGlobalRestriction> {
return this.call(this.restrictionMosaicRoutesApi.getMosaicGlobalRestriction(mosaicId.toHex()), (body) =>
this.toMosaicGlobalRestriction(body),
);
}

/**
* Get mosaic global restrictions.
* @summary Get mosaic global restrictions for a given list of mosaics.
* @param mosaicIds List of mosaic identifier.
* @returns Observable<MosaicGlobalRestriction[]>
*/
getMosaicGlobalRestrictions(mosaicIds: MosaicId[]): Observable<MosaicGlobalRestriction[]> {
const mosaicIdsBody = {
mosaicIds: mosaicIds.map((id) => id.toHex()),
};
return this.call(this.restrictionMosaicRoutesApi.getMosaicGlobalRestrictions(mosaicIdsBody), (body) =>
body.map(this.toMosaicGlobalRestriction),
);
}

/**
* This method maps a MosaicAddressRestrictionDTO from rest to the SDK's MosaicAddressRestriction model object.
* Returns a mosaic restrictions page based on the criteria.
*
* @internal
* @param {MosaicAddressRestrictionDTO} dto the MosaicAddressRestrictionDTO object from rest.
* @returns {MosaicAddressRestriction} a MosaicAddressRestriction model
* @param criteria the criteria
* @return a page of {@link MosaicAddressRestriction | MosaicGlobalRestriction}
*/
private toMosaicAddressRestriction(dto: MosaicAddressRestrictionDTO): MosaicAddressRestriction {
const restrictionItems = new Map<string, string>();
dto.mosaicRestrictionEntry.restrictions.forEach((restriction) => {
restrictionItems.set(restriction.key, restriction.value);
});
return new MosaicAddressRestriction(
dto.mosaicRestrictionEntry.compositeHash,
dto.mosaicRestrictionEntry.entryType.valueOf(),
new MosaicId(dto.mosaicRestrictionEntry.mosaicId),
Address.createFromEncoded(dto.mosaicRestrictionEntry.targetAddress),
restrictionItems,
public searchMosaicRestrictions(
criteria: RestrictionMosaicSearchCriteria,
): Observable<Page<MosaicAddressRestriction | MosaicGlobalRestriction>> {
return this.call(
this.restrictionMosaicRoutesApi.searchMosaicRestriction(
criteria.mosaicId?.toHex(),
criteria.entryType?.valueOf(),
criteria.targetAddress?.plain(),
criteria.pageSize,
criteria.pageNumber,
criteria.offset,
DtoMapping.mapEnum(criteria.order),
),
(body) => super.toPage(body.pagination, body.data, this.toMosaicRestriction),
);
}

/**
* This method maps a MosaicGlobalRestrictionDTO from rest to the SDK's MosaicGlobalRestriction model object.
* This method maps a mosaic restriction dto from rest to the SDK's model object.
*
* @internal
* @param {MosaicGlobalRestrictionDTO} dto the MosaicGlobalRestrictionDTO object from rest.
* @returns {MosaicGlobalRestriction} a MosaicGlobalRestriction model
* @param {MosaicAddressRestrictionDTO | MosaicGlobalRestrictionDTO} dto the restriction object from rest.
* @returns {MosaicAddressRestriction | MosaicGlobalRestriction} a restriction model
*/
private toMosaicGlobalRestriction(dto: MosaicGlobalRestrictionDTO): MosaicGlobalRestriction {
private toMosaicRestriction(
dto: MosaicAddressRestrictionDTO | MosaicGlobalRestrictionDTO,
): MosaicAddressRestriction | MosaicGlobalRestriction {
if ((dto.mosaicRestrictionEntry as any).targetAddress) {
const mosaicAddressrestrictionItems = new Map<string, string>();
dto.mosaicRestrictionEntry.restrictions.forEach((restriction) => {
mosaicAddressrestrictionItems.set(restriction.key, restriction.value);
});
return new MosaicAddressRestriction(
dto.mosaicRestrictionEntry.compositeHash,
dto.mosaicRestrictionEntry.entryType.valueOf(),
new MosaicId(dto.mosaicRestrictionEntry.mosaicId),
Address.createFromEncoded((dto as MosaicAddressRestrictionDTO).mosaicRestrictionEntry.targetAddress),
mosaicAddressrestrictionItems,
);
}
const restirctionItems = new Map<string, MosaicGlobalRestrictionItem>();
dto.mosaicRestrictionEntry.restrictions.forEach((restriction) =>
restirctionItems.set(
Expand Down
Loading