Skip to content

Commit 60c4e9c

Browse files
authored
Merge pull request #222 from rg911/task/g218_block_outgoing_account_restriction
Block outgoing account restriction
2 parents 433fc74 + 7ac0505 commit 60c4e9c

17 files changed

+478
-130
lines changed

e2e/infrastructure/AccountHttp.spec.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@ import {assert, expect} from 'chai';
1919
import {AccountHttp} from '../../src/infrastructure/AccountHttp';
2020
import { Listener, TransactionHttp } from '../../src/infrastructure/infrastructure';
2121
import { Account } from '../../src/model/account/Account';
22+
import { AccountRestrictionType } from '../../src/model/account/AccountRestrictionType';
2223
import {Address} from '../../src/model/account/Address';
2324
import {PublicAccount} from '../../src/model/account/PublicAccount';
2425
import { RestrictionModificationType } from '../../src/model/account/RestrictionModificationType';
25-
import { RestrictionType } from '../../src/model/account/RestrictionType';
2626
import {NetworkType} from '../../src/model/blockchain/NetworkType';
2727
import { NetworkCurrencyMosaic } from '../../src/model/mosaic/NetworkCurrencyMosaic';
2828
import { AliasAction } from '../../src/model/namespace/AliasAction';
@@ -200,7 +200,7 @@ describe('AccountHttp', () => {
200200
);
201201
const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
202202
Deadline.create(),
203-
RestrictionType.BlockAddress,
203+
AccountRestrictionType.BlockIncomingAddress,
204204
[addressPropertyFilter],
205205
NetworkType.MIJIN_TEST,
206206
);
@@ -426,7 +426,7 @@ describe('AccountHttp', () => {
426426
);
427427
const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
428428
Deadline.create(),
429-
RestrictionType.BlockAddress,
429+
AccountRestrictionType.BlockIncomingAddress,
430430
[addressPropertyFilter],
431431
NetworkType.MIJIN_TEST,
432432
);

e2e/infrastructure/TransactionHttp.spec.ts

Lines changed: 164 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ import { NamespaceHttp } from '../../src/infrastructure/infrastructure';
2525
import {Listener} from '../../src/infrastructure/Listener';
2626
import {TransactionHttp} from '../../src/infrastructure/TransactionHttp';
2727
import {Account} from '../../src/model/account/Account';
28+
import { AccountRestrictionType } from '../../src/model/account/AccountRestrictionType';
2829
import { RestrictionModificationType } from '../../src/model/account/RestrictionModificationType';
29-
import { RestrictionType } from '../../src/model/account/RestrictionType';
3030
import {NetworkType} from '../../src/model/blockchain/NetworkType';
3131
import { Mosaic } from '../../src/model/mosaic/Mosaic';
3232
import {MosaicId} from '../../src/model/mosaic/MosaicId';
@@ -387,7 +387,7 @@ describe('TransactionHttp', () => {
387387
transactionHttp.announce(signedTransaction);
388388
});
389389
});
390-
describe('AccountRestrictionTransaction - Address', () => {
390+
describe('AccountRestrictionTransaction - Outgoing Address', () => {
391391
let listener: Listener;
392392
before (() => {
393393
listener = new Listener(config.apiUrl);
@@ -404,7 +404,7 @@ describe('TransactionHttp', () => {
404404
);
405405
const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
406406
Deadline.create(),
407-
RestrictionType.BlockAddress,
407+
AccountRestrictionType.BlockOutgoingAddress,
408408
[addressRestrictionFilter],
409409
NetworkType.MIJIN_TEST,
410410
);
@@ -425,7 +425,7 @@ describe('TransactionHttp', () => {
425425
transactionHttp.announce(signedTransaction);
426426
});
427427
});
428-
describe('AccountRestrictionTransaction - Address', () => {
428+
describe('AccountRestrictionTransaction - Outgoing Address', () => {
429429
let listener: Listener;
430430
before (() => {
431431
listener = new Listener(config.apiUrl);
@@ -441,7 +441,83 @@ describe('TransactionHttp', () => {
441441
);
442442
const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
443443
Deadline.create(),
444-
RestrictionType.BlockAddress,
444+
AccountRestrictionType.BlockOutgoingAddress,
445+
[addressRestrictionFilter],
446+
NetworkType.MIJIN_TEST,
447+
);
448+
const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(),
449+
[addressModification.toAggregate(account.publicAccount)],
450+
NetworkType.MIJIN_TEST,
451+
[],
452+
);
453+
const signedTransaction = aggregateTransaction.signWith(account, generationHash);
454+
listener.confirmed(account.address).subscribe((transaction: Transaction) => {
455+
done();
456+
});
457+
listener.status(account.address).subscribe((error) => {
458+
console.log('Error:', error);
459+
assert(false);
460+
done();
461+
});
462+
transactionHttp.announce(signedTransaction);
463+
});
464+
});
465+
466+
describe('AccountRestrictionTransaction - Incoming Address', () => {
467+
let listener: Listener;
468+
before (() => {
469+
listener = new Listener(config.apiUrl);
470+
return listener.open();
471+
});
472+
after(() => {
473+
return listener.close();
474+
});
475+
476+
it('standalone', (done) => {
477+
const addressRestrictionFilter = AccountRestrictionModification.createForAddress(
478+
RestrictionModificationType.Add,
479+
account3.address,
480+
);
481+
const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
482+
Deadline.create(),
483+
AccountRestrictionType.BlockIncomingAddress,
484+
[addressRestrictionFilter],
485+
NetworkType.MIJIN_TEST,
486+
);
487+
const signedTransaction = addressModification.signWith(account, generationHash);
488+
489+
listener.confirmed(account.address).subscribe((transaction: AccountAddressRestrictionModificationTransaction) => {
490+
expect(transaction.modifications, 'Modifications').not.to.be.undefined;
491+
expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined;
492+
expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined;
493+
expect(transaction.restrictionType, 'RestrictionType').not.to.be.undefined;
494+
done();
495+
});
496+
listener.status(account.address).subscribe((error) => {
497+
console.log('Error:', error);
498+
assert(false);
499+
done();
500+
});
501+
transactionHttp.announce(signedTransaction);
502+
});
503+
});
504+
describe('AccountRestrictionTransaction - Incoming Address', () => {
505+
let listener: Listener;
506+
before (() => {
507+
listener = new Listener(config.apiUrl);
508+
return listener.open();
509+
});
510+
after(() => {
511+
return listener.close();
512+
});
513+
it('aggregate', (done) => {
514+
const addressRestrictionFilter = AccountRestrictionModification.createForAddress(
515+
RestrictionModificationType.Remove,
516+
account3.address,
517+
);
518+
const addressModification = AccountRestrictionTransaction.createAddressRestrictionModificationTransaction(
519+
Deadline.create(),
520+
AccountRestrictionType.BlockIncomingAddress,
445521
[addressRestrictionFilter],
446522
NetworkType.MIJIN_TEST,
447523
);
@@ -479,7 +555,7 @@ describe('TransactionHttp', () => {
479555
);
480556
const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction(
481557
Deadline.create(),
482-
RestrictionType.BlockMosaic,
558+
AccountRestrictionType.BlockMosaic,
483559
[mosaicRestrictionFilter],
484560
NetworkType.MIJIN_TEST,
485561
);
@@ -516,7 +592,7 @@ describe('TransactionHttp', () => {
516592
);
517593
const addressModification = AccountRestrictionTransaction.createMosaicRestrictionModificationTransaction(
518594
Deadline.create(),
519-
RestrictionType.BlockMosaic,
595+
AccountRestrictionType.BlockMosaic,
520596
[mosaicRestrictionFilter],
521597
NetworkType.MIJIN_TEST,
522598
);
@@ -537,7 +613,7 @@ describe('TransactionHttp', () => {
537613
transactionHttp.announce(signedTransaction);
538614
});
539615
});
540-
describe('AccountRestrictionTransaction - Operation', () => {
616+
describe('AccountRestrictionTransaction - Incoming Operation', () => {
541617
let listener: Listener;
542618
before (() => {
543619
listener = new Listener(config.apiUrl);
@@ -554,7 +630,7 @@ describe('TransactionHttp', () => {
554630
);
555631
const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction(
556632
Deadline.create(),
557-
RestrictionType.BlockTransaction,
633+
AccountRestrictionType.BlockIncomingTransactionType,
558634
[operationRestrictionFilter],
559635
NetworkType.MIJIN_TEST,
560636
);
@@ -575,7 +651,7 @@ describe('TransactionHttp', () => {
575651
transactionHttp.announce(signedTransaction);
576652
});
577653
});
578-
describe('AccountRestrictionTransaction - Operation', () => {
654+
describe('AccountRestrictionTransaction - Incoming Operation', () => {
579655
let listener: Listener;
580656
before (() => {
581657
listener = new Listener(config.apiUrl);
@@ -591,7 +667,7 @@ describe('TransactionHttp', () => {
591667
);
592668
const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction(
593669
Deadline.create(),
594-
RestrictionType.BlockTransaction,
670+
AccountRestrictionType.BlockIncomingTransactionType,
595671
[operationRestrictionFilter],
596672
NetworkType.MIJIN_TEST,
597673
);
@@ -612,6 +688,83 @@ describe('TransactionHttp', () => {
612688
transactionHttp.announce(signedTransaction);
613689
});
614690
});
691+
692+
describe('AccountRestrictionTransaction - Outgoing Operation', () => {
693+
let listener: Listener;
694+
before (() => {
695+
listener = new Listener(config.apiUrl);
696+
return listener.open();
697+
});
698+
after(() => {
699+
return listener.close();
700+
});
701+
702+
it('standalone', (done) => {
703+
const operationRestrictionFilter = AccountRestrictionModification.createForOperation(
704+
RestrictionModificationType.Add,
705+
TransactionType.LINK_ACCOUNT,
706+
);
707+
const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction(
708+
Deadline.create(),
709+
AccountRestrictionType.BlockOutgoingTransactionType,
710+
[operationRestrictionFilter],
711+
NetworkType.MIJIN_TEST,
712+
);
713+
const signedTransaction = addressModification.signWith(account3, generationHash);
714+
715+
listener.confirmed(account3.address).subscribe((transaction: AccountOperationRestrictionModificationTransaction) => {
716+
expect(transaction.modifications, 'Modifications').not.to.be.undefined;
717+
expect(transaction.modifications[0].modificationType, 'Modifications.ModificationType').not.to.be.undefined;
718+
expect(transaction.modifications[0].value, 'Modifications.Value').not.to.be.undefined;
719+
expect(transaction.restrictionType, 'RestrictionType').not.to.be.undefined;
720+
done();
721+
});
722+
listener.status(account3.address).subscribe((error) => {
723+
console.log('Error:', error);
724+
assert(false);
725+
done();
726+
});
727+
transactionHttp.announce(signedTransaction);
728+
});
729+
});
730+
describe('AccountRestrictionTransaction - Outgoing Operation', () => {
731+
let listener: Listener;
732+
before (() => {
733+
listener = new Listener(config.apiUrl);
734+
return listener.open();
735+
});
736+
after(() => {
737+
return listener.close();
738+
});
739+
it('aggregate', (done) => {
740+
const operationRestrictionFilter = AccountRestrictionModification.createForOperation(
741+
RestrictionModificationType.Remove,
742+
TransactionType.LINK_ACCOUNT,
743+
);
744+
const addressModification = AccountRestrictionTransaction.createOperationRestrictionModificationTransaction(
745+
Deadline.create(),
746+
AccountRestrictionType.BlockOutgoingTransactionType,
747+
[operationRestrictionFilter],
748+
NetworkType.MIJIN_TEST,
749+
);
750+
const aggregateTransaction = AggregateTransaction.createComplete(Deadline.create(),
751+
[addressModification.toAggregate(account3.publicAccount)],
752+
NetworkType.MIJIN_TEST,
753+
[],
754+
);
755+
const signedTransaction = aggregateTransaction.signWith(account3, generationHash);
756+
listener.confirmed(account3.address).subscribe((transaction: Transaction) => {
757+
done();
758+
});
759+
listener.status(account3.address).subscribe((error) => {
760+
console.log('Error:', error);
761+
assert(false);
762+
done();
763+
});
764+
transactionHttp.announce(signedTransaction);
765+
});
766+
});
767+
615768
describe('AccountLinkTransaction', () => {
616769
let listener: Listener;
617770
before (() => {

src/core/utils/DtoMapping.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
import { AccountRestriction } from '../../model/account/AccountRestriction';
1818
import { AccountRestrictions } from '../../model/account/AccountRestrictions';
1919
import { AccountRestrictionsInfo } from '../../model/account/AccountRestrictionsInfo';
20+
import { AccountRestrictionType } from '../../model/account/AccountRestrictionType';
2021
import { Address } from '../../model/account/Address';
21-
import { RestrictionType } from '../../model/account/RestrictionType';
2222
import { MosaicId } from '../../model/mosaic/MosaicId';
2323

2424
export class DtoMapping {
@@ -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 RestrictionType.AllowAddress:
38-
case RestrictionType.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)));
41-
case RestrictionType.AllowMosaic:
42-
case RestrictionType.BlockMosaic:
43+
case AccountRestrictionType.AllowMosaic:
44+
case AccountRestrictionType.BlockMosaic:
4345
return new AccountRestriction(prop.restrictionType,
4446
prop.values.map((value) => new MosaicId(value)));
45-
case RestrictionType.AllowTransaction:
46-
case RestrictionType.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}`);

src/model/account/AccountRestriction.ts

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

17-
import { RestrictionType } from './RestrictionType';
17+
import { AccountRestrictionType } from './AccountRestrictionType';
1818
/**
1919
* Account restriction structure describes restriction information.
2020
*/
@@ -29,7 +29,7 @@ export class AccountRestriction {
2929
/**
3030
* Account restriction type
3131
*/
32-
public readonly restrictionType: RestrictionType,
32+
public readonly restrictionType: AccountRestrictionType,
3333
/**
3434
* Restriction values.
3535
*/

0 commit comments

Comments
 (0)