Merge pull request #122 from zcash-hackworks/run-gofmt
run gofmt on all files (one-time)
This commit is contained in:
commit
5134a4b4eb
|
@ -8,13 +8,13 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/btcsuite/btcd/rpcclient"
|
"github.com/btcsuite/btcd/rpcclient"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/zcash-hackworks/lightwalletd/frontend"
|
"github.com/zcash-hackworks/lightwalletd/frontend"
|
||||||
|
@ -27,9 +27,9 @@ var logger = logrus.New()
|
||||||
var db *sql.DB
|
var db *sql.DB
|
||||||
|
|
||||||
type Options struct {
|
type Options struct {
|
||||||
dbPath string
|
dbPath string
|
||||||
logLevel uint64
|
logLevel uint64
|
||||||
logPath string
|
logPath string
|
||||||
zcashConfPath string
|
zcashConfPath string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,19 +106,18 @@ func main() {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(logrus.Fields{
|
log.WithFields(logrus.Fields{
|
||||||
"error": err,
|
"error": err,
|
||||||
}).Warn("unable to get current height from local db storage")
|
}).Warn("unable to get current height from local db storage")
|
||||||
height = 0
|
height = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//ingest from Sapling testnet height
|
//ingest from Sapling testnet height
|
||||||
if height < 280000 {
|
if height < 280000 {
|
||||||
height = 280000
|
height = 280000
|
||||||
log.WithFields(logrus.Fields{
|
log.WithFields(logrus.Fields{
|
||||||
"error": err,
|
"error": err,
|
||||||
}).Warn("invalid current height read from local db storage")
|
}).Warn("invalid current height read from local db storage")
|
||||||
}
|
}
|
||||||
|
|
||||||
timeout_count := 0
|
timeout_count := 0
|
||||||
reorg_count := -1
|
reorg_count := -1
|
||||||
hash := ""
|
hash := ""
|
||||||
|
@ -130,7 +129,7 @@ func main() {
|
||||||
height -= 11
|
height -= 11
|
||||||
}
|
}
|
||||||
block, err := getBlock(rpcClient, height)
|
block, err := getBlock(rpcClient, height)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(logrus.Fields{
|
log.WithFields(logrus.Fields{
|
||||||
"height": height,
|
"height": height,
|
||||||
|
@ -139,7 +138,7 @@ func main() {
|
||||||
timeout_count++
|
timeout_count++
|
||||||
if timeout_count == 3 {
|
if timeout_count == 3 {
|
||||||
log.WithFields(logrus.Fields{
|
log.WithFields(logrus.Fields{
|
||||||
"timeouts": timeout_count,
|
"timeouts": timeout_count,
|
||||||
}).Warn("unable to issue RPC call to zcashd node 3 times")
|
}).Warn("unable to issue RPC call to zcashd node 3 times")
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -155,17 +154,17 @@ func main() {
|
||||||
reorg_count++
|
reorg_count++
|
||||||
log.WithFields(logrus.Fields{
|
log.WithFields(logrus.Fields{
|
||||||
"height": height,
|
"height": height,
|
||||||
"hash": hash,
|
"hash": hash,
|
||||||
"phash": phash,
|
"phash": phash,
|
||||||
"reorg": reorg_count,
|
"reorg": reorg_count,
|
||||||
}).Warn("REORG")
|
}).Warn("REORG")
|
||||||
} else {
|
} else {
|
||||||
hash = hex.EncodeToString(block.GetDisplayHash())
|
hash = hex.EncodeToString(block.GetDisplayHash())
|
||||||
}
|
}
|
||||||
if reorg_count == -1 {
|
if reorg_count == -1 {
|
||||||
hash = hex.EncodeToString(block.GetDisplayHash())
|
hash = hex.EncodeToString(block.GetDisplayHash())
|
||||||
reorg_count =0
|
reorg_count = 0
|
||||||
}
|
}
|
||||||
height++
|
height++
|
||||||
} else {
|
} else {
|
||||||
//TODO implement blocknotify to minimize polling on corner cases
|
//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
|
var blockDataHex string
|
||||||
err = json.Unmarshal(result, &blockDataHex)
|
err = json.Unmarshal(result, &blockDataHex)
|
||||||
if err != nil{
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "error reading JSON response")
|
return nil, errors.Wrap(err, "error reading JSON response")
|
||||||
}
|
}
|
||||||
|
|
||||||
blockData, err := hex.DecodeString(blockDataHex)
|
blockData, err := hex.DecodeString(blockDataHex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "error decoding getblock output")
|
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
|
return block, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func handleBlock(db *sql.DB, block *parser.Block) {
|
func handleBlock(db *sql.DB, block *parser.Block) {
|
||||||
prevBlockHash := hex.EncodeToString(block.GetPrevHash())
|
prevBlockHash := hex.EncodeToString(block.GetPrevHash())
|
||||||
blockHash := hex.EncodeToString(block.GetEncodableHash())
|
blockHash := hex.EncodeToString(block.GetEncodableHash())
|
||||||
marshaledBlock, _ := proto.Marshal(block.ToCompact())
|
marshaledBlock, _ := proto.Marshal(block.ToCompact())
|
||||||
|
|
||||||
err := storage.StoreBlock(
|
err := storage.StoreBlock(
|
||||||
db,
|
db,
|
||||||
block.GetHeight(),
|
block.GetHeight(),
|
||||||
|
|
|
@ -3,10 +3,10 @@ package main
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"flag"
|
"flag"
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"fmt"
|
"os/signal"
|
||||||
"os/signal"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ func init() {
|
||||||
DisableLevelTruncation: true,
|
DisableLevelTruncation: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
onexit := func () {
|
onexit := func() {
|
||||||
fmt.Printf("Lightwalletd died with a Fatal error. Check logfile for details.\n")
|
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 {
|
type Options struct {
|
||||||
bindAddr string `json:"bind_address,omitempty"`
|
bindAddr string `json:"bind_address,omitempty"`
|
||||||
dbPath string `json:"db_path"`
|
dbPath string `json:"db_path"`
|
||||||
tlsCertPath string `json:"tls_cert_path,omitempty"`
|
tlsCertPath string `json:"tls_cert_path,omitempty"`
|
||||||
tlsKeyPath string `json:"tls_cert_key,omitempty"`
|
tlsKeyPath string `json:"tls_cert_key,omitempty"`
|
||||||
logLevel uint64 `json:"log_level,omitempty"`
|
logLevel uint64 `json:"log_level,omitempty"`
|
||||||
logPath string `json:"log_file,omitempty"`
|
logPath string `json:"log_file,omitempty"`
|
||||||
zcashConfPath string `json:"zcash_conf,omitempty"`
|
zcashConfPath string `json:"zcash_conf,omitempty"`
|
||||||
veryInsecure bool `json:"very_insecure,omitempty"`
|
veryInsecure bool `json:"very_insecure,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func fileExists(filename string) bool {
|
func fileExists(filename string) bool {
|
||||||
info, err := os.Stat(filename)
|
info, err := os.Stat(filename)
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return !info.IsDir()
|
return !info.IsDir()
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
@ -114,7 +114,7 @@ func main() {
|
||||||
// TODO support config from file and env vars
|
// TODO support config from file and env vars
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
filesThatShouldExist := []string {
|
filesThatShouldExist := []string{
|
||||||
opts.dbPath,
|
opts.dbPath,
|
||||||
opts.tlsCertPath,
|
opts.tlsCertPath,
|
||||||
opts.tlsKeyPath,
|
opts.tlsKeyPath,
|
||||||
|
@ -124,9 +124,9 @@ func main() {
|
||||||
|
|
||||||
for _, filename := range filesThatShouldExist {
|
for _, filename := range filesThatShouldExist {
|
||||||
if !fileExists(opts.logPath) {
|
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
|
continue
|
||||||
}
|
}
|
||||||
if !fileExists(filename) {
|
if !fileExists(filename) {
|
||||||
|
@ -155,9 +155,9 @@ func main() {
|
||||||
// gRPC initialization
|
// gRPC initialization
|
||||||
var server *grpc.Server
|
var server *grpc.Server
|
||||||
|
|
||||||
if opts.veryInsecure {
|
if opts.veryInsecure {
|
||||||
server = grpc.NewServer(LoggingInterceptor())
|
server = grpc.NewServer(LoggingInterceptor())
|
||||||
} else {
|
} else {
|
||||||
transportCreds, err := credentials.NewServerTLSFromFile(opts.tlsCertPath, opts.tlsKeyPath)
|
transportCreds, err := credentials.NewServerTLSFromFile(opts.tlsCertPath, opts.tlsKeyPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(logrus.Fields{
|
log.WithFields(logrus.Fields{
|
||||||
|
@ -167,7 +167,7 @@ func main() {
|
||||||
}).Fatal("couldn't load TLS credentials")
|
}).Fatal("couldn't load TLS credentials")
|
||||||
}
|
}
|
||||||
server = grpc.NewServer(grpc.Creds(transportCreds), LoggingInterceptor())
|
server = grpc.NewServer(grpc.Creds(transportCreds), LoggingInterceptor())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enable reflection for debugging
|
// Enable reflection for debugging
|
||||||
if opts.logLevel >= uint64(logrus.WarnLevel) {
|
if opts.logLevel >= uint64(logrus.WarnLevel) {
|
||||||
|
|
|
@ -101,10 +101,10 @@ func (b *Block) GetPrevHash() []byte {
|
||||||
func (b *Block) ToCompact() *walletrpc.CompactBlock {
|
func (b *Block) ToCompact() *walletrpc.CompactBlock {
|
||||||
compactBlock := &walletrpc.CompactBlock{
|
compactBlock := &walletrpc.CompactBlock{
|
||||||
//TODO ProtoVersion: 1,
|
//TODO ProtoVersion: 1,
|
||||||
Height: uint64(b.GetHeight()),
|
Height: uint64(b.GetHeight()),
|
||||||
PrevHash: b.hdr.HashPrevBlock,
|
PrevHash: b.hdr.HashPrevBlock,
|
||||||
Hash: b.GetEncodableHash(),
|
Hash: b.GetEncodableHash(),
|
||||||
Time: b.hdr.Time,
|
Time: b.hdr.Time,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Only Sapling transactions have a meaningful compact encoding
|
// Only Sapling transactions have a meaningful compact encoding
|
||||||
|
|
|
@ -109,7 +109,7 @@ func (s *String) ReadCompactSize(size *int) bool {
|
||||||
minSize = 0x10000
|
minSize = 0x10000
|
||||||
case lenByte == 255:
|
case lenByte == 255:
|
||||||
// this case is not currently usable, beyond maxCompactSize;
|
// 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
|
// lenLen = 8; minSize = 0x100000000
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,7 +110,7 @@ func NewTLSCertPair(organization string, validUntil time.Time, extraHosts []stri
|
||||||
|
|
||||||
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature |
|
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature |
|
||||||
x509.KeyUsageCertSign,
|
x509.KeyUsageCertSign,
|
||||||
IsCA: true, // so can sign self.
|
IsCA: true, // so can sign self.
|
||||||
BasicConstraintsValid: true,
|
BasicConstraintsValid: true,
|
||||||
|
|
||||||
DNSNames: dnsNames,
|
DNSNames: dnsNames,
|
||||||
|
|
|
@ -186,8 +186,8 @@ func (k *Key) Float64() (float64, error) {
|
||||||
|
|
||||||
// Int returns int type value.
|
// Int returns int type value.
|
||||||
func (k *Key) Int() (int, error) {
|
func (k *Key) Int() (int, error) {
|
||||||
v, err := strconv.ParseInt(k.String(), 0, 64)
|
v, err := strconv.ParseInt(k.String(), 0, 64)
|
||||||
return int(v), err
|
return int(v), err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Int64 returns int64 type value.
|
// 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))
|
vals := make([]int, 0, len(strs))
|
||||||
for _, str := range strs {
|
for _, str := range strs {
|
||||||
valInt64, err := strconv.ParseInt(str, 0, 64)
|
valInt64, err := strconv.ParseInt(str, 0, 64)
|
||||||
val := int(valInt64)
|
val := int(valInt64)
|
||||||
if err != nil && returnOnInvalid {
|
if err != nil && returnOnInvalid {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue