faucet

package
v0.1.34 Latest Latest
Warning

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

Go to latest
Published: May 30, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Index

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.

func (*Config) Validate

func (config *Config) Validate() error

Validate checks faucet server configuration for correctness and minimum requirements: - SigningKeyName must be set - SupportedSendCoins must include at least one valid coin string (e.g. "1upokt") - ListenAddress must be a valid "host:port" string

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

func (srv *Server) GetBalances(ctx context.Context, address string) (cosmostypes.Coins, error)

GetBalances queries the onchain balances for the specified address.

func (*Server) GetSigningAddress

func (srv *Server) GetSigningAddress() string

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.

func (*Server) Serve

func (srv *Server) Serve(ctx context.Context) error

Serve starts the HTTP server and blocks until the context is canceled.

Jump to

Keyboard shortcuts

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