@@ -14,14 +14,28 @@ 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"
17
18
)
18
19
20
+ 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
28
+ }
29
+
19
30
type Indexer struct {
20
31
pipeline * pipeline.Pipeline
32
+ domains map [string ]Domain
21
33
}
22
34
23
35
// Singleton indexer instance
24
- var globalIndexer = & Indexer {}
36
+ var globalIndexer = & Indexer {
37
+ domains : make (map [string ]Domain ),
38
+ }
25
39
26
40
func (i * Indexer ) Start () error {
27
41
cfg := config .GetConfig ()
@@ -105,20 +119,63 @@ func (i *Indexer) handleEvent(evt event.Event) error {
105
119
return err
106
120
}
107
121
datumFields := datum .Value ().(cbor.Constructor ).Fields ()
108
- domainName := string (datumFields [0 ].(cbor.ByteString ).Bytes ())
109
- nsRecords := []string {}
122
+ domainName := string (datumFields [0 ].(cbor.ByteString ).Bytes ()) + `.`
110
123
for _ , record := range datumFields [1 ].([]any ) {
111
- nsRecords = append (
112
- nsRecords ,
113
- string (record .(cbor.ByteString ).Bytes ()),
114
- )
124
+ nameServer := string (record .(cbor.ByteString ).Bytes ()) + `.`
125
+ // Create NS record for domain
126
+ i .addRecord (domainName , domainName , "NS" , nameServer )
127
+ // Create A record for name server
128
+ // We use a dummy IP address for now, since the on-chain data doesn't contain the IP yet
129
+ i .addRecord (domainName , nameServer , "A" , "1.2.3.4" )
130
+ }
131
+ logger .Infof ("found updated registration for domain: %s" , domainName )
132
+ }
133
+ }
134
+ return nil
135
+ }
136
+
137
+ func (i * Indexer ) LookupRecords (name string , recordType string ) []DomainRecord {
138
+ for domainName , domain := range i .domains {
139
+ if dns .IsSubDomain (domainName , name ) {
140
+ if records , ok := domain .records [name ]; ok {
141
+ if record , ok := records [recordType ]; ok {
142
+ return record
143
+ } else {
144
+ return nil
145
+ }
146
+ } else {
147
+ return nil
115
148
}
116
- logger .Infof ("found domain %s with NS records: %v" , domainName , nsRecords )
117
149
}
118
150
}
119
151
return nil
120
152
}
121
153
154
+ func (i * Indexer ) addRecord (domainName string , recordName string , recordType string , value string ) {
155
+ // Create initial domain record
156
+ if _ , ok := i .domains [domainName ]; ! ok {
157
+ i .domains [domainName ] = Domain {
158
+ name : domainName ,
159
+ records : make (map [string ]map [string ][]DomainRecord ),
160
+ }
161
+ }
162
+ // Create initial list for record type
163
+ if _ , ok := i .domains [domainName ].records [recordName ]; ! ok {
164
+ i .domains [domainName ].records [recordName ] = make (map [string ][]DomainRecord )
165
+ if _ , ok := i .domains [domainName ].records [recordName ][recordType ]; ! ok {
166
+ i .domains [domainName ].records [recordName ][recordType ] = make ([]DomainRecord , 0 )
167
+ }
168
+ }
169
+ // Create record
170
+ i .domains [domainName ].records [recordName ][recordType ] = append (
171
+ i .domains [domainName ].records [recordName ][recordType ],
172
+ DomainRecord {
173
+ Name : recordName ,
174
+ Value : value ,
175
+ },
176
+ )
177
+ }
178
+
122
179
// GetIndexer returns the global indexer instance
123
180
func GetIndexer () * Indexer {
124
181
return globalIndexer
0 commit comments