@@ -141,8 +141,12 @@ func (i *Indexer) Start() error {
141
141
)
142
142
i .pipeline .AddFilter (filterEvent )
143
143
// We only care about transactions on a certain address
144
+ var filterAddresses []string
145
+ for _ , profile := range config .GetProfiles () {
146
+ filterAddresses = append (filterAddresses , profile .ScriptAddress )
147
+ }
144
148
filterChainsync := filter_chainsync .New (
145
- filter_chainsync .WithAddresses ([] string { cfg . Indexer . ScriptAddress } ),
149
+ filter_chainsync .WithAddresses (filterAddresses ),
146
150
)
147
151
i .pipeline .AddFilter (filterChainsync )
148
152
// Configure pipeline output
@@ -172,102 +176,107 @@ func (i *Indexer) handleEvent(evt event.Event) error {
172
176
eventTx := evt .Payload .(input_chainsync.TransactionEvent )
173
177
eventCtx := evt .Context .(input_chainsync.TransactionContext )
174
178
for _ , txOutput := range eventTx .Outputs {
175
- datum := txOutput .Datum ()
176
- if datum != nil {
177
- var dnsDomain models.CardanoDnsDomain
178
- if _ , err := cbor .Decode (datum .Cbor (), & dnsDomain ); err != nil {
179
- logger .Warnf (
180
- "error decoding TX (%s) output datum: %s" ,
181
- eventCtx .TransactionHash ,
182
- err ,
183
- )
184
- // Stop processing TX output if we can't parse the datum
179
+ for _ , profile := range config .GetProfiles () {
180
+ if txOutput .Address ().String () != profile .ScriptAddress {
185
181
continue
186
182
}
187
- origin := string (dnsDomain .Origin )
188
- // Convert origin to canonical form for consistency
189
- // This mostly means adding a trailing period if it doesn't have one
190
- domainName := dns .CanonicalName (origin )
191
- // We want an empty value for the TLD root for convenience
192
- if domainName == `.` {
193
- domainName = ``
194
- }
195
- // Append TLD
196
- domainName = dns .CanonicalName (
197
- domainName + cfg .Indexer .Tld ,
198
- )
199
- if cfg .Indexer .Verify {
200
- // Look for asset matching domain origin and TLD policy ID
201
- if txOutput .Assets () == nil {
183
+ datum := txOutput .Datum ()
184
+ if datum != nil {
185
+ var dnsDomain models.CardanoDnsDomain
186
+ if _ , err := cbor .Decode (datum .Cbor (), & dnsDomain ); err != nil {
202
187
logger .Warnf (
203
- "ignoring datum for domain %q with no matching asset" ,
204
- domainName ,
188
+ "error decoding TX (%s) output datum: %s" ,
189
+ eventCtx .TransactionHash ,
190
+ err ,
205
191
)
192
+ // Stop processing TX output if we can't parse the datum
206
193
continue
207
194
}
208
- foundAsset := false
209
- for _ , policyId := range txOutput .Assets ().Policies () {
210
- for _ , assetName := range txOutput .Assets ().Assets (policyId ) {
211
- if policyId .String () == cfg .Indexer .PolicyId {
212
- if string (assetName ) == string (origin ) {
213
- foundAsset = true
195
+ origin := string (dnsDomain .Origin )
196
+ // Convert origin to canonical form for consistency
197
+ // This mostly means adding a trailing period if it doesn't have one
198
+ domainName := dns .CanonicalName (origin )
199
+ // We want an empty value for the TLD root for convenience
200
+ if domainName == `.` {
201
+ domainName = ``
202
+ }
203
+ // Append TLD
204
+ domainName = dns .CanonicalName (
205
+ domainName + profile .Tld ,
206
+ )
207
+ if cfg .Indexer .Verify {
208
+ // Look for asset matching domain origin and TLD policy ID
209
+ if txOutput .Assets () == nil {
210
+ logger .Warnf (
211
+ "ignoring datum for domain %q with no matching asset" ,
212
+ domainName ,
213
+ )
214
+ continue
215
+ }
216
+ foundAsset := false
217
+ for _ , policyId := range txOutput .Assets ().Policies () {
218
+ for _ , assetName := range txOutput .Assets ().Assets (policyId ) {
219
+ if policyId .String () == profile .PolicyId {
220
+ if string (assetName ) == string (origin ) {
221
+ foundAsset = true
222
+ } else {
223
+ logger .Warnf (
224
+ "ignoring datum for domain %q with no matching asset" ,
225
+ domainName ,
226
+ )
227
+ }
214
228
} else {
215
229
logger .Warnf (
216
230
"ignoring datum for domain %q with no matching asset" ,
217
231
domainName ,
218
232
)
219
233
}
220
- } else {
234
+ }
235
+ }
236
+ if ! foundAsset {
237
+ continue
238
+ }
239
+ // Make sure all records are for specified origin domain
240
+ badRecordName := false
241
+ for _ , record := range dnsDomain .Records {
242
+ recordName := dns .CanonicalName (
243
+ string (record .Lhs ),
244
+ )
245
+ if ! strings .HasSuffix (recordName , domainName ) {
221
246
logger .Warnf (
222
- "ignoring datum for domain %q with no matching asset" ,
247
+ "ignoring datum with record %q outside of origin domain (%s)" ,
248
+ recordName ,
223
249
domainName ,
224
250
)
251
+ badRecordName = true
252
+ break
225
253
}
226
254
}
255
+ if badRecordName {
256
+ continue
257
+ }
227
258
}
228
- if ! foundAsset {
229
- continue
230
- }
231
- // Make sure all records are for specified origin domain
232
- badRecordName := false
259
+ // Convert domain records into our storage format
260
+ tmpRecords := []state.DomainRecord {}
233
261
for _ , record := range dnsDomain .Records {
234
- recordName := dns .CanonicalName (
235
- string (record .Lhs ),
236
- )
237
- if ! strings .HasSuffix (recordName , domainName ) {
238
- logger .Warnf (
239
- "ignoring datum with record %q outside of origin domain (%s)" ,
240
- recordName ,
241
- domainName ,
242
- )
243
- badRecordName = true
244
- break
262
+ tmpRecord := state.DomainRecord {
263
+ Lhs : string (record .Lhs ),
264
+ Type : string (record .Type ),
265
+ Rhs : string (record .Rhs ),
245
266
}
267
+ if record .Ttl .HasValue () {
268
+ tmpRecord .Ttl = int (record .Ttl .Value )
269
+ }
270
+ tmpRecords = append (tmpRecords , tmpRecord )
246
271
}
247
- if badRecordName {
248
- continue
249
- }
250
- }
251
- // Convert domain records into our storage format
252
- tmpRecords := []state.DomainRecord {}
253
- for _ , record := range dnsDomain .Records {
254
- tmpRecord := state.DomainRecord {
255
- Lhs : string (record .Lhs ),
256
- Type : string (record .Type ),
257
- Rhs : string (record .Rhs ),
258
- }
259
- if record .Ttl .HasValue () {
260
- tmpRecord .Ttl = int (record .Ttl .Value )
272
+ if err := state .GetState ().UpdateDomain (domainName , tmpRecords ); err != nil {
273
+ return err
261
274
}
262
- tmpRecords = append ( tmpRecords , tmpRecord )
263
- }
264
- if err := state . GetState (). UpdateDomain ( domainName , tmpRecords ); err != nil {
265
- return err
275
+ logger . Infof (
276
+ "found updated registration for domain: %s" ,
277
+ domainName ,
278
+ )
266
279
}
267
- logger .Infof (
268
- "found updated registration for domain: %s" ,
269
- domainName ,
270
- )
271
280
}
272
281
}
273
282
return nil
0 commit comments