address additional comments
This commit is contained in:
parent
aa88bd24a2
commit
692af7e6b9
4 changed files with 53 additions and 2 deletions
|
@ -242,7 +242,7 @@ burned).
|
|||
|
||||
#### `getpeerheights` call
|
||||
|
||||
This method returns the block height and user agent of all connected peers.
|
||||
This method returns the block height and user agent of all connected peers. The block height field may be stale depending on the PingInterval node config and the time since the last ping. Ping behavior may differ between node implementations.
|
||||
|
||||
#### Historic calls
|
||||
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
package result
|
||||
|
||||
type (
|
||||
// GetPeerHeights is the payload for outputting peer heights in `getpeerheights` RPC call.
|
||||
GetPeerHeights struct {
|
||||
PeerHeights PeerHeights `json:"peers"`
|
||||
PeerHeights PeerHeights `json:"connected"`
|
||||
}
|
||||
|
||||
// PeerHeights represents a slice of PeerHeight.
|
||||
PeerHeights []PeerHeight
|
||||
|
||||
// PeerHeight gives the user agent and last known block height of a connected peer.
|
||||
PeerHeight struct {
|
||||
Address string `json:"address"`
|
||||
UserAgent string `json:"useragent"`
|
||||
|
@ -21,6 +24,7 @@ func NewGetPeerHeights() GetPeerHeights {
|
|||
}
|
||||
}
|
||||
|
||||
// AddPeers adds a set of peers to the peer heights slice.
|
||||
func (g *GetPeerHeights) AddPeers(ps []struct {
|
||||
Address string
|
||||
UserAgent string
|
||||
|
|
|
@ -397,6 +397,16 @@ func (c *Client) GetPeers() (*result.GetPeers, error) {
|
|||
return resp, nil
|
||||
}
|
||||
|
||||
// GetPeerHeights returns the last known block height and user agent of all connected peers.
|
||||
func (c *Client) GetPeerHeights() (*result.GetPeerHeights, error) {
|
||||
var resp = &result.GetPeerHeights{}
|
||||
|
||||
if err := c.performRequest("getpeerheights", nil, resp); err != nil {
|
||||
return resp, err
|
||||
}
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
// GetRawMemPool returns a list of unconfirmed transactions in the memory.
|
||||
func (c *Client) GetRawMemPool() ([]util.Uint256, error) {
|
||||
var resp = new([]util.Uint256)
|
||||
|
|
|
@ -594,6 +594,37 @@ var rpcClientTestCases = map[string][]rpcClientTestCase{
|
|||
},
|
||||
},
|
||||
},
|
||||
"getpeerheights": {
|
||||
{
|
||||
name: "positive",
|
||||
invoke: func(c *Client) (any, error) {
|
||||
return c.GetPeerHeights()
|
||||
},
|
||||
serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"connected":[{"useragent":"/NEO-GO:0.106.1/","height":1337}]}}`,
|
||||
result: func(c *Client) any {
|
||||
return &result.GetPeerHeights{
|
||||
PeerHeights: []result.PeerHeight{
|
||||
{
|
||||
UserAgent: "/NEO-GO:0.106.1/",
|
||||
Height: 1337,
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "empty",
|
||||
invoke: func(c *Client) (any, error) {
|
||||
return c.GetPeerHeights()
|
||||
},
|
||||
serverResponse: `{"jsonrpc":"2.0","id":1,"result":{"connected":[]}}`,
|
||||
result: func(c *Client) any {
|
||||
return &result.GetPeerHeights{
|
||||
PeerHeights: []result.PeerHeight{},
|
||||
}
|
||||
},
|
||||
},
|
||||
},
|
||||
"getrawmempool": {
|
||||
{
|
||||
name: "positive",
|
||||
|
@ -1768,6 +1799,12 @@ var rpcClientErrorCases = map[string][]rpcClientErrorCase{
|
|||
return c.GetPeers()
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "getpeerheights_unmarshalling_error",
|
||||
invoke: func(c *Client) (any, error) {
|
||||
return c.GetPeerHeights()
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "getrawmempool_unmarshalling_error",
|
||||
invoke: func(c *Client) (any, error) {
|
||||
|
|
Loading…
Reference in a new issue