diff --git a/pkg/solana/logpoller/models.go b/pkg/solana/logpoller/models.go index fe6092333..7afb0a50e 100644 --- a/pkg/solana/logpoller/models.go +++ b/pkg/solana/logpoller/models.go @@ -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 diff --git a/pkg/solana/logpoller/orm.go b/pkg/solana/logpoller/orm.go index b9daec231..12035438f 100644 --- a/pkg/solana/logpoller/orm.go +++ b/pkg/solana/logpoller/orm.go @@ -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 diff --git a/pkg/solana/logpoller/orm_test.go b/pkg/solana/logpoller/orm_test.go index 09c91c5c7..7c733e1d6 100644 --- a/pkg/solana/logpoller/orm_test.go +++ b/pkg/solana/logpoller/orm_test.go @@ -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, diff --git a/pkg/solana/logpoller/query.go b/pkg/solana/logpoller/query.go index bb516d4da..36e5fb159 100644 --- a/pkg/solana/logpoller/query.go +++ b/pkg/solana/logpoller/query.go @@ -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 @@ -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{}, @@ -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 } @@ -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. @@ -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) } diff --git a/pkg/solana/logpoller/types.go b/pkg/solana/logpoller/types.go index 5b42877a6..0581a7630 100644 --- a/pkg/solana/logpoller/types.go +++ b/pkg/solana/logpoller/types.go @@ -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 { @@ -95,5 +95,4 @@ func (p *SubkeyPaths) Scan(src interface{}) error { } return nil - }