ethutils

package module
v0.0.0-...-42b2cff Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2021 License: Apache-2.0 Imports: 18 Imported by: 0

README

Build Status

ethutils

utils for ethereum contract

Documentation

Index

Constants

This section is empty.

Variables

These are the multipliers for ether denominations.

View Source
var (
	One = big.NewInt(1)
	Two = big.NewInt(2)
)

Normal used numbers in ethereum dapp.

View Source
var (
	CallOpt = &bind.CallOpts{}
)

common params

View Source
var (
	LocalRPCURL = "http://127.0.0.1:8545"
)

Config default values.

Functions

func AutoDeploy

func AutoDeploy(optionName string, deployFunc DeployFunc, auth *bind.TransactOpts) (common.Address, *types.Transaction, interface{})

AutoDeploy deploys contract/ panic if error/logs info info. Transaction sender's nonce will add 1 automatically.

func AutoSendTx

func AutoSendTx(optionName string, transactFunc TransactFunc, auth *bind.TransactOpts) *types.Transaction

AutoSendTx send tx to contract using contract object generated by abigen. Panic if errors. Transaction sender's nonce will add 1 automatically.

func MustGenrateKey

func MustGenrateKey() *ecdsa.PrivateKey

MustGenrateKey generates an random key using ethereum/crypto.

func MustGetClient

func MustGetClient(url string) *ethclient.Client

MustGetClient panics if can't get client

func MustGetDefaultOptByEncryptFile

func MustGetDefaultOptByEncryptFile(keypath string, pw string, client *ethclient.Client) *bind.TransactOpts

MustGetDefaultOptByEncryptFile returns an ethereum account with nonce set by keystore file path path.

func MustGetDefaultOptByHexKey

func MustGetDefaultOptByHexKey(keyHex string, client *ethclient.Client) *bind.TransactOpts

MustGetDefaultOptByHexKey returns an ethereum account with nonce set by hex key.

func MustGetETHAccountByEncryptFile

func MustGetETHAccountByEncryptFile(keypath string, pw string) *bind.TransactOpts

MustGetETHAccountByEncryptFile returns an ethereum account by keystore file path path.

func MustGetEthAccount

func MustGetEthAccount(keyHex string) *bind.TransactOpts

MustGetEthAccount returns an ethereum operation account by hex private key.

func MustGetPrivateKeyByEncryptFile

func MustGetPrivateKeyByEncryptFile(keypath string, pw string) *keystore.Key

func MustReadLines

func MustReadLines(f string) []string

MustReadLines returns all lines in file.

func MustSetNonce

func MustSetNonce(client *ethclient.Client, account *bind.TransactOpts)

MustSetNonce sets nonce to ethereum account if nonce is nil.

func PanicIfErr

func PanicIfErr(err error)

PanicIfErr panics if error occurs.

func PrivateKeyToHex

func PrivateKeyToHex(key *ecdsa.PrivateKey) string

PrivateKeyToHex change to private key to hex format.

func WaitForTx

func WaitForTx(client *ethclient.Client, hash common.Hash) (*types.Receipt, error)

WaitForTx stuck until tx is included in a block. receipt of tx will be returned

Types

type DeployFunc

type DeployFunc func() (common.Address, *types.Transaction, interface{}, error)

DeployFunc deploys contracts when executing.

type RPCClient

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

RPCClient implements methods by calling rpc client

func MustGetRPCClient

func MustGetRPCClient(url string) *RPCClient

MustGetRPCClient returns a ethereum rpc client instance.

func (*RPCClient) IsMining

func (rc *RPCClient) IsMining() (bool, error)

IsMining checks the miner is mining or not.

func (*RPCClient) StartMining

func (rc *RPCClient) StartMining() (bool, error)

StartMining start miner mining process

func (*RPCClient) StopMining

func (rc *RPCClient) StopMining() (bool, error)

StopMining stop miner mining process

type TransactFunc

type TransactFunc func() (*types.Transaction, error)

TransactFunc is a func to send tx to contract. Panic if errors. Transaction sender's nonce will add 1 automatically.

Jump to

Keyboard shortcuts

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