Skip to content

Commit

Permalink
feature: add root page that lists all rollups (#3)
Browse files Browse the repository at this point in the history
* add svelte routing. add main page that lists all rollups

- needs styling

* styles
  • Loading branch information
steezeburger authored Jan 31, 2024
1 parent 7b75124 commit 2f84bb1
Show file tree
Hide file tree
Showing 17 changed files with 717 additions and 58 deletions.
15 changes: 15 additions & 0 deletions internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func (s *Server) setupRouter() *mux.Router {
limiter := NewLimiter(s.cfg.proxyCount, time.Duration(s.cfg.interval)*time.Minute)
api.Handle("/claim", negroni.New(limiter, negroni.Wrap(s.handleClaim()))).Methods("POST")
api.Handle("/info/{rollupName}", s.handleInfo()).Methods("GET")
api.Handle("/rollups", s.handleRollups()).Methods("GET")

fs := http.FileServer(web.Dist())

Expand Down Expand Up @@ -187,6 +188,20 @@ func (s *Server) handleInfo() http.HandlerFunc {
}
}

// handleRollups returns all deployed rollups
func (s *Server) handleRollups() http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
rollups, err := s.sm.Rollups()
if err != nil {
log.WithError(err).Error("Failed to get rollups")
_ = renderJSON(w, errorResponse{Message: err.Error(), Status: http.StatusInternalServerError}, http.StatusInternalServerError)
return
}

_ = renderJSON(w, rollups, http.StatusOK)
}
}

// txBuilderFromRequest creates and returns a TxBuilder from the request
func (s *Server) txBuilderFromRequest(r *http.Request) (chain.TxBuilder, error) {
claimRequest, err := readClaimRequest(r)
Expand Down
48 changes: 40 additions & 8 deletions internal/store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
)

type RollupStoreManager interface {
Rollups() ([]RollupDoc, error)
FindRollupByName(name string) (RollupDoc, error)
RollupByNameWithPrivate(name string) (RollupDoc, error)
}
Expand Down Expand Up @@ -57,10 +58,10 @@ const (
)

type RollupDoc struct {
ID string `firestore:"id"`
Name string `firestore:"name"`
NetworkID uint32 `firestore:"networkId"`
Status RollupDocumentStatus `firestore:"status"`
ID string `firestore:"id" json:"id"`
Name string `firestore:"name" json:"name"`
NetworkID uint32 `firestore:"networkId" json:"networkId"`
Status RollupDocumentStatus `firestore:"status" json:"status"`

RollupPublicDetails
PrivateDetails RollupPrivateDoc
Expand All @@ -72,10 +73,41 @@ type RollupPrivateDoc struct {
}

type RollupPublicDetails struct {
RollupAccountAddress string `firestore:"rollupAccountAddress"`
RollupAccountPublicKey string `firestore:"rollupAccountPublicKey"`
SequencerAccountAddress string `firestore:"sequencerAccountAddress"`
SequencerAccountPublicKey string `firestore:"sequencerAccountPublicKey"`
RollupAccountAddress string `firestore:"rollupAccountAddress" json:"rollupAccountAddress"`
RollupAccountPublicKey string `firestore:"rollupAccountPublicKey" json:"rollupAccountPublicKey"`
SequencerAccountAddress string `firestore:"sequencerAccountAddress" json:"sequencerAccountAddress"`
SequencerAccountPublicKey string `firestore:"sequencerAccountPublicKey" json:"sequencerAccountPublicKey"`
}

// Rollups queries the store to find all deployed rollups
func (m *Manager) Rollups() ([]RollupDoc, error) {
ctx := context.Background()

iter := m.client.CollectionGroup(m.rollupsCollection).
Where("status", "==", StatusDeployed).
OrderBy("name", firestore.Asc).
Documents(ctx)
defer iter.Stop()

var rollups []RollupDoc
for {
doc, err := iter.Next()
if errors.Is(err, iterator.Done) {
break
}
if err != nil {
return []RollupDoc{}, err
}

var rollup RollupDoc
if err := doc.DataTo(&rollup); err != nil {
return []RollupDoc{}, err
}
rollup.ID = doc.Ref.ID
rollups = append(rollups, rollup)
}

return rollups, nil
}

// FindRollupByName queries the store to find a rollup with the given name
Expand Down
Loading

0 comments on commit 2f84bb1

Please sign in to comment.