contracts

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 RECONNECT_TIMEOUT = 2 * time.Second

Variables

View Source
var (
	ErrNoEventSignature       = errors.New("no event signature")
	ErrEventSignatureMismatch = errors.New("event signature mismatch")
)
View Source
var (
	ErrNotRunning = fmt.Errorf("the contract is not in the running state")
)
View Source
var (
	ErrUnknownEvent = errors.New("unknown event")
)

Functions

func CreateEventMapper

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

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

func WatchContractEvents

func WatchContractEvents(ctx context.Context, client EthereumClient, contractAddr common.Address, mapper EventMapper, log interfaces.ILogger) (*lib.Subscription, error)

WatchContractEvents watches for all events from the contract and converts them to the concrete type, using mapper

Types

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 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 HashrateEthereum

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

func NewHashrateEthereum

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

func (*HashrateEthereum) ClaimValidatorReward

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

func (*HashrateEthereum) CloseContract

func (g *HashrateEthereum) CloseContract(ctx context.Context, contractID string, closeoutType CloseoutType, 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) GetLumerinAddress

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

func (*HashrateEthereum) PurchaseContract

func (g *HashrateEthereum) PurchaseContract(ctx context.Context, contractID string, privKey string, version int) error

func (*HashrateEthereum) SetLegacyTx

func (g *HashrateEthereum) SetLegacyTx(legacyTx bool)

Jump to

Keyboard shortcuts

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