confirm

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2022 License: MIT Imports: 9 Imported by: 6

Documentation

Index

Constants

View Source
const (
	DEFAULT_CONFIEMATION_BLOCKS   = uint64(2)
	DEFAULT_CONFIEMATION_INTERVAL = int64(1) // 1s
	DEFAULT_WORKER_INTERVAL       = int64(10)
	DEFAULT_TIMEOUT               = int64(60)
)

Variables

View Source
var (
	ErrTxNotFound                 = errors.New("tx not found")
	ErrTxFailed                   = errors.New("tx failed")
	ErrTxConfirmPending           = errors.New("tx confirm pending")
	ErrQueueIsEmpty               = errors.New("queue is empty")
	ErrBeforeConfirmationInterval = errors.New("before confirmation interval")
)
View Source
var (
	DEFAULT_WORKERS = runtime.NumCPU() - 2
)

Functions

func DefaultAfterTxConfirmed

func DefaultAfterTxConfirmed(hash string) error

func DefaultAfterTxSent

func DefaultAfterTxSent(hash string) error

func DefaultErrHandler

func DefaultErrHandler(hash string, err error)

Types

type AfterTxConfirmed

type AfterTxConfirmed func(string) error

AfterTxConfirmed

func WithAfterTxConfirmed

func WithAfterTxConfirmed(f func(string) error) AfterTxConfirmed

func (AfterTxConfirmed) Apply

func (f AfterTxConfirmed) Apply(c *Confirmer)

type AfterTxSent

type AfterTxSent func(string) error

AfterTxSent

func WithAfterTxSent

func WithAfterTxSent(f func(string) error) AfterTxSent

func (AfterTxSent) Apply

func (f AfterTxSent) Apply(c *Confirmer)

type Client

type Client interface {
	SendTx(ctx context.Context, tx interface{}) (string, error)
	ConfirmTx(ctx context.Context, hash string, confirmationBlocks uint64) error
}

type ConfirmationBlocks

type ConfirmationBlocks uint64

ConfirmationBlocks

func WithConfirmationBlock

func WithConfirmationBlock(b uint64) ConfirmationBlocks

func (ConfirmationBlocks) Apply

func (b ConfirmationBlocks) Apply(c *Confirmer)

type ConfirmationInterval

type ConfirmationInterval int64

ConfirmationInterval

func WithConfirmationInterval

func WithConfirmationInterval(i int64) ConfirmationInterval

func (ConfirmationInterval) Apply

func (i ConfirmationInterval) Apply(c *Confirmer)

type Confirmer

type Confirmer struct {
	AfterTxSent      HashHandler
	AfterTxConfirmed HashHandler
	ErrHandler       ErrHandler
	// contains filtered or unexported fields
}

func NewConfirmer

func NewConfirmer(client Client, queueSize int, opts ...Opt) Confirmer

func (*Confirmer) Close

func (c *Confirmer) Close(canncel context.CancelFunc)

func (*Confirmer) DequeueTx

func (c *Confirmer) DequeueTx(ctx context.Context) (string, error)

func (*Confirmer) EnqueueTx

func (c *Confirmer) EnqueueTx(ctx context.Context, tx interface{}) error

func (*Confirmer) QueueLen

func (c *Confirmer) QueueLen() int

func (*Confirmer) Start

func (c *Confirmer) Start(ctx context.Context) error

type ErrHandler

type ErrHandler func(string, error)

func WithErrHandler

func WithErrHandler(f func(string, error)) ErrHandler

func (ErrHandler) Apply

func (f ErrHandler) Apply(c *Confirmer)

type HashHandler

type HashHandler func(string) error

type Opt

type Opt interface {
	Apply(c *Confirmer)
}

type Timeout

type Timeout int64

Timeout

func WithTimeout

func WithTimeout(t int64) Timeout

func (Timeout) Apply

func (t Timeout) Apply(c *Confirmer)

type WorkerInterval

type WorkerInterval int64

WorkerInterval

func WithWorkerInterval

func WithWorkerInterval(i int64) WorkerInterval

func (WorkerInterval) Apply

func (i WorkerInterval) Apply(c *Confirmer)

type Workers

type Workers int

Workers

func WithWorkers

func WithWorkers(w int) Workers

func (Workers) Apply

func (w Workers) Apply(c *Confirmer)

Jump to

Keyboard shortcuts

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