OSDN Git Service

delete miner
authormars <mars@bytom.io>
Sun, 25 Nov 2018 10:21:14 +0000 (18:21 +0800)
committermars <mars@bytom.io>
Sun, 25 Nov 2018 10:21:14 +0000 (18:21 +0800)
cmd/miner/main.go [deleted file]

diff --git a/cmd/miner/main.go b/cmd/miner/main.go
deleted file mode 100644 (file)
index ebb978a..0000000
+++ /dev/null
@@ -1,96 +0,0 @@
-package main
-
-import (
-       "encoding/json"
-       "log"
-       "os"
-
-       "github.com/vapor/api"
-       "github.com/vapor/consensus"
-       "github.com/vapor/consensus/difficulty"
-       "github.com/vapor/protocol/bc"
-       "github.com/vapor/protocol/bc/types"
-       "github.com/vapor/util"
-)
-
-const (
-       maxNonce = ^uint64(0) // 2^64 - 1
-       isCrazy  = true
-       esHR     = 1 //estimated Hashrate
-)
-
-var (
-       lastNonce  = ^uint64(0)
-       lastHeight = uint64(0)
-)
-
-// do proof of work
-func doWork(bh *types.BlockHeader, seed *bc.Hash) bool {
-       log.Println("Start from nonce:", lastNonce+1)
-       for i := uint64(lastNonce + 1); i <= uint64(lastNonce+consensus.TargetSecondsPerBlock*esHR) && i <= maxNonce; i++ {
-               bh.Nonce = i
-               // log.Printf("nonce = %v\n", i)
-               headerHash := bh.Hash()
-               if difficulty.CheckProofOfWork(&headerHash, seed, bh.Bits) {
-                       log.Printf("Mining succeed! Proof hash: %v\n", headerHash.String())
-                       return true
-               }
-       }
-       log.Println("Stop at nonce:", bh.Nonce)
-       lastNonce = bh.Nonce
-       return false
-}
-
-func getBlockHeaderByHeight(height uint64) {
-       type Req struct {
-               BlockHeight uint64 `json:"block_height"`
-       }
-
-       type Resp struct {
-               BlockHeader *types.BlockHeader `json:"block_header"`
-               Reward      uint64             `json:"reward"`
-       }
-
-       data, _ := util.ClientCall("/get-block-header", Req{BlockHeight: height})
-       rawData, err := json.Marshal(data)
-       if err != nil {
-               log.Fatalln(err)
-       }
-
-       resp := &Resp{}
-       if err = json.Unmarshal(rawData, resp); err != nil {
-               log.Fatalln(err)
-       }
-       log.Println("Reward:", resp.Reward)
-}
-
-func main() {
-       for true {
-               data, _ := util.ClientCall("/get-work", nil)
-               if data == nil {
-                       os.Exit(1)
-               }
-               rawData, err := json.Marshal(data)
-               if err != nil {
-                       log.Fatalln(err)
-               }
-               resp := &api.GetWorkResp{}
-               if err = json.Unmarshal(rawData, resp); err != nil {
-                       log.Fatalln(err)
-               }
-
-               log.Println("Mining at height:", resp.BlockHeader.Height)
-               if lastHeight != resp.BlockHeader.Height {
-                       lastNonce = ^uint64(0)
-               }
-               if doWork(resp.BlockHeader, resp.Seed) {
-                       util.ClientCall("/submit-work", &api.SubmitWorkReq{BlockHeader: resp.BlockHeader})
-                       getBlockHeaderByHeight(resp.BlockHeader.Height)
-               }
-
-               lastHeight = resp.BlockHeader.Height
-               if !isCrazy {
-                       return
-               }
-       }
-}