NewLedgerForge initializes a new instance of LedgerForge with the provided database datasource. It fetches the configuration, initializes Redis client, balance tracker, queue, and search client. Parameters: - db database.IDataSource: The datasource for database operations. Returns: - *LedgerForge:
(db database.IDataSource)
| 119 | // - *LedgerForge: A pointer to the newly created LedgerForge instance. |
| 120 | // - error: An error if any of the initialization steps fail. |
| 121 | func NewLedgerForge(db database.IDataSource) (*LedgerForge, error) { |
| 122 | configuration, err := config.Fetch() |
| 123 | if err != nil { |
| 124 | return nil, err |
| 125 | } |
| 126 | |
| 127 | redisClient, asynqClient, err := initializeRedisClients(configuration) |
| 128 | if err != nil { |
| 129 | return nil, err |
| 130 | } |
| 131 | |
| 132 | bt := NewBalanceTracker() |
| 133 | hotPairManager := hotpairs.NewManager(redisClient, hotpairs.Config{ |
| 134 | Enabled: configuration.Queue.EnableHotLane, |
| 135 | HotQueueName: configuration.Queue.HotQueueName, |
| 136 | HotPairTTL: configuration.Queue.HotPairTTL, |
| 137 | LockContentionThreshold: configuration.Queue.HotPairLockContentionThreshold, |
| 138 | }) |
| 139 | newQueue := NewQueue(configuration, asynqClient) |
| 140 | newSearch := search.NewTypesenseClient(configuration.TypeSenseKey, []string{configuration.TypeSense.Dns}) |
| 141 | hookManager := hooks.NewHookManager(redisClient, asynqClient) |
| 142 | tokenizer := initializeTokenizationService(configuration) |
| 143 | httpClient := initializeHTTPClient() |
| 144 | |
| 145 | newCache := cache.NewCacheWithClient(redisClient) |
| 146 | |
| 147 | b := &LedgerForge{ |
| 148 | datasource: db, |
| 149 | bt: bt, |
| 150 | queue: newQueue, |
| 151 | redis: redisClient, |
| 152 | asynqClient: asynqClient, |
| 153 | search: newSearch, |
| 154 | tokenizer: tokenizer, |
| 155 | httpClient: httpClient, |
| 156 | Hooks: hookManager, |
| 157 | config: configuration, |
| 158 | cache: newCache, |
| 159 | hotPairs: hotPairManager, |
| 160 | } |
| 161 | |
| 162 | notification.RegisterWebhookSender(func(event string, payload interface{}) error { |
| 163 | return b.SendWebhook(NewWebhook{ |
| 164 | Event: event, |
| 165 | Payload: payload, |
| 166 | }) |
| 167 | }) |
| 168 | |
| 169 | return b, nil |
| 170 | } |
| 171 | |
| 172 | // Close properly closes all connections and resources used by the LedgerForge instance. |
| 173 | func (b *LedgerForge) Close() error { |