Skip to content

Commit

Permalink
remove superfluous error return
Browse files Browse the repository at this point in the history
  • Loading branch information
nosequeldeebee committed Mar 4, 2018
1 parent c473b6c commit 2c6282d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 14 deletions.
10 changes: 3 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,7 @@ func handleWriteBlock(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()

mutex.Lock()
newBlock, err := generateBlock(Blockchain[len(Blockchain)-1], m.BPM)
if err != nil {
respondWithJSON(w, r, http.StatusInternalServerError, m)
return
}
newBlock := generateBlock(Blockchain[len(Blockchain)-1], m.BPM)
mutex.Unlock()

if isBlockValid(newBlock, Blockchain[len(Blockchain)-1]) {
Expand Down Expand Up @@ -161,7 +157,7 @@ func calculateHash(block Block) string {
}

// create a new block using previous block's hash
func generateBlock(oldBlock Block, BPM int) (Block, error) {
func generateBlock(oldBlock Block, BPM int) Block {

var newBlock Block

Expand All @@ -173,5 +169,5 @@ func generateBlock(oldBlock Block, BPM int) (Block, error) {
newBlock.PrevHash = oldBlock.Hash
newBlock.Hash = calculateHash(newBlock)

return newBlock, nil
return newBlock
}
10 changes: 3 additions & 7 deletions proof-work/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,7 @@ func handleWriteBlock(w http.ResponseWriter, r *http.Request) {

//ensure atomicity when creating new block
mutex.Lock()
newBlock, err := generateBlock(Blockchain[len(Blockchain)-1], m.BPM)
if err != nil {
respondWithJSON(w, r, http.StatusInternalServerError, m)
return
}
newBlock := generateBlock(Blockchain[len(Blockchain)-1], m.BPM)
mutex.Unlock()

if isBlockValid(newBlock, Blockchain[len(Blockchain)-1]) {
Expand Down Expand Up @@ -169,7 +165,7 @@ func calculateHash(block Block) string {
}

// create a new block using previous block's hash
func generateBlock(oldBlock Block, BPM int) (Block, error) {
func generateBlock(oldBlock Block, BPM int) Block {
var newBlock Block

t := time.Now()
Expand All @@ -194,7 +190,7 @@ func generateBlock(oldBlock Block, BPM int) (Block, error) {
}

}
return newBlock, nil
return newBlock
}

func isHashValid(hash string, difficulty int) bool {
Expand Down

0 comments on commit 2c6282d

Please sign in to comment.