Skip to content

Commit

Permalink
linter fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dhaidashenko committed Dec 20, 2024
1 parent cc8c764 commit 4178d4c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 90 deletions.
4 changes: 2 additions & 2 deletions pkg/solana/logpoller/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ type Filter struct {

type Log struct {
ID int64
FilterId int64
ChainId string
FilterID int64
ChainID string
LogIndex int64
BlockHash Hash
BlockNumber int64
Expand Down
4 changes: 2 additions & 2 deletions pkg/solana/logpoller/orm.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ func (o *DSORM) insertLogsWithinTx(ctx context.Context, logs []Log, tx sqlutil.D

func (o *DSORM) validateLogs(logs []Log) error {
for _, log := range logs {
if o.chainID != log.ChainId {
return fmt.Errorf("invalid chainID in log got %v want %v", log.ChainId, o.chainID)
if o.chainID != log.ChainID {
return fmt.Errorf("invalid chainID in log got %v want %v", log.ChainID, o.chainID)
}
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/solana/logpoller/orm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ func TestLogPollerLogs(t *testing.T) {
signature, err := privateKey.Sign(data)
require.NoError(t, err)
log := Log{
FilterId: filterID,
ChainId: chainID,
FilterID: filterID,
ChainID: chainID,
LogIndex: 1,
BlockHash: Hash(pubKey),
BlockNumber: 10,
Expand Down
88 changes: 7 additions & 81 deletions pkg/solana/logpoller/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import (
"fmt"
"strings"
"time"

"github.com/gagliardetto/solana-go"
"github.com/lib/pq"
)

// queryArgs is a helper for building the arguments to a postgres query created by DSORM
Expand All @@ -18,10 +15,10 @@ type queryArgs struct {
err []error
}

func newQueryArgs(chainId string) *queryArgs {
func newQueryArgs(chainID string) *queryArgs {
return &queryArgs{
args: map[string]any{
"chain_id": chainId,
"chain_id": chainID,
},
idxLookup: make(map[string]uint8),
err: []error{},
Expand All @@ -34,18 +31,12 @@ func (q *queryArgs) withField(fieldName string, value any) *queryArgs {
return args
}

func (q *queryArgs) withIndexedField(fieldName string, value any) string {
field, _ := q.withIndexableField(fieldName, value, true)

return field
}

func (q *queryArgs) withIndexableField(fieldName string, value any, addIndex bool) (string, *queryArgs) {
if addIndex {
idx := q.nextIdx(fieldName)
idxName := fmt.Sprintf("%s_%d", fieldName, idx)

q.idxLookup[fieldName] = uint8(idx)
q.idxLookup[fieldName] = idx
fieldName = idxName
}

Expand All @@ -54,13 +45,13 @@ func (q *queryArgs) withIndexableField(fieldName string, value any, addIndex boo
return fieldName, q
}

func (q *queryArgs) nextIdx(baseFieldName string) int {
func (q *queryArgs) nextIdx(baseFieldName string) uint8 {
idx, ok := q.idxLookup[baseFieldName]
if !ok {
return 0
}

return int(idx) + 1
return idx + 1
}

// withName sets the Name field in queryArgs.
Expand Down Expand Up @@ -108,73 +99,8 @@ func (q *queryArgs) withMaxLogsKept(maxLogsKept int64) *queryArgs {
return q.withField("max_logs_kept", maxLogsKept)
}

// withID sets the ID field in Log.
func (q *queryArgs) withID(id int64) *queryArgs {
return q.withField("id", id)
}

// withFilterId sets the FilterId field in Log.
func (q *queryArgs) withFilterId(filterId int64) *queryArgs {
return q.withField("filter_id", filterId)
}

// withChainId sets the ChainId field in Log.
func (q *queryArgs) withChainId(chainId string) *queryArgs {
return q.withField("chain_id", chainId)
}

// withLogIndex sets the LogIndex field in Log.
func (q *queryArgs) withLogIndex(logIndex int64) *queryArgs {
return q.withField("log_index", logIndex)
}

// withBlockHash sets the BlockHash field in Log.
func (q *queryArgs) withBlockHash(blockHash solana.Hash) *queryArgs {
return q.withField("block_hash", blockHash)
}

// withBlockNumber sets the BlockNumber field in Log.
func (q *queryArgs) withBlockNumber(blockNumber int64) *queryArgs {
return q.withField("block_number", blockNumber)
}

// withBlockTimestamp sets the BlockTimestamp field in Log.
func (q *queryArgs) withBlockTimestamp(blockTimestamp time.Time) *queryArgs {
return q.withField("block_timestamp", blockTimestamp)
}

// withSubkeyValues sets the SubkeyValues field in Log.
func (q *queryArgs) withSubkeyValues(subkeyValues pq.ByteaArray) *queryArgs {
return q.withField("subkey_values", subkeyValues)
}

// withTxHash sets the TxHash field in Log.
func (q *queryArgs) withTxHash(txHash solana.Signature) *queryArgs {
return q.withField("tx_hash", txHash)
}

// withData sets the Data field in Log.
func (q *queryArgs) withData(data []byte) *queryArgs {
return q.withField("data", data)
}

// withCreatedAt sets the CreatedAt field in Log.
func (q *queryArgs) withCreatedAt(createdAt time.Time) *queryArgs {
return q.withField("created_at", createdAt)
}

// withExpiresAt sets the ExpiresAt field in Log.
func (q *queryArgs) withExpiresAt(expiresAt *time.Time) *queryArgs {
return q.withField("expires_at", expiresAt)
}

// withSequenceNum sets the SequenceNum field in Log.
func (q *queryArgs) withSequenceNum(sequenceNum int64) *queryArgs {
return q.withField("sequence_num", sequenceNum)
}

func newQueryArgsForEvent(chainId string, address PublicKey, eventSig []byte) *queryArgs {
return newQueryArgs(chainId).
func newQueryArgsForEvent(chainID string, address PublicKey, eventSig []byte) *queryArgs {
return newQueryArgs(chainID).
withAddress(address).
withEventSig(eventSig)
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/solana/logpoller/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ func scanFixedLengthArray(name string, maxLength int, src interface{}, dest []by

type SubkeyPaths [][]string

func (k SubkeyPaths) Value() (driver.Value, error) {
return json.Marshal([][]string(k))
func (p SubkeyPaths) Value() (driver.Value, error) {
return json.Marshal([][]string(p))
}

func (p *SubkeyPaths) Scan(src interface{}) error {
Expand All @@ -95,5 +95,4 @@ func (p *SubkeyPaths) Scan(src interface{}) error {
}

return nil

}

0 comments on commit 4178d4c

Please sign in to comment.