Documentation
¶
Index ¶
- type Config
- type FaucetOptionFn
- type FundResponse
- type Server
- func (srv *Server) GetBalances(ctx context.Context, address string) (cosmostypes.Coins, error)
- func (srv *Server) GetSigningAddress() string
- func (srv *Server) SendDenom(ctx context.Context, logger polylog.Logger, denom string, ...) (*FundResponse, error)
- func (srv *Server) Serve(ctx context.Context) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// SigningKeyName specifies the key (by name) used to sign transactions.
// - Must exist in the keyring.
SigningKeyName string `mapstructure:"signing_key_name"`
// SupportedSendCoins lists cosmos-sdk coin strings (amount + denom).
// - Specifies which coins the faucet can send to users.
SupportedSendCoins []string `mapstructure:"supported_send_coins"`
// CreateAccountsOnly controls faucet behavior:
// - true: Only service requests for accounts not yet on-chain (i.e. new accounts without an onchain public key)
// - false: Service all requests (i.e. do not reject requests from any)
CreateAccountsOnly bool `mapstructure:"create_accounts_only"`
// ListenAddress specifies the network address for the faucet HTTP server.
// - Format: "host:port"
ListenAddress string `mapstructure:"listen_address"`
// contains filtered or unexported fields
}
Config defines the configuration for a faucet server. Loaded via viper. Can be provided through: - A config file matching this structure (uses mapstructure tags as keys) - Environment variables, prefixed with "FAUCET_" (e.g. FAUCET_SIGNING_KEY_NAME)
func NewFaucetConfig ¶
func NewFaucetConfig( clientCtx cosmosclient.Context, signingKeyName string, listenAddress string, sendTokens []string, createAccountOnly bool, ) (*Config, error)
NewFaucetConfig creates a new faucet server configuration from the provided arguments.
func (*Config) GetSigningAddress ¶
func (config *Config) GetSigningAddress() cosmostypes.AccAddress
GetSigningAddress returns the address of the configured signing key.
func (*Config) GetSupportedSendCoins ¶
func (config *Config) GetSupportedSendCoins() cosmostypes.Coins
GetSupportedSendCoins returns SupportedSendCoins as a cosmos-sdk Coins object.
func (*Config) LoadSigningKey ¶
func (config *Config) LoadSigningKey(clientCtx cosmosclient.Context) error
LoadSigningKey loads the signing key from the keyring in the given client context. - Uses the configured SigningKeyName.
type FaucetOptionFn ¶
type FaucetOptionFn func(server *Server)
FaucetOptionFn defines a function that configures a faucet server instance.
func WithBankQueryClient ¶
func WithBankQueryClient(bankQueryClient bankGRPCQueryClient) FaucetOptionFn
WithBankQueryClient sets the faucet server's bank query client.
func WithConfig ¶
func WithConfig(config *Config) FaucetOptionFn
WithConfig sets the faucet server's configuration object.
func WithTxClient ¶
func WithTxClient(txClient client.TxClient) FaucetOptionFn
WithTxClient sets the faucet server's transaction (tx) client.
type FundResponse ¶
type FundResponse struct {
TxHash string `json:"tx_hash"`
Code uint32 `json:"code"`
Log string `json:"log"`
RecipientAddress string `json:"recipient_address"`
SentCoins types.Coins `json:"sent_coins"`
CreateAccountsOnly bool `json:"create_accounts_only,omitempty"`
}
FundResponse is the response object returned by the /{denom}/{recipient_address} endpoint. ALL successful HTTP requests will have status code 202 with a non-empty TxHash. A successful HTTP response (202) DOES NOT guarantee that the onchain TX will be successful.
func NewFundResponse ¶
func NewFundResponse( txHash string, code uint32, recipientAddress string, sentCoins types.Coins, log string, createAccountsOnly bool, ) *FundResponse
NewFundResponse is a constructor for FundResponse. It guarantees that no fields are omitted during construction.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server handles HTTP funding requests by broadcasting onchain bank send transactions using a dedicated faucet account.
func NewFaucetServer ¶
func NewFaucetServer(ctx context.Context, opts ...FaucetOptionFn) (*Server, error)
NewFaucetServer constructs a new Server using the provided options.
func (*Server) GetBalances ¶
GetBalances queries the onchain balances for the specified address.
func (*Server) GetSigningAddress ¶
GetSigningAddress returns the faucet's current signing address as a string.
func (*Server) SendDenom ¶
func (srv *Server) SendDenom( ctx context.Context, logger polylog.Logger, denom string, recipientAddress cosmostypes.AccAddress, ) (*FundResponse, error)
SendDenom sends tokens of the specified denom to recipientAddress. - Amount is determined by SupportedSendCoins config. - Only checks that the TX passed CheckTx (entered mempool); does not wait for commit. - TX MAY still fail after being accepted into the mempool.