-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(api): add epochs api * feat(api): add epoch info api
- Loading branch information
1 parent
93c29f8
commit 6cdfd9c
Showing
7 changed files
with
253 additions
and
180 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package server | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gorilla/mux" | ||
|
||
"github.com/piplabs/story/client/server/utils" | ||
"github.com/piplabs/story/client/x/epochs/keeper" | ||
epochstypes "github.com/piplabs/story/client/x/epochs/types" | ||
) | ||
|
||
func (s *Server) initEpochsRoute() { | ||
s.httpMux.HandleFunc("/epochs/epoch_infos", utils.SimpleWrap(s.aminoCodec, s.GetEpochInfos)) | ||
s.httpMux.HandleFunc("/epochs/epoch_infos/{identifier}", utils.SimpleWrap(s.aminoCodec, s.GetEpochInfo)) | ||
} | ||
|
||
// GetEpochInfos queries running epochInfos. | ||
func (s *Server) GetEpochInfos(r *http.Request) (resp any, err error) { | ||
queryContext, err := s.createQueryContextByHeader(r) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
queryResp, err := keeper.NewQuerier(*s.store.GetEpochsKeeper()).GetEpochInfos(queryContext, &epochstypes.GetEpochInfosRequest{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return queryResp, nil | ||
} | ||
|
||
// GetEpochInfo queries epoch info of specified identifier. | ||
func (s *Server) GetEpochInfo(r *http.Request) (resp any, err error) { | ||
queryContext, err := s.createQueryContextByHeader(r) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
queryResp, err := keeper.NewQuerier(*s.store.GetEpochsKeeper()).GetEpochInfo(queryContext, &epochstypes.GetEpochInfoRequest{ | ||
Identifier: mux.Vars(r)["identifier"], | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return queryResp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.