goethx

package module
v1.0.6 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

README

Transaction listener for ethereum

Documentation Go Report Card Coverage Status CircleCI Maintainability

Usage

txm, err := goethx.NewTxMgr(&logger.Log, ethClient, 6, 15* time.Minute, 1 * time.Second)
if err != nil {
    log.Fatalf("goethx.NewTxMgr: %v", err)
}
chTx := make(chan goethx.TxMsg)
go txm.MonitorTx(common.HexToHash("0x123"), chTx)
msg := <- chTx
if msg.Err != nil {
    log.Fatalf("goethx.MonitorTx(%s): %v", common.HexToHash("0x123").String(), msg.Err)
}

Documentation

Overview

Package goethx will help you monitor ethereum transactions

Index

Constants

View Source
const PublicBlockCountValid = 3

PublicBlockCountValid represents after how many blocks a tx is considered valid

View Source
const PublicPollingInterval = 2000

PublicPollingInterval represents the number of seconds between each tx check

View Source
const PublicPollingTimeOut = 7200000

PublicPollingTimeOut represents the number of seconds after we stop looking at tx

Variables

This section is empty.

Functions

This section is empty.

Types

type TxMgr

type TxMgr struct {
	Logger          logrus.StdLogger
	Cli             ethCli
	BlockCountValid int64
	PollingInterval time.Duration
	PollingTimeOut  time.Duration
	TxProcessing    map[common.Hash]bool
	Mutex           *sync.Mutex
}

TxMgr will allow listening to transactions

func NewTxMgr

func NewTxMgr(
	lg logrus.StdLogger,
	cli ethCli,
	bcv int64,
	pi time.Duration,
	pto time.Duration,
) *TxMgr

NewTxMgr will return an TxListener entity

func (*TxMgr) MonitorTx

func (txm *TxMgr) MonitorTx(
	ctx context.Context,
	txH common.Hash,
	chTx chan TxMsg,
)

MonitorTx will monitor a tx until success, error or timeout

type TxMgrI

type TxMgrI interface {
	MonitorTx(
		ctx context.Context,
		txH common.Hash,
		chTx chan<- TxMsg,
	) (bool, error)
}

TxMgrI represent the interface to listen to eth tx

type TxMsg

type TxMsg struct {
	Hash   common.Hash
	Status TxStatus
	Err    error
}

TxMsg is the message sent through the channel

type TxStatus

type TxStatus int

TxStatus represent the status of the tx

const (
	// TxNil is used when status is empty
	TxNil TxStatus = 0
	// TxPending is used when the tx is still waiting to be mined
	TxPending TxStatus = 10
	// TxError is used when the tx is not successful
	TxError TxStatus = 100
	// TxNotFound is used when no tx has been found
	TxNotFound TxStatus = 101
	// TxTimeOut is used when tx has not been included in a block
	// within the polling timeout
	TxTimeOut TxStatus = 102
	// TxSuccessNotEnoughBlocks is when tx has been included
	// but not eough blocks have been appended after
	TxSuccessNotEnoughBlocks = 103
	// TxSuccess is used when tx is successfully included into a block
	TxSuccess TxStatus = 1000
)

func (TxStatus) String added in v1.0.3

func (txs TxStatus) String() string

String fits stringer interface

Jump to

Keyboard shortcuts

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