@@ -14,17 +14,11 @@ import (
14
14
input_chainsync "github.com/blinklabs-io/snek/input/chainsync"
15
15
output_embedded "github.com/blinklabs-io/snek/output/embedded"
16
16
"github.com/blinklabs-io/snek/pipeline"
17
- "github.com/miekg/dns"
18
17
)
19
18
20
19
type Domain struct {
21
- name string
22
- records map [string ]map [string ][]DomainRecord
23
- }
24
-
25
- type DomainRecord struct {
26
- Name string
27
- Value string
20
+ Name string
21
+ Nameservers map [string ]string
28
22
}
29
23
30
24
type Indexer struct {
@@ -120,63 +114,31 @@ func (i *Indexer) handleEvent(evt event.Event) error {
120
114
}
121
115
datumFields := datum .Value ().(cbor.Constructor ).Fields ()
122
116
domainName := string (datumFields [0 ].(cbor.ByteString ).Bytes ()) + `.`
117
+ // Create empty domain record
118
+ // This will also clobber any previous definition of the domain
119
+ i .domains [domainName ] = Domain {
120
+ Name : domainName ,
121
+ Nameservers : make (map [string ]string ),
122
+ }
123
123
for _ , record := range datumFields [1 ].([]any ) {
124
124
recordConstructor := record .(cbor.Constructor )
125
125
nameServer := string (recordConstructor .Fields ()[0 ].(cbor.ByteString ).Bytes ()) + `.`
126
126
ipAddress := string (recordConstructor .Fields ()[1 ].(cbor.ByteString ).Bytes ())
127
- // Create NS record for domain
128
- i .addRecord (domainName , domainName , "NS" , nameServer )
129
- // Create A record for name server
130
- i .addRecord (domainName , nameServer , "A" , ipAddress )
127
+ i .domains [domainName ].Nameservers [nameServer ] = ipAddress
131
128
}
132
129
logger .Infof ("found updated registration for domain: %s" , domainName )
133
130
}
134
131
}
135
132
return nil
136
133
}
137
134
138
- func (i * Indexer ) LookupRecords (name string , recordType string ) []DomainRecord {
139
- for domainName , domain := range i .domains {
140
- if dns .IsSubDomain (domainName , name ) {
141
- if records , ok := domain .records [name ]; ok {
142
- if record , ok := records [recordType ]; ok {
143
- return record
144
- } else {
145
- return nil
146
- }
147
- } else {
148
- return nil
149
- }
150
- }
135
+ func (i * Indexer ) LookupDomain (name string ) * Domain {
136
+ if domain , ok := i .domains [name ]; ok {
137
+ return & domain
151
138
}
152
139
return nil
153
140
}
154
141
155
- func (i * Indexer ) addRecord (domainName string , recordName string , recordType string , value string ) {
156
- // Create initial domain record
157
- if _ , ok := i .domains [domainName ]; ! ok {
158
- i .domains [domainName ] = Domain {
159
- name : domainName ,
160
- records : make (map [string ]map [string ][]DomainRecord ),
161
- }
162
- }
163
- // Create initial list for record type
164
- if _ , ok := i .domains [domainName ].records [recordName ]; ! ok {
165
- i .domains [domainName ].records [recordName ] = make (map [string ][]DomainRecord )
166
- if _ , ok := i .domains [domainName ].records [recordName ][recordType ]; ! ok {
167
- i .domains [domainName ].records [recordName ][recordType ] = make ([]DomainRecord , 0 )
168
- }
169
- }
170
- // Create record
171
- i .domains [domainName ].records [recordName ][recordType ] = append (
172
- i .domains [domainName ].records [recordName ][recordType ],
173
- DomainRecord {
174
- Name : recordName ,
175
- Value : value ,
176
- },
177
- )
178
- }
179
-
180
142
// GetIndexer returns the global indexer instance
181
143
func GetIndexer () * Indexer {
182
144
return globalIndexer
0 commit comments