Documentation
¶
Index ¶
Constants ¶
const ( DefaultLimit = 50 MaxLimit = 200 )
Variables ¶
This section is empty.
Functions ¶
func RegisterRoutes ¶
func RegisterRoutes(r chi.Router, svc ListService, logger *zap.Logger)
RegisterRoutes registers token endpoints on the given router.
Types ¶
type Config ¶
type Config struct {
SupportedTokens map[common.Address]ERC20Token `yaml:"supported_tokens" validate:"required,min=1"`
}
Config holds token metadata indexed by contract address.
type ERC20 ¶
type ERC20 interface {
Name(ctx context.Context) string
Symbol(ctx context.Context) string
Decimals(ctx context.Context) uint8
TotalSupply(ctx context.Context) big.Int
BalanceOf(ctx context.Context, address common.Address) big.Int
TransferFrom(ctx context.Context, idempotencyKey string, from, to common.Address, amount big.Int) error
Approve(ctx context.Context, spender common.Address, amount big.Int) error
Allowance(ctx context.Context, owner, spender common.Address) big.Int
}
ERC20 defines the ERC-20 surface exposed by this package.
type ERC20Token ¶
type ERC20Token struct {
Name string `yaml:"name" validate:"required"`
Symbol string `yaml:"symbol" validate:"required"`
Decimals int `yaml:"decimals" validate:"gte=0,lte=18"`
InstrumentID string `yaml:"instrument_id" validate:"required"`
}
ERC20Token contains ERC-20 token metadata and Canton instrument mapping.
type HTTP ¶
type HTTP struct {
// contains filtered or unexported fields
}
HTTP wraps ListService to provide token HTTP endpoints.
type ListService ¶
type ListService interface {
GetSupportedTokens(ctx context.Context, cursor string, limit int) (*TokensPage, error)
}
ListService is the narrow interface the HTTP layer depends on.
type Native ¶
type Native interface {
GetBalance(ctx context.Context, address common.Address) (big.Int, error)
Transfer(ctx context.Context, from, to common.Address, amount big.Int) error
}
Native defines the native-token surface exposed by this package.
type Provider ¶
type Provider interface {
GetTotalSupply(ctx context.Context, tokenSymbol string) (string, error)
GetBalance(ctx context.Context, tokenSymbol, partyID string) (string, error)
}
Provider defines token data provider.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides token operations shared by API and EthRPC endpoints.
func NewTokenService ¶
func NewTokenService( cfg *Config, provider Provider, userStore UserStore, cantonClient canton.Token, ) *Service
NewTokenService creates a Service.
func (*Service) ERC20 ¶
ERC20 returns an ERC-20 view for the given contract address, or an error if the address is not a supported token contract.
func (*Service) GetSupportedTokens ¶
func (s *Service) GetSupportedTokens(_ context.Context, cursor string, limit int) (*TokensPage, error)
GetSupportedTokens returns a cursor-paginated list of supported tokens sorted by address. cursor is the address of the last item from the previous page; empty string starts from the beginning.
type TokenItem ¶
type TokenItem struct {
Address string `json:"address"`
Name string `json:"name"`
Symbol string `json:"symbol"`
Decimals int `json:"decimals"`
}
TokenItem is a single token entry in the list response.
type TokensPage ¶
type TokensPage struct {
Items []TokenItem `json:"items"`
NextCursor string `json:"next_cursor,omitempty"`
HasMore bool `json:"has_more"`
}
TokensPage is the cursor-paginated response for GET /tokens.