@@ -27,6 +27,7 @@ import {
27
27
SubscribeAsyncParams ,
28
28
TransferResult ,
29
29
TxParams ,
30
+ ErrorCode ,
30
31
} from '../../../types' ;
31
32
import {
32
33
bigNumberToDate ,
@@ -310,8 +311,12 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
310
311
* unpause the module
311
312
*/
312
313
public unpause = async ( params : TxParams ) => {
313
- assert . assert ( await this . paused ( ) , 'Controller not currently paused' ) ;
314
- assert . assert ( await this . isCallerTheSecurityTokenOwner ( params . txData ) , 'Sender is not owner' ) ;
314
+ assert . assert ( await this . paused ( ) , ErrorCode . PreconditionRequired , 'Controller not currently paused' ) ;
315
+ assert . assert (
316
+ await this . isCallerTheSecurityTokenOwner ( params . txData ) ,
317
+ ErrorCode . Unauthorized ,
318
+ 'Sender is not owner' ,
319
+ ) ;
315
320
return ( await this . contract ) . unpause . sendTransactionAsync ( params . txData , params . safetyFactor ) ;
316
321
} ;
317
322
@@ -326,16 +331,20 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
326
331
* pause the module
327
332
*/
328
333
public pause = async ( params : TxParams ) => {
329
- assert . assert ( ! ( await this . paused ( ) ) , 'Controller currently paused' ) ;
330
- assert . assert ( await this . isCallerTheSecurityTokenOwner ( params . txData ) , 'Sender is not owner' ) ;
334
+ assert . assert ( ! ( await this . paused ( ) ) , ErrorCode . ContractPaused , 'Controller currently paused' ) ;
335
+ assert . assert (
336
+ await this . isCallerTheSecurityTokenOwner ( params . txData ) ,
337
+ ErrorCode . Unauthorized ,
338
+ 'Sender is not owner' ,
339
+ ) ;
331
340
return ( await this . contract ) . pause . sendTransactionAsync ( params . txData , params . safetyFactor ) ;
332
341
} ;
333
342
334
343
/**
335
344
* Return the different blacklist details corresponding to a blacklists name
336
345
*/
337
346
public blacklists = async ( params : BlacklistParams ) : Promise < BlacklistsDetails > => {
338
- assert . assert ( params . blacklistName . length > 0 , 'Blacklist name must not be an empty string' ) ;
347
+ assert . assert ( params . blacklistName . length > 0 , ErrorCode . InvalidData , 'Blacklist name must not be an empty string' ) ;
339
348
const result = await ( await this . contract ) . blacklists . callAsync ( stringToBytes32 ( params . blacklistName ) ) ;
340
349
return {
341
350
startTime : bigNumberToDate ( result [ 0 ] ) ,
@@ -348,7 +357,11 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
348
357
* Used to add the blacklist type
349
358
*/
350
359
public addBlacklistType = async ( params : BlacklistTypeParams ) => {
351
- assert . assert ( await this . isCallerAllowed ( params . txData , Perm . Admin ) , 'Caller is not allowed' ) ;
360
+ assert . assert (
361
+ await this . isCallerAllowed ( params . txData , Perm . Admin ) ,
362
+ ErrorCode . Unauthorized ,
363
+ 'Caller is not allowed' ,
364
+ ) ;
352
365
await this . checkAddBlacklistType ( params ) ;
353
366
return ( await this . contract ) . addBlacklistType . sendTransactionAsync (
354
367
dateToBigNumber ( params . startTime ) ,
@@ -368,8 +381,12 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
368
381
[ params . startTimes , params . endTimes , params . blacklistNames , params . repeatPeriodTimes ] ,
369
382
'Argument arrays length mismatch' ,
370
383
) ;
371
- assert . assert ( params . startTimes . length > 0 , 'Empty blacklist information' ) ;
372
- assert . assert ( await this . isCallerAllowed ( params . txData , Perm . Admin ) , 'Caller is not allowed' ) ;
384
+ assert . assert ( params . startTimes . length > 0 , ErrorCode . InvalidData , 'Empty blacklist information' ) ;
385
+ assert . assert (
386
+ await this . isCallerAllowed ( params . txData , Perm . Admin ) ,
387
+ ErrorCode . Unauthorized ,
388
+ 'Caller is not allowed' ,
389
+ ) ;
373
390
const results = [ ] ;
374
391
for ( let i = 0 ; i < params . startTimes . length ; i += 1 ) {
375
392
results . push (
@@ -396,7 +413,11 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
396
413
* Used to modify the details of a given blacklist type
397
414
*/
398
415
public modifyBlacklistType = async ( params : BlacklistTypeParams ) => {
399
- assert . assert ( await this . isCallerAllowed ( params . txData , Perm . Admin ) , 'Caller is not allowed' ) ;
416
+ assert . assert (
417
+ await this . isCallerAllowed ( params . txData , Perm . Admin ) ,
418
+ ErrorCode . Unauthorized ,
419
+ 'Caller is not allowed' ,
420
+ ) ;
400
421
await this . checkModifyBlacklistType ( params ) ;
401
422
return ( await this . contract ) . modifyBlacklistType . sendTransactionAsync (
402
423
dateToBigNumber ( params . startTime ) ,
@@ -416,8 +437,12 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
416
437
[ params . startTimes , params . endTimes , params . blacklistNames , params . repeatPeriodTimes ] ,
417
438
'Argument arrays length mismatch' ,
418
439
) ;
419
- assert . assert ( params . startTimes . length > 0 , 'Empty blacklist information' ) ;
420
- assert . assert ( await this . isCallerAllowed ( params . txData , Perm . Admin ) , 'Caller is not allowed' ) ;
440
+ assert . assert ( params . startTimes . length > 0 , ErrorCode . InvalidData , 'Empty blacklist information' ) ;
441
+ assert . assert (
442
+ await this . isCallerAllowed ( params . txData , Perm . Admin ) ,
443
+ ErrorCode . Unauthorized ,
444
+ 'Caller is not allowed' ,
445
+ ) ;
421
446
const results = [ ] ;
422
447
for ( let i = 0 ; i < params . startTimes . length ; i += 1 ) {
423
448
results . push (
@@ -444,7 +469,11 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
444
469
* Used to delete the blacklist type
445
470
*/
446
471
public deleteBlacklistType = async ( params : DeleteBlacklistTypeParams ) => {
447
- assert . assert ( await this . isCallerAllowed ( params . txData , Perm . Admin ) , 'Caller is not allowed' ) ;
472
+ assert . assert (
473
+ await this . isCallerAllowed ( params . txData , Perm . Admin ) ,
474
+ ErrorCode . Unauthorized ,
475
+ 'Caller is not allowed' ,
476
+ ) ;
448
477
await this . checkDeleteBlacklistType ( params . blacklistName ) ;
449
478
return ( await this . contract ) . deleteBlacklistType . sendTransactionAsync (
450
479
stringToBytes32 ( params . blacklistName ) ,
@@ -457,8 +486,12 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
457
486
* Used to delete the multiple blacklist types
458
487
*/
459
488
public deleteBlacklistTypeMulti = async ( params : DeleteBlacklistTypeMultiParams ) => {
460
- assert . assert ( params . blacklistNames . length > 0 , 'Empty blacklist information' ) ;
461
- assert . assert ( await this . isCallerAllowed ( params . txData , Perm . Admin ) , 'Caller is not allowed' ) ;
489
+ assert . assert ( params . blacklistNames . length > 0 , ErrorCode . InvalidData , 'Empty blacklist information' ) ;
490
+ assert . assert (
491
+ await this . isCallerAllowed ( params . txData , Perm . Admin ) ,
492
+ ErrorCode . Unauthorized ,
493
+ 'Caller is not allowed' ,
494
+ ) ;
462
495
const results = [ ] ;
463
496
for ( let i = 0 ; i < params . blacklistNames . length ; i += 1 ) {
464
497
results . push ( this . checkDeleteBlacklistType ( params . blacklistNames [ i ] ) ) ;
@@ -475,7 +508,11 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
475
508
* Used to assign the blacklist type to the investor
476
509
*/
477
510
public addInvestorToBlacklist = async ( params : InvestorAndBlacklistParams ) => {
478
- assert . assert ( await this . isCallerAllowed ( params . txData , Perm . Admin ) , 'Caller is not allowed' ) ;
511
+ assert . assert (
512
+ await this . isCallerAllowed ( params . txData , Perm . Admin ) ,
513
+ ErrorCode . Unauthorized ,
514
+ 'Caller is not allowed' ,
515
+ ) ;
479
516
await this . checkAddInvestorToBlacklist ( params ) ;
480
517
return ( await this . contract ) . addInvestorToBlacklist . sendTransactionAsync (
481
518
params . userAddress ,
@@ -489,8 +526,12 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
489
526
* Used to assign a single blacklist type to multiple investors
490
527
*/
491
528
public addInvestorToBlacklistMulti = async ( params : InvestorMultiAndBlacklistParams ) => {
492
- assert . assert ( await this . isCallerAllowed ( params . txData , Perm . Admin ) , 'Caller is not allowed' ) ;
493
- assert . assert ( params . userAddresses . length > 0 , 'Empty user address information' ) ;
529
+ assert . assert (
530
+ await this . isCallerAllowed ( params . txData , Perm . Admin ) ,
531
+ ErrorCode . Unauthorized ,
532
+ 'Caller is not allowed' ,
533
+ ) ;
534
+ assert . assert ( params . userAddresses . length > 0 , ErrorCode . InvalidData , 'Empty user address information' ) ;
494
535
const results = [ ] ;
495
536
for ( let i = 0 ; i < params . userAddresses . length ; i += 1 ) {
496
537
results . push (
@@ -513,9 +554,13 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
513
554
* Used to assign multiple specific blacklist types to multiple investors
514
555
*/
515
556
public addMultiInvestorToBlacklistMulti = async ( params : InvestorMultiAndBlacklistMultiParams ) => {
516
- assert . assert ( await this . isCallerAllowed ( params . txData , Perm . Admin ) , 'Caller is not allowed' ) ;
557
+ assert . assert (
558
+ await this . isCallerAllowed ( params . txData , Perm . Admin ) ,
559
+ ErrorCode . Unauthorized ,
560
+ 'Caller is not allowed' ,
561
+ ) ;
517
562
assert . areValidArrayLengths ( [ params . userAddresses , params . blacklistNames ] , 'Argument arrays length mismatch' ) ;
518
- assert . assert ( params . userAddresses . length > 0 , 'Empty user address information' ) ;
563
+ assert . assert ( params . userAddresses . length > 0 , ErrorCode . InvalidData , 'Empty user address information' ) ;
519
564
const results = [ ] ;
520
565
for ( let i = 0 ; i < params . userAddresses . length ; i += 1 ) {
521
566
results . push (
@@ -538,7 +583,11 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
538
583
* Used to create a new blacklist type and add it to the investor
539
584
*/
540
585
public addInvestorToNewBlacklist = async ( params : AddNewInvestorToNewBlacklistParams ) => {
541
- assert . assert ( await this . isCallerAllowed ( params . txData , Perm . Admin ) , 'Caller is not allowed' ) ;
586
+ assert . assert (
587
+ await this . isCallerAllowed ( params . txData , Perm . Admin ) ,
588
+ ErrorCode . Unauthorized ,
589
+ 'Caller is not allowed' ,
590
+ ) ;
542
591
await this . checkAddBlacklistType ( params ) ;
543
592
return ( await this . contract ) . addInvestorToNewBlacklist . sendTransactionAsync (
544
593
dateToBigNumber ( params . startTime ) ,
@@ -555,7 +604,11 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
555
604
* Used to delete the investor from the blacklist
556
605
*/
557
606
public deleteInvestorFromBlacklist = async ( params : InvestorAndBlacklistParams ) => {
558
- assert . assert ( await this . isCallerAllowed ( params . txData , Perm . Admin ) , 'Caller is not allowed' ) ;
607
+ assert . assert (
608
+ await this . isCallerAllowed ( params . txData , Perm . Admin ) ,
609
+ ErrorCode . Unauthorized ,
610
+ 'Caller is not allowed' ,
611
+ ) ;
559
612
await this . checkDeleteInvestorFromBlacklist ( params ) ;
560
613
return ( await this . contract ) . deleteInvestorFromBlacklist . sendTransactionAsync (
561
614
params . userAddress ,
@@ -569,9 +622,13 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
569
622
* Used to delete the multiple investors from multiple specific blacklists
570
623
*/
571
624
public deleteMultiInvestorsFromBlacklistMulti = async ( params : InvestorMultiAndBlacklistMultiParams ) => {
572
- assert . assert ( await this . isCallerAllowed ( params . txData , Perm . Admin ) , 'Caller is not allowed' ) ;
625
+ assert . assert (
626
+ await this . isCallerAllowed ( params . txData , Perm . Admin ) ,
627
+ ErrorCode . Unauthorized ,
628
+ 'Caller is not allowed' ,
629
+ ) ;
573
630
assert . areValidArrayLengths ( [ params . userAddresses , params . blacklistNames ] , 'Argument arrays length mismatch' ) ;
574
- assert . assert ( params . userAddresses . length > 0 , 'Empty user address information' ) ;
631
+ assert . assert ( params . userAddresses . length > 0 , ErrorCode . InvalidData , 'Empty user address information' ) ;
575
632
const results = [ ] ;
576
633
for ( let i = 0 ; i < params . userAddresses . length ; i += 1 ) {
577
634
results . push (
@@ -594,7 +651,11 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
594
651
* Used to delete the investor from all the associated blacklist types
595
652
*/
596
653
public deleteInvestorFromAllBlacklist = async ( params : DeleteInvestorFromAllBlacklistParams ) => {
597
- assert . assert ( await this . isCallerAllowed ( params . txData , Perm . Admin ) , 'Caller is not allowed' ) ;
654
+ assert . assert (
655
+ await this . isCallerAllowed ( params . txData , Perm . Admin ) ,
656
+ ErrorCode . Unauthorized ,
657
+ 'Caller is not allowed' ,
658
+ ) ;
598
659
await this . checkDeleteInvestorFromAllBlacklist ( params ) ;
599
660
return ( await this . contract ) . deleteInvestorFromAllBlacklist . sendTransactionAsync (
600
661
params . investor ,
@@ -607,7 +668,11 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
607
668
* Used to delete multiple investors from multiple associated blacklist types
608
669
*/
609
670
public deleteInvestorFromAllBlacklistMulti = async ( params : DeleteInvestorFromAllBlacklistMultiParams ) => {
610
- assert . assert ( await this . isCallerAllowed ( params . txData , Perm . Admin ) , 'Caller is not allowed' ) ;
671
+ assert . assert (
672
+ await this . isCallerAllowed ( params . txData , Perm . Admin ) ,
673
+ ErrorCode . Unauthorized ,
674
+ 'Caller is not allowed' ,
675
+ ) ;
611
676
const results = [ ] ;
612
677
for ( let i = 0 ; i < params . investors . length ; i += 1 ) {
613
678
results . push (
@@ -629,7 +694,11 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
629
694
* @return address List of investors associated with the blacklist
630
695
*/
631
696
public getListOfAddresses = async ( params : BlacklistParams ) : Promise < string [ ] > => {
632
- assert . assert ( params . blacklistName . length > 0 , 'Blacklist details must not be an empty string' ) ;
697
+ assert . assert (
698
+ params . blacklistName . length > 0 ,
699
+ ErrorCode . InvalidData ,
700
+ 'Blacklist details must not be an empty string' ,
701
+ ) ;
633
702
return ( await this . contract ) . getListOfAddresses . callAsync ( stringToBytes32 ( params . blacklistName ) ) ;
634
703
} ;
635
704
@@ -749,7 +818,11 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
749
818
750
819
private checkAddBlacklistType = async ( params : BlacklistTypeParams ) => {
751
820
const blacklistInfo = await this . blacklists ( { blacklistName : params . blacklistName } ) ;
752
- assert . assert ( dateToBigNumber ( blacklistInfo . endTime ) . isZero ( ) , 'Blacklist you are trying to add already exists' ) ;
821
+ assert . assert (
822
+ dateToBigNumber ( blacklistInfo . endTime ) . isZero ( ) ,
823
+ ErrorCode . BacklistAlreadyExist ,
824
+ 'Blacklist you are trying to add already exists' ,
825
+ ) ;
753
826
await this . checkBlacklistTypeDetails ( params ) ;
754
827
} ;
755
828
@@ -760,50 +833,64 @@ export default class BlacklistTransferManagerWrapper extends ModuleWrapper {
760
833
} ;
761
834
762
835
private checkBlacklistTypeDetails = async ( params : BlacklistTypeParams ) => {
763
- assert . assert ( params . blacklistName . length > 0 , 'Blacklist Name cannot be empty string' ) ;
836
+ assert . assert ( params . blacklistName . length > 0 , ErrorCode . InvalidData , 'Blacklist Name cannot be empty string' ) ;
764
837
assert . isFutureDate ( params . startTime , 'Start time must be in the future' ) ;
765
- assert . assert ( params . startTime < params . endTime , 'Start time must be before the end time' ) ;
838
+ assert . assert ( params . startTime < params . endTime , ErrorCode . TooLate , 'Start time must be before the end time' ) ;
766
839
if ( params . repeatPeriodTime !== 0 ) {
767
840
const blacklistDays = ( params . endTime . getTime ( ) - params . startTime . getTime ( ) ) / ( 1000 * 60 * 60 * 24 ) ;
768
841
assert . assert (
769
842
blacklistDays <= params . repeatPeriodTime ,
843
+ ErrorCode . TooEarly ,
770
844
'The repeat period time in days must be greater than or equal to the difference between start and end time' ,
771
845
) ;
772
846
}
773
847
} ;
774
848
775
849
private checkDeleteBlacklistType = async ( blacklistName : string ) => {
776
- assert . assert ( blacklistName . length > 0 , 'Blacklist Name cannot be empty string' ) ;
850
+ assert . assert ( blacklistName . length > 0 , ErrorCode . InvalidData , 'Blacklist Name cannot be empty string' ) ;
777
851
const blacklistsDetails = await this . blacklists ( { blacklistName } ) ;
778
852
assert . isNotDateZero ( blacklistsDetails . endTime , 'Blacklist does not exist' ) ;
779
853
const lookupListOfAddresses = await this . getListOfAddresses ( { blacklistName } ) ;
780
854
assert . assert (
781
855
lookupListOfAddresses . length === 0 ,
856
+ ErrorCode . PreconditionRequired ,
782
857
'There are users attached to the blacklist that must be removed before removing the blacklist type' ,
783
858
) ;
784
859
} ;
785
860
786
861
private checkBlacklistToModifyInvestors = async ( params : InvestorAndBlacklistParams ) => {
787
- assert . assert ( params . blacklistName . length > 0 , 'Blacklist name cannot be empty string' ) ;
862
+ assert . assert ( params . blacklistName . length > 0 , ErrorCode . InvalidData , 'Blacklist name cannot be empty string' ) ;
788
863
const blacklistsDetails = await this . blacklists ( { blacklistName : params . blacklistName } ) ;
789
864
assert . isNotDateZero ( blacklistsDetails . endTime , 'Blacklist does not exist' ) ;
790
865
} ;
791
866
792
867
private checkAddInvestorToBlacklist = async ( params : InvestorAndBlacklistParams ) => {
793
868
await this . checkBlacklistToModifyInvestors ( params ) ;
794
869
const currentBlacklistNames = await this . getBlacklistNamesToUser ( { user : params . userAddress } ) ;
795
- assert . assert ( ! currentBlacklistNames . includes ( params . blacklistName ) , 'User already added to this blacklist name' ) ;
870
+ assert . assert (
871
+ ! currentBlacklistNames . includes ( params . blacklistName ) ,
872
+ ErrorCode . AlreadyAdded ,
873
+ 'User already added to this blacklist name' ,
874
+ ) ;
796
875
} ;
797
876
798
877
private checkDeleteInvestorFromBlacklist = async ( params : InvestorAndBlacklistParams ) => {
799
878
await this . checkBlacklistToModifyInvestors ( params ) ;
800
879
const currentBlacklistNames = await this . getBlacklistNamesToUser ( { user : params . userAddress } ) ;
801
- assert . assert ( currentBlacklistNames . includes ( params . blacklistName ) , 'User is not added to this blacklist name' ) ;
880
+ assert . assert (
881
+ currentBlacklistNames . includes ( params . blacklistName ) ,
882
+ ErrorCode . PreconditionRequired ,
883
+ 'User is not added to this blacklist name' ,
884
+ ) ;
802
885
} ;
803
886
804
887
private checkDeleteInvestorFromAllBlacklist = async ( params : DeleteInvestorFromAllBlacklistParams ) => {
805
888
assert . isNonZeroETHAddressHex ( 'Investor Address' , params . investor ) ;
806
889
const currentBlacklistNames = await this . getBlacklistNamesToUser ( { user : params . investor } ) ;
807
- assert . assert ( currentBlacklistNames . length > 0 , 'Investor is not currently present on any blacklists' ) ;
890
+ assert . assert (
891
+ currentBlacklistNames . length > 0 ,
892
+ ErrorCode . PreconditionRequired ,
893
+ 'Investor is not currently present on any blacklists' ,
894
+ ) ;
808
895
} ;
809
896
}
0 commit comments