Skip to content

Commit

Permalink
feat: add block data
Browse files Browse the repository at this point in the history
Signed-off-by: Ales Verbic <[email protected]>
  • Loading branch information
verbotenj committed Sep 1, 2023
1 parent ec8a5ef commit 11eda5d
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions internal/miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 11eda5d

Please sign in to comment.