ethereum

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2020 License: MIT Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrTransactionUnderpriced transaction is under priced
	ErrTransactionUnderpriced = errors.Error("replacement transaction underpriced")

	// ErrNonceTooLow nonce is too low
	ErrNonceTooLow = errors.Error("nonce too low")

	// ErrTransactionFailed error when transaction failed
	ErrTransactionFailed = errors.Error("Transaction failed")

	// ErrEthTransaction is a generic error type to be used for Ethereum errors
	ErrEthTransaction = errors.Error("error on ethereum tx layer")

	// ErrEthURL is used when failed to parse ethereum node URL
	ErrEthURL = errors.Error("failed to parse ethereum node URL")

	// ErrEthKeyNotProvided holds specific error when ethereum key is not provided
	ErrEthKeyNotProvided = errors.Error("Ethereum Key not provided")
)
View Source
const (
	// EthTXStatusTaskName contains the name of the task
	EthTXStatusTaskName string = "EthTXStatusTaskName"

	// TransactionTxHashParam contains the name  of the parameter
	TransactionTxHashParam string = "TxHashParam"

	// TransactionAccountParam contains the name  of the account
	TransactionAccountParam string = "Account ID"

	// TransactionEventName contains the name of the event filtered
	TransactionEventName string = "TxEventName"

	// TransactionEventValueIdx contains the index of the position of the event value
	TransactionEventValueIdx string = "TxEventValueIdx"

	// TransactionStatusSuccess contains the flag for a successful receipt.status
	TransactionStatusSuccess uint64 = 1
)
View Source
const (
	// ETHWaitForEvent is the name of the task
	ETHWaitForEvent = "EthWaitForEventTask"

	// WaitForEventFromBlock is the key for the from block
	WaitForEventFromBlock = "WaitForEventFromBlock"

	// WaitForEventAddress is the key for the address
	WaitForEventAddress = "WaitForEventAddress"

	// WaitForEventNameSignature is the key for the name and signature of the event
	WaitForEventNameSignature = "WaitForEventNameSignature"

	// WaitForEventTopic is the key for the topic
	WaitForEventTopic = "WaitForEventTopic"
)
View Source
const BootstrappedEthereumClient string = "BootstrappedEthereumClient"

BootstrappedEthereumClient is a key to mapped client in bootstrap context.

Variables

This section is empty.

Functions

func BindContract added in v1.0.0

func BindContract(address common.Address, abi abi.ABI, client Client) *bind.BoundContract

BindContract returns a bind contract at the address with corresponding ABI

func CreateWaitForEventJob added in v1.0.0

func CreateWaitForEventJob(
	parentCtx context.Context,
	jobsMan jobs.Manager,
	tq queue.TaskQueuer,
	self identity.DID,
	jobID jobs.JobID,
	eventSignature string,
	fromBlock *big.Int, address common.Address, topic common.Hash) (jobs.JobID, chan error, error)

CreateWaitForEventJob creates a job for waiting for event from ethereum

func DefaultWaitForTransactionMiningContext

func DefaultWaitForTransactionMiningContext(d time.Duration) (ctx context.Context, cancelFunc context.CancelFunc)

DefaultWaitForTransactionMiningContext returns context with timeout for write operations

func GetInt

func GetInt(key interface{}) (int, error)

GetInt converts key interface (float64) to int (used queueing only)

func QueueEthTXStatusTask

func QueueEthTXStatusTask(
	accountID identity.DID,
	jobID jobs.JobID,
	txHash common.Hash,
	queuer queue.TaskQueuer) (res queue.TaskResult, err error)

QueueEthTXStatusTask starts a new queuing transaction check task.

func QueueEthTXStatusTaskWithValue

func QueueEthTXStatusTaskWithValue(
	accountID identity.DID,
	jobID jobs.JobID,
	txHash common.Hash,
	queuer queue.TaskQueuer,
	txValue *jobs.JobValue) (res queue.TaskResult, err error)

QueueEthTXStatusTaskWithValue starts a new queuing transaction check task with a filtered value.

func SetClient

func SetClient(client Client)

SetClient sets the Client Note that this is a singleton and is the same connection for the whole application.

Types

type Bootstrapper

type Bootstrapper struct{}

Bootstrapper implements bootstrap.Bootstrapper.

func (Bootstrapper) Bootstrap

func (Bootstrapper) Bootstrap(ctx map[string]interface{}) error

Bootstrap initialises ethereum client.

type Client

type Client interface {

	// GetEthClient returns the ethereum client
	GetEthClient() EthClient

	// GetNodeURL returns the node url
	GetNodeURL() *url.URL

	// GetBlockByNumber returns the block by number
	GetBlockByNumber(ctx context.Context, number *big.Int) (*types.Block, error)

	// GetTxOpts returns a cached options if available else creates and returns new options
	GetTxOpts(ctx context.Context, accountName string) (*bind.TransactOpts, error)

	// SubmitTransactionWithRetries submits transaction to the ethereum chain
	// Blocking Function that sends transaction using reflection wrapped in a retrial block. It is based on the ErrTransactionUnderpriced error,
	// meaning that a transaction is being attempted to run twice, and the logic is to override the existing one. As we have constant
	// gas prices that means that a concurrent transaction race condition event has happened.
	// - contractMethod: Contract Method that implements GenericEthereumAsset (usually autogenerated binding from abi)
	// - params: Arbitrary number of parameters that are passed to the function fname call
	// Note: contractMethod must always return "*types.Job, error"
	SubmitTransactionWithRetries(contractMethod interface{}, opts *bind.TransactOpts, params ...interface{}) (tx *types.Transaction, err error)

	// GetGethCallOpts returns the Call options with default
	GetGethCallOpts(pending bool) (*bind.CallOpts, context.CancelFunc)

	// TransactionByHash returns a Ethereum transaction
	TransactionByHash(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error)

	// TransactionReceipt return receipt of a transaction
	TransactionReceipt(ctx context.Context, txHash common.Hash) (*types.Receipt, error)
}

Client can be implemented by any chain client

func GetClient

func GetClient() Client

GetClient returns the current Client

func NewGethClient

func NewGethClient(config Config) (Client, error)

NewGethClient returns an gethClient which implements Client

type Config

type Config interface {
	GetEthereumMaxGasPrice() *big.Int
	GetEthereumNodeURL() string
	GetEthereumAccount(accountName string) (account *config.AccountConfig, err error)
	GetEthereumIntervalRetry() time.Duration
	GetEthereumMaxRetries() int
	GetEthereumContextReadWaitTimeout() time.Duration
	GetEthereumGasMultiplier() float64
}

Config defines functions to get ethereum details

type EthClient added in v1.0.0

type EthClient interface {
	ethereum.ChainReader
	ethereum.ChainSyncReader
	ethereum.TransactionReader
	bind.ContractBackend

	NonceAt(ctx context.Context, account common.Address, blockNumber *big.Int) (uint64, error)
}

EthClient abstracts the implementation of eth client

type TransactionStatusTask

type TransactionStatusTask struct {
	jobsv1.BaseTask
	// contains filtered or unexported fields
}

TransactionStatusTask is struct for the task to check an Ethereum transaction

func NewTransactionStatusTask

func NewTransactionStatusTask(
	timeout time.Duration,
	txService jobs.Manager,
	transactionByHash func(ctx context.Context, hash common.Hash) (tx *types.Transaction, isPending bool, err error),
	transactionReceipt func(ctx context.Context, txHash common.Hash) (*types.Receipt, error),
	ethContextInitializer func(d time.Duration) (ctx context.Context, cancelFunc context.CancelFunc),

) *TransactionStatusTask

NewTransactionStatusTask returns a the struct for the task

func (*TransactionStatusTask) Copy

Copy returns a new instance of mintingConfirmationTask

func (*TransactionStatusTask) ParseKwargs

func (tst *TransactionStatusTask) ParseKwargs(kwargs map[string]interface{}) (err error)

ParseKwargs - define a method to parse CentID

func (*TransactionStatusTask) RunTask

func (tst *TransactionStatusTask) RunTask() (resp interface{}, err error)

RunTask calls listens to events from geth related to MintingConfirmationTask#TokenID and records result.

func (*TransactionStatusTask) TaskTypeName

func (tst *TransactionStatusTask) TaskTypeName() string

TaskTypeName returns mintingConfirmationTaskName

type WaitForEventTask added in v1.0.0

type WaitForEventTask struct {
	jobsv1.BaseTask
	// contains filtered or unexported fields
}

WaitForEventTask holds from block, addresses of the contract to listen events from, topics of the event the task assumes to block to be the latest

func NewWaitEventTask added in v1.0.0

func NewWaitEventTask(
	jobsManager jobs.Manager,
	ethContextInitializer func() (ctx context.Context, cancelFunc context.CancelFunc),
	filterLogsFunc func(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error),
) *WaitForEventTask

NewWaitEventTask returns a new wait event task for registration

func (*WaitForEventTask) Copy added in v1.0.0

Copy copies the state of the task into a new task

func (*WaitForEventTask) ParseKwargs added in v1.0.0

func (t *WaitForEventTask) ParseKwargs(kwargs map[string]interface{}) error

ParseKwargs parses the kwargs into a query.

func (*WaitForEventTask) RunTask added in v1.0.0

func (t *WaitForEventTask) RunTask() (res interface{}, err error)

RunTask runs the task of fetching the logs.

func (*WaitForEventTask) TaskTypeName added in v1.0.0

func (t *WaitForEventTask) TaskTypeName() string

TaskTypeName returns EthWaitForEvent

type WatchTransaction

type WatchTransaction struct {
	Status uint64
	Error  error
}

WatchTransaction holds the transaction status received form chain event

Jump to

Keyboard shortcuts

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