ethereum

package module
v0.0.0-...-9e984db Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2019 License: LGPL-3.0 Imports: 20 Imported by: 0

README

go-ethereum GoDoc Build Status Go Report Card Coverage Status

Packages to simplify work with the Ethereum blockchain

Contributing

If you'd like to add new exported APIs, please open an issue describing your proposal — discussing API changes ahead of time makes pull request review much smoother. In your issue, pull request, and any other communications, please remember to treat your fellow contributors with respect!

Setup

Fork, then clone the repository:

mkdir -p $GOPATH/src/github.com/monetha
cd $GOPATH/src/github.com/monetha
git clone git@github.com:your_github_username/go-ethereum.git
cd go-ethereum
git remote add upstream https://github.com/monetha/go-ethereum.git
git fetch upstream

Install dependencies:

make dependencies

Make sure that the tests and the linters pass:

make test
make lint
Making Changes

Start by creating a new branch for your changes:

cd $GOPATH/src/github.com/monetha/go-ethereum
git checkout master
git fetch upstream
git rebase upstream/master
git checkout -b cool_new_feature

Make your changes, then ensure that make lint and make test still pass. If you're satisfied with your changes, push them to your fork.

git push origin cool_new_feature

Then use the GitHub UI to open a pull request.

At this point, you're waiting on us to review your changes. We try to respond to issues and pull requests within a few business days, and we may suggest some improvements or alternatives. Once your changes are approved, one of the project maintainers will merge them.

We're much more likely to approve your changes if you:

  • Add tests for new functionality.
  • Write a good commit message.
  • Maintain backward compatibility.

Documentation

Index

Constants

View Source
const (
	// TransactionFailed is the status code of a transaction if execution failed.
	TransactionFailed = TransactionStatus(0)

	// TransactionSuccessful is the status code of a transaction if execution succeeded.
	TransactionSuccessful = TransactionStatus(1)
)

Variables

View Source
var ErrNotFound = errors.New("not found")

ErrNotFound is returned by API methods if the requested item does not exist.

Functions

func NewAddressFromHex

func NewAddressFromHex(hex string) (addr common.Address, err error)

NewAddressFromHex parses hex string and returns address.

Types

type Block

type Block struct {
	Difficulty   *big.Int
	ExtraData    []byte
	GasLimit     *big.Int
	GasUsed      *big.Int
	Hash         common.Hash
	Miner        common.Address
	Number       *big.Int
	Timestamp    uint64
	Transactions Transactions
}

Block holds information about Ethereum block.

func (*Block) String

func (b *Block) String() string

type ContractLogFilterer

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

ContractLogFilterer extends FilterLogs method of bind.BoundContract struct to allow filter multiple events

func NewContractLogFilterer

func NewContractLogFilterer(address common.Address, abi abi.ABI, filterer bind.ContractFilterer) *ContractLogFilterer

NewContractLogFilterer creates a instance of ContractLogFilterer.

func (*ContractLogFilterer) FilterLogs

func (c *ContractLogFilterer) FilterLogs(opts *bind.FilterOpts, names []string, query ...[]interface{}) (chan types.Log, event.Subscription, error)

FilterLogs filters contract logs for past blocks, returning the necessary channels to construct a strongly typed bound iterator on top of them.

type Eth

type Eth struct {
	Backend           backend.Backend
	LogFun            log.Fun
	SuggestedGasPrice *big.Int
}

Eth simplifies some operations with the Ethereum network

func New

func New(b backend.Backend, lf log.Fun) *Eth

New creates new instance of Eth

func (*Eth) Log

func (e *Eth) Log(msg string, ctx ...interface{})

Log writes message to the log with the context data

func (*Eth) NewHandleNonceBackend

func (e *Eth) NewHandleNonceBackend(handleAddresses []common.Address) *Eth

NewHandleNonceBackend returns new instance of Eth which 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 (*Eth) NewSession

func (e *Eth) NewSession(key *ecdsa.PrivateKey) *Session

NewSession creates an instance of Sessionclear

func (*Eth) UpdateSuggestedGasPrice

func (e *Eth) UpdateSuggestedGasPrice(ctx context.Context) error

UpdateSuggestedGasPrice initializes suggested gas price from backend

func (*Eth) WaitForTxReceipt

func (e *Eth) WaitForTxReceipt(ctx context.Context, txHash common.Hash) (tr *types.Receipt, err error)

WaitForTxReceipt waits until the transaction is successfully mined. It returns error if receipt status is not equal to `types.ReceiptStatusSuccessful`.

type Key

type Key struct {
	// Address is address associated with the PrivateKey (stored for simplicity)
	Address common.Address
	// PrivateKey represents a ECDSA private key. Pubkey/address can be derived from it.
	PrivateKey *ecdsa.PrivateKey
}

Key is combination of public address and private key.

func NewKey

func NewKey() (*Key, error)

NewKey generates a random Key.

func NewKeyFromPrivateKey

func NewKeyFromPrivateKey(hexkey string) (*Key, error)

NewKeyFromPrivateKey creates Key from hex-string representation of private key.

func (*Key) AddressString

func (k *Key) AddressString() string

AddressString returns string representation of address.

func (*Key) PrivateKeyString

func (k *Key) PrivateKeyString() string

PrivateKeyString returns hex-string representation of private key.

func (*Key) PublicKeyString

func (k *Key) PublicKeyString() string

PublicKeyString returns hex-string representation of public key.

type Session

type Session struct {
	*Eth
	TransactOpts bind.TransactOpts
}

Session provides holds basic pre-configured parameters like backend, authorization, logging

func (*Session) IsEnoughFunds

func (s *Session) IsEnoughFunds(ctx context.Context, gasLimit int64) (enough bool, minBalance *big.Int, err error)

IsEnoughFunds retrieves current account balance and checks if it's enough funds given gas limit. SetGasPrice needs to be called with non-nil parameter before calling this method.

type SliceLogFilterer

type SliceLogFilterer []*types.Log

SliceLogFilterer implements ethereum.SliceLogFilterer for log event slice.

func (SliceLogFilterer) FilterLogs

func (logs SliceLogFilterer) FilterLogs(ctx context.Context, query ethereum.FilterQuery) (res []types.Log, err error)

FilterLogs implements ethereum.SliceLogFilterer.

func (SliceLogFilterer) SubscribeFilterLogs

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

SubscribeFilterLogs implements ethereum.SliceLogFilterer.

type Transaction

type Transaction struct {
	BlockNumber      *big.Int
	From             common.Address
	GasLimit         *big.Int
	GasPrice         *big.Int
	GasUsed          *big.Int
	Hash             common.Hash
	Input            []byte
	Nonce            uint64
	To               *common.Address // nil means contract creation
	TransactionIndex uint64
	Value            *big.Int
	ContractAddress  *common.Address
	Status           *TransactionStatus
	Logs             []*types.Log
}

Transaction holds information about Ethereum transaction.

func (*Transaction) String

func (t *Transaction) String() string

type TransactionStatus

type TransactionStatus uint

TransactionStatus is receipt status of transaction.

type Transactions

type Transactions []*Transaction

Transactions slice type.

type Transferer

type Transferer struct {
	ContractTransactor bind.ContractTransactor
}

Transferer allows to make ethers transfer between accounts.

func (Transferer) SuggestGasLimit

func (t Transferer) SuggestGasLimit(opts *bind.TransactOpts, to common.Address, input []byte) (gasLimit *big.Int, err error)

SuggestGasLimit returns suggested gas limit to make transfer.

func (Transferer) Transfer

func (t Transferer) Transfer(opts *bind.TransactOpts, to common.Address, input []byte) (*types.Transaction, error)

Transfer transfers ethers to `to` account. `input` is optional and can be set to nil.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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