@@ -440,10 +440,10 @@ export const validators = {
440
440
}
441
441
}
442
442
443
- const wt = params [ index ]
443
+ const clReq = params [ index ]
444
444
445
445
for ( const field of requiredFields ) {
446
- if ( wt [ field ] === undefined ) {
446
+ if ( clReq [ field ] === undefined ) {
447
447
return {
448
448
code : INVALID_PARAMS ,
449
449
message : `invalid argument ${ index } : required field ${ field } ` ,
@@ -458,25 +458,25 @@ export const validators = {
458
458
}
459
459
460
460
// validate pubkey
461
- for ( const field of [ wt . pubkey ] ) {
461
+ for ( const field of [ clReq . pubkey ] ) {
462
462
const v = validate ( field , this . bytes48 )
463
463
if ( v !== undefined ) return v
464
464
}
465
465
466
466
// validate withdrawalCredentials
467
- for ( const field of [ wt . withdrawalCredentials ] ) {
467
+ for ( const field of [ clReq . withdrawalCredentials ] ) {
468
468
const v = validate ( field , this . bytes32 )
469
469
if ( v !== undefined ) return v
470
470
}
471
471
472
472
// validate amount, index
473
- for ( const field of [ wt . amount , wt . index ] ) {
473
+ for ( const field of [ clReq . amount , clReq . index ] ) {
474
474
const v = validate ( field , this . bytes8 )
475
475
if ( v !== undefined ) return v
476
476
}
477
477
478
478
// validate signature
479
- for ( const field of [ wt . signature ] ) {
479
+ for ( const field of [ clReq . signature ] ) {
480
480
const v = validate ( field , this . bytes96 )
481
481
if ( v !== undefined ) return v
482
482
}
@@ -494,10 +494,10 @@ export const validators = {
494
494
}
495
495
}
496
496
497
- const wt = params [ index ]
497
+ const clReq = params [ index ]
498
498
499
499
for ( const field of requiredFields ) {
500
- if ( wt [ field ] === undefined ) {
500
+ if ( clReq [ field ] === undefined ) {
501
501
return {
502
502
code : INVALID_PARAMS ,
503
503
message : `invalid argument ${ index } : required field ${ field } ` ,
@@ -512,26 +512,74 @@ export const validators = {
512
512
}
513
513
514
514
// validate sourceAddress
515
- for ( const field of [ wt . sourceAddress ] ) {
515
+ for ( const field of [ clReq . sourceAddress ] ) {
516
516
const v = validate ( field , this . address )
517
517
if ( v !== undefined ) return v
518
518
}
519
519
520
520
// validate validatorPubkey
521
- for ( const field of [ wt . validatorPubkey ] ) {
521
+ for ( const field of [ clReq . validatorPubkey ] ) {
522
522
const v = validate ( field , this . bytes48 )
523
523
if ( v !== undefined ) return v
524
524
}
525
525
526
526
// validate amount
527
- for ( const field of [ wt . amount ] ) {
527
+ for ( const field of [ clReq . amount ] ) {
528
528
const v = validate ( field , this . bytes8 )
529
529
if ( v !== undefined ) return v
530
530
}
531
531
}
532
532
}
533
533
} ,
534
534
535
+ get consolidationRequest ( ) {
536
+ return ( requiredFields : string [ ] = [ 'sourceAddress' , 'sourcePubkey' , 'targetPubkey' ] ) => {
537
+ return ( params : any [ ] , index : number ) => {
538
+ if ( typeof params [ index ] !== 'object' ) {
539
+ return {
540
+ code : INVALID_PARAMS ,
541
+ message : `invalid argument ${ index } : argument must be an object` ,
542
+ }
543
+ }
544
+
545
+ const clReq = params [ index ]
546
+
547
+ for ( const field of requiredFields ) {
548
+ if ( clReq [ field ] === undefined ) {
549
+ return {
550
+ code : INVALID_PARAMS ,
551
+ message : `invalid argument ${ index } : required field ${ field } ` ,
552
+ }
553
+ }
554
+ }
555
+
556
+ const validate = ( field : any , validator : Function ) => {
557
+ if ( field === undefined ) return
558
+ const v = validator ( [ field ] , 0 )
559
+ if ( v !== undefined ) return v
560
+ }
561
+
562
+ // validate sourceAddress
563
+ for ( const field of [ clReq . sourceAddress ] ) {
564
+ const v = validate ( field , this . address )
565
+ if ( v !== undefined ) return v
566
+ }
567
+
568
+ // validate validatorPubkey
569
+ for ( const field of [ clReq . sourcePubkey ] ) {
570
+ const v = validate ( field , this . bytes48 )
571
+ if ( v !== undefined ) return v
572
+ }
573
+
574
+ // validate amount
575
+ for ( const field of [ clReq . targetPubkey ] ) {
576
+ const v = validate ( field , this . bytes48 )
577
+ if ( v !== undefined ) return v
578
+ }
579
+ }
580
+ }
581
+ } ,
582
+
535
583
/**
536
584
* object validator to check if type is object with
537
585
* required keys and expected validation of values
0 commit comments