@@ -10,16 +10,19 @@ import (
1010
1111 "github.com/ava-labs/gecko/api"
1212 "github.com/ava-labs/gecko/chains"
13+ "github.com/ava-labs/gecko/genesis"
1314 "github.com/ava-labs/gecko/ids"
1415 "github.com/ava-labs/gecko/network"
1516 "github.com/ava-labs/gecko/snow/engine/common"
1617 "github.com/ava-labs/gecko/utils/logging"
18+ "github.com/ava-labs/gecko/version"
1719
1820 cjson "github.com/ava-labs/gecko/utils/json"
1921)
2022
2123// Admin is the API service for node admin management
2224type Admin struct {
25+ version version.Version
2326 nodeID ids.ShortID
2427 networkID uint32
2528 log logging.Logger
@@ -30,12 +33,13 @@ type Admin struct {
3033}
3134
3235// NewService returns a new admin API service
33- func NewService (nodeID ids.ShortID , networkID uint32 , log logging.Logger , chainManager chains.Manager , peers network.Network , httpServer * api.Server ) * common.HTTPHandler {
36+ func NewService (version version. Version , nodeID ids.ShortID , networkID uint32 , log logging.Logger , chainManager chains.Manager , peers network.Network , httpServer * api.Server ) * common.HTTPHandler {
3437 newServer := rpc .NewServer ()
3538 codec := cjson .NewCodec ()
3639 newServer .RegisterCodec (codec , "application/json" )
3740 newServer .RegisterCodec (codec , "application/json;charset=UTF-8" )
3841 newServer .RegisterService (& Admin {
42+ version : version ,
3943 nodeID : nodeID ,
4044 networkID : networkID ,
4145 log : log ,
@@ -46,38 +50,58 @@ func NewService(nodeID ids.ShortID, networkID uint32, log logging.Logger, chainM
4650 return & common.HTTPHandler {Handler : newServer }
4751}
4852
49- // GetNodeIDArgs are the arguments for calling GetNodeID
50- type GetNodeIDArgs struct {}
53+ // GetNodeVersionReply are the results from calling GetNodeVersion
54+ type GetNodeVersionReply struct {
55+ Version string `json:"version"`
56+ }
57+
58+ // GetNodeVersion returns the version this node is running
59+ func (service * Admin ) GetNodeVersion (_ * http.Request , _ * struct {}, reply * GetNodeVersionReply ) error {
60+ service .log .Debug ("Admin: GetNodeVersion called" )
61+
62+ reply .Version = service .version .String ()
63+ return nil
64+ }
5165
5266// GetNodeIDReply are the results from calling GetNodeID
5367type GetNodeIDReply struct {
5468 NodeID ids.ShortID `json:"nodeID"`
5569}
5670
5771// GetNodeID returns the node ID of this node
58- func (service * Admin ) GetNodeID (r * http.Request , args * GetNodeIDArgs , reply * GetNodeIDReply ) error {
72+ func (service * Admin ) GetNodeID (_ * http.Request , _ * struct {} , reply * GetNodeIDReply ) error {
5973 service .log .Debug ("Admin: GetNodeID called" )
6074
6175 reply .NodeID = service .nodeID
6276 return nil
6377}
6478
65- // GetNetworkIDArgs are the arguments for calling GetNetworkID
66- type GetNetworkIDArgs struct {}
67-
6879// GetNetworkIDReply are the results from calling GetNetworkID
6980type GetNetworkIDReply struct {
7081 NetworkID cjson.Uint32 `json:"networkID"`
7182}
7283
7384// GetNetworkID returns the network ID this node is running on
74- func (service * Admin ) GetNetworkID (r * http.Request , args * GetNetworkIDArgs , reply * GetNetworkIDReply ) error {
85+ func (service * Admin ) GetNetworkID (_ * http.Request , _ * struct {} , reply * GetNetworkIDReply ) error {
7586 service .log .Debug ("Admin: GetNetworkID called" )
7687
7788 reply .NetworkID = cjson .Uint32 (service .networkID )
7889 return nil
7990}
8091
92+ // GetNetworkNameReply is the result from calling GetNetworkName
93+ type GetNetworkNameReply struct {
94+ NetworkName string `json:"networkName"`
95+ }
96+
97+ // GetNetworkName returns the network name this node is running on
98+ func (service * Admin ) GetNetworkName (_ * http.Request , _ * struct {}, reply * GetNetworkNameReply ) error {
99+ service .log .Debug ("Admin: GetNetworkName called" )
100+
101+ reply .NetworkName = genesis .NetworkName (service .networkID )
102+ return nil
103+ }
104+
81105// GetBlockchainIDArgs are the arguments for calling GetBlockchainID
82106type GetBlockchainIDArgs struct {
83107 Alias string `json:"alias"`
@@ -89,24 +113,21 @@ type GetBlockchainIDReply struct {
89113}
90114
91115// GetBlockchainID returns the blockchain ID that resolves the alias that was supplied
92- func (service * Admin ) GetBlockchainID (r * http.Request , args * GetBlockchainIDArgs , reply * GetBlockchainIDReply ) error {
116+ func (service * Admin ) GetBlockchainID (_ * http.Request , args * GetBlockchainIDArgs , reply * GetBlockchainIDReply ) error {
93117 service .log .Debug ("Admin: GetBlockchainID called" )
94118
95119 bID , err := service .chainManager .Lookup (args .Alias )
96120 reply .BlockchainID = bID .String ()
97121 return err
98122}
99123
100- // PeersArgs are the arguments for calling Peers
101- type PeersArgs struct {}
102-
103124// PeersReply are the results from calling Peers
104125type PeersReply struct {
105126 Peers []network.PeerID `json:"peers"`
106127}
107128
108129// Peers returns the list of current validators
109- func (service * Admin ) Peers (r * http.Request , args * PeersArgs , reply * PeersReply ) error {
130+ func (service * Admin ) Peers (_ * http.Request , _ * struct {} , reply * PeersReply ) error {
110131 service .log .Debug ("Admin: Peers called" )
111132 reply .Peers = service .networking .Peers ()
112133 return nil
@@ -123,22 +144,19 @@ type StartCPUProfilerReply struct {
123144}
124145
125146// StartCPUProfiler starts a cpu profile writing to the specified file
126- func (service * Admin ) StartCPUProfiler (r * http.Request , args * StartCPUProfilerArgs , reply * StartCPUProfilerReply ) error {
147+ func (service * Admin ) StartCPUProfiler (_ * http.Request , args * StartCPUProfilerArgs , reply * StartCPUProfilerReply ) error {
127148 service .log .Debug ("Admin: StartCPUProfiler called with %s" , args .Filename )
128149 reply .Success = true
129150 return service .performance .StartCPUProfiler (args .Filename )
130151}
131152
132- // StopCPUProfilerArgs are the arguments for calling StopCPUProfiler
133- type StopCPUProfilerArgs struct {}
134-
135153// StopCPUProfilerReply are the results from calling StopCPUProfiler
136154type StopCPUProfilerReply struct {
137155 Success bool `json:"success"`
138156}
139157
140158// StopCPUProfiler stops the cpu profile
141- func (service * Admin ) StopCPUProfiler (r * http.Request , args * StopCPUProfilerArgs , reply * StopCPUProfilerReply ) error {
159+ func (service * Admin ) StopCPUProfiler (_ * http.Request , _ * struct {} , reply * StopCPUProfilerReply ) error {
142160 service .log .Debug ("Admin: StopCPUProfiler called" )
143161 reply .Success = true
144162 return service .performance .StopCPUProfiler ()
@@ -155,7 +173,7 @@ type MemoryProfileReply struct {
155173}
156174
157175// MemoryProfile runs a memory profile writing to the specified file
158- func (service * Admin ) MemoryProfile (r * http.Request , args * MemoryProfileArgs , reply * MemoryProfileReply ) error {
176+ func (service * Admin ) MemoryProfile (_ * http.Request , args * MemoryProfileArgs , reply * MemoryProfileReply ) error {
159177 service .log .Debug ("Admin: MemoryProfile called with %s" , args .Filename )
160178 reply .Success = true
161179 return service .performance .MemoryProfile (args .Filename )
@@ -172,7 +190,7 @@ type LockProfileReply struct {
172190}
173191
174192// LockProfile runs a mutex profile writing to the specified file
175- func (service * Admin ) LockProfile (r * http.Request , args * LockProfileArgs , reply * LockProfileReply ) error {
193+ func (service * Admin ) LockProfile (_ * http.Request , args * LockProfileArgs , reply * LockProfileReply ) error {
176194 service .log .Debug ("Admin: LockProfile called with %s" , args .Filename )
177195 reply .Success = true
178196 return service .performance .LockProfile (args .Filename )
@@ -190,7 +208,7 @@ type AliasReply struct {
190208}
191209
192210// Alias attempts to alias an HTTP endpoint to a new name
193- func (service * Admin ) Alias (r * http.Request , args * AliasArgs , reply * AliasReply ) error {
211+ func (service * Admin ) Alias (_ * http.Request , args * AliasArgs , reply * AliasReply ) error {
194212 service .log .Debug ("Admin: Alias called with URL: %s, Alias: %s" , args .Endpoint , args .Alias )
195213 reply .Success = true
196214 return service .httpServer .AddAliasesWithReadLock (args .Endpoint , args .Alias )
@@ -233,7 +251,7 @@ type StacktraceReply struct {
233251}
234252
235253// Stacktrace returns the current global stacktrace
236- func (service * Admin ) Stacktrace (_ * http.Request , _ * StacktraceArgs , reply * StacktraceReply ) error {
254+ func (service * Admin ) Stacktrace (_ * http.Request , _ * struct {} , reply * StacktraceReply ) error {
237255 reply .Stacktrace = logging.Stacktrace {Global : true }.String ()
238256 return nil
239257}
0 commit comments