Browse Source

port to hush

master
DenioD 5 years ago
parent
commit
f6fa52fde1
  1. 26
      cmd/server/main.go
  2. 2
      common/cache.go
  3. 10
      common/common.go
  4. 6
      frontend/rpc_client.go
  5. 16
      frontend/service.go
  6. 2
      go.mod
  7. 4
      parser/block.go
  8. 2
      parser/block_header.go
  9. 4
      parser/transaction.go
  10. 2
      parser/transaction_test.go

26
cmd/server/main.go

@ -15,9 +15,9 @@ import (
"google.golang.org/grpc/peer"
"google.golang.org/grpc/reflection"
"github.com/adityapk00/lightwalletd/common"
"github.com/adityapk00/lightwalletd/frontend"
"github.com/adityapk00/lightwalletd/walletrpc"
"github.com/DenioD/lightwalletd/common"
"github.com/DenioD/lightwalletd/frontend"
"github.com/DenioD/lightwalletd/walletrpc"
)
var log *logrus.Entry
@ -81,32 +81,32 @@ type Options struct {
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"`
cacheSize int `json:"zcash_conf,omitempty"`
hush3ConfPath string `json:"hush3_conf,omitempty"`
cacheSize int `json:"hush3_conf,omitempty"`
}
func main() {
opts := &Options{}
flag.StringVar(&opts.bindAddr, "bind-addr", "127.0.0.1:9067", "the address to listen on")
flag.StringVar(&opts.bindAddr, "bind-addr", "127.0.0.1:9069", "the address to listen on")
flag.StringVar(&opts.tlsCertPath, "tls-cert", "", "the path to a TLS certificate (optional)")
flag.StringVar(&opts.tlsKeyPath, "tls-key", "", "the path to a TLS key file (optional)")
flag.Uint64Var(&opts.logLevel, "log-level", uint64(logrus.InfoLevel), "log level (logrus 1-7)")
flag.StringVar(&opts.logPath, "log-file", "", "log file to write to")
flag.StringVar(&opts.zcashConfPath, "conf-file", "", "conf file to pull RPC creds from")
flag.StringVar(&opts.hush3ConfPath, "conf-file", "", "conf file to pull RPC creds from")
flag.IntVar(&opts.cacheSize, "cache-size", 40000, "number of blocks to hold in the cache")
// TODO prod metrics
// TODO support config from file and env vars
flag.Parse()
if opts.zcashConfPath == "" {
if opts.hush3ConfPath == "" {
flag.Usage()
os.Exit(1)
}
if opts.tlsCertPath == "" || opts.tlsKeyPath == "" {
println("Please specify a TLS certificate/key to use. You can use a self-signed certificate.")
println("See 'https://github.com/adityapk00/lightwalletd/blob/master/README.md#running-your-own-zeclite-lightwalletd'")
println("See 'https://github.com/DenioD/lightwalletd/blob/master/README.md#running-your-own-hushlite-lightwalletd'")
os.Exit(1)
}
@ -148,17 +148,17 @@ func main() {
reflection.Register(server)
}
// Initialize Zcash RPC client. Right now (Jan 2018) this is only for
// Initialize Hush RPC client. Right now (Jan 2018) this is only for
// sending transactions, but in the future it could back a different type
// of block streamer.
rpcClient, err := frontend.NewZRPCFromConf(opts.zcashConfPath)
rpcClient, err := frontend.NewZRPCFromConf(opts.hush3ConfPath)
if err != nil {
log.WithFields(logrus.Fields{
"error": err,
}).Warn("zcash.conf failed, will try empty credentials for rpc")
}).Warn("HUSH3.conf failed, will try empty credentials for rpc")
rpcClient, err = frontend.NewZRPCFromCreds("127.0.0.1:8232", "", "")
rpcClient, err = frontend.NewZRPCFromCreds("127.0.0.1:18031", "", "")
if err != nil {
log.WithFields(logrus.Fields{

2
common/cache.go

@ -4,7 +4,7 @@ import (
"bytes"
"sync"
"github.com/adityapk00/lightwalletd/walletrpc"
"github.com/DenioD/lightwalletd/walletrpc"
"github.com/golang/protobuf/proto"
)

10
common/common.go

@ -8,8 +8,8 @@ import (
"strings"
"time"
"github.com/adityapk00/lightwalletd/parser"
"github.com/adityapk00/lightwalletd/walletrpc"
"github.com/DenioD/lightwalletd/parser"
"github.com/DenioD/lightwalletd/walletrpc"
"github.com/btcsuite/btcd/rpcclient"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
@ -25,7 +25,7 @@ func GetSaplingInfo(rpcClient *rpcclient.Client) (int, int, string, string, erro
if rpcErr != nil {
errParts := strings.SplitN(rpcErr.Error(), ":", 2)
errCode, err = strconv.ParseInt(errParts[0], 10, 32)
//Check to see if we are requesting a height the zcashd doesn't have yet
//Check to see if we are requesting a height the hushd doesn't have yet
if err == nil && errCode == -8 {
return -1, -1, "", "", nil
}
@ -65,7 +65,7 @@ func getBlockFromRPC(rpcClient *rpcclient.Client, height int) (*walletrpc.Compac
if rpcErr != nil {
errParts := strings.SplitN(rpcErr.Error(), ":", 2)
errCode, err = strconv.ParseInt(errParts[0], 10, 32)
//Check to see if we are requesting a height the zcashd doesn't have yet
//Check to see if we are requesting a height the hushd doesn't have yet
if err == nil && errCode == -8 {
return nil, nil
}
@ -130,7 +130,7 @@ func BlockIngestor(rpcClient *rpcclient.Client, cache *BlockCache, log *logrus.E
if timeoutCount == 3 {
log.WithFields(logrus.Fields{
"timeouts": timeoutCount,
}).Warn("unable to issue RPC call to zcashd node 3 times")
}).Warn("unable to issue RPC call to hushd node 3 times")
break
}
}

6
frontend/rpc_client.go

@ -23,13 +23,13 @@ func NewZRPCFromConf(confPath string) (*rpcclient.Client, error) {
}
func NewZRPCFromCreds(addr, username, password string) (*rpcclient.Client, error) {
// Connect to local zcash RPC server using HTTP POST mode.
// Connect to local hush RPC server using HTTP POST mode.
connCfg := &rpcclient.ConnConfig{
Host: addr,
User: username,
Pass: password,
HTTPPostMode: true, // Zcash only supports HTTP POST mode
DisableTLS: true, // Zcash does not provide TLS by default
HTTPPostMode: true, // Hush only supports HTTP POST mode
DisableTLS: true, // Hush does not provide TLS by default
}
// Notice the notification parameter is nil since notifications are
// not supported in HTTP POST mode.

16
frontend/service.go

@ -12,8 +12,8 @@ import (
"github.com/btcsuite/btcd/rpcclient"
"github.com/sirupsen/logrus"
"github.com/adityapk00/lightwalletd/common"
"github.com/adityapk00/lightwalletd/walletrpc"
"github.com/DenioD/lightwalletd/common"
"github.com/DenioD/lightwalletd/walletrpc"
)
var (
@ -68,7 +68,7 @@ func (s *SqlStreamer) GetAddressTxids(addressBlockFilter *walletrpc.TransparentA
s.log.Errorf("Got error: %s", rpcErr.Error())
errParts := strings.SplitN(rpcErr.Error(), ":", 2)
errCode, err = strconv.ParseInt(errParts[0], 10, 32)
//Check to see if we are requesting a height the zcashd doesn't have yet
//Check to see if we are requesting a height the hushd doesn't have yet
if err == nil && errCode == -8 {
return nil
}
@ -173,7 +173,7 @@ func (s *SqlStreamer) GetTransaction(ctx context.Context, txf *walletrpc.TxFilte
s.log.Errorf("Got error: %s", rpcErr.Error())
errParts := strings.SplitN(rpcErr.Error(), ":", 2)
errCode, err = strconv.ParseInt(errParts[0], 10, 32)
//Check to see if we are requesting a height the zcashd doesn't have yet
//Check to see if we are requesting a height the hushd doesn't have yet
if err == nil && errCode == -8 {
return nil, err
}
@ -203,7 +203,7 @@ func (s *SqlStreamer) GetTransaction(ctx context.Context, txf *walletrpc.TxFilte
s.log.Errorf("Got error: %s", rpcErr.Error())
errParts := strings.SplitN(rpcErr.Error(), ":", 2)
errCode, err = strconv.ParseInt(errParts[0], 10, 32)
//Check to see if we are requesting a height the zcashd doesn't have yet
//Check to see if we are requesting a height the hushd doesn't have yet
if err == nil && errCode == -8 {
return nil, err
}
@ -241,8 +241,8 @@ func (s *SqlStreamer) GetLightdInfo(ctx context.Context, in *walletrpc.Empty) (*
// TODO these are called Error but they aren't at the moment.
// A success will return code 0 and message txhash.
return &walletrpc.LightdInfo{
Version: "0.1-zeclightd",
Vendor: "ZecWallet LightWalletD",
Version: "0.1-hushlightd",
Vendor: "HushWallet LightWalletD",
TaddrSupport: true,
ChainName: chainName,
SaplingActivationHeight: uint64(saplingHeight),
@ -251,7 +251,7 @@ func (s *SqlStreamer) GetLightdInfo(ctx context.Context, in *walletrpc.Empty) (*
}, nil
}
// SendTransaction forwards raw transaction bytes to a zcashd instance over JSON-RPC
// SendTransaction forwards raw transaction bytes to a hushd instance over JSON-RPC
func (s *SqlStreamer) SendTransaction(ctx context.Context, rawtx *walletrpc.RawTransaction) (*walletrpc.SendResponse, error) {
// sendrawtransaction "hexstring" ( allowhighfees )
//

2
go.mod

@ -1,4 +1,4 @@
module github.com/adityapk00/lightwalletd
module github.com/DenioD/lightwalletd
go 1.12

4
parser/block.go

@ -4,8 +4,8 @@ import (
"fmt"
"github.com/pkg/errors"
"github.com/adityapk00/lightwalletd/parser/internal/bytestring"
"github.com/adityapk00/lightwalletd/walletrpc"
"github.com/DenioD/lightwalletd/parser/internal/bytestring"
"github.com/DenioD/lightwalletd/walletrpc"
)
type Block struct {

2
parser/block_header.go

@ -8,7 +8,7 @@ import (
"math/big"
"github.com/pkg/errors"
"github.com/adityapk00/lightwalletd/parser/internal/bytestring"
"github.com/DenioD/lightwalletd/parser/internal/bytestring"
)
const (

4
parser/transaction.go

@ -4,8 +4,8 @@ import (
"crypto/sha256"
"github.com/pkg/errors"
"github.com/adityapk00/lightwalletd/parser/internal/bytestring"
"github.com/adityapk00/lightwalletd/walletrpc"
"github.com/DenioD/lightwalletd/parser/internal/bytestring"
"github.com/DenioD/lightwalletd/walletrpc"
)
type rawTransaction struct {

2
parser/transaction_test.go

@ -9,7 +9,7 @@ import (
"strings"
"testing"
"github.com/adityapk00/lightwalletd/parser/internal/bytestring"
"github.com/DenioD/lightwalletd/parser/internal/bytestring"
)
// "Human-readable" version of joinSplit struct defined in transaction.go.

Loading…
Cancel
Save