Skip to content

Commit

Permalink
add node version endpoint (#505)
Browse files Browse the repository at this point in the history
Co-authored-by: Lazy Nina <>
  • Loading branch information
lazynina authored Jul 11, 2023
1 parent 289c1d2 commit c24e48c
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions routes/exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ var (
IsBlacklisted = []byte{1}
)

const NodeVersion = "3.4.4"

const (
// RoutePathAPIBase ...
RoutePathAPIBase = "/api/v1"
Expand All @@ -46,6 +48,8 @@ const (
RoutePathAPINodeInfo = "/api/v1/node-info"
// RoutePathAPIBlock ...
RoutePathAPIBlock = "/api/v1/block"
// RoutePathAPINodeVersion ...
RoutePathAPINodeVersion = "/api/v1/node-version"
)

// APIRoutes returns the routes for the public-facing API.
Expand Down Expand Up @@ -100,6 +104,13 @@ func (fes *APIServer) APIRoutes() []Route {
fes.APIBlock,
PublicAccess,
},
{
"APINodeVersion",
[]string{"GET"},
RoutePathAPINodeVersion,
fes.APINodeVersion,
PublicAccess,
},
}

return APIRoutes
Expand Down Expand Up @@ -1373,6 +1384,21 @@ func (fes *APIServer) APIBlock(ww http.ResponseWriter, rr *http.Request) {
}
}

type APINodeVersionResponse struct {
Version string
}

// APINodeVersion returns the version of the node.
func (fes *APIServer) APINodeVersion(ww http.ResponseWriter, rr *http.Request) {
if err := json.NewEncoder(ww).Encode(&APINodeVersionResponse{
Version: NodeVersion,
}); err != nil {
APIAddError(ww, fmt.Sprintf("APINodeVersion: Problem encoding response "+
"as JSON: %v", err))
return
}
}

// TODO: This is a somewhat redundant version of processTransaction It exists
// because the API needed to cut out the derivation of the public key from the
// user object, among other things.
Expand Down

0 comments on commit c24e48c

Please sign in to comment.