@@ -2,6 +2,7 @@ package dataaccess
22
33import (
44 "context"
5+ "strings"
56
67 "github.com/ethereum/go-ethereum/common/hexutil"
78 t "github.com/gobitfly/beaconchain/pkg/api/types"
@@ -13,9 +14,10 @@ type SearchRepository interface {
1314 GetSearchValidatorByPublicKey (ctx context.Context , chainId uint64 , publicKey []byte ) (* t.SearchValidator , error )
1415 GetSearchValidatorsByDepositAddress (ctx context.Context , chainId uint64 , address []byte ) (* t.SearchValidatorsByDepositAddress , error )
1516 GetSearchValidatorsByDepositEnsName (ctx context.Context , chainId uint64 , ensName string ) (* t.SearchValidatorsByDepositAddress , error )
16- GetSearchValidatorsByWithdrawalCredential (ctx context.Context , chainId uint64 , credential []byte ) (* t.SearchValidatorsByWithdrwalCredential , error )
17- GetSearchValidatorsByWithdrawalEnsName (ctx context.Context , chainId uint64 , ensName string ) (* t.SearchValidatorsByWithdrwalCredential , error )
18- GetSearchValidatorsByGraffiti (ctx context.Context , chainId uint64 , graffiti string ) (* t.SearchValidatorsByGraffiti , error )
17+ GetSearchValidatorsByWithdrawalCredential (ctx context.Context , chainId uint64 , credential []byte ) (* t.SearchValidatorsByWithdrawalCredential , error )
18+ GetSearchValidatorsByWithdrawalEnsName (ctx context.Context , chainId uint64 , ensName string ) (* t.SearchValidatorsByWithdrawalCredential , error )
19+ GetSearchValidatorsByGraffitiText (ctx context.Context , chainId uint64 , graffiti string ) (* t.SearchValidatorsByGraffiti , error )
20+ GetSearchValidatorsByGraffitiHex (ctx context.Context , chainId uint64 , graffiti []byte ) (* t.SearchValidatorsByGraffiti , error )
1921}
2022
2123func (d * DataAccessService ) GetSearchValidatorByIndex (ctx context.Context , chainId , index uint64 ) (* t.SearchValidator , error ) {
@@ -75,9 +77,9 @@ func (d *DataAccessService) GetSearchValidatorsByDepositEnsName(ctx context.Cont
7577 return nil , ErrNotFound
7678}
7779
78- func (d * DataAccessService ) GetSearchValidatorsByWithdrawalCredential (ctx context.Context , chainId uint64 , credential []byte ) (* t.SearchValidatorsByWithdrwalCredential , error ) {
80+ func (d * DataAccessService ) GetSearchValidatorsByWithdrawalCredential (ctx context.Context , chainId uint64 , credential []byte ) (* t.SearchValidatorsByWithdrawalCredential , error ) {
7981 // TODO: implement handling of chainid
80- ret := & t.SearchValidatorsByWithdrwalCredential {
82+ ret := & t.SearchValidatorsByWithdrawalCredential {
8183 WithdrawalCredential : hexutil .Encode (credential ),
8284 }
8385 err := db .ReaderDb .GetContext (ctx , & ret .Count , "select count(validatorindex) from validators where withdrawalcredentials = $1;" , credential )
@@ -90,16 +92,17 @@ func (d *DataAccessService) GetSearchValidatorsByWithdrawalCredential(ctx contex
9092 return ret , nil
9193}
9294
93- func (d * DataAccessService ) GetSearchValidatorsByWithdrawalEnsName (ctx context.Context , chainId uint64 , ensName string ) (* t.SearchValidatorsByWithdrwalCredential , error ) {
95+ func (d * DataAccessService ) GetSearchValidatorsByWithdrawalEnsName (ctx context.Context , chainId uint64 , ensName string ) (* t.SearchValidatorsByWithdrawalCredential , error ) {
9496 // TODO: implement handling of chainid
9597 // TODO: finalize ens implementation first
9698 return nil , ErrNotFound
9799}
98100
99- func (d * DataAccessService ) GetSearchValidatorsByGraffiti (ctx context.Context , chainId uint64 , graffiti string ) (* t.SearchValidatorsByGraffiti , error ) {
101+ func (d * DataAccessService ) GetSearchValidatorsByGraffitiText (ctx context.Context , chainId uint64 , graffiti string ) (* t.SearchValidatorsByGraffiti , error ) {
100102 // TODO: implement handling of chainid
101103 ret := & t.SearchValidatorsByGraffiti {
102104 Graffiti : graffiti ,
105+ Hex : hexutil .Encode ([]byte (graffiti )),
103106 }
104107 err := db .ReaderDb .GetContext (ctx , & ret .Count , "select count(distinct proposer) from blocks where graffiti_text = $1;" , graffiti )
105108 if err != nil {
@@ -110,3 +113,19 @@ func (d *DataAccessService) GetSearchValidatorsByGraffiti(ctx context.Context, c
110113 }
111114 return ret , nil
112115}
116+
117+ func (d * DataAccessService ) GetSearchValidatorsByGraffitiHex (ctx context.Context , chainId uint64 , graffiti []byte ) (* t.SearchValidatorsByGraffiti , error ) {
118+ // TODO: implement handling of chainid
119+ ret := & t.SearchValidatorsByGraffiti {
120+ Graffiti : strings .TrimRight (string (graffiti ), "\u0000 " ),
121+ Hex : hexutil .Encode (graffiti ),
122+ }
123+ err := db .ReaderDb .GetContext (ctx , & ret .Count , "select count(distinct proposer) from blocks where graffiti = $1;" , graffiti )
124+ if err != nil {
125+ return nil , err
126+ }
127+ if ret .Count == 0 {
128+ return nil , ErrNotFound
129+ }
130+ return ret , nil
131+ }
0 commit comments