Documentation
¶
Overview ¶
Package config is the single source of application configuration. It reads the environment once at startup, validates it, and hands back a typed Config that the rest of the platform passes around instead of touching os.Getenv directly.
New is the only entry point. It loads every variable, fails fast if a required one is missing, applies defaults for the optional ones, and validates the Stellar material — treasury, admin, and server secret keys, the USDC issuer, and the contract ID are parsed through the SDK so a malformed value is caught at boot rather than on first use. The network passphrase is derived from the environment: development runs against the test network, everything else against the public network.
Layout ¶
Config is composed of one sub-config per concern — Postgres, Redis, Server, Stellar, Payments, Mobile, and Auth — and Payments nests one config per provider. Sub-configs carry the small helpers that turn raw fields into usable values: PostgresConfig.DSN, RedisConfig.Addr, ServerConfig's listen addresses, StellarConfig.NewRpcClient, and so on. Some values are shared or derived rather than read twice — the MoneyGram anchor reuses the Stellar network passphrase and falls back to the global USDC issuer when its own is unset.
Provider configuration ¶
MoneyGram is the default cash-pickup anchor and is always wired, so it has its own Validate to confirm the anchor fields are present. Its REST API credentials (for FX rates) are optional; HasRESTCredentials reports whether they are populated, letting callers fall back to another provider's rates when they are not.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AfricasTalkingConfig ¶
type AfricasTalkingConfig struct {
Username string
APIKey string
BaseURL string
SenderID string // from AT_SENDER_ID (alphanumeric or shortcode)
Shortcode string // from AT_SHORTCODE (numeric shortcode)
// HTTPTimeout bounds a single SMS send attempt. From AT_HTTP_TIMEOUT
// (seconds); zero when unset, leaving the adapter to apply its default.
HTTPTimeout time.Duration
}
AfricasTalkingConfig holds all SMS/USSD-related configuration for Africa's Talking
func (*AfricasTalkingConfig) ResolveSenderID ¶
func (c *AfricasTalkingConfig) ResolveSenderID() string
ResolveSenderID returns the sender ID to use for SMS. Priority: SenderID > Shortcode > "" (AT defaults to AFRICASTKNG).
type AuthConfig ¶
type Config ¶
type Config struct {
Postgres PostgresConfig
Redis RedisConfig
Server ServerConfig
Stellar StellarConfig
Payments PaymentsConfig
Mobile MobileConfig
Auth AuthConfig
Shortener ShortenerConfig
}
Config holds all configuration for the application, composed of sub-configs.
type FonbnkConfig ¶
FonbnkConfig holds all Fonbnk-related configuration
type MobileConfig ¶
type MobileConfig struct {
AfricasTalking AfricasTalkingConfig
// SessionTimeout is the Redis TTL for a USSD session, refreshed on each
// request. From USSD_SESSION_TIMEOUT (seconds); defaults to 5 minutes.
SessionTimeout time.Duration
// USSDDialString is what a user dials to reach this deployment, stored
// complete with prefix and terminator.
USSDDialString string
// RepayPaybill is the mobile-money paybill number shown on the USSD repay
// screen. From REPAY_PAYBILL. Builder-injected and environment-specific:
// it names the builder's own merchant account, so the platform ships no
// default. Blank hides the mobile-money option rather than printing a
// number nobody can pay into.
RepayPaybill string
}
MobileConfig holds all mobile-related configuration
type MoneyGramConfig ¶ added in v1.0.0
type MoneyGramConfig struct {
// SEP-1 / 9 / 10 / 24 — Stellar anchor protocol
HomeDomain string // e.g. "stellar.moneygram.com"
ServerSigningKey string // pinned from TOML, validated at boot
NetworkPassphrase string // matches StellarConfig.NetworkPassphrase
USDCIssuer string // matches StellarConfig.USDCIssuer
TransferServerURL string // override, otherwise resolved from TOML
// REST API — OAuth 2.0 client_credentials (FX rates)
ClientID string
ClientSecret string
OAuthURL string // token endpoint
FXRateURL string // GET /fx-rate/v1/rates
// Entry-rate buffers applied by the FX orchestrator, as fractions
// (0.01 = 1 %). Nil leaves the orchestrator's own defaults in place;
// an explicit 0 quotes raw source rates with no buffer at all.
// From MONEYGRAM_FX_ENTRY_BUFFER_PCT and
// MONEYGRAM_FX_ENTRY_BUFFER_PCT_FALLBACK.
FXEntryBufferPct *float64
FXEntryBufferPctFallback *float64
// Custodial wallets. AuthSecret co-signs SEP-10; FundsSecret is the SEP-24
// account and USDC send source. Both default to TREASURY_SECRET_KEY.
AuthSecret string
FundsSecret string
// Poller cadence. Zero leaves mgpoller.DefaultConfig's value in place
// rather than config duplicating the defaults.
PollInterval time.Duration // MONEYGRAM_POLL_INTERVAL (seconds)
PollMaxBatch int // MONEYGRAM_POLL_MAX_BATCH
RefundSettleMaxAttempts int // MONEYGRAM_REFUND_MAX_ATTEMPTS
// Borrower repayment cash-in. Separate from the withdrawal cadence above
// because the two directions wait on different things: a withdrawal is
// ours to finish and is polled hard, a deposit is the borrower's and
// spends most of its window idle.
RepaymentWindow time.Duration // REPAYMENT_WINDOW (seconds)
RepaymentPollInterval time.Duration // REPAYMENT_POLL_INTERVAL (seconds)
RepaymentReminderBefore time.Duration // REPAYMENT_REMINDER_BEFORE (seconds)
RepaymentVaultMaxAttempt int // REPAYMENT_VAULT_MAX_ATTEMPTS
// Per-row poll schedule. These write repayment_next_poll_at, which is what
// actually decides whether a row is returned — shortening
// RepaymentPollInterval alone changes how often the runner asks, not what
// it gets back, so a row parked 30 minutes out stays parked.
//
// Production wants them long: a deposit spends most of its window with the
// borrower walking to an agent, and polling harder learns nothing. Set them
// to a few seconds in development to watch a deposit move in real time.
RepaymentActiveBackoff time.Duration // REPAYMENT_ACTIVE_BACKOFF (seconds), default 2m
RepaymentIdleBackoff time.Duration // REPAYMENT_IDLE_BACKOFF (seconds), default 30m
RepaymentVaultRetryBackoff time.Duration // REPAYMENT_VAULT_RETRY_BACKOFF (seconds), default 1h
}
MoneyGramConfig holds all MoneyGram-related configuration.
func (*MoneyGramConfig) AuthAddress ¶ added in v1.0.0
func (c *MoneyGramConfig) AuthAddress() (string, error)
AuthAddress returns the public G... address of the SEP-10 auth wallet.
func (*MoneyGramConfig) FundsAddress ¶ added in v1.0.0
func (c *MoneyGramConfig) FundsAddress() (string, error)
FundsAddress returns the public G... address of the funds wallet — the SEP-24 account and USDC send source.
func (*MoneyGramConfig) HasRESTCredentials ¶ added in v1.0.0
func (c *MoneyGramConfig) HasRESTCredentials() bool
HasRESTCredentials reports whether the REST API credentials are populated. Callers should fall back to YC for FX rates when this returns false.
func (*MoneyGramConfig) Validate ¶ added in v1.0.0
func (c *MoneyGramConfig) Validate() error
Validate checks that all fields required to construct a working MoneyGram client are set.
Validate intentionally does not require REST API credentials (ClientID / ClientSecret / OAuthURL / FXRateURL): the SEP-1/10/24 anchor flow can run without them, and those credentials are gated on Open Q #6 confirming MG issues REST API access to Ramps partners.
type PaymentsConfig ¶
type PaymentsConfig struct {
YellowCard YellowCardConfig
Fonbnk FonbnkConfig
MoneyGram MoneyGramConfig
// EntryFXBufferPct is the flat safety margin the loan adapter applies when
// it re-quotes the entry rate from a provider's own Quoter, as a fraction
// (0.02 = 2 %). Nil leaves the adapter's default in place; an explicit 0
// persists the quoted rate unbuffered. From LOAN_ENTRY_FX_BUFFER_PCT.
//
// Distinct from the MoneyGram orchestrator's buffers, which apply on the
// cascade path and carry their own per-leg settings.
EntryFXBufferPct *float64
// EnableProviderRelaySwitch turns on per-transaction routing between
// providers on effective post-fee rate. Off routes every transaction to
// YellowCard, the default provider. From
// ENABLE_PAYMENT_PROVIDER_RELAY_SWITCH; unset is off.
EnableProviderRelaySwitch bool
}
PaymentsConfig bundles all payment provider configurations
type PostgresConfig ¶
type PostgresConfig struct {
Host string
User string
Password string
DBName string
Port string
SSLMode string
TimeZone string
}
PostgresConfig holds all database-related configuration.
func (*PostgresConfig) DSN ¶
func (c *PostgresConfig) DSN() string
DSN returns the connection string for Postgres.
type RedisConfig ¶
type RedisConfig struct {
Host string
Port string
Password string
DBNumber int
IdempotencyTTL time.Duration
}
RedisConfig holds all Redis-related configuration.
func (*RedisConfig) Addr ¶
func (c *RedisConfig) Addr() string
Addr returns the host:port address for Redis.
func (*RedisConfig) GetIdempotencyTTL ¶
func (c *RedisConfig) GetIdempotencyTTL() time.Duration
GetIdempotencyTTL returns the configured TTL or default of 24 hours
type ServerConfig ¶
type ServerConfig struct {
ServerEnvironment string
ServerHost string
CoreServerPort string
CreditServerPort string
// PublicBaseURL is the externally-reachable origin used to build SMS
// short-links (e.g. https://microvault.outray.app). No trailing slash.
PublicBaseURL string
}
ServerConfig holds all server-related configuration.
func (*ServerConfig) CoreAddr ¶
func (c *ServerConfig) CoreAddr() string
CoreAddr returns the host:port address for the core server to listen on.
func (*ServerConfig) CreditAddr ¶
func (c *ServerConfig) CreditAddr() string
CreditAddr returns the host:port address for the credit server to listen on.
type ShortenerConfig ¶ added in v1.0.0
type ShortenerConfig struct {
// APIKey is the dub workspace API key (from DUB_API_KEY). Presence
// enables the shortener.
APIKey string
// BaseURL is the dub API origin (from DUB_API_URL), set to point at a
// self-hosted instance. Empty uses the SDK default, https://api.dub.co.
BaseURL string
// Domain is the short-link domain links are created under (from
// DUB_DOMAIN). Optional; empty lets the workspace default apply.
Domain string
// PreviewTitle overrides the og:title in dub Custom Link Previews (from
// DUB_PREVIEW_TITLE). Optional; empty derives it from the destination host.
PreviewTitle string
// PreviewDescription overrides the og:description (from
// DUB_PREVIEW_DESCRIPTION). Optional; empty derives it from the
// destination host and path.
PreviewDescription string
// ImagePreviewURL is the og:image shown in dub Custom Link Previews
// (from DUB_IMAGE_PREVIEW_URL). Optional.
ImagePreviewURL string
}
ShortenerConfig configures the optional dub link shortener used for outbound cash-pickup SMS links. When APIKey is empty the shortener is off and links fall back to the self-hosted /r/{code} redirect.
func (*ShortenerConfig) Enabled ¶ added in v1.0.0
func (c *ShortenerConfig) Enabled() bool
Enabled reports whether the dub shortener should be used.
type StellarConfig ¶
type StellarConfig struct {
RpcURL string
// AdminPublicKey is derived from AdminSecretKey at load, not read from the environment.
AdminPublicKey string
AdminSecretKey string
TreasurySecretKey string
ServerSecretKey string
NetworkPassphrase string
EnableMultiSig bool
MultiSigLowThreshold uint32
MultiSigMediumThreshold uint32
MultiSigHighThreshold uint32
USDCIssuer string
ContractID string
// AccountIndexBase advances account_index_seq at boot so a freshly rebuilt
// (testnet) database hands out BIP44 derivation indices above any burned
// on-chain. 0 (the default) leaves the sequence untouched. From
// ACCOUNT_INDEX_BASE.
AccountIndexBase int64
}
StellarConfig holds all stellar-related configuration.
func (*StellarConfig) NewRpcClient ¶
func (c *StellarConfig) NewRpcClient() *rpcclient.Client
NewRpcClient creates a new instance of Stellar RPC Client to connect with Stellar's RPC Server
func (*StellarConfig) TreasuryAddress ¶ added in v1.1.2
func (c *StellarConfig) TreasuryAddress() (string, error)
TreasuryAddress derives the treasury's public address from its secret key.