faucet

package
v0.7.5 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2021 License: Apache-2.0, BSD-2-Clause Imports: 26 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// GenesisTokenAmount is the total supply.
	GenesisTokenAmount = 1000000000000000

	// RemainderAddressIndex is the RemainderAddressIndex.
	RemainderAddressIndex = 0

	// MinimumFaucetBalance defines the minimum token amount required, before the faucet stops operating.
	MinimumFaucetBalance = 0.1 * GenesisTokenAmount

	// MaxFaucetOutputsCount defines the max outputs count for the Facuet as the ledgerstate.MaxOutputCount -1 remainder output.
	MaxFaucetOutputsCount = ledgerstate.MaxOutputCount - 1

	// WaitForConfirmation defines the wait time before considering a transaction confirmed.
	WaitForConfirmation = 10 * time.Second
)
View Source
const (
	// PluginName is the name of the faucet plugin.
	PluginName = "Faucet"
)

Variables

View Source
var (
	// ErrNotEnoughFundingOutputs if there are not enough funding outputs in the faucet.
	ErrNotEnoughFundingOutputs = errors.New("not enough funding outputs to complete the request")
	// ErrMissingRemainderOutput is returned if the remainder output can not be found.
	ErrMissingRemainderOutput = errors.New("can't find faucet remainder output")
	// ErrNotEnoughFunds is returned when not enough funds are left in the faucet.
	ErrNotEnoughFunds = errors.New("not enough funds in the faucet")
	// ErrConfirmationTimeoutExpired is returned when a faucet transaction was not confirmed in expected time.
	ErrConfirmationTimeoutExpired = errors.New("tx confirmation time expired")
)
View Source
var Parameters = &ParametersDefinition{}

Parameters contains the configuration parameters of the faucet plugin.

Functions

func IsAddressBlackListed added in v0.5.4

func IsAddressBlackListed(address ledgerstate.Address) bool

IsAddressBlackListed returns if an address is blacklisted. adds the given address to the blacklist and removes the oldest blacklist entry if it would go over capacity.

func Plugin

func Plugin() *node.Plugin

Plugin returns the plugin instance of the faucet plugin.

func RemoveAddressFromBlacklist added in v0.5.4

func RemoveAddressFromBlacklist(address ledgerstate.Address)

RemoveAddressFromBlacklist removes an address from the blacklist.

Types

type FaucetOutput added in v0.5.4

type FaucetOutput struct {
	ID           ledgerstate.OutputID
	Balance      uint64
	Address      ledgerstate.Address
	AddressIndex uint64
}

FaucetOutput represents an output controlled by the faucet.

type ParametersDefinition added in v0.7.4

type ParametersDefinition struct {
	// Seed defines the base58 encoded seed the faucet uses.
	Seed string `usage:"the base58 encoded seed of the faucet, must be defined if this faucet is enabled"`

	// TokensPerRequest defines the amount of tokens the faucet should send for each request.
	TokensPerRequest int `default:"1000000" usage:"the amount of tokens the faucet should send for each request"`

	// MaxTransactionBookedAwaitTimeSeconds defines the time to await for the transaction fulfilling a funding request
	// to become booked in the value layer.
	MaxTransactionBookedAwaitTimeSeconds int `default:"5" usage:"the max amount of time for a funding transaction to become booked in the value layer"`

	// PowDifficulty defines the PoW difficulty for faucet payloads.
	PowDifficulty int `default:"22" usage:"defines the PoW difficulty for faucet payloads"`

	// BlacklistCapacity holds the maximum amount the address blacklist holds.
	// An address for which a funding was done in the past is added to the blacklist and eventually is removed from it.
	BlacklistCapacity int `default:"10000" usage:"holds the maximum amount the address blacklist holds"`

	// PreparedOutputsCount is the number of outputs the faucet prepares for requests.
	PreparedOutputsCount int `default:"126" usage:"number of outputs the faucet prepares"`

	// StartIndex defines from which address index the faucet should start gathering outputs.
	StartIndex int `default:"0" usage:"address index to start faucet with"`
}

ParametersDefinition contains the definition of configuration parameters used by the faucet plugin.

type StateManager added in v0.5.4

type StateManager struct {

	// ensures that only one goroutine can work on the stateManager at any time
	sync.RWMutex
	// contains filtered or unexported fields
}

StateManager manages the funds and outputs of the faucet. Can derive its state from a synchronized Tangle, can carry out funding requests, and prepares more funding outputs when needed.

func Faucet

func Faucet() *StateManager

Faucet gets the faucet component instance the faucet plugin has initialized.

func NewStateManager added in v0.5.4

func NewStateManager(
	tokensPerRequest uint64,
	seed *walletseed.Seed,
	preparedOutputsCount uint64,
	maxTxBookedTime time.Duration,
) *StateManager

NewStateManager creates a new state manager for the faucet.

func (*StateManager) DeriveStateFromTangle added in v0.5.4

func (s *StateManager) DeriveStateFromTangle(startIndex int) (err error)

DeriveStateFromTangle derives the faucet state from a synchronized Tangle.

  • startIndex defines from which address index to start look for prepared outputs.
  • remainder output should always sit on address 0.
  • if no funding outputs are found, the faucet creates them from the remainder output.

func (*StateManager) FulFillFundingRequest added in v0.5.4

func (s *StateManager) FulFillFundingRequest(requestMsg *tangle.Message) (m *tangle.Message, txID string, err error)

FulFillFundingRequest fulfills a faucet request by spending the next funding output to the requested address. Mana of the transaction is pledged to the requesting node.

func (*StateManager) FundingOutputsCount added in v0.5.4

func (s *StateManager) FundingOutputsCount() int

FundingOutputsCount returns the number of available outputs that can be used to fund a request.

Jump to

Keyboard shortcuts

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