Skip to content

Commit e6f296d

Browse files
Feature: add RPC networks endpoint
1 parent c795d35 commit e6f296d

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

node/data.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,3 +239,39 @@ type InjectOperationRequest struct {
239239
ChainID string
240240
Async bool
241241
}
242+
243+
// NetworkPointWithURI -
244+
type NetworkPointWithURI struct {
245+
URI string
246+
NetworkPoint
247+
}
248+
249+
// UnmarshalJSON -
250+
func (n *NetworkPointWithURI) UnmarshalJSON(buf []byte) error {
251+
tmp := []interface{}{&n.URI, &n.NetworkPoint}
252+
wantLen := len(tmp)
253+
if err := json.Unmarshal(buf, &tmp); err != nil {
254+
return err
255+
}
256+
if g, e := len(tmp), wantLen; g != e {
257+
return errors.Errorf("wrong number of fields in NetworkPointWithURI: %d != %d", g, e)
258+
}
259+
return nil
260+
}
261+
262+
// NetworkPoint -
263+
type NetworkPoint struct {
264+
Trusted bool `json:"trusted"`
265+
GreylistedUntil string `json:"greylisted_until"`
266+
State struct {
267+
EventKind string `json:"event_kind"`
268+
P2PPeerID string `json:"p2p_peer_id"`
269+
} `json:"state"`
270+
P2PPeerID string `json:"p2p_peer_id"`
271+
LastFailedConnection string `json:"last_failed_connection"`
272+
LastRejectedConnection []string `json:"last_rejected_connection"`
273+
LastEstablishedConnection []string `json:"last_established_connection"`
274+
LastDisconnection []string `json:"last_disconnection"`
275+
LastSeen []string `json:"last_seen"`
276+
LastMiss string `json:"last_miss"`
277+
}

node/node.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,10 @@ func (rpc *NodeRPC) ContractStorage(block, contract string, output interface{},
207207
err = rpc.get(fmt.Sprintf("chains/main/blocks/%s/context/contracts/%s/storage", block, contract), nil, options, &output)
208208
return
209209
}
210+
211+
// NetworkPoints -
212+
func (rpc *NodeRPC) NetworkPoints(opts ...RequestOption) (output []NetworkPointWithURI, err error) {
213+
options := newRequestOpts(opts...)
214+
err = rpc.get("network/points", nil, options, &output)
215+
return
216+
}

0 commit comments

Comments
 (0)