transactions

package
v0.0.0-...-ced8335 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2018 License: MPL-2.0 Imports: 23 Imported by: 0

Documentation

Overview

Package transactions is a generated GoMock package.

Index

Constants

View Source
const (
	// EventTransactionQueued is triggered when send transaction request is queued
	EventTransactionQueued = "transaction.queued"
	// EventTransactionFailed is triggered when send transaction request fails
	EventTransactionFailed = "transaction.failed"
)
View Source
const (
	// SendTransactionNoErrorCode is sent when no error occurred.
	SendTransactionNoErrorCode = iota
	// SendTransactionDefaultErrorCode is every case when there is no special tx return code.
	SendTransactionDefaultErrorCode
	// SendTransactionPasswordErrorCode is sent when account failed verification.
	SendTransactionPasswordErrorCode
	// SendTransactionTimeoutErrorCode is sent when tx is timed out.
	SendTransactionTimeoutErrorCode
	// SendTransactionDiscardedErrorCode is sent when tx was discarded.
	SendTransactionDiscardedErrorCode
)
View Source
const (
	// SendTxDefaultErrorCode is sent by default, when error is not nil, but type is unknown/unexpected.
	SendTxDefaultErrorCode = SendTransactionDefaultErrorCode
	// DefaultTxSendCompletionTimeout defines how many seconds to wait before returning result in sentTransaction().
	DefaultTxSendCompletionTimeout = 300 * time.Second
)
View Source
const (
	// DefaultTxQueueCap defines how many items can be queued.
	DefaultTxQueueCap = int(35)
)
View Source
const (
	// MessageIDKey is a key for message ID
	// This ID is required to track from which chat a given send transaction request is coming.
	MessageIDKey = contextKey("message_id")
)

Variables

View Source
var (
	//ErrQueuedTxTimedOut - error transaction sending timed out
	ErrQueuedTxTimedOut = errors.New("transaction sending timed out")
	//ErrQueuedTxDiscarded - error transaction discarded
	ErrQueuedTxDiscarded = errors.New("transaction has been discarded")
)
View Source
var (
	// ErrQueuedTxExist - transaction was already enqueued
	ErrQueuedTxExist = errors.New("transaction already exist in queue")
	//ErrQueuedTxIDNotFound - error transaction hash not found
	ErrQueuedTxIDNotFound = errors.New("transaction hash not found")
	//ErrQueuedTxInProgress - error transaction is in progress
	ErrQueuedTxInProgress = errors.New("transaction is in progress")
	//ErrInvalidCompleteTxSender - error transaction with invalid sender
	ErrInvalidCompleteTxSender = errors.New("transaction can only be completed by the same account which created it")
)
View Source
var (
	ErrInvalidSendTxArgs = errors.New("Transaction arguments are invalid (are both 'input' and 'data' fields used?)")
)

errors

View Source
var ErrTxQueueRunFailure = errors.New("error running transaction queue")

ErrTxQueueRunFailure - error running transaction queue

Functions

func NotifyOnEnqueue

func NotifyOnEnqueue(queuedTx *QueuedTx)

NotifyOnEnqueue returns handler that processes incoming tx queue requests

func NotifyOnReturn

func NotifyOnReturn(queuedTx *QueuedTx, err error)

NotifyOnReturn returns handler that processes responses from internal tx manager

Types

type AddrLocker

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

AddrLocker provides locks for addresses

func (*AddrLocker) LockAddr

func (l *AddrLocker) LockAddr(address common.Address)

LockAddr locks an account's mutex. This is used to prevent another tx getting the same nonce until the lock is released. The mutex prevents the (an identical nonce) from being read again during the time that the first transaction is being signed.

func (*AddrLocker) UnlockAddr

func (l *AddrLocker) UnlockAddr(address common.Address)

UnlockAddr unlocks the mutex of the given account.

type EthTransactor

type EthTransactor interface {
	PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)
	ethereum.GasEstimator
	ethereum.GasPricer
	ethereum.TransactionSender
}

EthTransactor provides methods to create transactions for ethereum network.

type EthTxClient

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

EthTxClient wraps common API methods that are used to send transaction.

func NewEthTxClient

func NewEthTxClient(client *rpc.Client) *EthTxClient

NewEthTxClient returns a new EthTxClient for client

func (*EthTxClient) EstimateGas

func (ec *EthTxClient) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error)

EstimateGas tries to estimate the gas needed to execute a specific transaction based on the current pending state of the backend blockchain. There is no guarantee that this is the true gas limit requirement as other transactions may be added or removed by miners, but it should provide a basis for setting a reasonable default.

func (*EthTxClient) PendingNonceAt

func (ec *EthTxClient) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

PendingNonceAt returns the account nonce of the given account in the pending state. This is the nonce that should be used for the next transaction.

func (*EthTxClient) SendTransaction

func (ec *EthTxClient) SendTransaction(ctx context.Context, tx *types.Transaction) error

SendTransaction injects a signed transaction into the pending pool for execution.

If the transaction was a contract creation use the TransactionReceipt method to get the contract address after the transaction has been mined.

func (*EthTxClient) SuggestGasPrice

func (ec *EthTxClient) SuggestGasPrice(ctx context.Context) (*big.Int, error)

SuggestGasPrice retrieves the currently suggested gas price to allow a timely execution of a transaction.

type Manager

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

Manager provides means to manage internal Status Backend (injected into LES)

func NewManager

func NewManager(rpcClientProvider RPCClientProvider) *Manager

NewManager returns a new Manager.

func (*Manager) CompleteTransaction

func (m *Manager) CompleteTransaction(id string, account *account.SelectedExtKey) (hash gethcommon.Hash, err error)

CompleteTransaction instructs backend to complete sending of a given transaction.

func (*Manager) DisableNotificactions

func (m *Manager) DisableNotificactions()

DisableNotificactions turns off notifications on enqueue and return of tx. It is not thread safe and must be called only before manager is started.

func (*Manager) DiscardTransaction

func (m *Manager) DiscardTransaction(id string) error

DiscardTransaction discards a given transaction from transaction queue

func (*Manager) NotifyErrored

func (m *Manager) NotifyErrored(id string, inputError error) error

NotifyErrored sends a notification for the given transaction

func (*Manager) QueueTransaction

func (m *Manager) QueueTransaction(tx *QueuedTx) error

QueueTransaction puts a transaction into the queue.

func (*Manager) SendTransactionRPCHandler

func (m *Manager) SendTransactionRPCHandler(ctx context.Context, args ...interface{}) (interface{}, error)

SendTransactionRPCHandler is a handler for eth_sendTransaction method. It accepts one param which is a slice with a map of transaction params.

func (*Manager) Start

func (m *Manager) Start(networkID uint64)

Start starts accepting new transactions into the queue.

func (*Manager) Stop

func (m *Manager) Stop()

Stop stops accepting new transactions into the queue.

func (*Manager) TransactionQueue

func (m *Manager) TransactionQueue() *TxQueue

TransactionQueue returns a reference to the queue.

func (*Manager) WaitForTransaction

func (m *Manager) WaitForTransaction(tx *QueuedTx) Result

WaitForTransaction adds a transaction to the queue and blocks until it's completed, discarded or times out.

type MocktestRPCClientProvider

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

MocktestRPCClientProvider is a mock of testRPCClientProvider interface

func NewMocktestRPCClientProvider

func NewMocktestRPCClientProvider(ctrl *gomock.Controller) *MocktestRPCClientProvider

NewMocktestRPCClientProvider creates a new mock instance

func (*MocktestRPCClientProvider) EXPECT

EXPECT returns an object that allows the caller to indicate expected use

func (*MocktestRPCClientProvider) RPCClient

func (m *MocktestRPCClientProvider) RPCClient() *rpc.Client

RPCClient mocks base method

type MocktestRPCClientProviderMockRecorder

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

MocktestRPCClientProviderMockRecorder is the mock recorder for MocktestRPCClientProvider

func (*MocktestRPCClientProviderMockRecorder) RPCClient

RPCClient indicates an expected call of RPCClient

type QueuedTx

type QueuedTx struct {
	ID      string
	Context context.Context
	Args    SendTxArgs
	Result  chan Result
}

QueuedTx holds enough information to complete the queued transaction.

func Create

func Create(ctx context.Context, args SendTxArgs) *QueuedTx

Create returns a transaction object.

type RPCClientProvider

type RPCClientProvider interface {
	RPCClient() *rpc.Client
}

RPCClientProvider is an interface that provides a way to obtain an rpc.Client.

type Result

type Result struct {
	Hash  common.Hash
	Error error
}

Result is a JSON returned from transaction complete function (used internally)

type ReturnSendTransactionEvent

type ReturnSendTransactionEvent struct {
	ID           string     `json:"id"`
	Args         SendTxArgs `json:"args"`
	MessageID    string     `json:"message_id"`
	ErrorMessage string     `json:"error_message"`
	ErrorCode    int        `json:"error_code,string"`
}

ReturnSendTransactionEvent is a JSON returned whenever transaction send is returned

type SendTransactionEvent

type SendTransactionEvent struct {
	ID        string     `json:"id"`
	Args      SendTxArgs `json:"args"`
	MessageID string     `json:"message_id"`
}

SendTransactionEvent is a signal sent on a send transaction request

type SendTxArgs

type SendTxArgs struct {
	From     common.Address  `json:"from"`
	To       *common.Address `json:"to"`
	Gas      *hexutil.Uint64 `json:"gas"`
	GasPrice *hexutil.Big    `json:"gasPrice"`
	Value    *hexutil.Big    `json:"value"`
	Nonce    *hexutil.Uint64 `json:"nonce"`
	// We keep both "input" and "data" for backward compatibility.
	// "input" is a preferred field.
	// see `vendor/github.com/ethereum/go-ethereum/internal/ethapi/api.go:1107`
	Input hexutil.Bytes `json:"input"`
	Data  hexutil.Bytes `json:"data"`
}

SendTxArgs represents the arguments to submit a new transaction into the transaction pool. This struct is based on go-ethereum's type in internal/ethapi/api.go, but we have freedom over the exact layout of this struct.

func (SendTxArgs) GetInput

func (args SendTxArgs) GetInput() hexutil.Bytes

GetInput returns either Input or Data field's value dependent on what is filled.

func (SendTxArgs) Valid

func (args SendTxArgs) Valid() bool

Valid checks whether this structure is filled in correctly.

type TxQueue

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

TxQueue is capped container that holds pending transactions

func (*TxQueue) Count

func (q *TxQueue) Count() int

Count returns number of currently queued transactions

func (*TxQueue) Done

func (q *TxQueue) Done(id string, hash gethcommon.Hash, err error) error

Done removes transaction from queue if no error or error is not transient and notify subscribers

func (*TxQueue) Enqueue

func (q *TxQueue) Enqueue(tx *QueuedTx) error

Enqueue enqueues incoming transaction

func (*TxQueue) Get

func (q *TxQueue) Get(id string) (*QueuedTx, error)

Get returns transaction by transaction identifier

func (*TxQueue) Has

func (q *TxQueue) Has(id string) bool

Has checks whether transaction with a given identifier exists in queue

func (*TxQueue) LockInprogress

func (q *TxQueue) LockInprogress(id string) error

LockInprogress returns error if transaction is already inprogress.

func (*TxQueue) Remove

func (q *TxQueue) Remove(id string)

Remove removes transaction by transaction identifier

func (*TxQueue) Reset

func (q *TxQueue) Reset()

Reset is to be used in tests only, as it simply creates new transaction map, w/o any cleanup of the previous one

func (*TxQueue) Start

func (q *TxQueue) Start()

Start starts enqueue and eviction loops

func (*TxQueue) Stop

func (q *TxQueue) Stop()

Stop stops transaction enqueue and eviction loops

Directories

Path Synopsis
Package fake is a generated GoMock package.
Package fake is a generated GoMock package.

Jump to

Keyboard shortcuts

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