Skip to content
Snippets Groups Projects
Commit f28c5649 authored by Miguel Montes's avatar Miguel Montes
Browse files

Agregado de información de último bloque firmado a nodeStatus

parent efb19800
No related branches found
No related tags found
No related merge requests found
......@@ -253,6 +253,25 @@ func (node *Node) Votes(blockNumber int64) (votes Proposals) {
return
}
func (node *Node) LastBlockSignedBy(address string, upperLimit int64) (blockNumber int64) {
if upperLimit == 0 || !node.IsSealer(address) {
return
}
for i := 0; i < 5; i++ {
snapshot := node.SnapshotAtBlock(upperLimit)
for number, sealer := range snapshot.Recents {
if BytesToHex(sealer[:]) == address {
return int64(number)
}
}
upperLimit = int64(snapshot.Number) - int64((len(snapshot.Recents)))
if upperLimit <= 0 {
return
}
}
return
}
func (node *Node) SealersStatus(blockNumber int64) (status map[string]*SealerStatus) {
if blockNumber == 0 { // Genesis block doesn't have signer
return
......
......@@ -358,17 +358,22 @@ func propose() {
func status() {
nodeStatus := struct {
Enode string `json:"enode"`
Network uint64 `json:"network"`
Genesis string `json:"genesis"`
BFANetwork bool `json:"bfaNetwork"`
BFAGenesis bool `json:"bfaGenesis"`
Accounts map[string]*big.Int `json:"accounts"`
Coinbase string `json:"coinbase"`
IsSealer bool `json:"isSealer"`
IsMining bool `json:"isMining"`
BlockNumber int64 `json:"blockNumber"`
PeerCount uint64 `json:"peerCount"`
Enode string `json:"enode"`
Network uint64 `json:"network"`
Genesis string `json:"genesis"`
BFANetwork bool `json:"bfaNetwork"`
BFAGenesis bool `json:"bfaGenesis"`
Accounts map[string]*big.Int `json:"accounts"`
Coinbase string `json:"coinbase"`
IsSealer bool `json:"isSealer"`
IsMining bool `json:"isMining"`
BlockNumber int64 `json:"blockNumber"`
Time int64 `json:"timestamp"`
DateTime string `json:"datetime"`
LastBlockSigned int64 `json:"lastBlockSigned,omitempty"`
LastTimeSigned int64 `json:"lastTimeSigned,omitempty"`
DateTimeLastBlockSigned string `json:"datetimeLastSigned,omitempty"`
PeerCount uint64 `json:"peerCount"`
}{
Accounts: make(map[string]*big.Int),
}
......@@ -384,8 +389,19 @@ func status() {
}
nodeStatus.Coinbase, _ = node.Coinbase()
nodeStatus.BlockNumber = node.BlockNumber()
header := node.HeaderByNumber(nodeStatus.BlockNumber)
nodeStatus.Time = header.Time.Int64()
nodeStatus.DateTime = time.Unix(nodeStatus.Time, 0).Format("2006-01-02 15:04:05")
nodeStatus.IsSealer = node.IsSealer(bfa.Self)
nodeStatus.IsMining = node.IsMining()
if nodeStatus.IsSealer {
nodeStatus.LastBlockSigned = node.LastBlockSignedBy(nodeStatus.Coinbase, nodeStatus.BlockNumber)
if nodeStatus.LastBlockSigned != 0 {
header := node.HeaderByNumber(nodeStatus.LastBlockSigned)
nodeStatus.LastTimeSigned = header.Time.Int64()
nodeStatus.DateTimeLastBlockSigned = time.Unix(nodeStatus.LastTimeSigned, 0).Format("2006-01-02 15:04:05")
}
}
nodeInfo := node.NodeInfo()
nodeStatus.Enode = nodeInfo.Enode
ethInfo := nodeInfo.Protocols["eth"].(map[string]interface{})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment