port to hush
This commit is contained in:
@@ -15,9 +15,9 @@ import (
|
|||||||
"google.golang.org/grpc/peer"
|
"google.golang.org/grpc/peer"
|
||||||
"google.golang.org/grpc/reflection"
|
"google.golang.org/grpc/reflection"
|
||||||
|
|
||||||
"github.com/adityapk00/lightwalletd/common"
|
"github.com/DenioD/lightwalletd/common"
|
||||||
"github.com/adityapk00/lightwalletd/frontend"
|
"github.com/DenioD/lightwalletd/frontend"
|
||||||
"github.com/adityapk00/lightwalletd/walletrpc"
|
"github.com/DenioD/lightwalletd/walletrpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
var log *logrus.Entry
|
var log *logrus.Entry
|
||||||
@@ -81,32 +81,32 @@ type Options struct {
|
|||||||
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"`
|
hush3ConfPath string `json:"hush3_conf,omitempty"`
|
||||||
cacheSize int `json:"zcash_conf,omitempty"`
|
cacheSize int `json:"hush3_conf,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
opts := &Options{}
|
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.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.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.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.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")
|
flag.IntVar(&opts.cacheSize, "cache-size", 40000, "number of blocks to hold in the cache")
|
||||||
|
|
||||||
// TODO prod metrics
|
// TODO prod metrics
|
||||||
// TODO support config from file and env vars
|
// TODO support config from file and env vars
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if opts.zcashConfPath == "" {
|
if opts.hush3ConfPath == "" {
|
||||||
flag.Usage()
|
flag.Usage()
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.tlsCertPath == "" || opts.tlsKeyPath == "" {
|
if opts.tlsCertPath == "" || opts.tlsKeyPath == "" {
|
||||||
println("Please specify a TLS certificate/key to use. You can use a self-signed certificate.")
|
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)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,17 +148,17 @@ func main() {
|
|||||||
reflection.Register(server)
|
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
|
// sending transactions, but in the future it could back a different type
|
||||||
// of block streamer.
|
// of block streamer.
|
||||||
|
|
||||||
rpcClient, err := frontend.NewZRPCFromConf(opts.zcashConfPath)
|
rpcClient, err := frontend.NewZRPCFromConf(opts.hush3ConfPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithFields(logrus.Fields{
|
log.WithFields(logrus.Fields{
|
||||||
"error": err,
|
"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 {
|
if err != nil {
|
||||||
log.WithFields(logrus.Fields{
|
log.WithFields(logrus.Fields{
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/adityapk00/lightwalletd/walletrpc"
|
"github.com/DenioD/lightwalletd/walletrpc"
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/adityapk00/lightwalletd/parser"
|
"github.com/DenioD/lightwalletd/parser"
|
||||||
"github.com/adityapk00/lightwalletd/walletrpc"
|
"github.com/DenioD/lightwalletd/walletrpc"
|
||||||
"github.com/btcsuite/btcd/rpcclient"
|
"github.com/btcsuite/btcd/rpcclient"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@@ -25,7 +25,7 @@ func GetSaplingInfo(rpcClient *rpcclient.Client) (int, int, string, string, erro
|
|||||||
if rpcErr != nil {
|
if rpcErr != nil {
|
||||||
errParts := strings.SplitN(rpcErr.Error(), ":", 2)
|
errParts := strings.SplitN(rpcErr.Error(), ":", 2)
|
||||||
errCode, err = strconv.ParseInt(errParts[0], 10, 32)
|
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 {
|
if err == nil && errCode == -8 {
|
||||||
return -1, -1, "", "", nil
|
return -1, -1, "", "", nil
|
||||||
}
|
}
|
||||||
@@ -65,7 +65,7 @@ func getBlockFromRPC(rpcClient *rpcclient.Client, height int) (*walletrpc.Compac
|
|||||||
if rpcErr != nil {
|
if rpcErr != nil {
|
||||||
errParts := strings.SplitN(rpcErr.Error(), ":", 2)
|
errParts := strings.SplitN(rpcErr.Error(), ":", 2)
|
||||||
errCode, err = strconv.ParseInt(errParts[0], 10, 32)
|
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 {
|
if err == nil && errCode == -8 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
@@ -130,7 +130,7 @@ func BlockIngestor(rpcClient *rpcclient.Client, cache *BlockCache, log *logrus.E
|
|||||||
if timeoutCount == 3 {
|
if timeoutCount == 3 {
|
||||||
log.WithFields(logrus.Fields{
|
log.WithFields(logrus.Fields{
|
||||||
"timeouts": timeoutCount,
|
"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
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,13 +23,13 @@ func NewZRPCFromConf(confPath string) (*rpcclient.Client, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewZRPCFromCreds(addr, username, password 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{
|
connCfg := &rpcclient.ConnConfig{
|
||||||
Host: addr,
|
Host: addr,
|
||||||
User: username,
|
User: username,
|
||||||
Pass: password,
|
Pass: password,
|
||||||
HTTPPostMode: true, // Zcash only supports HTTP POST mode
|
HTTPPostMode: true, // Hush only supports HTTP POST mode
|
||||||
DisableTLS: true, // Zcash does not provide TLS by default
|
DisableTLS: true, // Hush does not provide TLS by default
|
||||||
}
|
}
|
||||||
// Notice the notification parameter is nil since notifications are
|
// Notice the notification parameter is nil since notifications are
|
||||||
// not supported in HTTP POST mode.
|
// not supported in HTTP POST mode.
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import (
|
|||||||
"github.com/btcsuite/btcd/rpcclient"
|
"github.com/btcsuite/btcd/rpcclient"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/adityapk00/lightwalletd/common"
|
"github.com/DenioD/lightwalletd/common"
|
||||||
"github.com/adityapk00/lightwalletd/walletrpc"
|
"github.com/DenioD/lightwalletd/walletrpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -68,7 +68,7 @@ func (s *SqlStreamer) GetAddressTxids(addressBlockFilter *walletrpc.TransparentA
|
|||||||
s.log.Errorf("Got error: %s", rpcErr.Error())
|
s.log.Errorf("Got error: %s", rpcErr.Error())
|
||||||
errParts := strings.SplitN(rpcErr.Error(), ":", 2)
|
errParts := strings.SplitN(rpcErr.Error(), ":", 2)
|
||||||
errCode, err = strconv.ParseInt(errParts[0], 10, 32)
|
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 {
|
if err == nil && errCode == -8 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -173,7 +173,7 @@ func (s *SqlStreamer) GetTransaction(ctx context.Context, txf *walletrpc.TxFilte
|
|||||||
s.log.Errorf("Got error: %s", rpcErr.Error())
|
s.log.Errorf("Got error: %s", rpcErr.Error())
|
||||||
errParts := strings.SplitN(rpcErr.Error(), ":", 2)
|
errParts := strings.SplitN(rpcErr.Error(), ":", 2)
|
||||||
errCode, err = strconv.ParseInt(errParts[0], 10, 32)
|
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 {
|
if err == nil && errCode == -8 {
|
||||||
return nil, err
|
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())
|
s.log.Errorf("Got error: %s", rpcErr.Error())
|
||||||
errParts := strings.SplitN(rpcErr.Error(), ":", 2)
|
errParts := strings.SplitN(rpcErr.Error(), ":", 2)
|
||||||
errCode, err = strconv.ParseInt(errParts[0], 10, 32)
|
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 {
|
if err == nil && errCode == -8 {
|
||||||
return nil, err
|
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.
|
// TODO these are called Error but they aren't at the moment.
|
||||||
// A success will return code 0 and message txhash.
|
// A success will return code 0 and message txhash.
|
||||||
return &walletrpc.LightdInfo{
|
return &walletrpc.LightdInfo{
|
||||||
Version: "0.1-zeclightd",
|
Version: "0.1-hushlightd",
|
||||||
Vendor: "ZecWallet LightWalletD",
|
Vendor: "HushWallet LightWalletD",
|
||||||
TaddrSupport: true,
|
TaddrSupport: true,
|
||||||
ChainName: chainName,
|
ChainName: chainName,
|
||||||
SaplingActivationHeight: uint64(saplingHeight),
|
SaplingActivationHeight: uint64(saplingHeight),
|
||||||
@@ -251,7 +251,7 @@ func (s *SqlStreamer) GetLightdInfo(ctx context.Context, in *walletrpc.Empty) (*
|
|||||||
}, nil
|
}, 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) {
|
func (s *SqlStreamer) SendTransaction(ctx context.Context, rawtx *walletrpc.RawTransaction) (*walletrpc.SendResponse, error) {
|
||||||
// sendrawtransaction "hexstring" ( allowhighfees )
|
// sendrawtransaction "hexstring" ( allowhighfees )
|
||||||
//
|
//
|
||||||
|
|||||||
2
go.mod
2
go.mod
@@ -1,4 +1,4 @@
|
|||||||
module github.com/adityapk00/lightwalletd
|
module github.com/DenioD/lightwalletd
|
||||||
|
|
||||||
go 1.12
|
go 1.12
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/adityapk00/lightwalletd/parser/internal/bytestring"
|
"github.com/DenioD/lightwalletd/parser/internal/bytestring"
|
||||||
"github.com/adityapk00/lightwalletd/walletrpc"
|
"github.com/DenioD/lightwalletd/walletrpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Block struct {
|
type Block struct {
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/adityapk00/lightwalletd/parser/internal/bytestring"
|
"github.com/DenioD/lightwalletd/parser/internal/bytestring"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import (
|
|||||||
"crypto/sha256"
|
"crypto/sha256"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/adityapk00/lightwalletd/parser/internal/bytestring"
|
"github.com/DenioD/lightwalletd/parser/internal/bytestring"
|
||||||
"github.com/adityapk00/lightwalletd/walletrpc"
|
"github.com/DenioD/lightwalletd/walletrpc"
|
||||||
)
|
)
|
||||||
|
|
||||||
type rawTransaction struct {
|
type rawTransaction struct {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"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.
|
// "Human-readable" version of joinSplit struct defined in transaction.go.
|
||||||
|
|||||||
Reference in New Issue
Block a user