Skip to content

Commit 51f43f5

Browse files
committed
Refactored AccountRestrictionType
1 parent eee44ef commit 51f43f5

File tree

11 files changed

+120
-47
lines changed

11 files changed

+120
-47
lines changed

e2e/infrastructure/AccountHttp.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ describe('AccountHttp', () => {
201201
);
202202
const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
203203
Deadline.create(),
204-
AccountRestrictionType.BlockAddress,
204+
AccountRestrictionType.BlockIncomingAddress,
205205
[addressPropertyFilter],
206206
NetworkType.MIJIN_TEST,
207207
);
@@ -427,7 +427,7 @@ describe('AccountHttp', () => {
427427
);
428428
const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
429429
Deadline.create(),
430-
AccountRestrictionType.BlockAddress,
430+
AccountRestrictionType.BlockIncomingAddress,
431431
[addressPropertyFilter],
432432
NetworkType.MIJIN_TEST,
433433
);

e2e/infrastructure/TransactionHttp.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ describe('TransactionHttp', () => {
404404
);
405405
const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
406406
Deadline.create(),
407-
AccountRestrictionType.BlockAddress,
407+
AccountRestrictionType.BlockIncomingAddress,
408408
[addressRestrictionFilter],
409409
NetworkType.MIJIN_TEST,
410410
);
@@ -441,7 +441,7 @@ describe('TransactionHttp', () => {
441441
);
442442
const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
443443
Deadline.create(),
444-
AccountRestrictionType.BlockAddress,
444+
AccountRestrictionType.BlockIncomingAddress,
445445
[addressRestrictionFilter],
446446
NetworkType.MIJIN_TEST,
447447
);
@@ -554,7 +554,7 @@ describe('TransactionHttp', () => {
554554
);
555555
const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction(
556556
Deadline.create(),
557-
AccountRestrictionType.BlockTransaction,
557+
AccountRestrictionType.BlockIncomingTransactionType,
558558
[operationRestrictionFilter],
559559
NetworkType.MIJIN_TEST,
560560
);
@@ -591,7 +591,7 @@ describe('TransactionHttp', () => {
591591
);
592592
const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction(
593593
Deadline.create(),
594-
AccountRestrictionType.BlockTransaction,
594+
AccountRestrictionType.BlockIncomingTransactionType,
595595
[operationRestrictionFilter],
596596
NetworkType.MIJIN_TEST,
597597
);

src/core/utils/DtoMapping.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,20 @@ export class DtoMapping {
3434
new AccountRestrictions(Address.createFromEncoded(accountRestrictions.accountRestrictions.address),
3535
accountRestrictions.accountRestrictions.restrictions.map((prop) => {
3636
switch (prop.restrictionType) {
37-
case AccountRestrictionType.AllowAddress:
38-
case AccountRestrictionType.BlockAddress:
37+
case AccountRestrictionType.AllowIncomingAddress:
38+
case AccountRestrictionType.BlockIncomingAddress:
39+
case AccountRestrictionType.AllowOutgoingAddress:
40+
case AccountRestrictionType.BlockOutgoingAddress:
3941
return new AccountRestriction(prop.restrictionType,
4042
prop.values.map((value) => Address.createFromEncoded(value)));
4143
case AccountRestrictionType.AllowMosaic:
4244
case AccountRestrictionType.BlockMosaic:
4345
return new AccountRestriction(prop.restrictionType,
4446
prop.values.map((value) => new MosaicId(value)));
45-
case AccountRestrictionType.AllowTransaction:
46-
case AccountRestrictionType.BlockTransaction:
47+
case AccountRestrictionType.AllowIncomingTransactionType:
48+
case AccountRestrictionType.AllowOutgoingTransactionType:
49+
case AccountRestrictionType.BlockIncomingTransactionType:
50+
case AccountRestrictionType.BlockOutgoingTransactionType:
4751
return new AccountRestriction(prop.restrictionType, prop.values);
4852
default:
4953
throw new Error(`Invalid restriction type: ${prop.restrictionType}`);
Lines changed: 76 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Copyright 2019 NEM
33
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* Licensed under the Apache License, Version 2.0 (the "License"),
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
@@ -16,19 +16,82 @@
1616

1717
/**
1818
* Account restriction type
19-
* 0x01 The restriction type is an address.
20-
* 0x02 The restriction type is mosaic id.
21-
* 0x03 The restriction type is a transaction type.
22-
* 0x04 restriction type sentinel.
23-
* 0x80 + type The restriction is interpreted as a blocking operation.
19+
* 0x01 Account restriction type is an address.
20+
* 0x02 Account restriction type is a mosaic id.
21+
* 0x04 Account restriction type is a transaction type.
22+
* 0x05 restriction type sentinel.
23+
* 0x40 Account restriction is interpreted as outgoing restriction.
24+
* 0x80 Account restriction is interpreted as blocking operation.
2425
*/
2526

26-
export enum AccountRestrictionType {
27-
AllowAddress = 0x01,
28-
AllowMosaic = 0x02,
29-
AllowTransaction = 0x04,
27+
// !!This enum will be deprecated once catbuffer code applied.
28+
enum AccountRestrictionTypeEnum {
29+
Address = 0x01,
30+
Mosaic = 0x02,
31+
TransactionType = 0x04,
3032
Sentinel = 0x05,
31-
BlockAddress = (0x80 + 0x01),
32-
BlockMosaic = (0x80 + 0x02),
33-
BlockTransaction = (0x80 + 0x04),
33+
Outgoing = 0x40,
34+
Block = 0x80,
35+
}
36+
37+
export enum AccountRestrictionType {
38+
/**
39+
* Allow only incoming transactions from a given address.
40+
*/
41+
AllowIncomingAddress = AccountRestrictionTypeEnum.Address,
42+
43+
/**
44+
* Allow only incoming transactions containing a a given mosaic identifier.
45+
*/
46+
AllowMosaic = AccountRestrictionTypeEnum.Mosaic,
47+
48+
/**
49+
* Allow only outgoing transactions with a given transaction type.
50+
*/
51+
AllowIncomingTransactionType = AccountRestrictionTypeEnum.TransactionType,
52+
53+
/**
54+
* Allow only outgoing transactions to a given address.
55+
*/
56+
AllowOutgoingAddress = (AccountRestrictionTypeEnum.Address + AccountRestrictionTypeEnum.Outgoing),
57+
58+
/**
59+
* Allow only outgoing transactions with a given transaction type.
60+
*/
61+
AllowOutgoingTransactionType = (AccountRestrictionTypeEnum.TransactionType +
62+
AccountRestrictionTypeEnum.Outgoing),
63+
64+
/**
65+
* Block incoming transactions from a given address.
66+
*/
67+
BlockIncomingAddress = (AccountRestrictionTypeEnum.Address + AccountRestrictionTypeEnum.Block),
68+
69+
/**
70+
* Block incoming transactions containing a given mosaic identifier.
71+
*/
72+
BlockMosaic = (AccountRestrictionTypeEnum.Mosaic + AccountRestrictionTypeEnum.Block),
73+
74+
/**
75+
* Block incoming transactions with a given transaction type.
76+
*/
77+
BlockIncomingTransactionType = (AccountRestrictionTypeEnum.TransactionType +
78+
AccountRestrictionTypeEnum.Block),
79+
80+
/**
81+
* Block outgoing transactions from a given address.
82+
*/
83+
BlockOutgoingAddress = (AccountRestrictionTypeEnum.Address +
84+
AccountRestrictionTypeEnum.Block +
85+
AccountRestrictionTypeEnum.Outgoing),
86+
/**
87+
* Block outgoing transactions with a given transaction type.
88+
*/
89+
BlockOutgoingTransactionType = (AccountRestrictionTypeEnum.TransactionType +
90+
AccountRestrictionTypeEnum.Block +
91+
AccountRestrictionTypeEnum.Outgoing),
92+
93+
/**
94+
* Account restriction sentinel.
95+
*/
96+
Sentinel = AccountRestrictionTypeEnum.Sentinel,
3497
}

src/model/transaction/AccountRestrictionTransaction.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ export class AccountRestrictionTransaction {
4141
networkType: NetworkType,
4242
maxFee: UInt64 = new UInt64([0, 0]),
4343
): AccountAddressRestrictionModificationTransaction {
44-
if (![AccountRestrictionType.AllowAddress, AccountRestrictionType.BlockAddress].includes(restrictionType)) {
44+
if (![AccountRestrictionType.AllowIncomingAddress,
45+
AccountRestrictionType.AllowOutgoingAddress,
46+
AccountRestrictionType.BlockOutgoingAddress,
47+
AccountRestrictionType.BlockIncomingAddress].includes(restrictionType)) {
4548
throw new Error ('Restriction type is not allowed.');
4649
}
4750
return AccountAddressRestrictionModificationTransaction.create(
@@ -69,7 +72,7 @@ export class AccountRestrictionTransaction {
6972
networkType: NetworkType,
7073
maxFee: UInt64 = new UInt64([0, 0]),
7174
): AccountMosaicRestrictionModificationTransaction {
72-
if (![AccountRestrictionType.AllowMosaic, AccountRestrictionType.BlockMosaic].includes(restrictionType)) {
75+
if (![AccountRestrictionType.AllowMosaic,AccountRestrictionType.BlockMosaic].includes(restrictionType)) {
7376
throw new Error ('Restriction type is not allowed.');
7477
}
7578
return AccountMosaicRestrictionModificationTransaction.create(
@@ -97,7 +100,10 @@ export class AccountRestrictionTransaction {
97100
networkType: NetworkType,
98101
maxFee: UInt64 = new UInt64([0, 0]),
99102
): AccountOperationRestrictionModificationTransaction {
100-
if (![AccountRestrictionType.AllowTransaction, AccountRestrictionType.BlockTransaction].includes(restrictionType)) {
103+
if (![AccountRestrictionType.AllowIncomingTransactionType,
104+
AccountRestrictionType.AllowOutgoingTransactionType,
105+
AccountRestrictionType.BlockOutgoingTransactionType,
106+
AccountRestrictionType.BlockOutgoingTransactionType].includes(restrictionType)) {
101107
throw new Error ('Restriction type is not allowed.');
102108
}
103109
return AccountOperationRestrictionModificationTransaction.create(

test/core/utils/TransactionMapping.spec.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ describe('TransactionMapping - createFromPayload', () => {
7979
);
8080
const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
8181
Deadline.create(),
82-
AccountRestrictionType.AllowAddress,
82+
AccountRestrictionType.AllowIncomingAddress,
8383
[addressRestrictionFilter],
8484
NetworkType.MIJIN_TEST,
8585
);
@@ -89,7 +89,7 @@ describe('TransactionMapping - createFromPayload', () => {
8989
const transaction = TransactionMapping
9090
.createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction;
9191

92-
expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowAddress);
92+
expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress);
9393
expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add);
9494
expect(transaction.modifications[0].value).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC');
9595
});
@@ -125,7 +125,7 @@ describe('TransactionMapping - createFromPayload', () => {
125125
);
126126
const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction(
127127
Deadline.create(),
128-
AccountRestrictionType.AllowTransaction,
128+
AccountRestrictionType.AllowIncomingTransactionType,
129129
[operationRestrictionFilter],
130130
NetworkType.MIJIN_TEST,
131131
);
@@ -134,7 +134,7 @@ describe('TransactionMapping - createFromPayload', () => {
134134

135135
const transaction = TransactionMapping
136136
.createFromPayload(signedTransaction.payload) as AccountAddressRestrictionModificationTransaction;
137-
expect(transaction.restrictionType).to.be.equal(RestrictionType.AllowTransaction);
137+
expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingTransactionType);
138138
expect(transaction.modifications[0].value).to.be.equal(operation);
139139
expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add);
140140
});
@@ -666,7 +666,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () =>
666666
);
667667
const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
668668
Deadline.create(),
669-
AccountRestrictionType.AllowAddress,
669+
AccountRestrictionType.AllowIncomingAddress,
670670
[addressRestrictionFilter],
671671
NetworkType.MIJIN_TEST,
672672
);
@@ -675,7 +675,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () =>
675675
TransactionMapping.createFromDTO(addressRestrictionTransaction.toJSON()) as AccountAddressRestrictionModificationTransaction;
676676

677677
expect(transaction.modifications[0].value).to.be.equal('SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC');
678-
expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowAddress);
678+
expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress);
679679
expect(transaction.modifications[0].modificationType).to.be.equal(RestrictionModificationType.Add);
680680
});
681681

@@ -708,7 +708,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () =>
708708
);
709709
const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction(
710710
Deadline.create(),
711-
AccountRestrictionType.AllowTransaction,
711+
AccountRestrictionType.AllowIncomingTransactionType,
712712
[operationRestrictionFilter],
713713
NetworkType.MIJIN_TEST,
714714
);
@@ -717,7 +717,7 @@ describe('TransactionMapping - createFromDTO (Transaction.toJSON() feed)', () =>
717717
TransactionMapping.createFromDTO(operationRestrictionTransaction.toJSON()) as AccountMosaicRestrictionModificationTransaction;
718718

719719
expect(transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION);
720-
expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowTransaction);
720+
expect(transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingTransactionType);
721721
expect(transaction.modifications.length).to.be.equal(1);
722722
});
723723

test/infrastructure/SerializeTransactionToJSON.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ describe('SerializeTransactionToJSON', () => {
8383
);
8484
const addressRestrictionTransaction = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
8585
Deadline.create(),
86-
AccountRestrictionType.AllowAddress,
86+
AccountRestrictionType.AllowIncomingAddress,
8787
[addressRestrictionFilter],
8888
NetworkType.MIJIN_TEST,
8989
);
9090

9191
const json = addressRestrictionTransaction.toJSON();
9292

9393
expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_ADDRESS);
94-
expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowAddress);
94+
expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingAddress);
9595
expect(json.transaction.modifications.length).to.be.equal(1);
9696
});
9797

@@ -123,15 +123,15 @@ describe('SerializeTransactionToJSON', () => {
123123
);
124124
const operationRestrictionTransaction = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction(
125125
Deadline.create(),
126-
AccountRestrictionType.AllowTransaction,
126+
AccountRestrictionType.AllowIncomingTransactionType,
127127
[operationRestrictionFilter],
128128
NetworkType.MIJIN_TEST,
129129
);
130130

131131
const json = operationRestrictionTransaction.toJSON();
132132

133133
expect(json.transaction.type).to.be.equal(TransactionType.MODIFY_ACCOUNT_RESTRICTION_OPERATION);
134-
expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowTransaction);
134+
expect(json.transaction.restrictionType).to.be.equal(AccountRestrictionType.AllowIncomingTransactionType);
135135
expect(json.transaction.modifications.length).to.be.equal(1);
136136
});
137137

test/model/account/AccountRestriction.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ describe('AccountRestriction', () => {
2323

2424
it('should createComplete an AccountRestriction object', () => {
2525
const accountRestrictionDTO = {
26-
restrictionType: AccountRestrictionType.AllowAddress,
26+
restrictionType: AccountRestrictionType.AllowIncomingAddress,
2727
values: ['906415867F121D037AF447E711B0F5E4D52EBBF066D96860EB'],
2828
};
2929

test/model/account/AccountRestrictions.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe('AccountRestrictions', () => {
2525
const accountRestrictionsDTO = {
2626
address: Address.createFromEncoded('9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142'),
2727
restrictions: [{
28-
restrictionType: AccountRestrictionType.AllowAddress,
28+
restrictionType: AccountRestrictionType.AllowIncomingAddress,
2929
values: [{modificationType: RestrictionModificationType.Add,
3030
value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM',
3131
}],

test/model/account/AccountRestrictionsInfo.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ describe('AccountRestrictionsInfo', () => {
3131
accountRestrictions: {
3232
address: '9050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E142',
3333
restrictions: [{
34-
restrictionType: AccountRestrictionType.AllowAddress,
34+
restrictionType: AccountRestrictionType.AllowIncomingAddress,
3535
values: [{modificationType: RestrictionModificationType.Add,
3636
value: 'SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM',
3737
}],

0 commit comments

Comments
 (0)