1
- import { BasePgStoreModule , PgSqlClient } from '@hirosystems/api-toolkit' ;
1
+ import { BasePgStoreModule , PgSqlClient , has0xPrefix } from '@hirosystems/api-toolkit' ;
2
2
import {
3
3
BlockLimitParamSchema ,
4
4
CompiledBurnBlockHashParam ,
@@ -624,6 +624,7 @@ export class PgStoreV2 extends BasePgStoreModule {
624
624
return this . sqlTransaction ( async sql => {
625
625
const limit = args . limit ?? PoxSignerLimitParamSchema . default ;
626
626
const offset = args . offset ?? 0 ;
627
+ const cycleNumber = parseInt ( args . cycle_number ) ;
627
628
const cycleCheck =
628
629
await sql `SELECT cycle_number FROM pox_cycles WHERE cycle_number = ${ args . cycle_number } LIMIT 1` ;
629
630
if ( cycleCheck . count === 0 )
@@ -634,8 +635,8 @@ export class PgStoreV2 extends BasePgStoreModule {
634
635
FROM pox4_events
635
636
WHERE canonical = true AND microblock_canonical = true
636
637
AND name in ('stack-aggregation-commit-indexed', 'stack-aggregation-commit')
637
- AND start_cycle_id = ${ args . cycle_number }
638
- AND end_cycle_id = ${ args . cycle_number + 1 }
638
+ AND start_cycle_id = ${ cycleNumber }
639
+ AND end_cycle_id = ${ cycleNumber + 1 }
639
640
ORDER BY stacker, block_height DESC, tx_index DESC, event_index DESC
640
641
), delegated_stackers AS (
641
642
SELECT DISTINCT ON (main.stacker)
@@ -646,8 +647,8 @@ export class PgStoreV2 extends BasePgStoreModule {
646
647
WHERE main.canonical = true
647
648
AND main.microblock_canonical = true
648
649
AND main.name IN ('delegate-stack-stx', 'delegate-stack-increase', 'delegate-stack-extend')
649
- AND main.start_cycle_id <= ${ args . cycle_number }
650
- AND main.end_cycle_id > ${ args . cycle_number }
650
+ AND main.start_cycle_id <= ${ cycleNumber }
651
+ AND main.end_cycle_id > ${ cycleNumber }
651
652
ORDER BY main.stacker, main.block_height DESC, main.microblock_sequence DESC, main.tx_index DESC, main.event_index DESC
652
653
), solo_stackers AS (
653
654
SELECT DISTINCT ON (stacker)
@@ -656,8 +657,8 @@ export class PgStoreV2 extends BasePgStoreModule {
656
657
FROM pox4_events
657
658
WHERE canonical = true AND microblock_canonical = true
658
659
AND name in ('stack-stx', 'stacks-increase', 'stack-extend')
659
- AND start_cycle_id <= ${ args . cycle_number }
660
- AND end_cycle_id > ${ args . cycle_number }
660
+ AND start_cycle_id <= ${ cycleNumber }
661
+ AND end_cycle_id > ${ cycleNumber }
661
662
ORDER BY stacker, block_height DESC, microblock_sequence DESC, tx_index DESC, event_index DESC
662
663
)
663
664
SELECT
@@ -672,7 +673,7 @@ export class PgStoreV2 extends BasePgStoreModule {
672
673
FROM pox_sets ps
673
674
LEFT JOIN delegated_stackers ds ON ps.signing_key = ds.signer_key
674
675
LEFT JOIN solo_stackers ss ON ps.signing_key = ss.signer_key
675
- WHERE ps.canonical = TRUE AND ps.cycle_number = ${ args . cycle_number }
676
+ WHERE ps.canonical = TRUE AND ps.cycle_number = ${ cycleNumber }
676
677
GROUP BY ps.signing_key, ps.weight, ps.stacked_amount, ps.weight_percent, ps.stacked_amount_percent
677
678
ORDER BY ps.weight DESC, ps.stacked_amount DESC, ps.signing_key
678
679
OFFSET ${ offset }
@@ -689,8 +690,10 @@ export class PgStoreV2 extends BasePgStoreModule {
689
690
690
691
async getPoxCycleSigner ( args : PoxCycleSignerParams ) : Promise < DbPoxCycleSigner | undefined > {
691
692
return this . sqlTransaction ( async sql => {
693
+ const signerKey = has0xPrefix ( args . signer_key ) ? args . signer_key : '0x' + args . signer_key ;
694
+ const cycleNumber = parseInt ( args . cycle_number ) ;
692
695
const cycleCheck =
693
- await sql `SELECT cycle_number FROM pox_cycles WHERE cycle_number = ${ args . cycle_number } LIMIT 1` ;
696
+ await sql `SELECT cycle_number FROM pox_cycles WHERE cycle_number = ${ cycleNumber } LIMIT 1` ;
694
697
if ( cycleCheck . count === 0 )
695
698
throw new InvalidRequestError ( `PoX cycle not found` , InvalidRequestErrorType . invalid_param ) ;
696
699
const results = await sql < DbPoxCycleSigner [ ] > `
@@ -699,8 +702,8 @@ export class PgStoreV2 extends BasePgStoreModule {
699
702
FROM pox4_events
700
703
WHERE canonical = true AND microblock_canonical = true
701
704
AND name in ('stack-aggregation-commit-indexed', 'stack-aggregation-commit')
702
- AND start_cycle_id = ${ args . cycle_number }
703
- AND end_cycle_id = ${ args . cycle_number + 1 }
705
+ AND start_cycle_id = ${ cycleNumber }
706
+ AND end_cycle_id = ${ cycleNumber + 1 }
704
707
ORDER BY stacker, block_height DESC, tx_index DESC, event_index DESC
705
708
), delegated_stackers AS (
706
709
SELECT DISTINCT ON (main.stacker)
@@ -711,8 +714,8 @@ export class PgStoreV2 extends BasePgStoreModule {
711
714
WHERE main.canonical = true
712
715
AND main.microblock_canonical = true
713
716
AND main.name IN ('delegate-stack-stx', 'delegate-stack-increase', 'delegate-stack-extend')
714
- AND main.start_cycle_id <= ${ args . cycle_number }
715
- AND main.end_cycle_id > ${ args . cycle_number }
717
+ AND main.start_cycle_id <= ${ cycleNumber }
718
+ AND main.end_cycle_id > ${ cycleNumber }
716
719
ORDER BY main.stacker, main.block_height DESC, main.microblock_sequence DESC, main.tx_index DESC, main.event_index DESC
717
720
), solo_stackers AS (
718
721
SELECT DISTINCT ON (stacker)
@@ -721,8 +724,8 @@ export class PgStoreV2 extends BasePgStoreModule {
721
724
FROM pox4_events
722
725
WHERE canonical = true AND microblock_canonical = true
723
726
AND name in ('stack-stx', 'stacks-increase', 'stack-extend')
724
- AND start_cycle_id <= ${ args . cycle_number }
725
- AND end_cycle_id > ${ args . cycle_number }
727
+ AND start_cycle_id <= ${ cycleNumber }
728
+ AND end_cycle_id > ${ cycleNumber }
726
729
ORDER BY stacker, block_height DESC, microblock_sequence DESC, tx_index DESC, event_index DESC
727
730
)
728
731
SELECT
@@ -737,8 +740,8 @@ export class PgStoreV2 extends BasePgStoreModule {
737
740
LEFT JOIN delegated_stackers ds ON ps.signing_key = ds.signer_key
738
741
LEFT JOIN solo_stackers ss ON ps.signing_key = ss.signer_key
739
742
WHERE ps.canonical = TRUE
740
- AND ps.cycle_number = ${ args . cycle_number }
741
- AND ps.signing_key = ${ args . signer_key }
743
+ AND ps.cycle_number = ${ cycleNumber }
744
+ AND ps.signing_key = ${ signerKey }
742
745
GROUP BY ps.signing_key, ps.weight, ps.stacked_amount, ps.weight_percent, ps.stacked_amount_percent
743
746
LIMIT 1
744
747
` ;
@@ -752,15 +755,17 @@ export class PgStoreV2 extends BasePgStoreModule {
752
755
return this . sqlTransaction ( async sql => {
753
756
const limit = args . limit ?? PoxSignerLimitParamSchema . default ;
754
757
const offset = args . offset ?? 0 ;
758
+ const signerKey = has0xPrefix ( args . signer_key ) ? args . signer_key : '0x' + args . signer_key ;
759
+ const cycleNumber = parseInt ( args . cycle_number ) ;
755
760
const cycleCheck = await sql `
756
- SELECT cycle_number FROM pox_cycles WHERE cycle_number = ${ args . cycle_number } LIMIT 1
761
+ SELECT cycle_number FROM pox_cycles WHERE cycle_number = ${ cycleNumber } LIMIT 1
757
762
` ;
758
763
if ( cycleCheck . count === 0 )
759
764
throw new InvalidRequestError ( `PoX cycle not found` , InvalidRequestErrorType . invalid_param ) ;
760
765
const signerCheck = await sql `
761
766
SELECT signing_key
762
767
FROM pox_sets
763
- WHERE cycle_number = ${ args . cycle_number } AND signing_key = ${ args . signer_key }
768
+ WHERE cycle_number = ${ cycleNumber } AND signing_key = ${ args . signer_key }
764
769
LIMIT 1
765
770
` ;
766
771
if ( signerCheck . count === 0 )
@@ -774,8 +779,8 @@ export class PgStoreV2 extends BasePgStoreModule {
774
779
FROM pox4_events
775
780
WHERE canonical = true AND microblock_canonical = true
776
781
AND name in ('stack-aggregation-commit-indexed', 'stack-aggregation-commit')
777
- AND start_cycle_id = ${ args . cycle_number }
778
- AND end_cycle_id = ${ args . cycle_number + 1 }
782
+ AND start_cycle_id = ${ cycleNumber }
783
+ AND end_cycle_id = ${ cycleNumber + 1 }
779
784
ORDER BY stacker, block_height DESC, tx_index DESC, event_index DESC
780
785
), delegated_stackers AS (
781
786
SELECT DISTINCT ON (main.stacker)
@@ -791,8 +796,8 @@ export class PgStoreV2 extends BasePgStoreModule {
791
796
WHERE main.canonical = true
792
797
AND main.microblock_canonical = true
793
798
AND main.name IN ('delegate-stack-stx', 'delegate-stack-increase', 'delegate-stack-extend')
794
- AND main.start_cycle_id <= ${ args . cycle_number }
795
- AND main.end_cycle_id > ${ args . cycle_number }
799
+ AND main.start_cycle_id <= ${ cycleNumber }
800
+ AND main.end_cycle_id > ${ cycleNumber }
796
801
ORDER BY main.stacker, main.block_height DESC, main.microblock_sequence DESC, main.tx_index DESC, main.event_index DESC
797
802
), solo_stackers AS (
798
803
SELECT DISTINCT ON (stacker)
@@ -806,8 +811,8 @@ export class PgStoreV2 extends BasePgStoreModule {
806
811
FROM pox4_events
807
812
WHERE canonical = true AND microblock_canonical = true
808
813
AND name in ('stack-stx', 'stacks-increase', 'stack-extend')
809
- AND start_cycle_id <= ${ args . cycle_number }
810
- AND end_cycle_id > ${ args . cycle_number }
814
+ AND start_cycle_id <= ${ cycleNumber }
815
+ AND end_cycle_id > ${ cycleNumber }
811
816
ORDER BY stacker, block_height DESC, microblock_sequence DESC, tx_index DESC, event_index DESC
812
817
), combined_stackers AS (
813
818
SELECT * FROM delegated_stackers
@@ -826,8 +831,8 @@ export class PgStoreV2 extends BasePgStoreModule {
826
831
FROM pox_sets ps
827
832
LEFT JOIN combined_stackers cs ON ps.signing_key = cs.signer_key
828
833
WHERE ps.canonical = TRUE
829
- AND ps.cycle_number = ${ args . cycle_number }
830
- AND ps.signing_key = ${ args . signer_key }
834
+ AND ps.cycle_number = ${ cycleNumber }
835
+ AND ps.signing_key = ${ signerKey }
831
836
ORDER BY locked DESC
832
837
LIMIT ${ limit }
833
838
OFFSET ${ offset }
0 commit comments