Documentation
¶
Index ¶
- Constants
- func CheckWalletServiceHealth() (bool, error)
- func InitDailyFreeSubscriptionRenewal()
- func ScheduleBatchUpdateAfter(delay time.Duration)
- type StorageInfo
- type SubscriptionManager
- func (m *SubscriptionManager) AllocateBitcoinAddressesForExistingUsers() error
- func (m *SubscriptionManager) BatchUpdateAllSubscriptionEvents() error
- func (m *SubscriptionManager) BatchUpdateAllSubscriptionEventsWithContext(ctx context.Context) error
- func (m *SubscriptionManager) CheckAndUpdateSubscriptionEvent(event *nostr.Event) (*nostr.Event, error)
- func (m *SubscriptionManager) CheckStorageAvailability(npub string, requestedBytes int64) error
- func (m *SubscriptionManager) InitializeSubscriber(npub string, mode string) error
- func (m *SubscriptionManager) ProcessPayment(npub string, transactionID string, amountSats int64) error
- func (m *SubscriptionManager) RefreshExpiredFreeTierSubscriptions() error
- func (m *SubscriptionManager) RequestNewAddresses(count int) error
- func (m *SubscriptionManager) UpdateNpubSubscriptionEvent(npub, tierName string) error
- func (m *SubscriptionManager) UpdateStorageUsage(npub string, newBytes int64) error
- func (m *SubscriptionManager) UpdateUserSubscriptionFromDatabase(npub string) error
Constants ¶
const ( AddressStatusAvailable = "available" AddressStatusAllocated = "allocated" AddressStatusUsed = "used" )
Address status constants
Variables ¶
This section is empty.
Functions ¶
func CheckWalletServiceHealth ¶
CheckWalletServiceHealth checks if the wallet service is reachable
func InitDailyFreeSubscriptionRenewal ¶
func InitDailyFreeSubscriptionRenewal()
InitDailyFreeSubscriptionRenewal sets up a daily job to refresh expired free tier subscriptions This should be called once when the application starts
func ScheduleBatchUpdateAfter ¶
ScheduleBatchUpdateAfter schedules a batch update of all kind 11888 events after the specified delay. If called multiple times, it cancels any previous scheduled update and restarts the timer with a new delay (sliding window approach).
Types ¶
type StorageInfo ¶
type StorageInfo struct { UsedBytes int64 // Current bytes used by the subscriber TotalBytes int64 // Total bytes allocated to the subscriber (0 for unlimited) IsUnlimited bool // True if storage is unlimited UpdatedAt time.Time // Last time storage information was updated }
StorageInfo tracks current storage usage information for a subscriber
type SubscriptionManager ¶
type SubscriptionManager struct {
// contains filtered or unexported fields
}
SubscriptionManager handles all subscription-related operations through NIP-88 events
func GetGlobalManager ¶
func GetGlobalManager() *SubscriptionManager
GetGlobalManager returns the global subscription manager instance Returns nil if not initialized
func InitGlobalManager ¶
func InitGlobalManager( store stores.Store, relayPrivKey *btcec.PrivateKey, relayDHTKey string, tiers []types.SubscriptionTier, ) *SubscriptionManager
InitGlobalManager initializes the global subscription manager instance
func NewSubscriptionManager ¶
func NewSubscriptionManager( store stores.Store, relayPrivKey *btcec.PrivateKey, relayDHTKey string, tiers []types.SubscriptionTier, ) *SubscriptionManager
NewSubscriptionManager creates and initializes a new subscription manager
func (*SubscriptionManager) AllocateBitcoinAddressesForExistingUsers ¶
func (m *SubscriptionManager) AllocateBitcoinAddressesForExistingUsers() error
AllocateBitcoinAddressesForExistingUsers allocates Bitcoin addresses for users who don't have them
func (*SubscriptionManager) BatchUpdateAllSubscriptionEvents ¶
func (m *SubscriptionManager) BatchUpdateAllSubscriptionEvents() error
BatchUpdateAllSubscriptionEvents processes all kind 11888 events in batches to update storage allocations after allowed users settings have changed
func (*SubscriptionManager) BatchUpdateAllSubscriptionEventsWithContext ¶
func (m *SubscriptionManager) BatchUpdateAllSubscriptionEventsWithContext(ctx context.Context) error
BatchUpdateAllSubscriptionEventsWithContext processes all kind 11888 events in batches with context support for cancellation
func (*SubscriptionManager) CheckAndUpdateSubscriptionEvent ¶
func (m *SubscriptionManager) CheckAndUpdateSubscriptionEvent(event *nostr.Event) (*nostr.Event, error)
CheckAndUpdateSubscriptionEvent checks if a kind 11888 event needs to be updated based on current allowed users settings and updates it if necessary
func (*SubscriptionManager) CheckStorageAvailability ¶
func (m *SubscriptionManager) CheckStorageAvailability(npub string, requestedBytes int64) error
CheckStorageAvailability checks if a subscriber has enough available storage for a given number of bytes. It retrieves storage data from the user's NIP-88 event and validates against their current usage and limits.
func (*SubscriptionManager) InitializeSubscriber ¶
func (m *SubscriptionManager) InitializeSubscriber(npub string, mode string) error
InitializeSubscriber creates a new subscriber or retrieves an existing one and creates their initial NIP-88 event.
func (*SubscriptionManager) ProcessPayment ¶
func (m *SubscriptionManager) ProcessPayment( npub string, transactionID string, amountSats int64, ) error
ProcessPayment handles a new subscription payment by updating the NIP-88 event and other relevant data
func (*SubscriptionManager) RefreshExpiredFreeTierSubscriptions ¶
func (m *SubscriptionManager) RefreshExpiredFreeTierSubscriptions() error
RefreshExpiredFreeTierSubscriptions finds and refreshes all expired free tier subscriptions
func (*SubscriptionManager) RequestNewAddresses ¶
func (m *SubscriptionManager) RequestNewAddresses(count int) error
RequestNewAddresses sends a request to the wallet to generate new addresses
func (*SubscriptionManager) UpdateNpubSubscriptionEvent ¶
func (m *SubscriptionManager) UpdateNpubSubscriptionEvent(npub, tierName string) error
UpdateNpubSubscriptionEvent updates the kind 11888 event for a specific npub with new tier information This is called when access control lists are updated and we need to sync the kind 11888 events
func (*SubscriptionManager) UpdateStorageUsage ¶
func (m *SubscriptionManager) UpdateStorageUsage(npub string, newBytes int64) error
UpdateStorageUsage updates the storage usage for a subscriber by modifying the relevant NIP-88 event This function logs errors but does not fail operations to maintain development flow
func (*SubscriptionManager) UpdateUserSubscriptionFromDatabase ¶
func (m *SubscriptionManager) UpdateUserSubscriptionFromDatabase(npub string) error
UpdateUserSubscriptionFromDatabase updates a user's kind 11888 event by looking up their tier from the database This follows the correct flow: DB lookup -> config lookup -> update event