From 389e9a43865ff4d5d7d183b3c42f45333d50824a Mon Sep 17 00:00:00 2001 From: Larry Ruane Date: Wed, 30 Oct 2019 10:43:51 -0600 Subject: [PATCH] run gofmt on all files (one-time) --- cmd/ingest/main.go | 42 ++++++++--------- cmd/server/main.go | 46 +++++++++---------- parser/block.go | 6 +-- parser/internal/bytestring/bytestring.go | 2 +- vendor/github.com/btcsuite/btcutil/certgen.go | 2 +- vendor/gopkg.in/ini.v1/key.go | 6 +-- 6 files changed, 51 insertions(+), 53 deletions(-) diff --git a/cmd/ingest/main.go b/cmd/ingest/main.go index 028e41b..70440e4 100644 --- a/cmd/ingest/main.go +++ b/cmd/ingest/main.go @@ -8,13 +8,13 @@ import ( "flag" "fmt" "os" - "time" "strconv" "strings" + "time" - "github.com/pkg/errors" "github.com/btcsuite/btcd/rpcclient" "github.com/golang/protobuf/proto" + "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/zcash-hackworks/lightwalletd/frontend" @@ -27,9 +27,9 @@ var logger = logrus.New() var db *sql.DB type Options struct { - dbPath string - logLevel uint64 - logPath string + dbPath string + logLevel uint64 + logPath string zcashConfPath string } @@ -106,19 +106,18 @@ func main() { if err != nil { log.WithFields(logrus.Fields{ "error": err, - }).Warn("unable to get current height from local db storage") - height = 0 + }).Warn("unable to get current height from local db storage") + height = 0 } - //ingest from Sapling testnet height if height < 280000 { height = 280000 log.WithFields(logrus.Fields{ "error": err, - }).Warn("invalid current height read from local db storage") + }).Warn("invalid current height read from local db storage") } - + timeout_count := 0 reorg_count := -1 hash := "" @@ -130,7 +129,7 @@ func main() { height -= 11 } block, err := getBlock(rpcClient, height) - + if err != nil { log.WithFields(logrus.Fields{ "height": height, @@ -139,7 +138,7 @@ func main() { timeout_count++ if timeout_count == 3 { log.WithFields(logrus.Fields{ - "timeouts": timeout_count, + "timeouts": timeout_count, }).Warn("unable to issue RPC call to zcashd node 3 times") break } @@ -155,17 +154,17 @@ func main() { reorg_count++ log.WithFields(logrus.Fields{ "height": height, - "hash": hash, - "phash": phash, - "reorg": reorg_count, + "hash": hash, + "phash": phash, + "reorg": reorg_count, }).Warn("REORG") } else { - hash = hex.EncodeToString(block.GetDisplayHash()) + hash = hex.EncodeToString(block.GetDisplayHash()) } if reorg_count == -1 { hash = hex.EncodeToString(block.GetDisplayHash()) - reorg_count =0 - } + reorg_count = 0 + } height++ } else { //TODO implement blocknotify to minimize polling on corner cases @@ -196,10 +195,10 @@ func getBlock(rpcClient *rpcclient.Client, height int) (*parser.Block, error) { var blockDataHex string err = json.Unmarshal(result, &blockDataHex) - if err != nil{ + if err != nil { return nil, errors.Wrap(err, "error reading JSON response") } - + blockData, err := hex.DecodeString(blockDataHex) if err != nil { return nil, errors.Wrap(err, "error decoding getblock output") @@ -216,12 +215,11 @@ func getBlock(rpcClient *rpcclient.Client, height int) (*parser.Block, error) { return block, nil } - func handleBlock(db *sql.DB, block *parser.Block) { prevBlockHash := hex.EncodeToString(block.GetPrevHash()) blockHash := hex.EncodeToString(block.GetEncodableHash()) marshaledBlock, _ := proto.Marshal(block.ToCompact()) - + err := storage.StoreBlock( db, block.GetHeight(), diff --git a/cmd/server/main.go b/cmd/server/main.go index 4d06094..bff919e 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -3,10 +3,10 @@ package main import ( "context" "flag" + "fmt" "net" "os" - "fmt" - "os/signal" + "os/signal" "syscall" "time" @@ -30,7 +30,7 @@ func init() { DisableLevelTruncation: true, }) - onexit := func () { + onexit := func() { fmt.Printf("Lightwalletd died with a Fatal error. Check logfile for details.\n") } @@ -82,22 +82,22 @@ func loggerFromContext(ctx context.Context) *logrus.Entry { } type Options struct { - bindAddr string `json:"bind_address,omitempty"` - dbPath string `json:"db_path"` - tlsCertPath string `json:"tls_cert_path,omitempty"` - tlsKeyPath string `json:"tls_cert_key,omitempty"` - logLevel uint64 `json:"log_level,omitempty"` - logPath string `json:"log_file,omitempty"` - zcashConfPath string `json:"zcash_conf,omitempty"` - veryInsecure bool `json:"very_insecure,omitempty"` + bindAddr string `json:"bind_address,omitempty"` + dbPath string `json:"db_path"` + tlsCertPath string `json:"tls_cert_path,omitempty"` + tlsKeyPath string `json:"tls_cert_key,omitempty"` + logLevel uint64 `json:"log_level,omitempty"` + logPath string `json:"log_file,omitempty"` + zcashConfPath string `json:"zcash_conf,omitempty"` + veryInsecure bool `json:"very_insecure,omitempty"` } func fileExists(filename string) bool { - info, err := os.Stat(filename) - if os.IsNotExist(err) { - return false - } - return !info.IsDir() + info, err := os.Stat(filename) + if os.IsNotExist(err) { + return false + } + return !info.IsDir() } func main() { @@ -114,7 +114,7 @@ func main() { // TODO support config from file and env vars flag.Parse() - filesThatShouldExist := []string { + filesThatShouldExist := []string{ opts.dbPath, opts.tlsCertPath, opts.tlsKeyPath, @@ -124,9 +124,9 @@ func main() { for _, filename := range filesThatShouldExist { if !fileExists(opts.logPath) { - os.OpenFile(opts.logPath, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666) + os.OpenFile(opts.logPath, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0666) } - if (opts.veryInsecure && (filename == opts.tlsCertPath || filename == opts.tlsKeyPath)) { + if opts.veryInsecure && (filename == opts.tlsCertPath || filename == opts.tlsKeyPath) { continue } if !fileExists(filename) { @@ -155,9 +155,9 @@ func main() { // gRPC initialization var server *grpc.Server - if opts.veryInsecure { - server = grpc.NewServer(LoggingInterceptor()) - } else { + if opts.veryInsecure { + server = grpc.NewServer(LoggingInterceptor()) + } else { transportCreds, err := credentials.NewServerTLSFromFile(opts.tlsCertPath, opts.tlsKeyPath) if err != nil { log.WithFields(logrus.Fields{ @@ -167,7 +167,7 @@ func main() { }).Fatal("couldn't load TLS credentials") } server = grpc.NewServer(grpc.Creds(transportCreds), LoggingInterceptor()) - } + } // Enable reflection for debugging if opts.logLevel >= uint64(logrus.WarnLevel) { diff --git a/parser/block.go b/parser/block.go index 44dd076..378b7f2 100644 --- a/parser/block.go +++ b/parser/block.go @@ -101,10 +101,10 @@ func (b *Block) GetPrevHash() []byte { func (b *Block) ToCompact() *walletrpc.CompactBlock { compactBlock := &walletrpc.CompactBlock{ //TODO ProtoVersion: 1, - Height: uint64(b.GetHeight()), + Height: uint64(b.GetHeight()), PrevHash: b.hdr.HashPrevBlock, - Hash: b.GetEncodableHash(), - Time: b.hdr.Time, + Hash: b.GetEncodableHash(), + Time: b.hdr.Time, } // Only Sapling transactions have a meaningful compact encoding diff --git a/parser/internal/bytestring/bytestring.go b/parser/internal/bytestring/bytestring.go index 702fe29..f2e8f2e 100644 --- a/parser/internal/bytestring/bytestring.go +++ b/parser/internal/bytestring/bytestring.go @@ -109,7 +109,7 @@ func (s *String) ReadCompactSize(size *int) bool { minSize = 0x10000 case lenByte == 255: // this case is not currently usable, beyond maxCompactSize; - // also, this is not possible if sizeof(int) is 4 bytes + // also, this is not possible if sizeof(int) is 4 bytes // lenLen = 8; minSize = 0x100000000 return false } diff --git a/vendor/github.com/btcsuite/btcutil/certgen.go b/vendor/github.com/btcsuite/btcutil/certgen.go index 26d1629..bbc45a4 100644 --- a/vendor/github.com/btcsuite/btcutil/certgen.go +++ b/vendor/github.com/btcsuite/btcutil/certgen.go @@ -110,7 +110,7 @@ func NewTLSCertPair(organization string, validUntil time.Time, extraHosts []stri KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature | x509.KeyUsageCertSign, - IsCA: true, // so can sign self. + IsCA: true, // so can sign self. BasicConstraintsValid: true, DNSNames: dnsNames, diff --git a/vendor/gopkg.in/ini.v1/key.go b/vendor/gopkg.in/ini.v1/key.go index 0fee0dc..7dd74fd 100644 --- a/vendor/gopkg.in/ini.v1/key.go +++ b/vendor/gopkg.in/ini.v1/key.go @@ -186,8 +186,8 @@ func (k *Key) Float64() (float64, error) { // Int returns int type value. func (k *Key) Int() (int, error) { - v, err := strconv.ParseInt(k.String(), 0, 64) - return int(v), err + v, err := strconv.ParseInt(k.String(), 0, 64) + return int(v), err } // Int64 returns int64 type value. @@ -669,7 +669,7 @@ func (k *Key) parseInts(strs []string, addInvalid, returnOnInvalid bool) ([]int, vals := make([]int, 0, len(strs)) for _, str := range strs { valInt64, err := strconv.ParseInt(str, 0, 64) - val := int(valInt64) + val := int(valInt64) if err != nil && returnOnInvalid { return nil, err }