Skip to content

Commit

Permalink
Merge pull request #23 from blinklabs-io/feat/parse-datum
Browse files Browse the repository at this point in the history
feat: parse on-chain datum
  • Loading branch information
agaffney authored Sep 2, 2023
2 parents b943ce9 + b6cbb2c commit 5013cf8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
30 changes: 13 additions & 17 deletions internal/indexer/indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/blinklabs-io/bluefin/internal/config"
"github.com/blinklabs-io/bluefin/internal/logging"
"github.com/blinklabs-io/bluefin/internal/miner"
"github.com/blinklabs-io/bluefin/internal/storage"
"github.com/blinklabs-io/bluefin/internal/wallet"

Expand All @@ -22,19 +23,6 @@ type Indexer struct {
pipeline *pipeline.Pipeline
}

type Datum struct {
nonce uint64
state State //nolint:unused
}

type State struct {
BlockNumber uint64
CurrentHash []byte
LeadingZeros uint64
DifficultyNumber uint64
EpochTime uint64
}

// Singleton indexer instance
var globalIndexer = &Indexer{}

Expand Down Expand Up @@ -146,13 +134,21 @@ func (i *Indexer) handleEvent(evt event.Event) error {
return err
}
datumFields := datum.Value().(cbor.Constructor).Fields()
var data = Datum{
nonce: datumFields[0].(uint64),
blockData := miner.BlockData{
BlockNumber: int64(datumFields[0].(uint64)),
TargetHash: datumFields[1].(cbor.ByteString).String(),
LeadingZeros: int64(datumFields[2].(uint64)),
DifficultyNumber: int64(datumFields[3].(uint64)),
EpochTime: int64(datumFields[4].(uint64)),
RealTimeNow: int64(datumFields[5].(uint64)),
}
switch v := datumFields[6].(type) {
case cbor.ByteString:
blockData.Message = v.String()
}
state := datumFields[1].(cbor.ByteString).String()
// TODO: do the thing

logger.Infof("found updated datum: nonce: %d, state: %s", data.nonce, state)
logger.Infof("found updated datum: %#v", blockData)
}
}
return nil
Expand Down
4 changes: 2 additions & 2 deletions internal/miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type BlockData struct {
EpochTime int64
RealTimeNow int64
Message string
Interlink []byte
Interlink [][]byte
}

type Miner struct {
Expand Down Expand Up @@ -88,7 +88,7 @@ func (m *Miner) Start() error {
difficultyNumber := state.DifficultyNumber
epochTime := state.DifficultyNumber + 90000 + realTimeNow - state.EpochTime
// TODO: calculate interlink
interlink := []byte("sampleInterlink")
interlink := [][]byte{[]byte("sampleInterlink")}

// Construct the new block data
postDatum := BlockData{
Expand Down

0 comments on commit 5013cf8

Please sign in to comment.