From 4dc71cfc2e1b711e412fcf2c0fffa589b607e3c3 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Thu, 17 Oct 2019 19:00:00 -0700 Subject: [PATCH 1/9] Update README.md --- README.md | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 9afd434..79b3cd9 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,13 @@ # Overview -Zecwallet lightwalletd is a fork of [lightwalletd](https://github.com/adityapk00/lightwalletd) from the ECC. +SilentDragonLite (SDL) is a fork of Zecwallet lightwalletd, which is a fork of [lightwalletd](https://github.com/adityapk00/lightwalletd) from the ECC. -It is a backend service that provides a bandwidth-efficient interface to the Zcash blockchain for the [Zecwallet light wallet](https://github.com/adityapk00/zecwallet-lite-lib). +It is a backend service that provides a bandwidth-efficient interface to the Hush blockchain for the [SilentDragonLite cli](https://github.com/MyHush/zecwallet-light-cli). ## Changes from upstream lightwalletd -This version of Zecwallet lightwalletd extends lightwalletd and: +This version of lightwalletd extends lightwalletd and: + +* Adds support for HUSH * Adds support for transparent addresses * Adds several new RPC calls for lightclients * Lots of perf improvements @@ -13,7 +15,7 @@ This version of Zecwallet lightwalletd extends lightwalletd and: * Replace local Txstore, delegating Tx lookups to Zcashd * Remove the need for a separate ingestor -## Running your own zeclite lightwalletd +## Running your own SDL lightwalletd #### 0. First, install [Go >= 1.11](https://golang.org/dl/#stable). @@ -23,25 +25,22 @@ openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -node ``` Answer the certificate questions to generate the self-signed certificate -#### 2. You need to run a zcash full node with the following options in zcash.conf +#### 2. You need to run a full node with the following options in HUSH3.conf ``` server=1 rpcuser=user rpcpassword=password rpcbind=127.0.0.1 -rpcport=8232 -experimentalfeatures=1 txindex=1 -insightexplorer=1 ``` #### 3. Run the frontend: You'll need to use the certificate generated from step 1 ``` -go run cmd/server/main.go -bind-addr 127.0.0.1:9067 -conf-file ~/.zcash/zcash.conf -tls-cert cert.pem -tls-key key.pem +go run cmd/server/main.go -bind-addr 127.0.0.1:9069 -conf-file ~/.komodo/HUSH3/HUSH3.conf -tls-cert cert.pem -tls-key key.pem ``` #### 4. Point the `zecwallet-cli` to this server ``` -./zecwallet-cli --server https://127.0.0.1:9067 --dangerous +./zecwallet-cli --server https://127.0.0.1:9069 --dangerous ``` From 330930fc1b60d68611d92af7b1fbd96848f9b6e8 Mon Sep 17 00:00:00 2001 From: Duke Leto Date: Fri, 22 Nov 2019 08:21:09 -0800 Subject: [PATCH 2/9] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 79b3cd9..81f131d 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ You'll need to use the certificate generated from step 1 go run cmd/server/main.go -bind-addr 127.0.0.1:9069 -conf-file ~/.komodo/HUSH3/HUSH3.conf -tls-cert cert.pem -tls-key key.pem ``` -#### 4. Point the `zecwallet-cli` to this server +#### 4. Point the `silentdragon-cli` to this server ``` -./zecwallet-cli --server https://127.0.0.1:9069 --dangerous +./silentdragon-cli --server https://127.0.0.1:9069 --dangerous ``` From a0513c48c3f1fee1e7b4b8af4d0e428660953276 Mon Sep 17 00:00:00 2001 From: Denio <41270280+DenioD@users.noreply.github.com> Date: Sun, 1 Dec 2019 18:55:59 +0100 Subject: [PATCH 3/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9afd434..e8d1b55 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ insightexplorer=1 #### 3. Run the frontend: You'll need to use the certificate generated from step 1 ``` -go run cmd/server/main.go -bind-addr 127.0.0.1:9067 -conf-file ~/.zcash/zcash.conf -tls-cert cert.pem -tls-key key.pem +go run cmd/server/main.go -bind-addr 127.0.0.1:9067 -conf-file ~/.komodo/HUSH3/HUSH3.conf -tls-cert cert.pem -tls-key key.pem ``` #### 4. Point the `zecwallet-cli` to this server From a269cd1e6b79e32c08f760f1f3a53d8849adb4a0 Mon Sep 17 00:00:00 2001 From: Denio Date: Mon, 2 Dec 2019 10:35:38 +0100 Subject: [PATCH 4/9] add difficulty to lightdinfo --- cmd/server/main.go | 4 ++-- common/common.go | 11 ++++++----- frontend/service.go | 3 ++- walletrpc/service.pb.go | 7 +++++++ walletrpc/service.proto | 1 + 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index 1aba8b9..2d0e412 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -168,14 +168,14 @@ func main() { } // Get the sapling activation height from the RPC - saplingHeight, blockHeight, chainName, branchID, err := common.GetSaplingInfo(rpcClient) + saplingHeight, blockHeight, chainName, branchID, difficulty, err := common.GetSaplingInfo(rpcClient) if err != nil { log.WithFields(logrus.Fields{ "error": err, }).Warn("Unable to get sapling activation height") } - log.Info("Got sapling height ", saplingHeight, " chain ", chainName, " branchID ", branchID) + log.Info("Got sapling height ", saplingHeight, " chain ", chainName, " branchID ", branchID," difficulty ", difficulty,) // Initialize the cache cache := common.NewBlockCache(opts.cacheSize) diff --git a/common/common.go b/common/common.go index 71c45a6..acec182 100644 --- a/common/common.go +++ b/common/common.go @@ -15,7 +15,7 @@ import ( "github.com/sirupsen/logrus" ) -func GetSaplingInfo(rpcClient *rpcclient.Client) (int, int, string, string, error) { +func GetSaplingInfo(rpcClient *rpcclient.Client) (int, int, string, string, int, error) { result, rpcErr := rpcClient.RawRequest("getblockchaininfo", make([]json.RawMessage, 0)) var err error @@ -27,15 +27,15 @@ func GetSaplingInfo(rpcClient *rpcclient.Client) (int, int, string, string, erro errCode, err = strconv.ParseInt(errParts[0], 10, 32) //Check to see if we are requesting a height the hushd doesn't have yet if err == nil && errCode == -8 { - return -1, -1, "", "", nil + return -1, -1, "", "",-1, nil } - return -1, -1, "", "", errors.Wrap(rpcErr, "error requesting block") + return -1, -1, "", "",-1, errors.Wrap(rpcErr, "error requesting block") } var f interface{} err = json.Unmarshal(result, &f) if err != nil { - return -1, -1, "", "", errors.Wrap(err, "error reading JSON response") + return -1, -1, "", "",-1, errors.Wrap(err, "error reading JSON response") } chainName := f.(map[string]interface{})["chain"].(string) @@ -45,11 +45,12 @@ func GetSaplingInfo(rpcClient *rpcclient.Client) (int, int, string, string, erro saplingHeight := saplingJSON.(map[string]interface{})["activationheight"].(float64) blockHeight := f.(map[string]interface{})["headers"].(float64) + difficulty := f.(map[string]interface{})["difficulty"].(float64) consensus := f.(map[string]interface{})["consensus"] branchID := consensus.(map[string]interface{})["nextblock"].(string) - return int(saplingHeight), int(blockHeight), chainName, branchID, nil + return int(saplingHeight), int(blockHeight), chainName, branchID, int(difficulty), nil } func getBlockFromRPC(rpcClient *rpcclient.Client, height int) (*walletrpc.CompactBlock, error) { diff --git a/frontend/service.go b/frontend/service.go index dcf66eb..e520d0d 100644 --- a/frontend/service.go +++ b/frontend/service.go @@ -229,7 +229,7 @@ func (s *SqlStreamer) GetTransaction(ctx context.Context, txf *walletrpc.TxFilte // GetLightdInfo gets the LightWalletD (this server) info func (s *SqlStreamer) GetLightdInfo(ctx context.Context, in *walletrpc.Empty) (*walletrpc.LightdInfo, error) { - saplingHeight, blockHeight, chainName, consensusBranchId, err := common.GetSaplingInfo(s.client) + saplingHeight, blockHeight, chainName, consensusBranchId, difficulty, err := common.GetSaplingInfo(s.client) if err != nil { s.log.WithFields(logrus.Fields{ @@ -248,6 +248,7 @@ func (s *SqlStreamer) GetLightdInfo(ctx context.Context, in *walletrpc.Empty) (* SaplingActivationHeight: uint64(saplingHeight), ConsensusBranchId: consensusBranchId, BlockHeight: uint64(blockHeight), + Difficulty: uint64(difficulty), }, nil } diff --git a/walletrpc/service.pb.go b/walletrpc/service.pb.go index 23303e0..ba5cbbf 100644 --- a/walletrpc/service.pb.go +++ b/walletrpc/service.pb.go @@ -347,6 +347,7 @@ type LightdInfo struct { SaplingActivationHeight uint64 `protobuf:"varint,5,opt,name=saplingActivationHeight,proto3" json:"saplingActivationHeight,omitempty"` ConsensusBranchId string `protobuf:"bytes,6,opt,name=consensusBranchId,proto3" json:"consensusBranchId,omitempty"` BlockHeight uint64 `protobuf:"varint,7,opt,name=blockHeight,proto3" json:"blockHeight,omitempty"` + Difficulty uint64 `protobuf:"varint,8,opt,name=difficulty,proto3" json:"difficulty,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -418,6 +419,12 @@ func (m *LightdInfo) GetConsensusBranchId() string { } return "" } +func (m *LightdInfo) Getdifficulty() uint64 { + if m != nil { + return m.Difficulty + } + return 0 +} func (m *LightdInfo) GetBlockHeight() uint64 { if m != nil { diff --git a/walletrpc/service.proto b/walletrpc/service.proto index 06c5b5b..a54a988 100644 --- a/walletrpc/service.proto +++ b/walletrpc/service.proto @@ -52,6 +52,7 @@ message LightdInfo { uint64 saplingActivationHeight = 5; string consensusBranchId = 6; // This should really be u32 or []byte, but string for readability uint64 blockHeight = 7; + string difficulty = 8; } message TransparentAddress { From 0978322f627e361d513af4fa11eb0694ede3e6e0 Mon Sep 17 00:00:00 2001 From: Denio Date: Mon, 2 Dec 2019 11:42:50 +0100 Subject: [PATCH 5/9] add longestchain and notarized to lightinfod --- cmd/server/main.go | 4 ++-- common/common.go | 14 ++++++++------ frontend/service.go | 4 +++- walletrpc/service.pb.go | 14 ++++++++++++++ walletrpc/service.proto | 4 +++- 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index 2d0e412..4b17603 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -168,14 +168,14 @@ func main() { } // Get the sapling activation height from the RPC - saplingHeight, blockHeight, chainName, branchID, difficulty, err := common.GetSaplingInfo(rpcClient) + saplingHeight, blockHeight, chainName, branchID, difficulty, longestchain, notarized, err := common.GetSaplingInfo(rpcClient) if err != nil { log.WithFields(logrus.Fields{ "error": err, }).Warn("Unable to get sapling activation height") } - log.Info("Got sapling height ", saplingHeight, " chain ", chainName, " branchID ", branchID," difficulty ", difficulty,) + log.Info("Got sapling height ", saplingHeight, " chain ", chainName, " branchID ", branchID," difficulty ", difficulty,longestchain, " longestchain ",notarized," notarized ") // Initialize the cache cache := common.NewBlockCache(opts.cacheSize) diff --git a/common/common.go b/common/common.go index acec182..6da4eaf 100644 --- a/common/common.go +++ b/common/common.go @@ -15,7 +15,7 @@ import ( "github.com/sirupsen/logrus" ) -func GetSaplingInfo(rpcClient *rpcclient.Client) (int, int, string, string, int, error) { +func GetSaplingInfo(rpcClient *rpcclient.Client) (int, int, string, string, int,int,int, error) { result, rpcErr := rpcClient.RawRequest("getblockchaininfo", make([]json.RawMessage, 0)) var err error @@ -27,15 +27,15 @@ func GetSaplingInfo(rpcClient *rpcclient.Client) (int, int, string, string, int, errCode, err = strconv.ParseInt(errParts[0], 10, 32) //Check to see if we are requesting a height the hushd doesn't have yet if err == nil && errCode == -8 { - return -1, -1, "", "",-1, nil + return -1, -1, "", "",-1,-1,-1, nil } - return -1, -1, "", "",-1, errors.Wrap(rpcErr, "error requesting block") + return -1, -1, "", "",-1,-1,-1, errors.Wrap(rpcErr, "error requesting block") } var f interface{} err = json.Unmarshal(result, &f) if err != nil { - return -1, -1, "", "",-1, errors.Wrap(err, "error reading JSON response") + return -1, -1, "", "",-1,-1,-1, errors.Wrap(err, "error reading JSON response") } chainName := f.(map[string]interface{})["chain"].(string) @@ -45,12 +45,14 @@ func GetSaplingInfo(rpcClient *rpcclient.Client) (int, int, string, string, int, saplingHeight := saplingJSON.(map[string]interface{})["activationheight"].(float64) blockHeight := f.(map[string]interface{})["headers"].(float64) - difficulty := f.(map[string]interface{})["difficulty"].(float64) + difficulty := f.(map[string]interface{})["difficulty"].(float64) + longestchain := f.(map[string]interface{})["longestchain"].(float64) + notarized := f.(map[string]interface{})["notarized"].(float64) consensus := f.(map[string]interface{})["consensus"] branchID := consensus.(map[string]interface{})["nextblock"].(string) - return int(saplingHeight), int(blockHeight), chainName, branchID, int(difficulty), nil + return int(saplingHeight), int(blockHeight), chainName, branchID, int(difficulty), int(longestchain), int(notarized), nil } func getBlockFromRPC(rpcClient *rpcclient.Client, height int) (*walletrpc.CompactBlock, error) { diff --git a/frontend/service.go b/frontend/service.go index e520d0d..e7325c9 100644 --- a/frontend/service.go +++ b/frontend/service.go @@ -229,7 +229,7 @@ func (s *SqlStreamer) GetTransaction(ctx context.Context, txf *walletrpc.TxFilte // GetLightdInfo gets the LightWalletD (this server) info func (s *SqlStreamer) GetLightdInfo(ctx context.Context, in *walletrpc.Empty) (*walletrpc.LightdInfo, error) { - saplingHeight, blockHeight, chainName, consensusBranchId, difficulty, err := common.GetSaplingInfo(s.client) + saplingHeight, blockHeight, chainName, consensusBranchId, difficulty, longestchain, notarized, err := common.GetSaplingInfo(s.client) if err != nil { s.log.WithFields(logrus.Fields{ @@ -249,6 +249,8 @@ func (s *SqlStreamer) GetLightdInfo(ctx context.Context, in *walletrpc.Empty) (* ConsensusBranchId: consensusBranchId, BlockHeight: uint64(blockHeight), Difficulty: uint64(difficulty), + Longestchain: uint64(longestchain), + Notarized: uint64(notarized), }, nil } diff --git a/walletrpc/service.pb.go b/walletrpc/service.pb.go index ba5cbbf..76831f7 100644 --- a/walletrpc/service.pb.go +++ b/walletrpc/service.pb.go @@ -348,6 +348,8 @@ type LightdInfo struct { ConsensusBranchId string `protobuf:"bytes,6,opt,name=consensusBranchId,proto3" json:"consensusBranchId,omitempty"` BlockHeight uint64 `protobuf:"varint,7,opt,name=blockHeight,proto3" json:"blockHeight,omitempty"` Difficulty uint64 `protobuf:"varint,8,opt,name=difficulty,proto3" json:"difficulty,omitempty"` + Longestchain uint64 `protobuf:"varint,9,opt,name=longestchain,proto3" json:"longestchain,omitempty"` + Notarized uint64 `protobuf:"varint,10,opt,name=notarized,proto3" json:"notarized,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -425,6 +427,18 @@ func (m *LightdInfo) Getdifficulty() uint64 { } return 0 } +func (m *LightdInfo) Getlongestchain() uint64 { + if m != nil { + return m.Longestchain + } + return 0 +} +func (m *LightdInfo) Getnotarized() uint64 { + if m != nil { + return m.Notarized + } + return 0 +} func (m *LightdInfo) GetBlockHeight() uint64 { if m != nil { diff --git a/walletrpc/service.proto b/walletrpc/service.proto index a54a988..322e56b 100644 --- a/walletrpc/service.proto +++ b/walletrpc/service.proto @@ -52,7 +52,9 @@ message LightdInfo { uint64 saplingActivationHeight = 5; string consensusBranchId = 6; // This should really be u32 or []byte, but string for readability uint64 blockHeight = 7; - string difficulty = 8; + uint64 difficulty = 8; + uint64 longestchain = 9; + uint64 notarized = 10; } message TransparentAddress { From 1608369f09ef3709cad5590c3900e03bca98bc27 Mon Sep 17 00:00:00 2001 From: Denio Date: Mon, 2 Dec 2019 21:37:56 +0100 Subject: [PATCH 6/9] add no-tls --- cmd/server/main.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cmd/server/main.go b/cmd/server/main.go index 4b17603..9c6470b 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -79,6 +79,7 @@ type Options struct { bindAddr string `json:"bind_address,omitempty"` tlsCertPath string `json:"tls_cert_path,omitempty"` tlsKeyPath string `json:"tls_cert_key,omitempty"` + noTLS bool `json:no_tls,omitempty` logLevel uint64 `json:"log_level,omitempty"` logPath string `json:"log_file,omitempty"` hush3ConfPath string `json:"hush3_conf,omitempty"` @@ -90,6 +91,7 @@ func main() { 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.BoolVar(&opts.noTLS, "no-tls", false, "Disable TLS, serve un-encrypted traffic.") 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.hush3ConfPath, "conf-file", "", "conf file to pull RPC creds from") @@ -104,7 +106,7 @@ func main() { os.Exit(1) } - if opts.tlsCertPath == "" || opts.tlsKeyPath == "" { + if !opts.noTLS && (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/DenioD/lightwalletd/blob/master/README.md#running-your-own-hushlite-lightwalletd'") os.Exit(1) @@ -129,7 +131,7 @@ func main() { // gRPC initialization var server *grpc.Server - if opts.tlsCertPath != "" && opts.tlsKeyPath != "" { + if !opts.noTLS && (opts.tlsCertPath != "" && opts.tlsKeyPath != "") { transportCreds, err := credentials.NewServerTLSFromFile(opts.tlsCertPath, opts.tlsKeyPath) if err != nil { log.WithFields(logrus.Fields{ From 01e1d766a0419da0bc83e4030c62168ff5f43e68 Mon Sep 17 00:00:00 2001 From: Denio Date: Thu, 5 Dec 2019 21:37:35 +0100 Subject: [PATCH 7/9] add coinsupply rpc to lightwalletd --- cmd/server/main.go | 10 ++++ common/common.go | 34 ++++++++++++ frontend/service.go | 24 +++++++++ walletrpc/service.pb.go | 115 ++++++++++++++++++++++++++++++++++++++++ walletrpc/service.proto | 9 ++++ 5 files changed, 192 insertions(+) diff --git a/cmd/server/main.go b/cmd/server/main.go index 9c6470b..e56c058 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -179,6 +179,16 @@ func main() { log.Info("Got sapling height ", saplingHeight, " chain ", chainName, " branchID ", branchID," difficulty ", difficulty,longestchain, " longestchain ",notarized," notarized ") + // Get the Coinsupply from the RPC + result, coin, height, supply, zfunds, total, err := common.GetCoinsupply(rpcClient) + if err != nil { + log.WithFields(logrus.Fields{ + "error": err, + }).Warn("Unable to get coinsupply") + } + + log.Info( " result ", result, " coin ", coin," height", height, "supply", supply ,"zfunds", zfunds, "total", total) + // Initialize the cache cache := common.NewBlockCache(opts.cacheSize) diff --git a/common/common.go b/common/common.go index 6da4eaf..4bb53fd 100644 --- a/common/common.go +++ b/common/common.go @@ -55,6 +55,40 @@ func GetSaplingInfo(rpcClient *rpcclient.Client) (int, int, string, string, int, return int(saplingHeight), int(blockHeight), chainName, branchID, int(difficulty), int(longestchain), int(notarized), nil } +func GetCoinsupply(rpcClient *rpcclient.Client) (string, string, int, int, int,int, error) { + result1, rpcErr := rpcClient.RawRequest("coinsupply", make([]json.RawMessage, 0)) + + var err error + var errCode int64 + + + // For some reason, the error responses are not JSON + 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 hushd doesn't have yet + if err == nil && errCode == -8 { + return "","", -1, -1,-1,-1, nil + } + return "","", -1, -1,-1,-1, errors.Wrap(rpcErr, "error requesting coinsupply") + } + + var f interface{} + err = json.Unmarshal(result1, &f) + if err != nil { + return "","", -1, -1,-1,-1, errors.Wrap(err, "error reading JSON response") + } + + result := f.(map[string]interface{})["result"].(string) + coin := f.(map[string]interface{})["coin"].(string) + height := f.(map[string]interface{})["height"].(float64) + supply := f.(map[string]interface{})["supply"].(float64) + zfunds := f.(map[string]interface{})["zfunds"].(float64) + total := f.(map[string]interface{})["total"].(float64) + + return result,coin, int(height), int(supply),int(zfunds), int(total), nil +} + func getBlockFromRPC(rpcClient *rpcclient.Client, height int) (*walletrpc.CompactBlock, error) { params := make([]json.RawMessage, 2) params[0] = json.RawMessage("\"" + strconv.Itoa(height) + "\"") diff --git a/frontend/service.go b/frontend/service.go index e7325c9..61da90f 100644 --- a/frontend/service.go +++ b/frontend/service.go @@ -254,6 +254,30 @@ func (s *SqlStreamer) GetLightdInfo(ctx context.Context, in *walletrpc.Empty) (* }, nil } +// GetCoinsupply gets the Coinsupply info +func (s *SqlStreamer) GetCoinsupply(ctx context.Context, in *walletrpc.Empty) (*walletrpc.Coinsupply, error) { + result, coin, height, supply, zfunds,total, err := common.GetCoinsupply(s.client) + + if err != nil { + s.log.WithFields(logrus.Fields{ + "error": err, + }).Warn("Unable to get Coinsupply") + return nil, err + } + + // TODO these are called Error but they aren't at the moment. + // A success will return code 0 and message txhash. + return &walletrpc.Coinsupply{ + Result: result, + Coin: coin, + Height: uint64(height), + Supply: uint64(supply), + Zfunds: uint64(zfunds), + Total: uint64(total), + }, nil +} + + // 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 ) diff --git a/walletrpc/service.pb.go b/walletrpc/service.pb.go index 76831f7..f73ee41 100644 --- a/walletrpc/service.pb.go +++ b/walletrpc/service.pb.go @@ -447,6 +447,85 @@ func (m *LightdInfo) GetBlockHeight() uint64 { return 0 } +type Coinsupply struct { + Result string `protobuf:"bytes,1,opt,name=result,proto3" json:"result,omitempty"` + Coin string `protobuf:"bytes,2,opt,name=coin,proto3" json:"coin,omitempty"` + Height uint64 `protobuf:"varint,3,opt,name=height,proto3" json:"height,omitempty"` + Supply uint64 `protobuf:"varint,4,opt,name=supply,proto3" json:"supply,omitempty"` + Zfunds uint64 `protobuf:"varint,5,opt,name=zfunds,proto3" json:"zfunds,omitempty"` + Total uint64 `protobuf:"varint,6,opt,name=total,proto3" json:"total,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Coinsupply) Reset() { *m = Coinsupply{} } +func (m *Coinsupply) String() string { return proto.CompactTextString(m) } +func (*Coinsupply) ProtoMessage() {} +func (*Coinsupply) Descriptor() ([]byte, []int) { + return fileDescriptor_a0b84a42fa06f626, []int{7} +} + +func (m *Coinsupply) XXX_Unmarshal(b []byte) error { + return xxx_messageInfo_Coinsupply.Unmarshal(m, b) +} +func (m *Coinsupply) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + return xxx_messageInfo_Coinsupply.Marshal(b, m, deterministic) +} +func (m *Coinsupply) XXX_Merge(src proto.Message) { + xxx_messageInfo_Coinsupply.Merge(m, src) +} +func (m *Coinsupply) XXX_Size() int { + return xxx_messageInfo_Coinsupply.Size(m) +} +func (m *Coinsupply) XXX_DiscardUnknown() { + xxx_messageInfo_Coinsupply.DiscardUnknown(m) +} + +var xxx_messageInfo_Coinsupply proto.InternalMessageInfo + +func (m *Coinsupply) GetResult() string { + if m != nil { + return m.Result + } + return "" +} + +func (m *Coinsupply) GetCoin() string { + if m != nil { + return m.Coin + } + return "" +} + +func (m *Coinsupply) GetHeight() uint64 { + if m != nil { + return m.Height + } + return 0 +} + +func (m *Coinsupply) GetSupply() uint64 { + if m != nil { + return m.Supply + } + return 0 +} + +func (m *Coinsupply) GetZfunds() uint64 { + if m != nil { + return m.Zfunds + } + return 0 +} + +func (m *Coinsupply) GetTotal() uint64 { + if m != nil { + return m.Total + } + return 0 +} + type TransparentAddress struct { Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` @@ -542,6 +621,7 @@ func init() { proto.RegisterType((*ChainSpec)(nil), "cash.z.wallet.sdk.rpc.ChainSpec") proto.RegisterType((*Empty)(nil), "cash.z.wallet.sdk.rpc.Empty") proto.RegisterType((*LightdInfo)(nil), "cash.z.wallet.sdk.rpc.LightdInfo") + proto.RegisterType((*Coinsupply)(nil), "cash.z.wallet.sdk.rpc.Coinsupply") proto.RegisterType((*TransparentAddress)(nil), "cash.z.wallet.sdk.rpc.TransparentAddress") proto.RegisterType((*TransparentAddressBlockFilter)(nil), "cash.z.wallet.sdk.rpc.TransparentAddressBlockFilter") } @@ -616,6 +696,7 @@ type CompactTxStreamerClient interface { GetAddressTxids(ctx context.Context, in *TransparentAddressBlockFilter, opts ...grpc.CallOption) (CompactTxStreamer_GetAddressTxidsClient, error) // Misc GetLightdInfo(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*LightdInfo, error) + GetCoinsupply(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Coinsupply, error) } type compactTxStreamerClient struct { @@ -734,6 +815,14 @@ func (c *compactTxStreamerClient) GetLightdInfo(ctx context.Context, in *Empty, } return out, nil } +func (c *compactTxStreamerClient) GetCoinsupply(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Coinsupply, error) { + out := new(Coinsupply) + err := c.cc.Invoke(ctx, "/cash.z.wallet.sdk.rpc.CompactTxStreamer/GetCoinsupply", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} // CompactTxStreamerServer is the server API for CompactTxStreamer service. type CompactTxStreamerServer interface { @@ -748,6 +837,7 @@ type CompactTxStreamerServer interface { GetAddressTxids(*TransparentAddressBlockFilter, CompactTxStreamer_GetAddressTxidsServer) error // Misc GetLightdInfo(context.Context, *Empty) (*LightdInfo, error) + GetCoinsupply(context.Context, *Empty) (*Coinsupply, error) } // UnimplementedCompactTxStreamerServer can be embedded to have forward compatible implementations. @@ -775,6 +865,9 @@ func (*UnimplementedCompactTxStreamerServer) GetAddressTxids(req *TransparentAdd func (*UnimplementedCompactTxStreamerServer) GetLightdInfo(ctx context.Context, req *Empty) (*LightdInfo, error) { return nil, status.Errorf(codes.Unimplemented, "method GetLightdInfo not implemented") } +func (*UnimplementedCompactTxStreamerServer) GetCoinsupply(ctx context.Context, req *Empty) (*Coinsupply, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetCoinsupply not implemented") +} func RegisterCompactTxStreamerServer(s *grpc.Server, srv CompactTxStreamerServer) { s.RegisterService(&_CompactTxStreamer_serviceDesc, srv) @@ -912,6 +1005,24 @@ func _CompactTxStreamer_GetLightdInfo_Handler(srv interface{}, ctx context.Conte return interceptor(ctx, in, info, handler) } +func _CompactTxStreamer_GetCoinsupply_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(CompactTxStreamerServer).GetCoinsupply(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/cash.z.wallet.sdk.rpc.CompactTxStreamer/GetCoinsupply", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(CompactTxStreamerServer).GetCoinsupply(ctx, req.(*Empty)) + } + return interceptor(ctx, in, info, handler) +} + var _CompactTxStreamer_serviceDesc = grpc.ServiceDesc{ ServiceName: "cash.z.wallet.sdk.rpc.CompactTxStreamer", HandlerType: (*CompactTxStreamerServer)(nil), @@ -936,6 +1047,10 @@ var _CompactTxStreamer_serviceDesc = grpc.ServiceDesc{ MethodName: "GetLightdInfo", Handler: _CompactTxStreamer_GetLightdInfo_Handler, }, + { + MethodName: "GetCoinsupply", + Handler: _CompactTxStreamer_GetCoinsupply_Handler, + }, }, Streams: []grpc.StreamDesc{ { diff --git a/walletrpc/service.proto b/walletrpc/service.proto index 322e56b..b5e0086 100644 --- a/walletrpc/service.proto +++ b/walletrpc/service.proto @@ -56,6 +56,14 @@ message LightdInfo { uint64 longestchain = 9; uint64 notarized = 10; } +message Coinsupply { + string result = 1; + string coin = 2; + uint64 height = 3; + uint64 supply = 4; + uint64 zfunds = 5; + uint64 total = 6; +} message TransparentAddress { string address = 1; @@ -81,4 +89,5 @@ service CompactTxStreamer { // Misc rpc GetLightdInfo(Empty) returns (LightdInfo) {} + rpc GetCoinsupply(Empty) returns (Coinsupply) {} } From da68a5368b597cdb0f37db359bbe55d8f884665d Mon Sep 17 00:00:00 2001 From: Dennis Netterdon Date: Fri, 15 May 2020 10:56:29 +0200 Subject: [PATCH 8/9] tix taddr --- frontend/service.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/frontend/service.go b/frontend/service.go index 61da90f..aeef4ed 100644 --- a/frontend/service.go +++ b/frontend/service.go @@ -8,6 +8,7 @@ import ( "strconv" "strings" "time" + "regexp" "github.com/btcsuite/btcd/rpcclient" "github.com/sirupsen/logrus" @@ -51,7 +52,17 @@ func (s *SqlStreamer) GetLatestBlock(ctx context.Context, placeholder *walletrpc } func (s *SqlStreamer) GetAddressTxids(addressBlockFilter *walletrpc.TransparentAddressBlockFilter, resp walletrpc.CompactTxStreamer_GetAddressTxidsServer) error { - params := make([]json.RawMessage, 1) + var err error + var errCode int64 + + // Test to make sure Address is a single t address + match, err := regexp.Match("^R[a-zA-Z0-9]{34}$", []byte(addressBlockFilter.Address)) + if err != nil || !match { + s.log.Errorf("Unrecognized address: %s", addressBlockFilter.Address) + return nil + } + + params := make([]json.RawMessage, 1) st := "{\"addresses\": [\"" + addressBlockFilter.Address + "\"]," + "\"start\": " + strconv.FormatUint(addressBlockFilter.Range.Start.Height, 10) + ", \"end\": " + strconv.FormatUint(addressBlockFilter.Range.End.Height, 10) + "}" @@ -60,8 +71,6 @@ func (s *SqlStreamer) GetAddressTxids(addressBlockFilter *walletrpc.TransparentA result, rpcErr := s.client.RawRequest("getaddresstxids", params) - var err error - var errCode int64 // For some reason, the error responses are not JSON if rpcErr != nil { From c952f7e3d9a6359fb3740a26f913a08e784f287d Mon Sep 17 00:00:00 2001 From: Dennis Netterdon Date: Fri, 15 May 2020 11:19:41 +0200 Subject: [PATCH 9/9] tix taddr --- frontend/service.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/service.go b/frontend/service.go index aeef4ed..1b82bc1 100644 --- a/frontend/service.go +++ b/frontend/service.go @@ -56,7 +56,7 @@ func (s *SqlStreamer) GetAddressTxids(addressBlockFilter *walletrpc.TransparentA var errCode int64 // Test to make sure Address is a single t address - match, err := regexp.Match("^R[a-zA-Z0-9]{34}$", []byte(addressBlockFilter.Address)) + match, err := regexp.Match("^R[a-zA-Z0-9]{33}$", []byte(addressBlockFilter.Address)) if err != nil || !match { s.log.Errorf("Unrecognized address: %s", addressBlockFilter.Address) return nil