|
|
@ -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) { |
|
|
|