Created
January 29, 2018 06:07
-
-
Save nosequeldeebee/c5bc5adb5c879fa56226c6b1e697b4fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func handleWriteBlock(w http.ResponseWriter, r *http.Request) { | |
var m Message | |
decoder := json.NewDecoder(r.Body) | |
if err := decoder.Decode(&m); err != nil { | |
respondWithJSON(w, r, http.StatusBadRequest, r.Body) | |
return | |
} | |
defer r.Body.Close() | |
newBlock, err := generateBlock(Blockchain[len(Blockchain)-1], m.BPM) | |
if err != nil { | |
respondWithJSON(w, r, http.StatusInternalServerError, m) | |
return | |
} | |
if isBlockValid(newBlock, Blockchain[len(Blockchain)-1]) { | |
newBlockchain := append(Blockchain, newBlock) | |
replaceChain(newBlockchain) | |
spew.Dump(Blockchain) | |
} | |
respondWithJSON(w, r, http.StatusCreated, newBlock) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment