eth

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2020 License: MIT Imports: 25 Imported by: 0

README

Generating Go bindings for contracts

The contracts folder contains Go bindings for the Livepeer protocol smart contracts generated using the abigen tool.

If the smart contracts are updated you can generate new Go bindings by doing the following:

cd $GOPATH/src/github.com/livepeer/go-livepeer/eth
git clone https://github.com/livepeer/protocol.git $GOPATH/src/github.com/livepeer/go-livepeer/eth/protocol
cd $GOPATH/src/github.com/livepeer/go-livepeer/eth/protocol
npm install
npm run compile
node scripts/parseArtifacts.js
cd $GOPATH/src/github.com/livepeer/go-livepeer/eth
go generate client.go

Documentation

Overview

Package eth client is the go client for the Livepeer Ethereum smart contract. Contracts here are generated.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAccountNotFound    = fmt.Errorf("ETH account not found")
	ErrLocked             = fmt.Errorf("account locked")
	ErrPassphraseMismatch = fmt.Errorf("passphrases do not match")
)
View Source
var (
	ErrReplacingMinedTx   = fmt.Errorf("trying to replace already mined tx")
	ErrCurrentRoundLocked = fmt.Errorf("current round locked")
	ErrMissingBackend     = fmt.Errorf("missing Ethereum client backend")
)
View Source
var (
	BlocksUntilFirstClaimDeadline = big.NewInt(200)
)

Functions

func FormatPerc added in v0.3.3

func FormatPerc(value *big.Int) string

func FormatUnits added in v0.3.3

func FormatUnits(baseAmount *big.Int, name string) string

func FromBaseAmount added in v0.5.2

func FromBaseAmount(v *big.Int) string

func FromPerc added in v0.3.3

func FromPerc(perc float64) *big.Int

func FromPercOfUint256 added in v0.5.0

func FromPercOfUint256(perc float64) *big.Int

func IsNullAddress

func IsNullAddress(addr ethcommon.Address) bool

func ToBaseAmount added in v0.5.2

func ToBaseAmount(v string) (*big.Int, error)

func ToPerc added in v0.3.3

func ToPerc(value *big.Int) float64

func Wait

func Wait(db *common.DB, blocks *big.Int) error

Types

type AccountManager added in v0.3.3

type AccountManager interface {
	Unlock(passphrase string) error
	Lock() error
	CreateTransactOpts(gasLimit uint64, gasPrice *big.Int) (*bind.TransactOpts, error)
	SignTx(tx *types.Transaction) (*types.Transaction, error)
	Sign(msg []byte) ([]byte, error)
	Account() accounts.Account
}

func NewAccountManager added in v0.3.3

func NewAccountManager(accountAddr ethcommon.Address, keystoreDir string, signer types.Signer) (AccountManager, error)

type BlockHashReader added in v0.5.0

type BlockHashReader interface {
	LastInitializedBlockHash() [32]byte
}

BlockHashReader describes methods for reading the last initialized block hash

type BlockNumReader added in v0.5.0

type BlockNumReader interface {
	LastSeenBlock() (*big.Int, error)
}

BlockNumReader describes methods for reading the last seen block number

type GasPriceMonitor added in v0.5.0

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

GasPriceMonitor polls for gas price updates and updates its own view of the current gas price that can be used by others

func NewGasPriceMonitor added in v0.5.0

func NewGasPriceMonitor(gpo GasPriceOracle, pollingInterval time.Duration) *GasPriceMonitor

NewGasPriceMonitor returns a GasPriceMonitor

func (*GasPriceMonitor) GasPrice added in v0.5.0

func (gpm *GasPriceMonitor) GasPrice() *big.Int

GasPrice returns the current gas price

func (*GasPriceMonitor) Start added in v0.5.0

func (gpm *GasPriceMonitor) Start(ctx context.Context) (chan struct{}, error)

Start starts polling for gas price updates and returns a channel to receive notifications of gas price changes

func (*GasPriceMonitor) Stop added in v0.5.0

func (gpm *GasPriceMonitor) Stop() error

Stop stops polling for gas price updates

type GasPriceOracle added in v0.5.0

type GasPriceOracle interface {
	SuggestGasPrice(ctx context.Context) (*big.Int, error)
}

GasPriceOracle defines methods for fetching a suggested gas price for submitting transactions

type LivepeerEthClient

type LivepeerEthClient interface {
	Setup(password string, gasLimit uint64, gasPrice *big.Int) error
	Account() accounts.Account
	Backend() (Backend, error)

	// Rounds
	InitializeRound() (*types.Transaction, error)
	CurrentRound() (*big.Int, error)
	LastInitializedRound() (*big.Int, error)
	BlockHashForRound(round *big.Int) ([32]byte, error)
	CurrentRoundInitialized() (bool, error)
	CurrentRoundLocked() (bool, error)
	CurrentRoundStartBlock() (*big.Int, error)

	// Token
	Transfer(toAddr ethcommon.Address, amount *big.Int) (*types.Transaction, error)
	Request() (*types.Transaction, error)
	NextValidRequest(addr ethcommon.Address) (*big.Int, error)
	BalanceOf(ethcommon.Address) (*big.Int, error)
	TotalSupply() (*big.Int, error)

	// Service Registry
	SetServiceURI(serviceURI string) (*types.Transaction, error)
	GetServiceURI(addr ethcommon.Address) (string, error)

	// Staking
	Transcoder(blockRewardCut, feeShare *big.Int) (*types.Transaction, error)
	Reward() (*types.Transaction, error)
	Bond(amount *big.Int, toAddr ethcommon.Address) (*types.Transaction, error)
	Rebond(unbondingLockID *big.Int) (*types.Transaction, error)
	RebondFromUnbonded(toAddr ethcommon.Address, unbondingLockID *big.Int) (*types.Transaction, error)
	Unbond(amount *big.Int) (*types.Transaction, error)
	WithdrawStake(unbondingLockID *big.Int) (*types.Transaction, error)
	WithdrawFees() (*types.Transaction, error)
	ClaimEarnings(endRound *big.Int) error
	GetTranscoder(addr ethcommon.Address) (*lpTypes.Transcoder, error)
	GetDelegator(addr ethcommon.Address) (*lpTypes.Delegator, error)
	GetDelegatorUnbondingLock(addr ethcommon.Address, unbondingLockId *big.Int) (*lpTypes.UnbondingLock, error)
	GetTranscoderEarningsPoolForRound(addr ethcommon.Address, round *big.Int) (*lpTypes.TokenPools, error)
	TranscoderPool() ([]*lpTypes.Transcoder, error)
	IsActiveTranscoder() (bool, error)
	GetTotalBonded() (*big.Int, error)
	GetTranscoderPoolSize() (*big.Int, error)

	// TicketBroker
	FundDepositAndReserve(depositAmount, penaltyEscrowAmount *big.Int) (*types.Transaction, error)
	FundDeposit(amount *big.Int) (*types.Transaction, error)
	FundReserve(amount *big.Int) (*types.Transaction, error)
	Unlock() (*types.Transaction, error)
	CancelUnlock() (*types.Transaction, error)
	Withdraw() (*types.Transaction, error)
	RedeemWinningTicket(ticket *pm.Ticket, sig []byte, recipientRand *big.Int) (*types.Transaction, error)
	IsUsedTicket(ticket *pm.Ticket) (bool, error)
	GetSenderInfo(addr ethcommon.Address) (*pm.SenderInfo, error)
	UnlockPeriod() (*big.Int, error)
	ClaimedReserve(reserveHolder ethcommon.Address, claimant ethcommon.Address) (*big.Int, error)

	// Parameters
	GetTranscoderPoolMaxSize() (*big.Int, error)
	RoundLength() (*big.Int, error)
	RoundLockAmount() (*big.Int, error)
	UnbondingPeriod() (uint64, error)
	Inflation() (*big.Int, error)
	InflationChange() (*big.Int, error)
	TargetBondingRate() (*big.Int, error)
	Paused() (bool, error)

	// Helpers
	ContractAddresses() map[string]ethcommon.Address
	CheckTx(*types.Transaction) error
	ReplaceTransaction(*types.Transaction, string, *big.Int) (*types.Transaction, error)
	Sign([]byte) ([]byte, error)
	GetGasInfo() (uint64, *big.Int)
	SetGasInfo(uint64, *big.Int) error
}

func NewClient

func NewClient(accountAddr ethcommon.Address, keystoreDir string, eth *ethclient.Client, controllerAddr ethcommon.Address, txTimeout time.Duration) (LivepeerEthClient, error)

type MockClient added in v0.5.0

type MockClient struct {
	mock.Mock

	// Embed StubClient to call its methods with MockClient
	// as the receiver so that MockClient implements the LivepeerETHClient
	// interface
	*StubClient
}

func (*MockClient) Account added in v0.5.0

func (m *MockClient) Account() accounts.Account

func (*MockClient) CancelUnlock added in v0.5.0

func (m *MockClient) CancelUnlock() (*types.Transaction, error)

func (*MockClient) CheckTx added in v0.5.0

func (m *MockClient) CheckTx(tx *types.Transaction) error

func (*MockClient) CurrentRound added in v0.5.0

func (m *MockClient) CurrentRound() (*big.Int, error)

CurrentRound returns the current round number

func (*MockClient) CurrentRoundInitialized added in v0.5.0

func (m *MockClient) CurrentRoundInitialized() (bool, error)

CurrentRoundInitialized returns whether the current round is initialized

func (*MockClient) CurrentRoundStartBlock added in v0.5.0

func (m *MockClient) CurrentRoundStartBlock() (*big.Int, error)

CurrentRoundStartBlock returns the block number that the current round started in

func (*MockClient) FundDeposit added in v0.5.0

func (m *MockClient) FundDeposit(amount *big.Int) (*types.Transaction, error)

func (*MockClient) FundDepositAndReserve added in v0.5.0

func (m *MockClient) FundDepositAndReserve(depositAmount, reserveAmount *big.Int) (*types.Transaction, error)

func (*MockClient) GetSenderInfo added in v0.5.0

func (m *MockClient) GetSenderInfo(addr common.Address) (*pm.SenderInfo, error)

func (*MockClient) GetTranscoderPoolMaxSize added in v0.5.0

func (m *MockClient) GetTranscoderPoolMaxSize() (*big.Int, error)

GetTranscoderPoolMaxSize returns the max size of the active set

func (*MockClient) InitializeRound added in v0.5.0

func (m *MockClient) InitializeRound() (*types.Transaction, error)

InitializeRound submits a round initialization transaction

func (*MockClient) Senders added in v0.5.0

func (m *MockClient) Senders(addr common.Address) (sender struct {
	Deposit       *big.Int
	WithdrawRound *big.Int
}, err error)

func (*MockClient) TranscoderPool added in v0.5.1

func (m *MockClient) TranscoderPool() ([]*lpTypes.Transcoder, error)

TranscoderPool returns a list of registered transcoders

func (*MockClient) Unlock added in v0.5.0

func (m *MockClient) Unlock() (*types.Transaction, error)

func (*MockClient) UnlockPeriod added in v0.5.0

func (m *MockClient) UnlockPeriod() (*big.Int, error)

func (*MockClient) Withdraw added in v0.5.0

func (m *MockClient) Withdraw() (*types.Transaction, error)

type NonceManager added in v0.5.0

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

NonceManager manages transaction nonces for multiple ETH addresses

func NewNonceManager added in v0.5.0

func NewNonceManager(remoteReader RemoteNonceReader) *NonceManager

NewNonceManager creates an instance of a NonceManager

func (*NonceManager) Lock added in v0.5.0

func (m *NonceManager) Lock(addr ethcommon.Address)

Lock locks the provided address. The caller should always call Lock before calling Next or Update

func (*NonceManager) Next added in v0.5.0

func (m *NonceManager) Next(addr ethcommon.Address) (uint64, error)

Next returns the next transaction nonce to be used for the provided address

func (*NonceManager) Unlock added in v0.5.0

func (m *NonceManager) Unlock(addr ethcommon.Address)

Unlock unlocks the provided address. The caller should always call Unlock after finishing calls to Next or Update

func (*NonceManager) Update added in v0.5.0

func (m *NonceManager) Update(addr ethcommon.Address, lastNonce uint64)

Update uses the last nonce for the provided address to update the next transaction nonce

type RemoteNonceReader added in v0.5.0

type RemoteNonceReader interface {
	PendingNonceAt(ctx context.Context, addr ethcommon.Address) (uint64, error)
}

RemoteNonceReader is an interface that describes an object capable of reading transaction nonces for ETH address from a remote source

type RoundInitializer added in v0.5.0

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

RoundInitializer is a service that automatically initializes the current round. Each round is split into epochs with a length of epochBlocks. During each epoch a member of the upcoming active set is selected to initialize the round This selection process is purely a client side implementation that attempts to minimize on-chain transaction collisions, but collisions are still possible if initialization transactions are submitted by parties that are not using this selection process

func NewRoundInitializer added in v0.5.0

func NewRoundInitializer(client LivepeerEthClient, blkNumRdr BlockNumReader, blkHashRdr BlockHashReader, pollingInterval time.Duration) *RoundInitializer

NewRoundInitializer creates a RoundInitializer instance

func (*RoundInitializer) Start added in v0.5.0

func (r *RoundInitializer) Start()

Start kicks off a loop that checks if the round should be initialized

func (*RoundInitializer) Stop added in v0.5.0

func (r *RoundInitializer) Stop()

Stop signals the polling loop to exit gracefully

type StubClient

type StubClient struct {
	SubLogsCh                    chan types.Log
	TranscoderAddress            common.Address
	BlockNum                     *big.Int
	BlockHashToReturn            common.Hash
	ProcessHistoricalUnbondError error
	Orchestrators                []*lpTypes.Transcoder
	RoundsErr                    error
	SenderInfo                   *pm.SenderInfo
	PoolSize                     *big.Int
	ClaimedAmount                *big.Int
	ClaimedReserveError          error
	Orch                         *lpTypes.Transcoder
	Err                          error
	TotalStake                   *big.Int
	TranscoderPoolError          error
}

func (*StubClient) Account

func (e *StubClient) Account() accounts.Account

func (*StubClient) Backend

func (e *StubClient) Backend() (Backend, error)

func (*StubClient) BalanceOf added in v0.3.3

func (e *StubClient) BalanceOf(addr common.Address) (*big.Int, error)

func (*StubClient) BlockHashForRound added in v0.5.0

func (e *StubClient) BlockHashForRound(round *big.Int) ([32]byte, error)

func (*StubClient) Bond

func (e *StubClient) Bond(amount *big.Int, toAddr common.Address) (*types.Transaction, error)

func (*StubClient) CancelUnlock added in v0.5.0

func (e *StubClient) CancelUnlock() (*types.Transaction, error)

func (*StubClient) CheckTx added in v0.3.3

func (c *StubClient) CheckTx(tx *types.Transaction) error

func (*StubClient) ClaimEarnings added in v0.3.3

func (e *StubClient) ClaimEarnings(endRound *big.Int) error

func (*StubClient) ClaimableReserve added in v0.5.0

func (e *StubClient) ClaimableReserve(reserveHolder, claimant ethcommon.Address) (*big.Int, error)

func (*StubClient) ClaimedReserve added in v0.5.0

func (e *StubClient) ClaimedReserve(sender ethcommon.Address, claimant ethcommon.Address) (*big.Int, error)

func (*StubClient) ContractAddresses added in v0.3.3

func (c *StubClient) ContractAddresses() map[string]common.Address

func (*StubClient) CurrentRound added in v0.3.3

func (e *StubClient) CurrentRound() (*big.Int, error)

func (*StubClient) CurrentRoundInitialized

func (e *StubClient) CurrentRoundInitialized() (bool, error)

func (*StubClient) CurrentRoundLocked added in v0.3.3

func (e *StubClient) CurrentRoundLocked() (bool, error)

func (*StubClient) CurrentRoundStartBlock added in v0.5.0

func (e *StubClient) CurrentRoundStartBlock() (*big.Int, error)

func (*StubClient) FundDeposit added in v0.5.0

func (e *StubClient) FundDeposit(amount *big.Int) (*types.Transaction, error)

func (*StubClient) FundDepositAndReserve added in v0.5.0

func (e *StubClient) FundDepositAndReserve(depositAmount, reserveAmount *big.Int) (*types.Transaction, error)

TicketBroker

func (*StubClient) FundReserve added in v0.5.0

func (e *StubClient) FundReserve(amount *big.Int) (*types.Transaction, error)

func (*StubClient) GetDelegator added in v0.3.3

func (e *StubClient) GetDelegator(addr common.Address) (*lpTypes.Delegator, error)

func (*StubClient) GetDelegatorUnbondingLock added in v0.3.3

func (e *StubClient) GetDelegatorUnbondingLock(addr common.Address, unbondingLockId *big.Int) (*lpTypes.UnbondingLock, error)

func (*StubClient) GetGasInfo added in v0.3.3

func (c *StubClient) GetGasInfo() (uint64, *big.Int)

func (*StubClient) GetSenderInfo added in v0.5.0

func (e *StubClient) GetSenderInfo(addr ethcommon.Address) (*pm.SenderInfo, error)

func (*StubClient) GetServiceURI added in v0.3.3

func (e *StubClient) GetServiceURI(addr common.Address) (string, error)

func (*StubClient) GetTotalBonded added in v0.3.3

func (e *StubClient) GetTotalBonded() (*big.Int, error)

func (*StubClient) GetTranscoder added in v0.3.3

func (e *StubClient) GetTranscoder(addr common.Address) (*lpTypes.Transcoder, error)

func (*StubClient) GetTranscoderEarningsPoolForRound added in v0.3.3

func (e *StubClient) GetTranscoderEarningsPoolForRound(addr common.Address, round *big.Int) (*lpTypes.TokenPools, error)

func (*StubClient) GetTranscoderPoolMaxSize added in v0.5.0

func (c *StubClient) GetTranscoderPoolMaxSize() (*big.Int, error)

Parameters

func (*StubClient) GetTranscoderPoolSize added in v0.5.0

func (e *StubClient) GetTranscoderPoolSize() (*big.Int, error)

func (*StubClient) Inflation added in v0.3.3

func (c *StubClient) Inflation() (*big.Int, error)

func (*StubClient) InflationChange added in v0.3.3

func (c *StubClient) InflationChange() (*big.Int, error)

func (*StubClient) InitializeRound

func (e *StubClient) InitializeRound() (*types.Transaction, error)

func (*StubClient) IsActiveTranscoder

func (e *StubClient) IsActiveTranscoder() (bool, error)

func (*StubClient) IsUsedTicket added in v0.5.0

func (e *StubClient) IsUsedTicket(ticket *pm.Ticket) (bool, error)

func (*StubClient) LastInitializedRound added in v0.3.3

func (e *StubClient) LastInitializedRound() (*big.Int, error)

func (*StubClient) NextValidRequest added in v0.5.2

func (c *StubClient) NextValidRequest(common.Address) (*big.Int, error)

Faucet

func (*StubClient) Paused added in v0.3.3

func (e *StubClient) Paused() (bool, error)

func (*StubClient) Rebond added in v0.3.3

func (e *StubClient) Rebond(*big.Int) (*types.Transaction, error)

func (*StubClient) RebondFromUnbonded added in v0.3.3

func (e *StubClient) RebondFromUnbonded(common.Address, *big.Int) (*types.Transaction, error)

func (*StubClient) RedeemWinningTicket added in v0.5.0

func (e *StubClient) RedeemWinningTicket(ticket *pm.Ticket, sig []byte, recipientRand *big.Int) (*types.Transaction, error)

func (*StubClient) ReplaceTransaction added in v0.3.3

func (c *StubClient) ReplaceTransaction(tx *types.Transaction, method string, gasPrice *big.Int) (*types.Transaction, error)

func (*StubClient) Request added in v0.3.3

func (e *StubClient) Request() (*types.Transaction, error)

func (*StubClient) Reward

func (e *StubClient) Reward() (*types.Transaction, error)

func (*StubClient) RoundLength added in v0.3.3

func (c *StubClient) RoundLength() (*big.Int, error)

func (*StubClient) RoundLockAmount added in v0.3.3

func (c *StubClient) RoundLockAmount() (*big.Int, error)

func (*StubClient) Senders added in v0.5.0

func (e *StubClient) Senders(addr ethcommon.Address) (sender struct {
	Deposit       *big.Int
	WithdrawRound *big.Int
}, err error)

func (*StubClient) SetGasInfo added in v0.3.3

func (c *StubClient) SetGasInfo(uint64, *big.Int) error

func (*StubClient) SetServiceURI added in v0.3.3

func (e *StubClient) SetServiceURI(serviceURI string) (*types.Transaction, error)

func (*StubClient) Setup added in v0.3.3

func (e *StubClient) Setup(password string, gasLimit uint64, gasPrice *big.Int) error

func (*StubClient) Sign added in v0.3.3

func (c *StubClient) Sign(msg []byte) ([]byte, error)

func (*StubClient) TargetBondingRate added in v0.3.3

func (c *StubClient) TargetBondingRate() (*big.Int, error)

func (*StubClient) TotalSupply added in v0.3.3

func (e *StubClient) TotalSupply() (*big.Int, error)

func (*StubClient) Transcoder

func (e *StubClient) Transcoder(blockRewardCut, feeShare *big.Int) (*types.Transaction, error)

func (*StubClient) TranscoderPool added in v0.5.1

func (e *StubClient) TranscoderPool() ([]*lpTypes.Transcoder, error)

func (*StubClient) Transfer

func (e *StubClient) Transfer(toAddr common.Address, amount *big.Int) (*types.Transaction, error)

func (*StubClient) Unbond

func (e *StubClient) Unbond(*big.Int) (*types.Transaction, error)

func (*StubClient) UnbondingPeriod added in v0.3.3

func (c *StubClient) UnbondingPeriod() (uint64, error)

func (*StubClient) Unlock added in v0.5.0

func (e *StubClient) Unlock() (*types.Transaction, error)

func (*StubClient) UnlockPeriod added in v0.5.0

func (e *StubClient) UnlockPeriod() (*big.Int, error)

func (*StubClient) Withdraw added in v0.3.3

func (e *StubClient) Withdraw() (*types.Transaction, error)

func (*StubClient) WithdrawFees added in v0.3.3

func (e *StubClient) WithdrawFees() (*types.Transaction, error)

func (*StubClient) WithdrawStake added in v0.3.3

func (e *StubClient) WithdrawStake(*big.Int) (*types.Transaction, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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