Skip to content

Commit

Permalink
feat: TLD auto-discovery (#199)
Browse files Browse the repository at this point in the history
  • Loading branch information
agaffney authored Aug 29, 2024
1 parent 6e8a7dc commit 03fdc76
Show file tree
Hide file tree
Showing 5 changed files with 382 additions and 119 deletions.
3 changes: 2 additions & 1 deletion internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ var globalConfig = &Config{
Directory: "./.state",
},
Profiles: []string{
// NOTE: this is here because .ada wasn't added to the discovery address when it was originally deployed
"ada-preprod",
"hydra-preprod",
"auto-preprod",
},
}

Expand Down
23 changes: 16 additions & 7 deletions internal/config/profile.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2023 Blink Labs Software
// Copyright 2024 Blink Labs Software
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
Expand All @@ -7,12 +7,13 @@
package config

type Profile struct {
Network string // Cardano network name
Tld string // Top-level domain
PolicyId string // Verification asset policy ID
ScriptAddress string // Address to follow
InterceptSlot uint64 // Chain-sync initial intercept slot
InterceptHash string // Chain-sync initial intercept hash
Network string // Cardano network name
Tld string // Top-level domain
PolicyId string // Verification asset policy ID
ScriptAddress string // Address to follow
InterceptSlot uint64 // Chain-sync initial intercept slot
InterceptHash string // Chain-sync initial intercept hash
DiscoveryAddress string // Auto-discovery address to follow
}

func GetProfiles() []Profile {
Expand Down Expand Up @@ -65,4 +66,12 @@ var Profiles = map[string]Profile{
InterceptSlot: 67799029,
InterceptHash: "4815dae9cd8f492ab51b109ba87d091ae85a0999af33ac459d8504122cb911f7",
},
"auto-preprod": Profile{
Network: "preprod",
PolicyId: "63cdaef8b84702282c3454ae130ada94a9b200e32be21abd47fc636b",
DiscoveryAddress: "addr_test1xrhqrug2hnc9az4ru02kp9rlfcppl464gl4yc8s8jm5p8kygc3uvcfh3r3kaa5gyk5l2vgdl8vj8cstslf4w2ajuy0wsp5fm89",
// The intercept slot/hash correspond to the block before the first TX on the above address
InterceptSlot: 67778432,
InterceptHash: "6db5cdcfa1ee9cc137b0b238ff9251d4481c23bf49ad6272cb833b034a003cbe",
},
}
48 changes: 48 additions & 0 deletions internal/indexer/datum.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2024 Blink Labs Software
//
// Use of this source code is governed by an MIT-style
// license that can be found in the LICENSE file or at
// https://opensource.org/licenses/MIT.

package indexer

import (
"fmt"

"github.com/blinklabs-io/gouroboros/cbor"
)

// DNSReferenceRefScriptDatum represents the auto-discovery datum type for scripts that handle DNS records
type DNSReferenceRefScriptDatum struct {
// This allows the type to be used with cbor.DecodeGeneric
cbor.StructAsArray
TldName []byte
SymbolDrat []byte
SymbolHns []byte
}

func (d *DNSReferenceRefScriptDatum) UnmarshalCBOR(cborData []byte) error {
var tmpData cbor.Constructor
if _, err := cbor.Decode(cborData, &tmpData); err != nil {
return err
}
if tmpData.Constructor() != 3 {
return fmt.Errorf("unexpected outer constructor index: %d", tmpData.Constructor())
}
tmpDataFields := tmpData.Fields()
if len(tmpDataFields) != 1 {
return fmt.Errorf("unexpected inner field count: expected 1, got %d", len(tmpDataFields))
}
fieldInner, ok := tmpDataFields[0].(cbor.Constructor)
if !ok {
return fmt.Errorf("unexpected data type %T for outer constructor field", tmpDataFields[0])
}
var tmpDataInner cbor.Constructor
if _, err := cbor.Decode(fieldInner.Cbor(), &tmpDataInner); err != nil {
return err
}
if tmpDataInner.Constructor() != 1 {
return fmt.Errorf("unexpected inner constructor index: %d", tmpDataInner.Constructor())
}
return cbor.DecodeGeneric(tmpDataInner.FieldsCbor(), d)
}
Loading

0 comments on commit 03fdc76

Please sign in to comment.