Files
CrimsonandGitHub 61cae8af0a chore: Move all CE plugins to own go modules (#780)
* Move all public connectors to ce/plugins

* Update tooling to account for new go modules under ce

* Ensure we test all CE plugins in CI

* Move Dummypay to ce/plugins for simplicity's sake in the generation scripts

* Use versioned pkg/domain in plugins

* Ensure that renovate updates all CE plugins in a single PR when pkg/domain tags are pushed to github

* Ensure Justfile commands work over all CE plugins

* Copy ce plugin go.mods in dev.Dockerfile

* Only add a go.mod for new plugins if they are ce

* Ensure generated generic client structs are named correctly for submodule

* Add coverprofile for each ce plugin

* Add set -e for Justfile for loops over plugins

* Infer go version from flake.nix in connector template tool
2026-07-01 14:53:02 +00:00

59 lines
1.4 KiB
Go

package generic
import (
"fmt"
"strconv"
"strings"
)
// parseAssetUMN parses an asset in UMN format.
// Supports two formats:
// - With precision: "USD/2", "BTC/8", "COIN/6"
// - Without precision: "COIN", "JPY", "TOKEN" (defaults to precision 0)
//
// Returns the currency code and precision.
// This allows the generic connector to accept ANY asset.
func parseAssetUMN(asset string) (string, int, error) {
if asset == "" {
return "", 0, fmt.Errorf("invalid asset format: empty asset")
}
parts := strings.Split(asset, "/")
switch len(parts) {
case 1:
if err := validateCurrencyCode(parts[0], asset); err != nil {
return "", 0, err
}
return parts[0], 0, nil
case 2:
if err := validateCurrencyCode(parts[0], asset); err != nil {
return "", 0, err
}
precision, err := strconv.Atoi(parts[1])
if err != nil {
return "", 0, fmt.Errorf("invalid precision in asset %s: %w", asset, err)
}
if precision < 0 {
return "", 0, fmt.Errorf("invalid precision in asset %s: must be non-negative", asset)
}
return parts[0], precision, nil
default:
return "", 0, fmt.Errorf("invalid asset format: %s (expected CURRENCY or CURRENCY/PRECISION)", asset)
}
}
func validateCurrencyCode(code, asset string) error {
if code == "" {
return fmt.Errorf("invalid asset format: empty currency code")
}
if code != strings.ToUpper(code) {
return fmt.Errorf("invalid asset %s: currency code must be uppercase", asset)
}
return nil
}