Skip to content

Commit 9acd0dc

Browse files
rg911fboucquez
andauthored
Split AccountRestrctionFlags into 3 specific flags (#573)
* Fixed #568 Split AccountRestrctionFlags into 3 specific flags * Listener (WS) refactoring (#570) * Fixed #569 - Listener filter on recipientAddress and target addresses (publicKeys) - Now resolving alias * Improved listener: 1) Added transaction hashes to the subscription 2) Reused methods when subscriptions are the same 3) Improved how aliases are loaded (lazy on demand) * Refactored regard PR feedbacks * typo fixed * Bugs fixed to use super.isSigned Co-authored-by: fernando <fboucquez@gmail.com> * Patched with latest catbuffer and openAPI (#576) * Fixed #575 - Patched with latest catbuffer and openAPI * Fixed typo * Fixed #568 Split AccountRestrctionFlags into 3 specific flags * Fixed rebase conflicts * Updated alpha version Co-authored-by: fernando <fboucquez@gmail.com>
1 parent 4d287e8 commit 9acd0dc

23 files changed

+229
-254
lines changed

e2e/infrastructure/RestrictionHttp.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import { MosaicFlags } from '../../src/model/mosaic/MosaicFlags';
2424
import { MosaicId } from '../../src/model/mosaic/MosaicId';
2525
import { MosaicNonce } from '../../src/model/mosaic/MosaicNonce';
2626
import { NetworkType } from '../../src/model/network/NetworkType';
27-
import { AccountRestrictionFlags } from '../../src/model/restriction/AccountRestrictionType';
2827
import { MosaicRestrictionEntryType } from '../../src/model/restriction/MosaicRestrictionEntryType';
2928
import { MosaicRestrictionType } from '../../src/model/restriction/MosaicRestrictionType';
3029
import { AccountRestrictionTransaction } from '../../src/model/transaction/AccountRestrictionTransaction';
@@ -35,6 +34,7 @@ import { MosaicDefinitionTransaction } from '../../src/model/transaction/MosaicD
3534
import { MosaicGlobalRestrictionTransaction } from '../../src/model/transaction/MosaicGlobalRestrictionTransaction';
3635
import { UInt64 } from '../../src/model/UInt64';
3736
import { IntegrationTestHelper } from './IntegrationTestHelper';
37+
import { AddressRestrictionFlag } from '../../src/model/model';
3838

3939
describe('RestrictionHttp', () => {
4040
const helper = new IntegrationTestHelper();
@@ -114,7 +114,7 @@ describe('RestrictionHttp', () => {
114114
it('Announce AccountRestrictionTransaction', () => {
115115
const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
116116
Deadline.create(),
117-
AccountRestrictionFlags.AllowIncomingAddress,
117+
AddressRestrictionFlag.AllowIncomingAddress,
118118
[account3.address],
119119
[],
120120
networkType,
@@ -275,7 +275,7 @@ describe('RestrictionHttp', () => {
275275
it('Announce AccountRestrictionTransaction', () => {
276276
const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
277277
Deadline.create(),
278-
AccountRestrictionFlags.AllowIncomingAddress,
278+
AddressRestrictionFlag.AllowIncomingAddress,
279279
[],
280280
[account3.address],
281281
networkType,

e2e/infrastructure/TransactionHttp.spec.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import { AliasAction } from '../../src/model/namespace/AliasAction';
3333
import { NamespaceId } from '../../src/model/namespace/NamespaceId';
3434
import { NetworkType } from '../../src/model/network/NetworkType';
3535
import { AccountRestrictionModificationAction } from '../../src/model/restriction/AccountRestrictionModificationAction';
36-
import { AccountRestrictionFlags } from '../../src/model/restriction/AccountRestrictionType';
3736
import { MosaicRestrictionType } from '../../src/model/restriction/MosaicRestrictionType';
3837
import { AccountAddressRestrictionTransaction } from '../../src/model/transaction/AccountAddressRestrictionTransaction';
3938
import { AccountKeyLinkTransaction } from '../../src/model/transaction/AccountKeyLinkTransaction';
@@ -69,6 +68,7 @@ import { LockHashUtils } from '../../src/core/utils/LockHashUtils';
6968
import { VrfKeyLinkTransaction } from '../../src/model/transaction/VrfKeyLinkTransaction';
7069
import { VotingKeyLinkTransaction } from '../../src/model/transaction/VotingKeyLinkTransaction';
7170
import { NodeKeyLinkTransaction } from '../../src/model/transaction/NodeKeyLinkTransaction';
71+
import { AddressRestrictionFlag, MosaicRestrictionFlag, OperationRestrictionFlag } from '../../src/model/model';
7272

7373
// eslint-disable-next-line @typescript-eslint/no-var-requires
7474
const CryptoJS = require('crypto-js');
@@ -429,7 +429,7 @@ describe('TransactionHttp', () => {
429429
it('standalone', () => {
430430
const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
431431
Deadline.create(),
432-
AccountRestrictionFlags.BlockOutgoingAddress,
432+
AddressRestrictionFlag.BlockOutgoingAddress,
433433
[account3.address],
434434
[],
435435
networkType,
@@ -447,7 +447,7 @@ describe('TransactionHttp', () => {
447447
it('aggregate', () => {
448448
const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
449449
Deadline.create(),
450-
AccountRestrictionFlags.BlockOutgoingAddress,
450+
AddressRestrictionFlag.BlockOutgoingAddress,
451451
[],
452452
[account3.address],
453453
networkType,
@@ -469,7 +469,7 @@ describe('TransactionHttp', () => {
469469
it('standalone', () => {
470470
const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
471471
Deadline.create(),
472-
AccountRestrictionFlags.BlockIncomingAddress,
472+
AddressRestrictionFlag.BlockIncomingAddress,
473473
[account3.address],
474474
[],
475475
networkType,
@@ -483,7 +483,7 @@ describe('TransactionHttp', () => {
483483
it('aggregate', () => {
484484
const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
485485
Deadline.create(),
486-
AccountRestrictionFlags.BlockIncomingAddress,
486+
AddressRestrictionFlag.BlockIncomingAddress,
487487
[],
488488
[account3.address],
489489
networkType,
@@ -505,7 +505,7 @@ describe('TransactionHttp', () => {
505505
AccountRestrictionModification.createForMosaic(AccountRestrictionModificationAction.Add, mosaicId);
506506
const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction(
507507
Deadline.create(),
508-
AccountRestrictionFlags.BlockMosaic,
508+
MosaicRestrictionFlag.BlockMosaic,
509509
[mosaicId],
510510
[],
511511
networkType,
@@ -524,7 +524,7 @@ describe('TransactionHttp', () => {
524524
it('aggregate', () => {
525525
const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction(
526526
Deadline.create(),
527-
AccountRestrictionFlags.BlockMosaic,
527+
MosaicRestrictionFlag.BlockMosaic,
528528
[],
529529
[mosaicId],
530530
networkType,
@@ -547,7 +547,7 @@ describe('TransactionHttp', () => {
547547
AccountRestrictionModification.createForOperation(AccountRestrictionModificationAction.Add, TransactionType.ACCOUNT_KEY_LINK);
548548
const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction(
549549
Deadline.create(),
550-
AccountRestrictionFlags.BlockOutgoingTransactionType,
550+
OperationRestrictionFlag.BlockOutgoingTransactionType,
551551
[TransactionType.ACCOUNT_KEY_LINK],
552552
[],
553553
networkType,
@@ -566,7 +566,7 @@ describe('TransactionHttp', () => {
566566
it('aggregate', () => {
567567
const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction(
568568
Deadline.create(),
569-
AccountRestrictionFlags.BlockOutgoingTransactionType,
569+
OperationRestrictionFlag.BlockOutgoingTransactionType,
570570
[],
571571
[TransactionType.ACCOUNT_KEY_LINK],
572572
networkType,

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "symbol-sdk",
3-
"version": "0.19.0",
3+
"version": "0.19.1",
44
"description": "Reactive symbol sdk for typescript and javascript",
55
"scripts": {
66
"pretest": "npm run build",

src/core/utils/DtoMapping.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { MosaicId } from '../../model/mosaic/MosaicId';
1919
import { AccountRestriction } from '../../model/restriction/AccountRestriction';
2020
import { AccountRestrictions } from '../../model/restriction/AccountRestrictions';
2121
import { AccountRestrictionsInfo } from '../../model/restriction/AccountRestrictionsInfo';
22-
import { AccountRestrictionFlags } from '../../model/restriction/AccountRestrictionType';
22+
import { AddressRestrictionFlag, MosaicRestrictionFlag, OperationRestrictionFlag } from '../../model/model';
2323

2424
export class DtoMapping {
2525
/**
@@ -34,22 +34,22 @@ export class DtoMapping {
3434
Address.createFromEncoded(accountRestrictions.accountRestrictions.address),
3535
accountRestrictions.accountRestrictions.restrictions.map((prop) => {
3636
switch (prop.restrictionFlags) {
37-
case AccountRestrictionFlags.AllowIncomingAddress:
38-
case AccountRestrictionFlags.BlockIncomingAddress:
39-
case AccountRestrictionFlags.AllowOutgoingAddress:
40-
case AccountRestrictionFlags.BlockOutgoingAddress:
37+
case AddressRestrictionFlag.AllowIncomingAddress:
38+
case AddressRestrictionFlag.BlockIncomingAddress:
39+
case AddressRestrictionFlag.AllowOutgoingAddress:
40+
case AddressRestrictionFlag.BlockOutgoingAddress:
4141
return new AccountRestriction(
4242
prop.restrictionFlags,
4343
prop.values.map((value) => Address.createFromEncoded(value)),
4444
);
45-
case AccountRestrictionFlags.AllowMosaic:
46-
case AccountRestrictionFlags.BlockMosaic:
45+
case MosaicRestrictionFlag.AllowMosaic:
46+
case MosaicRestrictionFlag.BlockMosaic:
4747
return new AccountRestriction(
4848
prop.restrictionFlags,
4949
prop.values.map((value) => new MosaicId(value)),
5050
);
51-
case AccountRestrictionFlags.AllowOutgoingTransactionType:
52-
case AccountRestrictionFlags.BlockOutgoingTransactionType:
51+
case OperationRestrictionFlag.AllowOutgoingTransactionType:
52+
case OperationRestrictionFlag.BlockOutgoingTransactionType:
5353
return new AccountRestriction(prop.restrictionFlags, prop.values);
5454
default:
5555
throw new Error(`Invalid restriction type: ${prop.restrictionFlags}`);

src/model/model.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,9 @@ export * from './restriction/AccountRestrictions';
123123
export * from './restriction/AccountRestrictionsInfo';
124124
export * from './restriction/AccountRestriction';
125125
export * from './restriction/AccountRestrictionModificationAction';
126-
export * from './restriction/AccountRestrictionType';
126+
export * from './restriction/AddressRestrictionFlag';
127+
export * from './restriction/MosaicRestrictionFlag';
128+
export * from './restriction/OperationRestrictionFlag';
127129
export * from './restriction/MosaicRestrictionType';
128130
export * from './restriction/MosaicAddressRestriction';
129131
export * from './restriction/MosaicGlobalRestriction';

src/model/restriction/AccountRestriction.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@
1414
* limitations under the License.
1515
*/
1616

17-
import { AccountRestrictionFlags } from './AccountRestrictionType';
17+
import { OperationRestrictionFlag } from './OperationRestrictionFlag';
18+
import { AddressRestrictionFlag } from './AddressRestrictionFlag';
19+
import { MosaicRestrictionFlag } from './MosaicRestrictionFlag';
20+
1821
/**
1922
* Account restriction structure describes restriction information.
2023
*/
@@ -26,9 +29,9 @@ export class AccountRestriction {
2629
*/
2730
constructor(
2831
/**
29-
* Account restriction type
32+
* Account restriction flag
3033
*/
31-
public readonly restrictionFlags: AccountRestrictionFlags,
34+
public readonly restrictionFlags: AddressRestrictionFlag | MosaicRestrictionFlag | OperationRestrictionFlag,
3235
/**
3336
* Restriction values.
3437
*/

src/model/restriction/AccountRestrictionType.ts

Lines changed: 0 additions & 77 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2020 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 { RestrictionFlag } from './RestrictionFlag';
18+
19+
export enum AddressRestrictionFlag {
20+
/**
21+
* Allow only incoming transactions from a given address.
22+
*/
23+
AllowIncomingAddress = RestrictionFlag.Address,
24+
25+
/**
26+
* Allow only outgoing transactions to a given address.
27+
*/
28+
AllowOutgoingAddress = RestrictionFlag.Address + RestrictionFlag.Outgoing,
29+
30+
/**
31+
* Block incoming transactions from a given address.
32+
*/
33+
BlockIncomingAddress = RestrictionFlag.Address + RestrictionFlag.Block,
34+
35+
/**
36+
* Block outgoing transactions from a given address.
37+
*/
38+
BlockOutgoingAddress = RestrictionFlag.Address + RestrictionFlag.Block + RestrictionFlag.Outgoing,
39+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright 2020 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 { RestrictionFlag } from './RestrictionFlag';
18+
19+
export enum MosaicRestrictionFlag {
20+
/**
21+
* Allow only incoming transactions containing a a given mosaic identifier.
22+
*/
23+
AllowMosaic = RestrictionFlag.Mosaic,
24+
25+
/**
26+
* Block incoming transactions containing a given mosaic identifier.
27+
*/
28+
BlockMosaic = RestrictionFlag.Mosaic + RestrictionFlag.Block,
29+
}

0 commit comments

Comments
 (0)