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

Method postTransactionActions

transaction.go:333–370  ·  view source on GitHub ↗

postTransactionActions performs post-processing actions for a transaction. It starts a tracing span, queues the transaction and balance data for indexing in dependency order, sends a webhook notification, and processes fund lineage if applicable. Parameters: - ctx context.Context: The context for t

(ctx context.Context, transaction *model.Transaction, sourceBalance, destinationBalance *model.Balance)

Source from the content-addressed store, hash-verified

331// - sourceBalance *model.Balance: The source balance (can be nil for rejected transactions).
332// - destinationBalance *model.Balance: The destination balance (can be nil for rejected transactions).
333func (l *LedgerForge) postTransactionActions(ctx context.Context, transaction *model.Transaction, sourceBalance, destinationBalance *model.Balance) {
334 _, span := tracer.Start(ctx, "Post Transaction Actions")
335 defer span.End()
336 go func() {
337 // Create an index batch to ensure balances are indexed before the transaction
338 batch := search.NewIndexBatch(transaction.TransactionID)
339
340 // Add balances as dependencies (indexed first) if they exist
341 if sourceBalance != nil {
342 batch.AddDependency("balances", sourceBalance.BalanceID, sourceBalance)
343 }
344 if destinationBalance != nil {
345 batch.AddDependency("balances", destinationBalance.BalanceID, destinationBalance)
346 }
347
348 // Set transaction as the primary item (indexed after dependencies)
349 batch.SetPrimary(l.Config().Transaction.IndexQueuePrefix, transaction.TransactionID, transaction)
350
351 // Queue the batch for indexing
352 err := l.queue.queueIndexBatch(batch)
353 if err != nil {
354 span.RecordError(err)
355 notification.NotifyError(err)
356 }
357
358 // Send webhook notification
359 err = l.SendWebhook(NewWebhook{
360 Event: getEventFromStatus(transaction.Status),
361 Payload: transaction,
362 })
363 if err != nil {
364 span.RecordError(err)
365 notification.NotifyError(err)
366 }
367
368 span.AddEvent("Post-transaction actions completed")
369 }()
370}
371
372// validateTxn validates a transaction by checking if its reference has already been used.
373// It starts a tracing span, checks the existence of the transaction reference, and records relevant events and errors.

Callers 2

RejectTransactionMethod · 0.95

Calls 9

AddDependencyMethod · 0.95
SetPrimaryMethod · 0.95
ConfigMethod · 0.95
SendWebhookMethod · 0.95
NewIndexBatchFunction · 0.92
NotifyErrorFunction · 0.92
getEventFromStatusFunction · 0.85
queueIndexBatchMethod · 0.80
StartMethod · 0.45

Tested by

no test coverage detected