backend

package
v0.6.5 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2019 License: GPL-3.0 Imports: 12 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Backend

type Backend interface {
	bind.ContractBackend
	ethereum.TransactionReader
	// BalanceAt returns the balance of the account of given address.
	BalanceAt(ctx context.Context, address common.Address, blockNum *big.Int) (*big.Int, error)
	// GetSenderPublicKey retrieves public key of sender from transaction.
	GetSenderPublicKey(t *types.Transaction) (*ecdsa.PublicKey, error)
	// NewKeyedTransactor is a utility method to easily create a transaction signer
	// from a single private key.
	NewKeyedTransactor(key *ecdsa.PrivateKey) *bind.TransactOpts
	// DecryptPayload decrypts transaction payload.
	DecryptPayload(ctx context.Context, tx *types.Transaction) ([]byte, error)
}

Backend contains all methods required for the backend operations.

func NewHandleNonceBackend

func NewHandleNonceBackend(inner Backend, handleAddresses []common.Address) Backend

NewHandleNonceBackend wraps backend and returns new instance of HandleNonceBackend.

type HandleNonceBackend

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

HandleNonceBackend internally handles nonce of the given addresses. It still calls PendingNonceAt of inner backend, but returns PendingNonceAt as a maximum of pending nonce in block-chain and internally stored nonce. It increments nonce for the given addresses after each successfully sent transaction (transaction may eventually fail in block-cain). Implementation is not thread-safe and should be used within one goroutine because otherwise invocations of PendingNonceAt and SendTransaction should be done atomically to have sequence of nonce without gaps (so that nonce would be equal to number of transactions sent).

func (*HandleNonceBackend) BalanceAt

func (b *HandleNonceBackend) BalanceAt(ctx context.Context, address common.Address, blockNum *big.Int) (*big.Int, error)

BalanceAt returns the balance of the account of given address.

func (*HandleNonceBackend) CallContract

func (b *HandleNonceBackend) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)

CallContract executes an Ethereum contract call with the specified data as the input.

func (*HandleNonceBackend) CodeAt

func (b *HandleNonceBackend) CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error)

CodeAt returns the code of the given account. This is needed to differentiate between contract internal errors and the local chain being out of sync.

func (*HandleNonceBackend) DecryptPayload

func (b *HandleNonceBackend) DecryptPayload(ctx context.Context, tx *types.Transaction) ([]byte, error)

DecryptPayload decrypts transaction payload.

func (*HandleNonceBackend) EstimateGas

func (b *HandleNonceBackend) EstimateGas(ctx context.Context, call ethereum.CallMsg) (usedGas uint64, err 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 (*HandleNonceBackend) FilterLogs

func (b *HandleNonceBackend) FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error)

FilterLogs executes a log filter operation, blocking during execution and returning all the results in one batch.

func (*HandleNonceBackend) GetSenderPublicKey

func (b *HandleNonceBackend) GetSenderPublicKey(t *types.Transaction) (*ecdsa.PublicKey, error)

GetSenderPublicKey retrieves public key of sender from transaction.

func (*HandleNonceBackend) NewKeyedTransactor

func (b *HandleNonceBackend) NewKeyedTransactor(key *ecdsa.PrivateKey) *bind.TransactOpts

NewKeyedTransactor is a utility method to easily create a transaction signer from a single private key.

func (*HandleNonceBackend) PendingCodeAt

func (b *HandleNonceBackend) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)

PendingCodeAt returns the code of the given account in the pending state.

func (*HandleNonceBackend) PendingNonceAt

func (b *HandleNonceBackend) PendingNonceAt(ctx context.Context, account common.Address) (nonce uint64, err error)

PendingNonceAt retrieves the current pending nonce associated with an account.

func (*HandleNonceBackend) SendTransaction

func (b *HandleNonceBackend) SendTransaction(ctx context.Context, tx *types.Transaction) (err error)

SendTransaction injects the transaction into the pending pool for execution.

func (*HandleNonceBackend) SubscribeFilterLogs

func (b *HandleNonceBackend) SubscribeFilterLogs(ctx context.Context, query ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)

SubscribeFilterLogs creates a background log filtering operation, returning a subscription immediately, which can be used to stream the found events.

func (*HandleNonceBackend) SuggestGasPrice

func (b *HandleNonceBackend) SuggestGasPrice(ctx context.Context) (*big.Int, error)

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

func (*HandleNonceBackend) TransactionByHash

func (b *HandleNonceBackend) TransactionByHash(ctx context.Context, txHash common.Hash) (tx *types.Transaction, isPending bool, err error)

TransactionByHash checks the pool of pending transactions in addition to the blockchain. The isPending return value indicates whether the transaction has been mined yet. Note that the transaction may not be part of the canonical chain even if it's not pending.

func (*HandleNonceBackend) TransactionReceipt

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

TransactionReceipt returns the receipt of a transaction by transaction hash.

type SimulatedBackendExt

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

SimulatedBackendExt wraps `backends.SimulatedBackend` and implements additionally `ethereum.TransactionReader` interface.

func NewSimulatedBackendExtended

func NewSimulatedBackendExtended(alloc core.GenesisAlloc, gasLimit uint64) *SimulatedBackendExt

NewSimulatedBackendExtended creates a new binding backend using a simulated blockchain for testing purposes. It uses `backends.SimulatedBackend` under the hood, but extends it to support `ethereum.TransactionReader` interface.

func (*SimulatedBackendExt) AdjustTime

func (b *SimulatedBackendExt) AdjustTime(adjustment time.Duration) error

AdjustTime adds a time shift to the simulated clock.

func (*SimulatedBackendExt) BalanceAt

func (b *SimulatedBackendExt) BalanceAt(ctx context.Context, address common.Address, blockNum *big.Int) (*big.Int, error)

BalanceAt returns the wei balance of a certain account in the blockchain.

func (*SimulatedBackendExt) CallContract

func (b *SimulatedBackendExt) CallContract(ctx context.Context, call ethereum.CallMsg, blockNumber *big.Int) ([]byte, error)

CallContract executes a contract call.

func (*SimulatedBackendExt) CodeAt

func (b *SimulatedBackendExt) CodeAt(ctx context.Context, contract common.Address, blockNumber *big.Int) ([]byte, error)

CodeAt returns the code associated with a certain account in the blockchain.

func (*SimulatedBackendExt) Commit

func (b *SimulatedBackendExt) Commit()

Commit imports all the pending transactions as a single block and starts a fresh new state.

func (*SimulatedBackendExt) DecryptPayload

func (b *SimulatedBackendExt) DecryptPayload(ctx context.Context, tx *types.Transaction) ([]byte, error)

DecryptPayload decrypts transaction payload.

func (*SimulatedBackendExt) EstimateGas

func (b *SimulatedBackendExt) EstimateGas(ctx context.Context, call ethereum.CallMsg) (usedGas uint64, err error)

EstimateGas executes the requested code against the currently pending block/state and returns the used amount of gas.

func (*SimulatedBackendExt) FilterLogs

func (b *SimulatedBackendExt) FilterLogs(ctx context.Context, query ethereum.FilterQuery) ([]types.Log, error)

FilterLogs executes a log filter operation, blocking during execution and returning all the results in one batch.

func (*SimulatedBackendExt) GetSenderPublicKey

func (b *SimulatedBackendExt) GetSenderPublicKey(t *types.Transaction) (*ecdsa.PublicKey, error)

GetSenderPublicKey retrieves public key of sender from transaction.

func (*SimulatedBackendExt) NewKeyedTransactor

func (b *SimulatedBackendExt) NewKeyedTransactor(key *ecdsa.PrivateKey) *bind.TransactOpts

NewKeyedTransactor is a utility method to easily create a transaction signer from a single private key.

func (*SimulatedBackendExt) PendingCodeAt

func (b *SimulatedBackendExt) PendingCodeAt(ctx context.Context, account common.Address) ([]byte, error)

PendingCodeAt returns the code associated with an account in the pending state.

func (*SimulatedBackendExt) PendingNonceAt

func (b *SimulatedBackendExt) PendingNonceAt(ctx context.Context, account common.Address) (uint64, error)

PendingNonceAt implements PendingStateReader.PendingNonceAt, retrieving the nonce currently pending for the account.

func (*SimulatedBackendExt) Rollback

func (b *SimulatedBackendExt) Rollback()

Rollback aborts all pending transactions, reverting to the last committed state.

func (*SimulatedBackendExt) SendTransaction

func (b *SimulatedBackendExt) SendTransaction(ctx context.Context, tx *types.Transaction) error

SendTransaction updates the pending block to include the given transaction. It panics if the transaction is invalid.

func (*SimulatedBackendExt) SubscribeFilterLogs

func (b *SimulatedBackendExt) SubscribeFilterLogs(ctx context.Context, query ethereum.FilterQuery, ch chan<- types.Log) (ethereum.Subscription, error)

SubscribeFilterLogs creates a background log filtering operation, returning a subscription immediately, which can be used to stream the found events.

func (*SimulatedBackendExt) SuggestGasPrice

func (b *SimulatedBackendExt) SuggestGasPrice(ctx context.Context) (*big.Int, error)

SuggestGasPrice implements ContractTransactor.SuggestGasPrice. Since the simulated chain doens't have miners, we just return a gas price of 1 for any call.

func (*SimulatedBackendExt) TransactionByHash

func (b *SimulatedBackendExt) TransactionByHash(ctx context.Context, txHash common.Hash) (tx *types.Transaction, isPending bool, err error)

TransactionByHash checks the pool of pending transactions in addition to the blockchain. The isPending return value indicates whether the transaction has been mined yet. Note that the transaction may not be part of the canonical chain even if it's not pending.

func (*SimulatedBackendExt) TransactionReceipt

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

TransactionReceipt returns the receipt of a transaction.

type Transaction

type Transaction types.Transaction

Transaction add new methods to types.Transaction

func (*Transaction) GetSenderPublicKey

func (t *Transaction) GetSenderPublicKey() (*ecdsa.PublicKey, error)

GetSenderPublicKey retrieves public key of sender from transaction.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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