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

Method processDestinationLineage

lineage.go:636–670  ·  view source on GitHub ↗

processDestinationLineage processes lineage tracking for the destination balance when it also tracks fund lineage. Uses pre-created destination balances to avoid nested lock acquisition (locks are already held by caller). Parameters: - ctx context.Context: The context for the operation. - txn *mode

(ctx context.Context, txn *model.Transaction, alloc Allocation, mapping *model.LineageMapping, sourceBalance, destinationBalance *model.Balance, destLineageBalances map[string]*destinationLineageInfo, index int)

Source from the content-addressed store, hash-verified

634// Returns:
635// - error: An error if destination lineage processing fails.
636func (l *LedgerForge) processDestinationLineage(ctx context.Context, txn *model.Transaction, alloc Allocation, mapping *model.LineageMapping, sourceBalance, destinationBalance *model.Balance, destLineageBalances map[string]*destinationLineageInfo, index int) error {
637 if destinationBalance == nil || !destinationBalance.TrackFundLineage || destinationBalance.IdentityID == "" {
638 return nil
639 }
640
641 // Use pre-created destination balances (locks already held by caller)
642 if destLineageBalances == nil {
643 return nil
644 }
645
646 destInfo, ok := destLineageBalances[mapping.Provider]
647 if !ok || destInfo == nil {
648 return nil
649 }
650
651 destShadowBalance := destInfo.shadowBalance
652 destAggBalance := destInfo.aggregateBalance
653
654 if err := l.queueReceiveTransaction(ctx, txn, alloc, mapping, sourceBalance, destinationBalance, destShadowBalance, destAggBalance, index); err != nil {
655 return fmt.Errorf("failed to queue receive transaction: %w", err)
656 }
657
658 destMapping := model.LineageMapping{
659 BalanceID: destinationBalance.BalanceID,
660 Provider: mapping.Provider,
661 ShadowBalanceID: destShadowBalance.BalanceID,
662 AggregateBalanceID: destAggBalance.BalanceID,
663 IdentityID: destinationBalance.IdentityID,
664 }
665 if err := l.datasource.UpsertLineageMapping(ctx, destMapping); err != nil {
666 return fmt.Errorf("failed to upsert destination lineage mapping: %w", err)
667 }
668
669 return nil
670}
671
672// getOrCreateDestinationLineageBalances retrieves or creates shadow and aggregate balances for the destination.
673//

Callers 1

processAllocationsMethod · 0.95

Calls 2

UpsertLineageMappingMethod · 0.65

Tested by

no test coverage detected