diff --git a/cmd/server/main.go b/cmd/server/main.go index 379f298..31ef6b9 100644 --- a/cmd/server/main.go +++ b/cmd/server/main.go @@ -15,9 +15,9 @@ import ( "google.golang.org/grpc/peer" "google.golang.org/grpc/reflection" - "github.com/DenioD/lightwalletd/common" - "github.com/DenioD/lightwalletd/frontend" - "github.com/DenioD/lightwalletd/walletrpc" + "git.hush.is/hush/lightwalletd/common" + "git.hush.is/hush/lightwalletd/frontend" + "git.hush.is/hush/lightwalletd/walletrpc" ) var log *logrus.Entry @@ -108,7 +108,7 @@ func main() { 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://git.hush.is/hush/lightwalletd/src/branch/master/README.md#running-your-own-sdl-lightwalletd") + println("See https://git.hush.is/hush/lightwalletd/src/branch/master/README.md#running-your-own-sdl-lightwalletd") os.Exit(1) } @@ -177,17 +177,17 @@ func main() { }).Warn("Unable to get sapling activation height") } - log.Info("Got sapling height ", saplingHeight, " chain ", chainName, " branchID ", branchID," difficulty ", difficulty,longestchain, " longestchain ",notarized," notarized ") + 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) + 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) + 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/cache.go b/common/cache.go index e1b7a7d..c2488a6 100644 --- a/common/cache.go +++ b/common/cache.go @@ -4,7 +4,7 @@ import ( "bytes" "sync" - "github.com/DenioD/lightwalletd/walletrpc" + "git.hush.is/hush/lightwalletd/walletrpc" "github.com/golang/protobuf/proto" ) diff --git a/common/common.go b/common/common.go index 4bb53fd..113dd59 100644 --- a/common/common.go +++ b/common/common.go @@ -8,14 +8,14 @@ import ( "strings" "time" - "github.com/DenioD/lightwalletd/parser" - "github.com/DenioD/lightwalletd/walletrpc" + "git.hush.is/hush/lightwalletd/parser" + "git.hush.is/hush/lightwalletd/walletrpc" "github.com/btcsuite/btcd/rpcclient" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) -func GetSaplingInfo(rpcClient *rpcclient.Client) (int, int, string, string, int,int,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,-1,-1, nil + return -1, -1, "", "", -1, -1, -1, nil } - return -1, -1, "", "",-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,-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) @@ -55,28 +55,27 @@ 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) { +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, nil } - return "","", -1, -1,-1,-1, errors.Wrap(rpcErr, "error requesting coinsupply") + 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") + return "", "", -1, -1, -1, -1, errors.Wrap(err, "error reading JSON response") } result := f.(map[string]interface{})["result"].(string) @@ -86,7 +85,7 @@ func GetCoinsupply(rpcClient *rpcclient.Client) (string, string, int, int, int,i 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 + return result, coin, int(height), int(supply), int(zfunds), int(total), nil } func getBlockFromRPC(rpcClient *rpcclient.Client, height int) (*walletrpc.CompactBlock, error) { diff --git a/frontend/service.go b/frontend/service.go index 1b82bc1..08f45ea 100644 --- a/frontend/service.go +++ b/frontend/service.go @@ -5,16 +5,16 @@ import ( "encoding/hex" "encoding/json" "errors" + "regexp" "strconv" "strings" "time" - "regexp" "github.com/btcsuite/btcd/rpcclient" "github.com/sirupsen/logrus" - "github.com/DenioD/lightwalletd/common" - "github.com/DenioD/lightwalletd/walletrpc" + "git.hush.is/hush/lightwalletd/common" + "git.hush.is/hush/lightwalletd/walletrpc" ) var ( @@ -53,16 +53,16 @@ func (s *SqlStreamer) GetLatestBlock(ctx context.Context, placeholder *walletrpc func (s *SqlStreamer) GetAddressTxids(addressBlockFilter *walletrpc.TransparentAddressBlockFilter, resp walletrpc.CompactTxStreamer_GetAddressTxidsServer) error { 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]{33}$", []byte(addressBlockFilter.Address)) - if err != nil || !match { - s.log.Errorf("Unrecognized address: %s", addressBlockFilter.Address) - return nil - } - - params := make([]json.RawMessage, 1) + var errCode int64 + + // Test to make sure Address is a single t 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 + } + + 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) + "}" @@ -71,7 +71,6 @@ func (s *SqlStreamer) GetAddressTxids(addressBlockFilter *walletrpc.TransparentA result, rpcErr := s.client.RawRequest("getaddresstxids", params) - // For some reason, the error responses are not JSON if rpcErr != nil { s.log.Errorf("Got error: %s", rpcErr.Error()) @@ -238,7 +237,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, longestchain, notarized, 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{ @@ -265,7 +264,7 @@ func (s *SqlStreamer) GetLightdInfo(ctx context.Context, in *walletrpc.Empty) (* // 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) + result, coin, height, supply, zfunds, total, err := common.GetCoinsupply(s.client) if err != nil { s.log.WithFields(logrus.Fields{ @@ -277,16 +276,15 @@ func (s *SqlStreamer) GetCoinsupply(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.Coinsupply{ - Result: result, - Coin: coin, - Height: uint64(height), - Supply: uint64(supply), - Zfunds: uint64(zfunds), - Total: uint64(total), + 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/go.mod b/go.mod index 8b79e9d..e350120 100644 --- a/go.mod +++ b/go.mod @@ -1,4 +1,4 @@ -module github.com/DenioD/lightwalletd +module git.hush.is/hush/lightwalletd go 1.12 diff --git a/parser/block.go b/parser/block.go index 6ab8c04..0fa83dd 100644 --- a/parser/block.go +++ b/parser/block.go @@ -3,9 +3,9 @@ package parser import ( "fmt" + "git.hush.is/hush/lightwalletd/parser/internal/bytestring" + "git.hush.is/hush/lightwalletd/walletrpc" "github.com/pkg/errors" - "github.com/DenioD/lightwalletd/parser/internal/bytestring" - "github.com/DenioD/lightwalletd/walletrpc" ) type Block struct { @@ -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 diff --git a/parser/block_header.go b/parser/block_header.go index df86f4d..49123b3 100644 --- a/parser/block_header.go +++ b/parser/block_header.go @@ -7,8 +7,8 @@ import ( "log" "math/big" + "git.hush.is/hush/lightwalletd/parser/internal/bytestring" "github.com/pkg/errors" - "github.com/DenioD/lightwalletd/parser/internal/bytestring" ) const ( diff --git a/parser/transaction.go b/parser/transaction.go index 7e6ef05..b8265fa 100644 --- a/parser/transaction.go +++ b/parser/transaction.go @@ -3,9 +3,9 @@ package parser import ( "crypto/sha256" + "git.hush.is/hush/lightwalletd/parser/internal/bytestring" + "git.hush.is/hush/lightwalletd/walletrpc" "github.com/pkg/errors" - "github.com/DenioD/lightwalletd/parser/internal/bytestring" - "github.com/DenioD/lightwalletd/walletrpc" ) type rawTransaction struct { diff --git a/parser/transaction_test.go b/parser/transaction_test.go index b68de4a..e6370ed 100644 --- a/parser/transaction_test.go +++ b/parser/transaction_test.go @@ -9,7 +9,7 @@ import ( "strings" "testing" - "github.com/DenioD/lightwalletd/parser/internal/bytestring" + "git.hush.is/hush/lightwalletd/parser/internal/bytestring" ) // "Human-readable" version of joinSplit struct defined in transaction.go.