Documentation
¶
Overview ¶
Package whitelist is the registration-whitelist domain. Its Service provides two things from one place:
- the authorization gate (Checker.IsWhitelisted) shared by the registration service and the Ethereum JSON-RPC facade. The skip decision (skip_whitelist_check) is baked into the Service at construction time, so consumers only ever ask "is this address allowed?" without carrying their own skip flag and branch; and
- the admin operations (Manager: add, remove, cursor-paginated list) exposed under /admin/whitelist.
Index ¶
- Constants
- Variables
- func RegisterAdminRoutes(r chi.Router, mgr Manager, token string, logger *zap.Logger)
- type Checker
- type Manager
- type Page
- type Service
- func (s *Service) Add(ctx context.Context, evmAddress, note string) error
- func (s *Service) IsWhitelisted(ctx context.Context, evmAddress string) (bool, error)
- func (s *Service) List(ctx context.Context, cursor string, limit int) (*Page, error)
- func (s *Service) Remove(ctx context.Context, evmAddress string) error
- type Store
Constants ¶
const ( DefaultLimit = 50 MaxLimit = 200 )
Cursor pagination bounds for List, mirroring the token list endpoint.
Variables ¶
var ErrEntryNotFound = errors.New("whitelist entry not found")
ErrEntryNotFound is returned by Remove when the address was not whitelisted.
Functions ¶
Types ¶
type Checker ¶
Checker reports whether an EVM address is permitted. It is the narrow gate consumed by the registration service and the eth-rpc facade.
type Manager ¶
type Manager interface {
Add(ctx context.Context, evmAddress, note string) error
Remove(ctx context.Context, evmAddress string) error
List(ctx context.Context, cursor string, limit int) (*Page, error)
}
Manager is the admin surface (add/remove/list) consumed by the HTTP layer.
type Page ¶
type Page struct {
Items []user.WhitelistEntry `json:"items"`
NextCursor string `json:"next_cursor,omitempty"`
HasMore bool `json:"has_more"`
}
Page is the cursor-paginated whitelist listing returned by List.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the whitelist domain. When skip is true the gate authorizes every address (skip_whitelist_check); the admin operations are unaffected.
func New ¶
New returns a whitelist Service backed by store. When skip is true every address is authorized by IsWhitelisted.
func (*Service) Add ¶
Add validates the address and upserts it (with an optional note). It is idempotent: re-adding an address updates its note rather than erroring, so callers can ensure-present without a prior read.
func (*Service) IsWhitelisted ¶
IsWhitelisted reports whether evmAddress may register/transact. With skip enabled it always returns true without touching the store.
func (*Service) List ¶
List returns one cursor-delimited page of whitelisted addresses, ordered by address. It fetches one extra row to determine HasMore without a separate count query; NextCursor is the last returned address (pass it back as cursor for the next page). limit is clamped to [1, MaxLimit] so a non-HTTP caller can't request a zero/negative page (which would yield an empty page that still reports HasMore and loop a paging client forever) or an unbounded one.
type Store ¶
type Store interface {
IsWhitelisted(ctx context.Context, evmAddress string) (bool, error)
AddToWhitelist(ctx context.Context, evmAddress, note string) error
RemoveFromWhitelist(ctx context.Context, evmAddress string) (removed bool, err error)
ListWhitelist(ctx context.Context, cursor string, limit int) ([]*user.WhitelistEntry, error)
}
Store is the persistence the whitelist needs. It is satisfied by the user store. ListWhitelist returns up to limit entries after cursor (the previous page's last evm_address; empty starts from the beginning).