Skip to content

Commit

Permalink
Feature: add RPC networks endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky committed Feb 17, 2022
1 parent c795d35 commit e6f296d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
36 changes: 36 additions & 0 deletions node/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,39 @@ type InjectOperationRequest struct {
ChainID string
Async bool
}

// NetworkPointWithURI -
type NetworkPointWithURI struct {
URI string
NetworkPoint
}

// UnmarshalJSON -
func (n *NetworkPointWithURI) UnmarshalJSON(buf []byte) error {
tmp := []interface{}{&n.URI, &n.NetworkPoint}
wantLen := len(tmp)
if err := json.Unmarshal(buf, &tmp); err != nil {
return err
}
if g, e := len(tmp), wantLen; g != e {
return errors.Errorf("wrong number of fields in NetworkPointWithURI: %d != %d", g, e)
}
return nil
}

// NetworkPoint -
type NetworkPoint struct {
Trusted bool `json:"trusted"`
GreylistedUntil string `json:"greylisted_until"`
State struct {
EventKind string `json:"event_kind"`
P2PPeerID string `json:"p2p_peer_id"`
} `json:"state"`
P2PPeerID string `json:"p2p_peer_id"`
LastFailedConnection string `json:"last_failed_connection"`
LastRejectedConnection []string `json:"last_rejected_connection"`
LastEstablishedConnection []string `json:"last_established_connection"`
LastDisconnection []string `json:"last_disconnection"`
LastSeen []string `json:"last_seen"`
LastMiss string `json:"last_miss"`
}
7 changes: 7 additions & 0 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,10 @@ func (rpc *NodeRPC) ContractStorage(block, contract string, output interface{},
err = rpc.get(fmt.Sprintf("chains/main/blocks/%s/context/contracts/%s/storage", block, contract), nil, options, &output)
return
}

// NetworkPoints -
func (rpc *NodeRPC) NetworkPoints(opts ...RequestOption) (output []NetworkPointWithURI, err error) {
options := newRequestOpts(opts...)
err = rpc.get("network/points", nil, options, &output)
return
}

0 comments on commit e6f296d

Please sign in to comment.