Documentation
¶
Overview ¶
Package store keeps Fundarr's state in one SQLite file: configured sources and destinations (secrets sealed), the normalized activity history, the latest balances, what was delivered where, and the run log.
Index ¶
- Constants
- Variables
- type APIToken
- type ActivityFilter
- type Adjustment
- type Change
- type Delivery
- type Entity
- type FeedItem
- type FeedState
- type NotifyTarget
- type PriceWindow
- type Route
- type Run
- type Statement
- type Store
- func (s *Store) APITokens(ctx context.Context) ([]APIToken, error)
- func (s *Store) Activities(ctx context.Context, f ActivityFilter) ([]model.Activity, error)
- func (s *Store) Activity(ctx context.Context, sourceID, id string) (*model.Activity, error)
- func (s *Store) AddActivities(ctx context.Context, acts []model.Activity) (int, error)
- func (s *Store) Adjustments(ctx context.Context, sourceID string) ([]Adjustment, error)
- func (s *Store) ApplyFeed(ctx context.Context, items []FeedItem) (int, error)
- func (s *Store) Balances(ctx context.Context, sourceID string) ([]model.Balance, time.Time, error)
- func (s *Store) BalancesDerived(ctx context.Context, sourceID string) bool
- func (s *Store) Changes(ctx context.Context, after int64, limit int) ([]Change, bool, error)
- func (s *Store) CheckAPIToken(ctx context.Context, token string) bool
- func (s *Store) Close() error
- func (s *Store) CloseInterrupted(ctx context.Context) (int64, error)
- func (s *Store) CountActivities(ctx context.Context, sourceID string) (int, error)
- func (s *Store) CreateAPIToken(ctx context.Context, name string) (APIToken, string, error)
- func (s *Store) DeleteAPIToken(ctx context.Context, id string) error
- func (s *Store) DeleteActivities(ctx context.Context, sourceID string, ids []string) error
- func (s *Store) DeleteDestination(ctx context.Context, id string) error
- func (s *Store) DeleteRoute(ctx context.Context, destID, srcID string) error
- func (s *Store) DeleteSource(ctx context.Context, id string) error
- func (s *Store) DeliveryCounts(ctx context.Context, destID string) (map[string]int, error)
- func (s *Store) Destination(ctx context.Context, id string) (*Entity, error)
- func (s *Store) DestinationError(ctx context.Context, id, msg string) error
- func (s *Store) Destinations(ctx context.Context) ([]*Entity, error)
- func (s *Store) EndRun(ctx context.Context, id int64, ok bool, summary, log string) error
- func (s *Store) FeedState(ctx context.Context) (FeedState, error)
- func (s *Store) NotifyTargets(ctx context.Context) ([]NotifyTarget, error)
- func (s *Store) Ping(ctx context.Context) error
- func (s *Store) PriceSeries(ctx context.Context, pair string) (map[string]string, error)
- func (s *Store) PriceWindows(ctx context.Context, pair string) ([]PriceWindow, error)
- func (s *Store) PutBalances(ctx context.Context, sourceID string, at time.Time, b []model.Balance) error
- func (s *Store) PutBalancesFrom(ctx context.Context, sourceID string, at time.Time, b []model.Balance, ...) error
- func (s *Store) PutDeliveries(ctx context.Context, ds []Delivery) error
- func (s *Store) PutDestination(ctx context.Context, e *Entity) error
- func (s *Store) PutPrices(ctx context.Context, pair string, w PriceWindow, closes map[string]string) error
- func (s *Store) PutRoute(ctx context.Context, r Route) error
- func (s *Store) PutSetting(ctx context.Context, key, value string) error
- func (s *Store) PutSource(ctx context.Context, e *Entity) error
- func (s *Store) PutSourceState(ctx context.Context, id string, state []byte) error
- func (s *Store) PutTransferLink(ctx context.Context, l TransferLink) error
- func (s *Store) ReplacePeriod(ctx context.Context, st Statement, acts []model.Activity) error
- func (s *Store) ResetDeliveries(ctx context.Context, destID, sourceID string) error
- func (s *Store) Routes(ctx context.Context) ([]Route, error)
- func (s *Store) Runs(ctx context.Context, subject string, limit int) ([]Run, error)
- func (s *Store) SetNotify(ctx context.Context, id, url string, secret []byte) error
- func (s *Store) Setting(ctx context.Context, key string) (string, error)
- func (s *Store) Source(ctx context.Context, id string) (*Entity, error)
- func (s *Store) SourceRan(ctx context.Context, id string, at time.Time, runErr error, state []byte) error
- func (s *Store) Sources(ctx context.Context) ([]*Entity, error)
- func (s *Store) StartRun(ctx context.Context, kind, subject string) (int64, error)
- func (s *Store) Statements(ctx context.Context, sourceID string) ([]Statement, error)
- func (s *Store) SubAccounts(ctx context.Context, sourceID string) ([]string, error)
- func (s *Store) TransferLinks(ctx context.Context) ([]TransferLink, error)
- type TransferLink
Constants ¶
const TombstoneKeep = 180 * 24 * time.Hour
TombstoneKeep is how long a removal stays in the feed.
Variables ¶
var ErrNotFound = errors.New("not found")
Functions ¶
This section is empty.
Types ¶
type APIToken ¶
type APIToken struct {
ID string `json:"id"`
Name string `json:"name"`
Created time.Time `json:"created"`
LastUsed time.Time `json:"lastUsed"`
// NotifyURL, when set, is told after each change to the history.
NotifyURL string `json:"notifyUrl"`
}
APIToken lets another program read Fundarr's data (the /api/v1 routes).
type ActivityFilter ¶
type ActivityFilter struct {
SourceID string
Since time.Time
Limit int
Offset int
// Undelivered: only those without a delivered/duplicate/skipped result
// for this destination.
UndeliveredTo string
// Newest lists the most recent first (oldest first otherwise).
Newest bool
// SettledBefore leaves out adjustments made after this time: a balance
// correction waits a while before going out, in case the platform's
// history catches up.
SettledBefore time.Time
}
ActivityFilter selects activities; zero fields mean no filter.
type Adjustment ¶
type Adjustment struct {
model.Activity
Created time.Time `json:"created"`
Delivered bool `json:"delivered"` // sent to at least one destination
}
Adjustment is a balance correction with what the UI needs about it.
type Entity ¶
type Entity struct {
ID string `json:"id"`
Kind string `json:"kind"`
Name string `json:"name"`
Settings map[string]string `json:"settings"`
Secrets []byte `json:"-"` // sealed JSON map
State []byte `json:"-"`
Enabled bool `json:"enabled"`
Interval time.Duration `json:"-"`
Created time.Time `json:"created"`
LastRun time.Time `json:"lastRun"`
LastOK time.Time `json:"lastOk"`
LastErr string `json:"lastError"`
}
Entity is a configured source or destination.
type FeedState ¶
type FeedState struct {
// Epoch changes when the feed starts over (a new database): cursors
// of another epoch are meaningless.
Epoch string
// Floor: tombstones up to it were forgotten. Head: the last number.
Floor, Head int64
}
FeedState is what cursors are checked against.
type NotifyTarget ¶
NotifyTarget is an app to tell about changes.
type PriceWindow ¶
PriceWindow is a range of days already asked to a provider.
type Route ¶
type Route struct {
DestinationID string `json:"destinationId"`
SourceID string `json:"sourceId"`
Account string `json:"account"`
Since time.Time `json:"since"` // only deliver activities from this date (zero: all)
// Accounts sends a sub-account of the source (a PEA beside a
// compte-titres) to another destination account; the others go to
// Account.
Accounts map[string]string `json:"accounts,omitempty"`
}
type Statement ¶
type Statement struct {
ID int64 `json:"id"`
SourceID string `json:"sourceId"`
Name string `json:"name"`
From time.Time `json:"from"`
To time.Time `json:"to"`
Activities int `json:"activities"`
At time.Time `json:"at"`
// Accounts: the sub-accounts it covers (nil: all).
Accounts []string `json:"accounts,omitempty"`
// Synced: downloaded by a sync, which replaces its previous copy
// (same name) instead of adding a statement.
Synced bool `json:"synced,omitempty"`
}
Statement is an imported platform statement: the reference for its period.
type Store ¶
type Store struct {
// Clock dates new rows (replaceable in tests).
Clock func() time.Time
// contains filtered or unexported fields
}
func (*Store) Activities ¶
func (*Store) AddActivities ¶
AddActivities inserts new activities and ignores ones already known (same source and native id). Returns how many were new.
func (*Store) Adjustments ¶
Adjustments lists a source's balance corrections, oldest first.
func (*Store) ApplyFeed ¶
ApplyFeed makes the feed match items, the whole current set, in one transaction: what is new or different gets a new sequence number, what is gone becomes a tombstone. Returns how many rows changed.
func (*Store) BalancesDerived ¶ added in v0.2.0
BalancesDerived reports whether a source's balances come from its history rather than the platform.
func (*Store) Changes ¶
Changes returns up to limit rows after seq, in order, and whether more follow. From 0 (a first copy) tombstones are left out.
func (*Store) CheckAPIToken ¶
CheckAPIToken says whether token is a live one, and marks it used.
func (*Store) CloseInterrupted ¶
CloseInterrupted marks runs left open by a stop or crash as failed.
func (*Store) CountActivities ¶
func (*Store) CreateAPIToken ¶
CreateAPIToken makes a token and returns it: this is the only time it can be read.
func (*Store) DeleteActivities ¶
DeleteActivities removes some of a source's activities (and what was recorded about their delivery).
func (*Store) DeleteDestination ¶
func (*Store) DeleteRoute ¶
func (*Store) DeliveryCounts ¶
DeliveryCounts returns, for a destination, how many activities are in each status.
func (*Store) Destination ¶
func (*Store) DestinationError ¶
func (*Store) NotifyTargets ¶
func (s *Store) NotifyTargets(ctx context.Context) ([]NotifyTarget, error)
func (*Store) PriceSeries ¶
PriceSeries returns the daily closes stored for a market, by day.
func (*Store) PriceWindows ¶
func (*Store) PutBalances ¶
func (*Store) PutBalancesFrom ¶ added in v0.2.0
func (s *Store) PutBalancesFrom(ctx context.Context, sourceID string, at time.Time, b []model.Balance, derived bool) error
PutBalancesFrom records balances; derived: the platform did not say, they are what the history adds up to.
func (*Store) PutDeliveries ¶
func (*Store) PutPrices ¶
func (s *Store) PutPrices(ctx context.Context, pair string, w PriceWindow, closes map[string]string) error
PutPrices stores closes fetched for a window of days.
func (*Store) PutSourceState ¶ added in v0.2.0
PutSourceState replaces a source's state outside a sync (after a sign-in, or when a sync ended because the session had expired).
func (*Store) PutTransferLink ¶
func (s *Store) PutTransferLink(ctx context.Context, l TransferLink) error
PutTransferLink records a choice; kind "" forgets the choices about out and in (back to automatic matching).
func (*Store) ReplacePeriod ¶
ReplacePeriod swaps a source's history between from and to (inclusive), in the statement's accounts, for acts, and records the statement, in one transaction. Activities that are in both keep their deliveries.
func (*Store) ResetDeliveries ¶
ResetDeliveries forgets what was delivered to a destination (to push again).
func (*Store) SetNotify ¶
SetNotify sets where a token's app is told about changes, with the sealed secret that signs the calls; url "" stops it.
func (*Store) SourceRan ¶
func (s *Store) SourceRan(ctx context.Context, id string, at time.Time, runErr error, state []byte) error
SourceRan records the outcome of a sync; state is only replaced on success.
func (*Store) Statements ¶
func (*Store) SubAccounts ¶ added in v0.2.0
SubAccounts lists the sub-accounts a source's history uses, besides the main one ("").
func (*Store) TransferLinks ¶
func (s *Store) TransferLinks(ctx context.Context) ([]TransferLink, error)
type TransferLink ¶
type TransferLink struct {
OutID string `json:"outId"`
InID string `json:"inId"`
Kind string `json:"kind"` // "pair" or "refuse"
}
TransferLink is a choice the user made about a withdrawal and a deposit.