OSDN Git Service

move back BlockHeaderJSON into api package
authorHAOYUatHZ <haoyu@protonmail.com>
Tue, 5 Jun 2018 08:01:35 +0000 (16:01 +0800)
committerHAOYUatHZ <haoyu@protonmail.com>
Tue, 5 Jun 2018 08:01:35 +0000 (16:01 +0800)
api/miner.go
protocol/bc/types/block_header.go

index 5613bcf..d0b1c27 100644 (file)
@@ -8,6 +8,18 @@ import (
        "github.com/bytom/protocol/bc/types"
 )
 
+// BlockHeaderJSON struct provides support for get work in json format, when it also follows
+// BlockHeader structure
+type BlockHeaderJSON struct {
+       Version           uint64                 `json:"version"`             // The version of the block.
+       Height            uint64                 `json:"height"`              // The height of the block.
+       PreviousBlockHash bc.Hash                `json:"previous_block_hash"` // The hash of the previous block.
+       Timestamp         uint64                 `json:"timestamp"`           // The time of the block in seconds.
+       Nonce             uint64                 `json:"nonce"`               // Nonce used to generate the block.
+       Bits              uint64                 `json:"bits"`                // Difficulty target for the block.
+       BlockCommitment   *types.BlockCommitment `json:"block_commitment"`    //Block commitment
+}
+
 // getWork gets work in compressed protobuf format
 func (a *API) getWork() Response {
        work, err := a.GetWork()
@@ -41,7 +53,7 @@ func (a *API) submitWork(ctx context.Context, req *SubmitWorkReq) Response {
 
 // SubmitWorkJSONReq is req struct for submit-work-json API
 type SubmitWorkJSONReq struct {
-       BlockHeader *types.BlockHeaderJSON `json:"block_header"`
+       BlockHeader *BlockHeaderJSON `json:"block_header"`
 }
 
 // submitWorkJSON submits work in json format
@@ -53,7 +65,7 @@ func (a *API) submitWorkJSON(ctx context.Context, req *SubmitWorkJSONReq) Respon
                Timestamp:         req.BlockHeader.Timestamp,
                Nonce:             req.BlockHeader.Nonce,
                Bits:              req.BlockHeader.Bits,
-               BlockCommitment:   req.BlockHeader.BlockCommitment,
+               BlockCommitment:   *req.BlockHeader.BlockCommitment,
        }
 
        if err := a.SubmitWork(bh); err != nil {
@@ -88,8 +100,8 @@ func (a *API) GetWork() (*GetWorkResp, error) {
 
 // GetWorkJSONResp is resp struct for get-work-json API
 type GetWorkJSONResp struct {
-       BlockHeader *types.BlockHeaderJSON `json:"block_header"`
-       Seed        *bc.Hash               `json:"seed"`
+       BlockHeader *BlockHeaderJSON `json:"block_header"`
+       Seed        *bc.Hash         `json:"seed"`
 }
 
 // GetWorkJSON gets work in json format
@@ -105,14 +117,14 @@ func (a *API) GetWorkJSON() (*GetWorkJSONResp, error) {
        }
 
        return &GetWorkJSONResp{
-               BlockHeader: &types.BlockHeaderJSON{
+               BlockHeader: &BlockHeaderJSON{
                        Version:           bh.Version,
                        Height:            bh.Height,
                        PreviousBlockHash: bh.PreviousBlockHash,
                        Timestamp:         bh.Timestamp,
                        Nonce:             bh.Nonce,
                        Bits:              bh.Bits,
-                       BlockCommitment:   bh.BlockCommitment,
+                       BlockCommitment:   &bh.BlockCommitment,
                },
                Seed: seed,
        }, nil
index b027967..f15184b 100644 (file)
@@ -23,18 +23,6 @@ type BlockHeader struct {
        BlockCommitment
 }
 
-// BlockHeaderJSON struct provides support for get work in json format, when it also follows
-// BlockHeader structure
-type BlockHeaderJSON struct {
-       Version           uint64                    `json:"version"`             // The version of the block.
-       Height            uint64                    `json:"height"`              // The height of the block.
-       PreviousBlockHash bc.Hash                   `json:"previous_block_hash"` // The hash of the previous block.
-       Timestamp         uint64                    `json:"timestamp"`           // The time of the block in seconds.
-       Nonce             uint64                    `json:"nonce"`               // Nonce used to generate the block.
-       Bits              uint64                    `json:"bits"`                // Difficulty target for the block.
-       BlockCommitment   `json:"block_commitment"` //Block commitment
-}
-
 // Time returns the time represented by the Timestamp in block header.
 func (bh *BlockHeader) Time() time.Time {
        return time.Unix(int64(bh.Timestamp), 0).UTC()