eth

package
v0.0.0-...-f39f649 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2021 License: Apache-2.0 Imports: 24 Imported by: 3

Documentation

Index

Constants

View Source
const (
	// DefaultGasLimit represents the default gas limit for this application.
	DefaultGasLimit = 2000000
)

Variables

This section is empty.

Functions

func ContextNodeReq

func ContextNodeReq() (context.Context, context.CancelFunc)

ContextNodeReq creates a node request timeout context (default: 2 sec). Use this context when performing a node request that doesn't wait for any blocks to be mined, e.g., setting up a subscription, sending a transaction (but not waiting for it to be mined).

Can be changed using SetNodeReqTimeout.

func ContextWaitMined

func ContextWaitMined() (context.Context, context.CancelFunc)

ContextWaitMined creates a mining timeout context (default: 10 sec). Use this context when waiting for a transaction to be mined or similar.

Can be changed using SetWaitMinedTimeout.

func EthToWeiFloat

func EthToWeiFloat(ethv float64) *big.Int

func EthToWeiInt

func EthToWeiInt(ethv int64) *big.Int

func NewHdWallet

func NewHdWallet(rng io.Reader) *hdwallet.Wallet

func NewRandomAddress

func NewRandomAddress(rng *rand.Rand) common.Address

NewRandomAddress creates a new random address.

func SetNodeReqTimeout

func SetNodeReqTimeout(duration time.Duration)

SetNodeReqTimeout sets the timeout used when creating contexts with ContextNodeReq.

func SetWaitMinedTimeout

func SetWaitMinedTimeout(duration time.Duration)

SetWaitMinedTimeout sets the timeout used when creating contexts with ContextWaitMined.

func WeiToEthFloat

func WeiToEthFloat(weiv *big.Int) *big.Float

func WeiToEthInt

func WeiToEthInt(weiv *big.Int) *big.Int

Types

type BlockSubscription

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

BlockSubscription represents a subscription to Ethereum blocks.

func (*BlockSubscription) Blocks

func (sub *BlockSubscription) Blocks() <-chan *tee.Block

Blocks returns the channel on which to receive subscribed blocks.

func (*BlockSubscription) Unsubscribe

func (sub *BlockSubscription) Unsubscribe()

Unsubscribe ends the subscription.

type BlockSubscription2

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

BlockSubscription2 represents a subscription to Ethereum blocks, version 2.

func (*BlockSubscription2) Blocks

func (blockSub *BlockSubscription2) Blocks() <-chan *tee.Block

Blocks returns the channel on which to receive subscribed blocks.

func (*BlockSubscription2) Unsubscribe

func (blockSub *BlockSubscription2) Unsubscribe()

Unsubscribe ends the subscription.

type Client

type Client struct {
	peruneth.ContractBackend
	// contains filtered or unexported fields
}

Client is an Ethereum client to interact with the Erdstall contract.

func CreateEthereumClient

func CreateEthereumClient(ctx context.Context, url string, wallet accounts.Wallet, a accounts.Account) (*Client, error)

CreateEthereumClient creates and connects a new ethereum client.

func NewClient

func NewClient(
	cb peruneth.ContractBackend,
	a accounts.Account,
) *Client

NewClient creates a new Erdstall Ethereum client.

func NewClientForWallet

func NewClientForWallet(
	ci peruneth.ContractInterface,
	w accounts.Wallet,
) (*Client, error)

NewClientForWallet returns a new Client using the given wallet as transactor. The first account is derived from the wallet and used as the account in the client.

func NewClientForWalletAndAccount

func NewClientForWalletAndAccount(
	ci peruneth.ContractInterface,
	w accounts.Wallet,
	a accounts.Account,
) *Client

NewClientForWalletAndAccount creates a new Erdstall Ethereum client for the given wallet and account.

func (*Client) Account

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

Account returns the account of the client.

func (*Client) BindContract

func (cl *Client) BindContract(ctx context.Context, addr common.Address) (*tee.Parameters, *bindings.Erdstall, error)

func (*Client) BlockByHash

func (cl *Client) BlockByHash(ctx context.Context, hash common.Hash) (*tee.Block, error)

BlockByHash returns the block for the given block hash together with the block's transaction receipts.

func (*Client) DeployContracts

func (cl *Client) DeployContracts(params *tee.Parameters) error

DeployContracts deploys the Erdstall contract to the blockchain. It updates the passed parameter's InitBlock and Contract fields.

func (*Client) NetworkID

func (cl *Client) NetworkID() (*big.Int, error)

NetworkID returns the ethereum client's network ID.

func (*Client) NewTransactor

func (cl *Client) NewTransactor(ctx context.Context) (*bind.TransactOpts, error)

NewTransactor creates a new transactor.

func (*Client) NextNonce

func (cl *Client) NextNonce(ctx context.Context) (uint64, error)

NextNonce returns the next Ethereum nonce.

func (*Client) OnlyErdstallReceipts

func (cl *Client) OnlyErdstallReceipts()

OnlyErdstallReceipts can be called during client setup to skip requesting transaction receipts. This affects all methods that create tee.Blocks.

func (*Client) SubscribeBlocks

func (cl *Client) SubscribeBlocks() (*BlockSubscription, error)

SubscribeBlocks subscribes the client to the mined Ethereum blocks.

func (*Client) SubscribeEpochs

func (cl *Client) SubscribeEpochs(ctx context.Context, params tee.Parameters, sink chan uint64, blockSink chan uint64) error

SubscribeEpochs writes new epochs into `sink`. Can be cancelled via ctx. Should be called in a go-routine, since it blocks. Future InitBlock numbers are not supported, so it will not return the 0. th epoch.

func (*Client) SubscribeExiting

func (cl *Client) SubscribeExiting(ctx context.Context, contract *bindings.Erdstall, epochs []uint64, accs []common.Address) (*ExitingSubscription, error)

SubscribeExiting writes received Exiting events into the Subscription. The `epochs` and `accs` arguments can be used to filter for specific events. Passing `nil` will skip the filtering. Can be cancelled via Unsubscribe.

func (*Client) SubscribeFrozen

func (cl *Client) SubscribeFrozen(ctx context.Context, contract *bindings.Erdstall, epochs []uint64) (*FrozenSubscription, error)

SubscribeFrozen writes received Frozen events into the Subscription. The `epochs` argument can be used to filter for specific events. Passing `nil` will skip the filtering. Can be cancelled via Unsubscribe.

func (*Client) SubscribeVerifiedBlocksFrom

func (cl *Client) SubscribeVerifiedBlocksFrom(start uint64) (*BlockSubscription2, error)

SubscribeVerifiedBlocksFrom subscribes the client to newly mined blocks starting from the given block number.

It only pushes blocks onto the subscription that are pow-depth deep from the tip of the chain.

func (*Client) TransactionReceipts

func (cl *Client) TransactionReceipts(ctx context.Context, block *types.Block) (types.Receipts, error)

TransactionReceipts returns the transaction receipts for the given block.

func (*Client) WaitForBlock

func (cl *Client) WaitForBlock(ctx context.Context, target uint64) error

type DefaultTransactor

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

DefaultTransactor can be used to make TransactOpts for accounts stored in a HD wallet.

func NewDefaultTransactor

func NewDefaultTransactor(w accounts.Wallet) *DefaultTransactor

NewDefaultTransactor returns a backend that can make TransactOpts for accounts contained in the given HD wallet.

func (*DefaultTransactor) NewTransactor

func (t *DefaultTransactor) NewTransactor(account accounts.Account) (*bind.TransactOpts, error)

NewTransactor returns a TransactOpts for the given account. It errors if the account is not contained in the wallet used for initializing transactor backend.

type ExitingSubscription

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

func (*ExitingSubscription) Err

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

func (*ExitingSubscription) Events

func (s *ExitingSubscription) Events() <-chan *bindings.ErdstallExiting

func (*ExitingSubscription) Unsubscribe

func (s *ExitingSubscription) Unsubscribe()

type FrozenSubscription

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

func (*FrozenSubscription) Err

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

func (*FrozenSubscription) Events

func (s *FrozenSubscription) Events() <-chan *bindings.ErdstallFrozen

func (*FrozenSubscription) Unsubscribe

func (s *FrozenSubscription) Unsubscribe()

type SimSetup

type SimSetup struct {
	SimBackend *chtest.SimulatedBackend    // A simulated blockchain backend
	Accounts   []accounts.Account          // funded accounts
	CB         *ethchannel.ContractBackend // contract backend that can transact for all accounts
	Wallet     *hd.Wallet                  // Wallet containing accounts (Perun wrapper)
	HdWallet   *hdwallet.Wallet            // Wallet containing accounts (original)
}

func NewSimSetup

func NewSimSetup(rng *rand.Rand, numAccounts int) *SimSetup

func (*SimSetup) Balance

func (s *SimSetup) Balance(a common.Address) *big.Int

Jump to

Keyboard shortcuts

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