wallet

package
v0.2.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 17, 2026 License: MIT Imports: 11 Imported by: 0

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

View Source
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.

View Source
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"
)
View Source
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

View Source
var Divisions = []int{1, 2, 3, 4, 5, 6, 7}

Divisions are the seven wallet divisions every corporation has.

View Source
var ErrUnauthorized = fmt.Errorf("wallet authorization rejected")

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 Due

func Due(last *time.Time, now time.Time) bool

Due reports whether a sync is worth doing.

func IsStatus

func IsStatus(err error, status int) bool

IsStatus reports whether an error came from one ESI status.

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 Balance

type Balance struct {
	Division int     `json:"division"`
	Balance  float64 `json:"balance"`
}

Balance is one division's balance from ESI.

type DepositResult

type DepositResult struct {
	Credited       int
	CreditedAmount float64
	Unmatched      int
	Invalid        int
}

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

type ResponseError struct {
	Status int
	What   string
}

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

type SyncResult struct {
	Balances int64 `json:"balances"`
	Journal  int64 `json:"journal"`
}

SyncResult reports one wallet sync.

type Token

type Token struct {
	CorporationID   int32
	CharacterID     int32
	AccessToken     string
	RefreshToken    string
	Expiry          time.Time
	Disabled        bool
	LastBalanceSync *time.Time
	LastJournalSync *time.Time
}

Token is a stored corporation wallet authorisation.

func LoadTokens

func LoadTokens(ctx context.Context, pool *pgxpool.Pool) ([]Token, error)

LoadTokens returns the corporation wallet authorisations worth syncing.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL