contracts

package
v1.9.1-dev Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const RECONNECT_TIMEOUT = 2 * time.Second

Variables

View Source
var (
	ErrNoEventSignature       = errors.New("no event signature")
	ErrEventSignatureMismatch = errors.New("event signature mismatch")
)

AllContractsMeta is an array of all contracts metadata to be used for decoding errors

View Source
var (
	ErrNotRunning = fmt.Errorf("the contract is not in the running state")
)
View Source
var (
	ErrUnknownEvent = errors.New("unknown event")
)
View Source
var (
	SubClosedError = errors.New("subscription closed")
)

Functions

func CreateEventMapper

func CreateEventMapper(eventFactory EventFactory, abi *abi.ABI) func(log types.Log) (interface{}, error)

func GetOngoingDeliveryRange added in v1.9.0

func GetOngoingDeliveryRange(firstDeliveryDate time.Time, deliveryInterval time.Duration, now time.Time) (start time.Time, end time.Time)

func UnpackLog

func UnpackLog(out interface{}, event string, log types.Log, ab *abi.ABI) error

UnpackLog unpacks the log into the provided struct, copied from go-ethereum implementation

Types

type CloseDeliveryReq added in v1.9.0

type CloseDeliveryReq struct {
	PositionID  common.Hash
	BlameSeller bool
}

type CloseListererFunc

type CloseListererFunc = func()

type CloseReason

type CloseReason uint8
const (
	CloseReasonUnspecified            CloseReason = 0
	CloseReasonUnderdelivery          CloseReason = 1
	CloseReasonDestinationUnavailable CloseReason = 2
	CloseReasonShareTimeout           CloseReason = 3
)

type CloseoutType

type CloseoutType uint8
const (
	CloseoutTypeCancel       CloseoutType = 0 // to be triggered by the buyer or validator if a contract needs to be canceled early for any reason
	CloseoutTypeOnlyWithdraw CloseoutType = 1 // to be triggered by the seller to withdraw funds at any time during the smart contracts lifecycle (contract is not closing)
	CloseoutTypeWithoutClaim CloseoutType = 2 // closeout without claiming funds
	CloseoutTypeWithClaim    CloseoutType = 3 // closeout with claiming funds
)

type ContractSpecs added in v1.9.0

type ContractSpecs struct {
	ValidatorAddress common.Address
	ValidatorURL     *url.URL
	DeliveryDuration time.Duration
	SpeedHps         uint64
}

type DataAccess

type DataAccess interface {
	// string used as address cause different blockchains may return different type of addresses
	GetContractsIDs() ([]string, error)
	GetContract(contractID string) (interface{}, error)
	CloseContract(contractID string, meta interface{}) error

	OnNewContract(func(contractID string)) CloseListererFunc
	OnContractUpdated(contractID string, cb func()) CloseListererFunc
	OnContractClosed(contractID string, cb func()) CloseListererFunc
}

type EthereumClient

type EthereumClient interface {
	bind.ContractBackend
	bind.DeployBackend
	ChainID(ctx context.Context) (*big.Int, error)
	BalanceAt(ctx context.Context, addr common.Address, blockNumber *big.Int) (*big.Int, error)
	StorageAt(ctx context.Context, account common.Address, key common.Hash, blockNumber *big.Int) ([]byte, error)
}

type EventFactory

type EventFactory func(name string) interface{}

type EventMapper

type EventMapper func(types.Log) (interface{}, error)

type FuturesContract added in v1.9.0

type FuturesContract struct {
	ContractID common.Hash
	Seller     common.Address
	Buyer      common.Address
	DestURL    string
	DeliveryAt time.Time
	Paid       bool
}

func (*FuturesContract) ID added in v1.9.0

func (fc *FuturesContract) ID() string

type FuturesEthereum added in v1.9.0

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

func NewFuturesEthereum added in v1.9.0

func NewFuturesEthereum(futuresAddr common.Address, multicalladdr common.Address, client EthereumClient, logWatcher LogWatcher, log interfaces.ILogger) *FuturesEthereum

func (*FuturesEthereum) BatchCloseDelivery added in v1.9.0

func (g *FuturesEthereum) BatchCloseDelivery(ctx context.Context, reqs []CloseDeliveryReq, privKey string) error

func (*FuturesEthereum) ClaimReward added in v1.9.0

func (g *FuturesEthereum) ClaimReward(ctx context.Context, deliveryDate time.Time, privKey string) error

func (*FuturesEthereum) CloseDelivery added in v1.9.0

func (g *FuturesEthereum) CloseDelivery(ctx context.Context, positionID common.Hash, blameSeller bool, privKey string) error

func (*FuturesEthereum) CreateFuturesSubscription added in v1.9.0

func (g *FuturesEthereum) CreateFuturesSubscription(ctx context.Context, futuresAddr common.Address) (*lib.Subscription, error)

func (*FuturesEthereum) GetContractSpecs added in v1.9.0

func (g *FuturesEthereum) GetContractSpecs(ctx context.Context) (*ContractSpecs, error)

func (*FuturesEthereum) GetMatchedContracts added in v1.9.0

func (g *FuturesEthereum) GetMatchedContracts(ctx context.Context, userAddress common.Address, deliveryDate time.Time) ([]FuturesContract, error)

func (*FuturesEthereum) GetOngoingDeliveryRange added in v1.9.0

func (g *FuturesEthereum) GetOngoingDeliveryRange(ctx context.Context) (start time.Time, end time.Time, duration time.Duration, err error)

GetOngoingDeliveryRange returns the start and end of the ongoing delivery range

func (*FuturesEthereum) GetPosition added in v1.9.0

func (g *FuturesEthereum) GetPosition(ctx context.Context, positionID common.Hash) (*FuturesContract, error)

func (*FuturesEthereum) GetToken added in v1.9.0

func (g *FuturesEthereum) GetToken(ctx context.Context) (common.Address, error)

func (*FuturesEthereum) SetLegacyTx added in v1.9.0

func (g *FuturesEthereum) SetLegacyTx(legacyTx bool)

type HashrateEthereum

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

func NewHashrateEthereum

func NewHashrateEthereum(clonefactoryAddr common.Address, client EthereumClient, logWatcher LogWatcher, log interfaces.ILogger) *HashrateEthereum

func (*HashrateEthereum) ClaimValidatorReward

func (g *HashrateEthereum) ClaimValidatorReward(ctx context.Context, contractID string, privKey string) error

func (*HashrateEthereum) CreateCloneFactorySubscription

func (s *HashrateEthereum) CreateCloneFactorySubscription(ctx context.Context, clonefactoryAddr common.Address) (*lib.Subscription, error)

func (*HashrateEthereum) CreateImplementationSubscription

func (s *HashrateEthereum) CreateImplementationSubscription(ctx context.Context, contractAddr common.Address) (*lib.Subscription, error)

func (*HashrateEthereum) EarlyClose

func (g *HashrateEthereum) EarlyClose(ctx context.Context, contractID string, reason CloseReason, privKey string) error

func (*HashrateEthereum) GetContract

func (g *HashrateEthereum) GetContract(ctx context.Context, contractID string) (*hashrate.EncryptedTerms, error)

func (*HashrateEthereum) GetContractsIDs

func (g *HashrateEthereum) GetContractsIDs(ctx context.Context) ([]string, error)

func (*HashrateEthereum) GetFeeToken added in v1.8.0

func (g *HashrateEthereum) GetFeeToken(ctx context.Context) (common.Address, error)

func (*HashrateEthereum) GetPaymentToken added in v1.8.0

func (g *HashrateEthereum) GetPaymentToken(ctx context.Context) (common.Address, error)

func (*HashrateEthereum) SetLegacyTx

func (g *HashrateEthereum) SetLegacyTx(legacyTx bool)

type LogWatcher added in v1.9.0

type LogWatcher interface {
	Watch(ctx context.Context, contractAddr common.Address, mapper EventMapper, fromBlock *big.Int) (*lib.Subscription, error)
}

type LogWatcherPolling added in v1.9.0

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

func NewLogWatcherPolling added in v1.9.0

func NewLogWatcherPolling(client i.EthClient, pollInterval time.Duration, maxReconnects int, log i.ILogger) *LogWatcherPolling

func (*LogWatcherPolling) Watch added in v1.9.0

func (w *LogWatcherPolling) Watch(ctx context.Context, contractAddr common.Address, mapper EventMapper, fromBlock *big.Int) (*lib.Subscription, error)

type LogWatcherSubscription added in v1.9.0

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

func NewLogWatcherSubscription added in v1.9.0

func NewLogWatcherSubscription(client i.EthClient, maxReconnects int, log i.ILogger) *LogWatcherSubscription

NewLogWatcherSubscription creates a new log subscription using websocket TODO: if it is going to be primary implementation we should rewrite it so it doesn't skip events in case of temporary downtime

func (*LogWatcherSubscription) Watch added in v1.9.0

func (w *LogWatcherSubscription) Watch(ctx context.Context, contractAddr common.Address, mapper EventMapper, fromBlock *big.Int) (*lib.Subscription, error)

Jump to

Keyboard shortcuts

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