Skip to content

Commit

Permalink
Feature: rollup explorer (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
aopoltorzhicky authored May 1, 2024
1 parent 231e8c5 commit 9b961a0
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 10 deletions.
24 changes: 14 additions & 10 deletions cmd/api/handler/responses/rollup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ import (
)

type RollupWithStats struct {
Id uint64 `example:"321" format:"integer" json:"id" swaggertype:"integer"`
Name string `example:"Rollup name" format:"string" json:"name" swaggertype:"string"`
Description string `example:"Long rollup description" format:"string" json:"description,omitempty" swaggertype:"string"`
Website string `example:"https://website.com" format:"string" json:"website,omitempty" swaggertype:"string"`
Twitter string `example:"https://x.com/account" format:"string" json:"twitter,omitempty" swaggertype:"string"`
Github string `example:"https://github.com/account" format:"string" json:"github,omitempty" swaggertype:"string"`
Logo string `example:"https://some_link.com/image.png" format:"string" json:"logo,omitempty" swaggertype:"string"`
Slug string `example:"rollup_slug" format:"string" json:"slug" swaggertype:"string"`
L2Beat string `example:"https://github.com/account" format:"string" json:"l2_beat,omitempty" swaggertype:"string"`
BridgeContract string `example:"https://github.com/account" format:"string" json:"bridge,omitempty" swaggertype:"string"`
Id uint64 `example:"321" format:"integer" json:"id" swaggertype:"integer"`
Name string `example:"Rollup name" format:"string" json:"name" swaggertype:"string"`
Description string `example:"Long rollup description" format:"string" json:"description,omitempty" swaggertype:"string"`
Website string `example:"https://website.com" format:"string" json:"website,omitempty" swaggertype:"string"`
Twitter string `example:"https://x.com/account" format:"string" json:"twitter,omitempty" swaggertype:"string"`
Github string `example:"https://github.com/account" format:"string" json:"github,omitempty" swaggertype:"string"`
Logo string `example:"https://some_link.com/image.png" format:"string" json:"logo,omitempty" swaggertype:"string"`
Slug string `example:"rollup_slug" format:"string" json:"slug" swaggertype:"string"`
L2Beat string `example:"https://l2beat.com/scaling/projects/karak" format:"string" json:"l2_beat,omitempty" swaggertype:"string"`
Explorer string `example:"https://explorer.karak.network/" format:"string" json:"explorer,omitempty" swaggertype:"string"`
BridgeContract string `example:"https://github.com/account" format:"string" json:"bridge,omitempty" swaggertype:"string"`

BlobsCount int64 `example:"2" format:"integer" json:"blobs_count" swaggertype:"integer"`
Size int64 `example:"1000" format:"integer" json:"size" swaggertype:"integer"`
Expand All @@ -40,6 +41,7 @@ func NewRollupWithStats(r storage.RollupWithStats) RollupWithStats {
Website: r.Website,
Logo: r.Logo,
L2Beat: r.L2Beat,
Explorer: r.Explorer,
BridgeContract: r.BridgeContract,
Links: r.Links,
Slug: r.Slug,
Expand All @@ -61,6 +63,7 @@ type Rollup struct {
Logo string `example:"https://some_link.com/image.png" format:"string" json:"logo,omitempty" swaggertype:"string"`
Slug string `example:"rollup_slug" format:"string" json:"slug" swaggertype:"string"`
L2Beat string `example:"https://github.com/account" format:"string" json:"l2_beat,omitempty" swaggertype:"string"`
Explorer string `example:"https://explorer.karak.network/" format:"string" json:"explorer,omitempty" swaggertype:"string"`
BridgeContract string `example:"https://github.com/account" format:"string" json:"bridge,omitempty" swaggertype:"string"`

Links []string `json:"links,omitempty"`
Expand All @@ -78,6 +81,7 @@ func NewRollup(r *storage.Rollup) Rollup {
Slug: r.Slug,
L2Beat: r.L2Beat,
BridgeContract: r.BridgeContract,
Explorer: r.Explorer,
Links: r.Links,
}
}
4 changes: 4 additions & 0 deletions cmd/api/handler/rollup_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type createRollupRequest struct {
Logo string `json:"logo" validate:"omitempty,url"`
L2Beat string `json:"l2_beat" validate:"omitempty,url"`
Bridge string `json:"bridge" validate:"omitempty,url"`
Explorer string `json:"explorer" validate:"omitempty,url"`
Links []string `json:"links" validate:"omitempty,dive,url"`
Providers []rollupProvider `json:"providers" validate:"required,min=1"`
}
Expand Down Expand Up @@ -81,6 +82,7 @@ func (handler RollupAuthHandler) createRollup(ctx context.Context, req *createRo
Twitter: req.Twitter,
Logo: req.Logo,
L2Beat: req.L2Beat,
Explorer: req.Explorer,
BridgeContract: req.Bridge,
Links: req.Links,
Slug: slug.Make(req.Name),
Expand Down Expand Up @@ -141,6 +143,7 @@ type updateRollupRequest struct {
Logo string `json:"logo" validate:"omitempty,url"`
L2Beat string `json:"l2_beat" validate:"omitempty,url"`
Bridge string `json:"bridge" validate:"omitempty,url"`
Explorer string `json:"explorer" validate:"omitempty,url"`
Links []string `json:"links" validate:"omitempty,dive,url"`
Providers []rollupProvider `json:"providers" validate:"omitempty,min=1"`
}
Expand Down Expand Up @@ -178,6 +181,7 @@ func (handler RollupAuthHandler) updateRollup(ctx context.Context, req *updateRo
Twitter: req.Twitter,
Logo: req.Logo,
L2Beat: req.L2Beat,
Explorer: req.Explorer,
BridgeContract: req.Bridge,
Links: req.Links,
}
Expand Down
3 changes: 3 additions & 0 deletions internal/storage/postgres/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,9 @@ func (tx Transaction) UpdateRollup(ctx context.Context, rollup *models.Rollup) e
if rollup.L2Beat != "" {
query = query.Set("l2_beat = ?", rollup.L2Beat)
}
if rollup.Explorer != "" {
query = query.Set("explorer = ?", rollup.Explorer)
}
if rollup.BridgeContract != "" {
query = query.Set("bridge_contract = ?", rollup.BridgeContract)
}
Expand Down
2 changes: 2 additions & 0 deletions internal/storage/postgres/transaction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,7 @@ func (s *TransactionTestSuite) TestSaveUpdateAndDeleteRollup() {
Twitter: "https://x.com/rollup2",
L2Beat: testLink,
BridgeContract: testLink,
Explorer: testLink,
Links: []string{testLink},
}
err = tx.SaveRollup(ctx, rollup)
Expand All @@ -768,6 +769,7 @@ func (s *TransactionTestSuite) TestSaveUpdateAndDeleteRollup() {
s.Require().EqualValues(rollup.GitHub, newRollup.GitHub)
s.Require().EqualValues(rollup.Twitter, newRollup.Twitter)
s.Require().EqualValues(testLink, newRollup.L2Beat)
s.Require().EqualValues(testLink, newRollup.Explorer)
s.Require().EqualValues(testLink, newRollup.BridgeContract)
s.Require().Len(newRollup.Links, 1)

Expand Down
2 changes: 2 additions & 0 deletions internal/storage/rollup.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type Rollup struct {
Slug string `bun:"slug,unique:rollup_slug" comment:"Rollup slug"`
BridgeContract string `bun:"bridge_contract" comment:"Link to bridge contract"`
L2Beat string `bun:"l2_beat" comment:"Link to L2 Beat"`
Explorer string `bun:"explorer" comment:"Link to chain explorer"`
Links []string `bun:"links,array" comment:"Other links to rollup related sites"`

Providers []*RollupProvider `bun:"rel:has-many,join:id=rollup_id"`
Expand All @@ -61,6 +62,7 @@ func (r Rollup) IsEmpty() bool {
r.Logo == "" &&
r.L2Beat == "" &&
r.BridgeContract == "" &&
r.Explorer == "" &&
r.Links == nil
}

Expand Down

0 comments on commit 9b961a0

Please sign in to comment.