Documentation ¶
Overview ¶
Package cosmosfaucet is a faucet to request tokens for sdk accounts.
Index ¶
Constants ¶
const ( // DefaultAccountName is the default account to transfer tokens from. DefaultAccountName = "faucet" // DefaultDenom is the default denomination to distribute. DefaultDenom = "uatom" // DefaultAmount specifies the default amount to transfer to an account // on each request. DefaultAmount = 10000000 // DefaultMaxAmount specifies the maximum amount that can be tranffered to an // account in all times. DefaultMaxAmount = 100000000 // DefaultLimitRefreshWindow specifies the time after which the max amount limit // is refreshed for an account [1 year] DefaultRefreshWindow = time.Hour * 24 * 365 )
Variables ¶
This section is empty.
Functions ¶
func TryRetrieve ¶
func TryRetrieve( ctx context.Context, chainID, rpcAddress, faucetAddress, accountAddress string, ) error
TryRetrieve tries to retrieve tokens from a faucet. faucet address is used when it's provided. otherwise, it'll try to guess the faucet address from the rpc address of the chain. a non-nil error is returned if cannot determine faucet's address or when coin retrieval is unsuccessful.
Types ¶
type ErrTransferRequest ¶
type ErrTransferRequest struct {
StatusCode int
}
ErrTransferRequest is a error that occurs when a transfer request fails
func (ErrTransferRequest) Error ¶
func (err ErrTransferRequest) Error() string
Error implement error
type Faucet ¶
type Faucet struct {
// contains filtered or unexported fields
}
Faucet represents a faucet.
func New ¶
New creates a new faucet with ccr (to access and use blockchain's CLI) and given options.
func (Faucet) ServeHTTP ¶
func (f Faucet) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler to expose the functionality of Faucet.Transfer() via HTTP. request/response payloads are compatible with the previous implementation at allinbits/cosmos-faucet.
type FaucetInfoResponse ¶
type FaucetInfoResponse struct { // IsAFaucet indicates that this is a faucet endpoint. // useful for auto discoveries. IsAFaucet bool `json:"is_a_faucet"` // ChainID is chain id of the chain that faucet is running for. ChainID string `json:"chain_id"` }
FaucetInfoResponse is the faucet info payload.
type HTTPClient ¶
type HTTPClient struct {
// contains filtered or unexported fields
}
HTTPClient is a faucet client.
func (HTTPClient) FaucetInfo ¶
func (c HTTPClient) FaucetInfo(ctx context.Context) (FaucetInfoResponse, error)
FaucetInfo fetch the faucet info for clients to determine if this is a real faucet and what is the chain id of the chain that faucet is operating for.
func (HTTPClient) Transfer ¶
func (c HTTPClient) Transfer(ctx context.Context, req TransferRequest) (TransferResponse, error)
Transfer requests tokens from the faucet with req.
type Option ¶
type Option func(*Faucet)
Option configures the faucetOptions.
func Account ¶
Account provides the account information to transfer tokens from. when mnemonic isn't provided, account assumed to be exists in the keyring.
func ChainID ¶
ChainID adds chain id to faucet. faucet will automatically fetch when it isn't provided.
func Coin ¶
Coin adds a new coin to coins list to distribute by the faucet. the first coin added to the list considered as the default coin during transfer requests.
amount is the amount of the coin can be distributed per request. maxAmount is the maximum amount of the coin that can be sent to a single account. denom is denomination of the coin to be distributed by the faucet.
func RefreshWindow ¶
RefreshWindow adds the duration to refresh the transfer limit to the faucet
type TransferRequest ¶
type TransferRequest struct { // AccountAddress to request for coins. AccountAddress string `json:"address"` // Coins that are requested. // default ones used when this one isn't provided. Coins []string `json:"coins"` }
func NewTransferRequest ¶
func NewTransferRequest(accountAddress string, coins []string) TransferRequest
type TransferResponse ¶
type TransferResponse struct {
Error string `json:"error,omitempty"`
}