Skip to content

Commit 7320506

Browse files
committed
feat: TLD auto-discovery
1 parent 7deaa0e commit 7320506

File tree

5 files changed

+382
-119
lines changed

5 files changed

+382
-119
lines changed

internal/config/config.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ var globalConfig = &Config{
9191
Directory: "./.state",
9292
},
9393
Profiles: []string{
94+
// NOTE: this is here because .ada wasn't added to the discovery address when it was originally deployed
9495
"ada-preprod",
95-
"hydra-preprod",
96+
"auto-preprod",
9697
},
9798
}
9899

internal/config/profile.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2023 Blink Labs Software
1+
// Copyright 2024 Blink Labs Software
22
//
33
// Use of this source code is governed by an MIT-style
44
// license that can be found in the LICENSE file or at
@@ -7,12 +7,13 @@
77
package config
88

99
type Profile struct {
10-
Network string // Cardano network name
11-
Tld string // Top-level domain
12-
PolicyId string // Verification asset policy ID
13-
ScriptAddress string // Address to follow
14-
InterceptSlot uint64 // Chain-sync initial intercept slot
15-
InterceptHash string // Chain-sync initial intercept hash
10+
Network string // Cardano network name
11+
Tld string // Top-level domain
12+
PolicyId string // Verification asset policy ID
13+
ScriptAddress string // Address to follow
14+
InterceptSlot uint64 // Chain-sync initial intercept slot
15+
InterceptHash string // Chain-sync initial intercept hash
16+
DiscoveryAddress string // Auto-discovery address to follow
1617
}
1718

1819
func GetProfiles() []Profile {
@@ -65,4 +66,12 @@ var Profiles = map[string]Profile{
6566
InterceptSlot: 67799029,
6667
InterceptHash: "4815dae9cd8f492ab51b109ba87d091ae85a0999af33ac459d8504122cb911f7",
6768
},
69+
"auto-preprod": Profile{
70+
Network: "preprod",
71+
PolicyId: "63cdaef8b84702282c3454ae130ada94a9b200e32be21abd47fc636b",
72+
DiscoveryAddress: "addr_test1xrhqrug2hnc9az4ru02kp9rlfcppl464gl4yc8s8jm5p8kygc3uvcfh3r3kaa5gyk5l2vgdl8vj8cstslf4w2ajuy0wsp5fm89",
73+
// The intercept slot/hash correspond to the block before the first TX on the above address
74+
InterceptSlot: 67778432,
75+
InterceptHash: "6db5cdcfa1ee9cc137b0b238ff9251d4481c23bf49ad6272cb833b034a003cbe",
76+
},
6877
}

internal/indexer/datum.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2024 Blink Labs Software
2+
//
3+
// Use of this source code is governed by an MIT-style
4+
// license that can be found in the LICENSE file or at
5+
// https://opensource.org/licenses/MIT.
6+
7+
package indexer
8+
9+
import (
10+
"fmt"
11+
12+
"github.com/blinklabs-io/gouroboros/cbor"
13+
)
14+
15+
// DNSReferenceRefScriptDatum represents the auto-discovery datum type for scripts that handle DNS records
16+
type DNSReferenceRefScriptDatum struct {
17+
// This allows the type to be used with cbor.DecodeGeneric
18+
cbor.StructAsArray
19+
TldName []byte
20+
SymbolDrat []byte
21+
SymbolHns []byte
22+
}
23+
24+
func (d *DNSReferenceRefScriptDatum) UnmarshalCBOR(cborData []byte) error {
25+
var tmpData cbor.Constructor
26+
if _, err := cbor.Decode(cborData, &tmpData); err != nil {
27+
return err
28+
}
29+
if tmpData.Constructor() != 3 {
30+
return fmt.Errorf("unexpected outer constructor index: %d", tmpData.Constructor())
31+
}
32+
tmpDataFields := tmpData.Fields()
33+
if len(tmpDataFields) != 1 {
34+
return fmt.Errorf("unexpected inner field count: expected 1, got %d", len(tmpDataFields))
35+
}
36+
fieldInner, ok := tmpDataFields[0].(cbor.Constructor)
37+
if !ok {
38+
return fmt.Errorf("unexpected data type %T for outer constructor field", tmpDataFields[0])
39+
}
40+
var tmpDataInner cbor.Constructor
41+
if _, err := cbor.Decode(fieldInner.Cbor(), &tmpDataInner); err != nil {
42+
return err
43+
}
44+
if tmpDataInner.Constructor() != 1 {
45+
return fmt.Errorf("unexpected inner constructor index: %d", tmpDataInner.Constructor())
46+
}
47+
return cbor.DecodeGeneric(tmpDataInner.FieldsCbor(), d)
48+
}

0 commit comments

Comments
 (0)