cosmosfaucet

package
v0.0.0-...-9032b55 Latest Latest
Warning

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

Go to latest
Published: May 28, 2022 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package cosmosfaucet is a faucet to request tokens for sdk accounts.

Index

Constants

View Source
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

func New(ctx context.Context, ccr chaincmdrunner.Runner, options ...Option) (Faucet, error)

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.

func (Faucet) TotalTransferredAmount

func (f Faucet) TotalTransferredAmount(ctx context.Context, toAccountAddress, denom string) (totalAmount uint64, err error)

TotalTransferredAmount returns the total transferred amount from faucet account to toAccountAddress.

func (*Faucet) Transfer

func (f *Faucet) Transfer(ctx context.Context, toAccountAddress string, coins sdk.Coins) error

Transfer transfer amount of tokens from the faucet account to toAccountAddress.

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 NewClient

func NewClient(addr string) HTTPClient

NewClient returns a new 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

Transfer requests tokens from the faucet with req.

type Option

type Option func(*Faucet)

Option configures the faucetOptions.

func Account

func Account(name, mnemonic string, coinType string) Option

Account provides the account information to transfer tokens from. when mnemonic isn't provided, account assumed to be exists in the keyring.

func ChainID

func ChainID(id string) Option

ChainID adds chain id to faucet. faucet will automatically fetch when it isn't provided.

func Coin

func Coin(amount, maxAmount uint64, denom string) Option

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 OpenAPI

func OpenAPI(apiAddress string) Option

OpenAPI configures how to serve Open API page and and spec.

func RefreshWindow

func RefreshWindow(refreshWindow time.Duration) Option

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"`
}

Jump to

Keyboard shortcuts

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