diff --git a/cmd/api/docs/swagger.json b/cmd/api/docs/swagger.json index be8dc50b..fdb2a436 100644 --- a/cmd/api/docs/swagger.json +++ b/cmd/api/docs/swagger.json @@ -6152,6 +6152,16 @@ "format": "string", "example": "https://github.com/account" }, + "category": { + "type": "string", + "format": "string", + "example": "nft" + }, + "compression": { + "type": "string", + "format": "string", + "example": "zip" + }, "description": { "type": "string", "format": "string", @@ -6193,6 +6203,11 @@ "format": "string", "example": "Rollup name" }, + "provider": { + "type": "string", + "format": "string", + "example": "name" + }, "slug": { "type": "string", "format": "string", @@ -6208,6 +6223,16 @@ "format": "string", "example": "https://x.com/account" }, + "type": { + "type": "string", + "format": "string", + "example": "settled" + }, + "vm": { + "type": "string", + "format": "string", + "example": "evm" + }, "website": { "type": "string", "format": "string", @@ -6308,6 +6333,16 @@ "format": "string", "example": "https://github.com/account" }, + "category": { + "type": "string", + "format": "string", + "example": "nft" + }, + "compression": { + "type": "string", + "format": "string", + "example": "zip" + }, "description": { "type": "string", "format": "string", @@ -6363,6 +6398,11 @@ "format": "integer", "example": 100 }, + "provider": { + "type": "string", + "format": "string", + "example": "name" + }, "slug": { "type": "string", "format": "string", @@ -6393,6 +6433,16 @@ "format": "string", "example": "https://x.com/account" }, + "type": { + "type": "string", + "format": "string", + "example": "settled" + }, + "vm": { + "type": "string", + "format": "string", + "example": "evm" + }, "website": { "type": "string", "format": "string", @@ -6418,6 +6468,16 @@ "format": "string", "example": "https://github.com/account" }, + "category": { + "type": "string", + "format": "string", + "example": "nft" + }, + "compression": { + "type": "string", + "format": "string", + "example": "zip" + }, "description": { "type": "string", "format": "string", @@ -6479,6 +6539,11 @@ "format": "string", "example": "Rollup name" }, + "provider": { + "type": "string", + "format": "string", + "example": "name" + }, "size": { "type": "integer", "format": "integer", @@ -6504,6 +6569,16 @@ "format": "string", "example": "https://x.com/account" }, + "type": { + "type": "string", + "format": "string", + "example": "settled" + }, + "vm": { + "type": "string", + "format": "string", + "example": "evm" + }, "website": { "type": "string", "format": "string", diff --git a/cmd/api/handler/responses/rollup.go b/cmd/api/handler/responses/rollup.go index 9f5ac4b0..1dd78f49 100644 --- a/cmd/api/handler/responses/rollup.go +++ b/cmd/api/handler/responses/rollup.go @@ -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"` @@ -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), } } @@ -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"` } @@ -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, } } @@ -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"` @@ -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), diff --git a/cmd/api/handler/rollup_auth.go b/cmd/api/handler/rollup_auth.go index 6bfce671..1ce82fc2 100644 --- a/cmd/api/handler/rollup_auth.go +++ b/cmd/api/handler/rollup_auth.go @@ -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" @@ -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"` } @@ -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), } @@ -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"` } @@ -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, } diff --git a/internal/storage/postgres/custom_types.go b/internal/storage/postgres/custom_types.go index 60e99c0b..215bbb0e 100644 --- a/internal/storage/postgres/custom_types.go +++ b/internal/storage/postgres/custom_types.go @@ -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 }) } diff --git a/internal/storage/postgres/transaction.go b/internal/storage/postgres/transaction.go index 98ec4c78..5e2762f0 100644 --- a/internal/storage/postgres/transaction.go +++ b/internal/storage/postgres/transaction.go @@ -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 diff --git a/internal/storage/postgres/transaction_test.go b/internal/storage/postgres/transaction_test.go index 87786c06..a46f62c0 100644 --- a/internal/storage/postgres/transaction_test.go +++ b/internal/storage/postgres/transaction_test.go @@ -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) diff --git a/internal/storage/rollup.go b/internal/storage/rollup.go index 108da1de..33e10124 100644 --- a/internal/storage/rollup.go +++ b/internal/storage/rollup.go @@ -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" @@ -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"` } @@ -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 { diff --git a/internal/storage/types/rolllup.go b/internal/storage/types/rolllup.go new file mode 100644 index 00000000..5d1c2557 --- /dev/null +++ b/internal/storage/types/rolllup.go @@ -0,0 +1,25 @@ +// SPDX-FileCopyrightText: 2024 PK Lab AG +// SPDX-License-Identifier: MIT + +package types + +// swagger:enum RollupCategory +/* + ENUM( + finance, + gaming, + nft + ) +*/ +//go:generate go-enum --marshal --sql --values --names +type RollupCategory string + +// swagger:enum RollupType +/* + ENUM( + sovereign, + settled + ) +*/ +//go:generate go-enum --marshal --sql --values --names +type RollupType string diff --git a/internal/storage/types/rolllup_enum.go b/internal/storage/types/rolllup_enum.go new file mode 100644 index 00000000..eeb7361e --- /dev/null +++ b/internal/storage/types/rolllup_enum.go @@ -0,0 +1,240 @@ +// SPDX-FileCopyrightText: 2024 PK Lab AG +// SPDX-License-Identifier: MIT + +// Code generated by go-enum DO NOT EDIT. +// Version: 0.5.7 +// Revision: bf63e108589bbd2327b13ec2c5da532aad234029 +// Build Date: 2023-07-25T23:27:55Z +// Built By: goreleaser + +package types + +import ( + "database/sql/driver" + "errors" + "fmt" + "strings" +) + +const ( + // RollupCategoryFinance is a RollupCategory of type finance. + RollupCategoryFinance RollupCategory = "finance" + // RollupCategoryGaming is a RollupCategory of type gaming. + RollupCategoryGaming RollupCategory = "gaming" + // RollupCategoryNft is a RollupCategory of type nft. + RollupCategoryNft RollupCategory = "nft" +) + +var ErrInvalidRollupCategory = fmt.Errorf("not a valid RollupCategory, try [%s]", strings.Join(_RollupCategoryNames, ", ")) + +var _RollupCategoryNames = []string{ + string(RollupCategoryFinance), + string(RollupCategoryGaming), + string(RollupCategoryNft), +} + +// RollupCategoryNames returns a list of possible string values of RollupCategory. +func RollupCategoryNames() []string { + tmp := make([]string, len(_RollupCategoryNames)) + copy(tmp, _RollupCategoryNames) + return tmp +} + +// RollupCategoryValues returns a list of the values for RollupCategory +func RollupCategoryValues() []RollupCategory { + return []RollupCategory{ + RollupCategoryFinance, + RollupCategoryGaming, + RollupCategoryNft, + } +} + +// String implements the Stringer interface. +func (x RollupCategory) String() string { + return string(x) +} + +// IsValid provides a quick way to determine if the typed value is +// part of the allowed enumerated values +func (x RollupCategory) IsValid() bool { + _, err := ParseRollupCategory(string(x)) + return err == nil +} + +var _RollupCategoryValue = map[string]RollupCategory{ + "finance": RollupCategoryFinance, + "gaming": RollupCategoryGaming, + "nft": RollupCategoryNft, +} + +// ParseRollupCategory attempts to convert a string to a RollupCategory. +func ParseRollupCategory(name string) (RollupCategory, error) { + if x, ok := _RollupCategoryValue[name]; ok { + return x, nil + } + return RollupCategory(""), fmt.Errorf("%s is %w", name, ErrInvalidRollupCategory) +} + +// MarshalText implements the text marshaller method. +func (x RollupCategory) MarshalText() ([]byte, error) { + return []byte(string(x)), nil +} + +// UnmarshalText implements the text unmarshaller method. +func (x *RollupCategory) UnmarshalText(text []byte) error { + tmp, err := ParseRollupCategory(string(text)) + if err != nil { + return err + } + *x = tmp + return nil +} + +var errRollupCategoryNilPtr = errors.New("value pointer is nil") // one per type for package clashes + +// Scan implements the Scanner interface. +func (x *RollupCategory) Scan(value interface{}) (err error) { + if value == nil { + *x = RollupCategory("") + return + } + + // A wider range of scannable types. + // driver.Value values at the top of the list for expediency + switch v := value.(type) { + case string: + *x, err = ParseRollupCategory(v) + case []byte: + *x, err = ParseRollupCategory(string(v)) + case RollupCategory: + *x = v + case *RollupCategory: + if v == nil { + return errRollupCategoryNilPtr + } + *x = *v + case *string: + if v == nil { + return errRollupCategoryNilPtr + } + *x, err = ParseRollupCategory(*v) + default: + return errors.New("invalid type for RollupCategory") + } + + return +} + +// Value implements the driver Valuer interface. +func (x RollupCategory) Value() (driver.Value, error) { + return x.String(), nil +} + +const ( + // RollupTypeSovereign is a RollupType of type sovereign. + RollupTypeSovereign RollupType = "sovereign" + // RollupTypeSettled is a RollupType of type settled. + RollupTypeSettled RollupType = "settled" +) + +var ErrInvalidRollupType = fmt.Errorf("not a valid RollupType, try [%s]", strings.Join(_RollupTypeNames, ", ")) + +var _RollupTypeNames = []string{ + string(RollupTypeSovereign), + string(RollupTypeSettled), +} + +// RollupTypeNames returns a list of possible string values of RollupType. +func RollupTypeNames() []string { + tmp := make([]string, len(_RollupTypeNames)) + copy(tmp, _RollupTypeNames) + return tmp +} + +// RollupTypeValues returns a list of the values for RollupType +func RollupTypeValues() []RollupType { + return []RollupType{ + RollupTypeSovereign, + RollupTypeSettled, + } +} + +// String implements the Stringer interface. +func (x RollupType) String() string { + return string(x) +} + +// IsValid provides a quick way to determine if the typed value is +// part of the allowed enumerated values +func (x RollupType) IsValid() bool { + _, err := ParseRollupType(string(x)) + return err == nil +} + +var _RollupTypeValue = map[string]RollupType{ + "sovereign": RollupTypeSovereign, + "settled": RollupTypeSettled, +} + +// ParseRollupType attempts to convert a string to a RollupType. +func ParseRollupType(name string) (RollupType, error) { + if x, ok := _RollupTypeValue[name]; ok { + return x, nil + } + return RollupType(""), fmt.Errorf("%s is %w", name, ErrInvalidRollupType) +} + +// MarshalText implements the text marshaller method. +func (x RollupType) MarshalText() ([]byte, error) { + return []byte(string(x)), nil +} + +// UnmarshalText implements the text unmarshaller method. +func (x *RollupType) UnmarshalText(text []byte) error { + tmp, err := ParseRollupType(string(text)) + if err != nil { + return err + } + *x = tmp + return nil +} + +var errRollupTypeNilPtr = errors.New("value pointer is nil") // one per type for package clashes + +// Scan implements the Scanner interface. +func (x *RollupType) Scan(value interface{}) (err error) { + if value == nil { + *x = RollupType("") + return + } + + // A wider range of scannable types. + // driver.Value values at the top of the list for expediency + switch v := value.(type) { + case string: + *x, err = ParseRollupType(v) + case []byte: + *x, err = ParseRollupType(string(v)) + case RollupType: + *x = v + case *RollupType: + if v == nil { + return errRollupTypeNilPtr + } + *x = *v + case *string: + if v == nil { + return errRollupTypeNilPtr + } + *x, err = ParseRollupType(*v) + default: + return errors.New("invalid type for RollupType") + } + + return +} + +// Value implements the driver Valuer interface. +func (x RollupType) Value() (driver.Value, error) { + return x.String(), nil +}