Fixed issues reported by goreportcard.com
This commit is contained in:
parent
c6316ca10f
commit
ab0eb65de0
@ -174,6 +174,9 @@ func (w *Worker) GetTransaction(txid string, spendingTxs bool) (*Tx, error) {
|
|||||||
valOutSat.Add(&valOutSat, &bchainVout.ValueSat)
|
valOutSat.Add(&valOutSat, &bchainVout.ValueSat)
|
||||||
vout.ScriptPubKey.Hex = bchainVout.ScriptPubKey.Hex
|
vout.ScriptPubKey.Hex = bchainVout.ScriptPubKey.Hex
|
||||||
vout.ScriptPubKey.AddrDesc, vout.ScriptPubKey.Addresses, vout.ScriptPubKey.Searchable, err = w.getAddressesFromVout(bchainVout)
|
vout.ScriptPubKey.AddrDesc, vout.ScriptPubKey.Addresses, vout.ScriptPubKey.Searchable, err = w.getAddressesFromVout(bchainVout)
|
||||||
|
if err != nil {
|
||||||
|
glog.Errorf("getAddressesFromVout error %v, %v, output %v", err, vout.ScriptPubKey.AddrDesc, vout.N)
|
||||||
|
}
|
||||||
if ta != nil {
|
if ta != nil {
|
||||||
vout.Spent = ta.Outputs[i].Spent
|
vout.Spent = ta.Outputs[i].Spent
|
||||||
if spendingTxs && vout.Spent {
|
if spendingTxs && vout.Spent {
|
||||||
@ -363,6 +366,9 @@ func (w *Worker) GetAddress(address string, page int, txsOnPage int, onlyTxids b
|
|||||||
}
|
}
|
||||||
// convert the address to the format defined by the parser
|
// convert the address to the format defined by the parser
|
||||||
addresses, _, err := w.chainParser.GetAddressesFromAddrDesc(addrDesc)
|
addresses, _, err := w.chainParser.GetAddressesFromAddrDesc(addrDesc)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Annotatef(err, "GetAddressesFromAddrDesc %v", addrDesc)
|
||||||
|
}
|
||||||
if len(addresses) == 1 {
|
if len(addresses) == 1 {
|
||||||
address = addresses[0]
|
address = addresses[0]
|
||||||
}
|
}
|
||||||
@ -505,10 +511,15 @@ func (w *Worker) GetBlock(bid string, page int, txsOnPage int) (*Block, error) {
|
|||||||
if page < 0 {
|
if page < 0 {
|
||||||
page = 0
|
page = 0
|
||||||
}
|
}
|
||||||
|
// try to decide if passed string (bid) is block height or block hash
|
||||||
|
// if it's a number, must be less than int32
|
||||||
var hash string
|
var hash string
|
||||||
height, err := strconv.Atoi(bid)
|
height, err := strconv.Atoi(bid)
|
||||||
if err == nil && height < int(^uint32(0)) {
|
if err == nil && height < int(^uint32(0)) {
|
||||||
hash, err = w.db.GetBlockHash(uint32(height))
|
hash, err = w.db.GetBlockHash(uint32(height))
|
||||||
|
if err != nil {
|
||||||
|
hash = bid
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
hash = bid
|
hash = bid
|
||||||
}
|
}
|
||||||
|
|||||||
@ -91,7 +91,6 @@ func GetChainParams(chain string) *chaincfg.Params {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var params *chaincfg.Params
|
|
||||||
switch chain {
|
switch chain {
|
||||||
case "test":
|
case "test":
|
||||||
return &TestNetParams
|
return &TestNetParams
|
||||||
@ -100,8 +99,6 @@ func GetChainParams(chain string) *chaincfg.Params {
|
|||||||
default:
|
default:
|
||||||
return &MainNetParams
|
return &MainNetParams
|
||||||
}
|
}
|
||||||
|
|
||||||
return params
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAddrDescFromAddress returns internal address representation of given address
|
// GetAddrDescFromAddress returns internal address representation of given address
|
||||||
|
|||||||
@ -416,6 +416,9 @@ func (b *EthereumRPC) GetBlock(hash string, height uint32) (*bchain.Block, error
|
|||||||
return nil, errors.Annotatef(fmt.Errorf("server returned empty transaction list but block header indicates transactions"), "hash %v, height %v", hash, height)
|
return nil, errors.Annotatef(fmt.Errorf("server returned empty transaction list but block header indicates transactions"), "hash %v, height %v", hash, height)
|
||||||
}
|
}
|
||||||
bbh, err := b.ethHeaderToBlockHeader(head)
|
bbh, err := b.ethHeaderToBlockHeader(head)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Annotatef(err, "hash %v, height %v", hash, height)
|
||||||
|
}
|
||||||
// TODO - this is probably not the correct size
|
// TODO - this is probably not the correct size
|
||||||
bbh.Size = len(raw)
|
bbh.Size = len(raw)
|
||||||
btxs := make([]bchain.Tx, len(body.Transactions))
|
btxs := make([]bchain.Tx, len(body.Transactions))
|
||||||
|
|||||||
@ -66,15 +66,12 @@ func GetChainParams(chain string) *chaincfg.Params {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var params *chaincfg.Params
|
|
||||||
switch chain {
|
switch chain {
|
||||||
case "test":
|
case "test":
|
||||||
return &TestNetParams
|
return &TestNetParams
|
||||||
default:
|
default:
|
||||||
return &MainNetParams
|
return &MainNetParams
|
||||||
}
|
}
|
||||||
|
|
||||||
return params
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PackTx packs transaction to byte array using protobuf
|
// PackTx packs transaction to byte array using protobuf
|
||||||
|
|||||||
@ -71,7 +71,6 @@ func GetChainParams(chain string) *chaincfg.Params {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var params *chaincfg.Params
|
|
||||||
switch chain {
|
switch chain {
|
||||||
case "test":
|
case "test":
|
||||||
return &TestNetParams
|
return &TestNetParams
|
||||||
@ -80,8 +79,6 @@ func GetChainParams(chain string) *chaincfg.Params {
|
|||||||
default:
|
default:
|
||||||
return &MainNetParams
|
return &MainNetParams
|
||||||
}
|
}
|
||||||
|
|
||||||
return params
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// PackTx packs transaction to byte array using protobuf
|
// PackTx packs transaction to byte array using protobuf
|
||||||
|
|||||||
@ -82,9 +82,17 @@ func (s *InternalServer) Shutdown(ctx context.Context) error {
|
|||||||
|
|
||||||
func (s *InternalServer) index(w http.ResponseWriter, r *http.Request) {
|
func (s *InternalServer) index(w http.ResponseWriter, r *http.Request) {
|
||||||
si, err := s.api.GetSystemInfo(true)
|
si, err := s.api.GetSystemInfo(true)
|
||||||
|
if err != nil {
|
||||||
|
glog.Error(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
buf, err := json.MarshalIndent(si, "", " ")
|
buf, err := json.MarshalIndent(si, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Error(err)
|
glog.Error(err)
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
w.Write(buf)
|
w.Write(buf)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user