github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/tools/validatormon/local.go (about)

     1  package main
     2  
     3  import (
     4  	"encoding/json"
     5  	"fmt"
     6  	"io"
     7  	"net/http"
     8  )
     9  
    10  type LocalReader struct{}
    11  
    12  type quorumRes struct {
    13  	Node string
    14  	Qset struct {
    15  		Ledger  int
    16  		Phase   string
    17  		Missing []string
    18  	}
    19  }
    20  
    21  func (r *LocalReader) StatusRead(accountID string) (*Status, error) {
    22  	url := fmt.Sprintf("http://localhost:11626/quorum?node=%s", accountID)
    23  
    24  	res, err := http.Get(url)
    25  	if err != nil {
    26  		return nil, err
    27  	}
    28  	body, err := io.ReadAll(res.Body)
    29  	res.Body.Close()
    30  	if err != nil {
    31  		return nil, err
    32  	}
    33  
    34  	return statusFromJSON(body)
    35  }
    36  
    37  func statusFromJSON(data []byte) (*Status, error) {
    38  	var q quorumRes
    39  	if err := json.Unmarshal(data, &q); err != nil {
    40  		return nil, err
    41  	}
    42  
    43  	return &Status{
    44  		Node:    q.Node,
    45  		Ledger:  q.Qset.Ledger,
    46  		Phase:   q.Qset.Phase,
    47  		Missing: q.Qset.Missing,
    48  	}, nil
    49  }