X-Git-Url: http://git.osdn.net/view?p=bytom%2Fvapor.git;a=blobdiff_plain;f=api%2Fminer.go;fp=api%2Fminer.go;h=a7029e97de7759843bf1f9acea1873a99190fc3e;hp=71869d5f56c25f3f053063d893042e7b745b56bb;hb=54373c1a3efe0e373ec1605840a4363e4b246c46;hpb=ee01d543fdfe1fd0a4d548965c66f7923ea7b062 diff --git a/api/miner.go b/api/miner.go index 71869d5f..a7029e97 100644 --- a/api/miner.go +++ b/api/miner.go @@ -6,22 +6,10 @@ import ( chainjson "github.com/vapor/encoding/json" "github.com/vapor/errors" - "github.com/vapor/protocol/bc" + "github.com/vapor/event" "github.com/vapor/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 -} - type CoinbaseArbitrary struct { Arbitrary chainjson.HexBytes `json:"arbitrary"` } @@ -61,35 +49,16 @@ func (a *API) submitBlock(ctx context.Context, req *SubmitBlockReq) Response { if err != nil { return NewErrorResponse(err) } + if isOrphan { return NewErrorResponse(errors.New("block submitted is orphan")) } - blockHash := req.Block.BlockHeader.Hash() - a.newBlockCh <- &blockHash - return NewSuccessResponse(true) -} - -// SubmitWorkReq is req struct for submit-work API -type SubmitWorkReq struct { - BlockHeader *types.BlockHeader `json:"block_header"` -} - -// SubmitWorkJSONReq is req struct for submit-work-json API -type SubmitWorkJSONReq struct { - BlockHeader *BlockHeaderJSON `json:"block_header"` -} - -// GetWorkResp is resp struct for get-work API -type GetWorkResp struct { - BlockHeader *types.BlockHeader `json:"block_header"` - Seed *bc.Hash `json:"seed"` -} + if err = a.eventDispatcher.Post(event.NewProposedBlockEvent{Block: *req.Block}); err != nil { + return NewErrorResponse(err) + } -// GetWorkJSONResp is resp struct for get-work-json API -type GetWorkJSONResp struct { - BlockHeader *BlockHeaderJSON `json:"block_header"` - Seed *bc.Hash `json:"seed"` + return NewSuccessResponse(true) } func (a *API) setMining(in struct { @@ -105,8 +74,7 @@ func (a *API) setMining(in struct { } func (a *API) startMining() Response { - //a.cpuMiner.Start() - a.miner.Start() + a.blockProposer.Start() if !a.IsMining() { return NewErrorResponse(errors.New("Failed to start mining")) } @@ -114,8 +82,7 @@ func (a *API) startMining() Response { } func (a *API) stopMining() Response { - //a.cpuMiner.Stop() - a.miner.Stop() + a.blockProposer.Stop() if a.IsMining() { return NewErrorResponse(errors.New("Failed to stop mining")) }