entity_manager

package
v1.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CharacterLimitAppName        = 50
	CharacterLimitAppDescription = 160
)
View Source
const (
	EntityTypeUser                       = "User"
	EntityTypeTrack                      = "Track"
	EntityTypePlaylist                   = "Playlist"
	EntityTypeDashboardWalletUser        = "DashboardWalletUser"
	EntityTypeUserWallet                 = "UserWallet"
	EntityTypeFollow                     = "Follow"
	EntityTypeSave                       = "Save"
	EntityTypeRepost                     = "Repost"
	EntityTypeSubscription               = "Subscription"
	EntityTypeNotificationSeen           = "NotificationSeen"
	EntityTypeNotification               = "Notification"
	EntityTypePlaylistSeen               = "PlaylistSeen"
	EntityTypeDeveloperApp               = "DeveloperApp"
	EntityTypeGrant                      = "Grant"
	EntityTypeAssociatedWallet           = "AssociatedWallet"
	EntityTypeUserEvent                  = "UserEvent"
	EntityTypeStem                       = "Stem"
	EntityTypeRemix                      = "Remix"
	EntityTypeTrackRoute                 = "TrackRoute"
	EntityTypePlaylistRoute              = "PlaylistRoute"
	EntityTypeTip                        = "Tip"
	EntityTypeComment                    = "Comment"
	EntityTypeCommentReaction            = "CommentReaction"
	EntityTypeCommentReport              = "CommentReport"
	EntityTypeCommentThread              = "CommentThread"
	EntityTypeCommentMention             = "CommentMention"
	EntityTypeMutedUser                  = "MutedUser"
	EntityTypeCommentNotificationSetting = "CommentNotificationSetting"
	EntityTypeEncryptedEmail             = "EncryptedEmail"
	EntityTypeEmailAccess                = "EmailAccess"
	EntityTypeEvent                      = "Event"
	EntityTypeShare                      = "Share"
)

Entity type constants.

View Source
const (
	ActionCreate       = "Create"
	ActionUpdate       = "Update"
	ActionDelete       = "Delete"
	ActionFollow       = "Follow"
	ActionUnfollow     = "Unfollow"
	ActionSave         = "Save"
	ActionUnsave       = "Unsave"
	ActionRepost       = "Repost"
	ActionUnrepost     = "Unrepost"
	ActionVerify       = "Verify"
	ActionSubscribe    = "Subscribe"
	ActionUnsubscribe  = "Unsubscribe"
	ActionView         = "View"
	ActionViewPlaylist = "ViewPlaylist"
	ActionApprove      = "Approve"
	ActionReject       = "Reject"
	ActionDownload     = "Download"
	ActionReact        = "React"
	ActionUnreact      = "Unreact"
	ActionPin          = "Pin"
	ActionUnpin        = "Unpin"
	ActionMute         = "Mute"
	ActionUnmute       = "Unmute"
	ActionAddEmail     = "AddEmail"
	ActionReport       = "Report"
	ActionShare        = "Share"
)

Action constants.

View Source
const (
	PlaylistIDOffset = 400_000
	TrackIDOffset    = 2_000_000
	UserIDOffset     = 3_000_000
	CommentIDOffset  = 4_000_000
)

ID offsets.

View Source
const (
	CharacterLimitUserBio     = 256
	CharacterLimitUserName    = 32
	CharacterLimitHandle      = 30
	CharacterLimitDescription = 2500
	CharacterLimitCommentBody = 400
)

Character limit constants.

View Source
const EntityTypeAny = "*"

EntityTypeAny is a wildcard entity type for handlers that match any entity type for a given action (e.g., social features: Follow matches entity_type "User", Save matches "Track" or "Playlist").

View Source
const MaxRedirectURILength = 2000

MaxRedirectURILength caps each individual URI string length.

View Source
const MaxRedirectURIs = 50

MaxRedirectURIs caps how many redirect URIs a single developer app may register.

Variables

View Source
var GenreAllowlist = map[string]struct{}{
	"Acoustic": {}, "Alternative": {}, "Ambient": {}, "Audiobooks": {}, "Blues": {},
	"Classical": {}, "Comedy": {}, "Country": {}, "Dancehall": {}, "Deep House": {},
	"Devotional": {}, "Disco": {}, "Downtempo": {}, "Drum & Bass": {}, "Dubstep": {},
	"Electro": {}, "Electronic": {}, "Experimental": {}, "Folk": {}, "Funk": {},
	"Future Bass": {}, "Future House": {}, "Glitch Hop": {}, "Hardstyle": {},
	"Hip-Hop/Rap": {}, "House": {}, "Hyperpop": {}, "Jazz": {}, "Jersey Club": {},
	"Jungle": {}, "Kids": {}, "Latin": {}, "Lo-Fi": {}, "Metal": {}, "Moombahton": {},
	"Podcasts": {}, "Pop": {}, "Progressive House": {}, "Punk": {}, "R&B/Soul": {},
	"Reggae": {}, "Rock": {}, "Soundtrack": {}, "Spoken Word": {}, "Tech House": {},
	"Techno": {}, "Trance": {}, "Trap": {}, "Tropical House": {}, "Vaporwave": {}, "World": {},
}

GenreAllowlist is the set of valid genre strings.

View Source
var VerifiedAddress = "0xbeef8E42e8B5964fDD2b7ca8efA0d9aef38AA996"

VerifiedAddress is the wallet address authorized to sign User Verify transactions.

Functions

func CreateTrackRouteID

func CreateTrackRouteID(title, handle string) string

CreateTrackRouteID constructs a track's route_id from an unsanitized title and handle. Resulting route_ids are of the shape `<handle>/<sanitized_title>`.

func GeneratePlaylistSlugAndCollisionID

func GeneratePlaylistSlugAndCollisionID(ctx context.Context, dbtx db.DBTX, ownerID, playlistID int64, name string) (slug, titleSlug string, collisionID int, err error)

GeneratePlaylistSlugAndCollisionID resolves slug collisions for playlist_routes.

func GenerateSlugAndCollisionID

func GenerateSlugAndCollisionID(ctx context.Context, dbtx db.DBTX, ownerID, trackID int64, title string) (slug, titleSlug string, collisionID int, err error)

GenerateSlugAndCollisionID resolves slug collisions for track_routes (task_helpers.generate_slug_and_collision_id).

func IsValidationError

func IsValidationError(err error) bool

IsValidationError returns true if the error is a ValidationError.

func SanitizeSlug

func SanitizeSlug(title string, recordID int64, collisionID int) string

SanitizeSlug converts a title into a URL-friendly slug.

func ValidateAccessConditions

func ValidateAccessConditions(p *Params) error

ValidateAccessConditions checks gating field consistency, matching Only validates when gating fields are present in metadata.

func ValidateBio

func ValidateBio(bio string) error

ValidateBio checks bio length.

func ValidateDescription

func ValidateDescription(desc string) error

ValidateDescription checks description length (used for tracks, playlists).

func ValidateGenre

func ValidateGenre(genre string) error

ValidateGenre checks genre is in the allowlist.

func ValidateHandle

func ValidateHandle(handle string) error

ValidateHandle checks handle format, length, and reserved words.

func ValidateSigner

func ValidateSigner(ctx context.Context, params *Params) error

ValidateSigner checks that the signer is the user's wallet or holds a valid grant from the user. Grants come from either a developer app (auto-approved at creation) or another user wallet acting in manager mode (must be approved by the grantor).

func ValidateUserName

func ValidateUserName(name string) error

ValidateUserName checks name length.

Types

type Dispatcher

type Dispatcher struct {
	// contains filtered or unexported fields
}

Dispatcher routes ManageEntity transactions to registered handlers.

func NewDispatcher

func NewDispatcher(logger *zap.Logger) *Dispatcher

NewDispatcher creates a Dispatcher with no registered handlers.

func (*Dispatcher) Dispatch

func (d *Dispatcher) Dispatch(ctx context.Context, params *Params) error

Dispatch routes a ManageEntity transaction to the appropriate handler. Returns nil if no handler is registered (unhandled entity/action pairs are silently skipped). Returns a ValidationError if the handler rejects the transaction. Returns a non-ValidationError for unexpected failures.

func (*Dispatcher) HandlerCount

func (d *Dispatcher) HandlerCount() int

HandlerCount returns the number of registered handlers.

func (*Dispatcher) HasHandler

func (d *Dispatcher) HasHandler(entityType, action string) bool

HasHandler returns true if a handler is registered for the given entity_type and action.

func (*Dispatcher) Register

func (d *Dispatcher) Register(h Handler)

Register adds a handler for a specific (entity_type, action) pair.

type Handler

type Handler interface {
	EntityType() string
	Action() string
	Handle(ctx context.Context, params *Params) error
}

Handler processes a specific (entity_type, action) pair.

func AssociatedWalletCreate

func AssociatedWalletCreate() Handler

func AssociatedWalletDelete

func AssociatedWalletDelete() Handler

func CommentCreate

func CommentCreate() Handler

CommentCreate returns the Comment Create handler.

func CommentDelete

func CommentDelete() Handler

CommentDelete returns the Comment Delete handler.

func CommentMute

func CommentMute() Handler

CommentMute returns the Comment Mute handler.

func CommentPin

func CommentPin() Handler

CommentPin returns the Comment Pin handler.

func CommentReact

func CommentReact() Handler

CommentReact returns the Comment React handler.

func CommentReport

func CommentReport() Handler

CommentReport returns the Comment Report handler.

func CommentUnmute

func CommentUnmute() Handler

CommentUnmute returns the Comment Unmute handler.

func CommentUnpin

func CommentUnpin() Handler

CommentUnpin returns the Comment Unpin handler.

func CommentUnreact

func CommentUnreact() Handler

CommentUnreact returns the Comment Unreact handler.

func CommentUpdate

func CommentUpdate() Handler

CommentUpdate returns the Comment Update handler.

func DashboardWalletCreate

func DashboardWalletCreate() Handler

func DashboardWalletDelete

func DashboardWalletDelete() Handler

func DeveloperAppCreate

func DeveloperAppCreate() Handler

DeveloperAppCreate returns the DeveloperApp Create handler.

func DeveloperAppDelete

func DeveloperAppDelete() Handler

DeveloperAppDelete returns the DeveloperApp Delete handler.

func DeveloperAppUpdate

func DeveloperAppUpdate() Handler

DeveloperAppUpdate returns the DeveloperApp Update handler.

func EmailAccessUpdate

func EmailAccessUpdate() Handler

func EncryptedEmailCreate

func EncryptedEmailCreate() Handler

func EventCreate

func EventCreate() Handler

func EventDelete

func EventDelete() Handler

func EventUpdate

func EventUpdate() Handler

func Follow

func Follow() Handler

func GrantApprove

func GrantApprove() Handler

GrantApprove returns the Grant Approve handler.

func GrantCreate

func GrantCreate() Handler

GrantCreate returns the Grant Create handler.

func GrantDelete

func GrantDelete() Handler

GrantDelete returns the Grant Delete (Revoke) handler.

func GrantReject

func GrantReject() Handler

GrantReject returns the Grant Reject handler.

func MuteUser

func MuteUser() Handler

MuteUser returns the MuteUser handler.

func NotificationCreate

func NotificationCreate() Handler

NotificationCreate returns the Notification Create handler.

func NotificationView

func NotificationView() Handler

NotificationView returns the Notification View handler.

func PlaylistCreate

func PlaylistCreate() Handler

PlaylistCreate returns the Playlist Create handler.

func PlaylistDelete

func PlaylistDelete() Handler

PlaylistDelete returns the Playlist Delete handler.

func PlaylistSeenView

func PlaylistSeenView() Handler

PlaylistSeenView returns the PlaylistSeen View handler.

func PlaylistUpdate

func PlaylistUpdate() Handler

PlaylistUpdate returns the Playlist Update handler.

func Repost

func Repost() Handler

func Save

func Save() Handler

func Share

func Share() Handler

func Subscribe

func Subscribe() Handler

func TipReaction

func TipReaction() Handler

func TrackCreate

func TrackCreate() Handler

TrackCreate returns the Track Create handler.

func TrackDelete

func TrackDelete() Handler

TrackDelete returns the Track Delete handler.

func TrackDownload

func TrackDownload() Handler

func TrackMute

func TrackMute() Handler

TrackMute returns the Track Mute handler (comment notification settings).

func TrackUnmute

func TrackUnmute() Handler

TrackUnmute returns the Track Unmute handler (comment notification settings).

func TrackUpdate

func TrackUpdate() Handler

TrackUpdate returns the Track Update handler.

func Unfollow

func Unfollow() Handler

func UnmuteUser

func UnmuteUser() Handler

UnmuteUser returns the UnmuteUser handler.

func Unrepost

func Unrepost() Handler

func Unsave

func Unsave() Handler

func Unsubscribe

func Unsubscribe() Handler

func UserCreate

func UserCreate() Handler

UserCreate returns the User Create handler.

func UserUpdate

func UserUpdate() Handler

UserUpdate returns the User Update handler.

func UserVerify

func UserVerify() Handler

UserVerify returns the User Verify handler.

type Params

type Params struct {
	TX          *corev1.ManageEntityLegacy
	UserID      int64
	EntityID    int64
	EntityType  string
	Action      string
	Signer      string
	Metadata    map[string]any
	RawMetadata string
	BlockNumber int64
	BlockTime   time.Time
	BlockHash   string
	TxHash      string
	DBTX        db.DBTX
	Logger      *zap.Logger
}

Params holds all context for processing a single ManageEntity transaction.

func NewParams

func NewParams(tx *corev1.ManageEntityLegacy, blockNumber int64, blockTime time.Time, blockHash, txHash string, dbtx db.DBTX, logger *zap.Logger) *Params

NewParams creates Params from a ManageEntityLegacy proto and block context.

func (*Params) MetadataBool

func (p *Params) MetadataBool(key string) (bool, bool)

MetadataBool returns a bool from parsed metadata.

func (*Params) MetadataBoolOr

func (p *Params) MetadataBoolOr(key string, def bool) bool

MetadataBoolOr returns the bool value or default if the key is absent.

func (*Params) MetadataInt64

func (p *Params) MetadataInt64(key string) (int64, bool)

MetadataInt64 returns an int64 from parsed metadata (supports number and string).

func (*Params) MetadataJSON

func (p *Params) MetadataJSON(key string) (any, bool)

MetadataJSON returns the raw value for a JSONB column (map, slice, etc.). Caller should json.Marshal for DB insertion.

func (*Params) MetadataString

func (p *Params) MetadataString(key string) string

MetadataString returns a string field from parsed metadata, or empty string.

func (*Params) Queries

func (p *Params) Queries() *db.Queries

Queries returns a sqlc Queries handle from the underlying DBTX.

type ValidationError

type ValidationError struct {
	// contains filtered or unexported fields
}

ValidationError indicates a transaction should be skipped (not a fatal indexing error).

func NewValidationError

func NewValidationError(format string, args ...any) *ValidationError

func (*ValidationError) Error

func (e *ValidationError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL