eth

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2019 License: MIT Imports: 26 Imported by: 0

README

Tests rely on a forked version of go-ethereum that has fast block times and Solidity library linking functionality added to the abigen tool found here: https://github.com/yondonfu/go-ethereum/tree/lpTest

git clone https://github.com/yondonfu/go-ethereum.git $GOPATH/src/github.com/ethereum/go-ethereum
cd $GOPATH/src/github.com/ethereum/go-ethereum
git checkout lpTest
go install ./...

Running tests

Start geth

cd $GOPATH/src/github.com/livepeer/go-livepeer/eth
bash init.sh

In a separate window

cd $GOPATH/src/github.com/livepeer/go-livepeer/eth
go test -v -args -v 3 -logtostderr true

When tests are complete

bash cleanup.sh

Generating Go bindings

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

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
truffle compile --all
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)
)
View Source
var (
	RpcTimeout = 10 * time.Second
)
View Source
var SubscribeRetry = uint64(3)

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 FromBaseUnit added in v0.3.3

func FromBaseUnit(baseAmount *big.Int) *big.Float

func FromPerc added in v0.3.3

func FromPerc(perc float64) *big.Int

func IsNullAddress

func IsNullAddress(addr common.Address) bool

func RecoverClaims added in v0.3.3

func RecoverClaims(c LivepeerEthClient, ipfs ipfs.IpfsApi, db *common.DB) error

func ToBaseUnit added in v0.3.3

func ToBaseUnit(lptAmount *big.Float) *big.Int

func ToPerc added in v0.3.3

func ToPerc(value *big.Int) float64

func VerifySig added in v0.3.3

func VerifySig(addr common.Address, msg, sig []byte) bool

func Wait

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

Types

type AccountManager added in v0.3.3

type AccountManager struct {
	Account accounts.Account
	// contains filtered or unexported fields
}

func NewAccountManager added in v0.3.3

func NewAccountManager(accountAddr ethcommon.Address, keystoreDir string) (*AccountManager, error)

func (*AccountManager) CreateTransactOpts added in v0.3.3

func (am *AccountManager) CreateTransactOpts(gasLimit uint64, gasPrice *big.Int) (*bind.TransactOpts, error)

Create transact opts for client use - account must be unlocked Can optionally set gas limit and gas price used

func (*AccountManager) Lock added in v0.3.3

func (am *AccountManager) Lock() error

Lock account using underlying keystore and remove associated private key from memory

func (*AccountManager) Sign added in v0.3.3

func (am *AccountManager) Sign(msg []byte) ([]byte, error)

Sign byte array message. Account must be unlocked

func (*AccountManager) SignTx added in v0.3.3

func (am *AccountManager) SignTx(signer types.Signer, tx *types.Transaction) (*types.Transaction, error)

Sign a transaction. Account must be unlocked

func (*AccountManager) Unlock added in v0.3.3

func (am *AccountManager) Unlock(passphrase string) error

Unlock account indefinitely using underlying keystore

type BasicClaimManager added in v0.3.3

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

BasicClaimManager manages the claim process for a Livepeer transcoder. Check the Livepeer protocol for more details.

func NewBasicClaimManager added in v0.3.3

func NewBasicClaimManager(job *ethTypes.Job, c LivepeerEthClient, ipfs ipfs.IpfsApi, db *common.DB) *BasicClaimManager

NewBasicClaimManager creates a new claim manager.

func (*BasicClaimManager) AddReceipt added in v0.3.3

func (c *BasicClaimManager) AddReceipt(seqNo int64,
	bDataFile string, bData []byte, bSig []byte,
	tData map[ffmpeg.VideoProfile][]byte, tStart time.Time, tEnd time.Time) ([]byte, error)

AddReceipt adds a claim for a given video segment.

func (*BasicClaimManager) BroadcasterAddr added in v0.3.3

func (c *BasicClaimManager) BroadcasterAddr() ethcommon.Address

func (*BasicClaimManager) CanClaim added in v0.3.3

func (c *BasicClaimManager) CanClaim(currentBlockNum *big.Int, job *ethTypes.Job) (bool, error)

func (*BasicClaimManager) ClaimVerifyAndDistributeFees added in v0.3.3

func (c *BasicClaimManager) ClaimVerifyAndDistributeFees() error

Claim creates the onchain claim for all the claims added through AddReceipt

func (*BasicClaimManager) SufficientBroadcasterDeposit added in v0.3.3

func (c *BasicClaimManager) SufficientBroadcasterDeposit() (bool, error)

type ClaimManager added in v0.3.3

type ClaimManager interface {
	AddReceipt(seqNo int64, bDataFile string, bData []byte, bSig []byte, tData map[ffmpeg.VideoProfile][]byte, tStart time.Time, tEnd time.Time) ([]byte, error)
	SufficientBroadcasterDeposit() (bool, error)
	ClaimVerifyAndDistributeFees() error
	CanClaim(*big.Int, *ethTypes.Job) (bool, error)
	BroadcasterAddr() ethcommon.Address
}

type EventMonitor added in v0.3.3

type EventMonitor interface {
	SubscribeNewJob(context.Context, string, chan types.Log, ethcommon.Address, logCallback) (ethereum.Subscription, error)
	SubscribeNewRound(context.Context, string, chan types.Log, logCallback) (ethereum.Subscription, error)
	SubscribeNewBlock(context.Context, string, chan *types.Header, headerCallback) (ethereum.Subscription, error)
	EventSubscriptions() map[string]bool
}

func NewEventMonitor added in v0.3.3

func NewEventMonitor(backend *ethclient.Client, contractAddrMap map[string]ethcommon.Address) EventMonitor

type EventService added in v0.3.3

type EventService interface {
	Start(context.Context) error
	Stop() error
	IsWorking() bool
}

type EventSubscription added in v0.3.3

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

type LivepeerEthClient

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

	// Rounds
	InitializeRound() (*types.Transaction, error)
	CurrentRound() (*big.Int, error)
	LastInitializedRound() (*big.Int, error)
	CurrentRoundInitialized() (bool, error)
	CurrentRoundLocked() (bool, error)

	// Token
	Transfer(toAddr ethcommon.Address, amount *big.Int) (*types.Transaction, error)
	Request() (*types.Transaction, 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 *big.Int, feeShare *big.Int, pricePerSegment *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)
	RegisteredTranscoders() ([]*lpTypes.Transcoder, error)
	IsActiveTranscoder() (bool, error)
	AssignedTranscoder(*lpTypes.Job) (ethcommon.Address, error)
	GetTotalBonded() (*big.Int, error)

	// Jobs
	Job(streamId string, transcodingOptions string, maxPricePerSegment *big.Int, endBlock *big.Int) (*types.Transaction, error)
	ClaimWork(jobId *big.Int, segmentRange [2]*big.Int, claimRoot [32]byte) (*types.Transaction, error)
	Verify(jobId *big.Int, claimId *big.Int, segmentNumber *big.Int, dataStorageHash string, dataHashes [2][32]byte, broadcasterSig []byte, proof []byte) (*types.Transaction, error)
	DistributeFees(jobId *big.Int, claimId *big.Int) (*types.Transaction, error)
	Deposit(amount *big.Int) (*types.Transaction, error)
	Withdraw() (*types.Transaction, error)
	GetJob(jobID *big.Int) (*lpTypes.Job, error)
	GetClaim(jobID *big.Int, claimID *big.Int) (*lpTypes.Claim, error)
	BroadcasterDeposit(broadcaster ethcommon.Address) (*big.Int, error)
	NumJobs() (*big.Int, error)

	// Parameters
	NumActiveTranscoders() (*big.Int, error)
	RoundLength() (*big.Int, error)
	RoundLockAmount() (*big.Int, error)
	UnbondingPeriod() (uint64, error)
	VerificationRate() (uint64, error)
	VerificationPeriod() (*big.Int, error)
	VerificationSlashingPeriod() (*big.Int, error)
	FailedVerificationSlashAmount() (*big.Int, error)
	MissedVerificationSlashAmount() (*big.Int, error)
	DoubleClaimSegmentSlashAmount() (*big.Int, error)
	FinderFee() (*big.Int, error)
	Inflation() (*big.Int, error)
	InflationChange() (*big.Int, error)
	TargetBondingRate() (*big.Int, error)
	VerificationCodeHash() (string, error)
	Paused() (bool, error)

	// Events
	WatchForJob(string) (*lpTypes.Job, error)
	ProcessHistoricalNewJob(*big.Int, bool, func(*contracts.JobsManagerNewJob) error) error
	WatchForNewJob(bool, chan *contracts.JobsManagerNewJob) (ethereum.Subscription, error)
	ProcessHistoricalUnbond(*big.Int, func(*contracts.BondingManagerUnbond) error) error
	WatchForUnbond(chan *contracts.BondingManagerUnbond) (ethereum.Subscription, error)
	ProcessHistoricalRebond(*big.Int, func(*contracts.BondingManagerRebond) error) error
	WatchForRebond(chan *contracts.BondingManagerRebond) (ethereum.Subscription, error)
	ProcessHistoricalWithdrawStake(*big.Int, func(*contracts.BondingManagerWithdrawStake) error) error
	WatchForWithdrawStake(chan *contracts.BondingManagerWithdrawStake) (ethereum.Subscription, error)

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

func NewClient

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

type SortUint64 added in v0.3.3

type SortUint64 []int64

func (SortUint64) Len added in v0.3.3

func (a SortUint64) Len() int

func (SortUint64) Less added in v0.3.3

func (a SortUint64) Less(i, j int) bool

func (SortUint64) Swap added in v0.3.3

func (a SortUint64) Swap(i, j int)

type StubClient

type StubClient struct {
	StrmID                       string
	TOpts                        string
	MaxPrice                     *big.Int
	Jid                          *big.Int
	SegSeqNum                    *big.Int
	VeriRate                     uint64
	DStorageHash                 string
	DHash                        [32]byte
	TDHash                       [32]byte
	BSig                         []byte
	Proof                        []byte
	VerifyCounter                int
	ClaimJid                     []*big.Int
	ClaimStart                   []*big.Int
	ClaimEnd                     []*big.Int
	ClaimRoot                    map[[32]byte]bool
	ClaimCounter                 int
	SubLogsCh                    chan types.Log
	JobsMap                      map[string]*lpTypes.Job
	TranscoderAddress            common.Address
	BlockNum                     *big.Int
	BlockHashToReturn            common.Hash
	Claims                       map[int]*lpTypes.Claim
	LatestBlockError             error
	JobError                     error
	WatchJobError                error
	ProcessHistoricalUnbondError error
}

func (*StubClient) Account

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

func (*StubClient) AssignedTranscoder added in v0.3.3

func (e *StubClient) AssignedTranscoder(job *lpTypes.Job) (common.Address, error)

func (*StubClient) Backend

func (e *StubClient) Backend() (*ethclient.Client, error)

func (*StubClient) BalanceOf added in v0.3.3

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

func (*StubClient) Bond

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

func (*StubClient) BroadcasterDeposit added in v0.3.3

func (c *StubClient) BroadcasterDeposit(broadcaster common.Address) (*big.Int, 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) ClaimWork

func (e *StubClient) ClaimWork(jobId *big.Int, segmentRange [2]*big.Int, claimRoot [32]byte) (*types.Transaction, 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) Deposit

func (c *StubClient) Deposit(amount *big.Int) (*types.Transaction, error)

func (*StubClient) DistributeFees

func (e *StubClient) DistributeFees(jobId *big.Int, claimId *big.Int) (*types.Transaction, error)

func (*StubClient) DoubleClaimSegmentSlashAmount added in v0.3.3

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

func (*StubClient) FailedVerificationSlashAmount added in v0.3.3

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

func (*StubClient) FinderFee added in v0.3.3

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

func (*StubClient) GetClaim

func (c *StubClient) GetClaim(jobID *big.Int, claimID *big.Int) (*lpTypes.Claim, 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) GetJob

func (e *StubClient) GetJob(jobID *big.Int) (*lpTypes.Job, 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) 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) Job

func (e *StubClient) Job(streamId string, transcodingOptions string, maxPricePerSegment *big.Int, endBlock *big.Int) (*types.Transaction, error)

func (*StubClient) LastInitializedRound added in v0.3.3

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

func (*StubClient) LatestBlockNum added in v0.3.3

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

func (*StubClient) MissedVerificationSlashAmount added in v0.3.3

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

func (*StubClient) NumActiveTranscoders added in v0.3.3

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

func (*StubClient) NumJobs added in v0.3.3

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

func (*StubClient) Paused added in v0.3.3

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

func (*StubClient) ProcessHistoricalNewJob added in v0.3.3

func (c *StubClient) ProcessHistoricalNewJob(*big.Int, bool, func(*contracts.JobsManagerNewJob) error) error

func (*StubClient) ProcessHistoricalRebond added in v0.3.3

func (c *StubClient) ProcessHistoricalRebond(*big.Int, func(*contracts.BondingManagerRebond) error) error

func (*StubClient) ProcessHistoricalUnbond added in v0.3.3

func (c *StubClient) ProcessHistoricalUnbond(*big.Int, func(*contracts.BondingManagerUnbond) error) error

func (*StubClient) ProcessHistoricalWithdrawStake added in v0.3.3

func (c *StubClient) ProcessHistoricalWithdrawStake(*big.Int, func(*contracts.BondingManagerWithdrawStake) error) 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) RegisteredTranscoders added in v0.3.3

func (e *StubClient) RegisteredTranscoders() ([]*lpTypes.Transcoder, 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) 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 *big.Int, feeShare *big.Int, pricePerSegment *big.Int) (*types.Transaction, 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) VerificationCodeHash added in v0.3.3

func (c *StubClient) VerificationCodeHash() (string, error)

func (*StubClient) VerificationPeriod

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

func (*StubClient) VerificationRate

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

func (*StubClient) VerificationSlashingPeriod added in v0.3.3

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

func (*StubClient) Verify

func (e *StubClient) Verify(jobId *big.Int, claimId *big.Int, segmentNumber *big.Int, dataStorageHash string, dataHashes [2][32]byte, broadcasterSig []byte, proof []byte) (*types.Transaction, error)

func (*StubClient) WatchForJob added in v0.3.3

func (c *StubClient) WatchForJob(j string) (*lpTypes.Job, error)

func (*StubClient) WatchForNewJob added in v0.3.3

func (c *StubClient) WatchForNewJob(bool, chan *contracts.JobsManagerNewJob) (ethereum.Subscription, error)

func (*StubClient) WatchForRebond added in v0.3.3

func (*StubClient) WatchForUnbond added in v0.3.3

func (*StubClient) WatchForWithdrawStake added in v0.3.3

func (c *StubClient) WatchForWithdrawStake(chan *contracts.BondingManagerWithdrawStake) (ethereum.Subscription, error)

func (*StubClient) Withdraw added in v0.3.3

func (c *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