github.com/immesys/bw2bc@v1.1.0/core/bad_block.go (about) 1 // Copyright 2015 The go-ethereum Authors 2 // This file is part of the go-ethereum library. 3 // 4 // The go-ethereum library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The go-ethereum library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>. 16 17 package core 18 19 import ( 20 "bytes" 21 "encoding/json" 22 "io/ioutil" 23 "net/http" 24 25 "github.com/ethereum/go-ethereum/common" 26 "github.com/ethereum/go-ethereum/core/types" 27 "github.com/ethereum/go-ethereum/logger" 28 "github.com/ethereum/go-ethereum/logger/glog" 29 "github.com/ethereum/go-ethereum/rlp" 30 ) 31 32 // DisabledBadBlockReporting can be set to prevent blocks being reported. 33 var DisableBadBlockReporting = true 34 35 // ReportBlock reports the block to the block reporting tool found at 36 // badblocks.ethdev.com 37 func ReportBlock(block *types.Block, err error) { 38 if DisableBadBlockReporting { 39 return 40 } 41 42 const url = "https://badblocks.ethdev.com" 43 44 blockRlp, _ := rlp.EncodeToBytes(block) 45 data := map[string]interface{}{ 46 "block": common.Bytes2Hex(blockRlp), 47 "errortype": err.Error(), 48 "hints": map[string]interface{}{ 49 "receipts": "NYI", 50 "vmtrace": "NYI", 51 }, 52 } 53 jsonStr, _ := json.Marshal(map[string]interface{}{"method": "eth_badBlock", "params": []interface{}{data}, "id": "1", "jsonrpc": "2.0"}) 54 55 req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonStr)) 56 req.Header.Set("Content-Type", "application/json") 57 58 client := &http.Client{} 59 resp, err := client.Do(req) 60 if err != nil { 61 glog.V(logger.Error).Infoln("POST err:", err) 62 return 63 } 64 defer resp.Body.Close() 65 66 if glog.V(logger.Debug) { 67 glog.Infoln("response Status:", resp.Status) 68 glog.Infoln("response Headers:", resp.Header) 69 body, _ := ioutil.ReadAll(resp.Body) 70 glog.Infoln("response Body:", string(body)) 71 } 72 }