5
5
"fmt"
6
6
"strings"
7
7
"time"
8
-
9
- "github.com/gagliardetto/solana-go"
10
- "github.com/lib/pq"
11
8
)
12
9
13
10
// queryArgs is a helper for building the arguments to a postgres query created by DSORM
@@ -18,10 +15,10 @@ type queryArgs struct {
18
15
err []error
19
16
}
20
17
21
- func newQueryArgs (chainId string ) * queryArgs {
18
+ func newQueryArgs (chainID string ) * queryArgs {
22
19
return & queryArgs {
23
20
args : map [string ]any {
24
- "chain_id" : chainId ,
21
+ "chain_id" : chainID ,
25
22
},
26
23
idxLookup : make (map [string ]uint8 ),
27
24
err : []error {},
@@ -34,18 +31,12 @@ func (q *queryArgs) withField(fieldName string, value any) *queryArgs {
34
31
return args
35
32
}
36
33
37
- func (q * queryArgs ) withIndexedField (fieldName string , value any ) string {
38
- field , _ := q .withIndexableField (fieldName , value , true )
39
-
40
- return field
41
- }
42
-
43
34
func (q * queryArgs ) withIndexableField (fieldName string , value any , addIndex bool ) (string , * queryArgs ) {
44
35
if addIndex {
45
36
idx := q .nextIdx (fieldName )
46
37
idxName := fmt .Sprintf ("%s_%d" , fieldName , idx )
47
38
48
- q .idxLookup [fieldName ] = uint8 ( idx )
39
+ q .idxLookup [fieldName ] = idx
49
40
fieldName = idxName
50
41
}
51
42
@@ -54,13 +45,13 @@ func (q *queryArgs) withIndexableField(fieldName string, value any, addIndex boo
54
45
return fieldName , q
55
46
}
56
47
57
- func (q * queryArgs ) nextIdx (baseFieldName string ) int {
48
+ func (q * queryArgs ) nextIdx (baseFieldName string ) uint8 {
58
49
idx , ok := q .idxLookup [baseFieldName ]
59
50
if ! ok {
60
51
return 0
61
52
}
62
53
63
- return int ( idx ) + 1
54
+ return idx + 1
64
55
}
65
56
66
57
// withName sets the Name field in queryArgs.
@@ -108,73 +99,8 @@ func (q *queryArgs) withMaxLogsKept(maxLogsKept int64) *queryArgs {
108
99
return q .withField ("max_logs_kept" , maxLogsKept )
109
100
}
110
101
111
- // withID sets the ID field in Log.
112
- func (q * queryArgs ) withID (id int64 ) * queryArgs {
113
- return q .withField ("id" , id )
114
- }
115
-
116
- // withFilterId sets the FilterId field in Log.
117
- func (q * queryArgs ) withFilterId (filterId int64 ) * queryArgs {
118
- return q .withField ("filter_id" , filterId )
119
- }
120
-
121
- // withChainId sets the ChainId field in Log.
122
- func (q * queryArgs ) withChainId (chainId string ) * queryArgs {
123
- return q .withField ("chain_id" , chainId )
124
- }
125
-
126
- // withLogIndex sets the LogIndex field in Log.
127
- func (q * queryArgs ) withLogIndex (logIndex int64 ) * queryArgs {
128
- return q .withField ("log_index" , logIndex )
129
- }
130
-
131
- // withBlockHash sets the BlockHash field in Log.
132
- func (q * queryArgs ) withBlockHash (blockHash solana.Hash ) * queryArgs {
133
- return q .withField ("block_hash" , blockHash )
134
- }
135
-
136
- // withBlockNumber sets the BlockNumber field in Log.
137
- func (q * queryArgs ) withBlockNumber (blockNumber int64 ) * queryArgs {
138
- return q .withField ("block_number" , blockNumber )
139
- }
140
-
141
- // withBlockTimestamp sets the BlockTimestamp field in Log.
142
- func (q * queryArgs ) withBlockTimestamp (blockTimestamp time.Time ) * queryArgs {
143
- return q .withField ("block_timestamp" , blockTimestamp )
144
- }
145
-
146
- // withSubkeyValues sets the SubkeyValues field in Log.
147
- func (q * queryArgs ) withSubkeyValues (subkeyValues pq.ByteaArray ) * queryArgs {
148
- return q .withField ("subkey_values" , subkeyValues )
149
- }
150
-
151
- // withTxHash sets the TxHash field in Log.
152
- func (q * queryArgs ) withTxHash (txHash solana.Signature ) * queryArgs {
153
- return q .withField ("tx_hash" , txHash )
154
- }
155
-
156
- // withData sets the Data field in Log.
157
- func (q * queryArgs ) withData (data []byte ) * queryArgs {
158
- return q .withField ("data" , data )
159
- }
160
-
161
- // withCreatedAt sets the CreatedAt field in Log.
162
- func (q * queryArgs ) withCreatedAt (createdAt time.Time ) * queryArgs {
163
- return q .withField ("created_at" , createdAt )
164
- }
165
-
166
- // withExpiresAt sets the ExpiresAt field in Log.
167
- func (q * queryArgs ) withExpiresAt (expiresAt * time.Time ) * queryArgs {
168
- return q .withField ("expires_at" , expiresAt )
169
- }
170
-
171
- // withSequenceNum sets the SequenceNum field in Log.
172
- func (q * queryArgs ) withSequenceNum (sequenceNum int64 ) * queryArgs {
173
- return q .withField ("sequence_num" , sequenceNum )
174
- }
175
-
176
- func newQueryArgsForEvent (chainId string , address PublicKey , eventSig []byte ) * queryArgs {
177
- return newQueryArgs (chainId ).
102
+ func newQueryArgsForEvent (chainID string , address PublicKey , eventSig []byte ) * queryArgs {
103
+ return newQueryArgs (chainID ).
178
104
withAddress (address ).
179
105
withEventSig (eventSig )
180
106
}
0 commit comments