mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-29 10:16:45 +00:00

* [NOD-1595] Implement all fields of GetBlockDAGInfo * [NOD-1595] * [NOD-1595] Don't swallow errors in GetDifficultyRatio * [NOD-1595] Change roundingPrecision in GetDifficultyRatio to 2 decimal places
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
package rpchandlers
|
|
|
|
import (
|
|
"github.com/kaspanet/kaspad/app/appmessage"
|
|
"github.com/kaspanet/kaspad/app/rpc/rpccontext"
|
|
"github.com/kaspanet/kaspad/domain/consensus/utils/hashes"
|
|
"github.com/kaspanet/kaspad/infrastructure/network/netadapter/router"
|
|
)
|
|
|
|
// HandleGetBlockDAGInfo handles the respectively named RPC command
|
|
func HandleGetBlockDAGInfo(context *rpccontext.Context, _ *router.Router, _ appmessage.Message) (appmessage.Message, error) {
|
|
params := context.Config.ActiveNetParams
|
|
consensus := context.Domain.Consensus()
|
|
|
|
response := appmessage.NewGetBlockDAGInfoResponseMessage()
|
|
response.NetworkName = params.Name
|
|
|
|
syncInfo, err := consensus.GetSyncInfo()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
response.BlockCount = syncInfo.BlockCount
|
|
response.HeaderCount = syncInfo.HeaderCount
|
|
|
|
tipHashes, err := consensus.Tips()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
response.TipHashes = hashes.ToStrings(tipHashes)
|
|
|
|
virtualInfo, err := consensus.GetVirtualInfo()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
response.VirtualParentHashes = hashes.ToStrings(virtualInfo.ParentHashes)
|
|
response.Difficulty = context.GetDifficultyRatio(virtualInfo.Bits, context.Config.ActiveNetParams)
|
|
response.PastMedianTime = virtualInfo.PastMedianTime
|
|
|
|
return response, nil
|
|
}
|