run gofmt on all files (one-time)
This commit is contained in:
parent
98038688a6
commit
389e9a4386
|
@ -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(),
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue