contract

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ResourceTypeHashrate        = "hashrate"
	ResourceEstimateHashrateGHS = "hashrate_ghs"
)

Variables

View Source
var (
	ErrContractDest  = errors.New("contract destination error")
	ErrShareTimeout  = errors.New("share timeout")
	ErrUnderdelivery = errors.New("contract is not delivering enough hashrate")
)
View Source
var (
	ErrNotRunningBlockchain = fmt.Errorf("contract is not running in blockchain")
	ErrStopped              = fmt.Errorf("contract is stopped")
	ErrAlreadyRunning       = fmt.Errorf("contract is already running")
)
View Source
var (
	AdjustmentThresholdGHS = 100.0
)
View Source
var (
	ErrContractClosed = errors.New("contract closed")
)

Functions

func GetMaxGlobalError

func GetMaxGlobalError(elapsed time.Duration, minError float64, flatness, skipPeriod time.Duration) float64

Types

type ContractFactory

type ContractFactory struct {
	// contains filtered or unexported fields
}

func NewContractFactory

func NewContractFactory(
	allocator *allocator.Allocator,
	hashrateFactory func() *hashrate.Hashrate,
	globalHashrate *hashrate.GlobalHashrate,
	store *contracts.HashrateEthereum,
	logFactory func(contractID string) (interfaces.ILogger, error),

	privateKey string,
	cycleDuration time.Duration,
	shareTimeout time.Duration,
	hrErrorThreshold float64,
	hashrateCounterNameBuyer string,
	validatorFlatness time.Duration,
	validatorStartTime time.Time,
	defaultDest *url.URL,
) (*ContractFactory, error)

func (*ContractFactory) CreateContract

func (c *ContractFactory) CreateContract(contractData *hashrateContract.EncryptedTerms) (resources.Contract, error)

func (*ContractFactory) GetType

func (c *ContractFactory) GetType() resources.ResourceType

type ContractWatcherBuyer

type ContractWatcherBuyer struct {

	//deps
	*hashrateContract.Terms
	// contains filtered or unexported fields
}

func NewContractWatcherBuyer

func NewContractWatcherBuyer(
	terms *hashrateContract.Terms,
	hashrateFactory func() *hashrate.Hashrate,
	allocator *allocator.Allocator,
	globalHashrate *hashrate.GlobalHashrate,
	log interfaces.ILogger,

	cycleDuration time.Duration,
	shareTimeout time.Duration,
	hrErrorThreshold float64,
	hashrateCounterNameBuyer string,
	hrValidationFlatness time.Duration,
	validatorStartTime time.Time,
	role resources.ContractRole,
	defaultDest *url.URL,
) *ContractWatcherBuyer

func (*ContractWatcherBuyer) Dest

func (p *ContractWatcherBuyer) Dest() string

func (*ContractWatcherBuyer) Done

func (p *ContractWatcherBuyer) Done() <-chan struct{}

func (*ContractWatcherBuyer) Err

func (p *ContractWatcherBuyer) Err() error

func (*ContractWatcherBuyer) Error

func (p *ContractWatcherBuyer) Error() error

func (*ContractWatcherBuyer) FulfillmentStartTime

func (p *ContractWatcherBuyer) FulfillmentStartTime() time.Time

func (*ContractWatcherBuyer) PoolDest

func (p *ContractWatcherBuyer) PoolDest() string

func (*ContractWatcherBuyer) ResourceEstimates

func (p *ContractWatcherBuyer) ResourceEstimates() map[string]float64

func (*ContractWatcherBuyer) ResourceEstimatesActual

func (p *ContractWatcherBuyer) ResourceEstimatesActual() map[string]float64

func (*ContractWatcherBuyer) ResourceType

func (p *ContractWatcherBuyer) ResourceType() string

func (*ContractWatcherBuyer) Role

func (*ContractWatcherBuyer) SetData

func (p *ContractWatcherBuyer) SetData(terms *hashrateContract.Terms)

func (*ContractWatcherBuyer) SetError

func (p *ContractWatcherBuyer) SetError(err error)

func (*ContractWatcherBuyer) StartFulfilling

func (p *ContractWatcherBuyer) StartFulfilling(ctx context.Context)

func (*ContractWatcherBuyer) StarvingGHS

func (p *ContractWatcherBuyer) StarvingGHS() int

func (*ContractWatcherBuyer) State

func (*ContractWatcherBuyer) StopFulfilling

func (p *ContractWatcherBuyer) StopFulfilling()

func (*ContractWatcherBuyer) ValidationStage

type ContractWatcherSellerV2

type ContractWatcherSellerV2 struct {

	// deps
	*hashrate.Terms
	// contains filtered or unexported fields
}

func NewContractWatcherSellerV2

func NewContractWatcherSellerV2(terms *hashrateContract.Terms, cycleDuration time.Duration, hashrateFactory func() *hr.Hashrate, allocator *allocator.Allocator, log interfaces.ILogger) *ContractWatcherSellerV2

func (*ContractWatcherSellerV2) Dest

func (p *ContractWatcherSellerV2) Dest() string

terms getters

func (*ContractWatcherSellerV2) Done

func (p *ContractWatcherSellerV2) Done() <-chan struct{}

func (*ContractWatcherSellerV2) Err

func (p *ContractWatcherSellerV2) Err() error

func (*ContractWatcherSellerV2) Error

func (p *ContractWatcherSellerV2) Error() error

func (*ContractWatcherSellerV2) FulfillmentStartTime

func (p *ContractWatcherSellerV2) FulfillmentStartTime() time.Time

state getters

func (*ContractWatcherSellerV2) GetDeliveryLogs

func (p *ContractWatcherSellerV2) GetDeliveryLogs() ([]DeliveryLogEntry, error)

func (*ContractWatcherSellerV2) IsRunning

func (p *ContractWatcherSellerV2) IsRunning() bool

func (*ContractWatcherSellerV2) PoolDest

func (p *ContractWatcherSellerV2) PoolDest() string

func (*ContractWatcherSellerV2) Reset

func (p *ContractWatcherSellerV2) Reset()

Reset resets the contract state

func (*ContractWatcherSellerV2) ResourceEstimates

func (p *ContractWatcherSellerV2) ResourceEstimates() map[string]float64

func (*ContractWatcherSellerV2) ResourceEstimatesActual

func (p *ContractWatcherSellerV2) ResourceEstimatesActual() map[string]float64

func (*ContractWatcherSellerV2) ResourceType

func (p *ContractWatcherSellerV2) ResourceType() string

func (*ContractWatcherSellerV2) Role

constants

func (*ContractWatcherSellerV2) SetError

func (p *ContractWatcherSellerV2) SetError(err error)

func (*ContractWatcherSellerV2) SetTerms

func (p *ContractWatcherSellerV2) SetTerms(terms *hashrate.Terms)

terms setters

func (*ContractWatcherSellerV2) ShouldBeRunning

func (p *ContractWatcherSellerV2) ShouldBeRunning() bool

func (*ContractWatcherSellerV2) StartFulfilling

func (p *ContractWatcherSellerV2) StartFulfilling() error

func (*ContractWatcherSellerV2) StarvingGHS

func (p *ContractWatcherSellerV2) StarvingGHS() int

func (*ContractWatcherSellerV2) State

func (*ContractWatcherSellerV2) StopFulfilling

func (p *ContractWatcherSellerV2) StopFulfilling()

func (*ContractWatcherSellerV2) ValidationStage

type ControllerBuyer

type ControllerBuyer struct {
	*ContractWatcherBuyer
	// contains filtered or unexported fields
}

func NewControllerBuyer

func NewControllerBuyer(contract *ContractWatcherBuyer, store *contracts.HashrateEthereum, privKey string, autoClaimReward bool) *ControllerBuyer

func (*ControllerBuyer) LoadTermsFromBlockchain

func (c *ControllerBuyer) LoadTermsFromBlockchain(ctx context.Context) error

LoadTermsFromBlockchain loads terms from blockchain and decrypts destination pool if exists

func (*ControllerBuyer) Run

func (c *ControllerBuyer) Run(ctx context.Context) error

func (*ControllerBuyer) SyncState

func (c *ControllerBuyer) SyncState(ctx context.Context) error

type ControllerSeller

type ControllerSeller struct {
	*ContractWatcherSellerV2
	// contains filtered or unexported fields
}

func NewControllerSeller

func NewControllerSeller(contract *ContractWatcherSellerV2, store *contracts.HashrateEthereum, privKey string) *ControllerSeller

func (*ControllerSeller) GetTermsFromBlockchain

func (c *ControllerSeller) GetTermsFromBlockchain(ctx context.Context) (*hashrateContract.Terms, error)

func (*ControllerSeller) LoadTermsFromBlockchain

func (c *ControllerSeller) LoadTermsFromBlockchain(ctx context.Context) error

LoadTermsFromBlockchain loads terms from blockchain and decrypts them, if decryption fails, still updates terms with nil dest

func (*ControllerSeller) Run

func (c *ControllerSeller) Run(ctx context.Context) error

func (*ControllerSeller) SyncState

func (c *ControllerSeller) SyncState(ctx context.Context) error

type DeliveryLog

type DeliveryLog struct {
	Entries []DeliveryLogEntry
	// contains filtered or unexported fields
}

func NewDeliveryLog

func NewDeliveryLog() *DeliveryLog

func (*DeliveryLog) AddEntry

func (l *DeliveryLog) AddEntry(entry DeliveryLogEntry)

func (*DeliveryLog) GetEntries

func (l *DeliveryLog) GetEntries() ([]DeliveryLogEntry, error)

type DeliveryLogEntry

type DeliveryLogEntry struct {
	Timestamp                         time.Time
	ActualGHS                         int
	FullMinersGHS                     int
	FullMiners                        []string
	FullMinersShares                  int
	PartialMinersGHS                  int
	PartialMiners                     []string
	PartialMinersShares               int
	UnderDeliveryGHS                  int
	GlobalHashrateGHS                 int
	GlobalUnderDeliveryGHS            int
	GlobalError                       float64
	NextCyclePartialDeliveryTargetGHS int
}

Jump to

Keyboard shortcuts

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