eth

package
v0.0.0-...-0001d10 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2020 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrExceedsBalance    = stderr.New("cost of transaction exceeds sender balance")
	ErrExceedsBlockLimit = stderr.New("requested gas greater than block gas limit")
	ErrInvalidNonce      = stderr.New("invalid transaction nonce")
)

Functions

This section is empty.

Types

type Client

type Client interface {
	EstimateGas(context.Context, ethereum.CallMsg) (uint64, error)
	GetExpiry(context.Context, common.Address) (uint64, error)
	GetPublicKey(context.Context, common.Address) (PublicKey, error)
	NonceAt(context.Context, common.Address) (uint64, error)
	SendTransaction(context.Context, *types.Transaction) (SendTransactionResponse, error)
	SubscribeFilterLogs(context.Context, ethereum.FilterQuery, chan<- types.Log) (ethereum.Subscription, error)
	TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
	BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)
	GetCode(ctx context.Context, addr common.Address) (string, error)
}

type Conn

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

type EthSubscription

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

EthSubscription abstracts an ethereum.Subscription to be able to pass a chan<- interface{} and to monitor the state of the subscription

func (*EthSubscription) Err

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

Err returns a channel to retrieve subscription errors. Only one error at most will be sent through this chanel, when the subscription is closed, this channel will be closed so this can be used by a client to monitor whether the subscription is active

func (*EthSubscription) Unsubscribe

func (s *EthSubscription) Unsubscribe()

Unsubscribe destroys the subscription

type LogSubscriber

type LogSubscriber struct {
	FilterQuery ethereum.FilterQuery
	BlockNumber uint64
	Index       uint
	// contains filtered or unexported fields
}

LogSubscriber creates log based subscriptions using the underlying clients

func (*LogSubscriber) Subscribe

func (s *LogSubscriber) Subscribe(
	ctx context.Context,
	client Client,
	c chan<- interface{},
) (ethereum.Subscription, error)

Subscribe implementation of Subscriber for LogSubscriber

type Pool

type Pool interface {
	Conn(context.Context) (*Conn, error)
	Report(context.Context, *Conn) error
}

type PooledClient

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

func NewPooledClient

func NewPooledClient(props PooledClientProps) *PooledClient

func (*PooledClient) BalanceAt

func (c *PooledClient) BalanceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (*big.Int, error)

func (*PooledClient) EstimateGas

func (c *PooledClient) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)

func (*PooledClient) GetCode

func (c *PooledClient) GetCode(ctx context.Context, addr common.Address) (string, error)

func (*PooledClient) GetExpiry

func (c *PooledClient) GetExpiry(ctx context.Context, address common.Address) (uint64, error)

func (*PooledClient) GetPublicKey

func (c *PooledClient) GetPublicKey(ctx context.Context, address common.Address) (PublicKey, error)

func (*PooledClient) NonceAt

func (c *PooledClient) NonceAt(ctx context.Context, account common.Address) (uint64, error)

func (*PooledClient) SendTransaction

func (c *PooledClient) SendTransaction(ctx context.Context, tx *types.Transaction) (SendTransactionResponse, error)

func (*PooledClient) SubscribeFilterLogs

func (c *PooledClient) SubscribeFilterLogs(
	ctx context.Context,
	q ethereum.FilterQuery,
	ch chan<- types.Log,
) (ethereum.Subscription, error)

func (*PooledClient) TransactionReceipt

func (c *PooledClient) TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)

type PooledClientProps

type PooledClientProps struct {
	Pool        Pool
	RetryConfig concurrent.RetryConfig
}

type PublicKey

type PublicKey struct {
	Timestamp uint64 `json:"timestamp"`
	PublicKey string `json:"public_key"`
	Signature string `json:"signature"`
}

type SendTransactionResponse

type SendTransactionResponse struct {
	Output string `json:"output"`
	Status uint64 `json:"status"`
	Hash   string `json:"transactionHash"`
}

type Subscriber

type Subscriber interface {
	// Subscribe creates a subscription and forwards the received
	// events on the provided channel
	Subscribe(context.Context, Client, chan<- interface{}) (ethereum.Subscription, error)
}

Subscriber is an interface for types that creates subscriptions against an ethereum-like backend

type Subscription

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

Subscription abstracts an ethereum subscription into a type that implements automatic dialing and retries

func NewSubscription

func NewSubscription(props SubscriptionProps) *Subscription

NewSubscription creates a new subscription with the passed properties

func (*Subscription) Key

func (s *Subscription) Key() string

Key uniquely identifies the subscription within the global space of subscriptions

func (*Subscription) Unsubscribe

func (s *Subscription) Unsubscribe()

type SubscriptionEndEvent

type SubscriptionEndEvent struct {
	// Key uniquely identifies a subscription. It is provided by the
	// supervisor
	Key string

	// Error in case the subscription ended because of an error
	Error error
}

SubscriptionEndEvent is issued to the subscription supervisor when the subscription has been destroyed

type SubscriptionManager

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

SubscriptionManager manages the lifetime of a group of subscriptions

func NewSubscriptionManager

func NewSubscriptionManager(
	props SubscriptionManagerProps,
) *SubscriptionManager

NewSubscriptionManager creates a new subscription manager

func (*SubscriptionManager) Create

func (m *SubscriptionManager) Create(
	ctx context.Context,
	key string,
	subscriber Subscriber,
	c chan<- interface{},
) error

Create a new subscription identified by the specified key

func (*SubscriptionManager) Destroy

func (m *SubscriptionManager) Destroy(
	ctx context.Context,
	key string,
) error

Destroy an existing subscription identified by the specified key

type SubscriptionManagerProps

type SubscriptionManagerProps struct {
	// Context used by the manager and that can be used
	// to signal a cancellation
	Context context.Context

	// Logger used by the manager and its subscriptions
	Logger log.Logger

	// Client to make requests
	Client Client
}

SubscriptionManagerProps properties used to create the behaviour of the manager and the subscriptions created

type SubscriptionProps

type SubscriptionProps struct {
	// Logger used by the subscription
	Logger log.Logger

	// Client to make requests
	Client Client

	// URL to dial to for the subscription. Must be a ws URL since
	// other provides may not support creating subscriptions
	URL string

	// Key uniquely identifies a subscription and it can be used to
	// notify the subscription supervisor
	Key string

	// Subscriber used to create the subscription
	Subscriber Subscriber

	// C channel to receive the events for a subscription
	C chan<- interface{}
}

SubscriptionProps are the properties required when creating a subscription

type UniDialer

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

UniDialer implements the Dialer interface and it provides a connection to a specific URL. If a different URL is attempted the FixedDialer will return an error

func NewUniDialer

func NewUniDialer(ctx context.Context, url string) *UniDialer

NewUniDialer keeps a connection open to an endpoint. If the connection needs to be recreated a client can signal the pool to recreate the connection. Only websocket endpoints are supported because only websocket endpoints support the subscribe API

func (*UniDialer) Conn

func (p *UniDialer) Conn(ctx context.Context) (*Conn, error)

DialContext implementation of Dialer for FixedDialer

func (*UniDialer) Report

func (p *UniDialer) Report(ctx context.Context, conn *Conn) error

Report returns a failed Client connection. In this case, the pool we create a new Client connection on the next DialContext

type UniDialerProps

type UniDialerProps struct {
	URL         string
	RetryConfig concurrent.RetryConfig
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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