OSDN Git Service

Miner - proof of work (#311)
[bytom/bytom.git] / blockchain / miner.go
1 package blockchain
2
3 import (
4         "github.com/bytom/mining"
5         "github.com/bytom/protocol/bc/legacy"
6 )
7
8 // Get the parameters of mining
9 func (bcr *BlockchainReactor) getWork() *WorkResp {
10         var resp WorkResp
11         if block, err := mining.NewBlockTemplate(bcr.chain, bcr.txPool, bcr.accounts); err != nil {
12                 return nil
13         } else {
14                 resp.Header = block.BlockHeader
15         }
16         seedCaches := bcr.chain.SeedCaches()
17         if seedCache, err := seedCaches.Get(&resp.Header.Seed); err != nil {
18                 return nil
19         } else {
20                 resp.Cache = seedCache
21         }
22
23         return &resp
24 }
25
26 type WorkResp struct {
27         Header legacy.BlockHeader
28         Cache  []uint32
29 }