add difficulty to lightdinfo
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user