Fix linting issues

This commit is contained in:
Martin Boehm 2021-11-28 21:26:55 +01:00
parent ae4cb2fb64
commit e143215288
64 changed files with 87 additions and 94 deletions

View File

@ -1,11 +1,11 @@
# Blockbook Contributor Guide # Blockbook Contributor Guide
Blockbook is back-end service for Trezor wallet. Although it is open source, the design and development of the core packages Blockbook is a back-end service for the Trezor wallet. Although it is open source, the design and development of the core packages
is done by Trezor developers in order to keep Blockbook compatible with Trezor. is done by the Trezor developers to keep Blockbook compatible with Trezor.
Bug fixes and support for new coins are welcome. **Please take note that non-fixing pull requests that change base Bug fixes and support for new coins are welcome. **Please take note that pull requests that are not fixes and that change base
packages or another coin code will not be accepted.** If you have a need to change some of the existing code, please file packages or another coin code will not be accepted.** If you need a change in the existing core code, please file
an issue and discuss your request with Blockbook maintainers. an issue and discuss your request with the Blockbook maintainers.
## Development environment ## Development environment
@ -16,8 +16,8 @@ Instructions to set up your development environment and build Blockbook are desc
### Reporting bugs ### Reporting bugs
A great way to contribute to the project is to send a detailed report when you encounter an issue. We always appreciate A great way to contribute to the project is to send a detailed report when you encounter a problem. We always appreciate
a well-written, thorough bug report, and will thank you for it! a well-written and thorough bug report, and we'll be grateful for it!
Check that [our issue database](https://github.com/trezor/blockbook/issues) doesn't already include that problem or Check that [our issue database](https://github.com/trezor/blockbook/issues) doesn't already include that problem or
suggestion before submitting an issue. If you find a match, you can use the "subscribe" button to get notified on suggestion before submitting an issue. If you find a match, you can use the "subscribe" button to get notified on

View File

@ -5,10 +5,10 @@
**Blockbook** is back-end service for Trezor wallet. Main features of **Blockbook** are: **Blockbook** is back-end service for Trezor wallet. Main features of **Blockbook** are:
- index of addresses and address balances of the connected block chain - index of addresses and address balances of the connected block chain
- fast searches in the indexes - fast index search
- simple blockchain explorer - simple blockchain explorer
- websocket, API and legacy Bitcore Insight compatible socket.io interfaces - websocket, API and legacy Bitcore Insight compatible socket.io interfaces
- support of multiple coins (Bitcoin and Ethereum type), with easy extensibility for other coins - support of multiple coins (Bitcoin and Ethereum type) with easy extensibility to other coins
- scripts for easy creation of debian packages for backend and blockbook - scripts for easy creation of debian packages for backend and blockbook
## Build and installation instructions ## Build and installation instructions
@ -51,7 +51,8 @@ Please add your experience to this [issue](https://github.com/trezor/blockbook/i
#### Error `internalState: database is in inconsistent state and cannot be used` #### Error `internalState: database is in inconsistent state and cannot be used`
Blockbook was killed during the initial import, most commonly by OOM killer. By default, Blockbook performs the initial import in bulk import mode, which for performance reasons does not store all the data immediately to the database. If Blockbook is killed during this phase, the database is left in an inconsistent state. Blockbook was killed during the initial import, most commonly by OOM killer.
By default, Blockbook performs the initial import in bulk import mode, which for performance reasons does not store all data immediately to the database. If Blockbook is killed during this phase, the database is left in an inconsistent state.
See above how to reduce the memory footprint, delete the database files and run the import again. See above how to reduce the memory footprint, delete the database files and run the import again.
@ -67,9 +68,9 @@ Your coin's block/transaction data may not be compatible with `BitcoinParser` `P
#### Cannot build Blockbook using `go build` command #### Cannot build Blockbook using `go build` command
When building Blockbook, I get error `not enough arguments in call to _Cfunc_rocksdb_approximate_sizes`. When building Blockbook I get error `not enough arguments in call to _Cfunc_rocksdb_approximate_sizes`.
RocksDB version 6.16.0 changed the API in backward incompatible way. It is necessary to build Blockbook with the tag `rocksdb_6_16`, which fixes the compatibility issue. The correct way to build Blockbook is: RocksDB version 6.16.0 changed the API in a backwards incompatible way. It is necessary to build Blockbook with the `rocksdb_6_16` tag to fix the compatibility problem. The correct way to build Blockbook is:
``` ```
go build -tags rocksdb_6_16 go build -tags rocksdb_6_16

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package api package api

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package bchain package bchain

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package bch package bch

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package bellcoin package bellcoin

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package bitcore package bitcore

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package bitzeny package bitzeny

View File

@ -1,5 +1,4 @@
//go:build unittest //go:build unittest
// +build unittest
package btc package btc

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package btg package btg

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package dash package dash

View File

@ -1,5 +1,4 @@
//go:build unittest //go:build unittest
// +build unittest
package dcr package dcr

View File

@ -54,7 +54,7 @@ func NewDecredRPC(config json.RawMessage, pushHandler func(bchain.NotificationTy
Dial: (&net.Dialer{KeepAlive: 600 * time.Second}).Dial, Dial: (&net.Dialer{KeepAlive: 600 * time.Second}).Dial,
MaxIdleConns: 100, MaxIdleConns: 100,
MaxIdleConnsPerHost: 100, // necessary to not to deplete ports MaxIdleConnsPerHost: 100, // necessary to not to deplete ports
TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
} }
d := &DecredRPC{ d := &DecredRPC{

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package deeponion package deeponion

View File

@ -6,14 +6,14 @@ import (
"github.com/trezor/blockbook/bchain/coins/btc" "github.com/trezor/blockbook/bchain/coins/btc"
) )
// network constants
const ( const (
// MainnetMagic is mainnet network constant
MainnetMagic wire.BitcoinNet = 0xdab6c3fa MainnetMagic wire.BitcoinNet = 0xdab6c3fa
TestnetMagic wire.BitcoinNet = 0xddbdc8fd TestnetMagic wire.BitcoinNet = 0xddbdc8fd
) )
// parser parameters
var ( var (
// MainNetParams are parser parameters for mainnet
MainNetParams chaincfg.Params MainNetParams chaincfg.Params
TestNetParams chaincfg.Params TestNetParams chaincfg.Params
) )

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package digibyte package digibyte

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package divi package divi

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package dogecoin package dogecoin

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package eth package eth

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package eth package eth

View File

@ -26,11 +26,11 @@ const (
TestnetMagic wire.BitcoinNet = 0xcffcbeea TestnetMagic wire.BitcoinNet = 0xcffcbeea
RegtestMagic wire.BitcoinNet = 0xfabfb5da RegtestMagic wire.BitcoinNet = 0xfabfb5da
GenesisBlockTime = 1414776286 GenesisBlockTime = 1414776286
SwitchToMTPBlockHeader = 1544443200 SwitchToMTPBlockHeader = 1544443200
SwitchToProgPowBlockHeaderTestnet = 1630069200 SwitchToProgPowBlockHeaderTestnet = 1630069200
SwitchToProgPowBlockHeaderMainnet = 1635228000 SwitchToProgPowBlockHeaderMainnet = 1635228000
MTPL = 64 MTPL = 64
SpendTxID = "0000000000000000000000000000000000000000000000000000000000000000" SpendTxID = "0000000000000000000000000000000000000000000000000000000000000000"
@ -159,7 +159,7 @@ func (p *FiroParser) ParseBlock(b []byte) (*bchain.Block, error) {
} }
// then ProgPow or MTP header // then ProgPow or MTP header
if(isProgPow(header, p.Params.Net == TestnetMagic)){ if isProgPow(header, p.Params.Net == TestnetMagic) {
progPowHeader := ProgPowBlockHeader{} progPowHeader := ProgPowBlockHeader{}
// header // header

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package firo package firo

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package flo package flo

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package fujicoin package fujicoin

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package gamecredits package gamecredits

View File

@ -50,7 +50,7 @@ type GroestlcoinParser struct {
func NewGroestlcoinParser(params *chaincfg.Params, c *btc.Configuration) *GroestlcoinParser { func NewGroestlcoinParser(params *chaincfg.Params, c *btc.Configuration) *GroestlcoinParser {
return &GroestlcoinParser{ return &GroestlcoinParser{
BitcoinParser: btc.NewBitcoinParser(params, c), BitcoinParser: btc.NewBitcoinParser(params, c),
baseparser: &bchain.BaseParser{}, baseparser: &bchain.BaseParser{},
} }
} }

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package grs package grs

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package koto package koto

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package liquid package liquid

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package litecoin package litecoin

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package monacoin package monacoin

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package monetaryunit package monetaryunit

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package myriad package myriad

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package namecoin package namecoin

View File

@ -1,5 +1,4 @@
//go:build unittest //go:build unittest
// +build unittest
package nuls package nuls

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package omotenashicoin package omotenashicoin

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package pivx package pivx

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package polis package polis

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package qtum package qtum

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package ravencoin package ravencoin

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package ritocoin package ritocoin

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package snowgem package snowgem

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package trezarcoin package trezarcoin

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package unobtanium package unobtanium

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package vertcoin package vertcoin

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package viacoin package viacoin

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package vipstarcoin package vipstarcoin

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package zec package zec

View File

@ -15,6 +15,7 @@ type ZCashRPC struct {
*btc.BitcoinRPC *btc.BitcoinRPC
} }
// ResGetBlockChainInfo is a response to GetChainInfo request
type ResGetBlockChainInfo struct { type ResGetBlockChainInfo struct {
Error *bchain.RPCError `json:"error"` Error *bchain.RPCError `json:"error"`
Result struct { Result struct {
@ -72,6 +73,7 @@ func (z *ZCashRPC) Initialize() error {
return nil return nil
} }
// GetChainInfo return info about the blockchain
func (z *ZCashRPC) GetChainInfo() (*bchain.ChainInfo, error) { func (z *ZCashRPC) GetChainInfo() (*bchain.ChainInfo, error) {
chainInfo := ResGetBlockChainInfo{} chainInfo := ResGetBlockChainInfo{}
err := z.Call(&btc.CmdGetBlockChainInfo{Method: "getblockchaininfo"}, &chainInfo) err := z.Call(&btc.CmdGetBlockChainInfo{Method: "getblockchaininfo"}, &chainInfo)

View File

@ -12,6 +12,7 @@ import (
"time" "time"
) )
// Config contains the structure of the config
type Config struct { type Config struct {
Coin struct { Coin struct {
Name string `json:"name"` Name string `json:"name"`
@ -108,6 +109,7 @@ func generateRPCAuth(user, pass string) (string, error) {
return out.String(), nil return out.String(), nil
} }
// ParseTemplate parses the template
func (c *Config) ParseTemplate() *template.Template { func (c *Config) ParseTemplate() *template.Template {
templates := map[string]string{ templates := map[string]string{
"IPC.RPCURLTemplate": c.IPC.RPCURLTemplate, "IPC.RPCURLTemplate": c.IPC.RPCURLTemplate,
@ -134,6 +136,7 @@ func (c *Config) ParseTemplate() *template.Template {
return t return t
} }
// LoadConfig loads the config files
func LoadConfig(configsDir, coin string) (*Config, error) { func LoadConfig(configsDir, coin string) (*Config, error) {
config := new(Config) config := new(Config)
@ -191,6 +194,7 @@ func isEmpty(config *Config, target string) bool {
} }
} }
// GeneratePackageDefinitions generate the package definitions from the config
func GeneratePackageDefinitions(config *Config, templateDir, outputDir string) error { func GeneratePackageDefinitions(config *Config, templateDir, outputDir string) error {
templ := config.ParseTemplate() templ := config.ParseTemplate()
@ -276,12 +280,7 @@ func writeTemplate(path string, info os.FileInfo, templ *template.Template, conf
} }
defer f.Close() defer f.Close()
err = templ.ExecuteTemplate(f, "main", config) return templ.ExecuteTemplate(f, "main", config)
if err != nil {
return err
}
return nil
} }
func writeBackendServerConfigFile(config *Config, outputDir string) error { func writeBackendServerConfigFile(config *Config, outputDir string) error {
@ -318,18 +317,13 @@ func writeBackendClientConfigFile(config *Config, outputDir string) error {
if config.Backend.ClientConfigFile == "" { if config.Backend.ClientConfigFile == "" {
return nil return nil
} else {
in, err := os.Open(filepath.Join(outputDir, "backend/config", config.Backend.ClientConfigFile))
if err != nil {
return err
}
defer in.Close()
_, err = io.Copy(out, in)
if err != nil {
return err
}
} }
in, err := os.Open(filepath.Join(outputDir, "backend/config", config.Backend.ClientConfigFile))
if err != nil {
return err
}
defer in.Close()
return nil _, err = io.Copy(out, in)
return err
} }

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package common package common

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package db package db

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package db package db

View File

@ -1,4 +1,4 @@
// +build integration //go:build integration
package db package db

View File

@ -1,4 +1,4 @@
// +build unittest //go:build unittest
package fiat package fiat

View File

@ -1,5 +1,4 @@
//go:build unittest //go:build unittest
// +build unittest
package server package server

View File

@ -1,4 +1,4 @@
// +build integration //go:build integration
package server package server

View File

@ -1,4 +1,4 @@
// +build integration //go:build integration
package tests package tests

View File

@ -1,4 +1,4 @@
// +build integration //go:build integration
package tests package tests

View File

@ -1,4 +1,4 @@
// +build integration //go:build integration
package rpc package rpc

View File

@ -1,4 +1,4 @@
// +build integration //go:build integration
package sync package sync

View File

@ -1,4 +1,4 @@
// +build integration //go:build integration
package sync package sync

View File

@ -1,4 +1,4 @@
// +build integration //go:build integration
package sync package sync

View File

@ -1,4 +1,4 @@
// +build integration //go:build integration
package sync package sync