Skip to content

Commit fad81b7

Browse files
rpcsrv: add SessionEnabled, MaxIteratorResultItems to getversion
Extend getversion RPC response with RPC server settings (SessionEnabled, MaxIteratorResultItems).Port neo-project/neo-modules#878. Close #3276 Signed-off-by: Ekaterina Pavlova <[email protected]>
1 parent e7a0ded commit fad81b7

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

pkg/neorpc/result/version.go

+34
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ type (
1919
Nonce uint32 `json:"nonce"`
2020
UserAgent string `json:"useragent"`
2121
Protocol Protocol `json:"protocol"`
22+
RPC RPC `json:"rpc"`
23+
}
24+
25+
// RPC represents the RPC server configuration.
26+
RPC struct {
27+
MaxIteratorResultItems int
28+
SessionEnabled bool
2229
}
2330

2431
// Protocol represents network-dependent parameters.
@@ -48,6 +55,12 @@ type (
4855
ValidatorsHistory map[uint32]uint32
4956
}
5057

58+
// rpcMarshallerAux is an auxiliary struct used for RPC JSON marshalling.
59+
rpcMarshallerAux struct {
60+
MaxIteratorResultItems int `json:"maxiteratorresultitems"`
61+
SessionEnabled bool `json:"sessionenabled"`
62+
}
63+
5164
// protocolMarshallerAux is an auxiliary struct used for Protocol JSON marshalling.
5265
protocolMarshallerAux struct {
5366
AddressVersion byte `json:"addressversion"`
@@ -77,6 +90,15 @@ type (
7790
// prefixHardfork is a prefix used for hardfork names in C# node.
7891
const prefixHardfork = "HF_"
7992

93+
// MarshalJSON implements the JSON marshaler interface.
94+
func (r RPC) MarshalJSON() ([]byte, error) {
95+
aux := rpcMarshallerAux{
96+
MaxIteratorResultItems: r.MaxIteratorResultItems,
97+
SessionEnabled: r.SessionEnabled,
98+
}
99+
return json.Marshal(aux)
100+
}
101+
80102
// MarshalJSON implements the JSON marshaler interface.
81103
func (p Protocol) MarshalJSON() ([]byte, error) {
82104
// Keep hardforks sorted by name in the result.
@@ -109,6 +131,18 @@ func (p Protocol) MarshalJSON() ([]byte, error) {
109131
return json.Marshal(aux)
110132
}
111133

134+
// UnmarshalJSON implements the JSON unmarshaler interface.
135+
func (r *RPC) UnmarshalJSON(data []byte) error {
136+
var aux rpcMarshallerAux
137+
err := json.Unmarshal(data, &aux)
138+
if err != nil {
139+
return err
140+
}
141+
r.MaxIteratorResultItems = aux.MaxIteratorResultItems
142+
r.SessionEnabled = aux.SessionEnabled
143+
return nil
144+
}
145+
112146
// UnmarshalJSON implements the JSON unmarshaler interface.
113147
func (p *Protocol) UnmarshalJSON(data []byte) error {
114148
var aux protocolMarshallerAux

pkg/neorpc/result/version_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ func TestVersion_MarshalUnmarshalJSON(t *testing.T) {
4242
"validatorscount": 7,
4343
"hardforks": [{"name": "Aspidochelone", "blockheight": 123}, {"name": "Basilisk", "blockheight": 1234}]
4444
},
45+
"rpc": {
46+
"maxiteratorresultitems": 0,
47+
"sessionenabled": false
48+
},
4549
"tcpport": 10333,
4650
"useragent": "/NEO-GO:0.98.6/",
4751
"wsport": 10334
@@ -69,6 +73,9 @@ func TestVersion_MarshalUnmarshalJSON(t *testing.T) {
6973
WSPort: 10334,
7074
Nonce: 1677922561,
7175
UserAgent: "/NEO-GO:0.98.6/",
76+
RPC: RPC{
77+
MaxIteratorResultItems: 0,
78+
SessionEnabled: false},
7279
Protocol: Protocol{
7380
AddressVersion: 53,
7481
Network: 860833102,

pkg/services/rpcsrv/server.go

+3
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,9 @@ func (s *Server) getVersion(_ params.Params) (any, *neorpc.Error) {
868868
TCPPort: port,
869869
Nonce: s.coreServer.ID(),
870870
UserAgent: s.coreServer.UserAgent,
871+
RPC: result.RPC{
872+
MaxIteratorResultItems: s.config.MaxIteratorResultItems,
873+
SessionEnabled: s.config.SessionEnabled},
871874
Protocol: result.Protocol{
872875
AddressVersion: address.NEO3Prefix,
873876
Network: cfg.Magic,

0 commit comments

Comments
 (0)