validateLineageProvider checks if the specified provider exists on the source balance. If the source tracks fund lineage but doesn't have the specified provider, returns empty string (provider should be ignored). If the source doesn't track lineage (e.g., @world), any provider is valid. Parameters:
(ctx context.Context, provider string, sourceBalance *model.Balance)
| 199 | // - string: The validated provider name (empty if invalid/should be ignored). |
| 200 | // - error: An error if validation fails (database errors only, not for invalid providers). |
| 201 | func (l *LedgerForge) validateLineageProvider(ctx context.Context, provider string, sourceBalance *model.Balance) (string, error) { |
| 202 | if provider == "" { |
| 203 | return "", nil |
| 204 | } |
| 205 | |
| 206 | // Source is nil or doesn't track lineage - provider is valid |
| 207 | if sourceBalance == nil || !sourceBalance.TrackFundLineage { |
| 208 | return provider, nil |
| 209 | } |
| 210 | |
| 211 | // Source tracks lineage - verify provider exists |
| 212 | mapping, err := l.datasource.GetLineageMappingByProvider(ctx, sourceBalance.BalanceID, provider) |
| 213 | if err != nil { |
| 214 | return "", fmt.Errorf("failed to validate provider on source: %w", err) |
| 215 | } |
| 216 | |
| 217 | if mapping == nil { |
| 218 | logrus.Warnf("lineage provider validation: provider %q does not exist on source balance %s - ignoring provider", |
| 219 | provider, sourceBalance.BalanceID) |
| 220 | return "", nil |
| 221 | } |
| 222 | |
| 223 | return provider, nil |
| 224 | } |
| 225 | |
| 226 | // processLineageCredit processes a credit transaction for fund lineage tracking. |
| 227 | // It creates shadow balances and queues a shadow transaction to track the provider's funds. |