From 11eda5d9c85dc9afe61d869502b555fdc9bc68f3 Mon Sep 17 00:00:00 2001 From: Ales Verbic Date: Fri, 1 Sep 2023 17:40:53 -0400 Subject: [PATCH] feat: add block data Signed-off-by: Ales Verbic --- internal/miner/miner.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/internal/miner/miner.go b/internal/miner/miner.go index 42db4c9..9114436 100644 --- a/internal/miner/miner.go +++ b/internal/miner/miner.go @@ -19,12 +19,24 @@ import ( "encoding/binary" "encoding/hex" "fmt" + "time" "github.com/blinklabs-io/bluefin/internal/config" "github.com/blinklabs-io/bluefin/internal/logging" "github.com/minio/sha256-simd" ) +type BlockData struct { + BlockNumber int64 + TargetHash string + LeadingZeros int64 + DifficultyNumber int64 + EpochTime int64 + RealTimeNow int64 + Message string + Interlink []byte +} + type Miner struct { Config *config.Config Logger *logging.Logger @@ -65,6 +77,31 @@ func (m *Miner) Start() error { hash, nonce := calculateHash(state) fmt.Printf("Hash with leading zeros: %s\n", hash) fmt.Printf("Nonce: %d\n", nonce) + + realTimeNow := time.Now().Unix()*1000 - 60000 + + // TODO prepare things for a new block and clean up + // Sample values for the new block + targetHash := hash + leadingZeros := state.LeadingZeros + difficultyNumber := state.DifficultyNumber + epochTime := state.DifficultyNumber + 90000 + realTimeNow - state.EpochTime + // TODO: calculate interlink + interlink := []byte("sampleInterlink") + + // Construct the new block data + postDatum := BlockData{ + BlockNumber: state.BlockNumber + 1, + TargetHash: targetHash, + LeadingZeros: leadingZeros, + DifficultyNumber: difficultyNumber, + EpochTime: epochTime, + RealTimeNow: 90000 + realTimeNow, + Message: "AlL HaIl tUnA", + Interlink: interlink, + } + // Fund next datum + fmt.Printf("Fund next datum %+v\n", postDatum) return nil }