contract

package
v1.8.7-dev Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: MIT Imports: 19 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,
	futuresStore *contracts.FuturesEthereum,
	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,
	validatorURL *url.URL,
	contractDuration time.Duration,
	contractHashrateGHPS float64,
) (*ContractFactory, error)

func (*ContractFactory) CreateContract

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

func (*ContractFactory) CreateFuturesContractBuyer added in v1.9.0

func (c *ContractFactory) CreateFuturesContractBuyer(contractData *contracts.FuturesContract) (resources.Contract, error)

func (*ContractFactory) CreateFuturesContractSeller added in v1.9.0

func (c *ContractFactory) CreateFuturesContractSeller(contractData *contracts.FuturesContract) (resources.Contract, error)

func (*ContractFactory) GetType

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

type ContractWatcherBuyer

type ContractWatcherBuyer struct {

	//deps
	Terms
	// contains filtered or unexported fields
}

func NewContractWatcherBuyer

func NewContractWatcherBuyer(
	terms 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 Terms)

func (*ContractWatcherBuyer) SetError

func (p *ContractWatcherBuyer) SetError(err error)

func (*ContractWatcherBuyer) StartFulfilling

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

func (*ContractWatcherBuyer) Started added in v1.9.0

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

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
	Terms
	// contains filtered or unexported fields
}

func NewContractWatcherSellerV2

func NewContractWatcherSellerV2(terms 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 Terms)

terms setters

func (*ContractWatcherSellerV2) ShouldBeRunning

func (p *ContractWatcherSellerV2) ShouldBeRunning() bool

func (*ContractWatcherSellerV2) StartFulfilling

func (p *ContractWatcherSellerV2) StartFulfilling() error

func (*ContractWatcherSellerV2) Started added in v1.9.0

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

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) Stop added in v1.9.0

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

func (*ControllerBuyer) SyncState

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

type ControllerFuturesBuyer added in v1.9.0

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

func NewControllerFuturesBuyer added in v1.9.0

func NewControllerFuturesBuyer(contract *ContractWatcherBuyer, store *contracts.FuturesEthereum, deliveryAt time.Time, privKey string, autoClaimReward bool) *ControllerFuturesBuyer

func (*ControllerFuturesBuyer) Run added in v1.9.0

func (*ControllerFuturesBuyer) Stop added in v1.9.0

func (*ControllerFuturesBuyer) SyncState added in v1.9.0

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

type ControllerFuturesSeller added in v1.9.0

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

func NewControllerFuturesSeller added in v1.9.0

func NewControllerFuturesSeller(contract *ContractWatcherSellerV2, deliveryAt time.Time) *ControllerFuturesSeller

func (*ControllerFuturesSeller) Run added in v1.9.0

func (*ControllerFuturesSeller) Stop added in v1.9.0

func (*ControllerFuturesSeller) SyncState added in v1.9.0

func (c *ControllerFuturesSeller) 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) Stop added in v1.9.0

func (c *ControllerSeller) Stop(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
}

type Terms added in v1.9.0

type Terms interface {
	ID() string
	BlockchainState() hashrate.BlockchainState
	Seller() string
	Buyer() string
	Validator() string
	StartTime() time.Time
	EndTime() time.Time
	Duration() time.Duration
	HashrateGHS() float64
	Balance() *big.Int
	Dest() *url.URL
	PoolDest() *url.URL
	Elapsed() time.Duration
	HasFutureTerms() bool
	IsDeleted() bool
	Price() *big.Int
	ProfitTarget() int8
	Version() uint32
	ResetStartTime()
}

Jump to

Keyboard shortcuts

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