eth

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2017 License: MIT Imports: 17 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 ProtocolBlockPerRound = big.NewInt(20)
View Source
var ProtocolCyclesPerRound = 2

Functions

func CheckRoundAndInit

func CheckRoundAndInit(client LivepeerEthClient) error

func IsNullAddress

func IsNullAddress(addr common.Address) bool

func NewTransactOptsForAccount

func NewTransactOptsForAccount(account accounts.Account, passphrase string, keyStore *keystore.KeyStore) (*bind.TransactOpts, error)

func NextBlockMultiple

func NextBlockMultiple(blockNum *big.Int, blockMultiple *big.Int) *big.Int

func ParseNewJobLog

func ParseNewJobLog(log types.Log) (broadcasterAddr common.Address, jid *big.Int, streamID string, transOptions string)

func Wait

func Wait(backend *ethclient.Client, rpcTimeout time.Duration, blocks *big.Int) error

func WaitForMinedTx

func WaitForMinedTx(backend *ethclient.Client, rpcTimeout time.Duration, minedTxTimeout time.Duration, txHash common.Hash, gas *big.Int) (*types.Receipt, error)

func WaitUntilBlockMultiple

func WaitUntilBlockMultiple(backend *ethclient.Client, rpcTimeout time.Duration, blockMultiple *big.Int) error

Types

type Claim

type Claim struct {
	SegmentRange         [2]*big.Int
	ClaimRoot            [32]byte
	ClaimBlock           *big.Int
	EndVerificationBlock *big.Int
	EndSlashingBlock     *big.Int
	Status               uint8
}

type Client

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

func NewClient

func NewClient(account accounts.Account, passphrase string, keystoreDir string, backend *ethclient.Client, gasPrice *big.Int, controllerAddr common.Address, rpcTimeout time.Duration, eventTimeout time.Duration) (*Client, error)

func (*Client) Account

func (c *Client) Account() accounts.Account

func (*Client) Approve

func (c *Client) Approve(toAddr common.Address, amount *big.Int) (<-chan types.Receipt, <-chan error)

func (*Client) ApproveAndTransact

func (c *Client) ApproveAndTransact(toAddr common.Address, amount *big.Int, txFunc func() (*types.Transaction, error)) (<-chan types.Receipt, <-chan error)

func (*Client) Backend

func (c *Client) Backend() *ethclient.Client

func (*Client) BatchDistributeFees

func (c *Client) BatchDistributeFees(jobId *big.Int, claimIds []*big.Int) (<-chan types.Receipt, <-chan error)

func (*Client) Bond

func (c *Client) Bond(amount *big.Int, toAddr common.Address) (<-chan types.Receipt, <-chan error)

func (*Client) ClaimWork

func (c *Client) ClaimWork(jobId *big.Int, segmentRange [2]*big.Int, claimRoot [32]byte) (<-chan types.Receipt, <-chan error)

func (*Client) CurrentRoundInitialized

func (c *Client) CurrentRoundInitialized() (bool, error)

func (*Client) DelegatorStake

func (c *Client) DelegatorStake() (*big.Int, error)

func (*Client) DelegatorStatus

func (c *Client) DelegatorStatus() (string, error)

func (*Client) Deposit

func (c *Client) Deposit(amount *big.Int) (<-chan types.Receipt, <-chan error)

func (*Client) DistributeFees

func (c *Client) DistributeFees(jobId *big.Int, claimId *big.Int) (<-chan types.Receipt, <-chan error)

func (*Client) GetBlockHashByNumber

func (c *Client) GetBlockHashByNumber(ctx context.Context, num *big.Int) (common.Hash, error)

func (*Client) GetBlockInfoByTxHash

func (c *Client) GetBlockInfoByTxHash(ctx context.Context, hash common.Hash) (blkNum *big.Int, blkHash common.Hash, err error)

func (*Client) GetBondingManagerAddr

func (c *Client) GetBondingManagerAddr() string

func (*Client) GetBroadcasterDeposit

func (c *Client) GetBroadcasterDeposit(broadcaster common.Address) (*big.Int, error)

func (*Client) GetCandidateTranscodersStats

func (c *Client) GetCandidateTranscodersStats() ([]TranscoderStats, error)

func (*Client) GetClaim

func (c *Client) GetClaim(jobID *big.Int, claimID *big.Int) (*Claim, error)

TODO: Go binding has an issue returning [32]byte...

func (*Client) GetControllerAddr

func (c *Client) GetControllerAddr() string

func (*Client) GetFaucetAddr

func (c *Client) GetFaucetAddr() string

func (*Client) GetJob

func (c *Client) GetJob(jobID *big.Int) (*Job, error)

func (*Client) GetJobsManagerAddr

func (c *Client) GetJobsManagerAddr() string

func (*Client) GetReceipt

func (c *Client) GetReceipt(tx *types.Transaction) (*types.Receipt, error)

func (*Client) GetRoundsManagerAddr

func (c *Client) GetRoundsManagerAddr() string

func (*Client) GetTokenAddr

func (c *Client) GetTokenAddr() string

func (*Client) GetTranscoderPendingPricingInfo

func (c *Client) GetTranscoderPendingPricingInfo(addr common.Address) (*big.Int, *big.Int, *big.Int, error)

func (*Client) GetTranscoderPricingInfo

func (c *Client) GetTranscoderPricingInfo(addr common.Address) (*big.Int, *big.Int, *big.Int, error)

func (*Client) InitializeRound

func (c *Client) InitializeRound() (<-chan types.Receipt, <-chan error)

func (*Client) IsActiveTranscoder

func (c *Client) IsActiveTranscoder() (bool, error)

func (*Client) IsAssignedTranscoder

func (c *Client) IsAssignedTranscoder(maxPricePerSegment *big.Int) bool

func (*Client) IsRegisteredTranscoder

func (c *Client) IsRegisteredTranscoder() (bool, error)

func (*Client) Job

func (c *Client) Job(streamId string, transcodingOptions string, maxPricePerSegment *big.Int, endBlock *big.Int) (<-chan types.Receipt, <-chan error)

func (*Client) LastRewardRound

func (c *Client) LastRewardRound() (*big.Int, error)

func (*Client) RequestTokens

func (c *Client) RequestTokens() (<-chan types.Receipt, <-chan error)

func (*Client) Reward

func (c *Client) Reward() (<-chan types.Receipt, <-chan error)

func (*Client) RoundInfo

func (c *Client) RoundInfo() (*big.Int, *big.Int, *big.Int, error)

RoundInfo returns the current round, start block of current round and current block of the protocol

func (*Client) RoundLength

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

func (*Client) RpcTimeout

func (c *Client) RpcTimeout() time.Duration

func (*Client) SetManagers

func (c *Client) SetManagers() error

func (*Client) SignSegmentHash

func (c *Client) SignSegmentHash(passphrase string, hash []byte) ([]byte, error)

func (*Client) SlashingPeriod

func (c *Client) SlashingPeriod() (*big.Int, error)

func (*Client) SubscribeToApproval

func (c *Client) SubscribeToApproval() (chan types.Log, ethereum.Subscription, error)

func (*Client) SubscribeToJobEvent

func (c *Client) SubscribeToJobEvent(ctx context.Context, logsCh chan types.Log, broadcasterAddr common.Address) (ethereum.Subscription, error)

func (*Client) TokenBalance

func (c *Client) TokenBalance() (*big.Int, error)

func (*Client) Transcoder

func (c *Client) Transcoder(blockRewardCut *big.Int, feeShare *big.Int, pricePerSegment *big.Int) (<-chan types.Receipt, <-chan error)

func (*Client) TranscoderBond

func (c *Client) TranscoderBond() (*big.Int, error)

func (*Client) TranscoderPendingPricingInfo

func (c *Client) TranscoderPendingPricingInfo() (*big.Int, *big.Int, *big.Int, error)

func (*Client) TranscoderPricingInfo

func (c *Client) TranscoderPricingInfo() (*big.Int, *big.Int, *big.Int, error)

func (*Client) TranscoderStake

func (c *Client) TranscoderStake() (*big.Int, error)

func (*Client) TranscoderStatus

func (c *Client) TranscoderStatus() (string, error)

func (*Client) Transfer

func (c *Client) Transfer(toAddr common.Address, amount *big.Int) (<-chan types.Receipt, <-chan error)

func (*Client) Unbond

func (c *Client) Unbond() (<-chan types.Receipt, <-chan error)

func (*Client) VerificationPeriod

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

func (*Client) VerificationRate

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

func (*Client) Verify

func (c *Client) Verify(jobId *big.Int, claimId *big.Int, segmentNumber *big.Int, dataStorageHash string, dataHashes [2][32]byte, broadcasterSig []byte, proof []byte) (<-chan types.Receipt, <-chan error)

func (*Client) WaitForReceipt

func (c *Client) WaitForReceipt(txFunc func() (*types.Transaction, error)) (<-chan types.Receipt, <-chan error)

func (*Client) WithdrawBond

func (c *Client) WithdrawBond() (<-chan types.Receipt, <-chan error)

func (*Client) WithdrawDeposit

func (c *Client) WithdrawDeposit() (<-chan types.Receipt, <-chan error)

type Job

type Job struct {
	JobId              *big.Int
	StreamId           string
	TranscodingOptions string
	MaxPricePerSegment *big.Int
	BroadcasterAddress common.Address
	TranscoderAddress  common.Address
	EndBlock           *big.Int
	Escrow             *big.Int
}

type LivepeerEthClient

type LivepeerEthClient interface {
	Backend() *ethclient.Client
	Account() accounts.Account
	RpcTimeout() time.Duration
	SubscribeToJobEvent(ctx context.Context, logsCh chan types.Log, broadcasterAddr common.Address) (ethereum.Subscription, error)
	RoundInfo() (*big.Int, *big.Int, *big.Int, error)
	InitializeRound() (<-chan types.Receipt, <-chan error)
	Transcoder(blockRewardCut *big.Int, feeShare *big.Int, pricePerSegment *big.Int) (<-chan types.Receipt, <-chan error)
	Bond(amount *big.Int, toAddr common.Address) (<-chan types.Receipt, <-chan error)
	Unbond() (<-chan types.Receipt, <-chan error)
	WithdrawBond() (<-chan types.Receipt, <-chan error)
	Reward() (<-chan types.Receipt, <-chan error)
	Deposit(amount *big.Int) (<-chan types.Receipt, <-chan error)
	GetBroadcasterDeposit(broadcaster common.Address) (*big.Int, error)
	WithdrawDeposit() (<-chan types.Receipt, <-chan error)
	Job(streamId string, transcodingOptions string, maxPricePerSegment *big.Int, endBlock *big.Int) (<-chan types.Receipt, <-chan error)
	ClaimWork(jobId *big.Int, segmentRange [2]*big.Int, claimRoot [32]byte) (<-chan types.Receipt, <-chan error)
	Verify(jobId *big.Int, claimId *big.Int, segmentNumber *big.Int, dataStorageHash string, dataHashes [2][32]byte, broadcasterSig []byte, proof []byte) (<-chan types.Receipt, <-chan error)
	DistributeFees(jobId *big.Int, claimId *big.Int) (<-chan types.Receipt, <-chan error)
	Transfer(toAddr common.Address, amount *big.Int) (<-chan types.Receipt, <-chan error)
	RequestTokens() (<-chan types.Receipt, <-chan error)
	CurrentRoundInitialized() (bool, error)
	IsActiveTranscoder() (bool, error)
	TranscoderStatus() (string, error)
	TranscoderStake() (*big.Int, error)
	TranscoderPendingPricingInfo() (*big.Int, *big.Int, *big.Int, error)
	TranscoderPricingInfo() (*big.Int, *big.Int, *big.Int, error)
	DelegatorStatus() (string, error)
	DelegatorStake() (*big.Int, error)
	TokenBalance() (*big.Int, error)
	GetJob(jobID *big.Int) (*Job, error)
	GetClaim(jobID *big.Int, claimID *big.Int) (*Claim, error)
	VerificationRate() (uint64, error)
	VerificationPeriod() (*big.Int, error)
	SlashingPeriod() (*big.Int, error)
	LastRewardRound() (*big.Int, error)
	IsRegisteredTranscoder() (bool, error)
	TranscoderBond() (*big.Int, error)
	GetCandidateTranscodersStats() ([]TranscoderStats, error)
	GetControllerAddr() string
	GetTokenAddr() string
	GetFaucetAddr() string
	GetBondingManagerAddr() string
	GetJobsManagerAddr() string
	GetRoundsManagerAddr() string
	GetBlockInfoByTxHash(ctx context.Context, hash common.Hash) (blkNum *big.Int, blkHash common.Hash, err error)
	GetBlockHashByNumber(ctx context.Context, num *big.Int) (common.Hash, error)
	IsAssignedTranscoder(maxPricePerSegment *big.Int) bool
}

type LogMonitor

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

func NewLogMonitor

func NewLogMonitor(eth LivepeerEthClient, broadcasterAddr common.Address) *LogMonitor

func (*LogMonitor) SubscribeToJobEvents

func (m *LogMonitor) SubscribeToJobEvents(callback func(j *Job))

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]*Job
	BlockNum          *big.Int
	BlockHashToReturn common.Hash
}

func (*StubClient) Account

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

func (*StubClient) Backend

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

func (*StubClient) Bond

func (e *StubClient) Bond(amount *big.Int, toAddr common.Address) (<-chan types.Receipt, <-chan error)

func (*StubClient) ClaimWork

func (e *StubClient) ClaimWork(jobId *big.Int, segmentRange [2]*big.Int, transcodeClaimsRoot [32]byte) (<-chan types.Receipt, <-chan error)

func (*StubClient) CurrentRoundInitialized

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

func (*StubClient) DelegatorStake

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

func (*StubClient) DelegatorStatus

func (e *StubClient) DelegatorStatus() (string, error)

func (*StubClient) Deposit

func (c *StubClient) Deposit(amount *big.Int) (<-chan types.Receipt, <-chan error)

func (*StubClient) DistributeFees

func (e *StubClient) DistributeFees(jobId *big.Int, claimId *big.Int) (<-chan types.Receipt, <-chan error)

func (*StubClient) GetBlockHashByNumber

func (c *StubClient) GetBlockHashByNumber(ctx context.Context, num *big.Int) (common.Hash, error)

func (*StubClient) GetBlockInfoByTxHash

func (e *StubClient) GetBlockInfoByTxHash(ctx context.Context, hash common.Hash) (blkNum *big.Int, blkHash common.Hash, err error)

func (*StubClient) GetBondingManagerAddr

func (e *StubClient) GetBondingManagerAddr() string

func (*StubClient) GetBroadcasterDeposit

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

func (*StubClient) GetCandidateTranscodersStats

func (e *StubClient) GetCandidateTranscodersStats() ([]TranscoderStats, error)

func (*StubClient) GetClaim

func (c *StubClient) GetClaim(jobID *big.Int, claimID *big.Int) (*Claim, error)

func (*StubClient) GetControllerAddr

func (e *StubClient) GetControllerAddr() string

func (*StubClient) GetFaucetAddr

func (e *StubClient) GetFaucetAddr() string

func (*StubClient) GetJob

func (e *StubClient) GetJob(jobID *big.Int) (*Job, error)

func (*StubClient) GetJobsManagerAddr

func (e *StubClient) GetJobsManagerAddr() string

func (*StubClient) GetReserveTranscodersStats

func (e *StubClient) GetReserveTranscodersStats() ([]TranscoderStats, error)

func (*StubClient) GetRoundsManagerAddr

func (e *StubClient) GetRoundsManagerAddr() string

func (*StubClient) GetTokenAddr

func (e *StubClient) GetTokenAddr() string

func (*StubClient) InitializeRound

func (e *StubClient) InitializeRound() (<-chan types.Receipt, <-chan error)

func (*StubClient) IsActiveTranscoder

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

func (*StubClient) IsAssignedTranscoder

func (c *StubClient) IsAssignedTranscoder(maxPricePerSegment *big.Int) bool

func (*StubClient) IsRegisteredTranscoder

func (c *StubClient) IsRegisteredTranscoder() (bool, error)

func (*StubClient) Job

func (e *StubClient) Job(streamId string, transcodingOptions string, maxPricePerSegment *big.Int, endBlock *big.Int) (<-chan types.Receipt, <-chan error)

func (*StubClient) JobDetails

func (e *StubClient) JobDetails(id *big.Int) (*big.Int, [32]byte, *big.Int, common.Address, common.Address, *big.Int, error)

func (*StubClient) LastRewardRound

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

func (*StubClient) RequestTokens

func (e *StubClient) RequestTokens() (<-chan types.Receipt, <-chan error)

func (*StubClient) Reward

func (e *StubClient) Reward() (<-chan types.Receipt, <-chan error)

func (*StubClient) RoundInfo

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

func (*StubClient) RpcTimeout

func (c *StubClient) RpcTimeout() time.Duration

func (*StubClient) SignSegmentHash

func (e *StubClient) SignSegmentHash(passphrase string, hash []byte) ([]byte, error)

func (*StubClient) SlashingPeriod

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

func (*StubClient) SubscribeToJobEvent

func (e *StubClient) SubscribeToJobEvent(ctx context.Context, logsCh chan types.Log, broadcasterAddr common.Address) (ethereum.Subscription, error)

func (*StubClient) TokenBalance

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

func (*StubClient) Transcoder

func (e *StubClient) Transcoder(blockRewardCut *big.Int, feeShare *big.Int, pricePerSegment *big.Int) (<-chan types.Receipt, <-chan error)

func (*StubClient) TranscoderBond

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

func (*StubClient) TranscoderPendingPricingInfo

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

func (*StubClient) TranscoderPricingInfo

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

func (*StubClient) TranscoderStake

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

func (*StubClient) TranscoderStatus

func (e *StubClient) TranscoderStatus() (string, error)

func (*StubClient) Transfer

func (e *StubClient) Transfer(toAddr common.Address, amount *big.Int) (<-chan types.Receipt, <-chan error)

func (*StubClient) Unbond

func (e *StubClient) Unbond() (<-chan types.Receipt, <-chan error)

func (*StubClient) ValidRewardTimeWindow

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

func (*StubClient) VerificationPeriod

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

func (*StubClient) VerificationRate

func (e *StubClient) VerificationRate() (uint64, 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) (<-chan types.Receipt, <-chan error)

func (*StubClient) WaitUntilNextRound

func (e *StubClient) WaitUntilNextRound() error

func (*StubClient) WatchEvent

func (e *StubClient) WatchEvent(logsCh <-chan types.Log) (types.Log, error)

func (*StubClient) WithdrawBond

func (e *StubClient) WithdrawBond() (<-chan types.Receipt, <-chan error)

func (*StubClient) WithdrawDeposit

func (c *StubClient) WithdrawDeposit() (<-chan types.Receipt, <-chan error)

type StubSubscription

type StubSubscription struct{}

func (*StubSubscription) Err

func (s *StubSubscription) Err() <-chan error

func (*StubSubscription) Unsubscribe

func (s *StubSubscription) Unsubscribe()

type TranscoderStats

type TranscoderStats struct {
	Address                common.Address
	TotalStake             *big.Int
	PendingBlockRewardCut  *big.Int
	PendingFeeShare        *big.Int
	PendingPricePerSegment *big.Int
	BlockRewardCut         *big.Int
	FeeShare               *big.Int
	PricePerSegment        *big.Int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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