Documentation
¶
Overview ¶
Package subscriptions manages service subscriptions for transaction and block events. It handles subscriber registration, event notification, and transaction confirmation tracking.
Index ¶
- Variables
- type BlockNotification
- type Config
- type Manager
- func (s *Manager) BlockEvent(blockNum int64, blockId string)
- func (s *Manager) NotifySubscriber(serviceId ServiceId, subject string, data Signer)
- func (s *Manager) SearchTransactionsAfterBlock(blockNum int) (txList []*TransferInfoRecord, err error)
- func (s *Manager) SearchTransactionsBeforeBlock(blockNum int) (txList []*TransferInfoRecord, err error)
- func (s *Manager) SubscriptionEdit(serviceId ServiceId, edit func(subscription *Subscription)) (err error)
- func (s *Manager) SubscriptionGet(serviceId ServiceId) (subscription *Subscription, err error)
- func (s *Manager) TransactionEvent(transactionInfo *types.TransferInfo)
- type Option
- func WithAddressManager(pool *address.Manager) Option
- func WithBlockchainClient(client types.ChainClient) Option
- func WithConfigStorage(storage storage.BinStorage) Option
- func WithGlobalConfig(config types.Config) Option
- func WithSubscribersStorage(storage storage.BinStorage) Option
- func WithTransactionStorage(storage *storage.BadgerHoldStorage) Option
- type ServiceId
- type Signer
- type Subscription
- type TransferInfoRecord
- type TransferNotification
Constants ¶
This section is empty.
Variables ¶
var ( // ErrConfigStorageEmpty is returned when config storage is not configured. ErrConfigStorageEmpty = errors.New("config storage not set") // ErrUnknownTransaction is returned when a transaction is not found. ErrUnknownTransaction = errors.New("unknown transaction") // ErrUnknownServiceId is returned when a service ID is not recognized. ErrUnknownServiceId = errors.New("unknown serviceId") )
Error definitions for subscription operations.
Functions ¶
This section is empty.
Types ¶
type BlockNotification ¶
BlockNotification is the payload sent to subscribers for block events.
type Config ¶
type Config struct {
Debug bool `json:"debug"`
// contains filtered or unexported fields
}
Config holds the subscription manager configuration.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles service subscriptions and event notifications. Tracks transactions, sends notifications to subscribers, and manages confirmation-based event delivery.
func NewManager ¶
NewManager creates a new subscription manager with the specified options. Loads existing subscriptions and starts the event processing loop.
func (*Manager) BlockEvent ¶
BlockEvent handles a new block event from the watchdog. Queues the event for processing in the event loop.
func (*Manager) NotifySubscriber ¶
NotifySubscriber sends a notification to a specific subscriber. Looks up the subscriber by ID and sends the data to their endpoint.
func (*Manager) SearchTransactionsAfterBlock ¶
func (s *Manager) SearchTransactionsAfterBlock(blockNum int) (txList []*TransferInfoRecord, err error)
SearchTransactionsAfterBlock finds unconfirmed transactions in blocks after the given number. Used to track pending confirmation updates.
func (*Manager) SearchTransactionsBeforeBlock ¶
func (s *Manager) SearchTransactionsBeforeBlock(blockNum int) (txList []*TransferInfoRecord, err error)
SearchTransactionsBeforeBlock finds unconfirmed transactions in blocks before the given number. Used to detect transactions that have reached confirmation threshold.
func (*Manager) SubscriptionEdit ¶
func (s *Manager) SubscriptionEdit(serviceId ServiceId, edit func(subscription *Subscription)) (err error)
SubscriptionEdit modifies a subscription using the provided edit function. Persists changes after editing.
func (*Manager) SubscriptionGet ¶
func (s *Manager) SubscriptionGet(serviceId ServiceId) (subscription *Subscription, err error)
SubscriptionGet retrieves a subscription by service ID. Returns ErrUnknownServiceId if not found.
func (*Manager) TransactionEvent ¶
func (s *Manager) TransactionEvent(transactionInfo *types.TransferInfo)
TransactionEvent handles a new transaction event from the watchdog. Queues the event for processing in the event loop.
type Option ¶
Option is a function that configures a Manager.
func WithAddressManager ¶
WithAddressManager sets the address manager for looking up subscribed addresses.
func WithBlockchainClient ¶
func WithBlockchainClient(client types.ChainClient) Option
WithBlockchainClient sets the blockchain client for chain queries and transfers.
func WithConfigStorage ¶
func WithConfigStorage(storage storage.BinStorage) Option
WithConfigStorage sets the storage backend for subscription configuration.
func WithGlobalConfig ¶
WithGlobalConfig sets the global application configuration.
func WithSubscribersStorage ¶
func WithSubscribersStorage(storage storage.BinStorage) Option
WithSubscribersStorage sets the storage backend for subscriber data.
func WithTransactionStorage ¶
func WithTransactionStorage(storage *storage.BadgerHoldStorage) Option
WithTransactionStorage sets the storage backend for transaction records.
type Signer ¶
type Signer interface {
Sign(apiKey string)
}
Signer defines an interface for signing notification payloads.
type Subscription ¶
type Subscription struct {
ServiceName string `json:"serviceName"`
ServiceId ServiceId `json:"serviceId"`
Internal bool `json:"internal,omitempty"`
ApiToken string `json:"apiToken"`
ApiKey string `json:"apiKey"`
EndpointUrl string `json:"eventUrl"`
ReportNewBlock bool `json:"reportNewBlock"`
ReportIncomingTx bool `json:"reportIncomingTx"`
ReportOutgoingTx bool `json:"reportOutgoingTx"`
ReportMainCoin bool `json:"reportMainCoin"`
ReportTokens map[string]bool `json:"reportTokens"`
ReportBalanceChange bool `json:"balanceChange"`
GatherToMaster bool `json:"gatherToMaster"`
MasterList []string `json:"masterList"`
SecuritySignRequests bool `json:"securitySignRequests,omitempty"`
SecuritySignResponse bool `json:"securitySignResponse,omitempty"`
//Reserved for future use
SecurityUseEncryption bool `json:"securityUseEncryption,omitempty"`
// contains filtered or unexported fields
}
Subscription represents a service's subscription configuration. Controls what events to report and where to send notifications.
func NewSubscription ¶
func NewSubscription(serviceId ServiceId, endpointUrl string, fillSettings func(s *Subscription)) *Subscription
NewSubscription creates a new subscription with the given service ID and endpoint URL. The fillSettings function allows customizing subscription settings.
type TransferInfoRecord ¶
type TransferInfoRecord struct {
TxID string `json:"tx_id" badgerhold:"key"`
Timestamp int64 `json:"timestamp"`
BlockNum int `json:"blockNum" badgerhold:"index"`
Ignore bool `json:"ignore"`
Success bool `json:"success"`
Transfer bool `json:"transfer"`
NativeCoin bool `json:"nativeCoin,omitempty"`
Symbol string `json:"symbol,omitempty"`
SmartContract bool `json:"smartContract,omitempty"`
From string `json:"from" badgerhold:"index"`
To string `json:"to" badgerhold:"index"`
Amount *big.Int `json:"amount"`
Token string `json:"token,omitempty"`
TokenSymbol string `json:"tokenSymbol,omitempty"`
Fee *big.Int `json:"fee"`
InPool bool `json:"inPool"`
Confirmed bool `json:"confirmed" badgerhold:"index"`
ChainSpecificData []byte `json:"chainSpecificData,omitempty"`
}
TransferInfoRecord is the persistent storage format for transaction data. Stored in BadgerHold with indexed fields for efficient queries.
type TransferNotification ¶
type TransferNotification struct {
ChainId string `json:"chainId"`
TxID string `json:"tx_id"`
Timestamp int64 `json:"timestamp"`
BlockNum int `json:"blockNum"`
Success bool `json:"success"`
Transfer bool `json:"transfer"`
NativeCoin bool `json:"nativeCoin,omitempty"`
Symbol string `json:"symbol,omitempty"`
SmartContract bool `json:"smartContract,omitempty"`
From string `json:"from"`
To string `json:"to"`
Amount *big.Int `json:"amount"`
Token string `json:"token,omitempty"`
TokenSymbol string `json:"tokenSymbol,omitempty"`
Fee *big.Int `json:"fee"`
InPool bool `json:"inPool"`
Confirmed bool `json:"confirmed"`
Confirmations int `json:"confirmations"`
UserId int64 `json:"userId,omitempty"`
InvoiceId int64 `json:"invoiceId,omitempty"`
Signature string `json:"sign,omitempty"`
}
TransferNotification is the payload sent to subscribers for transaction events. Includes confirmation count, user/invoice IDs, and optional signature for verification.
func (*TransferNotification) Sign ¶
func (n *TransferNotification) Sign(apiKey string)
Sign generates an HMAC-SHA256 signature for the notification using the API key. The signature covers all critical fields to prevent tampering.