Skip to content

Commit

Permalink
Feature: add rollup columns (#284)
Browse files Browse the repository at this point in the history
* Feature: add rollup columns

* Add vm column

* Fix: gaming type

* API docs
  • Loading branch information
aopoltorzhicky authored Sep 16, 2024
1 parent 7b722b1 commit 1a54661
Show file tree
Hide file tree
Showing 9 changed files with 453 additions and 14 deletions.
75 changes: 75 additions & 0 deletions cmd/api/docs/swagger.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions cmd/api/handler/responses/rollup.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ type RollupWithStats struct {
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"`
Stack string `example:"op_stack" format:"string" json:"stack,omitempty" swaggertype:"string"`
Type string `example:"settled" format:"string" json:"type,omitempty" swaggertype:"string"`
Category string `example:"nft" format:"string" json:"category,omitempty" swaggertype:"string"`
VM string `example:"evm" format:"string" json:"vm,omitempty" swaggertype:"string"`
Provider string `example:"name" format:"string" json:"provider,omitempty" swaggertype:"string"`
Compression string `example:"zip" format:"string" json:"compression,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 Down Expand Up @@ -58,6 +63,11 @@ func NewRollupWithStats(r storage.RollupWithStats) RollupWithStats {
FeePct: r.FeePct,
LastAction: r.LastActionTime,
FirstAction: r.FirstActionTime,
Compression: r.Compression,
Category: r.Category.String(),
Type: r.Type.String(),
Provider: r.Provider,
VM: r.VM,
Fee: r.Fee.StringFixed(0),
}
}
Expand All @@ -75,6 +85,11 @@ type Rollup struct {
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"`
Stack string `example:"op_stack" format:"string" json:"stack,omitempty" swaggertype:"string"`
Type string `example:"settled" format:"string" json:"type,omitempty" swaggertype:"string"`
Category string `example:"nft" format:"string" json:"category,omitempty" swaggertype:"string"`
Provider string `example:"name" format:"string" json:"provider,omitempty" swaggertype:"string"`
Compression string `example:"zip" format:"string" json:"compression,omitempty" swaggertype:"string"`
VM string `example:"evm" format:"string" json:"vm,omitempty" swaggertype:"string"`

Links []string `json:"links,omitempty"`
}
Expand All @@ -94,6 +109,11 @@ func NewRollup(r *storage.Rollup) Rollup {
Stack: r.Stack,
Explorer: r.Explorer,
Links: r.Links,
Compression: r.Compression,
Category: r.Category.String(),
Type: r.Type.String(),
Provider: r.Provider,
VM: r.VM,
}
}

Expand Down Expand Up @@ -129,6 +149,11 @@ type RollupWithDayStats struct {
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"`
Stack string `example:"op_stack" format:"string" json:"stack,omitempty" swaggertype:"string"`
Type string `example:"settled" format:"string" json:"type,omitempty" swaggertype:"string"`
Category string `example:"nft" format:"string" json:"category,omitempty" swaggertype:"string"`
Provider string `example:"name" format:"string" json:"provider,omitempty" swaggertype:"string"`
Compression string `example:"zip" format:"string" json:"compression,omitempty" swaggertype:"string"`
VM string `example:"evm" format:"string" json:"vm,omitempty" swaggertype:"string"`

AvgSize int64 `example:"100" format:"integer" json:"avg_size" swaggertype:"integer"`
BlobsCount int64 `example:"100" format:"integer" json:"blobs_count" swaggertype:"integer"`
Expand All @@ -155,6 +180,11 @@ func NewRollupWithDayStats(r storage.RollupWithDayStats) RollupWithDayStats {
Explorer: r.Explorer,
BridgeContract: r.BridgeContract,
Stack: r.Stack,
Compression: r.Compression,
Category: r.Category.String(),
Type: r.Type.String(),
Provider: r.Provider,
VM: r.VM,
Slug: r.Slug,
BlobsCount: r.BlobsCount,
AvgSize: int64(r.AvgSize),
Expand Down
21 changes: 21 additions & 0 deletions cmd/api/handler/rollup_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/celenium-io/celestia-indexer/internal/storage"
"github.com/celenium-io/celestia-indexer/internal/storage/postgres"
enums "github.com/celenium-io/celestia-indexer/internal/storage/types"
"github.com/celenium-io/celestia-indexer/pkg/types"
sdk "github.com/dipdup-net/indexer-sdk/pkg/storage"
"github.com/gosimple/slug"
Expand Down Expand Up @@ -48,6 +49,11 @@ type createRollupRequest struct {
Explorer string `json:"explorer" validate:"omitempty,url"`
Stack string `json:"stack" validate:"omitempty"`
Links []string `json:"links" validate:"omitempty,dive,url"`
Category string `json:"category" validate:"omitempty,oneof=nft gaming finance"`
Type string `json:"type" validate:"omitempty,oneof=settled sovereign"`
Compression string `json:"compression" validate:"omitempty"`
VM string `json:"vm" validate:"omitempty"`
Provider string `json:"provider" validate:"omitempty"`
Providers []rollupProvider `json:"providers" validate:"required,min=1"`
}

Expand Down Expand Up @@ -87,6 +93,11 @@ func (handler RollupAuthHandler) createRollup(ctx context.Context, req *createRo
BridgeContract: req.Bridge,
Stack: req.Stack,
Links: req.Links,
Compression: req.Compression,
Provider: req.Provider,
VM: req.VM,
Type: enums.RollupType(req.Type),
Category: enums.RollupCategory(req.Category),
Slug: slug.Make(req.Name),
}

Expand Down Expand Up @@ -151,6 +162,11 @@ type updateRollupRequest struct {
Bridge string `json:"bridge" validate:"omitempty,eth_addr"`
Explorer string `json:"explorer" validate:"omitempty,url"`
Stack string `json:"stack" validate:"omitempty"`
Category string `json:"category" validate:"omitempty,oneof=nft gaming finance"`
Type string `json:"type" validate:"omitempty,oneof=settled sovereign"`
Compression string `json:"compression" validate:"omitempty"`
Provider string `json:"provider" validate:"omitempty"`
VM string `json:"vm" validate:"omitempty"`
Links []string `json:"links" validate:"omitempty,dive,url"`
Providers []rollupProvider `json:"providers" validate:"omitempty,min=1"`
}
Expand Down Expand Up @@ -191,6 +207,11 @@ func (handler RollupAuthHandler) updateRollup(ctx context.Context, req *updateRo
Explorer: req.Explorer,
BridgeContract: req.Bridge,
Stack: req.Stack,
Compression: req.Compression,
Provider: req.Provider,
VM: req.VM,
Type: enums.RollupType(req.Type),
Category: enums.RollupCategory(req.Category),
Links: req.Links,
}

Expand Down
20 changes: 20 additions & 0 deletions internal/storage/postgres/custom_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,26 @@ func createTypes(ctx context.Context, conn *database.Bun) error {
); err != nil {
return err
}

if _, err := tx.ExecContext(
ctx,
createTypeQuery,
"rollup_type",
bun.Safe("rollup_type"),
bun.In(types.RollupTypeValues()),
); err != nil {
return err
}

if _, err := tx.ExecContext(
ctx,
createTypeQuery,
"rollup_category",
bun.Safe("rollup_category"),
bun.In(types.RollupCategoryValues()),
); err != nil {
return err
}
return nil
})
}
15 changes: 15 additions & 0 deletions internal/storage/postgres/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,21 @@ func (tx Transaction) UpdateRollup(ctx context.Context, rollup *models.Rollup) e
if rollup.Links != nil {
query = query.Set("links = ?", pq.Array(rollup.Links))
}
if rollup.Type != "" {
query = query.Set("type = ?", rollup.Type)
}
if rollup.Category != "" {
query = query.Set("category = ?", rollup.Category)
}
if rollup.Provider != "" {
query = query.Set("provider = ?", rollup.Provider)
}
if rollup.Compression != "" {
query = query.Set("compression = ?", rollup.Compression)
}
if rollup.VM != "" {
query = query.Set("vm = ?", rollup.VM)
}

_, err := query.Exec(ctx)
return err
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 @@ -748,6 +748,8 @@ func (s *TransactionTestSuite) TestSaveUpdateAndDeleteRollup() {
BridgeContract: testLink,
Explorer: testLink,
Stack: "stack",
Type: types.RollupTypeSettled,
Category: types.RollupCategoryFinance,
Links: []string{testLink},
}
err = tx.SaveRollup(ctx, rollup)
Expand Down
39 changes: 25 additions & 14 deletions internal/storage/rollup.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"time"

"github.com/celenium-io/celestia-indexer/internal/storage/types"
sdk "github.com/dipdup-net/indexer-sdk/pkg/storage"
"github.com/shopspring/decimal"
"github.com/uptrace/bun"
Expand All @@ -33,19 +34,24 @@ type IRollup interface {
type Rollup struct {
bun.BaseModel `bun:"rollup" comment:"Table with rollups."`

Id uint64 `bun:"id,pk,autoincrement" comment:"Unique internal identity"`
Name string `bun:"name" comment:"Rollup's name"`
Description string `bun:"description" comment:"Rollup's description"`
Website string `bun:"website" comment:"Website"`
GitHub string `bun:"github" comment:"Github repository"`
Twitter string `bun:"twitter" comment:"Twitter account"`
Logo string `bun:"logo" comment:"Link to rollup logo"`
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"`
Stack string `bun:"stack" comment:"Underlaying stack"`
Links []string `bun:"links,array" comment:"Other links to rollup related sites"`
Id uint64 `bun:"id,pk,autoincrement" comment:"Unique internal identity"`
Name string `bun:"name" comment:"Rollup's name"`
Description string `bun:"description" comment:"Rollup's description"`
Website string `bun:"website" comment:"Website"`
GitHub string `bun:"github" comment:"Github repository"`
Twitter string `bun:"twitter" comment:"Twitter account"`
Logo string `bun:"logo" comment:"Link to rollup logo"`
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"`
Stack string `bun:"stack" comment:"Underlaying stack"`
Compression string `bun:"compression" comment:"Compression"`
Provider string `bun:"provider" comment:"RaaS provider"`
Type types.RollupType `bun:"type,type:rollup_type" comment:"Type of rollup: settled or sovereign"`
Category types.RollupCategory `bun:"category,type:rollup_category" comment:"Category of rollup"`
VM string `bun:"vm" comment:"Virtual machine"`
Links []string `bun:"links,array" comment:"Other links to rollup related sites"`

Providers []*RollupProvider `bun:"rel:has-many,join:id=rollup_id"`
}
Expand All @@ -66,7 +72,12 @@ func (r Rollup) IsEmpty() bool {
r.BridgeContract == "" &&
r.Explorer == "" &&
r.Stack == "" &&
r.Links == nil
r.Links == nil &&
r.Category == "" &&
r.Compression == "" &&
r.Provider == "" &&
r.Type == "" &&
r.VM == ""
}

type RollupWithStats struct {
Expand Down
Loading

0 comments on commit 1a54661

Please sign in to comment.