Documentation
¶
Overview ¶
Package wallet syncs corporation wallet balances and journals from ESI.
A corporation has seven wallet divisions and each keeps its own paginated journal, so one sync is up to seven paginated walks plus a balances call. That is expensive enough that it is gated on staleness rather than run unconditionally.
The journal is append-only from our side: entries are inserted and never updated, because a journal entry is a historical fact that CCP does not revise. That makes the whole sync idempotent — re-reading a page inserts nothing new.
Index ¶
- Constants
- Variables
- func DisableToken(ctx context.Context, pool *pgxpool.Pool, corporationID int32, reason string) error
- func Due(last *time.Time, now time.Time) bool
- func IsStatus(err error, status int) bool
- func SyncBalances(ctx context.Context, pool *pgxpool.Pool, client *esi.Client, ...) (int64, error)
- func SyncJournal(ctx context.Context, pool *pgxpool.Pool, client *esi.Client, ...) (int64, error)
- type Balance
- type DepositResult
- type JournalEntry
- type ResponseError
- type SyncResult
- type Token
Constants ¶
const ( SyncInterval = time.Hour SyncTolerance = 5 * time.Minute StaleAfter = SyncInterval - SyncTolerance )
SyncInterval is how often a wallet is refreshed.
The tolerance matters and is not padding for its own sake: the dispatching cron fires on wall-clock hour boundaries, so a sync that finished at HH:01 would still look fresh at HH+1:00 and the wallet would refresh every second hour instead of every hour. Subtracting five minutes closes that gap.
const ( // DepositsEnabledConfigKey is the launch cutoff. Historical donations must // not suddenly become wallet credit when this processor is deployed. DepositsEnabledConfigKey = "ek-wallet:deposits-enabled-at" )
const JournalPageLimit = 200
JournalPageLimit bounds a division's walk. ESI reports the page count, so this is a guard against a paging bug rather than the normal exit.
Variables ¶
var Divisions = []int{1, 2, 3, 4, 5, 6, 7}
Divisions are the seven wallet divisions every corporation has.
ErrUnauthorized means the wallet authorisation no longer works.
Separated because the response is different from an ordinary failure: the character lost the Accountant role or left the corporation, and no amount of retrying will restore it. The caller disables the token.
Functions ¶
func DisableToken ¶
func DisableToken(ctx context.Context, pool *pgxpool.Pool, corporationID int32, reason string) error
DisableToken stops a corporation's wallet being synced and records why.
func SyncBalances ¶
func SyncBalances(ctx context.Context, pool *pgxpool.Pool, client *esi.Client, corporationID int32, accessToken string) (int64, error)
SyncBalances writes the current balance of each division.
Balances are current state rather than history, so this overwrites. The journal below is the historical record.
func SyncJournal ¶
func SyncJournal(ctx context.Context, pool *pgxpool.Pool, client *esi.Client, corporationID int32, accessToken string) (int64, error)
SyncJournal walks every division's journal and stores what is new.
ON CONFLICT DO NOTHING rather than an update: a journal entry is a historical fact CCP does not revise, so re-reading a page must be a no-op. That is what makes an interrupted sync safe to simply run again.
Types ¶
type DepositResult ¶
DepositResult reports one catch-up pass.
func ProcessPendingDeposits ¶
func ProcessPendingDeposits( ctx context.Context, pool *pgxpool.Pool, corporationID int32, ) (DepositResult, error)
ProcessPendingDeposits credits eligible EVE-KILL player donations to the authoritative sender's per-character wallet.
type JournalEntry ¶
type JournalEntry struct {
ID int64 `json:"id"`
Date string `json:"date"`
RefType string `json:"ref_type"`
Description string `json:"description"`
Amount *float64 `json:"amount"`
BalanceAfter *float64 `json:"balance"`
FirstPartyID *int64 `json:"first_party_id"`
SecondPartyID *int64 `json:"second_party_id"`
ContextID *int64 `json:"context_id"`
ContextIDType *string `json:"context_id_type"`
Reason *string `json:"reason"`
Tax *float64 `json:"tax"`
TaxReceiverID *int64 `json:"tax_receiver_id"`
}
JournalEntry is one wallet journal line.
type ResponseError ¶
ResponseError preserves the ESI status so the worker can refresh-and-retry a 401 without treating a 403 role failure as a dead SSO grant.
func (*ResponseError) Error ¶
func (e *ResponseError) Error() string
func (*ResponseError) Unwrap ¶
func (e *ResponseError) Unwrap() error
type SyncResult ¶
SyncResult reports one wallet sync.