Skip to content

Commit

Permalink
Merge pull request #77 from blinklabs-io/feat/datum-format-update
Browse files Browse the repository at this point in the history
feat: update datum format in resolver
  • Loading branch information
wolf31o2 authored Nov 18, 2023
2 parents 53dcc35 + aefebb3 commit 45f536e
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 22 deletions.
7 changes: 4 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module github.com/blinklabs-io/cdnsd
go 1.20

require (
github.com/blinklabs-io/gouroboros v0.62.0
github.com/blinklabs-io/cardano-models v0.1.0
github.com/blinklabs-io/gouroboros v0.64.0
github.com/blinklabs-io/snek v0.15.0
github.com/dgraph-io/badger/v4 v4.2.0
github.com/kelseyhightower/envconfig v1.4.0
Expand All @@ -29,10 +30,10 @@ require (
github.com/x448/float16 v0.8.4 // indirect
go.opencensus.io v0.22.5 // indirect
go.uber.org/multierr v1.10.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/crypto v0.15.0 // indirect
golang.org/x/mod v0.13.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/sys v0.14.0 // indirect
golang.org/x/tools v0.14.0 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
14 changes: 8 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/blinklabs-io/gouroboros v0.62.0 h1:vfTjXeIbrc4aLr0svKXNZbAujM2VWh6PU8MBOlZaf5c=
github.com/blinklabs-io/gouroboros v0.62.0/go.mod h1:D5YJka8EyVmiXNMbRvjH23H9lNMLA4+qSlNNC/j7R0k=
github.com/blinklabs-io/cardano-models v0.1.0 h1:tgSAuo8V8cXDeDf4OrevY3Aj5AIJSjI1DINAOrQeda0=
github.com/blinklabs-io/cardano-models v0.1.0/go.mod h1:XYJvY5XE6vTKbVVK1YqUq615T/bUoeavcc9zG25M8Os=
github.com/blinklabs-io/gouroboros v0.64.0 h1:8wm1blxhE+qI/GElc3/pmi3YoI3jepEEPFJK6LkP/JE=
github.com/blinklabs-io/gouroboros v0.64.0/go.mod h1:fph4LBNmSliMxt5ut40lXqqbZHWmXjT6p7o1hCyDEbQ=
github.com/blinklabs-io/snek v0.15.0 h1:opj+apWge2ujHIDiFrI08P6rW7gUeKRsNXzje8UCjx4=
github.com/blinklabs-io/snek v0.15.0/go.mod h1:9pR+B/oQ/bf+G6tB4NnA6x0i10+ucDixpHc0LzF6500=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
Expand Down Expand Up @@ -74,8 +76,8 @@ go.uber.org/zap v1.26.0/go.mod h1:dtElttAiwGvoJ/vj4IwHBS/gXsEu/pZ50mUIRWuG0so=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.14.0 h1:wBqGXzWJW6m1XrIKlAH0Hs1JJ7+9KBwnIO8v66Q9cHc=
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4=
golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA=
golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
Expand Down Expand Up @@ -108,8 +110,8 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20221010170243-090e33056c14/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
30 changes: 17 additions & 13 deletions internal/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ package indexer

import (
"encoding/hex"
"strings"

"github.com/blinklabs-io/cdnsd/internal/config"
"github.com/blinklabs-io/cdnsd/internal/logging"
"github.com/blinklabs-io/cdnsd/internal/state"

models "github.com/blinklabs-io/cardano-models"
"github.com/blinklabs-io/gouroboros/cbor"
ocommon "github.com/blinklabs-io/gouroboros/protocol/common"
"github.com/blinklabs-io/snek/event"
Expand Down Expand Up @@ -156,26 +158,28 @@ func (i *Indexer) handleEvent(evt event.Event) error {
for _, txOutput := range eventTx.Outputs {
datum := txOutput.Datum()
if datum != nil {
if _, err := datum.Decode(); err != nil {
var dnsDomain models.CardanoDnsDomain
if _, err := cbor.Decode(datum.Cbor(), &dnsDomain); err != nil {
logger.Warnf(
"error decoding TX (%s) output datum: %s",
eventCtx.TransactionHash,
err,
)
return err
// Stop processing TX output if we can't parse the datum
continue
}
datumFields := datum.Value().(cbor.Constructor).Fields()
domainName := string(datumFields[0].(cbor.ByteString).Bytes())
domainName := string(dnsDomain.Origin)
nameServers := map[string]string{}
for _, record := range datumFields[1].([]any) {
recordConstructor := record.(cbor.Constructor)
nameServer := string(
recordConstructor.Fields()[0].(cbor.ByteString).Bytes(),
)
ipAddress := string(
recordConstructor.Fields()[1].(cbor.ByteString).Bytes(),
)
nameServers[nameServer] = ipAddress
for _, record := range dnsDomain.Records {
// NOTE: we're losing information here, but we need to revamp the storage
// format before we can use it. We're also making the assumption that all
// records are for nameservers
switch strings.ToUpper(string(record.Type)) {
case "A", "AAAA":
nameServers[string(record.Lhs)] = string(record.Rhs)
default:
continue
}
}
if err := state.GetState().UpdateDomain(domainName, nameServers); err != nil {
return err
Expand Down

0 comments on commit 45f536e

Please sign in to comment.