MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / NewLedgerForge

Function NewLedgerForge

ledgerforge.go:121–170  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

119// - *LedgerForge: A pointer to the newly created LedgerForge instance.
120// - error: An error if any of the initialization steps fail.
121func 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.
173func (b *LedgerForge) Close() error {

Calls 12

SendWebhookMethod · 0.95
FetchFunction · 0.92
NewManagerFunction · 0.92
NewTypesenseClientFunction · 0.92
NewHookManagerFunction · 0.92
NewCacheWithClientFunction · 0.92
RegisterWebhookSenderFunction · 0.92
initializeRedisClientsFunction · 0.85
NewBalanceTrackerFunction · 0.85
NewQueueFunction · 0.85
initializeHTTPClientFunction · 0.85