ethdrv

package module
v0.0.0-...-9705ef6 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2019 License: Apache-2.0 Imports: 21 Imported by: 1

README

ethdrv

GoDoc Go Report Card

Ethereum Driver - utility tools for Ethereum interaction.

This library adds functions to:

  • use truffle-schema files to extract contract addresses
  • password / password file support
  • transactor support

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ZeroAddress = common.HexToAddress("00")

ZeroAddress represents Ethereum unknown or invalid address

Functions

func FlogTx

func FlogTx(w io.Writer, msg string, tx *types.Transaction, logger log15.Logger)

FlogTx logs transaction into a Writer

func IncNonce

func IncNonce(nonce *big.Int) *big.Int

IncNonce increments nonce by one and returns updated nonce

func IncTxoNonce

func IncTxoNonce(txo *bind.TransactOpts, tx *types.Transaction)

IncTxoNonce increments transaction options nonce

func IsZeroAddr

func IsZeroAddr(a common.Address) bool

IsZeroAddr check if `a` is zero or invalid address

func LogTx

func LogTx(msg string, tx *types.Transaction, logger log15.Logger)

LogTx is a handy function to create debug log for successful transaction

func MustHaveEvents

func MustHaveEvents(e abi.ABI, logger log15.Logger, eventNames ...string)

MustHaveEvents ensures that the ABI object has listed events

func MustParseABI

func MustParseABI(name string, ctrABI string, logger log15.Logger) abi.ABI

MustParseABI parses abi string

func ParseAddress

func ParseAddress(addr string) (a common.Address, err errstack.E)

ParseAddress converts hex string to Ethereum address

func ParseAddressErrp

func ParseAddressErrp(addr string, errp errstack.Putter) common.Address

ParseAddressErrp calls ToAddress and sets the error in the putter

func SubscribeSimple

func SubscribeSimple(ctx context.Context,
	client *ethclient.Client,
	topics [][]common.Hash, addresses []common.Address) (<-chan types.Log, ethereum.Subscription, errstack.E)

SubscribeSimple is a simple utility function to create events subscription

func UnmarshalEvent

func UnmarshalEvent(dest interface{}, data []byte, e abi.Event) errstack.E

UnmarshalEvent blockchain log into the event structure `dest` must be a pointer to initialized structure

Types

type ContractFactory

type ContractFactory interface {
	TxrFactory
}

ContractFactory delivers methods to easily construct contracts

func NewContractFactory

func NewContractFactory(c *ethclient.Client, sf SchemaFactory, txrF TxrFactory, isTestRPC bool) ContractFactory

NewContractFactory is a default contract provider based on truffle schema files.

type KeySimple

type KeySimple struct {
	Address common.Address
	ID      string
	Version int
}

KeySimple is a simple version of keystore.Key structure

func MustReadKeySimple

func MustReadKeySimple(JSONFile string, logger log15.Logger) KeySimple

MustReadKeySimple calls ReadKeySimple and panics if it get's an error

func ReadKeySimple

func ReadKeySimple(JSONFile string, logger log15.Logger) (KeySimple, errstack.E)

ReadKeySimple reads the JSON key into the key object

func (*KeySimple) UnmarshalJSON

func (k *KeySimple) UnmarshalJSON(j []byte) (err error)

UnmarshalJSON implement interface for json.Unmrashall

type NetSchema

type NetSchema struct {
	Address   string
	UpdatedAt int `json:"updated_at"`
}

NetSchema is a type representing truffle-schema network description

type PgtAddress

type PgtAddress struct {
	common.Address
}

PgtAddress is a ethereum Address wrapper to provide DB interface

func (*PgtAddress) Scan

func (a *PgtAddress) Scan(src interface{}) error

Scan implements sql.Sanner interface

func (PgtAddress) Value

func (a PgtAddress) Value() (driver.Value, error)

Value implements sql/driver.Valuer

type Schema

type Schema struct {
	Name          string `json:"contractName"`
	Networks      map[int]NetSchema
	SchemaVersion string `json:"schemaVersion"`
	UpdatedAt     string `json:"updatedAt"`
}

Schema is a type representing truffle-schema contract file

func (Schema) Address

func (s Schema) Address(networkID int) (a common.Address, e errstack.E)

Address is a handy method which returns smart contract address deployed for given network

type SchemaFactory

type SchemaFactory struct {
	Dir     string
	Network int
	// contains filtered or unexported fields
}

SchemaFactory is a structure which provides contract schema functions and data

func NewSchemaFactory

func NewSchemaFactory(contractsPath string, network int, logger log15.Logger) (SchemaFactory, errstack.E)

NewSchemaFactory creates new SchemaFactory.

func (SchemaFactory) MustReadGetAddress

func (sf SchemaFactory) MustReadGetAddress(name string) (Schema, common.Address)

MustReadGetAddress returns contract schema and address and panics on error

func (SchemaFactory) Read

func (sf SchemaFactory) Read(name string) (s Schema, err errstack.E)

Read reads truffle-schema file. The name should not finish with ".json"

func (SchemaFactory) ReadGetAddress

func (sf SchemaFactory) ReadGetAddress(name string) (s Schema, a common.Address, err errstack.E)

ReadGetAddress reads schema using `Read` and extract contract address using then network identifier.

type TxrFactory

type TxrFactory interface {
	Txo() *bind.TransactOpts
	Addr() common.Address
}

TxrFactory wraps parameters to create bind.TransactOpts

func NewJSONTxrFactory

func NewJSONTxrFactory(filename, passphrase string, logger log15.Logger) (TxrFactory, errstack.E)

NewJSONTxrFactory creates TxrFactory using on JSON account file and passphrase

func NewPrivKeyTxrFactory

func NewPrivKeyTxrFactory(hexkey string) (TxrFactory, errstack.E)

NewPrivKeyTxrFactory creates new transactor using a hex string of a ECDSA key.

Directories

Path Synopsis
examples
roles
Roles interface example This package shows how to use a smart-contract interface with go interfaces.
Roles interface example This package shows how to use a smart-contract interface with go interfaces.

Jump to

Keyboard shortcuts

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